diff options
author | Maxim Kryzhanovsky <xmaks@email.cz> | 2010-03-29 09:09:05 +0200 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2010-03-29 09:09:05 +0200 |
commit | fcb84c8bd2bba23c1e43145775b831b42f674f7b (patch) | |
tree | 4c4069e419d668821e9d46b4672880106b4f6d13 | |
parent | 603884b07e4ffffa1c00c5982d7583f6a136f1c2 (diff) | |
download | busybox-w32-fcb84c8bd2bba23c1e43145775b831b42f674f7b.tar.gz busybox-w32-fcb84c8bd2bba23c1e43145775b831b42f674f7b.tar.bz2 busybox-w32-fcb84c8bd2bba23c1e43145775b831b42f674f7b.zip |
ifplugd: code shrink
text data bss dec hex filename
840048 453 6828 847329 cede1 busybox_old
839915 453 6828 847196 ced5c busybox_unstripped
Signed-off-by: Maxim Kryzhanovsky <xmaks@email.cz>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | networking/ifplugd.c | 88 |
1 files changed, 34 insertions, 54 deletions
diff --git a/networking/ifplugd.c b/networking/ifplugd.c index 3567dea03..373910863 100644 --- a/networking/ifplugd.c +++ b/networking/ifplugd.c | |||
@@ -214,7 +214,7 @@ static int network_ioctl(int request, void* data, const char *errmsg) | |||
214 | { | 214 | { |
215 | int r = ioctl(ioctl_fd, request, data); | 215 | int r = ioctl(ioctl_fd, request, data); |
216 | if (r < 0 && errmsg) | 216 | if (r < 0 && errmsg) |
217 | bb_perror_msg(errmsg); | 217 | bb_perror_msg("%s failed", errmsg); |
218 | return r; | 218 | return r; |
219 | } | 219 | } |
220 | 220 | ||
@@ -239,7 +239,7 @@ static void up_iface(void) | |||
239 | return; | 239 | return; |
240 | 240 | ||
241 | set_ifreq_to_ifname(&ifrequest); | 241 | set_ifreq_to_ifname(&ifrequest); |
242 | if (network_ioctl(SIOCGIFFLAGS, &ifrequest, "can't get interface flags") < 0) { | 242 | if (network_ioctl(SIOCGIFFLAGS, &ifrequest, "getting interface flags") < 0) { |
243 | G.iface_exists = 0; | 243 | G.iface_exists = 0; |
244 | return; | 244 | return; |
245 | } | 245 | } |
@@ -248,7 +248,7 @@ static void up_iface(void) | |||
248 | ifrequest.ifr_flags |= IFF_UP; | 248 | ifrequest.ifr_flags |= IFF_UP; |
249 | /* Let user know we mess up with interface */ | 249 | /* Let user know we mess up with interface */ |
250 | bb_error_msg("upping interface"); | 250 | bb_error_msg("upping interface"); |
251 | if (network_ioctl(SIOCSIFFLAGS, &ifrequest, "can't set interface flags") < 0) | 251 | if (network_ioctl(SIOCSIFFLAGS, &ifrequest, "setting interface flags") < 0) |
252 | xfunc_die(); | 252 | xfunc_die(); |
253 | } | 253 | } |
254 | 254 | ||
@@ -307,13 +307,13 @@ static smallint detect_link_mii(void) | |||
307 | 307 | ||
308 | set_ifreq_to_ifname(&ifreq); | 308 | set_ifreq_to_ifname(&ifreq); |
309 | 309 | ||
310 | if (network_ioctl(SIOCGMIIPHY, &ifreq, "SIOCGMIIPHY failed") < 0) { | 310 | if (network_ioctl(SIOCGMIIPHY, &ifreq, "SIOCGMIIPHY") < 0) { |
311 | return IFSTATUS_ERR; | 311 | return IFSTATUS_ERR; |
312 | } | 312 | } |
313 | 313 | ||
314 | mii->reg_num = 1; | 314 | mii->reg_num = 1; |
315 | 315 | ||
316 | if (network_ioctl(SIOCGMIIREG, &ifreq, "SIOCGMIIREG failed") < 0) { | 316 | if (network_ioctl(SIOCGMIIREG, &ifreq, "SIOCGMIIREG") < 0) { |
317 | return IFSTATUS_ERR; | 317 | return IFSTATUS_ERR; |
318 | } | 318 | } |
319 | 319 | ||
@@ -327,13 +327,13 @@ static smallint detect_link_priv(void) | |||
327 | 327 | ||
328 | set_ifreq_to_ifname(&ifreq); | 328 | set_ifreq_to_ifname(&ifreq); |
329 | 329 | ||
330 | if (network_ioctl(SIOCDEVPRIVATE, &ifreq, "SIOCDEVPRIVATE failed") < 0) { | 330 | if (network_ioctl(SIOCDEVPRIVATE, &ifreq, "SIOCDEVPRIVATE") < 0) { |
331 | return IFSTATUS_ERR; | 331 | return IFSTATUS_ERR; |
332 | } | 332 | } |
333 | 333 | ||
334 | mii->reg_num = 1; | 334 | mii->reg_num = 1; |
335 | 335 | ||
336 | if (network_ioctl(SIOCDEVPRIVATE+1, &ifreq, "SIOCDEVPRIVATE+1 failed") < 0) { | 336 | if (network_ioctl(SIOCDEVPRIVATE+1, &ifreq, "SIOCDEVPRIVATE+1") < 0) { |
337 | return IFSTATUS_ERR; | 337 | return IFSTATUS_ERR; |
338 | } | 338 | } |
339 | 339 | ||
@@ -350,7 +350,7 @@ static smallint detect_link_ethtool(void) | |||
350 | edata.cmd = ETHTOOL_GLINK; | 350 | edata.cmd = ETHTOOL_GLINK; |
351 | ifreq.ifr_data = (void*) &edata; | 351 | ifreq.ifr_data = (void*) &edata; |
352 | 352 | ||
353 | if (network_ioctl(SIOCETHTOOL, &ifreq, "ETHTOOL_GLINK failed") < 0) { | 353 | if (network_ioctl(SIOCETHTOOL, &ifreq, "ETHTOOL_GLINK") < 0) { |
354 | return IFSTATUS_ERR; | 354 | return IFSTATUS_ERR; |
355 | } | 355 | } |
356 | 356 | ||
@@ -363,7 +363,7 @@ static smallint detect_link_iff(void) | |||
363 | 363 | ||
364 | set_ifreq_to_ifname(&ifreq); | 364 | set_ifreq_to_ifname(&ifreq); |
365 | 365 | ||
366 | if (network_ioctl(SIOCGIFFLAGS, &ifreq, "SIOCGIFFLAGS failed") < 0) { | 366 | if (network_ioctl(SIOCGIFFLAGS, &ifreq, "SIOCGIFFLAGS") < 0) { |
367 | return IFSTATUS_ERR; | 367 | return IFSTATUS_ERR; |
368 | } | 368 | } |
369 | 369 | ||
@@ -381,20 +381,21 @@ static smallint detect_link_iff(void) | |||
381 | 381 | ||
382 | static smallint detect_link_wlan(void) | 382 | static smallint detect_link_wlan(void) |
383 | { | 383 | { |
384 | int i; | ||
384 | struct iwreq iwrequest; | 385 | struct iwreq iwrequest; |
385 | uint8_t mac[ETH_ALEN]; | 386 | uint8_t mac[ETH_ALEN]; |
386 | 387 | ||
387 | memset(&iwrequest, 0, sizeof(struct iwreq)); | 388 | memset(&iwrequest, 0, sizeof(iwrequest)); |
388 | strncpy_IFNAMSIZ(iwrequest.ifr_ifrn.ifrn_name, G.iface); | 389 | strncpy_IFNAMSIZ(iwrequest.ifr_ifrn.ifrn_name, G.iface); |
389 | 390 | ||
390 | if (network_ioctl(SIOCGIWAP, &iwrequest, "SIOCGIWAP failed") < 0) { | 391 | if (network_ioctl(SIOCGIWAP, &iwrequest, "SIOCGIWAP") < 0) { |
391 | return IFSTATUS_ERR; | 392 | return IFSTATUS_ERR; |
392 | } | 393 | } |
393 | 394 | ||
394 | memcpy(mac, &(iwrequest.u.ap_addr.sa_data), ETH_ALEN); | 395 | memcpy(mac, &iwrequest.u.ap_addr.sa_data, ETH_ALEN); |
395 | 396 | ||
396 | if (mac[0] == 0xFF || mac[0] == 0x44 || mac[0] == 0x00) { | 397 | if (mac[0] == 0xFF || mac[0] == 0x44 || mac[0] == 0x00) { |
397 | for (int i = 1; i < ETH_ALEN; ++i) { | 398 | for (i = 1; i < ETH_ALEN; ++i) { |
398 | if (mac[i] != mac[0]) | 399 | if (mac[i] != mac[0]) |
399 | return IFSTATUS_UP; | 400 | return IFSTATUS_UP; |
400 | } | 401 | } |
@@ -406,7 +407,17 @@ static smallint detect_link_wlan(void) | |||
406 | 407 | ||
407 | static smallint detect_link_auto(void) | 408 | static smallint detect_link_auto(void) |
408 | { | 409 | { |
409 | const char *method; | 410 | static const struct { |
411 | const char *name; | ||
412 | smallint (*func)(void); | ||
413 | } method[] = { | ||
414 | { "SIOCETHTOOL" , &detect_link_ethtool }, | ||
415 | { "SIOCGMIIPHY" , &detect_link_mii }, | ||
416 | { "SIOCDEVPRIVATE" , &detect_link_priv }, | ||
417 | { "wireless extension", &detect_link_wlan }, | ||
418 | { "IFF_RUNNING" , &detect_link_iff }, | ||
419 | }; | ||
420 | int i; | ||
410 | smallint iface_status; | 421 | smallint iface_status; |
411 | smallint sv_logmode; | 422 | smallint sv_logmode; |
412 | 423 | ||
@@ -417,48 +428,17 @@ static smallint detect_link_auto(void) | |||
417 | } | 428 | } |
418 | 429 | ||
419 | sv_logmode = logmode; | 430 | sv_logmode = logmode; |
420 | logmode = LOGMODE_NONE; | 431 | for (i = 0; i < ARRAY_SIZE(method); i++) { |
421 | 432 | logmode = LOGMODE_NONE; | |
422 | iface_status = detect_link_ethtool(); | 433 | iface_status = method[i].func(); |
423 | if (iface_status != IFSTATUS_ERR) { | ||
424 | G.cached_detect_link_func = detect_link_ethtool; | ||
425 | method = "SIOCETHTOOL"; | ||
426 | found_method: | ||
427 | logmode = sv_logmode; | 434 | logmode = sv_logmode; |
428 | bb_error_msg("using %s detection mode", method); | 435 | if (iface_status != IFSTATUS_ERR) { |
429 | return iface_status; | 436 | G.cached_detect_link_func = method[i].func; |
430 | } | 437 | bb_error_msg("using %s detection mode", method[i].name); |
431 | 438 | break; | |
432 | iface_status = detect_link_mii(); | 439 | } |
433 | if (iface_status != IFSTATUS_ERR) { | ||
434 | G.cached_detect_link_func = detect_link_mii; | ||
435 | method = "SIOCGMIIPHY"; | ||
436 | goto found_method; | ||
437 | } | ||
438 | |||
439 | iface_status = detect_link_priv(); | ||
440 | if (iface_status != IFSTATUS_ERR) { | ||
441 | G.cached_detect_link_func = detect_link_priv; | ||
442 | method = "SIOCDEVPRIVATE"; | ||
443 | goto found_method; | ||
444 | } | ||
445 | |||
446 | iface_status = detect_link_wlan(); | ||
447 | if (iface_status != IFSTATUS_ERR) { | ||
448 | G.cached_detect_link_func = detect_link_wlan; | ||
449 | method = "wireless extension"; | ||
450 | goto found_method; | ||
451 | } | ||
452 | |||
453 | iface_status = detect_link_iff(); | ||
454 | if (iface_status != IFSTATUS_ERR) { | ||
455 | G.cached_detect_link_func = detect_link_iff; | ||
456 | method = "IFF_RUNNING"; | ||
457 | goto found_method; | ||
458 | } | 440 | } |
459 | 441 | return iface_status; | |
460 | logmode = sv_logmode; | ||
461 | return iface_status; /* IFSTATUS_ERR */ | ||
462 | } | 442 | } |
463 | 443 | ||
464 | static smallint detect_link(void) | 444 | static smallint detect_link(void) |