Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
| 2 | /* |
| 3 | * Small implementation of brctl for busybox. |
| 4 | * |
Bernhard Reutner-Fischer | 6c4dade | 2008-09-25 12:13:34 +0000 | [diff] [blame] | 5 | * Copyright (C) 2008 by Bernhard Reutner-Fischer |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 6 | * |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 7 | * Some helper functions from bridge-utils are |
| 8 | * Copyright (C) 2000 Lennert Buytenhek |
| 9 | * |
Denys Vlasenko | 0ef64bd | 2010-08-16 20:14:46 +0200 | [diff] [blame] | 10 | * Licensed under GPLv2 or later, see file LICENSE in this source tree. |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 11 | */ |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 12 | /* This applet currently uses only the ioctl interface and no sysfs at all. |
| 13 | * At the time of this writing this was considered a feature. |
| 14 | */ |
Pere Orga | 5bc8c00 | 2011-04-11 03:29:49 +0200 | [diff] [blame] | 15 | |
| 16 | //usage:#define brctl_trivial_usage |
| 17 | //usage: "COMMAND [BRIDGE [INTERFACE]]" |
| 18 | //usage:#define brctl_full_usage "\n\n" |
| 19 | //usage: "Manage ethernet bridges\n" |
| 20 | //usage: "\nCommands:" |
| 21 | //usage: IF_FEATURE_BRCTL_SHOW( |
| 22 | //usage: "\n show Show a list of bridges" |
| 23 | //usage: ) |
| 24 | //usage: "\n addbr BRIDGE Create BRIDGE" |
| 25 | //usage: "\n delbr BRIDGE Delete BRIDGE" |
| 26 | //usage: "\n addif BRIDGE IFACE Add IFACE to BRIDGE" |
| 27 | //usage: "\n delif BRIDGE IFACE Delete IFACE from BRIDGE" |
| 28 | //usage: IF_FEATURE_BRCTL_FANCY( |
| 29 | //usage: "\n setageing BRIDGE TIME Set ageing time" |
| 30 | //usage: "\n setfd BRIDGE TIME Set bridge forward delay" |
| 31 | //usage: "\n sethello BRIDGE TIME Set hello time" |
| 32 | //usage: "\n setmaxage BRIDGE TIME Set max message age" |
| 33 | //usage: "\n setpathcost BRIDGE COST Set path cost" |
| 34 | //usage: "\n setportprio BRIDGE PRIO Set port priority" |
| 35 | //usage: "\n setbridgeprio BRIDGE PRIO Set bridge priority" |
| 36 | //usage: "\n stp BRIDGE [1/yes/on|0/no/off] STP on/off" |
| 37 | //usage: ) |
| 38 | |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 39 | #include "libbb.h" |
| 40 | #include <linux/sockios.h> |
| 41 | #include <net/if.h> |
| 42 | |
Denis Vlasenko | 802cab1 | 2009-01-31 20:08:21 +0000 | [diff] [blame] | 43 | #ifndef SIOCBRADDBR |
| 44 | # define SIOCBRADDBR BRCTL_ADD_BRIDGE |
| 45 | #endif |
| 46 | #ifndef SIOCBRDELBR |
| 47 | # define SIOCBRDELBR BRCTL_DEL_BRIDGE |
| 48 | #endif |
| 49 | #ifndef SIOCBRADDIF |
| 50 | # define SIOCBRADDIF BRCTL_ADD_IF |
| 51 | #endif |
| 52 | #ifndef SIOCBRDELIF |
| 53 | # define SIOCBRDELIF BRCTL_DEL_IF |
| 54 | #endif |
| 55 | |
| 56 | |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 57 | /* Maximum number of ports supported per bridge interface. */ |
| 58 | #ifndef MAX_PORTS |
Maciek Borzecki | 30ebd7b | 2010-03-23 05:18:38 +0100 | [diff] [blame] | 59 | # define MAX_PORTS 32 |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 60 | #endif |
| 61 | |
| 62 | /* Use internal number parsing and not the "exact" conversion. */ |
| 63 | /* #define BRCTL_USE_INTERNAL 0 */ /* use exact conversion */ |
| 64 | #define BRCTL_USE_INTERNAL 1 |
| 65 | |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 66 | #if ENABLE_FEATURE_BRCTL_FANCY |
Maciek Borzecki | 30ebd7b | 2010-03-23 05:18:38 +0100 | [diff] [blame] | 67 | # include <linux/if_bridge.h> |
Denis Vlasenko | d0a071a | 2008-03-17 09:33:45 +0000 | [diff] [blame] | 68 | |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 69 | /* FIXME: These 4 funcs are not really clean and could be improved */ |
Denis Vlasenko | d0a071a | 2008-03-17 09:33:45 +0000 | [diff] [blame] | 70 | static ALWAYS_INLINE void strtotimeval(struct timeval *tv, |
| 71 | const char *time_str) |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 72 | { |
| 73 | double secs; |
Maciek Borzecki | 30ebd7b | 2010-03-23 05:18:38 +0100 | [diff] [blame] | 74 | # if BRCTL_USE_INTERNAL |
Maciek Borzecki | 46abfc0 | 2010-03-16 12:41:29 +0100 | [diff] [blame] | 75 | char *endptr; |
| 76 | secs = /*bb_*/strtod(time_str, &endptr); |
| 77 | if (endptr == time_str) |
Maciek Borzecki | 30ebd7b | 2010-03-23 05:18:38 +0100 | [diff] [blame] | 78 | # else |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 79 | if (sscanf(time_str, "%lf", &secs) != 1) |
Maciek Borzecki | 30ebd7b | 2010-03-23 05:18:38 +0100 | [diff] [blame] | 80 | # endif |
| 81 | bb_error_msg_and_die(bb_msg_invalid_arg, time_str, "timespec"); |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 82 | tv->tv_sec = secs; |
| 83 | tv->tv_usec = 1000000 * (secs - tv->tv_sec); |
| 84 | } |
| 85 | |
Maciek Borzecki | 30ebd7b | 2010-03-23 05:18:38 +0100 | [diff] [blame] | 86 | static ALWAYS_INLINE unsigned long tv_to_jiffies(const struct timeval *tv) |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 87 | { |
| 88 | unsigned long long jif; |
| 89 | |
| 90 | jif = 1000000ULL * tv->tv_sec + tv->tv_usec; |
| 91 | |
| 92 | return jif/10000; |
| 93 | } |
Denis Vlasenko | d0a071a | 2008-03-17 09:33:45 +0000 | [diff] [blame] | 94 | # if 0 |
Maciek Borzecki | 30ebd7b | 2010-03-23 05:18:38 +0100 | [diff] [blame] | 95 | static void jiffies_to_tv(struct timeval *tv, unsigned long jiffies) |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 96 | { |
| 97 | unsigned long long tvusec; |
| 98 | |
| 99 | tvusec = 10000ULL*jiffies; |
| 100 | tv->tv_sec = tvusec/1000000; |
| 101 | tv->tv_usec = tvusec - 1000000 * tv->tv_sec; |
| 102 | } |
| 103 | # endif |
| 104 | static unsigned long str_to_jiffies(const char *time_str) |
| 105 | { |
| 106 | struct timeval tv; |
| 107 | strtotimeval(&tv, time_str); |
Maciek Borzecki | 30ebd7b | 2010-03-23 05:18:38 +0100 | [diff] [blame] | 108 | return tv_to_jiffies(&tv); |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 109 | } |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 110 | |
| 111 | static void arm_ioctl(unsigned long *args, |
Denis Vlasenko | d0a071a | 2008-03-17 09:33:45 +0000 | [diff] [blame] | 112 | unsigned long arg0, unsigned long arg1, unsigned long arg2) |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 113 | { |
| 114 | args[0] = arg0; |
| 115 | args[1] = arg1; |
| 116 | args[2] = arg2; |
| 117 | args[3] = 0; |
| 118 | } |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 119 | #endif |
| 120 | |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 121 | |
Denis Vlasenko | d0a071a | 2008-03-17 09:33:45 +0000 | [diff] [blame] | 122 | int brctl_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
Denis Vlasenko | a60f84e | 2008-07-05 09:18:54 +0000 | [diff] [blame] | 123 | int brctl_main(int argc UNUSED_PARAM, char **argv) |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 124 | { |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 125 | static const char keywords[] ALIGN1 = |
| 126 | "addbr\0" "delbr\0" "addif\0" "delif\0" |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 127 | IF_FEATURE_BRCTL_FANCY( |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 128 | "stp\0" |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 129 | "setageing\0" "setfd\0" "sethello\0" "setmaxage\0" |
| 130 | "setpathcost\0" "setportprio\0" "setbridgeprio\0" |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 131 | ) |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 132 | IF_FEATURE_BRCTL_SHOW("showmacs\0" "show\0"); |
Denis Vlasenko | d0a071a | 2008-03-17 09:33:45 +0000 | [diff] [blame] | 133 | |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 134 | enum { ARG_addbr = 0, ARG_delbr, ARG_addif, ARG_delif |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 135 | IF_FEATURE_BRCTL_FANCY(, |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 136 | ARG_stp, |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 137 | ARG_setageing, ARG_setfd, ARG_sethello, ARG_setmaxage, |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 138 | ARG_setpathcost, ARG_setportprio, ARG_setbridgeprio |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 139 | ) |
Denis Vlasenko | 5e34ff2 | 2009-04-21 11:09:40 +0000 | [diff] [blame] | 140 | IF_FEATURE_BRCTL_SHOW(, ARG_showmacs, ARG_show) |
Denis Vlasenko | d0a071a | 2008-03-17 09:33:45 +0000 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | int fd; |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 144 | smallint key; |
| 145 | struct ifreq ifr; |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 146 | char *br, *brif; |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 147 | |
| 148 | argv++; |
| 149 | while (*argv) { |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 150 | #if ENABLE_FEATURE_BRCTL_FANCY |
| 151 | int ifidx[MAX_PORTS]; |
| 152 | unsigned long args[4]; |
| 153 | ifr.ifr_data = (char *) &args; |
| 154 | #endif |
| 155 | |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 156 | key = index_in_strings(keywords, *argv); |
| 157 | if (key == -1) /* no match found in keywords array, bail out. */ |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 158 | bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); |
| 159 | argv++; |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 160 | fd = xsocket(AF_INET, SOCK_STREAM, 0); |
| 161 | |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 162 | #if ENABLE_FEATURE_BRCTL_SHOW |
| 163 | if (key == ARG_show) { /* show */ |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 164 | char brname[IFNAMSIZ]; |
| 165 | int bridx[MAX_PORTS]; |
| 166 | int i, num; |
| 167 | arm_ioctl(args, BRCTL_GET_BRIDGES, |
| 168 | (unsigned long) bridx, MAX_PORTS); |
| 169 | num = xioctl(fd, SIOCGIFBR, args); |
| 170 | printf("bridge name\tbridge id\t\tSTP enabled\tinterfaces\n"); |
| 171 | for (i = 0; i < num; i++) { |
| 172 | char ifname[IFNAMSIZ]; |
| 173 | int j, tabs; |
| 174 | struct __bridge_info bi; |
| 175 | unsigned char *x; |
| 176 | |
| 177 | if (!if_indextoname(bridx[i], brname)) |
| 178 | bb_perror_msg_and_die("can't get bridge name for index %d", i); |
Denis Vlasenko | 360d966 | 2008-12-02 18:18:50 +0000 | [diff] [blame] | 179 | strncpy_IFNAMSIZ(ifr.ifr_name, brname); |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 180 | |
| 181 | arm_ioctl(args, BRCTL_GET_BRIDGE_INFO, |
| 182 | (unsigned long) &bi, 0); |
| 183 | xioctl(fd, SIOCDEVPRIVATE, &ifr); |
| 184 | printf("%s\t\t", brname); |
| 185 | |
| 186 | /* print bridge id */ |
| 187 | x = (unsigned char *) &bi.bridge_id; |
| 188 | for (j = 0; j < 8; j++) { |
| 189 | printf("%.2x", x[j]); |
| 190 | if (j == 1) |
| 191 | bb_putchar('.'); |
| 192 | } |
| 193 | printf(bi.stp_enabled ? "\tyes" : "\tno"); |
| 194 | |
| 195 | /* print interface list */ |
| 196 | arm_ioctl(args, BRCTL_GET_PORT_LIST, |
| 197 | (unsigned long) ifidx, MAX_PORTS); |
| 198 | xioctl(fd, SIOCDEVPRIVATE, &ifr); |
| 199 | tabs = 0; |
| 200 | for (j = 0; j < MAX_PORTS; j++) { |
| 201 | if (!ifidx[j]) |
| 202 | continue; |
| 203 | if (!if_indextoname(ifidx[j], ifname)) |
| 204 | bb_perror_msg_and_die("can't get interface name for index %d", j); |
| 205 | if (tabs) |
| 206 | printf("\t\t\t\t\t"); |
| 207 | else |
| 208 | tabs = 1; |
| 209 | printf("\t\t%s\n", ifname); |
| 210 | } |
Denys Vlasenko | e4dcba1 | 2010-10-28 18:57:19 +0200 | [diff] [blame] | 211 | if (!tabs) /* bridge has no interfaces */ |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 212 | bb_putchar('\n'); |
| 213 | } |
| 214 | goto done; |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 215 | } |
| 216 | #endif |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 217 | |
| 218 | if (!*argv) /* all but 'show' need at least one argument */ |
| 219 | bb_show_usage(); |
| 220 | |
Denis Vlasenko | d0a071a | 2008-03-17 09:33:45 +0000 | [diff] [blame] | 221 | br = *argv++; |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 222 | |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 223 | if (key == ARG_addbr || key == ARG_delbr) { /* addbr or delbr */ |
| 224 | ioctl_or_perror_and_die(fd, |
Denis Vlasenko | d0a071a | 2008-03-17 09:33:45 +0000 | [diff] [blame] | 225 | key == ARG_addbr ? SIOCBRADDBR : SIOCBRDELBR, |
| 226 | br, "bridge %s", br); |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 227 | goto done; |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 228 | } |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 229 | |
Bernhard Reutner-Fischer | 0c0f176 | 2010-03-17 11:23:04 +0100 | [diff] [blame] | 230 | if (!*argv) /* all but 'addbr/delbr' need at least two arguments */ |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 231 | bb_show_usage(); |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 232 | |
Denis Vlasenko | 360d966 | 2008-12-02 18:18:50 +0000 | [diff] [blame] | 233 | strncpy_IFNAMSIZ(ifr.ifr_name, br); |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 234 | if (key == ARG_addif || key == ARG_delif) { /* addif or delif */ |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 235 | brif = *argv; |
Denis Vlasenko | d0a071a | 2008-03-17 09:33:45 +0000 | [diff] [blame] | 236 | ifr.ifr_ifindex = if_nametoindex(brif); |
| 237 | if (!ifr.ifr_ifindex) { |
| 238 | bb_perror_msg_and_die("iface %s", brif); |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 239 | } |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 240 | ioctl_or_perror_and_die(fd, |
Denis Vlasenko | d0a071a | 2008-03-17 09:33:45 +0000 | [diff] [blame] | 241 | key == ARG_addif ? SIOCBRADDIF : SIOCBRDELIF, |
| 242 | &ifr, "bridge %s", br); |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 243 | goto done_next_argv; |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 244 | } |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 245 | #if ENABLE_FEATURE_BRCTL_FANCY |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 246 | if (key == ARG_stp) { /* stp */ |
Denys Vlasenko | 8a659f6 | 2010-04-03 00:52:16 +0200 | [diff] [blame] | 247 | static const char no_yes[] ALIGN1 = |
Maciek Borzecki | 30ebd7b | 2010-03-23 05:18:38 +0100 | [diff] [blame] | 248 | "0\0" "off\0" "n\0" "no\0" /* 0 .. 3 */ |
| 249 | "1\0" "on\0" "y\0" "yes\0"; /* 4 .. 7 */ |
Denys Vlasenko | 8a659f6 | 2010-04-03 00:52:16 +0200 | [diff] [blame] | 250 | int onoff = index_in_strings(no_yes, *argv); |
Maciek Borzecki | 30ebd7b | 2010-03-23 05:18:38 +0100 | [diff] [blame] | 251 | if (onoff < 0) |
| 252 | bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); |
| 253 | onoff = (unsigned)onoff / 4; |
| 254 | arm_ioctl(args, BRCTL_SET_BRIDGE_STP_STATE, onoff, 0); |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 255 | goto fire; |
| 256 | } |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 257 | if ((unsigned)(key - ARG_setageing) < 4) { /* time related ops */ |
| 258 | static const uint8_t ops[] ALIGN1 = { |
| 259 | BRCTL_SET_AGEING_TIME, /* ARG_setageing */ |
| 260 | BRCTL_SET_BRIDGE_FORWARD_DELAY, /* ARG_setfd */ |
| 261 | BRCTL_SET_BRIDGE_HELLO_TIME, /* ARG_sethello */ |
| 262 | BRCTL_SET_BRIDGE_MAX_AGE /* ARG_setmaxage */ |
| 263 | }; |
| 264 | arm_ioctl(args, ops[key - ARG_setageing], str_to_jiffies(*argv), 0); |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 265 | goto fire; |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 266 | } |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 267 | if (key == ARG_setpathcost |
Denis Vlasenko | d0a071a | 2008-03-17 09:33:45 +0000 | [diff] [blame] | 268 | || key == ARG_setportprio |
| 269 | || key == ARG_setbridgeprio |
| 270 | ) { |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 271 | static const uint8_t ops[] ALIGN1 = { |
| 272 | BRCTL_SET_PATH_COST, /* ARG_setpathcost */ |
| 273 | BRCTL_SET_PORT_PRIORITY, /* ARG_setportprio */ |
| 274 | BRCTL_SET_BRIDGE_PRIORITY /* ARG_setbridgeprio */ |
| 275 | }; |
| 276 | int port = -1; |
| 277 | unsigned arg1, arg2; |
| 278 | |
| 279 | if (key != ARG_setbridgeprio) { |
| 280 | /* get portnum */ |
| 281 | unsigned i; |
| 282 | |
| 283 | port = if_nametoindex(*argv++); |
| 284 | if (!port) |
| 285 | bb_error_msg_and_die(bb_msg_invalid_arg, *argv, "port"); |
| 286 | memset(ifidx, 0, sizeof ifidx); |
| 287 | arm_ioctl(args, BRCTL_GET_PORT_LIST, (unsigned long)ifidx, |
| 288 | MAX_PORTS); |
| 289 | xioctl(fd, SIOCDEVPRIVATE, &ifr); |
| 290 | for (i = 0; i < MAX_PORTS; i++) { |
| 291 | if (ifidx[i] == port) { |
| 292 | port = i; |
| 293 | break; |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | arg1 = port; |
Denys Vlasenko | 7783248 | 2010-08-12 14:14:45 +0200 | [diff] [blame] | 298 | arg2 = xatoi_positive(*argv); |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 299 | if (key == ARG_setbridgeprio) { |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 300 | arg1 = arg2; |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 301 | arg2 = 0; |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 302 | } |
| 303 | arm_ioctl(args, ops[key - ARG_setpathcost], arg1, arg2); |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 304 | } |
| 305 | fire: |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 306 | /* Execute the previously set command */ |
Bernhard Reutner-Fischer | 2b11fb4 | 2008-01-14 16:10:11 +0000 | [diff] [blame] | 307 | xioctl(fd, SIOCDEVPRIVATE, &ifr); |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 308 | #endif |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 309 | done_next_argv: |
| 310 | argv++; |
Bernhard Reutner-Fischer | 1aac3ab | 2008-01-13 18:43:50 +0000 | [diff] [blame] | 311 | done: |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 312 | close(fd); |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 313 | } |
Denis Vlasenko | 278a1c2 | 2008-04-06 07:17:02 +0000 | [diff] [blame] | 314 | |
Bernhard Reutner-Fischer | d27d925 | 2008-01-13 15:23:27 +0000 | [diff] [blame] | 315 | return EXIT_SUCCESS; |
| 316 | } |