Browse Source

[dhcpv6] Include RFC5970 client architecture options in DHCPv6 requests

RFC5970 defines DHCPv6 options 61 (client system architecture type)
and 62 (client network interface identifier), with contents equivalent
to DHCPv4 options 93 and 94 respectively.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 8 years ago
parent
commit
fda8916c83
2 changed files with 52 additions and 17 deletions
  1. 33
    0
      src/include/ipxe/dhcpv6.h
  2. 19
    17
      src/net/udp/dhcpv6.c

+ 33
- 0
src/include/ipxe/dhcpv6.h View File

@@ -157,6 +157,12 @@ struct dhcpv6_user_class_option {
157 157
 /** DHCPv6 bootfile parameters option */
158 158
 #define DHCPV6_BOOTFILE_PARAM 60
159 159
 
160
+/** DHCPv6 client system architecture option */
161
+#define DHCPV6_CLIENT_ARCHITECTURE 61
162
+
163
+/** DHCPv6 client network interface identifier option */
164
+#define DHCPV6_CLIENT_NDI 62
165
+
160 166
 /** DHCPv6 syslog server option
161 167
  *
162 168
  * This option code has not yet been assigned by IANA.  Please update
@@ -164,6 +170,33 @@ struct dhcpv6_user_class_option {
164 170
  */
165 171
 #define DHCPV6_LOG_SERVERS 0xffffffffUL
166 172
 
173
+/** Construct a DHCPv6 option code */
174
+#define DHCPV6_CODE( code ) \
175
+	( ( (code) >> 8 ) & 0xff ), ( ( (code) >> 0 ) & 0xff )
176
+
177
+/** Construct a DHCPv6 option length */
178
+#define DHCPV6_LEN( len ) \
179
+	( ( (len) >> 8 ) & 0xff ), ( ( (len) >> 0 ) & 0xff )
180
+
181
+/** Construct a DHCPv6 option from a list of bytes */
182
+#define DHCPV6_OPTION( ... ) \
183
+	DHCPV6_LEN ( VA_ARG_COUNT ( __VA_ARGS__ ) ), __VA_ARGS__
184
+
185
+/** Construct a DHCPv6 option from a list of characters */
186
+#define DHCPV6_STRING( ... ) DHCPV6_OPTION ( __VA_ARGS__ )
187
+
188
+/** Construct a byte-valued DHCPv6 option */
189
+#define DHCPV6_BYTE( value ) DHCPV6_OPTION ( value )
190
+
191
+/** Construct a word-valued DHCPv6 option */
192
+#define DHCPV6_WORD( value ) DHCPV6_OPTION ( ( ( (value) >> 8 ) & 0xff ), \
193
+					     ( ( (value) >> 0 ) & 0xff ) )
194
+/** Construct a dword-valued DHCPv6 option */
195
+#define DHCPV6_DWORD( value ) DHCPV6_OPTION ( ( ( (value) >> 24 ) & 0xff ), \
196
+					      ( ( (value) >> 16 ) & 0xff ), \
197
+					      ( ( (value) >>  8 ) & 0xff ), \
198
+					      ( ( (value) >>  0 ) & 0xff ) )
199
+
167 200
 /**
168 201
  * Any DHCPv6 option
169 202
  *

+ 19
- 17
src/net/udp/dhcpv6.c View File

@@ -40,6 +40,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
40 40
 #include <ipxe/crc32.h>
41 41
 #include <ipxe/errortab.h>
42 42
 #include <ipxe/ipv6.h>
43
+#include <ipxe/dhcp_arch.h>
43 44
 #include <ipxe/dhcpv6.h>
44 45
 
45 46
 /** @file
@@ -364,10 +365,17 @@ static int dhcpv6_register ( struct dhcpv6_option_list *options,
364 365
  *
365 366
  */
366 367
 
