Hi,
some months ago I've send a patch to extend the matching capabilities of
nameif. The patch was modified (in fact broken ;]) and applied.
While testing the latest releases i've found that nameif does not work
at all anymore, as the /proc/net/dev parsing code and some other things
were broken.
Appended is a patch to fix nameif, I've also extended the cleanup-code
to match the new data structure and did some minor code shrinks.
Nico
$ make bloatcheck
function old new delta
delete_eth_table - 46 +46
nameif_main 721 732 +11
.rodata 144518 144523 +5
prepend_new_eth_table 301 303 +2
------------------------------------------------------------------------------
(add/remove: 1/0 grow/shrink: 3/0 up/down: 64/0) Total: 64
bytes
text data bss dec hex filename
668132 2568 9856 680556 a626c busybox_old
668196 2568 9856 680620 a62ac busybox_unstripped
Index: networking/nameif.c
===================================================================
--- networking/nameif.c (Revision 21682)
+++ networking/nameif.c (Arbeitskopie)
@@ -5,6 +5,7 @@
* Written 2000 by Andi Kleen.
* Busybox port 2002 by Nick Fedchik <[EMAIL PROTECTED]>
* Glenn McGrath
+ * Extended matching support 2008 by Nico Erfurth <[EMAIL PROTECTED]>
*
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
*/
@@ -93,12 +94,10 @@
found_selector++;
} else {
#endif
- lmac = ether_aton(selector + (strncmp(selector, "mac=", 4) == 0 ? 4 : 0));
- /* Check ascii selector, convert and copy to *mac */
- if (lmac == NULL)
+ lmac = xmalloc(ETH_ALEN);
+ ch->mac = ether_aton_r(selector + (strncmp(selector, "mac=", 4) ? 0 : 4), lmac);
+ if (ch->mac == NULL)
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
found_selector++;
};
@@ -115,7 +114,7 @@
if (strlen(ifname) >= IF_NAMESIZE)
bb_error_msg_and_die("interface name '%s' too long", ifname);
ch = xzalloc(sizeof(*ch));
- ch->ifname = ifname;
+ ch->ifname = xstrdup(ifname);
nameif_parse_selector(ch, selector);
ch->next = *clist;
if (*clist)
@@ -123,6 +122,16 @@
*clist = ch;
}
+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);
+};
+
int nameif_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
int nameif_main(int argc, char **argv)
{
@@ -156,14 +165,13 @@
char *next;
line_ptr = skip_whitespace(line);
- if ((line_ptr[0] == '#') || (line_ptr[0] == '\n')) {
- free(line);
- continue;
- }
+ if ((line_ptr[0] == '#') || (line_ptr[0] == '\n'))
+ goto read_next_line;
next = skip_non_whitespace(line_ptr);
if (*next)
*next++ = '\0';
prepend_new_eth_table(&clist, line_ptr, next);
+ read_next_line:
free(line);
}
fclose(ifh);
@@ -187,7 +195,7 @@
/* Find the current interface name and copy it to ifr.ifr_name */
line_ptr = skip_whitespace(line);
- *skip_non_whitespace(line_ptr) = '\0';
+ *strpbrk(line_ptr, " \t\n:") = '\0';
memset(&ifr, 0, sizeof(struct ifreq));
strncpy(ifr.ifr_name, line_ptr, sizeof(ifr.ifr_name));
@@ -230,16 +238,15 @@
else
clist = ch->next;
if (ch->next != NULL)
- ch->next->prev = ch->prev;
- if (ENABLE_FEATURE_CLEAN_UP) {
- free(ch->ifname);
- free(ch->mac);
- free(ch);
- }
+ ch->next->prev = ch->prev;
+ if (ENABLE_FEATURE_CLEAN_UP)
+ delete_eth_table(ch);
next_line:
free(line);
}
if (ENABLE_FEATURE_CLEAN_UP) {
+ for (ch = clist; ch; ch = ch->next)
+ delete_eth_table(ch);
fclose(ifh);
};
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox