Quellcode durchsuchen

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

tags/v0.9.3
Michael Brown vor 17 Jahren
Ursprung
Commit
fb809da2df
4 geänderte Dateien mit 23 neuen und 14 gelöschten Zeilen
  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 Datei anzeigen

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

+ 3
- 3
src/net/dhcpopts.c Datei anzeigen

@@ -35,7 +35,7 @@
35 35
  */
36 36
 
37 37
 /** List of registered DHCP option blocks */
38
-static LIST_HEAD ( option_blocks );
38
+LIST_HEAD ( dhcp_option_blocks );
39 39
 
40 40
 /** Registered DHCP option applicators */
41 41
 static struct dhcp_option_applicator dhcp_option_applicators[0]
@@ -259,7 +259,7 @@ struct dhcp_option * find_dhcp_option ( struct dhcp_option_block *options,
259 259
 	if ( options ) {
260 260
 		return find_dhcp_option_with_encap ( options, tag, NULL );
261 261
 	} else {
262
-		list_for_each_entry ( options, &option_blocks, list ) {
262
+		list_for_each_entry ( options, &dhcp_option_blocks, list ) {
263 263
 			if ( ( option = find_dhcp_option ( options, tag ) ) )
264 264
 				return option;
265 265
 		}
@@ -283,7 +283,7 @@ void register_dhcp_options ( struct dhcp_option_block *options ) {
283 283
 	      options, options->priority );
284 284
 
285 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 287
 		if ( options->priority > existing->priority )
288 288
 			break;
289 289
 	}

+ 7
- 3
src/net/udp/dhcp.c Datei anzeigen

@@ -1006,14 +1006,18 @@ int dhcp_configure_netdev ( struct net_device *netdev,
1006 1006
 	struct in_addr gateway = { INADDR_NONE };
1007 1007
 	int rc;
1008 1008
 
1009
-	/* Clear any existing routing table entry */
1010
-	del_ipv4_address ( netdev );
1011
-
1012 1009
 	/* Retrieve IP address configuration */
1013 1010
 	find_dhcp_ipv4_option ( options, DHCP_EB_YIADDR, &address );
1014 1011
 	find_dhcp_ipv4_option ( options, DHCP_SUBNET_MASK, &netmask );
1015 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 1021
 	/* Set up new IP address configuration */
1018 1022
 	if ( ( rc = add_ipv4_address ( netdev, address, netmask,
1019 1023
 				       gateway ) ) != 0 ) {

+ 11
- 8
src/usr/dhcpmgmt.c Datei anzeigen

@@ -32,27 +32,30 @@
32 32
  *
33 33
  */
34 34
 
35
-static struct dhcp_option_block *dhcp_options = NULL;
36
-
37 35
 static int dhcp_success ( struct net_device *netdev,
38 36
 			  struct dhcp_option_block *options ) {
39
-	dhcp_options = dhcpopt_get ( options );
37
+	DBGC ( options, "DHCP client registering options %p\n", options );
40 38
 	register_dhcp_options ( options );
41 39
 	return dhcp_configure_netdev ( netdev, options );
42 40
 }
43 41
 
44 42
 int dhcp ( struct net_device *netdev ) {
43
+	struct dhcp_option_block *options;
44
+	struct dhcp_option_block *tmp;
45 45
 	int rc;
46 46
 
47 47
 	/* Check we can open the interface first */
48 48
 	if ( ( rc = ifopen ( netdev ) ) != 0 )
49 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 61
 	/* Perform DHCP */

Laden…
Abbrechen
Speichern