Browse Source

[dhcpv6] Allow stateful DHCPv6 to apply obtained IPv6 addresses

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 11 years ago
parent
commit
017e6c56af
1 changed files with 24 additions and 6 deletions
  1. 24
    6
      src/net/udp/dhcpv6.c

+ 24
- 6
src/net/udp/dhcpv6.c View File

35
 #include <ipxe/in.h>
35
 #include <ipxe/in.h>
36
 #include <ipxe/crc32.h>
36
 #include <ipxe/crc32.h>
37
 #include <ipxe/errortab.h>
37
 #include <ipxe/errortab.h>
38
+#include <ipxe/ipv6.h>
38
 #include <ipxe/dhcpv6.h>
39
 #include <ipxe/dhcpv6.h>
39
 
40
 
40
 /** @file
41
 /** @file
408
 	/** Include leased IPv6 address within request */
409
 	/** Include leased IPv6 address within request */
409
 	DHCPV6_TX_IAADDR = 0x02,
410
 	DHCPV6_TX_IAADDR = 0x02,
410
 	/** Record received server ID */
411
 	/** Record received server ID */
411
-	DHCPV6_RX_SERVER_ID = 0x04,
412
+	DHCPV6_RX_RECORD_SERVER_ID = 0x04,
412
 	/** Record received IPv6 address */
413
 	/** Record received IPv6 address */
413
-	DHCPV6_RX_IAADDR = 0x08,
414
+	DHCPV6_RX_RECORD_IAADDR = 0x08,
415
+	/** Apply received IPv6 address */
416
+	DHCPV6_RX_APPLY_IAADDR = 0x10,
414
 };
417
 };
415
 
418
 
416
 /** DHCPv6 request state */
419
 /** DHCPv6 request state */
417
 static struct dhcpv6_session_state dhcpv6_request = {
420
 static struct dhcpv6_session_state dhcpv6_request = {
418
 	.tx_type = DHCPV6_REQUEST,
421
 	.tx_type = DHCPV6_REQUEST,
419
 	.rx_type = DHCPV6_REPLY,
422
 	.rx_type = DHCPV6_REPLY,
420
-	.flags = ( DHCPV6_TX_IA_NA | DHCPV6_TX_IAADDR | DHCPV6_RX_IAADDR ),
423
+	.flags = ( DHCPV6_TX_IA_NA | DHCPV6_TX_IAADDR |
424
+		   DHCPV6_RX_RECORD_IAADDR | DHCPV6_RX_APPLY_IAADDR ),
421
 	.next = NULL,
425
 	.next = NULL,
422
 };
426
 };
423
 
427
 
425
 static struct dhcpv6_session_state dhcpv6_solicit = {
429
 static struct dhcpv6_session_state dhcpv6_solicit = {
426
 	.tx_type = DHCPV6_SOLICIT,
430
 	.tx_type = DHCPV6_SOLICIT,
427
 	.rx_type = DHCPV6_ADVERTISE,
431
 	.rx_type = DHCPV6_ADVERTISE,
428
-	.flags = ( DHCPV6_TX_IA_NA | DHCPV6_RX_SERVER_ID | DHCPV6_RX_IAADDR ),
432
+	.flags = ( DHCPV6_TX_IA_NA | DHCPV6_RX_RECORD_SERVER_ID |
433
+		   DHCPV6_RX_RECORD_IAADDR ),
429
 	.next = &dhcpv6_request,
434
 	.next = &dhcpv6_request,
430
 };
435
 };
431
 
436
 
785
 	}
790
 	}
786
 
791
 
787
 	/* Record identity association address, if applicable */
792
 	/* Record identity association address, if applicable */
788
-	if ( dhcpv6->state->flags & DHCPV6_RX_IAADDR ) {
793
+	if ( dhcpv6->state->flags & DHCPV6_RX_RECORD_IAADDR ) {
789
 		if ( ( rc = dhcpv6_iaaddr ( &options, dhcpv6->iaid,
794
 		if ( ( rc = dhcpv6_iaaddr ( &options, dhcpv6->iaid,
790
 					    &dhcpv6->lease ) ) != 0 ) {
795
 					    &dhcpv6->lease ) ) != 0 ) {
791
 			DBGC ( dhcpv6, "DHCPv6 %s received %s with unusable "
796
 			DBGC ( dhcpv6, "DHCPv6 %s received %s with unusable "
802
 	}
807
 	}
803
 
808
 
804
 	/* Record server ID, if applicable */
809
 	/* Record server ID, if applicable */
805
-	if ( dhcpv6->state->flags & DHCPV6_RX_SERVER_ID ) {
810
+	if ( dhcpv6->state->flags & DHCPV6_RX_RECORD_SERVER_ID ) {
806
 		assert ( dhcpv6->server_duid == NULL );
811
 		assert ( dhcpv6->server_duid == NULL );
807
 		option = dhcpv6_option ( &options, DHCPV6_SERVER_ID );
812
 		option = dhcpv6_option ( &options, DHCPV6_SERVER_ID );
808
 		if ( ! option ) {
813
 		if ( ! option ) {
822
 			 dhcpv6->server_duid_len );
827
 			 dhcpv6->server_duid_len );
823
 	}
828
 	}
824
 
829
 
830
+	/* Apply identity association address, if applicable */
831
+	if ( dhcpv6->state->flags & DHCPV6_RX_APPLY_IAADDR ) {
832
+		if ( ( rc = ipv6_set_address ( dhcpv6->netdev,
833
+					       &dhcpv6->lease ) ) != 0 ) {
834
+			DBGC ( dhcpv6, "DHCPv6 %s could not apply %s: %s\n",
835
+			       dhcpv6->netdev->name,
836
+			       inet6_ntoa ( &dhcpv6->lease ), strerror ( rc ) );
837
+			/* This is plausibly the error we want to return */
838
+			dhcpv6->rc = rc;
839
+			goto done;
840
+		}
841
+	}
842
+
825
 	/* Transition to next state or complete DHCPv6, as applicable */
843
 	/* Transition to next state or complete DHCPv6, as applicable */
826
 	if ( dhcpv6->state->next ) {
844
 	if ( dhcpv6->state->next ) {
827
 
845
 

Loading…
Cancel
Save