summaryrefslogtreecommitdiff
path: root/networking/nameif.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2008-04-10 02:03:21 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2008-04-10 02:03:21 +0000
commitb3f39f0cfa766344cd1faec3de3c8812184a237f (patch)
tree36ae9ed007783c5b17e7eb461837e0a61c160d4e /networking/nameif.c
parent858ebf130ae3c337f64af7c510ac86d412c055ed (diff)
downloadbusybox-w32-b3f39f0cfa766344cd1faec3de3c8812184a237f.tar.gz
busybox-w32-b3f39f0cfa766344cd1faec3de3c8812184a237f.tar.bz2
busybox-w32-b3f39f0cfa766344cd1faec3de3c8812184a237f.zip
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
Diffstat (limited to 'networking/nameif.c')
-rw-r--r--networking/nameif.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/networking/nameif.c b/networking/nameif.c
index 43388ab32..afc88917e 100644
--- a/networking/nameif.c
+++ b/networking/nameif.c
@@ -5,6 +5,7 @@
5 * Written 2000 by Andi Kleen. 5 * Written 2000 by Andi Kleen.
6 * Busybox port 2002 by Nick Fedchik <nick@fedchik.org.ua> 6 * Busybox port 2002 by Nick Fedchik <nick@fedchik.org.ua>
7 * Glenn McGrath 7 * Glenn McGrath
8 * Extended matching support 2008 by Nico Erfurth <masta@perlgolf.de>
8 * 9 *
9 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball. 10 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
10 */ 11 */
@@ -93,12 +94,10 @@ static void nameif_parse_selector(ethtable_t *ch, char *selector)
93 found_selector++; 94 found_selector++;
94 } else { 95 } else {
95#endif 96#endif
96 lmac = ether_aton(selector + (strncmp(selector, "mac=", 4) == 0 ? 4 : 0)); 97 lmac = xmalloc(ETH_ALEN);
97 /* Check ascii selector, convert and copy to *mac */ 98 ch->mac = ether_aton_r(selector + (strncmp(selector, "mac=", 4) ? 0 : 4), lmac);
98 if (lmac == NULL) 99 if (ch->mac == NULL)
99 bb_error_msg_and_die("cannot parse %s", selector); 100 bb_error_msg_and_die("cannot parse %s", selector);
100 ch->mac = xmalloc(ETH_ALEN);
101 memcpy(ch->mac, lmac, ETH_ALEN);
102#if ENABLE_FEATURE_NAMEIF_EXTENDED 101#if ENABLE_FEATURE_NAMEIF_EXTENDED
103 found_selector++; 102 found_selector++;
104 }; 103 };
@@ -115,7 +114,7 @@ static void prepend_new_eth_table(ethtable_t **clist, char *ifname, char *select
115 if (strlen(ifname) >= IF_NAMESIZE) 114 if (strlen(ifname) >= IF_NAMESIZE)
116 bb_error_msg_and_die("interface name '%s' too long", ifname); 115 bb_error_msg_and_die("interface name '%s' too long", ifname);
117 ch = xzalloc(sizeof(*ch)); 116 ch = xzalloc(sizeof(*ch));
118 ch->ifname = ifname; 117 ch->ifname = xstrdup(ifname);
119 nameif_parse_selector(ch, selector); 118 nameif_parse_selector(ch, selector);
120 ch->next = *clist; 119 ch->next = *clist;
121 if (*clist) 120 if (*clist)
@@ -123,6 +122,21 @@ static void prepend_new_eth_table(ethtable_t **clist, char *ifname, char *select
123 *clist = ch; 122 *clist = ch;
124} 123}
125 124
125#if ENABLE_FEATURE_CLEAN_UP
126static void delete_eth_table(ethtable_t *ch)
127{
128 free(ch->ifname);
129#if ENABLE_FEATURE_NAMEIF_EXTENDED
130 free(ch->bus_info);
131 free(ch->driver);
132#endif
133 free(ch->mac);
134 free(ch);
135};
136#else
137void delete_eth_table(ethtable_t *ch);
138#endif
139
126int nameif_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 140int nameif_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
127int nameif_main(int argc, char **argv) 141int nameif_main(int argc, char **argv)
128{ 142{
@@ -156,14 +170,13 @@ int nameif_main(int argc, char **argv)
156 char *next; 170 char *next;
157 171
158 line_ptr = skip_whitespace(line); 172 line_ptr = skip_whitespace(line);
159 if ((line_ptr[0] == '#') || (line_ptr[0] == '\n')) { 173 if ((line_ptr[0] == '#') || (line_ptr[0] == '\n'))
160 free(line); 174 goto read_next_line;
161 continue;
162 }
163 next = skip_non_whitespace(line_ptr); 175 next = skip_non_whitespace(line_ptr);
164 if (*next) 176 if (*next)
165 *next++ = '\0'; 177 *next++ = '\0';
166 prepend_new_eth_table(&clist, line_ptr, next); 178 prepend_new_eth_table(&clist, line_ptr, next);
179 read_next_line:
167 free(line); 180 free(line);
168 } 181 }
169 fclose(ifh); 182 fclose(ifh);
@@ -187,7 +200,7 @@ int nameif_main(int argc, char **argv)
187 200
188 /* Find the current interface name and copy it to ifr.ifr_name */ 201 /* Find the current interface name and copy it to ifr.ifr_name */
189 line_ptr = skip_whitespace(line); 202 line_ptr = skip_whitespace(line);
190 *skip_non_whitespace(line_ptr) = '\0'; 203 *strpbrk(line_ptr, " \t\n:") = '\0';
191 204
192 memset(&ifr, 0, sizeof(struct ifreq)); 205 memset(&ifr, 0, sizeof(struct ifreq));
193 strncpy(ifr.ifr_name, line_ptr, sizeof(ifr.ifr_name)); 206 strncpy(ifr.ifr_name, line_ptr, sizeof(ifr.ifr_name));
@@ -230,16 +243,15 @@ int nameif_main(int argc, char **argv)
230 else 243 else
231 clist = ch->next; 244 clist = ch->next;
232 if (ch->next != NULL) 245 if (ch->next != NULL)
233 ch->next->prev = ch->prev; 246 ch->next->prev = ch->prev;
234 if (ENABLE_FEATURE_CLEAN_UP) { 247 if (ENABLE_FEATURE_CLEAN_UP)
235 free(ch->ifname); 248 delete_eth_table(ch);
236 free(ch->mac);
237 free(ch);
238 }
239 next_line: 249 next_line:
240 free(line); 250 free(line);
241 } 251 }
242 if (ENABLE_FEATURE_CLEAN_UP) { 252 if (ENABLE_FEATURE_CLEAN_UP) {
253 for (ch = clist; ch; ch = ch->next)
254 delete_eth_table(ch);
243 fclose(ifh); 255 fclose(ifh);
244 }; 256 };
245 257