Changeset 3232 in MondoRescue for branches/3.2/mindi-busybox/networking/udhcp/common.c
- Timestamp:
- Jan 1, 2014, 12:47:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/3.2/mindi-busybox/networking/udhcp/common.c
r2725 r3232 30 30 // { OPTION_IP | OPTION_LIST , 0x08 }, /* DHCP_COOKIE_SERVER */ 31 31 { OPTION_IP | OPTION_LIST , 0x09 }, /* DHCP_LPR_SERVER */ 32 { OPTION_STRING 32 { OPTION_STRING_HOST | OPTION_REQ, 0x0c }, /* DHCP_HOST_NAME */ 33 33 { OPTION_U16 , 0x0d }, /* DHCP_BOOT_SIZE */ 34 { OPTION_STRING 34 { OPTION_STRING_HOST | OPTION_REQ, 0x0f }, /* DHCP_DOMAIN_NAME */ 35 35 { OPTION_IP , 0x10 }, /* DHCP_SWAP_SERVER */ 36 36 { OPTION_STRING , 0x11 }, /* DHCP_ROOT_PATH */ 37 37 { OPTION_U8 , 0x17 }, /* DHCP_IP_TTL */ 38 38 { OPTION_U16 , 0x1a }, /* DHCP_MTU */ 39 //TODO: why do we request DHCP_BROADCAST? Can't we assume that 40 //in the unlikely case it is different from typical N.N.255.255, 41 //server would let us know anyway? 39 42 { OPTION_IP | OPTION_REQ, 0x1c }, /* DHCP_BROADCAST */ 40 43 { OPTION_IP_PAIR | OPTION_LIST , 0x21 }, /* DHCP_ROUTES */ 41 { OPTION_STRING 44 { OPTION_STRING_HOST , 0x28 }, /* DHCP_NIS_DOMAIN */ 42 45 { OPTION_IP | OPTION_LIST , 0x29 }, /* DHCP_NIS_SERVER */ 43 46 { OPTION_IP | OPTION_LIST | OPTION_REQ, 0x2a }, /* DHCP_NTP_SERVER */ … … 47 50 { OPTION_STRING , 0x38 }, /* DHCP_ERR_MESSAGE */ 48 51 //TODO: must be combined with 'sname' and 'file' handling: 49 { OPTION_STRING 52 { OPTION_STRING_HOST , 0x42 }, /* DHCP_TFTP_SERVER_NAME */ 50 53 { OPTION_STRING , 0x43 }, /* DHCP_BOOT_FILE */ 51 54 //TODO: not a string, but a set of LASCII strings: … … 55 58 { OPTION_SIP_SERVERS , 0x78 }, /* DHCP_SIP_SERVERS */ 56 59 #endif 57 { OPTION_STATIC_ROUTES , 0x79 }, /* DHCP_STATIC_ROUTES */ 58 { OPTION_STATIC_ROUTES , 0xf9 }, /* DHCP_MS_STATIC_ROUTES */ 60 { OPTION_STATIC_ROUTES | OPTION_LIST , 0x79 }, /* DHCP_STATIC_ROUTES */ 61 #if ENABLE_FEATURE_UDHCP_8021Q 62 { OPTION_U16 , 0x84 }, /* DHCP_VLAN_ID */ 63 { OPTION_U8 , 0x85 }, /* DHCP_VLAN_PRIORITY */ 64 #endif 65 { OPTION_6RD , 0xd4 }, /* DHCP_6RD */ 66 { OPTION_STATIC_ROUTES | OPTION_LIST , 0xf9 }, /* DHCP_MS_STATIC_ROUTES */ 59 67 { OPTION_STRING , 0xfc }, /* DHCP_WPAD */ 60 68 … … 116 124 "sipsrv" "\0" /* DHCP_SIP_SERVERS */ 117 125 #endif 118 // doesn't work in udhcpd.conf since OPTION_STATIC_ROUTES119 // is not handled yet by "string->option" conversion code:120 126 "staticroutes" "\0"/* DHCP_STATIC_ROUTES */ 127 #if ENABLE_FEATURE_UDHCP_8021Q 128 "vlanid" "\0" /* DHCP_VLAN_ID */ 129 "vlanpriority" "\0"/* DHCP_VLAN_PRIORITY */ 130 #endif 131 "ip6rd" "\0" /* DHCP_6RD */ 121 132 "msstaticroutes""\0"/* DHCP_MS_STATIC_ROUTES */ 122 133 "wpad" "\0" /* DHCP_WPAD */ … … 136 147 // [OPTION_BOOLEAN] = 1, 137 148 [OPTION_STRING] = 1, /* ignored by udhcp_str2optset */ 149 [OPTION_STRING_HOST] = 1, /* ignored by udhcp_str2optset */ 138 150 #if ENABLE_FEATURE_UDHCP_RFC3397 139 151 [OPTION_DNS_STRING] = 1, /* ignored by both udhcp_str2optset and xmalloc_optname_optval */ … … 147 159 /* Just like OPTION_STRING, we use minimum length here */ 148 160 [OPTION_STATIC_ROUTES] = 5, 161 [OPTION_6RD] = 22, /* ignored by udhcp_str2optset */ 149 162 }; 150 163 … … 324 337 if (!lsa) 325 338 return 0; 326 *(uint32_t*)arg = lsa->u.sin.sin_addr.s_addr; 339 /* arg maybe unaligned */ 340 move_to_unaligned32((uint32_t*)arg, lsa->u.sin.sin_addr.s_addr); 327 341 free(lsa); 328 342 return 1; … … 404 418 405 419 existing->data = xrealloc(existing->data, OPT_DATA + 1 + old_len + length); 406 if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING) { 420 if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING 421 || (optflag->flags & OPTION_TYPE_MASK) == OPTION_STRING_HOST 422 ) { 407 423 /* add space separator between STRING options in a list */ 408 424 existing->data[OPT_DATA + old_len] = ' '; … … 421 437 { 422 438 struct option_set **opt_list = arg; 423 char *opt, *val , *endptr;439 char *opt, *val; 424 440 char *str; 425 441 const struct dhcp_optflag *optflag; … … 427 443 unsigned optcode; 428 444 int retval, length; 429 char buffer[8] ALIGNED(4); 445 /* IP_PAIR needs 8 bytes, STATIC_ROUTES needs 9 max */ 446 char buffer[9] ALIGNED(4); 430 447 uint16_t *result_u16 = (uint16_t *) buffer; 431 448 uint32_t *result_u32 = (uint32_t *) buffer; … … 468 485 break; 469 486 case OPTION_STRING: 487 case OPTION_STRING_HOST: 470 488 #if ENABLE_FEATURE_UDHCP_RFC3397 471 489 case OPTION_DNS_STRING: … … 484 502 // } 485 503 case OPTION_U8: 486 buffer[0] = strtoul(val, &endptr, 0);487 retval = (e ndptr[0] == '\0');504 buffer[0] = bb_strtou32(val, NULL, 0); 505 retval = (errno == 0); 488 506 break; 489 507 /* htonX are macros in older libc's, using temp var … … 491 509 /* TODO: use bb_strtoX? */ 492 510 case OPTION_U16: { 493 u nsigned long tmp = strtoul(val, &endptr, 0);511 uint32_t tmp = bb_strtou32(val, NULL, 0); 494 512 *result_u16 = htons(tmp); 495 retval = (e ndptr[0] == '\0'/*&& tmp < 0x10000*/);513 retval = (errno == 0 /*&& tmp < 0x10000*/); 496 514 break; 497 515 } 498 516 // case OPTION_S16: { 499 // long tmp = strtol(val, &endptr, 0);517 // long tmp = bb_strtoi32(val, NULL, 0); 500 518 // *result_u16 = htons(tmp); 501 // retval = (e ndptr[0] == '\0');519 // retval = (errno == 0); 502 520 // break; 503 521 // } 504 522 case OPTION_U32: { 505 u nsigned long tmp = strtoul(val, &endptr, 0);523 uint32_t tmp = bb_strtou32(val, NULL, 0); 506 524 *result_u32 = htonl(tmp); 507 retval = (e ndptr[0] == '\0');525 retval = (errno == 0); 508 526 break; 509 527 } 510 528 case OPTION_S32: { 511 long tmp = strtol(val, &endptr, 0);529 int32_t tmp = bb_strtoi32(val, NULL, 0); 512 530 *result_u32 = htonl(tmp); 513 retval = (endptr[0] == '\0'); 531 retval = (errno == 0); 532 break; 533 } 534 case OPTION_STATIC_ROUTES: { 535 /* Input: "a.b.c.d/m" */ 536 /* Output: mask(1 byte),pfx(0-4 bytes),gw(4 bytes) */ 537 unsigned mask; 538 char *slash = strchr(val, '/'); 539 if (slash) { 540 *slash = '\0'; 541 retval = udhcp_str2nip(val, buffer + 1); 542 buffer[0] = mask = bb_strtou(slash + 1, NULL, 10); 543 val = strtok(NULL, ", \t/-"); 544 if (!val || mask > 32 || errno) 545 retval = 0; 546 if (retval) { 547 length = ((mask + 7) >> 3) + 5; 548 retval = udhcp_str2nip(val, buffer + (length - 4)); 549 } 550 } 514 551 break; 515 552 } … … 522 559 if (retval) 523 560 attach_option(opt_list, optflag, opt, length); 524 } while (retval && optflag->flags & OPTION_LIST);561 } while (retval && (optflag->flags & OPTION_LIST)); 525 562 526 563 return retval; 527 564 } 565 566 /* note: ip is a pointer to an IPv6 in network order, possibly misaliged */ 567 int FAST_FUNC sprint_nip6(char *dest, /*const char *pre,*/ const uint8_t *ip) 568 { 569 char hexstrbuf[16 * 2]; 570 bin2hex(hexstrbuf, (void*)ip, 16); 571 return sprintf(dest, /* "%s" */ 572 "%.4s:%.4s:%.4s:%.4s:%.4s:%.4s:%.4s:%.4s", 573 /* pre, */ 574 hexstrbuf + 0 * 4, 575 hexstrbuf + 1 * 4, 576 hexstrbuf + 2 * 4, 577 hexstrbuf + 3 * 4, 578 hexstrbuf + 4 * 4, 579 hexstrbuf + 5 * 4, 580 hexstrbuf + 6 * 4, 581 hexstrbuf + 7 * 4 582 ); 583 }
Note:
See TracChangeset
for help on using the changeset viewer.