Browse Source

[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 years ago
parent
commit
de2c6fa240
3 changed files with 34 additions and 11 deletions
  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 View File

2429
 	.type = &setting_type_string,
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
  * Built-in settings block
2443
  * Built-in settings block

+ 2
- 0
src/include/ipxe/settings.h View File

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

+ 23
- 11
src/net/udp/dhcp.c View File

99
 	DHCP_END
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
 /** DHCP server address setting */
108
 /** DHCP server address setting */
103
 const struct setting dhcp_server_setting __setting ( SETTING_MISC,
109
 const struct setting dhcp_server_setting __setting ( SETTING_MISC,
104
 						     dhcp-server ) = {
110
 						     dhcp-server ) = {
975
 	struct dhcp_netdev_desc dhcp_desc;
981
 	struct dhcp_netdev_desc dhcp_desc;
976
 	struct dhcp_client_id client_id;
982
 	struct dhcp_client_id client_id;
977
 	struct dhcp_client_uuid client_uuid;
983
 	struct dhcp_client_uuid client_uuid;
984
+	const struct setting *setting;
978
 	uint8_t *dhcp_features;
985
 	uint8_t *dhcp_features;
979
 	size_t dhcp_features_len;
986
 	size_t dhcp_features_len;
980
 	size_t ll_addr_len;
987
 	size_t ll_addr_len;
981
-	void *user_class;
988
+	void *raw;
982
 	ssize_t len;
989
 	ssize_t len;
990
+	unsigned int i;
983
 	int rc;
991
 	int rc;
984
 
992
 
985
 	/* Create DHCP packet */
993
 	/* Create DHCP packet */
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
  err_store_client_uuid:
1075
  err_store_client_uuid:
1064
  err_store_client_id:
1076
  err_store_client_id:
1065
  err_store_busid:
1077
  err_store_busid:

Loading…
Cancel
Save