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