blob: 5d5f0af301fbfadcb9822ddcb47b180cfaaa0de0 [file] [log] [blame]
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +00001/* vi: set sw=4 ts=4: */
2/*
3 * Small implementation of brctl for busybox.
4 *
Bernhard Reutner-Fischer6c4dade2008-09-25 12:13:34 +00005 * Copyright (C) 2008 by Bernhard Reutner-Fischer
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +00006 *
Bernhard Reutner-Fischer2b11fb42008-01-14 16:10:11 +00007 * Some helper functions from bridge-utils are
8 * Copyright (C) 2000 Lennert Buytenhek
9 *
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +020010 * Licensed under GPLv2 or later, see file LICENSE in this source tree.
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +000011 */
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +000012/* 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 */
Denys Vlasenko47367e12016-11-23 09:05:14 +010015//config:config BRCTL
Denys Vlasenko4eed2c62017-07-18 22:01:24 +020016//config: bool "brctl (4.7 kb)"
Denys Vlasenko47367e12016-11-23 09:05:14 +010017//config: default y
18//config: select PLATFORM_LINUX
19//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020020//config: Manage ethernet bridges.
21//config: Supports addbr/delbr and addif/delif.
Denys Vlasenko47367e12016-11-23 09:05:14 +010022//config:
23//config:config FEATURE_BRCTL_FANCY
24//config: bool "Fancy options"
25//config: default y
26//config: depends on BRCTL
27//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020028//config: Add support for extended option like:
29//config: setageing, setfd, sethello, setmaxage,
30//config: setpathcost, setportprio, setbridgeprio,
31//config: stp
32//config: This adds about 600 bytes.
Denys Vlasenko47367e12016-11-23 09:05:14 +010033//config:
34//config:config FEATURE_BRCTL_SHOW
35//config: bool "Support show"
36//config: default y
37//config: depends on BRCTL && FEATURE_BRCTL_FANCY
38//config: help
Denys Vlasenko72089cf2017-07-21 09:50:55 +020039//config: Add support for option which prints the current config:
40//config: show
Denys Vlasenko47367e12016-11-23 09:05:14 +010041
Denys Vlasenko86e07f62017-08-06 20:14:02 +020042//applet:IF_BRCTL(APPLET_NOEXEC(brctl, brctl, BB_DIR_USR_SBIN, BB_SUID_DROP, brctl))
Denys Vlasenko47367e12016-11-23 09:05:14 +010043
44//kbuild:lib-$(CONFIG_BRCTL) += brctl.o
Pere Orga5bc8c002011-04-11 03:29:49 +020045
46//usage:#define brctl_trivial_usage
47//usage: "COMMAND [BRIDGE [INTERFACE]]"
48//usage:#define brctl_full_usage "\n\n"
49//usage: "Manage ethernet bridges\n"
50//usage: "\nCommands:"
51//usage: IF_FEATURE_BRCTL_SHOW(
52//usage: "\n show Show a list of bridges"
53//usage: )
54//usage: "\n addbr BRIDGE Create BRIDGE"
55//usage: "\n delbr BRIDGE Delete BRIDGE"
56//usage: "\n addif BRIDGE IFACE Add IFACE to BRIDGE"
57//usage: "\n delif BRIDGE IFACE Delete IFACE from BRIDGE"
58//usage: IF_FEATURE_BRCTL_FANCY(
59//usage: "\n setageing BRIDGE TIME Set ageing time"
60//usage: "\n setfd BRIDGE TIME Set bridge forward delay"
61//usage: "\n sethello BRIDGE TIME Set hello time"
62//usage: "\n setmaxage BRIDGE TIME Set max message age"
63//usage: "\n setpathcost BRIDGE COST Set path cost"
64//usage: "\n setportprio BRIDGE PRIO Set port priority"
65//usage: "\n setbridgeprio BRIDGE PRIO Set bridge priority"
66//usage: "\n stp BRIDGE [1/yes/on|0/no/off] STP on/off"
67//usage: )
68
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +000069#include "libbb.h"
70#include <linux/sockios.h>
71#include <net/if.h>
72
Denis Vlasenko802cab12009-01-31 20:08:21 +000073#ifndef SIOCBRADDBR
74# define SIOCBRADDBR BRCTL_ADD_BRIDGE
75#endif
76#ifndef SIOCBRDELBR
77# define SIOCBRDELBR BRCTL_DEL_BRIDGE
78#endif
79#ifndef SIOCBRADDIF
80# define SIOCBRADDIF BRCTL_ADD_IF
81#endif
82#ifndef SIOCBRDELIF
83# define SIOCBRDELIF BRCTL_DEL_IF
84#endif
85
86
Bernhard Reutner-Fischer2b11fb42008-01-14 16:10:11 +000087/* Maximum number of ports supported per bridge interface. */
88#ifndef MAX_PORTS
Maciek Borzecki30ebd7b2010-03-23 05:18:38 +010089# define MAX_PORTS 32
Bernhard Reutner-Fischer2b11fb42008-01-14 16:10:11 +000090#endif
91
92/* Use internal number parsing and not the "exact" conversion. */
93/* #define BRCTL_USE_INTERNAL 0 */ /* use exact conversion */
94#define BRCTL_USE_INTERNAL 1
95
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +000096#if ENABLE_FEATURE_BRCTL_FANCY
Denys Vlasenko5fa6d1a2015-10-05 11:15:43 +020097/* #include <linux/if_bridge.h>
98 * breaks on musl: we already included netinet/in.h in libbb.h,
99 * if we include <linux/if_bridge.h> here, we get this:
100 * In file included from /usr/include/linux/if_bridge.h:18,
101 * from networking/brctl.c:67:
102 * /usr/include/linux/in6.h:32: error: redefinition of 'struct in6_addr'
103 * /usr/include/linux/in6.h:49: error: redefinition of 'struct sockaddr_in6'
104 * /usr/include/linux/in6.h:59: error: redefinition of 'struct ipv6_mreq'
105 */
106/* From <linux/if_bridge.h> */
107#define BRCTL_GET_VERSION 0
108#define BRCTL_GET_BRIDGES 1
109#define BRCTL_ADD_BRIDGE 2
110#define BRCTL_DEL_BRIDGE 3
111#define BRCTL_ADD_IF 4
112#define BRCTL_DEL_IF 5
113#define BRCTL_GET_BRIDGE_INFO 6
114#define BRCTL_GET_PORT_LIST 7
115#define BRCTL_SET_BRIDGE_FORWARD_DELAY 8
116#define BRCTL_SET_BRIDGE_HELLO_TIME 9
117#define BRCTL_SET_BRIDGE_MAX_AGE 10
118#define BRCTL_SET_AGEING_TIME 11
119#define BRCTL_SET_GC_INTERVAL 12
120#define BRCTL_GET_PORT_INFO 13
121#define BRCTL_SET_BRIDGE_STP_STATE 14
122#define BRCTL_SET_BRIDGE_PRIORITY 15
123#define BRCTL_SET_PORT_PRIORITY 16
124#define BRCTL_SET_PATH_COST 17
125#define BRCTL_GET_FDB_ENTRIES 18
126struct __bridge_info {
127 uint64_t designated_root;
128 uint64_t bridge_id;
129 uint32_t root_path_cost;
130 uint32_t max_age;
131 uint32_t hello_time;
132 uint32_t forward_delay;
133 uint32_t bridge_max_age;
134 uint32_t bridge_hello_time;
135 uint32_t bridge_forward_delay;
136 uint8_t topology_change;
137 uint8_t topology_change_detected;
138 uint8_t root_port;
139 uint8_t stp_enabled;
140 uint32_t ageing_time;
141 uint32_t gc_interval;
142 uint32_t hello_timer_value;
143 uint32_t tcn_timer_value;
144 uint32_t topology_change_timer_value;
145 uint32_t gc_timer_value;
146};
147/* end <linux/if_bridge.h> */
Denis Vlasenkod0a071a2008-03-17 09:33:45 +0000148
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000149/* FIXME: These 4 funcs are not really clean and could be improved */
Denys Vlasenko49b8e722012-06-10 14:16:16 +0200150static ALWAYS_INLINE void bb_strtotimeval(struct timeval *tv,
Denis Vlasenkod0a071a2008-03-17 09:33:45 +0000151 const char *time_str)
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000152{
153 double secs;
Maciek Borzecki30ebd7b2010-03-23 05:18:38 +0100154# if BRCTL_USE_INTERNAL
Maciek Borzecki46abfc02010-03-16 12:41:29 +0100155 char *endptr;
156 secs = /*bb_*/strtod(time_str, &endptr);
157 if (endptr == time_str)
Maciek Borzecki30ebd7b2010-03-23 05:18:38 +0100158# else
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000159 if (sscanf(time_str, "%lf", &secs) != 1)
Maciek Borzecki30ebd7b2010-03-23 05:18:38 +0100160# endif
Denys Vlasenko0f296a32015-10-14 13:21:01 +0200161 bb_error_msg_and_die(bb_msg_invalid_arg_to, time_str, "timespec");
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000162 tv->tv_sec = secs;
163 tv->tv_usec = 1000000 * (secs - tv->tv_sec);
164}
165
Maciek Borzecki30ebd7b2010-03-23 05:18:38 +0100166static ALWAYS_INLINE unsigned long tv_to_jiffies(const struct timeval *tv)
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000167{
168 unsigned long long jif;
169
170 jif = 1000000ULL * tv->tv_sec + tv->tv_usec;
171
172 return jif/10000;
173}
Denis Vlasenkod0a071a2008-03-17 09:33:45 +0000174# if 0
Maciek Borzecki30ebd7b2010-03-23 05:18:38 +0100175static void jiffies_to_tv(struct timeval *tv, unsigned long jiffies)
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000176{
177 unsigned long long tvusec;
178
179 tvusec = 10000ULL*jiffies;
180 tv->tv_sec = tvusec/1000000;
181 tv->tv_usec = tvusec - 1000000 * tv->tv_sec;
182}
183# endif
184static unsigned long str_to_jiffies(const char *time_str)
185{
186 struct timeval tv;
Denys Vlasenko49b8e722012-06-10 14:16:16 +0200187 bb_strtotimeval(&tv, time_str);
Maciek Borzecki30ebd7b2010-03-23 05:18:38 +0100188 return tv_to_jiffies(&tv);
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000189}
Bernhard Reutner-Fischer2b11fb42008-01-14 16:10:11 +0000190
191static void arm_ioctl(unsigned long *args,
Denis Vlasenkod0a071a2008-03-17 09:33:45 +0000192 unsigned long arg0, unsigned long arg1, unsigned long arg2)
Bernhard Reutner-Fischer2b11fb42008-01-14 16:10:11 +0000193{
194 args[0] = arg0;
195 args[1] = arg1;
196 args[2] = arg2;
197 args[3] = 0;
198}
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +0000199#endif
200
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000201
Denis Vlasenkod0a071a2008-03-17 09:33:45 +0000202int brctl_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
Denis Vlasenkoa60f84e2008-07-05 09:18:54 +0000203int brctl_main(int argc UNUSED_PARAM, char **argv)
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +0000204{
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +0000205 static const char keywords[] ALIGN1 =
206 "addbr\0" "delbr\0" "addif\0" "delif\0"
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000207 IF_FEATURE_BRCTL_FANCY(
Bernhard Reutner-Fischer2b11fb42008-01-14 16:10:11 +0000208 "stp\0"
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000209 "setageing\0" "setfd\0" "sethello\0" "setmaxage\0"
210 "setpathcost\0" "setportprio\0" "setbridgeprio\0"
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000211 )
Nicolas Thillf47ce072012-09-25 14:06:01 +0200212 IF_FEATURE_BRCTL_SHOW("show\0");
Denis Vlasenkod0a071a2008-03-17 09:33:45 +0000213
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000214 enum { ARG_addbr = 0, ARG_delbr, ARG_addif, ARG_delif
Denis Vlasenko5e34ff22009-04-21 11:09:40 +0000215 IF_FEATURE_BRCTL_FANCY(,
Denys Vlasenko60cb48c2013-01-14 15:57:44 +0100216 ARG_stp,
217 ARG_setageing, ARG_setfd, ARG_sethello, ARG_setmaxage,
218 ARG_setpathcost, ARG_setportprio, ARG_setbridgeprio
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000219 )
Nicolas Thillf47ce072012-09-25 14:06:01 +0200220 IF_FEATURE_BRCTL_SHOW(, ARG_show)
Denis Vlasenkod0a071a2008-03-17 09:33:45 +0000221 };
222
223 int fd;
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000224 smallint key;
225 struct ifreq ifr;
Bernhard Reutner-Fischer2b11fb42008-01-14 16:10:11 +0000226 char *br, *brif;
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +0000227
228 argv++;
229 while (*argv) {
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000230#if ENABLE_FEATURE_BRCTL_FANCY
231 int ifidx[MAX_PORTS];
232 unsigned long args[4];
233 ifr.ifr_data = (char *) &args;
234#endif
235
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000236 key = index_in_strings(keywords, *argv);
237 if (key == -1) /* no match found in keywords array, bail out. */
Denys Vlasenko0f296a32015-10-14 13:21:01 +0200238 bb_error_msg_and_die(bb_msg_invalid_arg_to, *argv, applet_name);
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +0000239 argv++;
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000240 fd = xsocket(AF_INET, SOCK_STREAM, 0);
241
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +0000242#if ENABLE_FEATURE_BRCTL_SHOW
243 if (key == ARG_show) { /* show */
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000244 char brname[IFNAMSIZ];
245 int bridx[MAX_PORTS];
246 int i, num;
247 arm_ioctl(args, BRCTL_GET_BRIDGES,
248 (unsigned long) bridx, MAX_PORTS);
249 num = xioctl(fd, SIOCGIFBR, args);
Denys Vlasenkod60752f2015-10-07 22:42:45 +0200250 puts("bridge name\tbridge id\t\tSTP enabled\tinterfaces");
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000251 for (i = 0; i < num; i++) {
252 char ifname[IFNAMSIZ];
253 int j, tabs;
254 struct __bridge_info bi;
255 unsigned char *x;
256
257 if (!if_indextoname(bridx[i], brname))
258 bb_perror_msg_and_die("can't get bridge name for index %d", i);
Denis Vlasenko360d9662008-12-02 18:18:50 +0000259 strncpy_IFNAMSIZ(ifr.ifr_name, brname);
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000260
261 arm_ioctl(args, BRCTL_GET_BRIDGE_INFO,
262 (unsigned long) &bi, 0);
263 xioctl(fd, SIOCDEVPRIVATE, &ifr);
264 printf("%s\t\t", brname);
265
266 /* print bridge id */
267 x = (unsigned char *) &bi.bridge_id;
268 for (j = 0; j < 8; j++) {
Denys Vlasenkod60752f2015-10-07 22:42:45 +0200269 printf("%02x", x[j]);
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000270 if (j == 1)
271 bb_putchar('.');
272 }
273 printf(bi.stp_enabled ? "\tyes" : "\tno");
274
275 /* print interface list */
276 arm_ioctl(args, BRCTL_GET_PORT_LIST,
277 (unsigned long) ifidx, MAX_PORTS);
278 xioctl(fd, SIOCDEVPRIVATE, &ifr);
279 tabs = 0;
280 for (j = 0; j < MAX_PORTS; j++) {
281 if (!ifidx[j])
282 continue;
283 if (!if_indextoname(ifidx[j], ifname))
284 bb_perror_msg_and_die("can't get interface name for index %d", j);
285 if (tabs)
286 printf("\t\t\t\t\t");
287 else
288 tabs = 1;
289 printf("\t\t%s\n", ifname);
290 }
Denys Vlasenkoe4dcba12010-10-28 18:57:19 +0200291 if (!tabs) /* bridge has no interfaces */
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000292 bb_putchar('\n');
293 }
294 goto done;
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +0000295 }
296#endif
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000297
298 if (!*argv) /* all but 'show' need at least one argument */
299 bb_show_usage();
300
Denis Vlasenkod0a071a2008-03-17 09:33:45 +0000301 br = *argv++;
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +0000302
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000303 if (key == ARG_addbr || key == ARG_delbr) { /* addbr or delbr */
304 ioctl_or_perror_and_die(fd,
Denis Vlasenkod0a071a2008-03-17 09:33:45 +0000305 key == ARG_addbr ? SIOCBRADDBR : SIOCBRDELBR,
306 br, "bridge %s", br);
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000307 goto done;
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +0000308 }
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000309
Bernhard Reutner-Fischer0c0f1762010-03-17 11:23:04 +0100310 if (!*argv) /* all but 'addbr/delbr' need at least two arguments */
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000311 bb_show_usage();
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000312
Denis Vlasenko360d9662008-12-02 18:18:50 +0000313 strncpy_IFNAMSIZ(ifr.ifr_name, br);
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000314 if (key == ARG_addif || key == ARG_delif) { /* addif or delif */
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000315 brif = *argv;
Denis Vlasenkod0a071a2008-03-17 09:33:45 +0000316 ifr.ifr_ifindex = if_nametoindex(brif);
317 if (!ifr.ifr_ifindex) {
318 bb_perror_msg_and_die("iface %s", brif);
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +0000319 }
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000320 ioctl_or_perror_and_die(fd,
Denis Vlasenkod0a071a2008-03-17 09:33:45 +0000321 key == ARG_addif ? SIOCBRADDIF : SIOCBRDELIF,
322 &ifr, "bridge %s", br);
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000323 goto done_next_argv;
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +0000324 }
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000325#if ENABLE_FEATURE_BRCTL_FANCY
Bernhard Reutner-Fischer2b11fb42008-01-14 16:10:11 +0000326 if (key == ARG_stp) { /* stp */
Denys Vlasenko8a659f62010-04-03 00:52:16 +0200327 static const char no_yes[] ALIGN1 =
Maciek Borzecki30ebd7b2010-03-23 05:18:38 +0100328 "0\0" "off\0" "n\0" "no\0" /* 0 .. 3 */
329 "1\0" "on\0" "y\0" "yes\0"; /* 4 .. 7 */
Denys Vlasenko8a659f62010-04-03 00:52:16 +0200330 int onoff = index_in_strings(no_yes, *argv);
Maciek Borzecki30ebd7b2010-03-23 05:18:38 +0100331 if (onoff < 0)
Denys Vlasenko0f296a32015-10-14 13:21:01 +0200332 bb_error_msg_and_die(bb_msg_invalid_arg_to, *argv, applet_name);
Maciek Borzecki30ebd7b2010-03-23 05:18:38 +0100333 onoff = (unsigned)onoff / 4;
334 arm_ioctl(args, BRCTL_SET_BRIDGE_STP_STATE, onoff, 0);
Bernhard Reutner-Fischer2b11fb42008-01-14 16:10:11 +0000335 goto fire;
336 }
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000337 if ((unsigned)(key - ARG_setageing) < 4) { /* time related ops */
338 static const uint8_t ops[] ALIGN1 = {
339 BRCTL_SET_AGEING_TIME, /* ARG_setageing */
340 BRCTL_SET_BRIDGE_FORWARD_DELAY, /* ARG_setfd */
341 BRCTL_SET_BRIDGE_HELLO_TIME, /* ARG_sethello */
342 BRCTL_SET_BRIDGE_MAX_AGE /* ARG_setmaxage */
343 };
344 arm_ioctl(args, ops[key - ARG_setageing], str_to_jiffies(*argv), 0);
Bernhard Reutner-Fischer2b11fb42008-01-14 16:10:11 +0000345 goto fire;
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000346 }
Bernhard Reutner-Fischer2b11fb42008-01-14 16:10:11 +0000347 if (key == ARG_setpathcost
Denis Vlasenkod0a071a2008-03-17 09:33:45 +0000348 || key == ARG_setportprio
349 || key == ARG_setbridgeprio
350 ) {
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000351 static const uint8_t ops[] ALIGN1 = {
352 BRCTL_SET_PATH_COST, /* ARG_setpathcost */
353 BRCTL_SET_PORT_PRIORITY, /* ARG_setportprio */
354 BRCTL_SET_BRIDGE_PRIORITY /* ARG_setbridgeprio */
355 };
356 int port = -1;
357 unsigned arg1, arg2;
358
359 if (key != ARG_setbridgeprio) {
360 /* get portnum */
361 unsigned i;
362
363 port = if_nametoindex(*argv++);
364 if (!port)
Denys Vlasenko0f296a32015-10-14 13:21:01 +0200365 bb_error_msg_and_die(bb_msg_invalid_arg_to, *argv, "port");
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000366 memset(ifidx, 0, sizeof ifidx);
367 arm_ioctl(args, BRCTL_GET_PORT_LIST, (unsigned long)ifidx,
Denys Vlasenko60cb48c2013-01-14 15:57:44 +0100368 MAX_PORTS);
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000369 xioctl(fd, SIOCDEVPRIVATE, &ifr);
370 for (i = 0; i < MAX_PORTS; i++) {
371 if (ifidx[i] == port) {
372 port = i;
373 break;
374 }
375 }
376 }
377 arg1 = port;
Denys Vlasenko77832482010-08-12 14:14:45 +0200378 arg2 = xatoi_positive(*argv);
Bernhard Reutner-Fischer2b11fb42008-01-14 16:10:11 +0000379 if (key == ARG_setbridgeprio) {
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000380 arg1 = arg2;
Bernhard Reutner-Fischer2b11fb42008-01-14 16:10:11 +0000381 arg2 = 0;
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000382 }
383 arm_ioctl(args, ops[key - ARG_setpathcost], arg1, arg2);
Bernhard Reutner-Fischer2b11fb42008-01-14 16:10:11 +0000384 }
385 fire:
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000386 /* Execute the previously set command */
Bernhard Reutner-Fischer2b11fb42008-01-14 16:10:11 +0000387 xioctl(fd, SIOCDEVPRIVATE, &ifr);
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000388#endif
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000389 done_next_argv:
390 argv++;
Bernhard Reutner-Fischer1aac3ab2008-01-13 18:43:50 +0000391 done:
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000392 close(fd);
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +0000393 }
Denis Vlasenko278a1c22008-04-06 07:17:02 +0000394
Bernhard Reutner-Fischerd27d9252008-01-13 15:23:27 +0000395 return EXIT_SUCCESS;
396}