]>
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])); | |
41973a47 RP |
201 | if (prtb[IFLA_BRPORT_NEIGH_SUPPRESS]) |
202 | print_onoff(fp, "neigh_suppress", | |
203 | rta_getattr_u8(prtb[IFLA_BRPORT_NEIGH_SUPPRESS])); | |
8cfde5c9 RP |
204 | if (prtb[IFLA_BRPORT_VLAN_TUNNEL]) |
205 | print_onoff(fp, "vlan_tunnel", | |
206 | rta_getattr_u8(prtb[IFLA_BRPORT_VLAN_TUNNEL])); | |
4cd20da1 | 207 | } |
b1b7ce0f VY |
208 | } else |
209 | print_portstate(fp, rta_getattr_u8(tb[IFLA_PROTINFO])); | |
d04bc300 SH |
210 | } |
211 | ||
b1b7ce0f VY |
212 | if (tb[IFLA_AF_SPEC]) { |
213 | /* This is reported by HW devices that have some bridging | |
214 | * capabilities. | |
215 | */ | |
216 | struct rtattr *aftb[IFLA_BRIDGE_MAX+1]; | |
217 | ||
218 | parse_rtattr_nested(aftb, IFLA_BRIDGE_MAX, tb[IFLA_AF_SPEC]); | |
219 | ||
a40d0827 JF |
220 | if (aftb[IFLA_BRIDGE_MODE]) |
221 | print_hwmode(fp, rta_getattr_u16(aftb[IFLA_BRIDGE_MODE])); | |
52fd1fe3 RM |
222 | if (show_details) { |
223 | if (aftb[IFLA_BRIDGE_VLAN_INFO]) { | |
224 | fprintf(fp, "\n"); | |
225 | print_vlan_info(fp, tb[IFLA_AF_SPEC], | |
226 | ifi->ifi_index); | |
227 | } | |
228 | } | |
b1b7ce0f | 229 | } |
d04bc300 SH |
230 | |
231 | fprintf(fp, "\n"); | |
232 | fflush(fp); | |
233 | return 0; | |
234 | } | |
64108901 VY |
235 | |
236 | static void usage(void) | |
237 | { | |
238 | fprintf(stderr, "Usage: bridge link set dev DEV [ cost COST ] [ priority PRIO ] [ state STATE ]\n"); | |
239 | fprintf(stderr, " [ guard {on | off} ]\n"); | |
df4b043f | 240 | fprintf(stderr, " [ hairpin {on | off} ]\n"); |
64108901 VY |
241 | fprintf(stderr, " [ fastleave {on | off} ]\n"); |
242 | fprintf(stderr, " [ root_block {on | off} ]\n"); | |
f0f4ab60 | 243 | fprintf(stderr, " [ learning {on | off} ]\n"); |
674bb438 | 244 | fprintf(stderr, " [ learning_sync {on | off} ]\n"); |
f0f4ab60 | 245 | fprintf(stderr, " [ flood {on | off} ]\n"); |
9208b4e7 | 246 | fprintf(stderr, " [ mcast_flood {on | off} ]\n"); |
8cfde5c9 RP |
247 | fprintf(stderr, " [ neigh_suppress {on | off} ]\n"); |
248 | fprintf(stderr, " [ vlan_tunnel {on | off} ]\n"); | |
64108901 | 249 | fprintf(stderr, " [ hwmode {vepa | veb} ]\n"); |
22a98f51 | 250 | fprintf(stderr, " [ self ] [ master ]\n"); |
64108901 VY |
251 | fprintf(stderr, " bridge link show [dev DEV]\n"); |
252 | exit(-1); | |
253 | } | |
254 | ||
255 | static bool on_off(char *arg, __s8 *attr, char *val) | |
256 | { | |
257 | if (strcmp(val, "on") == 0) | |
258 | *attr = 1; | |
259 | else if (strcmp(val, "off") == 0) | |
260 | *attr = 0; | |
261 | else { | |
262 | fprintf(stderr, | |
263 | "Error: argument of \"%s\" must be \"on\" or \"off\"\n", | |
264 | arg); | |
265 | return false; | |
266 | } | |
267 | ||
268 | return true; | |
269 | } | |
270 | ||
271 | static int brlink_modify(int argc, char **argv) | |
272 | { | |
273 | struct { | |
274 | struct nlmsghdr n; | |
275 | struct ifinfomsg ifm; | |
276 | char buf[512]; | |
d17b136f PS |
277 | } req = { |
278 | .n.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)), | |
279 | .n.nlmsg_flags = NLM_F_REQUEST, | |
280 | .n.nlmsg_type = RTM_SETLINK, | |
281 | .ifm.ifi_family = PF_BRIDGE, | |
282 | }; | |
64108901 | 283 | char *d = NULL; |
41973a47 | 284 | __s8 neigh_suppress = -1; |
f0f4ab60 | 285 | __s8 learning = -1; |
674bb438 | 286 | __s8 learning_sync = -1; |
f0f4ab60 | 287 | __s8 flood = -1; |
8cfde5c9 | 288 | __s8 vlan_tunnel = -1; |
9208b4e7 | 289 | __s8 mcast_flood = -1; |
64108901 VY |
290 | __s8 hairpin = -1; |
291 | __s8 bpdu_guard = -1; | |
292 | __s8 fast_leave = -1; | |
b1b7ce0f | 293 | __s8 root_block = -1; |
64108901 VY |
294 | __u32 cost = 0; |
295 | __s16 priority = -1; | |
296 | __s8 state = -1; | |
297 | __s16 mode = -1; | |
6fdb4658 | 298 | __u16 flags = 0; |
64108901 VY |
299 | struct rtattr *nest; |
300 | ||
64108901 VY |
301 | while (argc > 0) { |
302 | if (strcmp(*argv, "dev") == 0) { | |
303 | NEXT_ARG(); | |
304 | d = *argv; | |
305 | } else if (strcmp(*argv, "guard") == 0) { | |
306 | NEXT_ARG(); | |
307 | if (!on_off("guard", &bpdu_guard, *argv)) | |
42ecedd4 | 308 | return -1; |
64108901 VY |
309 | } else if (strcmp(*argv, "hairpin") == 0) { |
310 | NEXT_ARG(); | |
311 | if (!on_off("hairping", &hairpin, *argv)) | |
42ecedd4 | 312 | return -1; |
64108901 VY |
313 | } else if (strcmp(*argv, "fastleave") == 0) { |
314 | NEXT_ARG(); | |
315 | if (!on_off("fastleave", &fast_leave, *argv)) | |
42ecedd4 | 316 | return -1; |
b1b7ce0f VY |
317 | } else if (strcmp(*argv, "root_block") == 0) { |
318 | NEXT_ARG(); | |
319 | if (!on_off("root_block", &root_block, *argv)) | |
42ecedd4 | 320 | return -1; |
f0f4ab60 VY |
321 | } else if (strcmp(*argv, "learning") == 0) { |
322 | NEXT_ARG(); | |
323 | if (!on_off("learning", &learning, *argv)) | |
42ecedd4 | 324 | return -1; |
674bb438 SF |
325 | } else if (strcmp(*argv, "learning_sync") == 0) { |
326 | NEXT_ARG(); | |
327 | if (!on_off("learning_sync", &learning_sync, *argv)) | |
42ecedd4 | 328 | return -1; |
f0f4ab60 VY |
329 | } else if (strcmp(*argv, "flood") == 0) { |
330 | NEXT_ARG(); | |
331 | if (!on_off("flood", &flood, *argv)) | |
42ecedd4 | 332 | return -1; |
9208b4e7 NA |
333 | } else if (strcmp(*argv, "mcast_flood") == 0) { |
334 | NEXT_ARG(); | |
335 | if (!on_off("mcast_flood", &mcast_flood, *argv)) | |
336 | return -1; | |
a40d0827 | 337 | } else if (strcmp(*argv, "cost") == 0) { |
64108901 VY |
338 | NEXT_ARG(); |
339 | cost = atoi(*argv); | |
a40d0827 | 340 | } else if (strcmp(*argv, "priority") == 0) { |
64108901 VY |
341 | NEXT_ARG(); |
342 | priority = atoi(*argv); | |
a40d0827 | 343 | } else if (strcmp(*argv, "state") == 0) { |
64108901 | 344 | NEXT_ARG(); |
6b8c871d | 345 | char *endptr; |
62000e51 | 346 | size_t nstates = ARRAY_SIZE(port_states); |
df4b043f | 347 | |
6b8c871d AP |
348 | state = strtol(*argv, &endptr, 10); |
349 | if (!(**argv != '\0' && *endptr == '\0')) { | |
350 | for (state = 0; state < nstates; state++) | |
351 | if (strcmp(port_states[state], *argv) == 0) | |
352 | break; | |
353 | if (state == nstates) { | |
354 | fprintf(stderr, | |
355 | "Error: invalid STP port state\n"); | |
42ecedd4 | 356 | return -1; |
6b8c871d AP |
357 | } |
358 | } | |
a40d0827 | 359 | } else if (strcmp(*argv, "hwmode") == 0) { |
64108901 | 360 | NEXT_ARG(); |
a40d0827 | 361 | flags = BRIDGE_FLAGS_SELF; |
64108901 VY |
362 | if (strcmp(*argv, "vepa") == 0) |
363 | mode = BRIDGE_MODE_VEPA; | |
364 | else if (strcmp(*argv, "veb") == 0) | |
365 | mode = BRIDGE_MODE_VEB; | |
366 | else { | |
367 | fprintf(stderr, | |
df4b043f | 368 | "Mode argument must be \"vepa\" or \"veb\".\n"); |
42ecedd4 | 369 | return -1; |
64108901 | 370 | } |
6fdb4658 | 371 | } else if (strcmp(*argv, "self") == 0) { |
22a98f51 RP |
372 | flags |= BRIDGE_FLAGS_SELF; |
373 | } else if (strcmp(*argv, "master") == 0) { | |
374 | flags |= BRIDGE_FLAGS_MASTER; | |
41973a47 RP |
375 | } else if (strcmp(*argv, "neigh_suppress") == 0) { |
376 | NEXT_ARG(); | |
377 | if (!on_off("neigh_suppress", &neigh_suppress, | |
378 | *argv)) | |
379 | return -1; | |
8cfde5c9 RP |
380 | } else if (strcmp(*argv, "vlan_tunnel") == 0) { |
381 | NEXT_ARG(); | |
382 | if (!on_off("vlan_tunnel", &vlan_tunnel, | |
383 | *argv)) | |
384 | return -1; | |
64108901 VY |
385 | } else { |
386 | usage(); | |
387 | } | |
388 | argc--; argv++; | |
389 | } | |
390 | if (d == NULL) { | |
391 | fprintf(stderr, "Device is a required argument.\n"); | |
42ecedd4 | 392 | return -1; |
64108901 VY |
393 | } |
394 | ||
395 | ||
396 | req.ifm.ifi_index = ll_name_to_index(d); | |
397 | if (req.ifm.ifi_index == 0) { | |
398 | fprintf(stderr, "Cannot find bridge device \"%s\"\n", d); | |
42ecedd4 | 399 | return -1; |
64108901 VY |
400 | } |
401 | ||
402 | /* Nested PROTINFO attribute. Contains: port flags, cost, priority and | |
403 | * state. | |
404 | */ | |
405 | nest = addattr_nest(&req.n, sizeof(req), | |
406 | IFLA_PROTINFO | NLA_F_NESTED); | |
407 | /* Flags first */ | |
408 | if (bpdu_guard >= 0) | |
409 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_GUARD, bpdu_guard); | |
410 | if (hairpin >= 0) | |
411 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_MODE, hairpin); | |
412 | if (fast_leave >= 0) | |
413 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_FAST_LEAVE, | |
414 | fast_leave); | |
b1b7ce0f VY |
415 | if (root_block >= 0) |
416 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_PROTECT, root_block); | |
f0f4ab60 VY |
417 | if (flood >= 0) |
418 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_UNICAST_FLOOD, flood); | |
9208b4e7 NA |
419 | if (mcast_flood >= 0) |
420 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_MCAST_FLOOD, | |
421 | mcast_flood); | |
f0f4ab60 VY |
422 | if (learning >= 0) |
423 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_LEARNING, learning); | |
674bb438 SF |
424 | if (learning_sync >= 0) |
425 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_LEARNING_SYNC, | |
426 | learning_sync); | |
64108901 VY |
427 | |
428 | if (cost > 0) | |
429 | addattr32(&req.n, sizeof(req), IFLA_BRPORT_COST, cost); | |
430 | ||
431 | if (priority >= 0) | |
432 | addattr16(&req.n, sizeof(req), IFLA_BRPORT_PRIORITY, priority); | |
433 | ||
434 | if (state >= 0) | |
435 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_STATE, state); | |
436 | ||
41973a47 RP |
437 | if (neigh_suppress != -1) |
438 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_NEIGH_SUPPRESS, | |
439 | neigh_suppress); | |
8cfde5c9 RP |
440 | if (vlan_tunnel != -1) |
441 | addattr8(&req.n, sizeof(req), IFLA_BRPORT_VLAN_TUNNEL, | |
442 | vlan_tunnel); | |
41973a47 | 443 | |
64108901 VY |
444 | addattr_nest_end(&req.n, nest); |
445 | ||
6fdb4658 RP |
446 | /* IFLA_AF_SPEC nested attribute. Contains IFLA_BRIDGE_FLAGS that |
447 | * designates master or self operation and IFLA_BRIDGE_MODE | |
448 | * for hw 'vepa' or 'veb' operation modes. The hwmodes are | |
449 | * only valid in 'self' mode on some devices so far. | |
64108901 | 450 | */ |
6fdb4658 | 451 | if (mode >= 0 || flags > 0) { |
64108901 VY |
452 | nest = addattr_nest(&req.n, sizeof(req), IFLA_AF_SPEC); |
453 | ||
6fdb4658 RP |
454 | if (flags > 0) |
455 | addattr16(&req.n, sizeof(req), IFLA_BRIDGE_FLAGS, flags); | |
64108901 VY |
456 | |
457 | if (mode >= 0) | |
458 | addattr16(&req.n, sizeof(req), IFLA_BRIDGE_MODE, mode); | |
459 | ||
460 | addattr_nest_end(&req.n, nest); | |
461 | } | |
462 | ||
86bf43c7 | 463 | if (rtnl_talk(&rth, &req.n, NULL) < 0) |
42ecedd4 | 464 | return -1; |
64108901 VY |
465 | |
466 | return 0; | |
467 | } | |
468 | ||
469 | static int brlink_show(int argc, char **argv) | |
470 | { | |
471 | char *filter_dev = NULL; | |
472 | ||
473 | while (argc > 0) { | |
474 | if (strcmp(*argv, "dev") == 0) { | |
475 | NEXT_ARG(); | |
476 | if (filter_dev) | |
477 | duparg("dev", *argv); | |
478 | filter_dev = *argv; | |
479 | } | |
480 | argc--; argv++; | |
481 | } | |
482 | ||
483 | if (filter_dev) { | |
484 | if ((filter_index = ll_name_to_index(filter_dev)) == 0) { | |
485 | fprintf(stderr, "Cannot find device \"%s\"\n", | |
486 | filter_dev); | |
487 | return -1; | |
488 | } | |
489 | } | |
490 | ||
fab9a18a RM |
491 | if (show_details) { |
492 | if (rtnl_wilddump_req_filter(&rth, PF_BRIDGE, RTM_GETLINK, | |
493 | (compress_vlans ? | |
494 | RTEXT_FILTER_BRVLAN_COMPRESSED : | |
495 | RTEXT_FILTER_BRVLAN)) < 0) { | |
496 | perror("Cannon send dump request"); | |
497 | exit(1); | |
498 | } | |
499 | } else { | |
500 | if (rtnl_wilddump_request(&rth, PF_BRIDGE, RTM_GETLINK) < 0) { | |
501 | perror("Cannon send dump request"); | |
502 | exit(1); | |
503 | } | |
64108901 VY |
504 | } |
505 | ||
506 | if (rtnl_dump_filter(&rth, print_linkinfo, stdout) < 0) { | |
507 | fprintf(stderr, "Dump terminated\n"); | |
508 | exit(1); | |
509 | } | |
510 | return 0; | |
511 | } | |
512 | ||
513 | int do_link(int argc, char **argv) | |
514 | { | |
515 | ll_init_map(&rth); | |
516 | if (argc > 0) { | |
517 | if (matches(*argv, "set") == 0 || | |
518 | matches(*argv, "change") == 0) | |
519 | return brlink_modify(argc-1, argv+1); | |
520 | if (matches(*argv, "show") == 0 || | |
521 | matches(*argv, "lst") == 0 || | |
522 | matches(*argv, "list") == 0) | |
523 | return brlink_show(argc-1, argv+1); | |
524 | if (matches(*argv, "help") == 0) | |
525 | usage(); | |
526 | } else | |
527 | return brlink_show(0, NULL); | |
528 | ||
529 | fprintf(stderr, "Command \"%s\" is unknown, try \"bridge link help\".\n", *argv); | |
530 | exit(-1); | |
531 | } |