nameif: fix vda's breakage (Nico Erfurth <masta AT perlgolf.de>)

function                                             old     new   delta
nameif_main                                          684     691      +7
prepend_new_eth_table                                304     301      -3
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 1/1 up/down: 7/-3)                Total: 4 bytes
This commit is contained in:
Denis Vlasenko 2008-04-10 02:03:21 +00:00
parent 858ebf130a
commit b3f39f0cfa

View File

@ -5,6 +5,7 @@
* Written 2000 by Andi Kleen. * Written 2000 by Andi Kleen.
* Busybox port 2002 by Nick Fedchik <nick@fedchik.org.ua> * Busybox port 2002 by Nick Fedchik <nick@fedchik.org.ua>
* Glenn McGrath * Glenn McGrath
* Extended matching support 2008 by Nico Erfurth <masta@perlgolf.de>
* *
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball. * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/ */
@ -93,12 +94,10 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector)
found_selector++; found_selector++;
} else { } else {
#endif #endif
lmac = ether_aton(selector + (strncmp(selector, "mac=", 4) == 0 ? 4 : 0)); lmac = xmalloc(ETH_ALEN);
/* Check ascii selector, convert and copy to *mac */ ch->mac = ether_aton_r(selector + (strncmp(selector, "mac=", 4) ? 0 : 4), lmac);
if (lmac == NULL) if (ch->mac == NULL)
bb_error_msg_and_die("cannot parse %s", selector); bb_error_msg_and_die("cannot parse %s", selector);
ch->mac = xmalloc(ETH_ALEN);
memcpy(ch->mac, lmac, ETH_ALEN);
#if ENABLE_FEATURE_NAMEIF_EXTENDED #if ENABLE_FEATURE_NAMEIF_EXTENDED
found_selector++; found_selector++;
}; };
@ -115,7 +114,7 @@ static void prepend_new_eth_table(ethtable_t **clist, char *ifname, char *select
if (strlen(ifname) >= IF_NAMESIZE) if (strlen(ifname) >= IF_NAMESIZE)
bb_error_msg_and_die("interface name '%s' too long", ifname); bb_error_msg_and_die("interface name '%s' too long", ifname);
ch = xzalloc(sizeof(*ch)); ch = xzalloc(sizeof(*ch));
ch->ifname = ifname; ch->ifname = xstrdup(ifname);
nameif_parse_selector(ch, selector); nameif_parse_selector(ch, selector);
ch->next = *clist; ch->next = *clist;
if (*clist) if (*clist)
@ -123,6 +122,21 @@ static void prepend_new_eth_table(ethtable_t **clist, char *ifname, char *select
*clist = ch; *clist = ch;
} }
#if ENABLE_FEATURE_CLEAN_UP
static void delete_eth_table(ethtable_t *ch)
{
free(ch->ifname);
#if ENABLE_FEATURE_NAMEIF_EXTENDED
free(ch->bus_info);
free(ch->driver);
#endif
free(ch->mac);
free(ch);
};
#else
void delete_eth_table(ethtable_t *ch);
#endif
int nameif_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; int nameif_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int nameif_main(int argc, char **argv) int nameif_main(int argc, char **argv)
{ {
@ -156,14 +170,13 @@ int nameif_main(int argc, char **argv)
char *next; char *next;
line_ptr = skip_whitespace(line); line_ptr = skip_whitespace(line);
if ((line_ptr[0] == '#') || (line_ptr[0] == '\n')) { if ((line_ptr[0] == '#') || (line_ptr[0] == '\n'))
free(line); goto read_next_line;
continue;
}
next = skip_non_whitespace(line_ptr); next = skip_non_whitespace(line_ptr);
if (*next) if (*next)
*next++ = '\0'; *next++ = '\0';
prepend_new_eth_table(&clist, line_ptr, next); prepend_new_eth_table(&clist, line_ptr, next);
read_next_line:
free(line); free(line);
} }
fclose(ifh); fclose(ifh);
@ -187,7 +200,7 @@ int nameif_main(int argc, char **argv)
/* Find the current interface name and copy it to ifr.ifr_name */ /* Find the current interface name and copy it to ifr.ifr_name */
line_ptr = skip_whitespace(line); line_ptr = skip_whitespace(line);
*skip_non_whitespace(line_ptr) = '\0'; *strpbrk(line_ptr, " \t\n:") = '\0';
memset(&ifr, 0, sizeof(struct ifreq)); memset(&ifr, 0, sizeof(struct ifreq));
strncpy(ifr.ifr_name, line_ptr, sizeof(ifr.ifr_name)); strncpy(ifr.ifr_name, line_ptr, sizeof(ifr.ifr_name));
@ -230,16 +243,15 @@ int nameif_main(int argc, char **argv)
else else
clist = ch->next; clist = ch->next;
if (ch->next != NULL) if (ch->next != NULL)
ch->next->prev = ch->prev; ch->next->prev = ch->prev;
if (ENABLE_FEATURE_CLEAN_UP) { if (ENABLE_FEATURE_CLEAN_UP)
free(ch->ifname); delete_eth_table(ch);
free(ch->mac);
free(ch);
}
next_line: next_line:
free(line); free(line);
} }
if (ENABLE_FEATURE_CLEAN_UP) { if (ENABLE_FEATURE_CLEAN_UP) {
for (ch = clist; ch; ch = ch->next)
delete_eth_table(ch);
fclose(ifh); fclose(ifh);
}; };