diff options
| author | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2008-01-13 15:23:27 +0000 |
|---|---|---|
| committer | Bernhard Reutner-Fischer <rep.dot.nop@gmail.com> | 2008-01-13 15:23:27 +0000 |
| commit | d27d925a6d83a2831ccccb48ca24cd77768cde1a (patch) | |
| tree | 4627274950722fccd8b5e583314c7c0d9482a88f | |
| parent | 481ce92bdffe1d5b6f8e3c9814cf2b62ca817c91 (diff) | |
| download | busybox-w32-d27d925a6d83a2831ccccb48ca24cd77768cde1a.tar.gz busybox-w32-d27d925a6d83a2831ccccb48ca24cd77768cde1a.tar.bz2 busybox-w32-d27d925a6d83a2831ccccb48ca24cd77768cde1a.zip | |
- new applet brctl
text data bss dec hex filename
289 20 0 309 135 networking/brctl.o
335 23 0 358 166 networking/brctl-verbose-ops.o
| -rw-r--r-- | include/applets.h | 1 | ||||
| -rw-r--r-- | include/usage.h | 10 | ||||
| -rw-r--r-- | networking/Config.in | 6 | ||||
| -rw-r--r-- | networking/Kbuild | 1 | ||||
| -rw-r--r-- | networking/brctl.c | 87 |
5 files changed, 105 insertions, 0 deletions
diff --git a/include/applets.h b/include/applets.h index 4934d18cd..830ff2842 100644 --- a/include/applets.h +++ b/include/applets.h | |||
| @@ -86,6 +86,7 @@ USE_AWK(APPLET_NOEXEC(awk, awk, _BB_DIR_USR_BIN, _BB_SUID_NEVER, awk)) | |||
| 86 | USE_BASENAME(APPLET_NOFORK(basename, basename, _BB_DIR_USR_BIN, _BB_SUID_NEVER, basename)) | 86 | USE_BASENAME(APPLET_NOFORK(basename, basename, _BB_DIR_USR_BIN, _BB_SUID_NEVER, basename)) |
| 87 | USE_BBCONFIG(APPLET(bbconfig, _BB_DIR_BIN, _BB_SUID_NEVER)) | 87 | USE_BBCONFIG(APPLET(bbconfig, _BB_DIR_BIN, _BB_SUID_NEVER)) |
| 88 | //USE_BBSH(APPLET(bbsh, _BB_DIR_BIN, _BB_SUID_NEVER)) | 88 | //USE_BBSH(APPLET(bbsh, _BB_DIR_BIN, _BB_SUID_NEVER)) |
| 89 | USE_BRCTL(APPLET(brctl, _BB_DIR_USR_SBIN, _BB_SUID_NEVER)) | ||
| 89 | USE_BUNZIP2(APPLET(bunzip2, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 90 | USE_BUNZIP2(APPLET(bunzip2, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
| 90 | USE_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, _BB_DIR_USR_BIN, _BB_SUID_NEVER, bzcat)) | 91 | USE_BUNZIP2(APPLET_ODDNAME(bzcat, bunzip2, _BB_DIR_USR_BIN, _BB_SUID_NEVER, bzcat)) |
| 91 | USE_BZIP2(APPLET(bzip2, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) | 92 | USE_BZIP2(APPLET(bzip2, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) |
diff --git a/include/usage.h b/include/usage.h index 464fb614b..cb8bd2a8d 100644 --- a/include/usage.h +++ b/include/usage.h | |||
| @@ -119,6 +119,16 @@ | |||
| 119 | "$ basename /foo/bar.txt .txt\n" \ | 119 | "$ basename /foo/bar.txt .txt\n" \ |
| 120 | "bar" | 120 | "bar" |
| 121 | 121 | ||
| 122 | #define brctl_trivial_usage \ | ||
| 123 | "COMMAND [BRIDGE [INTERFACE]]" | ||
| 124 | #define brctl_full_usage \ | ||
| 125 | "Manage ethernet bridges." \ | ||
| 126 | "\n\nCommands:\n" \ | ||
| 127 | " addbr <bridge> Create <bridge>\n" \ | ||
| 128 | " delbr <bridge> Delete <bridge>\n" \ | ||
| 129 | " addif <bridge> <iface> Add <iface> to <bridge>\n" \ | ||
| 130 | " delif <bridge> <iface> Delete <iface> from <bridge>" | ||
| 131 | |||
| 122 | #define bunzip2_trivial_usage \ | 132 | #define bunzip2_trivial_usage \ |
| 123 | "[OPTION]... [FILE]" | 133 | "[OPTION]... [FILE]" |
| 124 | #define bunzip2_full_usage \ | 134 | #define bunzip2_full_usage \ |
diff --git a/networking/Config.in b/networking/Config.in index 5a766046a..83579bc4f 100644 --- a/networking/Config.in +++ b/networking/Config.in | |||
| @@ -47,6 +47,12 @@ config ARPING | |||
| 47 | help | 47 | help |
| 48 | Ping hosts by ARP packets. | 48 | Ping hosts by ARP packets. |
| 49 | 49 | ||
| 50 | config BRCTL | ||
| 51 | bool "brctl" | ||
| 52 | default n | ||
| 53 | help | ||
| 54 | Manage ethernet bridges. | ||
| 55 | |||
| 50 | config DNSD | 56 | config DNSD |
| 51 | bool "dnsd" | 57 | bool "dnsd" |
| 52 | default n | 58 | default n |
diff --git a/networking/Kbuild b/networking/Kbuild index 23968a833..3bcbe0242 100644 --- a/networking/Kbuild +++ b/networking/Kbuild | |||
| @@ -7,6 +7,7 @@ | |||
| 7 | lib-y:= | 7 | lib-y:= |
| 8 | lib-$(CONFIG_ARP) += arp.o interface.o | 8 | lib-$(CONFIG_ARP) += arp.o interface.o |
| 9 | lib-$(CONFIG_ARPING) += arping.o | 9 | lib-$(CONFIG_ARPING) += arping.o |
| 10 | lib-$(CONFIG_BRCTL) += brctl.o | ||
| 10 | lib-$(CONFIG_DNSD) += dnsd.o | 11 | lib-$(CONFIG_DNSD) += dnsd.o |
| 11 | lib-$(CONFIG_ETHER_WAKE) += ether-wake.o | 12 | lib-$(CONFIG_ETHER_WAKE) += ether-wake.o |
| 12 | lib-$(CONFIG_FAKEIDENTD) += isrv_identd.o isrv.o | 13 | lib-$(CONFIG_FAKEIDENTD) += isrv_identd.o isrv.o |
diff --git a/networking/brctl.c b/networking/brctl.c new file mode 100644 index 000000000..21d528f91 --- /dev/null +++ b/networking/brctl.c | |||
| @@ -0,0 +1,87 @@ | |||
| 1 | /* vi: set sw=4 ts=4: */ | ||
| 2 | /* | ||
| 3 | * Small implementation of brctl for busybox. | ||
| 4 | * | ||
| 5 | * Copyright (C) 2008 by Bernhard Fischer | ||
| 6 | * | ||
| 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. | ||
| 8 | */ | ||
| 9 | #include "libbb.h" | ||
| 10 | #include <linux/sockios.h> | ||
| 11 | #include <net/if.h> | ||
| 12 | |||
| 13 | #ifdef ENABLE_FEATURE_BRCTL_SHOW | ||
| 14 | #error Remove these | ||
| 15 | #endif | ||
| 16 | #define ENABLE_FEATURE_BRCTL_SHOW 0 | ||
| 17 | #define USE_FEATURE_BRCTL_SHOW(...) | ||
| 18 | |||
| 19 | |||
| 20 | /* Fancy diagnostics -- printing add/del -- costs 49 bytes. */ | ||
| 21 | #if 0 | ||
| 22 | #define BRCTL_VERBOSE(...) __VA_ARGS__ | ||
| 23 | #else | ||
| 24 | #define BRCTL_VERBOSE(...) | ||
| 25 | #endif | ||
| 26 | |||
| 27 | int brctl_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | ||
| 28 | int brctl_main(int argc, char **argv) | ||
| 29 | { | ||
| 30 | int fd; | ||
| 31 | static const char keywords[] ALIGN1 = | ||
| 32 | "addbr\0" "delbr\0" "addif\0" "delif\0" | ||
| 33 | USE_FEATURE_BRCTL_SHOW("show\0"); | ||
| 34 | enum { ARG_addbr = 1, ARG_delbr, ARG_addif, ARG_delif | ||
| 35 | USE_FEATURE_BRCTL_SHOW(, ARG_show) }; | ||
| 36 | smalluint key; | ||
| 37 | static char info[] = BRCTL_VERBOSE("%s ")"bridge %s\0 iface %s"; | ||
| 38 | |||
| 39 | argv++; | ||
| 40 | while (*argv) { | ||
| 41 | BRCTL_VERBOSE(char *op;) | ||
| 42 | |||
| 43 | key = index_in_strings(keywords, *argv) + 1; | ||
| 44 | if (key == 0) /* no match found in keywords array, bail out. */ | ||
| 45 | bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); | ||
| 46 | argv++; | ||
| 47 | #if ENABLE_FEATURE_BRCTL_SHOW | ||
| 48 | if (key == ARG_show) { /* show */ | ||
| 49 | ; | ||
| 50 | } | ||
| 51 | #endif | ||
| 52 | BRCTL_VERBOSE(op = (char*)((key % 2) ? "add" : "del");) | ||
| 53 | fd = xsocket(AF_INET, SOCK_STREAM, 0); | ||
| 54 | if (key < 3) {/* addbr or delbr */ | ||
| 55 | char *br; | ||
| 56 | |||
| 57 | br = *(argv++); | ||
| 58 | if (ioctl(fd, key == ARG_addbr ? SIOCBRADDBR : SIOCBRDELBR, br) < 0) | ||
| 59 | { | ||
| 60 | info[9 BRCTL_VERBOSE(+3)] = '\0'; | ||
| 61 | bb_perror_msg_and_die(info, BRCTL_VERBOSE(op,) br); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | if (key > 2) { /* addif or delif */ | ||
| 65 | struct ifreq ifr; | ||
| 66 | char *br, *brif; | ||
| 67 | |||
| 68 | br = *(argv++); | ||
| 69 | if (!*argv) | ||
| 70 | bb_show_usage(); | ||
| 71 | brif = *(argv++); | ||
| 72 | |||
| 73 | if (!(ifr.ifr_ifindex = if_nametoindex(brif))) { | ||
| 74 | bb_perror_msg_and_die(info+11 BRCTL_VERBOSE(+3), brif); | ||
| 75 | } | ||
| 76 | safe_strncpy(ifr.ifr_name, br, IFNAMSIZ); | ||
| 77 | if (ioctl(fd, | ||
| 78 | key == ARG_addif ? SIOCBRADDIF : SIOCBRDELIF, &ifr) < 0) { | ||
| 79 | info[9 BRCTL_VERBOSE(+3)] = ','; | ||
| 80 | bb_perror_msg_and_die (info, BRCTL_VERBOSE(op,) br, brif); | ||
| 81 | } | ||
| 82 | } | ||
| 83 | if (ENABLE_FEATURE_CLEAN_UP) | ||
| 84 | close(fd); | ||
| 85 | } | ||
| 86 | return EXIT_SUCCESS; | ||
| 87 | } | ||
