diff options
-rw-r--r-- | networking/udhcp/common.h | 2 | ||||
-rw-r--r-- | networking/udhcp/dhcpc.c | 41 |
2 files changed, 16 insertions, 27 deletions
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index 73f860a77..6214db06a 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h | |||
@@ -78,7 +78,7 @@ struct BUG_bad_sizeof_struct_ip_udp_dhcp_packet { | |||
78 | /*** Options ***/ | 78 | /*** Options ***/ |
79 | 79 | ||
80 | enum { | 80 | enum { |
81 | OPTION_IP = 1, | 81 | OPTION_IP = 0, |
82 | OPTION_IP_PAIR, | 82 | OPTION_IP_PAIR, |
83 | OPTION_STRING, | 83 | OPTION_STRING, |
84 | /* Opts of STRING_HOST type will be sanitized before they are passed | 84 | /* Opts of STRING_HOST type will be sanitized before they are passed |
diff --git a/networking/udhcp/dhcpc.c b/networking/udhcp/dhcpc.c index 6422181da..102178a4f 100644 --- a/networking/udhcp/dhcpc.c +++ b/networking/udhcp/dhcpc.c | |||
@@ -208,9 +208,8 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_ | |||
208 | case OPTION_IP: | 208 | case OPTION_IP: |
209 | case OPTION_IP_PAIR: | 209 | case OPTION_IP_PAIR: |
210 | dest += sprint_nip(dest, "", option); | 210 | dest += sprint_nip(dest, "", option); |
211 | if (type == OPTION_IP) | 211 | if (type == OPTION_IP_PAIR) |
212 | break; | 212 | dest += sprint_nip(dest, "/", option + 4); |
213 | dest += sprint_nip(dest, "/", option + 4); | ||
214 | break; | 213 | break; |
215 | // case OPTION_BOOLEAN: | 214 | // case OPTION_BOOLEAN: |
216 | // dest += sprintf(dest, *option ? "yes" : "no"); | 215 | // dest += sprintf(dest, *option ? "yes" : "no"); |
@@ -312,7 +311,7 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_ | |||
312 | * IPv4MaskLen <= 32, | 311 | * IPv4MaskLen <= 32, |
313 | * 6rdPrefixLen <= 128, | 312 | * 6rdPrefixLen <= 128, |
314 | * 6rdPrefixLen + (32 - IPv4MaskLen) <= 128 | 313 | * 6rdPrefixLen + (32 - IPv4MaskLen) <= 128 |
315 | * (2nd condition need no check - it follows from 1st and 3rd). | 314 | * (2nd condition needs no check - it follows from 1st and 3rd). |
316 | * Else, return envvar with empty value ("optname=") | 315 | * Else, return envvar with empty value ("optname=") |
317 | */ | 316 | */ |
318 | if (len >= (1 + 1 + 16 + 4) | 317 | if (len >= (1 + 1 + 16 + 4) |
@@ -326,17 +325,12 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_ | |||
326 | /* 6rdPrefix */ | 325 | /* 6rdPrefix */ |
327 | dest += sprint_nip6(dest, /* "", */ option); | 326 | dest += sprint_nip6(dest, /* "", */ option); |
328 | option += 16; | 327 | option += 16; |
329 | len -= 1 + 1 + 16 + 4; | 328 | len -= 1 + 1 + 16; |
330 | /* "+ 4" above corresponds to the length of IPv4 addr | 329 | *dest++ = ' '; |
331 | * we consume in the loop below */ | 330 | /* 6rdBRIPv4Address(es), use common IPv4 logic to process them */ |
332 | while (1) { | 331 | type = OPTION_IP; |
333 | /* 6rdBRIPv4Address(es) */ | 332 | optlen = 4; |
334 | dest += sprint_nip(dest, " ", option); | 333 | continue; |
335 | option += 4; | ||
336 | len -= 4; /* do we have yet another 4+ bytes? */ | ||
337 | if (len < 0) | ||
338 | break; /* no */ | ||
339 | } | ||
340 | } | 334 | } |
341 | 335 | ||
342 | return ret; | 336 | return ret; |
@@ -358,23 +352,18 @@ static NOINLINE char *xmalloc_optname_optval(uint8_t *option, const struct dhcp_ | |||
358 | */ | 352 | */ |
359 | option++; | 353 | option++; |
360 | len--; | 354 | len--; |
355 | if (option[-1] == 1) { | ||
356 | /* use common IPv4 logic to process IP addrs */ | ||
357 | type = OPTION_IP; | ||
358 | optlen = 4; | ||
359 | continue; | ||
360 | } | ||
361 | if (option[-1] == 0) { | 361 | if (option[-1] == 0) { |
362 | dest = dname_dec(option, len, ret); | 362 | dest = dname_dec(option, len, ret); |
363 | if (dest) { | 363 | if (dest) { |
364 | free(ret); | 364 | free(ret); |
365 | return dest; | 365 | return dest; |
366 | } | 366 | } |
367 | } else | ||
368 | if (option[-1] == 1) { | ||
369 | const char *pfx = ""; | ||
370 | while (1) { | ||
371 | len -= 4; | ||
372 | if (len < 0) | ||
373 | break; | ||
374 | dest += sprint_nip(dest, pfx, option); | ||
375 | pfx = " "; | ||
376 | option += 4; | ||
377 | } | ||
378 | } | 367 | } |
379 | return ret; | 368 | return ret; |
380 | #endif | 369 | #endif |