cachedhcp.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2009 Joshua Oreman <oremanj@rwcr.net>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00017  */
00018 
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <string.h>
00024 #include <gpxe/dhcp.h>
00025 #include <gpxe/dhcppkt.h>
00026 #include <gpxe/netdevice.h>
00027 #include <gpxe/iobuf.h>
00028 #include <gpxe/uaccess.h>
00029 
00030 /** @file
00031  *
00032  * Cached DHCP packet handling
00033  *
00034  */
00035 
00036 /**
00037  * Store cached DHCPACK packet
00038  *
00039  * @v data              User pointer to cached DHCP packet data
00040  * @v len               Length of cached DHCP packet data
00041  * @ret rc              Return status code
00042  *
00043  * This function should be called by the architecture-specific
00044  * get_cached_dhcpack() handler.
00045  */
00046 void store_cached_dhcpack ( userptr_t data, size_t len ) {
00047         struct dhcp_packet *dhcppkt;
00048         struct dhcphdr *dhcphdr;
00049         struct settings *parent;
00050         int rc;
00051 
00052         /* Create DHCP packet */
00053         dhcppkt = zalloc ( sizeof ( *dhcppkt ) + len );
00054         if ( ! dhcppkt )
00055                 return;
00056 
00057         /* Fill in data for DHCP packet */
00058         dhcphdr = ( ( ( void * ) dhcppkt ) + sizeof ( * dhcppkt ) );
00059         copy_from_user ( dhcphdr, data, 0, len );
00060         dhcppkt_init ( dhcppkt, dhcphdr, len );
00061         DBG_HD ( dhcppkt->options.data, dhcppkt->options.len );
00062 
00063         /* Register settings on the last opened network device.
00064          * This will have the effect of registering cached settings
00065          * with a network device when "dhcp netX" is performed for that
00066          * device, which is usually what we want.
00067          */
00068         parent = netdev_settings ( last_opened_netdev() );
00069         if ( ( rc = register_settings ( &dhcppkt->settings, parent ) ) != 0 )
00070                 DBG ( "DHCP could not register cached settings: %s\n",
00071                       strerror ( rc ) );
00072 
00073         dhcppkt_put ( dhcppkt );
00074 
00075         DBG ( "DHCP registered cached settings\n" );
00076 }

Generated on Tue Apr 6 20:01:10 2010 for gPXE by  doxygen 1.5.7.1