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