dhcp.c: Provide an option to omit the vendor class

Some obsolete DHCP implementations in specialized network hardware
(Cisco, we're looking at you) discard DHCP messages from a client
attempting to reconfigure itself and providing a different vendor class
identifier the second time — much like a network-booting system.

To cope with that, propagator will not send a vendor class identifier
if `dhcp-send-vendor-id:off' is specified as part of its "automatic"
parameters on the kernel command line.
Feel free to use any boolean value: yes/no, true/false, on/off.
The default behaviour is "yes".
This commit is contained in:
Arseny Maslennikov 2018-06-06 19:42:53 +03:00
parent 41519b564d
commit dfa3713d0f
3 changed files with 34 additions and 7 deletions

View File

@ -84,6 +84,26 @@ char * get_auto_value(char * auto_param)
return value_not_bound;
}
int auto_parse_boolean(const char *v) {
/* assert(v); */
if (streq(v, "1") ||
streq(v, "yes") ||
streq(v, "true") ||
streq(v, "on") ||
streq(v, "y") ||
streq(v, "t"))
return 1;
else if (streq(v, "0") ||
streq(v, "no") ||
streq(v, "false") ||
streq(v, "off") ||
streq(v, "n") ||
streq(v, "f"))
return 0;
return -1;
}
enum return_type ask_from_list_auto(char *msg, char ** elems, char ** choice, char * auto_param, char ** elems_auto)
{

View File

@ -25,6 +25,7 @@
void grab_automatic_params(char * line);
char * get_auto_value(char * auto_param);
int auto_parse_boolean(const char *v);
enum return_type ask_from_list_auto(char *msg, char ** elems, char ** choice, char * auto_param, char ** elems_auto);
enum return_type ask_from_list_comments_auto(char *msg, char ** elems, char ** elems_comments, char ** choice, char * auto_param, char ** elems_auto);

20
dhcp.c
View File

@ -45,6 +45,7 @@
#include <fcntl.h>
#include <sys/poll.h>
#include "automatic.h"
#include "stage1.h"
#include "log.h"
#include "network.h"
@ -550,6 +551,7 @@ enum return_type perform_dhcp(struct interface_info * intf)
unsigned char messageType;
unsigned int lease;
short aShort;
int send_vendor_id;
int num_options;
char requested_options[50];
@ -560,7 +562,9 @@ enum return_type perform_dhcp(struct interface_info * intf)
}
*/
make_vendor_class_id();
send_vendor_id = auto_parse_boolean(get_auto_value("dhcp-send-vendor-id"));
if (send_vendor_id)
make_vendor_class_id();
s = socket(AF_INET, SOCK_DGRAM, 0);
if (s < 0) {
@ -594,9 +598,10 @@ enum return_type perform_dhcp(struct interface_info * intf)
broadcast_addr.sin_port = htons(BOOTP_SERVER_PORT); /* bootp server */
memset(&broadcast_addr.sin_addr, 0xff, sizeof(broadcast_addr.sin_addr)); /* broadcast */
add_vendor_code(&breq, DHCP_OPTION_VENDORCLASS,
strlen(vendor_class_id),
vendor_class_id);
if (send_vendor_id)
add_vendor_code(&breq, DHCP_OPTION_VENDORCLASS,
strlen(vendor_class_id),
vendor_class_id);
log_message("DHCP: sending DISCOVER");
@ -624,9 +629,10 @@ enum return_type perform_dhcp(struct interface_info * intf)
add_vendor_code(&breq, DHCP_OPTION_SERVER, 4, &server_addr.sin_addr);
add_vendor_code(&breq, DHCP_OPTION_REQADDR, 4, &bresp.yiaddr);
add_vendor_code(&breq, DHCP_OPTION_VENDORCLASS,
strlen(vendor_class_id),
vendor_class_id);
if (send_vendor_id)
add_vendor_code(&breq, DHCP_OPTION_VENDORCLASS,
strlen(vendor_class_id),
vendor_class_id);
aShort = ntohs(sizeof(struct bootp_request));
add_vendor_code(&breq, DHCP_OPTION_MAXSIZE, 2, &aShort);