Bläddra i källkod

A DHCP session holds a persistent reference to a network device

tags/v0.9.3
Michael Brown 17 år sedan
förälder
incheckning
7fafa89258
2 ändrade filer med 27 tillägg och 0 borttagningar
  1. 3
    0
      src/include/gpxe/dhcp.h
  2. 24
    0
      src/net/udp/dhcp.c

+ 3
- 0
src/include/gpxe/dhcp.h Visa fil

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

+ 24
- 0
src/net/udp/dhcp.c Visa fil

@@ -498,6 +498,7 @@ udp_to_dhcp ( struct udp_connection *conn ) {
498 498
  * @v rc		Return status code
499 499
  */
500 500
 static void dhcp_done ( struct dhcp_session *dhcp, int rc ) {
501
+
501 502
 	/* Free up options if we failed */
502 503
 	if ( rc != 0 ) {
503 504
 		if ( dhcp->options ) {
@@ -506,9 +507,15 @@ static void dhcp_done ( struct dhcp_session *dhcp, int rc ) {
506 507
 		}
507 508
 	}
508 509
 
510
+	/* Stop retry timer */
511
+	stop_timer ( &dhcp->timer );
512
+
509 513
 	/* Close UDP connection */
510 514
 	udp_close ( &dhcp->udp );
511 515
 
516
+	/* Release reference on net device */
517
+	ref_del ( &dhcp->netdev_ref );
518
+
512 519
 	/* Mark async operation as complete */
513 520
 	async_done ( &dhcp->aop, rc );
514 521
 }
@@ -689,6 +696,19 @@ static struct udp_operations dhcp_udp_operations = {
689 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 713
  * Initiate DHCP on a network interface
694 714
  *
@@ -714,6 +734,10 @@ struct async_operation * start_dhcp ( struct dhcp_session *dhcp ) {
714 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 741
 	/* Proof of concept: just send a single DHCPDISCOVER */
718 742
 	dhcp_send_request ( dhcp );
719 743
 

Laddar…
Avbryt
Spara