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