Browse Source

Remove some assumptions about DHCP obtaining only a single options block.

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
fb809da2df
4 changed files with 23 additions and 14 deletions
  1. 2
    0
      src/include/gpxe/dhcp.h
  2. 3
    3
      src/net/dhcpopts.c
  3. 7
    3
      src/net/udp/dhcp.c
  4. 11
    8
      src/usr/dhcpmgmt.c

+ 2
- 0
src/include/gpxe/dhcp.h View File

512
 	ref_put ( &options->refcnt );
512
 	ref_put ( &options->refcnt );
513
 }
513
 }
514
 
514
 
515
+extern struct list_head dhcp_option_blocks;
516
+
515
 extern unsigned long dhcp_num_option ( struct dhcp_option *option );
517
 extern unsigned long dhcp_num_option ( struct dhcp_option *option );
516
 extern void dhcp_ipv4_option ( struct dhcp_option *option,
518
 extern void dhcp_ipv4_option ( struct dhcp_option *option,
517
 			       struct in_addr *inp );
519
 			       struct in_addr *inp );

+ 3
- 3
src/net/dhcpopts.c View File

35
  */
35
  */
36
 
36
 
37
 /** List of registered DHCP option blocks */
37
 /** List of registered DHCP option blocks */
38
-static LIST_HEAD ( option_blocks );
38
+LIST_HEAD ( dhcp_option_blocks );
39
 
39
 
40
 /** Registered DHCP option applicators */
40
 /** Registered DHCP option applicators */
41
 static struct dhcp_option_applicator dhcp_option_applicators[0]
41
 static struct dhcp_option_applicator dhcp_option_applicators[0]
259
 	if ( options ) {
259
 	if ( options ) {
260
 		return find_dhcp_option_with_encap ( options, tag, NULL );
260
 		return find_dhcp_option_with_encap ( options, tag, NULL );
261
 	} else {
261
 	} else {
262
-		list_for_each_entry ( options, &option_blocks, list ) {
262
+		list_for_each_entry ( options, &dhcp_option_blocks, list ) {
263
 			if ( ( option = find_dhcp_option ( options, tag ) ) )
263
 			if ( ( option = find_dhcp_option ( options, tag ) ) )
264
 				return option;
264
 				return option;
265
 		}
265
 		}
283
 	      options, options->priority );
283
 	      options, options->priority );
284
 
284
 
285
 	/* Insert after any existing blocks which have a higher priority */
285
 	/* Insert after any existing blocks which have a higher priority */
286
-	list_for_each_entry ( existing, &option_blocks, list ) {
286
+	list_for_each_entry ( existing, &dhcp_option_blocks, list ) {
287
 		if ( options->priority > existing->priority )
287
 		if ( options->priority > existing->priority )
288
 			break;
288
 			break;
289
 	}
289
 	}

+ 7
- 3
src/net/udp/dhcp.c View File

1006
 	struct in_addr gateway = { INADDR_NONE };
1006
 	struct in_addr gateway = { INADDR_NONE };
1007
 	int rc;
1007
 	int rc;
1008
 
1008
 
1009
-	/* Clear any existing routing table entry */
1010
-	del_ipv4_address ( netdev );
1011
-
1012
 	/* Retrieve IP address configuration */
1009
 	/* Retrieve IP address configuration */
1013
 	find_dhcp_ipv4_option ( options, DHCP_EB_YIADDR, &address );
1010
 	find_dhcp_ipv4_option ( options, DHCP_EB_YIADDR, &address );
1014
 	find_dhcp_ipv4_option ( options, DHCP_SUBNET_MASK, &netmask );
1011
 	find_dhcp_ipv4_option ( options, DHCP_SUBNET_MASK, &netmask );
1015
 	find_dhcp_ipv4_option ( options, DHCP_ROUTERS, &gateway );
1012
 	find_dhcp_ipv4_option ( options, DHCP_ROUTERS, &gateway );
1016
 
1013
 
1014
+	/* Do nothing unless we have at least an IP address to use */
1015
+	if ( ! address.s_addr )
1016
+		return 0;
1017
+
1018
+	/* Clear any existing routing table entry */
1019
+	del_ipv4_address ( netdev );
1020
+
1017
 	/* Set up new IP address configuration */
1021
 	/* Set up new IP address configuration */
1018
 	if ( ( rc = add_ipv4_address ( netdev, address, netmask,
1022
 	if ( ( rc = add_ipv4_address ( netdev, address, netmask,
1019
 				       gateway ) ) != 0 ) {
1023
 				       gateway ) ) != 0 ) {

+ 11
- 8
src/usr/dhcpmgmt.c View File

32
  *
32
  *
33
  */
33
  */
34
 
34
 
35
-static struct dhcp_option_block *dhcp_options = NULL;
36
-
37
 static int dhcp_success ( struct net_device *netdev,
35
 static int dhcp_success ( struct net_device *netdev,
38
 			  struct dhcp_option_block *options ) {
36
 			  struct dhcp_option_block *options ) {
39
-	dhcp_options = dhcpopt_get ( options );
37
+	DBGC ( options, "DHCP client registering options %p\n", options );
40
 	register_dhcp_options ( options );
38
 	register_dhcp_options ( options );
41
 	return dhcp_configure_netdev ( netdev, options );
39
 	return dhcp_configure_netdev ( netdev, options );
42
 }
40
 }
43
 
41
 
44
 int dhcp ( struct net_device *netdev ) {
42
 int dhcp ( struct net_device *netdev ) {
43
+	struct dhcp_option_block *options;
44
+	struct dhcp_option_block *tmp;
45
 	int rc;
45
 	int rc;
46
 
46
 
47
 	/* Check we can open the interface first */
47
 	/* Check we can open the interface first */
48
 	if ( ( rc = ifopen ( netdev ) ) != 0 )
48
 	if ( ( rc = ifopen ( netdev ) ) != 0 )
49
 		return rc;
49
 		return rc;
50
 
50
 
51
-	/* Unregister any previously acquired options */
52
-	if ( dhcp_options ) {
53
-		unregister_dhcp_options ( dhcp_options );
54
-		dhcpopt_put ( dhcp_options );
55
-		dhcp_options = NULL;
51
+	/* Unregister any option blocks acquired via DHCP */
52
+	list_for_each_entry_safe ( options, tmp, &dhcp_option_blocks, list ) {
53
+		/* Skip static option blocks (e.g. from NVS) */
54
+		if ( find_dhcp_option ( options, DHCP_MESSAGE_TYPE ) ) {
55
+			DBGC ( options, "DHCP client unregistering options "
56
+			       "%p\n", options );
57
+			unregister_dhcp_options ( options );
58
+		}
56
 	}
59
 	}
57
 
60
 
58
 	/* Perform DHCP */
61
 	/* Perform DHCP */

Loading…
Cancel
Save