aboutsummaryrefslogtreecommitdiff
path: root/networking/udhcp/common.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/udhcp/common.c')
-rw-r--r--networking/udhcp/common.c35
1 files changed, 23 insertions, 12 deletions
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c
index adbcd77ac..77d7fd5d4 100644
--- a/networking/udhcp/common.c
+++ b/networking/udhcp/common.c
@@ -50,7 +50,8 @@ const struct dhcp_option dhcp_options[] = {
50//TODO: not a string, but a set of LASCII strings: 50//TODO: not a string, but a set of LASCII strings:
51// { OPTION_STRING , 0x4D }, /* DHCP_USER_CLASS */ 51// { OPTION_STRING , 0x4D }, /* DHCP_USER_CLASS */
52#if ENABLE_FEATURE_UDHCP_RFC3397 52#if ENABLE_FEATURE_UDHCP_RFC3397
53 { OPTION_STR1035 | OPTION_LIST , 0x77 }, /* DHCP_DOMAIN_SEARCH */ 53 { OPTION_DNS_STRING | OPTION_LIST , 0x77 }, /* DHCP_DOMAIN_SEARCH */
54 { OPTION_SIP_SERVERS , 0x78 }, /* DHCP_SIP_SERVERS */
54#endif 55#endif
55 { OPTION_STATIC_ROUTES , 0x79 }, /* DHCP_STATIC_ROUTES */ 56 { OPTION_STATIC_ROUTES , 0x79 }, /* DHCP_STATIC_ROUTES */
56 { OPTION_STRING , 0xfc }, /* DHCP_WPAD */ 57 { OPTION_STRING , 0xfc }, /* DHCP_WPAD */
@@ -106,22 +107,32 @@ const char dhcp_option_strings[] ALIGN1 =
106// "userclass" "\0" /* DHCP_USER_CLASS */ 107// "userclass" "\0" /* DHCP_USER_CLASS */
107#if ENABLE_FEATURE_UDHCP_RFC3397 108#if ENABLE_FEATURE_UDHCP_RFC3397
108 "search" "\0" /* DHCP_DOMAIN_SEARCH */ 109 "search" "\0" /* DHCP_DOMAIN_SEARCH */
110// doesn't work in udhcpd.conf since OPTION_SIP_SERVERS
111// is not handled yet by "string->option" conversion code:
112 "sipservers" "\0" /* DHCP_SIP_SERVERS */
109#endif 113#endif
110// "staticroutes" is only used to set udhcpc environment, it doesn't work 114// doesn't work in udhcpd.conf since OPTION_STATIC_ROUTES
111// in udhcpd.conf since OPTION_STATIC_ROUTES is not handled yet 115// is not handled yet by "string->option" conversion code:
112// by "string->option" conversion code: 116 "staticroutes" "\0"/* DHCP_STATIC_ROUTES */
113 "staticroutes" "\0"/* DHCP_STATIC_ROUTES */ 117 "wpad" "\0" /* DHCP_WPAD */
114 "wpad" "\0" /* DHCP_WPAD */
115 ; 118 ;
116 119
117/* Lengths of the different option types */ 120/* Lengths of the option types in binary form.
121 * Used by:
122 * udhcp_str2optset: to determine how many bytes to allocate.
123 * xmalloc_optname_optval: to estimate string length
124 * from binary option length: (option[LEN] / dhcp_option_lengths[opt_type])
125 * is the number of elements, multiply in by one element's string width
126 * (len_of_option_as_string[opt_type]) and you know how wide string you need.
127 */
118const uint8_t dhcp_option_lengths[] ALIGN1 = { 128const uint8_t dhcp_option_lengths[] ALIGN1 = {
119 [OPTION_IP] = 4, 129 [OPTION_IP] = 4,
120 [OPTION_IP_PAIR] = 8, 130 [OPTION_IP_PAIR] = 8,
121// [OPTION_BOOLEAN] = 1, 131// [OPTION_BOOLEAN] = 1,
122 [OPTION_STRING] = 1, 132 [OPTION_STRING] = 1, /* ignored by udhcp_str2optset */
123#if ENABLE_FEATURE_UDHCP_RFC3397 133#if ENABLE_FEATURE_UDHCP_RFC3397
124 [OPTION_STR1035] = 1, 134 [OPTION_DNS_STRING] = 1, /* ignored by both udhcp_str2optset and xmalloc_optname_optval */
135 [OPTION_SIP_SERVERS] = 1,
125#endif 136#endif
126 [OPTION_U8] = 1, 137 [OPTION_U8] = 1,
127 [OPTION_U16] = 2, 138 [OPTION_U16] = 2,
@@ -332,7 +343,7 @@ static NOINLINE void attach_option(
332 if (!existing) { 343 if (!existing) {
333 log2("Attaching option %02x to list", option->code); 344 log2("Attaching option %02x to list", option->code);
334#if ENABLE_FEATURE_UDHCP_RFC3397 345#if ENABLE_FEATURE_UDHCP_RFC3397
335 if ((option->flags & OPTION_TYPE_MASK) == OPTION_STR1035) { 346 if ((option->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) {
336 /* reuse buffer and length for RFC1035-formatted string */ 347 /* reuse buffer and length for RFC1035-formatted string */
337 allocated = buffer = (char *)dname_enc(NULL, 0, buffer, &length); 348 allocated = buffer = (char *)dname_enc(NULL, 0, buffer, &length);
338 } 349 }
@@ -360,7 +371,7 @@ static NOINLINE void attach_option(
360 log1("Attaching option %02x to existing member of list", option->code); 371 log1("Attaching option %02x to existing member of list", option->code);
361 old_len = existing->data[OPT_LEN]; 372 old_len = existing->data[OPT_LEN];
362#if ENABLE_FEATURE_UDHCP_RFC3397 373#if ENABLE_FEATURE_UDHCP_RFC3397
363 if ((option->flags & OPTION_TYPE_MASK) == OPTION_STR1035) { 374 if ((option->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) {
364 /* reuse buffer and length for RFC1035-formatted string */ 375 /* reuse buffer and length for RFC1035-formatted string */
365 allocated = buffer = (char *)dname_enc(existing->data + OPT_DATA, old_len, buffer, &length); 376 allocated = buffer = (char *)dname_enc(existing->data + OPT_DATA, old_len, buffer, &length);
366 } 377 }
@@ -426,7 +437,7 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg)
426 break; 437 break;
427 case OPTION_STRING: 438 case OPTION_STRING:
428#if ENABLE_FEATURE_UDHCP_RFC3397 439#if ENABLE_FEATURE_UDHCP_RFC3397
429 case OPTION_STR1035: 440 case OPTION_DNS_STRING:
430#endif 441#endif
431 length = strnlen(val, 254); 442 length = strnlen(val, 254);
432 if (length > 0) { 443 if (length > 0) {