diff options
Diffstat (limited to 'networking/udhcp/common.c')
-rw-r--r-- | networking/udhcp/common.c | 118 |
1 files changed, 70 insertions, 48 deletions
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index fbf9c6878..e5fd74f91 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c | |||
@@ -65,6 +65,7 @@ const struct dhcp_optflag dhcp_optflags[] = { | |||
65 | #endif | 65 | #endif |
66 | { OPTION_STRING , 0xd1 }, /* DHCP_PXE_CONF_FILE */ | 66 | { OPTION_STRING , 0xd1 }, /* DHCP_PXE_CONF_FILE */ |
67 | { OPTION_STRING , 0xd2 }, /* DHCP_PXE_PATH_PREFIX */ | 67 | { OPTION_STRING , 0xd2 }, /* DHCP_PXE_PATH_PREFIX */ |
68 | { OPTION_U32 , 0xd3 }, /* DHCP_REBOOT_TIME */ | ||
68 | { OPTION_6RD , 0xd4 }, /* DHCP_6RD */ | 69 | { OPTION_6RD , 0xd4 }, /* DHCP_6RD */ |
69 | { OPTION_STATIC_ROUTES | OPTION_LIST , 0xf9 }, /* DHCP_MS_STATIC_ROUTES */ | 70 | { OPTION_STATIC_ROUTES | OPTION_LIST , 0xf9 }, /* DHCP_MS_STATIC_ROUTES */ |
70 | { OPTION_STRING , 0xfc }, /* DHCP_WPAD */ | 71 | { OPTION_STRING , 0xfc }, /* DHCP_WPAD */ |
@@ -92,50 +93,51 @@ const struct dhcp_optflag dhcp_optflags[] = { | |||
92 | */ | 93 | */ |
93 | /* Must match dhcp_optflags[] order */ | 94 | /* Must match dhcp_optflags[] order */ |
94 | const char dhcp_option_strings[] ALIGN1 = | 95 | const char dhcp_option_strings[] ALIGN1 = |
95 | "subnet" "\0" /* DHCP_SUBNET */ | 96 | "subnet" "\0" /* DHCP_SUBNET */ |
96 | "timezone" "\0" /* DHCP_TIME_OFFSET */ | 97 | "timezone" "\0" /* DHCP_TIME_OFFSET */ |
97 | "router" "\0" /* DHCP_ROUTER */ | 98 | "router" "\0" /* DHCP_ROUTER */ |
98 | // "timesrv" "\0" /* DHCP_TIME_SERVER */ | 99 | // "timesrv" "\0" /* DHCP_TIME_SERVER */ |
99 | // "namesrv" "\0" /* DHCP_NAME_SERVER */ | 100 | // "namesrv" "\0" /* DHCP_NAME_SERVER */ |
100 | "dns" "\0" /* DHCP_DNS_SERVER */ | 101 | "dns" "\0" /* DHCP_DNS_SERVER */ |
101 | // "logsrv" "\0" /* DHCP_LOG_SERVER */ | 102 | // "logsrv" "\0" /* DHCP_LOG_SERVER */ |
102 | // "cookiesrv" "\0" /* DHCP_COOKIE_SERVER */ | 103 | // "cookiesrv" "\0" /* DHCP_COOKIE_SERVER */ |
103 | "lprsrv" "\0" /* DHCP_LPR_SERVER */ | 104 | "lprsrv" "\0" /* DHCP_LPR_SERVER */ |
104 | "hostname" "\0" /* DHCP_HOST_NAME */ | 105 | "hostname" "\0" /* DHCP_HOST_NAME */ |
105 | "bootsize" "\0" /* DHCP_BOOT_SIZE */ | 106 | "bootsize" "\0" /* DHCP_BOOT_SIZE */ |
106 | "domain" "\0" /* DHCP_DOMAIN_NAME */ | 107 | "domain" "\0" /* DHCP_DOMAIN_NAME */ |
107 | "swapsrv" "\0" /* DHCP_SWAP_SERVER */ | 108 | "swapsrv" "\0" /* DHCP_SWAP_SERVER */ |
108 | "rootpath" "\0" /* DHCP_ROOT_PATH */ | 109 | "rootpath" "\0" /* DHCP_ROOT_PATH */ |
109 | "ipttl" "\0" /* DHCP_IP_TTL */ | 110 | "ipttl" "\0" /* DHCP_IP_TTL */ |
110 | "mtu" "\0" /* DHCP_MTU */ | 111 | "mtu" "\0" /* DHCP_MTU */ |
111 | "broadcast" "\0" /* DHCP_BROADCAST */ | 112 | "broadcast" "\0" /* DHCP_BROADCAST */ |
112 | "routes" "\0" /* DHCP_ROUTES */ | 113 | "routes" "\0" /* DHCP_ROUTES */ |
113 | "nisdomain" "\0" /* DHCP_NIS_DOMAIN */ | 114 | "nisdomain" "\0" /* DHCP_NIS_DOMAIN */ |
114 | "nissrv" "\0" /* DHCP_NIS_SERVER */ | 115 | "nissrv" "\0" /* DHCP_NIS_SERVER */ |
115 | "ntpsrv" "\0" /* DHCP_NTP_SERVER */ | 116 | "ntpsrv" "\0" /* DHCP_NTP_SERVER */ |
116 | "wins" "\0" /* DHCP_WINS_SERVER */ | 117 | "wins" "\0" /* DHCP_WINS_SERVER */ |
117 | "lease" "\0" /* DHCP_LEASE_TIME */ | 118 | "lease" "\0" /* DHCP_LEASE_TIME */ |
118 | "serverid" "\0" /* DHCP_SERVER_ID */ | 119 | "serverid" "\0" /* DHCP_SERVER_ID */ |
119 | "message" "\0" /* DHCP_ERR_MESSAGE */ | 120 | "message" "\0" /* DHCP_ERR_MESSAGE */ |
120 | "tftp" "\0" /* DHCP_TFTP_SERVER_NAME */ | 121 | "tftp" "\0" /* DHCP_TFTP_SERVER_NAME*/ |
121 | "bootfile" "\0" /* DHCP_BOOT_FILE */ | 122 | "bootfile" "\0" /* DHCP_BOOT_FILE */ |
122 | // "userclass" "\0" /* DHCP_USER_CLASS */ | 123 | // "userclass" "\0" /* DHCP_USER_CLASS */ |
123 | #if ENABLE_FEATURE_UDHCP_RFC3397 | 124 | #if ENABLE_FEATURE_UDHCP_RFC3397 |
124 | "search" "\0" /* DHCP_DOMAIN_SEARCH */ | 125 | "search" "\0" /* DHCP_DOMAIN_SEARCH */ |
125 | // doesn't work in udhcpd.conf since OPTION_SIP_SERVERS | 126 | // doesn't work in udhcpd.conf since OPTION_SIP_SERVERS |
126 | // is not handled yet by "string->option" conversion code: | 127 | // is not handled yet by "string->option" conversion code: |
127 | "sipsrv" "\0" /* DHCP_SIP_SERVERS */ | 128 | "sipsrv" "\0" /* DHCP_SIP_SERVERS */ |
128 | #endif | 129 | #endif |
129 | "staticroutes" "\0"/* DHCP_STATIC_ROUTES */ | 130 | "staticroutes" "\0" /* DHCP_STATIC_ROUTES */ |
130 | #if ENABLE_FEATURE_UDHCP_8021Q | 131 | #if ENABLE_FEATURE_UDHCP_8021Q |
131 | "vlanid" "\0" /* DHCP_VLAN_ID */ | 132 | "vlanid" "\0" /* DHCP_VLAN_ID */ |
132 | "vlanpriority" "\0"/* DHCP_VLAN_PRIORITY */ | 133 | "vlanpriority" "\0" /* DHCP_VLAN_PRIORITY */ |
133 | #endif | 134 | #endif |
134 | "pxeconffile" "\0" /* DHCP_PXE_CONF_FILE */ | 135 | "pxeconffile" "\0" /* DHCP_PXE_CONF_FILE */ |
135 | "pxepathprefix" "\0" /* DHCP_PXE_PATH_PREFIX */ | 136 | "pxepathprefix" "\0" /* DHCP_PXE_PATH_PREFIX */ |
136 | "ip6rd" "\0" /* DHCP_6RD */ | 137 | "reboottime" "\0" /* DHCP_REBOOT_TIME */ |
137 | "msstaticroutes""\0"/* DHCP_MS_STATIC_ROUTES */ | 138 | "ip6rd" "\0" /* DHCP_6RD */ |
138 | "wpad" "\0" /* DHCP_WPAD */ | 139 | "msstaticroutes" "\0" /* DHCP_MS_STATIC_ROUTES*/ |
140 | "wpad" "\0" /* DHCP_WPAD */ | ||
139 | ; | 141 | ; |
140 | #endif | 142 | #endif |
141 | 143 | ||
@@ -379,12 +381,18 @@ int FAST_FUNC udhcp_str2nip(const char *str, void *arg) | |||
379 | * and to parse udhcpd.conf's "opt OPTNAME OPTVAL" directives. | 381 | * and to parse udhcpd.conf's "opt OPTNAME OPTVAL" directives. |
380 | */ | 382 | */ |
381 | /* helper: add an option to the opt_list */ | 383 | /* helper: add an option to the opt_list */ |
384 | #if !ENABLE_UDHCPC6 | ||
385 | #define attach_option(opt_list, optflag, buffer, length, dhcpv6) \ | ||
386 | attach_option(opt_list, optflag, buffer, length) | ||
387 | #endif | ||
382 | static NOINLINE void attach_option( | 388 | static NOINLINE void attach_option( |
383 | struct option_set **opt_list, | 389 | struct option_set **opt_list, |
384 | const struct dhcp_optflag *optflag, | 390 | const struct dhcp_optflag *optflag, |
385 | char *buffer, | 391 | char *buffer, |
386 | int length) | 392 | int length, |
393 | bool dhcpv6) | ||
387 | { | 394 | { |
395 | IF_NOT_UDHCPC6(bool dhcpv6 = 0;) | ||
388 | struct option_set *existing; | 396 | struct option_set *existing; |
389 | char *allocated = NULL; | 397 | char *allocated = NULL; |
390 | 398 | ||
@@ -410,10 +418,21 @@ static NOINLINE void attach_option( | |||
410 | /* make a new option */ | 418 | /* make a new option */ |
411 | log2("attaching option %02x to list", optflag->code); | 419 | log2("attaching option %02x to list", optflag->code); |
412 | new = xmalloc(sizeof(*new)); | 420 | new = xmalloc(sizeof(*new)); |
413 | new->data = xmalloc(length + OPT_DATA); | 421 | if (!dhcpv6) { |
414 | new->data[OPT_CODE] = optflag->code; | 422 | new->data = xmalloc(length + OPT_DATA); |
415 | new->data[OPT_LEN] = length; | 423 | new->data[OPT_CODE] = optflag->code; |
416 | memcpy(new->data + OPT_DATA, (allocated ? allocated : buffer), length); | 424 | new->data[OPT_LEN] = length; |
425 | memcpy(new->data + OPT_DATA, (allocated ? allocated : buffer), | ||
426 | length); | ||
427 | } else { | ||
428 | new->data = xmalloc(length + D6_OPT_DATA); | ||
429 | new->data[D6_OPT_CODE] = optflag->code >> 8; | ||
430 | new->data[D6_OPT_CODE + 1] = optflag->code & 0xff; | ||
431 | new->data[D6_OPT_LEN] = length >> 8; | ||
432 | new->data[D6_OPT_LEN + 1] = length & 0xff; | ||
433 | memcpy(new->data + D6_OPT_DATA, (allocated ? allocated : buffer), | ||
434 | length); | ||
435 | } | ||
417 | 436 | ||
418 | curr = opt_list; | 437 | curr = opt_list; |
419 | while (*curr && (*curr)->data[OPT_CODE] < optflag->code) | 438 | while (*curr && (*curr)->data[OPT_CODE] < optflag->code) |
@@ -450,7 +469,9 @@ static NOINLINE void attach_option( | |||
450 | free(allocated); | 469 | free(allocated); |
451 | } | 470 | } |
452 | 471 | ||
453 | int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg, const struct dhcp_optflag *optflags, const char *option_strings) | 472 | int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg, |
473 | const struct dhcp_optflag *optflags, const char *option_strings, | ||
474 | bool dhcpv6) | ||
454 | { | 475 | { |
455 | struct option_set **opt_list = arg; | 476 | struct option_set **opt_list = arg; |
456 | char *opt; | 477 | char *opt; |
@@ -489,9 +510,10 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg, const struct dh | |||
489 | int length; | 510 | int length; |
490 | char *val; | 511 | char *val; |
491 | 512 | ||
492 | if (optflag->flags == OPTION_BIN) | 513 | if (optflag->flags == OPTION_BIN) { |
493 | val = trim(strtok(NULL, "")); /* do not split "'q w e'" */ | 514 | val = strtok(NULL, ""); /* do not split "'q w e'" */ |
494 | else | 515 | trim(val); |
516 | } else | ||
495 | val = strtok(NULL, ", \t"); | 517 | val = strtok(NULL, ", \t"); |
496 | if (!val) | 518 | if (!val) |
497 | break; | 519 | break; |
@@ -601,7 +623,7 @@ case_OPTION_STRING: | |||
601 | } | 623 | } |
602 | 624 | ||
603 | if (retval) | 625 | if (retval) |
604 | attach_option(opt_list, optflag, opt, length); | 626 | attach_option(opt_list, optflag, opt, length, dhcpv6); |
605 | } while (retval && (optflag->flags & OPTION_LIST)); | 627 | } while (retval && (optflag->flags & OPTION_LIST)); |
606 | 628 | ||
607 | return retval; | 629 | return retval; |