mirror of
https://github.com/topjohnwu/ndk-busybox.git
synced 2024-11-27 21:50:32 +00:00
udhcp: handle errors in read_staticlease
also gets rid of ether-aton's static buffer in ether-wake: text data bss dec hexfilename 838664 441 7572 846677 ceb55busybox_old 838650 441 7564 846655 ceb3fbusybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
30ebd7bd78
commit
37a658c4c8
@ -111,10 +111,9 @@ static void get_dest_addr(const char *hostid, struct ether_addr *eaddr)
|
||||
{
|
||||
struct ether_addr *eap;
|
||||
|
||||
eap = ether_aton(hostid);
|
||||
eap = ether_aton_r(hostid, eaddr);
|
||||
if (eap) {
|
||||
*eaddr = *eap;
|
||||
bb_debug_msg("The target station address is %s\n\n", ether_ntoa(eaddr));
|
||||
bb_debug_msg("The target station address is %s\n\n", ether_ntoa(eap));
|
||||
#if !defined(__UCLIBC_MAJOR__) \
|
||||
|| __UCLIBC_MAJOR__ > 0 \
|
||||
|| __UCLIBC_MINOR__ > 9 \
|
||||
@ -122,8 +121,9 @@ static void get_dest_addr(const char *hostid, struct ether_addr *eaddr)
|
||||
} else if (ether_hostton(hostid, eaddr) == 0) {
|
||||
bb_debug_msg("Station address for hostname %s is %s\n\n", hostid, ether_ntoa(eaddr));
|
||||
#endif
|
||||
} else
|
||||
} else {
|
||||
bb_show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
static int get_fill(unsigned char *pkt, struct ether_addr *eaddr, int broadcast)
|
||||
|
@ -90,7 +90,7 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector)
|
||||
} else {
|
||||
#endif
|
||||
lmac = xmalloc(ETH_ALEN);
|
||||
ch->mac = ether_aton_r(selector + (strncmp(selector, "mac=", 4) ? 0 : 4), lmac);
|
||||
ch->mac = ether_aton_r(selector + (strncmp(selector, "mac=", 4) != 0 ? 0 : 4), lmac);
|
||||
if (ch->mac == NULL)
|
||||
bb_error_msg_and_die("can't parse %s", selector);
|
||||
#if ENABLE_FEATURE_NAMEIF_EXTENDED
|
||||
|
@ -176,7 +176,7 @@ uint8_t *dname_enc(const uint8_t *cstr, int clen, const char *src, int *retlen)
|
||||
|
||||
// RFC 2131 Table 5: Fields and options used by DHCP clients
|
||||
//
|
||||
// Fiels 'hops', 'yiaddr', 'siaddr', 'giaddr' are always zero
|
||||
// Fields 'hops', 'yiaddr', 'siaddr', 'giaddr' are always zero
|
||||
//
|
||||
// Field DHCPDISCOVER DHCPINFORM DHCPREQUEST DHCPDECLINE DHCPRELEASE
|
||||
// ----- ------------ ------------ ----------- ----------- -----------
|
||||
|
@ -34,11 +34,6 @@ static int FAST_FUNC read_nip(const char *line, void *arg)
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int FAST_FUNC read_mac(const char *line, void *arg)
|
||||
{
|
||||
return NULL == ether_aton_r(line, (struct ether_addr *)arg);
|
||||
}
|
||||
|
||||
static int FAST_FUNC read_str(const char *line, void *arg)
|
||||
{
|
||||
char **dest = arg;
|
||||
@ -242,6 +237,7 @@ static int FAST_FUNC read_opt(const char *const_line, void *arg)
|
||||
if (retval)
|
||||
attach_option(opt_list, option, opt, length);
|
||||
} while (retval && option->flags & OPTION_LIST);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
@ -250,19 +246,21 @@ static int FAST_FUNC read_staticlease(const char *const_line, void *arg)
|
||||
char *line;
|
||||
char *mac_string;
|
||||
char *ip_string;
|
||||
struct ether_addr mac_bytes;
|
||||
uint32_t ip;
|
||||
struct ether_addr mac_bytes; /* it's "struct { uint8_t mac[6]; }" */
|
||||
uint32_t nip;
|
||||
|
||||
/* Read mac */
|
||||
line = (char *) const_line;
|
||||
mac_string = strtok_r(line, " \t", &line);
|
||||
read_mac(mac_string, &mac_bytes);
|
||||
if (!mac_string || !ether_aton_r(mac_string, &mac_bytes))
|
||||
return 0;
|
||||
|
||||
/* Read ip */
|
||||
ip_string = strtok_r(NULL, " \t", &line);
|
||||
read_nip(ip_string, &ip);
|
||||
if (!ip_string || !read_nip(ip_string, &nip))
|
||||
return 0;
|
||||
|
||||
add_static_lease(arg, (uint8_t*) &mac_bytes, ip);
|
||||
add_static_lease(arg, (uint8_t*) &mac_bytes, nip);
|
||||
|
||||
log_static_leases(arg);
|
||||
|
||||
@ -316,7 +314,7 @@ void FAST_FUNC read_config(const char *file)
|
||||
parser = config_open(file);
|
||||
while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) {
|
||||
for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) {
|
||||
if (!strcasecmp(token[0], k->keyword)) {
|
||||
if (strcasecmp(token[0], k->keyword) == 0) {
|
||||
if (!k->handler(token[1], k->var)) {
|
||||
bb_error_msg("can't parse line %u in %s",
|
||||
parser->lineno, file);
|
||||
|
@ -113,8 +113,8 @@ int FAST_FUNC udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd)
|
||||
};
|
||||
int i;
|
||||
for (i = 0; broken_vendors[i][0]; i++) {
|
||||
if (vendor[OPT_LEN - 2] == (uint8_t)strlen(broken_vendors[i])
|
||||
&& !strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - 2])
|
||||
if (vendor[OPT_LEN - OPT_DATA] == (uint8_t)strlen(broken_vendors[i])
|
||||
&& strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - OPT_DATA]) == 0
|
||||
) {
|
||||
log1("Broken client (%s), forcing broadcast replies",
|
||||
broken_vendors[i]);
|
||||
@ -122,7 +122,7 @@ int FAST_FUNC udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd)
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (vendor[OPT_LEN - 2] == (uint8_t)(sizeof("MSFT 98")-1)
|
||||
if (vendor[OPT_LEN - OPT_DATA] == (uint8_t)(sizeof("MSFT 98")-1)
|
||||
&& memcmp(vendor, "MSFT 98", sizeof("MSFT 98")-1) == 0
|
||||
) {
|
||||
log1("Broken client (%s), forcing broadcast replies", "MSFT 98");
|
||||
|
Loading…
Reference in New Issue
Block a user