Changeset 3621 in MondoRescue for branches/3.3/mindi-busybox/networking/udhcp/common.c
- Timestamp:
- Dec 20, 2016, 4:07:32 PM (7 years ago)
- Location:
- branches/3.3
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/3.3/mindi-busybox/networking/udhcp/common.c
r3232 r3621 63 63 { OPTION_U8 , 0x85 }, /* DHCP_VLAN_PRIORITY */ 64 64 #endif 65 { OPTION_STRING , 0xd1 }, /* DHCP_PXE_CONF_FILE */ 66 { OPTION_STRING , 0xd2 }, /* DHCP_PXE_PATH_PREFIX */ 65 67 { OPTION_6RD , 0xd4 }, /* DHCP_6RD */ 66 68 { OPTION_STATIC_ROUTES | OPTION_LIST , 0xf9 }, /* DHCP_MS_STATIC_ROUTES */ … … 129 131 "vlanpriority" "\0"/* DHCP_VLAN_PRIORITY */ 130 132 #endif 133 "pxeconffile" "\0" /* DHCP_PXE_CONF_FILE */ 134 "pxepathprefix" "\0" /* DHCP_PXE_PATH_PREFIX */ 131 135 "ip6rd" "\0" /* DHCP_6RD */ 132 136 "msstaticroutes""\0"/* DHCP_MS_STATIC_ROUTES */ … … 139 143 * xmalloc_optname_optval: to estimate string length 140 144 * from binary option length: (option[LEN] / dhcp_option_lengths[opt_type]) 141 * is the number of elements, multiply i nby one element's string width145 * is the number of elements, multiply it by one element's string width 142 146 * (len_of_option_as_string[opt_type]) and you know how wide string you need. 143 147 */ … … 159 163 /* Just like OPTION_STRING, we use minimum length here */ 160 164 [OPTION_STATIC_ROUTES] = 5, 161 [OPTION_6RD] = 22, /* ignored by udhcp_str2optset */ 165 [OPTION_6RD] = 12, /* ignored by udhcp_str2optset */ 166 /* The above value was chosen as follows: 167 * len_of_option_as_string[] for this option is >60: it's a string of the form 168 * "32 128 ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff 255.255.255.255 ". 169 * Each additional ipv4 address takes 4 bytes in binary option and appends 170 * another "255.255.255.255 " 16-byte string. We can set [OPTION_6RD] = 4 171 * but this severely overestimates string length: instead of 16 bytes, 172 * it adds >60 for every 4 bytes in binary option. 173 * We cheat and declare here that option is in units of 12 bytes. 174 * This adds more than 60 bytes for every three ipv4 addresses - more than enough. 175 * (Even 16 instead of 12 should work, but let's be paranoid). 176 */ 162 177 }; 163 178 … … 169 184 char buf[256 * 2 + 2]; 170 185 *bin2hex(buf, (void*) (opt + OPT_DATA), opt[OPT_LEN]) = '\0'; 171 bb_ info_msg("%s: 0x%02x %s", pfx, opt[OPT_CODE], buf);186 bb_error_msg("%s: 0x%02x %s", pfx, opt[OPT_CODE], buf); 172 187 } 173 188 } … … 243 258 244 259 if (optionptr[OPT_CODE] == code) { 245 log_option(" Option found", optionptr);260 log_option("option found", optionptr); 246 261 return optionptr + OPT_DATA; 247 262 } … … 255 270 256 271 /* log3 because udhcpc uses it a lot - very noisy */ 257 log3(" Option 0x%02x not found", code);272 log3("option 0x%02x not found", code); 258 273 return NULL; 259 274 } … … 289 304 return; 290 305 } 291 log_option(" Adding option", addopt);306 log_option("adding option", addopt); 292 307 memcpy(optionptr + end, addopt, len); 293 308 optionptr[end + len] = DHCP_END; … … 372 387 int length) 373 388 { 374 struct option_set *existing, *new, **curr; 375 char *allocated = NULL; 389 struct option_set *existing; 390 char *allocated; 391 392 allocated = allocate_tempopt_if_needed(optflag, buffer, &length); 393 #if ENABLE_FEATURE_UDHCP_RFC3397 394 if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) { 395 /* reuse buffer and length for RFC1035-formatted string */ 396 allocated = buffer = (char *)dname_enc(NULL, 0, buffer, &length); 397 } 398 #endif 376 399 377 400 existing = udhcp_find_option(*opt_list, optflag->code); 378 401 if (!existing) { 379 log2("Attaching option %02x to list", optflag->code); 380 allocated = allocate_tempopt_if_needed(optflag, buffer, &length); 381 #if ENABLE_FEATURE_UDHCP_RFC3397 382 if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) { 383 /* reuse buffer and length for RFC1035-formatted string */ 384 allocated = buffer = (char *)dname_enc(NULL, 0, buffer, &length); 385 } 386 #endif 402 struct option_set *new, **curr; 403 387 404 /* make a new option */ 405 log2("attaching option %02x to list", optflag->code); 388 406 new = xmalloc(sizeof(*new)); 389 407 new->data = xmalloc(length + OPT_DATA); … … 405 423 406 424 /* add it to an existing option */ 407 log2("Attaching option %02x to existing member of list", optflag->code); 408 allocated = allocate_tempopt_if_needed(optflag, buffer, &length); 425 log2("attaching option %02x to existing member of list", optflag->code); 409 426 old_len = existing->data[OPT_LEN]; 410 #if ENABLE_FEATURE_UDHCP_RFC3397411 if ((optflag->flags & OPTION_TYPE_MASK) == OPTION_DNS_STRING) {412 /* reuse buffer and length for RFC1035-formatted string */413 allocated = buffer = (char *)dname_enc(existing->data + OPT_DATA, old_len, buffer, &length);414 }415 #endif416 427 if (old_len + length < 255) { 417 428 /* actually 255 is ok too, but adding a space can overlow it */ … … 425 436 old_len++; 426 437 } 427 memcpy(existing->data + OPT_DATA + old_len, buffer, length);438 memcpy(existing->data + OPT_DATA + old_len, (allocated ? allocated : buffer), length); 428 439 existing->data[OPT_LEN] = old_len + length; 429 440 } /* else, ignore the data, we could put this in a second option in the future */
Note:
See TracChangeset
for help on using the changeset viewer.