Kaynağa Gözat

[dhcp] Allow vendor class to be changed in DHCP requests

Allow the DHCPv4 vendor class to be specified via the "vendor-class"
setting.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 7 yıl önce
ebeveyn
işleme
de2c6fa240
3 değiştirilmiş dosya ile 34 ekleme ve 11 silme
  1. 9
    0
      src/core/settings.c
  2. 2
    0
      src/include/ipxe/settings.h
  3. 23
    11
      src/net/udp/dhcp.c

+ 9
- 0
src/core/settings.c Dosyayı Görüntüle

@@ -2429,6 +2429,15 @@ const struct setting user_class_setting __setting ( SETTING_HOST_EXTRA,
2429 2429
 	.type = &setting_type_string,
2430 2430
 };
2431 2431
 
2432
+/** DHCP vendor class setting */
2433
+const struct setting vendor_class_setting __setting ( SETTING_HOST_EXTRA,
2434
+						      vendor-class ) = {
2435
+	.name = "vendor-class",
2436
+	.description = "DHCP vendor class",
2437
+	.tag = DHCP_VENDOR_CLASS_ID,
2438
+	.type = &setting_type_string,
2439
+};
2440
+
2432 2441
 /******************************************************************************
2433 2442
  *
2434 2443
  * Built-in settings block

+ 2
- 0
src/include/ipxe/settings.h Dosyayı Görüntüle

@@ -468,6 +468,8 @@ busid_setting __setting ( SETTING_NETDEV, busid );
468 468
 extern const struct setting
469 469
 user_class_setting __setting ( SETTING_HOST_EXTRA, user-class );
470 470
 extern const struct setting
471
+vendor_class_setting __setting ( SETTING_HOST_EXTRA, vendor-class );
472
+extern const struct setting
471 473
 manufacturer_setting __setting ( SETTING_HOST_EXTRA, manufacturer );
472 474
 extern const struct setting
473 475
 product_setting __setting ( SETTING_HOST_EXTRA, product );

+ 23
- 11
src/net/udp/dhcp.c Dosyayı Görüntüle

@@ -99,6 +99,12 @@ static uint8_t dhcp_request_options_data[] = {
99 99
 	DHCP_END
100 100
 };
101 101
 
102
+/** Settings copied in to all DHCP requests */
103
+static const struct setting * dhcp_request_settings[] = {
104
+	&user_class_setting,
105
+	&vendor_class_setting,
106
+};
107
+
102 108
 /** DHCP server address setting */
103 109
 const struct setting dhcp_server_setting __setting ( SETTING_MISC,
104 110
 						     dhcp-server ) = {
@@ -975,11 +981,13 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
975 981
 	struct dhcp_netdev_desc dhcp_desc;
976 982
 	struct dhcp_client_id client_id;
977 983
 	struct dhcp_client_uuid client_uuid;
984
+	const struct setting *setting;
978 985
 	uint8_t *dhcp_features;
979 986
 	size_t dhcp_features_len;
980 987
 	size_t ll_addr_len;
981
-	void *user_class;
988
+	void *raw;
982 989
 	ssize_t len;
990
+	unsigned int i;
983 991
 	int rc;
984 992
 
985 993
 	/* Create DHCP packet */
@@ -1047,19 +1055,23 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
1047 1055
 		}
1048 1056
 	}
1049 1057
 
1050
-	/* Add user class, if we have one. */
1051
-	if ( ( len = fetch_raw_setting_copy ( NULL, &user_class_setting,
1052
-					      &user_class ) ) >= 0 ) {
1053
-		if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_USER_CLASS_ID,
1054
-					    user_class, len ) ) != 0 ) {
1055
-			DBG ( "DHCP could not set user class: %s\n",
1056
-			      strerror ( rc ) );
1057
-			goto err_store_user_class;
1058
+	/* Add request settings, if applicable */
1059
+	for ( i = 0 ; i < ( sizeof ( dhcp_request_settings ) /
1060
+			    sizeof ( dhcp_request_settings[0] ) ) ; i++ ) {
1061
+		setting = dhcp_request_settings[i];
1062
+		if ( ( len = fetch_raw_setting_copy ( NULL, setting,
1063
+						      &raw ) ) >= 0 ) {
1064
+			rc = dhcppkt_store ( dhcppkt, setting->tag, raw, len );
1065
+			free ( raw );
1066
+			if ( rc != 0 ) {
1067
+				DBG ( "DHCP could not set %s: %s\n",
1068
+				      setting->name, strerror ( rc ) );
1069
+				goto err_store_raw;
1070
+			}
1058 1071
 		}
1059 1072
 	}
1060 1073
 
1061
- err_store_user_class:
1062
-	free ( user_class );
1074
+ err_store_raw:
1063 1075
  err_store_client_uuid:
1064 1076
  err_store_client_id:
1065 1077
  err_store_busid:

Loading…
İptal
Kaydet