diff --git a/automatic.c b/automatic.c index ff9c359..54ed411 100644 --- a/automatic.c +++ b/automatic.c @@ -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) { diff --git a/automatic.h b/automatic.h index 4b58c0e..f1b8ff4 100644 --- a/automatic.h +++ b/automatic.h @@ -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); diff --git a/dhcp.c b/dhcp.c index a543dc7..c6a9a27 100644 --- a/dhcp.c +++ b/dhcp.c @@ -45,6 +45,7 @@ #include #include +#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);