Add memtest support.
[syslinux-debian/hramrach.git] / gpxe / src / net / cachedhcp.c
blob37f344b69507e8d7bf05c22ee03fc5cf2371b42f
1 /*
2 * Copyright (C) 2009 Joshua Oreman <oremanj@rwcr.net>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 FILE_LICENCE ( GPL2_OR_LATER );
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <gpxe/dhcp.h>
25 #include <gpxe/dhcppkt.h>
26 #include <gpxe/netdevice.h>
27 #include <gpxe/iobuf.h>
28 #include <gpxe/uaccess.h>
30 /** @file
32 * Cached DHCP packet handling
36 /**
37 * Store cached DHCPACK packet
39 * @v data User pointer to cached DHCP packet data
40 * @v len Length of cached DHCP packet data
41 * @ret rc Return status code
43 * This function should be called by the architecture-specific
44 * get_cached_dhcpack() handler.
46 void store_cached_dhcpack ( userptr_t data, size_t len ) {
47 struct dhcp_packet *dhcppkt;
48 struct dhcphdr *dhcphdr;
49 struct settings *parent;
50 int rc;
52 /* Create DHCP packet */
53 dhcppkt = zalloc ( sizeof ( *dhcppkt ) + len );
54 if ( ! dhcppkt )
55 return;
57 /* Fill in data for DHCP packet */
58 dhcphdr = ( ( ( void * ) dhcppkt ) + sizeof ( * dhcppkt ) );
59 copy_from_user ( dhcphdr, data, 0, len );
60 dhcppkt_init ( dhcppkt, dhcphdr, len );
61 DBG_HD ( dhcppkt->options.data, dhcppkt->options.len );
63 /* Register settings on the last opened network device.
64 * This will have the effect of registering cached settings
65 * with a network device when "dhcp netX" is performed for that
66 * device, which is usually what we want.
68 parent = netdev_settings ( last_opened_netdev() );
69 if ( ( rc = register_settings ( &dhcppkt->settings, parent ) ) != 0 )
70 DBG ( "DHCP could not register cached settings: %s\n",
71 strerror ( rc ) );
73 dhcppkt_put ( dhcppkt );
75 DBG ( "DHCP registered cached settings\n" );