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