]>
Commit | Line | Data |
---|---|---|
d04bc300 SH |
1 | |
2 | #include <stdio.h> | |
3 | #include <stdlib.h> | |
4 | #include <unistd.h> | |
5 | #include <time.h> | |
6 | #include <sys/socket.h> | |
7 | #include <sys/time.h> | |
8 | #include <netinet/in.h> | |
9 | #include <linux/if.h> | |
10 | #include <linux/if_bridge.h> | |
11 | #include <string.h> | |
64108901 | 12 | #include <stdbool.h> |
d04bc300 | 13 | |
64108901 | 14 | #include "libnetlink.h" |
d04bc300 SH |
15 | #include "utils.h" |
16 | #include "br_common.h" | |
17 | ||
9dca899b | 18 | static unsigned int filter_index; |
64108901 | 19 | |
d04bc300 SH |
20 | static const char *port_states[] = { |
21 | [BR_STATE_DISABLED] = "disabled", | |
22 | [BR_STATE_LISTENING] = "listening", | |
23 | [BR_STATE_LEARNING] = "learning", | |
24 | [BR_STATE_FORWARDING] = "forwarding", | |
25 | [BR_STATE_BLOCKING] = "blocking", | |
26 | }; | |
27 | ||
df4b043f | 28 | extern char *if_indextoname(unsigned int __ifindex, char *__ifname); |
d04bc300 | 29 | |
df4b043f | 30 | static void print_link_flags(FILE *fp, unsigned int flags) |
d04bc300 SH |
31 | { |
32 | fprintf(fp, "<"); | |
33 | if (flags & IFF_UP && !(flags & IFF_RUNNING)) | |
34 | fprintf(fp, "NO-CARRIER%s", flags ? "," : ""); | |
35 | flags &= ~IFF_RUNNING; | |
36 | #define _PF(f) if (flags&IFF_##f) { \ | |
df4b043f SH |
37 | flags &= ~IFF_##f ; \ |
38 | fprintf(fp, #f "%s", flags ? "," : ""); } | |
d04bc300 SH |
39 | _PF(LOOPBACK); |
40 | _PF(BROADCAST); | |
41 | _PF(POINTOPOINT); | |
42 | _PF(MULTICAST); | |
43 | _PF(NOARP); | |
44 | _PF(ALLMULTI); | |
45 | _PF(PROMISC); | |
46 | _PF(MASTER); | |
47 | _PF(SLAVE); | |
48 | _PF(DEBUG); | |
49 | _PF(DYNAMIC); | |
50 | _PF(AUTOMEDIA); | |
51 | _PF(PORTSEL); | |
52 | _PF(NOTRAILERS); | |
53 | _PF(UP); | |
54 | _PF(LOWER_UP); | |
55 | _PF(DORMANT); | |
56 | _PF(ECHO); | |
57 | #undef _PF | |
df4b043f | 58 | if (flags) |
d04bc300 SH |
59 | fprintf(fp, "%x", flags); |
60 | fprintf(fp, "> "); | |
61 | } | |
62 | ||
63 | static const char *oper_states[] = { | |
38df7ac9 | 64 | "UNKNOWN", "NOTPRESENT", "DOWN", "LOWERLAYERDOWN", |
d04bc300 SH |
65 | "TESTING", "DORMANT", "UP" |
66 | }; | |
67 | ||
b1b7ce0f VY |
68 | static const char *hw_mode[] = {"VEB", "VEPA"}; |
69 | ||
d04bc300 SH |
70 | static void print_operstate(FILE *f, __u8 state) |
71 | { | |
df4b043f | 72 | if (state >= ARRAY_SIZE(oper_states)) |
d04bc300 SH |
73 | fprintf(f, "state %#x ", state); |
74 | else | |
75 | fprintf(f, "state %s ", oper_states[state]); | |
76 | } | |
77 | ||
b1b7ce0f VY |
78 | static void print_portstate(FILE *f, __u8 state) |
79 | { | |
80 | if (state <= BR_STATE_BLOCKING) | |
81 | fprintf(f, "state %s ", port_states[state]); | |
82 | else | |
83 | fprintf(f, "state (%d) ", state); | |
84 | } | |
85 | ||
86 | static void print_onoff(FILE *f, char *flag, __u8 val) | |
87 | { | |
88 | fprintf(f, "%s %s ", flag, val ? "on" : "off"); | |
89 | } | |
90 | ||
91 | static void print_hwmode(FILE *f, __u16 mode) | |
92 | { | |
df4b043f | 93 | if (mode >= ARRAY_SIZE(hw_mode)) |
b1b7ce0f VY |
94 | fprintf(f, "hwmode %#hx ", mode); |
95 | else | |
96 | fprintf(f, "hwmode %s ", hw_mode[mode]); | |
97 | } | |
98 | ||
d04bc300 SH |
99 | int print_linkinfo(const struct sockaddr_nl *who, |
100 | struct nlmsghdr *n, void *arg) | |
101 | { | |
102 | FILE *fp = arg; | |
103 | int len = n->nlmsg_len; | |
104 | struct ifinfomsg *ifi = NLMSG_DATA(n); | |
df4b043f | 105 | struct rtattr *tb[IFLA_MAX+1]; |
d04bc300 SH |
106 | char b1[IFNAMSIZ]; |
107 | ||
108 | len -= NLMSG_LENGTH(sizeof(*ifi)); | |
109 | if (len < 0) { | |
110 | fprintf(stderr, "Message too short!\n"); | |
111 | return -1; | |
df4b043f | 112 | } |
d04bc300 SH |
113 | |
114 | if (!(ifi->ifi_family == AF_BRIDGE || ifi->ifi_family == AF_UNSPEC)) | |
115 | return 0; | |
116 | ||
64108901 VY |
117 | if (filter_index && filter_index != ifi->ifi_index) |
118 | return 0; | |
119 | ||
b1b7ce0f | 120 | parse_rtattr_flags(tb, IFLA_MAX, IFLA_RTA(ifi), len, NLA_F_NESTED); |
d04bc300 SH |
121 | |
122 | if (tb[IFLA_IFNAME] == NULL) { | |
123 | fprintf(stderr, "BUG: nil ifname\n"); | |
124 | return -1; | |
125 | } | |
126 | ||
127 | if (n->nlmsg_type == RTM_DELLINK) | |
128 | fprintf(fp, "Deleted "); | |
129 | ||
130 | fprintf(fp, "%d: %s ", ifi->ifi_index, | |
1465db1a | 131 | tb[IFLA_IFNAME] ? rta_getattr_str(tb[IFLA_IFNAME]) : "<nil>"); |
d04bc300 | 132 | |
38df7ac9 | 133 | if (tb[IFLA_OPERSTATE]) |
1465db1a | 134 | print_operstate(fp, rta_getattr_u8(tb[IFLA_OPERSTATE])); |
38df7ac9 | 135 | |
d04bc300 SH |
136 | if (tb[IFLA_LINK]) { |
137 | SPRINT_BUF(b1); | |
1465db1a | 138 | int iflink = rta_getattr_u32(tb[IFLA_LINK]); |
df4b043f | 139 | |
d04bc300 SH |
140 | if (iflink == 0) |
141 | fprintf(fp, "@NONE: "); | |
1465db1a | 142 | else |
38df7ac9 | 143 | fprintf(fp, "@%s: ", |
d04bc300 | 144 | if_indextoname(iflink, b1)); |
1465db1a | 145 | } else |
d04bc300 | 146 | fprintf(fp, ": "); |
d04bc300 SH |
147 | |
148 | print_link_flags(fp, ifi->ifi_flags); | |
149 | ||
150 | if (tb[IFLA_MTU]) | |
1465db1a | 151 | fprintf(fp, "mtu %u ", rta_getattr_u32(tb[IFLA_MTU])); |
d04bc300 | 152 | |
1465db1a | 153 | if (tb[IFLA_MASTER]) |
38df7ac9 | 154 | fprintf(fp, "master %s ", |
1465db1a | 155 | if_indextoname(rta_getattr_u32(tb[IFLA_MASTER]), b1)); |
d04bc300 SH |
156 | |
157 | if (tb[IFLA_PROTINFO]) { | |
b1b7ce0f VY |
158 | if (tb[IFLA_PROTINFO]->rta_type & NLA_F_NESTED) { |
159 | struct rtattr *prtb[IFLA_BRPORT_MAX+1]; | |
160 | ||
161 | parse_rtattr_nested(prtb, IFLA_BRPORT_MAX, | |
162 | tb[IFLA_PROTINFO]); | |
163 | ||
164 | if (prtb[IFLA_BRPORT_STATE]) | |
165 | print_portstate(fp, | |
166 | rta_getattr_u8(prtb[IFLA_BRPORT_STATE])); | |
167 | if (prtb[IFLA_BRPORT_PRIORITY]) | |
168 | fprintf(fp, "priority %hu ", | |
169 | rta_getattr_u16(prtb[IFLA_BRPORT_PRIORITY])); | |
170 | if (prtb[IFLA_BRPORT_COST]) | |
171 | fprintf(fp, "cost %u ", | |
172 | rta_getattr_u32(prtb[IFLA_BRPORT_COST])); | |
4cd20da1 SH |
173 | |
174 | if (show_details) { | |
175 | fprintf(fp, "%s ", _SL_); | |
176 | ||
177 | if (prtb[IFLA_BRPORT_MODE]) | |
178 | print_onoff(fp, "hairpin", | |
179 | rta_getattr_u8(prtb[IFLA_BRPORT_MODE])); | |
180 | if (prtb[IFLA_BRPORT_GUARD]) | |
181 | print_onoff(fp, "guard", | |
182 | rta_getattr_u8(prtb[IFLA_BRPORT_GUARD])); | |
183 | if (prtb[IFLA_BRPORT_PROTECT]) | |
184 | print_onoff(fp, "root_block", | |
185 | rta_getattr_u8(prtb[IFLA_BRPORT_PROTECT])); | |
186 | if (prtb[IFLA_BRPORT_FAST_LEAVE]) | |
187 | print_onoff(fp, "fastleave", | |
188 | rta_getattr_u8(prtb[IFLA_BRPORT_FAST_LEAVE])); | |
f0f4ab60 VY |
189 | if (prtb[IFLA_BRPORT_LEARNING]) |
190 | print_onoff(fp, "learning", | |
191 | rta_getattr_u8(prtb[IFLA_BRPORT_LEARNING])); | |
674bb438 SF |
192 | if (prtb[IFLA_BRPORT_LEARNING_SYNC]) |
193 | print_onoff(fp, "learning_sync", | |
194 | rta_getattr_u8(prtb[IFLA_BRPORT_LEARNING_SYNC])); | |
f0f4ab60 VY |
195 | if (prtb[IFLA_BRPORT_UNICAST_FLOOD]) |
196 | print_onoff(fp, "flood", | |
197 | rta_getattr_u8(prtb[IFLA_BRPORT_UNICAST_FLOOD])); | |
9208b4e7 NA |
198 | if (prtb[IFLA_BRPORT_MCAST_FLOOD]) |
199 | print_onoff(fp, "mcast_flood", | |
200 | rta_getattr_u8(prtb[IFLA_BRPORT_MCAST_FLOOD])); | |
4cd20da1 | 201 | } |
b1b7ce0f VY |
202 | } else |
203 | print_portstate(fp, rta_getattr_u8(tb[IFLA_PROTINFO])); | |
d04bc300 SH |
204 | } |
205 | ||
b1b7ce0f VY |
206 | if (tb[IFLA_AF_SPEC]) { |
207 | /* This is reported by HW devices that have some bridging | |
208 | * capabilities. | |
209 | */ | |
210 | struct rtattr *aftb[IFLA_BRIDGE_MAX+1]; | |
211 | ||
212 | parse_rtattr_nested(aftb, IFLA_BRIDGE_MAX, tb[IFLA_AF_SPEC]); | |
213 | ||
a40d0827 JF |
214 | if (aftb[IFLA_BRIDGE_MODE]) |
215 | print_hwmode(fp, rta_getattr_u16(aftb[IFLA_BRIDGE_MODE])); | |
b1b7ce0f | 216 | } |
d04bc300 SH |
217 | |
218 | fprintf(fp, "\n"); | |
219 | fflush(fp); | |
220 | return 0; | |
221 | } | |
64108901 VY |
222 | |
223 | static void usage(void) | |
224 | { | |
225 | fprintf(stderr, "Usage: bridge link set dev DEV [ cost COST ] [ priority PRIO ] [ state STATE ]\n"); | |
226 | fprintf(stderr, " [ guard {on | off} ]\n"); | |
df4b043f | 227 | fprintf(stderr, " [ hairpin {on | off} ]\n"); |
64108901 VY |
228 | fprintf(stderr, " [ fastleave {on | off} ]\n"); |
229 | fprintf(stderr, " [ root_block {on | off} ]\n"); | |
f0f4ab60 | 230 | fprintf(stderr, " [ learning {on | off} ]\n"); |
674bb438 | 231 | fprintf(stderr, " [ learning_sync {on | off} ]\n"); |
f0f4ab60 | 232 | fprintf(stderr, " [ flood {on | off} ]\n"); |
9208b4e7 | 233 | fprintf(stderr, " [ mcast_flood {on | off} ]\n"); |
64108901 | 234 | fprintf(stderr, " [ hwmode {vepa | veb} ]\n"); |
22a98f51 | 235 | fprintf(stderr, " [ self ] [ master ]\n"); |
64108901 VY |
236 | fprintf(stderr, " bridge link show [dev DEV]\n"); |
237 | exit(-1); | |
238 | } | |
239 | ||
240 | static bool on_off(char *arg, __s8 *attr, char *val) | |
241 | { | |
242 | if (strcmp(val, "on") == 0) | |
243 | *attr = 1; | |
244 | else if (strcmp(val, "off") == 0) | |
245 | *attr = 0; | |
246 | else { | |
247 | fprintf(stderr, | |
248 | "Error: argument of \"%s\" must be \"on\" or \"off\"\n", | |
249 | arg); | |
250 | return false; | |
251 | } | |
252 | ||
253 | return true; | |
254 | } | |
255 | ||
256 | static int brlink_modify(int argc, char **argv) | |
257 | { | |
258 | struct { | |
259 | struct nlmsghdr n; | |
260 | struct ifinfomsg ifm; | |
261 | char buf[512]; | |
d17b136f PS |
262 | } req = { |
263 | .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)), | |
264 | .n.nlmsg_flags = NLM_F_REQUEST, | |
265 | .n.nlmsg_type = RTM_SETLINK, | |
266 | .ifm.ifi_family = PF_BRIDGE, | |
267 | }; | |
64108901 | 268 | char *d = NULL; |
f0f4ab60 | 269 | __s8 learning = -1; |
674bb438 | 270 | __s8 learning_sync = -1; |
f0f4ab60 | 271 | __s8 flood = -1; |
9208b4e7 | 272 | __s8 mcast_flood = -1; |
64108901 VY |
273 | __s8 hairpin = -1; |
274 | __s8 bpdu_guard = -1; | |
275 | __s8 fast_leave = -1; | |
b1b7ce0f | 276 | __s8 root_block = -1; |
64108901 VY |
277 | __u32 cost = 0; |
278 | __s16 priority = -1; | |
279 | __s8 state = -1; | |
280 | __s16 mode = -1; | |
6fdb4658 | 281 | __u16 flags = 0; |
64108901 VY |
282 | struct rtattr *nest; |
283 | ||
64108901 VY |
284 | while (argc > 0) { |
285 | if (strcmp(*argv, "dev") == 0) { | |
286 | NEXT_ARG(); | |
287 | d = *argv; | |
288 | } else if (strcmp(*argv, "guard") == 0) { | |
289 | NEXT_ARG(); | |
290 | if (!on_off("guard", &bpdu_guard, *argv)) | |
42ecedd4 | 291 | return -1; |
64108901 VY |
292 | } else if (strcmp(*argv, "hairpin") == 0) { |
293 | NEXT_ARG(); | |
294 | if (!on_off("hairping", &hairpin, *argv)) | |
42ecedd4 | 295 | return -1; |
64108901 VY |
296 | } else if (strcmp(*argv, "fastleave") == 0) { |
297 | NEXT_ARG(); | |
298 | if (!on_off("fastleave", &fast_leave, *argv)) | |
42ecedd4 | 299 | return -1; |
b1b7ce0f VY |
300 | } else if (strcmp(*argv, "root_block") == 0) { |
301 | NEXT_ARG(); | |
302 | if (!on_off("root_block", &root_block, *argv)) | |
42ecedd4 | 303 | return -1; |
f0f4ab60 VY |
304 | } else if (strcmp(*argv, "learning") == 0) { |
305 | NEXT_ARG(); | |
306 | if (!on_off("learning", &learning, *argv)) | |
42ecedd4 | 307 | return -1; |
674bb438 SF |
308 | } else if (strcmp(*argv, "learning_sync") == 0) { |
309 | NEXT_ARG(); | |
310 | if (!on_off("learning_sync", &learning_sync, *argv)) | |
42ecedd4 | 311 | return -1; |
f0f4ab60 VY |
312 | } else if (strcmp(*argv, "flood") == 0) { |
313 | NEXT_ARG(); | |
314 | if (!on_off("flood", &flood, *argv)) | |
42ecedd4 | 315 | return -1; |
9208b4e7 NA |
316 | } else if (strcmp(*argv, "mcast_flood") == 0) { |
317 | NEXT_ARG(); | |
318 | if (!on_off("mcast_flood", &mcast_flood, *argv)) | |
319 | return -1; | |
a40d0827 | 320 | } else if (strcmp(*argv, "cost") == 0) { |
64108901 VY |
321 | NEXT_ARG(); |
322 | cost = atoi(*argv); | |
a40d0827 | 323 | } else if (strcmp(*argv, "priority") == 0) { |
64108901 VY |
324 | NEXT_ARG(); |
325 | priority = atoi(*argv); | |
a40d0827 | 326 | } else if (strcmp(*argv, "state") == 0) { |
64108901 | 327 | NEXT_ARG(); |
6b8c871d | 328 | char *endptr; |
62000e51 | 329 | size_t nstates = ARRAY_SIZE(port_states); |
df4b043f | 330 | |
6b8c871d AP |
331 | state = strtol(*argv, &endptr, 10); |
332 | if (!(**argv != '\0' && *endptr == '\0')) { | |
333 | for (state = 0; state < nstates; state++) | |
334 | if (strcmp(port_states[state], *argv) == 0) | |
335 | break; | |
336 | if (state == nstates) { | |
337 | fprintf(stderr, | |
338 | "Error: invalid STP port state\n"); | |
42ecedd4 | 339 | return -1; |
6b8c871d AP |
340 | } |
341 | } | |
a40d0827 | 342 | } else if (strcmp(*argv, "hwmode") == 0) { |
64108901 | 343 | NEXT_ARG(); |
a40d0827 | 344 | flags = BRIDGE_FLAGS_SELF; |
64108901 VY |
345 | if (strcmp(*argv, "vepa") == 0) |
346 | mode = BRIDGE_MODE_VEPA; | |
347 | else if (strcmp(*argv, "veb") == 0) | |
348 | mode = BRIDGE_MODE_VEB; | |
349 | else { | |
350 | fprintf(stderr, | |
df4b043f | 351 | "Mode argument must be \"vepa\" or \"veb\".\n"); |
42ecedd4 | 352 | return -1; |
64108901 | 353 | } |
6fdb4658 | 354 | } else if (strcmp(*argv, "self") == 0) { |
22a98f51 RP |
355 | flags |= BRIDGE_FLAGS_SELF; |
356 | } else if (strcmp(*argv, "master") == 0) { | |
357 | flags |= BRIDGE_FLAGS_MASTER; | |
64108901 VY |
358 | } else { |
359 | usage(); | |
360 | } | |
361 | argc--; argv++; | |
362 | } | |
363 | if (d == NULL) { | |
364 | fprintf(stderr, "Device is a required argument.\n"); | |
42ecedd4 | 365 | return -1; |
64108901 VY |
366 | } |
367 | ||
368 | ||
369 | req.ifm.ifi_index = ll_name_to_index(d); | |
370 | if (req.ifm.ifi_index == 0) { | |
371 | fprintf(stderr, "Cannot find bridge device \"%s\"\n", d); | |
42ecedd4 | 372 | return -1; |
64108901 VY |
373 | } |
374 | ||
375 | /* Nested PROTINFO attribute. Contains: port flags, cost, priority and | |
376 | * state. | |
377 | */ | |
378 | nest = addattr_nest(&req.n, sizeof(req), | |
379 | IFLA_PROTINFO | NLA_F_NESTED); | |
380 | /* Flags first */ | |
381 | if (bpdu_guard >= 0) | |
382 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_GUARD, bpdu_guard); | |
383 | if (hairpin >= 0) | |
384 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_MODE, hairpin); | |
385 | if (fast_leave >= 0) | |
386 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_FAST_LEAVE, | |
387 | fast_leave); | |
b1b7ce0f VY |
388 | if (root_block >= 0) |
389 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_PROTECT, root_block); | |
f0f4ab60 VY |
390 | if (flood >= 0) |
391 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_UNICAST_FLOOD, flood); | |
9208b4e7 NA |
392 | if (mcast_flood >= 0) |
393 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_MCAST_FLOOD, | |
394 | mcast_flood); | |
f0f4ab60 VY |
395 | if (learning >= 0) |
396 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_LEARNING, learning); | |
674bb438 SF |
397 | if (learning_sync >= 0) |
398 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_LEARNING_SYNC, | |
399 | learning_sync); | |
64108901 VY |
400 | |
401 | if (cost > 0) | |
402 | addattr32(&req.n, sizeof(req), IFLA_BRPORT_COST, cost); | |
403 | ||
404 | if (priority >= 0) | |
405 | addattr16(&req.n, sizeof(req), IFLA_BRPORT_PRIORITY, priority); | |
406 | ||
407 | if (state >= 0) | |
408 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_STATE, state); | |
409 | ||
410 | addattr_nest_end(&req.n, nest); | |
411 | ||
6fdb4658 RP |
412 | /* IFLA_AF_SPEC nested attribute. Contains IFLA_BRIDGE_FLAGS that |
413 | * designates master or self operation and IFLA_BRIDGE_MODE | |
414 | * for hw 'vepa' or 'veb' operation modes. The hwmodes are | |
415 | * only valid in 'self' mode on some devices so far. | |
64108901 | 416 | */ |
6fdb4658 | 417 | if (mode >= 0 || flags > 0) { |
64108901 VY |
418 | nest = addattr_nest(&req.n, sizeof(req), IFLA_AF_SPEC); |
419 | ||
6fdb4658 RP |
420 | if (flags > 0) |
421 | addattr16(&req.n, sizeof(req), IFLA_BRIDGE_FLAGS, flags); | |
64108901 VY |
422 | |
423 | if (mode >= 0) | |
424 | addattr16(&req.n, sizeof(req), IFLA_BRIDGE_MODE, mode); | |
425 | ||
426 | addattr_nest_end(&req.n, nest); | |
427 | } | |
428 | ||
c079e121 | 429 | if (rtnl_talk(&rth, &req.n, NULL, 0) < 0) |
42ecedd4 | 430 | return -1; |
64108901 VY |
431 | |
432 | return 0; | |
433 | } | |
434 | ||
435 | static int brlink_show(int argc, char **argv) | |
436 | { | |
437 | char *filter_dev = NULL; | |
438 | ||
439 | while (argc > 0) { | |
440 | if (strcmp(*argv, "dev") == 0) { | |
441 | NEXT_ARG(); | |
442 | if (filter_dev) | |
443 | duparg("dev", *argv); | |
444 | filter_dev = *argv; | |
445 | } | |
446 | argc--; argv++; | |
447 | } | |
448 | ||
449 | if (filter_dev) { | |
450 | if ((filter_index = ll_name_to_index(filter_dev)) == 0) { | |
451 | fprintf(stderr, "Cannot find device \"%s\"\n", | |
452 | filter_dev); | |
453 | return -1; | |
454 | } | |
455 | } | |
456 | ||
457 | if (rtnl_wilddump_request(&rth, PF_BRIDGE, RTM_GETLINK) < 0) { | |
458 | perror("Cannon send dump request"); | |
459 | exit(1); | |
460 | } | |
461 | ||
462 | if (rtnl_dump_filter(&rth, print_linkinfo, stdout) < 0) { | |
463 | fprintf(stderr, "Dump terminated\n"); | |
464 | exit(1); | |
465 | } | |
466 | return 0; | |
467 | } | |
468 | ||
469 | int do_link(int argc, char **argv) | |
470 | { | |
471 | ll_init_map(&rth); | |
472 | if (argc > 0) { | |
473 | if (matches(*argv, "set") == 0 || | |
474 | matches(*argv, "change") == 0) | |
475 | return brlink_modify(argc-1, argv+1); | |
476 | if (matches(*argv, "show") == 0 || | |
477 | matches(*argv, "lst") == 0 || | |
478 | matches(*argv, "list") == 0) | |
479 | return brlink_show(argc-1, argv+1); | |
480 | if (matches(*argv, "help") == 0) | |
481 | usage(); | |
482 | } else | |
483 | return brlink_show(0, NULL); | |
484 | ||
485 | fprintf(stderr, "Command \"%s\" is unknown, try \"bridge link help\".\n", *argv); | |
486 | exit(-1); | |
487 | } |