瀏覽代碼

[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 9 年之前
父節點
當前提交
fda8916c83
共有 2 個文件被更改,包括 52 次插入17 次删除
  1. 33
    0
      src/include/ipxe/dhcpv6.h
  2. 19
    17
      src/net/udp/dhcpv6.c

+ 33
- 0
src/include/ipxe/dhcpv6.h 查看文件

157
 /** DHCPv6 bootfile parameters option */
157
 /** DHCPv6 bootfile parameters option */
158
 #define DHCPV6_BOOTFILE_PARAM 60
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
 /** DHCPv6 syslog server option
166
 /** DHCPv6 syslog server option
161
  *
167
  *
162
  * This option code has not yet been assigned by IANA.  Please update
168
  * This option code has not yet been assigned by IANA.  Please update
164
  */
170
  */
165
 #define DHCPV6_LOG_SERVERS 0xffffffffUL
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
  * Any DHCPv6 option
201
  * Any DHCPv6 option
169
  *
202
  *

+ 19
- 17
src/net/udp/dhcpv6.c 查看文件

40
 #include <ipxe/crc32.h>
40
 #include <ipxe/crc32.h>
41
 #include <ipxe/errortab.h>
41
 #include <ipxe/errortab.h>
42
 #include <ipxe/ipv6.h>
42
 #include <ipxe/ipv6.h>
43
+#include <ipxe/dhcp_arch.h>
43
 #include <ipxe/dhcpv6.h>
44
 #include <ipxe/dhcpv6.h>
44
 
45
 
45
 /** @file
46
 /** @file
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
 	struct dhcpv6_duid_option *server_id;
573
 	struct dhcpv6_duid_option *server_id;
566
 	struct dhcpv6_ia_na_option *ia_na;
574
 	struct dhcpv6_ia_na_option *ia_na;
567
 	struct dhcpv6_iaaddr_option *iaaddr;
575
 	struct dhcpv6_iaaddr_option *iaaddr;
568
-	struct dhcpv6_option_request_option *option_request;
569
 	struct dhcpv6_user_class_option *user_class;
576
 	struct dhcpv6_user_class_option *user_class;
570
 	struct dhcpv6_elapsed_time_option *elapsed;
577
 	struct dhcpv6_elapsed_time_option *elapsed;
571
 	struct dhcpv6_header *dhcphdr;
578
 	struct dhcpv6_header *dhcphdr;
572
 	struct io_buffer *iobuf;
579
 	struct io_buffer *iobuf;
580
+	void *options;
573
 	size_t client_id_len;
581
 	size_t client_id_len;
574
 	size_t server_id_len;
582
 	size_t server_id_len;
575
 	size_t ia_na_len;
583
 	size_t ia_na_len;
576
-	size_t option_request_len;
577
 	size_t user_class_string_len;
584
 	size_t user_class_string_len;
578
 	size_t user_class_len;
585
 	size_t user_class_len;
579
 	size_t elapsed_len;
586
 	size_t elapsed_len;
592
 	} else {
599
 	} else {
593
 		ia_na_len = 0;
600
 		ia_na_len = 0;
594
 	}
601
 	}
595
-	option_request_len = ( sizeof ( *option_request ) +
596
-			       sizeof ( dhcpv6_requested_options ) );
597
 	user_class_string_len = dhcpv6_user_class ( NULL, 0 );
602
 	user_class_string_len = dhcpv6_user_class ( NULL, 0 );
598
 	user_class_len = ( sizeof ( *user_class ) +
603
 	user_class_len = ( sizeof ( *user_class ) +
599
 			   sizeof ( user_class->user_class[0] ) +
604
 			   sizeof ( user_class->user_class[0] ) +
600
 			   user_class_string_len );
605
 			   user_class_string_len );
601
 	elapsed_len = sizeof ( *elapsed );
606
 	elapsed_len = sizeof ( *elapsed );
602
 	total_len = ( sizeof ( *dhcphdr ) + client_id_len + server_id_len +
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
 	/* Allocate packet */
611
 	/* Allocate packet */
607
 	iobuf = xfer_alloc_iob ( &dhcpv6->xfer, total_len );
612
 	iobuf = xfer_alloc_iob ( &dhcpv6->xfer, total_len );
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
 	/* Construct user class */
665
 	/* Construct user class */
664
 	user_class = iob_put ( iobuf, user_class_len );
666
 	user_class = iob_put ( iobuf, user_class_len );

Loading…
取消
儲存