diff options
| author | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-23 15:43:08 +0100 |
|---|---|---|
| committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-23 15:43:08 +0100 |
| commit | 37a658c4c86fa5ad9fb6f76cba2fca80f4249036 (patch) | |
| tree | 0cdb35ff2c8baa859eab8a0e5cc5af5108ae06a4 | |
| parent | 30ebd7bd7838787bdb7de0b484e37e442ab16ac5 (diff) | |
| download | busybox-w32-37a658c4c86fa5ad9fb6f76cba2fca80f4249036.tar.gz busybox-w32-37a658c4c86fa5ad9fb6f76cba2fca80f4249036.tar.bz2 busybox-w32-37a658c4c86fa5ad9fb6f76cba2fca80f4249036.zip | |
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>
| -rw-r--r-- | networking/ether-wake.c | 8 | ||||
| -rw-r--r-- | networking/nameif.c | 2 | ||||
| -rw-r--r-- | networking/udhcp/common.h | 2 | ||||
| -rw-r--r-- | networking/udhcp/files.c | 20 | ||||
| -rw-r--r-- | networking/udhcp/packet.c | 6 |
5 files changed, 18 insertions, 20 deletions
diff --git a/networking/ether-wake.c b/networking/ether-wake.c index e05db7a80..deeb68c09 100644 --- a/networking/ether-wake.c +++ b/networking/ether-wake.c | |||
| @@ -111,10 +111,9 @@ static void get_dest_addr(const char *hostid, struct ether_addr *eaddr) | |||
| 111 | { | 111 | { |
| 112 | struct ether_addr *eap; | 112 | struct ether_addr *eap; |
| 113 | 113 | ||
| 114 | eap = ether_aton(hostid); | 114 | eap = ether_aton_r(hostid, eaddr); |
| 115 | if (eap) { | 115 | if (eap) { |
| 116 | *eaddr = *eap; | 116 | bb_debug_msg("The target station address is %s\n\n", ether_ntoa(eap)); |
| 117 | bb_debug_msg("The target station address is %s\n\n", ether_ntoa(eaddr)); | ||
| 118 | #if !defined(__UCLIBC_MAJOR__) \ | 117 | #if !defined(__UCLIBC_MAJOR__) \ |
| 119 | || __UCLIBC_MAJOR__ > 0 \ | 118 | || __UCLIBC_MAJOR__ > 0 \ |
| 120 | || __UCLIBC_MINOR__ > 9 \ | 119 | || __UCLIBC_MINOR__ > 9 \ |
| @@ -122,8 +121,9 @@ static void get_dest_addr(const char *hostid, struct ether_addr *eaddr) | |||
| 122 | } else if (ether_hostton(hostid, eaddr) == 0) { | 121 | } else if (ether_hostton(hostid, eaddr) == 0) { |
| 123 | bb_debug_msg("Station address for hostname %s is %s\n\n", hostid, ether_ntoa(eaddr)); | 122 | bb_debug_msg("Station address for hostname %s is %s\n\n", hostid, ether_ntoa(eaddr)); |
| 124 | #endif | 123 | #endif |
| 125 | } else | 124 | } else { |
| 126 | bb_show_usage(); | 125 | bb_show_usage(); |
| 126 | } | ||
| 127 | } | 127 | } |
| 128 | 128 | ||
| 129 | static int get_fill(unsigned char *pkt, struct ether_addr *eaddr, int broadcast) | 129 | static int get_fill(unsigned char *pkt, struct ether_addr *eaddr, int broadcast) |
diff --git a/networking/nameif.c b/networking/nameif.c index 36fbb954e..046e308c5 100644 --- a/networking/nameif.c +++ b/networking/nameif.c | |||
| @@ -90,7 +90,7 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector) | |||
| 90 | } else { | 90 | } else { |
| 91 | #endif | 91 | #endif |
| 92 | lmac = xmalloc(ETH_ALEN); | 92 | lmac = xmalloc(ETH_ALEN); |
| 93 | ch->mac = ether_aton_r(selector + (strncmp(selector, "mac=", 4) ? 0 : 4), lmac); | 93 | ch->mac = ether_aton_r(selector + (strncmp(selector, "mac=", 4) != 0 ? 0 : 4), lmac); |
| 94 | if (ch->mac == NULL) | 94 | if (ch->mac == NULL) |
| 95 | bb_error_msg_and_die("can't parse %s", selector); | 95 | bb_error_msg_and_die("can't parse %s", selector); |
| 96 | #if ENABLE_FEATURE_NAMEIF_EXTENDED | 96 | #if ENABLE_FEATURE_NAMEIF_EXTENDED |
diff --git a/networking/udhcp/common.h b/networking/udhcp/common.h index 2179c5395..15fe785c1 100644 --- a/networking/udhcp/common.h +++ b/networking/udhcp/common.h | |||
| @@ -176,7 +176,7 @@ uint8_t *dname_enc(const uint8_t *cstr, int clen, const char *src, int *retlen) | |||
| 176 | 176 | ||
| 177 | // RFC 2131 Table 5: Fields and options used by DHCP clients | 177 | // RFC 2131 Table 5: Fields and options used by DHCP clients |
| 178 | // | 178 | // |
| 179 | // Fiels 'hops', 'yiaddr', 'siaddr', 'giaddr' are always zero | 179 | // Fields 'hops', 'yiaddr', 'siaddr', 'giaddr' are always zero |
| 180 | // | 180 | // |
| 181 | // Field DHCPDISCOVER DHCPINFORM DHCPREQUEST DHCPDECLINE DHCPRELEASE | 181 | // Field DHCPDISCOVER DHCPINFORM DHCPREQUEST DHCPDECLINE DHCPRELEASE |
| 182 | // ----- ------------ ------------ ----------- ----------- ----------- | 182 | // ----- ------------ ------------ ----------- ----------- ----------- |
diff --git a/networking/udhcp/files.c b/networking/udhcp/files.c index 968d8ed79..05a7b998a 100644 --- a/networking/udhcp/files.c +++ b/networking/udhcp/files.c | |||
| @@ -34,11 +34,6 @@ static int FAST_FUNC read_nip(const char *line, void *arg) | |||
| 34 | return 1; | 34 | return 1; |
| 35 | } | 35 | } |
| 36 | 36 | ||
| 37 | static int FAST_FUNC read_mac(const char *line, void *arg) | ||
| 38 | { | ||
| 39 | return NULL == ether_aton_r(line, (struct ether_addr *)arg); | ||
| 40 | } | ||
| 41 | |||
| 42 | static int FAST_FUNC read_str(const char *line, void *arg) | 37 | static int FAST_FUNC read_str(const char *line, void *arg) |
| 43 | { | 38 | { |
| 44 | char **dest = arg; | 39 | char **dest = arg; |
| @@ -242,6 +237,7 @@ static int FAST_FUNC read_opt(const char *const_line, void *arg) | |||
| 242 | if (retval) | 237 | if (retval) |
| 243 | attach_option(opt_list, option, opt, length); | 238 | attach_option(opt_list, option, opt, length); |
| 244 | } while (retval && option->flags & OPTION_LIST); | 239 | } while (retval && option->flags & OPTION_LIST); |
| 240 | |||
| 245 | return retval; | 241 | return retval; |
| 246 | } | 242 | } |
| 247 | 243 | ||
| @@ -250,19 +246,21 @@ static int FAST_FUNC read_staticlease(const char *const_line, void *arg) | |||
| 250 | char *line; | 246 | char *line; |
| 251 | char *mac_string; | 247 | char *mac_string; |
| 252 | char *ip_string; | 248 | char *ip_string; |
| 253 | struct ether_addr mac_bytes; | 249 | struct ether_addr mac_bytes; /* it's "struct { uint8_t mac[6]; }" */ |
| 254 | uint32_t ip; | 250 | uint32_t nip; |
| 255 | 251 | ||
| 256 | /* Read mac */ | 252 | /* Read mac */ |
| 257 | line = (char *) const_line; | 253 | line = (char *) const_line; |
| 258 | mac_string = strtok_r(line, " \t", &line); | 254 | mac_string = strtok_r(line, " \t", &line); |
| 259 | read_mac(mac_string, &mac_bytes); | 255 | if (!mac_string || !ether_aton_r(mac_string, &mac_bytes)) |
| 256 | return 0; | ||
| 260 | 257 | ||
| 261 | /* Read ip */ | 258 | /* Read ip */ |
| 262 | ip_string = strtok_r(NULL, " \t", &line); | 259 | ip_string = strtok_r(NULL, " \t", &line); |
| 263 | read_nip(ip_string, &ip); | 260 | if (!ip_string || !read_nip(ip_string, &nip)) |
| 261 | return 0; | ||
| 264 | 262 | ||
| 265 | add_static_lease(arg, (uint8_t*) &mac_bytes, ip); | 263 | add_static_lease(arg, (uint8_t*) &mac_bytes, nip); |
| 266 | 264 | ||
| 267 | log_static_leases(arg); | 265 | log_static_leases(arg); |
| 268 | 266 | ||
| @@ -316,7 +314,7 @@ void FAST_FUNC read_config(const char *file) | |||
| 316 | parser = config_open(file); | 314 | parser = config_open(file); |
| 317 | while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) { | 315 | while (config_read(parser, token, 2, 2, "# \t", PARSE_NORMAL)) { |
| 318 | for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) { | 316 | for (k = keywords, i = 0; i < ARRAY_SIZE(keywords); k++, i++) { |
| 319 | if (!strcasecmp(token[0], k->keyword)) { | 317 | if (strcasecmp(token[0], k->keyword) == 0) { |
| 320 | if (!k->handler(token[1], k->var)) { | 318 | if (!k->handler(token[1], k->var)) { |
| 321 | bb_error_msg("can't parse line %u in %s", | 319 | bb_error_msg("can't parse line %u in %s", |
| 322 | parser->lineno, file); | 320 | parser->lineno, file); |
diff --git a/networking/udhcp/packet.c b/networking/udhcp/packet.c index 03d5e1fc8..5b113bc10 100644 --- a/networking/udhcp/packet.c +++ b/networking/udhcp/packet.c | |||
| @@ -113,8 +113,8 @@ int FAST_FUNC udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd) | |||
| 113 | }; | 113 | }; |
| 114 | int i; | 114 | int i; |
| 115 | for (i = 0; broken_vendors[i][0]; i++) { | 115 | for (i = 0; broken_vendors[i][0]; i++) { |
| 116 | if (vendor[OPT_LEN - 2] == (uint8_t)strlen(broken_vendors[i]) | 116 | if (vendor[OPT_LEN - OPT_DATA] == (uint8_t)strlen(broken_vendors[i]) |
| 117 | && !strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - 2]) | 117 | && strncmp((char*)vendor, broken_vendors[i], vendor[OPT_LEN - OPT_DATA]) == 0 |
| 118 | ) { | 118 | ) { |
| 119 | log1("Broken client (%s), forcing broadcast replies", | 119 | log1("Broken client (%s), forcing broadcast replies", |
| 120 | broken_vendors[i]); | 120 | broken_vendors[i]); |
| @@ -122,7 +122,7 @@ int FAST_FUNC udhcp_recv_kernel_packet(struct dhcp_packet *packet, int fd) | |||
| 122 | } | 122 | } |
| 123 | } | 123 | } |
| 124 | #else | 124 | #else |
| 125 | if (vendor[OPT_LEN - 2] == (uint8_t)(sizeof("MSFT 98")-1) | 125 | if (vendor[OPT_LEN - OPT_DATA] == (uint8_t)(sizeof("MSFT 98")-1) |
| 126 | && memcmp(vendor, "MSFT 98", sizeof("MSFT 98")-1) == 0 | 126 | && memcmp(vendor, "MSFT 98", sizeof("MSFT 98")-1) == 0 |
| 127 | ) { | 127 | ) { |
| 128 | log1("Broken client (%s), forcing broadcast replies", "MSFT 98"); | 128 | log1("Broken client (%s), forcing broadcast replies", "MSFT 98"); |
