diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-08 08:01:12 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2008-06-08 08:01:12 +0000 |
commit | 048897c9712f99555e607c11732ad761e4397c48 (patch) | |
tree | ea29283fd590a6379e4caeed7307010cd13d879c | |
parent | 52a8d975da9c6b26fc7f6323a78556208cf0cd64 (diff) | |
download | busybox-w32-048897c9712f99555e607c11732ad761e4397c48.tar.gz busybox-w32-048897c9712f99555e607c11732ad761e4397c48.tar.bz2 busybox-w32-048897c9712f99555e607c11732ad761e4397c48.zip |
ifenslave: small shrink
text data bss dec hex filename
809731 624 7060 817415 c7907 busybox_old
809629 624 7060 817313 c78a1 busybox_unstripped
-rw-r--r-- | networking/ifenslave.c | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/networking/ifenslave.c b/networking/ifenslave.c index 1e983f2ba..fed186967 100644 --- a/networking/ifenslave.c +++ b/networking/ifenslave.c | |||
@@ -261,9 +261,7 @@ static void change_active(char *master_ifname, char *slave_ifname) | |||
261 | struct ifreq ifr; | 261 | struct ifreq ifr; |
262 | 262 | ||
263 | if (!(slave.flags.ifr_flags & IFF_SLAVE)) { | 263 | if (!(slave.flags.ifr_flags & IFF_SLAVE)) { |
264 | bb_error_msg_and_die( | 264 | bb_error_msg_and_die("%s is not a slave", slave_ifname); |
265 | "%s is not a slave", | ||
266 | slave_ifname); | ||
267 | } | 265 | } |
268 | 266 | ||
269 | strncpy_IFNAMSIZ(ifr.ifr_slave, slave_ifname); | 267 | strncpy_IFNAMSIZ(ifr.ifr_slave, slave_ifname); |
@@ -402,8 +400,7 @@ static int release(char *master_ifname, char *slave_ifname) | |||
402 | int res = 0; | 400 | int res = 0; |
403 | 401 | ||
404 | if (!(slave.flags.ifr_flags & IFF_SLAVE)) { | 402 | if (!(slave.flags.ifr_flags & IFF_SLAVE)) { |
405 | bb_error_msg("%s is not a slave", | 403 | bb_error_msg("%s is not a slave", slave_ifname); |
406 | slave_ifname); | ||
407 | return 1; | 404 | return 1; |
408 | } | 405 | } |
409 | 406 | ||
@@ -462,18 +459,19 @@ int ifenslave_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
462 | }; | 459 | }; |
463 | #if ENABLE_GETOPT_LONG | 460 | #if ENABLE_GETOPT_LONG |
464 | static const char ifenslave_longopts[] ALIGN1 = | 461 | static const char ifenslave_longopts[] ALIGN1 = |
465 | "change-active\0" No_argument "c" | 462 | "change-active\0" No_argument "c" |
466 | "detach\0" No_argument "d" | 463 | "detach\0" No_argument "d" |
467 | "force\0" No_argument "f" | 464 | "force\0" No_argument "f" |
465 | /* "all-interfaces\0" No_argument "a" */ | ||
468 | ; | 466 | ; |
469 | 467 | ||
470 | applet_long_options = ifenslave_longopts; | 468 | applet_long_options = ifenslave_longopts; |
471 | #endif | 469 | #endif |
472 | INIT_G(); | 470 | INIT_G(); |
473 | 471 | ||
474 | opt = getopt32(argv, "cdf"); | 472 | opt = getopt32(argv, "cdfa"); |
475 | argv += optind; | 473 | argv += optind; |
476 | if (opt & (opt-1)) /* options check */ | 474 | if (opt & (opt-1)) /* Only one option can be given */ |
477 | bb_show_usage(); | 475 | bb_show_usage(); |
478 | 476 | ||
479 | master_ifname = *argv++; | 477 | master_ifname = *argv++; |
@@ -505,25 +503,25 @@ int ifenslave_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
505 | return EXIT_SUCCESS; | 503 | return EXIT_SUCCESS; |
506 | } | 504 | } |
507 | 505 | ||
508 | res = get_if_settings(master_ifname, &master); | 506 | if (get_if_settings(master_ifname, &master)) { |
509 | if (res) { | ||
510 | /* Probably a good reason not to go on */ | 507 | /* Probably a good reason not to go on */ |
511 | bb_perror_msg_and_die("%s: can't get settings", master_ifname); | 508 | bb_perror_msg_and_die("%s: can't get settings", master_ifname); |
512 | } | 509 | } |
513 | 510 | ||
514 | /* check if master is indeed a master; | 511 | /* Check if master is indeed a master; |
515 | * if not then fail any operation | 512 | * if not then fail any operation |
516 | */ | 513 | */ |
517 | if (!(master.flags.ifr_flags & IFF_MASTER)) | 514 | if (!(master.flags.ifr_flags & IFF_MASTER)) |
518 | bb_error_msg_and_die("%s is not a master", master_ifname); | 515 | bb_error_msg_and_die("%s is not a master", master_ifname); |
519 | 516 | ||
520 | /* check if master is up; if not then fail any operation */ | 517 | /* Check if master is up; if not then fail any operation */ |
521 | if (!(master.flags.ifr_flags & IFF_UP)) | 518 | if (!(master.flags.ifr_flags & IFF_UP)) |
522 | bb_error_msg_and_die("%s is not up", master_ifname); | 519 | bb_error_msg_and_die("%s is not up", master_ifname); |
523 | 520 | ||
524 | /* No opts: neither -c[hange] nor -d[etach] -> it's "enslave" then; | 521 | #ifdef WHY_BOTHER |
525 | * and -f[orce] is not there too */ | 522 | /* Neither -c[hange] nor -d[etach] -> it's "enslave" then; |
526 | if (!opt) { | 523 | * and -f[orce] is not there too. Check that it's ethernet. */ |
524 | if (!(opt & (OPT_d|OPT_c|OPT_f)) { | ||
527 | /* The family '1' is ARPHRD_ETHER for ethernet. */ | 525 | /* The family '1' is ARPHRD_ETHER for ethernet. */ |
528 | if (master.hwaddr.ifr_hwaddr.sa_family != 1) { | 526 | if (master.hwaddr.ifr_hwaddr.sa_family != 1) { |
529 | bb_error_msg_and_die( | 527 | bb_error_msg_and_die( |
@@ -531,10 +529,11 @@ int ifenslave_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
531 | master_ifname); | 529 | master_ifname); |
532 | } | 530 | } |
533 | } | 531 | } |
532 | #endif | ||
534 | 533 | ||
535 | /* Accepts only one slave */ | 534 | /* Accepts only one slave */ |
536 | if (opt & OPT_c) { | 535 | if (opt & OPT_c) { |
537 | /* change active slave */ | 536 | /* Change active slave */ |
538 | if (get_slave_flags(slave_ifname)) { | 537 | if (get_slave_flags(slave_ifname)) { |
539 | bb_perror_msg_and_die( | 538 | bb_perror_msg_and_die( |
540 | "%s: can't get flags", slave_ifname); | 539 | "%s: can't get flags", slave_ifname); |
@@ -543,11 +542,11 @@ int ifenslave_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
543 | return EXIT_SUCCESS; | 542 | return EXIT_SUCCESS; |
544 | } | 543 | } |
545 | 544 | ||
546 | /* Accept multiple slaves */ | 545 | /* Accepts multiple slaves */ |
547 | res = 0; | 546 | res = 0; |
548 | do { | 547 | do { |
549 | if (opt & OPT_d) { | 548 | if (opt & OPT_d) { |
550 | /* detach a slave interface from the master */ | 549 | /* Detach a slave interface from the master */ |
551 | rv = get_slave_flags(slave_ifname); | 550 | rv = get_slave_flags(slave_ifname); |
552 | if (rv) { | 551 | if (rv) { |
553 | /* Can't work with this slave, */ | 552 | /* Can't work with this slave, */ |
@@ -560,14 +559,12 @@ int ifenslave_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
560 | } | 559 | } |
561 | rv = release(master_ifname, slave_ifname); | 560 | rv = release(master_ifname, slave_ifname); |
562 | if (rv) { | 561 | if (rv) { |
563 | bb_perror_msg( | 562 | bb_perror_msg("can't release %s from %s", |
564 | "master %s, slave %s: " | 563 | slave_ifname, master_ifname); |
565 | "can't release", | ||
566 | master_ifname, slave_ifname); | ||
567 | res = rv; | 564 | res = rv; |
568 | } | 565 | } |
569 | } else { | 566 | } else { |
570 | /* attach a slave interface to the master */ | 567 | /* Attach a slave interface to the master */ |
571 | rv = get_if_settings(slave_ifname, &slave); | 568 | rv = get_if_settings(slave_ifname, &slave); |
572 | if (rv) { | 569 | if (rv) { |
573 | /* Can't work with this slave, */ | 570 | /* Can't work with this slave, */ |
@@ -580,10 +577,8 @@ int ifenslave_main(int argc ATTRIBUTE_UNUSED, char **argv) | |||
580 | } | 577 | } |
581 | rv = enslave(master_ifname, slave_ifname); | 578 | rv = enslave(master_ifname, slave_ifname); |
582 | if (rv) { | 579 | if (rv) { |
583 | bb_perror_msg( | 580 | bb_perror_msg("can't enslave %s to %s", |
584 | "master %s, slave %s: " | 581 | slave_ifname, master_ifname); |
585 | "can't enslave", | ||
586 | master_ifname, slave_ifname); | ||
587 | res = rv; | 582 | res = rv; |
588 | } | 583 | } |
589 | } | 584 | } |