Browse Source

A DHCP session holds a persistent reference to a network device

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
7fafa89258
2 changed files with 27 additions and 0 deletions
  1. 3
    0
      src/include/gpxe/dhcp.h
  2. 24
    0
      src/net/udp/dhcp.c

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

13
 #include <gpxe/udp.h>
13
 #include <gpxe/udp.h>
14
 #include <gpxe/async.h>
14
 #include <gpxe/async.h>
15
 #include <gpxe/retry.h>
15
 #include <gpxe/retry.h>
16
+#include <gpxe/hotplug.h>
16
 
17
 
17
 /** BOOTP/DHCP server port */
18
 /** BOOTP/DHCP server port */
18
 #define BOOTPS_PORT 67
19
 #define BOOTPS_PORT 67
452
 
453
 
453
 	/** Network device being configured */
454
 	/** Network device being configured */
454
 	struct net_device *netdev;
455
 	struct net_device *netdev;
456
+	/** Persistent reference to network device */
457
+	struct reference netdev_ref;
455
 
458
 
456
 	/** Options obtained from server */
459
 	/** Options obtained from server */
457
 	struct dhcp_option_block *options;
460
 	struct dhcp_option_block *options;

+ 24
- 0
src/net/udp/dhcp.c View File

498
  * @v rc		Return status code
498
  * @v rc		Return status code
499
  */
499
  */
500
 static void dhcp_done ( struct dhcp_session *dhcp, int rc ) {
500
 static void dhcp_done ( struct dhcp_session *dhcp, int rc ) {
501
+
501
 	/* Free up options if we failed */
502
 	/* Free up options if we failed */
502
 	if ( rc != 0 ) {
503
 	if ( rc != 0 ) {
503
 		if ( dhcp->options ) {
504
 		if ( dhcp->options ) {
506
 		}
507
 		}
507
 	}
508
 	}
508
 
509
 
510
+	/* Stop retry timer */
511
+	stop_timer ( &dhcp->timer );
512
+
509
 	/* Close UDP connection */
513
 	/* Close UDP connection */
510
 	udp_close ( &dhcp->udp );
514
 	udp_close ( &dhcp->udp );
511
 
515
 
516
+	/* Release reference on net device */
517
+	ref_del ( &dhcp->netdev_ref );
518
+
512
 	/* Mark async operation as complete */
519
 	/* Mark async operation as complete */
513
 	async_done ( &dhcp->aop, rc );
520
 	async_done ( &dhcp->aop, rc );
514
 }
521
 }
689
 	.newdata	= dhcp_newdata,
696
 	.newdata	= dhcp_newdata,
690
 };
697
 };
691
 
698
 
699
+/**
700
+ * Forget reference to net_device
701
+ *
702
+ * @v ref		Persistent reference
703
+ */
704
+static void dhcp_forget_netdev ( struct reference *ref ) {
705
+	struct dhcp_session *dhcp
706
+		= container_of ( ref, struct dhcp_session, netdev_ref );
707
+
708
+	/* Kill DHCP session immediately */
709
+	dhcp_done ( dhcp, -ENETUNREACH );
710
+}
711
+
692
 /**
712
 /**
693
  * Initiate DHCP on a network interface
713
  * Initiate DHCP on a network interface
694
  *
714
  *
714
 		goto out;
734
 		goto out;
715
 	}
735
 	}
716
 
736
 
737
+	/* Add persistent reference to net device */
738
+	dhcp->netdev_ref.forget = dhcp_forget_netdev;
739
+	ref_add ( &dhcp->netdev_ref, &dhcp->netdev->references );
740
+
717
 	/* Proof of concept: just send a single DHCPDISCOVER */
741
 	/* Proof of concept: just send a single DHCPDISCOVER */
718
 	dhcp_send_request ( dhcp );
742
 	dhcp_send_request ( dhcp );
719
 
743
 

Loading…
Cancel
Save