diff options
Diffstat (limited to 'networking/udhcp/common.c')
-rw-r--r-- | networking/udhcp/common.c | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/networking/udhcp/common.c b/networking/udhcp/common.c index 77d7fd5d4..fb4f8d16c 100644 --- a/networking/udhcp/common.c +++ b/networking/udhcp/common.c | |||
@@ -18,7 +18,7 @@ const uint8_t MAC_BCAST_ADDR[6] ALIGN2 = { | |||
18 | * See RFC2132 for more options. | 18 | * See RFC2132 for more options. |
19 | * OPTION_REQ: these options are requested by udhcpc (unless -o). | 19 | * OPTION_REQ: these options are requested by udhcpc (unless -o). |
20 | */ | 20 | */ |
21 | const struct dhcp_option dhcp_options[] = { | 21 | const struct dhcp_optflag dhcp_optflags[] = { |
22 | /* flags code */ | 22 | /* flags code */ |
23 | { OPTION_IP | OPTION_REQ, 0x01 }, /* DHCP_SUBNET */ | 23 | { OPTION_IP | OPTION_REQ, 0x01 }, /* DHCP_SUBNET */ |
24 | { OPTION_S32 , 0x02 }, /* DHCP_TIME_OFFSET */ | 24 | { OPTION_S32 , 0x02 }, /* DHCP_TIME_OFFSET */ |
@@ -76,7 +76,7 @@ const struct dhcp_option dhcp_options[] = { | |||
76 | * for udhcpc stript, and for setting options for udhcpd via | 76 | * for udhcpc stript, and for setting options for udhcpd via |
77 | * "opt OPTION_NAME OPTION_VALUE" directives in udhcpd.conf file. | 77 | * "opt OPTION_NAME OPTION_VALUE" directives in udhcpd.conf file. |
78 | */ | 78 | */ |
79 | /* Must match dhcp_options[] order */ | 79 | /* Must match dhcp_optflags[] order */ |
80 | const char dhcp_option_strings[] ALIGN1 = | 80 | const char dhcp_option_strings[] ALIGN1 = |
81 | "subnet" "\0" /* DHCP_SUBNET */ | 81 | "subnet" "\0" /* DHCP_SUBNET */ |
82 | "timezone" "\0" /* DHCP_TIME_OFFSET */ | 82 | "timezone" "\0" /* DHCP_TIME_OFFSET */ |
@@ -278,9 +278,9 @@ void FAST_FUNC udhcp_add_binary_option(struct dhcp_packet *packet, uint8_t *addo | |||
278 | /* Add an one to four byte option to a packet */ | 278 | /* Add an one to four byte option to a packet */ |
279 | void FAST_FUNC udhcp_add_simple_option(struct dhcp_packet *packet, uint8_t code, uint32_t data) | 279 | void FAST_FUNC udhcp_add_simple_option(struct dhcp_packet *packet, uint8_t code, uint32_t data) |
280 | { | 280 | { |
281 | const struct dhcp_option *dh; | 281 | const struct dhcp_optflag *dh; |
282 | 282 | ||
283 | for (dh = dhcp_options; dh->code; dh++) { | 283 | for (dh = dhcp_optflags; dh->code; dh++) { |
284 | if (dh->code == code) { | 284 | if (dh->code == code) { |
285 | uint8_t option[6], len; | 285 | uint8_t option[6], len; |
286 | 286 | ||
@@ -330,7 +330,7 @@ int FAST_FUNC udhcp_str2nip(const char *str, void *arg) | |||
330 | /* helper: add an option to the opt_list */ | 330 | /* helper: add an option to the opt_list */ |
331 | static NOINLINE void attach_option( | 331 | static NOINLINE void attach_option( |
332 | struct option_set **opt_list, | 332 | struct option_set **opt_list, |
333 | const struct dhcp_option *option, | 333 | const struct dhcp_optflag *optflag, |
334 | char *buffer, | 334 | char *buffer, |
335 | int length) | 335 | int length) |
336 | { | 336 | { |
@@ -339,11 +339,11 @@ static NOINLINE void attach_option( | |||
339 | char *allocated = NULL; | 339 | char *allocated = NULL; |
340 | #endif | 340 | #endif |
341 | 341 | ||
342 | existing = udhcp_find_option(*opt_list, option->code); | 342 | existing = udhcp_find_option(*opt_list, optflag->code); |
343 | if (!existing) { | 343 | if (!existing) { |
344 | log2("Attaching option %02x to list", option->code); | 344 | log2("Attaching option %02x to list", optflag->code); |
345 | #if ENABLE_FEATURE_UDHCP_RFC3397 | 345 | #if ENABLE_FEATURE_UDHCP_RFC3397 |
346 | if ((option->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) { | 346 | if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) { |
347 | /* reuse buffer and length for RFC1035-formatted string */ | 347 | /* reuse buffer and length for RFC1035-formatted string */ |
348 | allocated = buffer = (char *)dname_enc(NULL, 0, buffer, &length); | 348 | allocated = buffer = (char *)dname_enc(NULL, 0, buffer, &length); |
349 | } | 349 | } |
@@ -351,12 +351,12 @@ static NOINLINE void attach_option( | |||
351 | /* make a new option */ | 351 | /* make a new option */ |
352 | new = xmalloc(sizeof(*new)); | 352 | new = xmalloc(sizeof(*new)); |
353 | new->data = xmalloc(length + OPT_DATA); | 353 | new->data = xmalloc(length + OPT_DATA); |
354 | new->data[OPT_CODE] = option->code; | 354 | new->data[OPT_CODE] = optflag->code; |
355 | new->data[OPT_LEN] = length; | 355 | new->data[OPT_LEN] = length; |
356 | memcpy(new->data + OPT_DATA, buffer, length); | 356 | memcpy(new->data + OPT_DATA, buffer, length); |
357 | 357 | ||
358 | curr = opt_list; | 358 | curr = opt_list; |
359 | while (*curr && (*curr)->data[OPT_CODE] < option->code) | 359 | while (*curr && (*curr)->data[OPT_CODE] < optflag->code) |
360 | curr = &(*curr)->next; | 360 | curr = &(*curr)->next; |
361 | 361 | ||
362 | new->next = *curr; | 362 | new->next = *curr; |
@@ -364,14 +364,14 @@ static NOINLINE void attach_option( | |||
364 | goto ret; | 364 | goto ret; |
365 | } | 365 | } |
366 | 366 | ||
367 | if (option->flags & OPTION_LIST) { | 367 | if (optflag->flags & OPTION_LIST) { |
368 | unsigned old_len; | 368 | unsigned old_len; |
369 | 369 | ||
370 | /* add it to an existing option */ | 370 | /* add it to an existing option */ |
371 | log1("Attaching option %02x to existing member of list", option->code); | 371 | log1("Attaching option %02x to existing member of list", optflag->code); |
372 | old_len = existing->data[OPT_LEN]; | 372 | old_len = existing->data[OPT_LEN]; |
373 | #if ENABLE_FEATURE_UDHCP_RFC3397 | 373 | #if ENABLE_FEATURE_UDHCP_RFC3397 |
374 | if ((option->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) { | 374 | if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) { |
375 | /* reuse buffer and length for RFC1035-formatted string */ | 375 | /* reuse buffer and length for RFC1035-formatted string */ |
376 | 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); |
377 | } | 377 | } |
@@ -380,7 +380,7 @@ static NOINLINE void attach_option( | |||
380 | /* actually 255 is ok too, but adding a space can overlow it */ | 380 | /* actually 255 is ok too, but adding a space can overlow it */ |
381 | 381 | ||
382 | existing->data = xrealloc(existing->data, OPT_DATA + 1 + old_len + length); | 382 | existing->data = xrealloc(existing->data, OPT_DATA + 1 + old_len + length); |
383 | if ((option->flags & OPTION_TYPE_MASK) == OPTION_STRING) { | 383 | if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING) { |
384 | /* add space separator between STRING options in a list */ | 384 | /* add space separator between STRING options in a list */ |
385 | existing->data[OPT_DATA + old_len] = ' '; | 385 | existing->data[OPT_DATA + old_len] = ' '; |
386 | old_len++; | 386 | old_len++; |
@@ -401,7 +401,7 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg) | |||
401 | struct option_set **opt_list = arg; | 401 | struct option_set **opt_list = arg; |
402 | char *opt, *val, *endptr; | 402 | char *opt, *val, *endptr; |
403 | char *str; | 403 | char *str; |
404 | const struct dhcp_option *option; | 404 | const struct dhcp_optflag *optflag; |
405 | int retval, length; | 405 | int retval, length; |
406 | char buffer[8] ALIGNED(4); | 406 | char buffer[8] ALIGNED(4); |
407 | uint16_t *result_u16 = (uint16_t *) buffer; | 407 | uint16_t *result_u16 = (uint16_t *) buffer; |
@@ -413,17 +413,17 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg) | |||
413 | if (!opt) | 413 | if (!opt) |
414 | return 0; | 414 | return 0; |
415 | 415 | ||
416 | option = &dhcp_options[udhcp_option_idx(opt)]; | 416 | optflag = &dhcp_optflags[udhcp_option_idx(opt)]; |
417 | 417 | ||
418 | retval = 0; | 418 | retval = 0; |
419 | do { | 419 | do { |
420 | val = strtok(NULL, ", \t"); | 420 | val = strtok(NULL, ", \t"); |
421 | if (!val) | 421 | if (!val) |
422 | break; | 422 | break; |
423 | length = dhcp_option_lengths[option->flags & OPTION_TYPE_MASK]; | 423 | length = dhcp_option_lengths[optflag->flags & OPTION_TYPE_MASK]; |
424 | retval = 0; | 424 | retval = 0; |
425 | opt = buffer; /* new meaning for variable opt */ | 425 | opt = buffer; /* new meaning for variable opt */ |
426 | switch (option->flags & OPTION_TYPE_MASK) { | 426 | switch (optflag->flags & OPTION_TYPE_MASK) { |
427 | case OPTION_IP: | 427 | case OPTION_IP: |
428 | retval = udhcp_str2nip(val, buffer); | 428 | retval = udhcp_str2nip(val, buffer); |
429 | break; | 429 | break; |
@@ -486,8 +486,8 @@ int FAST_FUNC udhcp_str2optset(const char *const_str, void *arg) | |||
486 | break; | 486 | break; |
487 | } | 487 | } |
488 | if (retval) | 488 | if (retval) |
489 | attach_option(opt_list, option, opt, length); | 489 | attach_option(opt_list, optflag, opt, length); |
490 | } while (retval && option->flags & OPTION_LIST); | 490 | } while (retval && optflag->flags & OPTION_LIST); |
491 | 491 | ||
492 | return retval; | 492 | return retval; |
493 | } | 493 | } |