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