david/ipxe
david
/
ipxe
Archived
1
0
Fork 0

[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>
This commit is contained in:
Michael Brown 2017-03-20 13:58:59 +02:00
parent 7692a8ff02
commit de2c6fa240
3 changed files with 34 additions and 11 deletions

View File

@ -2429,6 +2429,15 @@ const struct setting user_class_setting __setting ( SETTING_HOST_EXTRA,
.type = &setting_type_string, .type = &setting_type_string,
}; };
/** DHCP vendor class setting */
const struct setting vendor_class_setting __setting ( SETTING_HOST_EXTRA,
vendor-class ) = {
.name = "vendor-class",
.description = "DHCP vendor class",
.tag = DHCP_VENDOR_CLASS_ID,
.type = &setting_type_string,
};
/****************************************************************************** /******************************************************************************
* *
* Built-in settings block * Built-in settings block

View File

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

View File

@ -99,6 +99,12 @@ static uint8_t dhcp_request_options_data[] = {
DHCP_END DHCP_END
}; };
/** Settings copied in to all DHCP requests */
static const struct setting * dhcp_request_settings[] = {
&user_class_setting,
&vendor_class_setting,
};
/** DHCP server address setting */ /** DHCP server address setting */
const struct setting dhcp_server_setting __setting ( SETTING_MISC, const struct setting dhcp_server_setting __setting ( SETTING_MISC,
dhcp-server ) = { dhcp-server ) = {
@ -975,11 +981,13 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
struct dhcp_netdev_desc dhcp_desc; struct dhcp_netdev_desc dhcp_desc;
struct dhcp_client_id client_id; struct dhcp_client_id client_id;
struct dhcp_client_uuid client_uuid; struct dhcp_client_uuid client_uuid;
const struct setting *setting;
uint8_t *dhcp_features; uint8_t *dhcp_features;
size_t dhcp_features_len; size_t dhcp_features_len;
size_t ll_addr_len; size_t ll_addr_len;
void *user_class; void *raw;
ssize_t len; ssize_t len;
unsigned int i;
int rc; int rc;
/* Create DHCP packet */ /* Create DHCP packet */
@ -1047,19 +1055,23 @@ int dhcp_create_request ( struct dhcp_packet *dhcppkt,
} }
} }
/* Add user class, if we have one. */ /* Add request settings, if applicable */
if ( ( len = fetch_raw_setting_copy ( NULL, &user_class_setting, for ( i = 0 ; i < ( sizeof ( dhcp_request_settings ) /
&user_class ) ) >= 0 ) { sizeof ( dhcp_request_settings[0] ) ) ; i++ ) {
if ( ( rc = dhcppkt_store ( dhcppkt, DHCP_USER_CLASS_ID, setting = dhcp_request_settings[i];
user_class, len ) ) != 0 ) { if ( ( len = fetch_raw_setting_copy ( NULL, setting,
DBG ( "DHCP could not set user class: %s\n", &raw ) ) >= 0 ) {
strerror ( rc ) ); rc = dhcppkt_store ( dhcppkt, setting->tag, raw, len );
goto err_store_user_class; free ( raw );
if ( rc != 0 ) {
DBG ( "DHCP could not set %s: %s\n",
setting->name, strerror ( rc ) );
goto err_store_raw;
}
} }
} }
err_store_user_class: err_store_raw:
free ( user_class );
err_store_client_uuid: err_store_client_uuid:
err_store_client_id: err_store_client_id:
err_store_busid: err_store_busid: