mirror of https://github.com/ipxe/ipxe.git
Remove some assumptions about DHCP obtaining only a single options block.
parent
8d18338ae7
commit
fb809da2df
|
@ -512,6 +512,8 @@ dhcpopt_put ( struct dhcp_option_block *options ) {
|
||||||
ref_put ( &options->refcnt );
|
ref_put ( &options->refcnt );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
extern struct list_head dhcp_option_blocks;
|
||||||
|
|
||||||
extern unsigned long dhcp_num_option ( struct dhcp_option *option );
|
extern unsigned long dhcp_num_option ( struct dhcp_option *option );
|
||||||
extern void dhcp_ipv4_option ( struct dhcp_option *option,
|
extern void dhcp_ipv4_option ( struct dhcp_option *option,
|
||||||
struct in_addr *inp );
|
struct in_addr *inp );
|
||||||
|
|
|
@ -35,7 +35,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/** List of registered DHCP option blocks */
|
/** List of registered DHCP option blocks */
|
||||||
static LIST_HEAD ( option_blocks );
|
LIST_HEAD ( dhcp_option_blocks );
|
||||||
|
|
||||||
/** Registered DHCP option applicators */
|
/** Registered DHCP option applicators */
|
||||||
static struct dhcp_option_applicator dhcp_option_applicators[0]
|
static struct dhcp_option_applicator dhcp_option_applicators[0]
|
||||||
|
@ -259,7 +259,7 @@ struct dhcp_option * find_dhcp_option ( struct dhcp_option_block *options,
|
||||||
if ( options ) {
|
if ( options ) {
|
||||||
return find_dhcp_option_with_encap ( options, tag, NULL );
|
return find_dhcp_option_with_encap ( options, tag, NULL );
|
||||||
} else {
|
} else {
|
||||||
list_for_each_entry ( options, &option_blocks, list ) {
|
list_for_each_entry ( options, &dhcp_option_blocks, list ) {
|
||||||
if ( ( option = find_dhcp_option ( options, tag ) ) )
|
if ( ( option = find_dhcp_option ( options, tag ) ) )
|
||||||
return option;
|
return option;
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,7 @@ void register_dhcp_options ( struct dhcp_option_block *options ) {
|
||||||
options, options->priority );
|
options, options->priority );
|
||||||
|
|
||||||
/* Insert after any existing blocks which have a higher priority */
|
/* Insert after any existing blocks which have a higher priority */
|
||||||
list_for_each_entry ( existing, &option_blocks, list ) {
|
list_for_each_entry ( existing, &dhcp_option_blocks, list ) {
|
||||||
if ( options->priority > existing->priority )
|
if ( options->priority > existing->priority )
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1006,14 +1006,18 @@ int dhcp_configure_netdev ( struct net_device *netdev,
|
||||||
struct in_addr gateway = { INADDR_NONE };
|
struct in_addr gateway = { INADDR_NONE };
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Clear any existing routing table entry */
|
|
||||||
del_ipv4_address ( netdev );
|
|
||||||
|
|
||||||
/* Retrieve IP address configuration */
|
/* Retrieve IP address configuration */
|
||||||
find_dhcp_ipv4_option ( options, DHCP_EB_YIADDR, &address );
|
find_dhcp_ipv4_option ( options, DHCP_EB_YIADDR, &address );
|
||||||
find_dhcp_ipv4_option ( options, DHCP_SUBNET_MASK, &netmask );
|
find_dhcp_ipv4_option ( options, DHCP_SUBNET_MASK, &netmask );
|
||||||
find_dhcp_ipv4_option ( options, DHCP_ROUTERS, &gateway );
|
find_dhcp_ipv4_option ( options, DHCP_ROUTERS, &gateway );
|
||||||
|
|
||||||
|
/* Do nothing unless we have at least an IP address to use */
|
||||||
|
if ( ! address.s_addr )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Clear any existing routing table entry */
|
||||||
|
del_ipv4_address ( netdev );
|
||||||
|
|
||||||
/* Set up new IP address configuration */
|
/* Set up new IP address configuration */
|
||||||
if ( ( rc = add_ipv4_address ( netdev, address, netmask,
|
if ( ( rc = add_ipv4_address ( netdev, address, netmask,
|
||||||
gateway ) ) != 0 ) {
|
gateway ) ) != 0 ) {
|
||||||
|
|
|
@ -32,27 +32,30 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static struct dhcp_option_block *dhcp_options = NULL;
|
|
||||||
|
|
||||||
static int dhcp_success ( struct net_device *netdev,
|
static int dhcp_success ( struct net_device *netdev,
|
||||||
struct dhcp_option_block *options ) {
|
struct dhcp_option_block *options ) {
|
||||||
dhcp_options = dhcpopt_get ( options );
|
DBGC ( options, "DHCP client registering options %p\n", options );
|
||||||
register_dhcp_options ( options );
|
register_dhcp_options ( options );
|
||||||
return dhcp_configure_netdev ( netdev, options );
|
return dhcp_configure_netdev ( netdev, options );
|
||||||
}
|
}
|
||||||
|
|
||||||
int dhcp ( struct net_device *netdev ) {
|
int dhcp ( struct net_device *netdev ) {
|
||||||
|
struct dhcp_option_block *options;
|
||||||
|
struct dhcp_option_block *tmp;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Check we can open the interface first */
|
/* Check we can open the interface first */
|
||||||
if ( ( rc = ifopen ( netdev ) ) != 0 )
|
if ( ( rc = ifopen ( netdev ) ) != 0 )
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
/* Unregister any previously acquired options */
|
/* Unregister any option blocks acquired via DHCP */
|
||||||
if ( dhcp_options ) {
|
list_for_each_entry_safe ( options, tmp, &dhcp_option_blocks, list ) {
|
||||||
unregister_dhcp_options ( dhcp_options );
|
/* Skip static option blocks (e.g. from NVS) */
|
||||||
dhcpopt_put ( dhcp_options );
|
if ( find_dhcp_option ( options, DHCP_MESSAGE_TYPE ) ) {
|
||||||
dhcp_options = NULL;
|
DBGC ( options, "DHCP client unregistering options "
|
||||||
|
"%p\n", options );
|
||||||
|
unregister_dhcp_options ( options );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Perform DHCP */
|
/* Perform DHCP */
|
||||||
|
|
Loading…
Reference in New Issue