367
-/** Options to be requested */
368
-static uint16_t dhcpv6_requested_options[] = {
369
-	htons ( DHCPV6_DNS_SERVERS ), htons ( DHCPV6_DOMAIN_LIST ),
370
-	htons ( DHCPV6_BOOTFILE_URL ), htons ( DHCPV6_BOOTFILE_PARAM ),
368
+/** Raw option data for options common to all DHCPv6 requests */
369
+static uint8_t dhcpv6_request_options_data[] = {
370
+	DHCPV6_CODE ( DHCPV6_OPTION_REQUEST ),
371
+	DHCPV6_OPTION ( DHCPV6_CODE ( DHCPV6_DNS_SERVERS ),
372
+			DHCPV6_CODE ( DHCPV6_DOMAIN_LIST ),
373
+			DHCPV6_CODE ( DHCPV6_BOOTFILE_URL ),
374
+			DHCPV6_CODE ( DHCPV6_BOOTFILE_PARAM ) ),
375
+	DHCPV6_CODE ( DHCPV6_CLIENT_ARCHITECTURE ),
376
+	DHCPV6_WORD ( DHCP_ARCH_CLIENT_ARCHITECTURE ),
377
+	DHCPV6_CODE ( DHCPV6_CLIENT_NDI ),
378
+	DHCPV6_OPTION ( DHCP_ARCH_CLIENT_NDI )
371 379
 };
372 380
 
373 381
 /**
@@ -565,15 +573,14 @@ static int dhcpv6_tx ( struct dhcpv6_session *dhcpv6 ) {
565 573
 	struct dhcpv6_duid_option *server_id;
566 574
 	struct dhcpv6_ia_na_option *ia_na;
567 575
 	struct dhcpv6_iaaddr_option *iaaddr;
568
-	struct dhcpv6_option_request_option *option_request;
569 576
 	struct dhcpv6_user_class_option *user_class;
570 577
 	struct dhcpv6_elapsed_time_option *elapsed;
571 578
 	struct dhcpv6_header *dhcphdr;
572 579
 	struct io_buffer *iobuf;
580
+	void *options;
573 581
 	size_t client_id_len;
574 582
 	size_t server_id_len;
575 583
 	size_t ia_na_len;
576
-	size_t option_request_len;
577 584
 	size_t user_class_string_len;
578 585
 	size_t user_class_len;
579 586
 	size_t elapsed_len;
@@ -592,16 +599,14 @@ static int dhcpv6_tx ( struct dhcpv6_session *dhcpv6 ) {
592 599
 	} else {
593 600
 		ia_na_len = 0;
594 601
 	}
595
-	option_request_len = ( sizeof ( *option_request ) +
596
-			       sizeof ( dhcpv6_requested_options ) );
597 602
 	user_class_string_len = dhcpv6_user_class ( NULL, 0 );
598 603
 	user_class_len = ( sizeof ( *user_class ) +
599 604
 			   sizeof ( user_class->user_class[0] ) +
600 605
 			   user_class_string_len );
601 606
 	elapsed_len = sizeof ( *elapsed );
602 607
 	total_len = ( sizeof ( *dhcphdr ) + client_id_len + server_id_len +
603
-		      ia_na_len + option_request_len + user_class_len +
604
-		      elapsed_len );
608
+		      ia_na_len + sizeof ( dhcpv6_request_options_data ) +
609
+		      user_class_len + elapsed_len );
605 610
 
606 611
 	/* Allocate packet */
607 612
 	iobuf = xfer_alloc_iob ( &dhcpv6->xfer, total_len );
@@ -652,13 +657,10 @@ static int dhcpv6_tx ( struct dhcpv6_session *dhcpv6 ) {
652 657
 		}
653 658
 	}
654 659
 
655
-	/* Construct option request */
656
-	option_request = iob_put ( iobuf, option_request_len );
657
-	option_request->header.code = htons ( DHCPV6_OPTION_REQUEST );
658
-	option_request->header.len = htons ( option_request_len -
659
-					     sizeof ( option_request->header ));
660
-	memcpy ( option_request->requested, dhcpv6_requested_options,
661
-		 sizeof ( dhcpv6_requested_options ) );
660
+	/* Construct fixed request options */
661
+	options = iob_put ( iobuf, sizeof ( dhcpv6_request_options_data ) );
662
+	memcpy ( options, dhcpv6_request_options_data,
663
+		 sizeof ( dhcpv6_request_options_data ) );
662 664
 
663 665
 	/* Construct user class */
664 666
 	user_class = iob_put ( iobuf, user_class_len );

Loading…
Cancel
Save