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., 51 Franklin Street, Fifth Floor, Boston, MA
20
FILE_LICENCE ( GPL2_OR_LATER );
25
#include <ipxe/dhcp.h>
26
#include <ipxe/dhcppkt.h>
27
#include <ipxe/netdevice.h>
28
#include <ipxe/iobuf.h>
29
#include <ipxe/uaccess.h>
33
* Cached DHCP packet handling
38
* Store cached DHCPACK packet
40
* @v data User pointer to cached DHCP packet data
41
* @v len Length of cached DHCP packet data
42
* @ret rc Return status code
44
* This function should be called by the architecture-specific
45
* get_cached_dhcpack() handler.
47
void store_cached_dhcpack ( userptr_t data, size_t len ) {
48
struct dhcp_packet *dhcppkt;
49
struct dhcphdr *dhcphdr;
50
struct settings *parent;
53
/* Create DHCP packet */
54
dhcppkt = zalloc ( sizeof ( *dhcppkt ) + len );
58
/* Fill in data for DHCP packet */
59
dhcphdr = ( ( ( void * ) dhcppkt ) + sizeof ( * dhcppkt ) );
60
copy_from_user ( dhcphdr, data, 0, len );
61
dhcppkt_init ( dhcppkt, dhcphdr, len );
62
DBG_HD ( dhcppkt->options.data, dhcppkt->options.used_len );
64
/* Register settings on the last opened network device.
65
* This will have the effect of registering cached settings
66
* with a network device when "dhcp netX" is performed for that
67
* device, which is usually what we want.
69
parent = netdev_settings ( last_opened_netdev() );
70
if ( ( rc = register_settings ( &dhcppkt->settings, parent,
71
DHCP_SETTINGS_NAME ) ) != 0 )
72
DBG ( "DHCP could not register cached settings: %s\n",
75
dhcppkt_put ( dhcppkt );
77
DBG ( "DHCP registered cached settings\n" );