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; 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) 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); void grab_automatic_params(char * line);
char * get_auto_value(char * auto_param); 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_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); enum return_type ask_from_list_comments_auto(char *msg, char ** elems, char ** elems_comments, char ** choice, char * auto_param, char ** elems_auto);

6
dhcp.c
View File

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