blob: 1b666f0adef48ca697d689348236467379e9641c [file] [log] [blame]
Jiri Pirko28d84b42014-09-28 16:33:29 -07001/*
2 * iplink_bridge.c Bridge device support
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Authors: Jiri Pirko <jiri@resnulli.us>
10 */
11
12#include <stdio.h>
13#include <stdlib.h>
14#include <string.h>
15#include <linux/if_link.h>
Nikolay Aleksandrov70dfb0b2016-02-09 00:14:19 +010016#include <netinet/ether.h>
Jiri Pirko28d84b42014-09-28 16:33:29 -070017
Toshiaki Makita1eea5c42015-08-31 18:48:46 +090018#include "rt_names.h"
Jiri Pirko28d84b42014-09-28 16:33:29 -070019#include "utils.h"
20#include "ip_common.h"
21
Zhang Shengju43367ef2015-08-12 06:03:23 +000022static void print_explain(FILE *f)
Jiri Pirko28d84b42014-09-28 16:33:29 -070023{
Zhang Shengju43367ef2015-08-12 06:03:23 +000024 fprintf(f,
Jiri Pirko28d84b42014-09-28 16:33:29 -070025 "Usage: ... bridge [ forward_delay FORWARD_DELAY ]\n"
26 " [ hello_time HELLO_TIME ]\n"
27 " [ max_age MAX_AGE ]\n"
Nikolay Aleksandrov6c99fb62015-06-16 13:38:47 +030028 " [ ageing_time AGEING_TIME ]\n"
Nikolay Aleksandrovdab04962015-06-16 13:38:48 +030029 " [ stp_state STP_STATE ]\n"
Nikolay Aleksandrovb0197a02015-06-16 13:38:49 +030030 " [ priority PRIORITY ]\n"
Nikolay Aleksandrov8caaf332016-02-09 00:14:22 +010031 " [ group_fwd_mask MASK ]\n"
Nikolay Aleksandrov0a61aa32016-02-09 00:14:23 +010032 " [ group_address ADDRESS ]\n"
Nikolay Aleksandrove4d456f2015-08-12 09:19:06 -070033 " [ vlan_filtering VLAN_FILTERING ]\n"
Toshiaki Makita1eea5c42015-08-31 18:48:46 +090034 " [ vlan_protocol VLAN_PROTOCOL ]\n"
Nikolay Aleksandrov719832a2016-02-09 00:14:24 +010035 " [ vlan_default_pvid VLAN_DEFAULT_PVID ]\n"
Nikolay Aleksandrov7ddd2d92016-02-09 00:14:26 +010036 " [ mcast_snooping MULTICAST_SNOOPING ]\n"
Nikolay Aleksandrov963d1372016-02-09 00:14:25 +010037 " [ mcast_router MULTICAST_ROUTER ]\n"
Nikolay Aleksandrov449843d2016-02-09 00:14:27 +010038 " [ mcast_query_use_ifaddr MCAST_QUERY_USE_IFADDR ]\n"
Nikolay Aleksandrov0778b742016-02-09 00:14:28 +010039 " [ mcast_querier MULTICAST_QUERIER ]\n"
Nikolay Aleksandrov92c0ef72016-02-09 00:14:29 +010040 " [ mcast_hash_elasticity HASH_ELASTICITY ]\n"
Nikolay Aleksandrov8b9eb7c2016-02-09 00:14:30 +010041 " [ mcast_hash_max HASH_MAX ]\n"
Nikolay Aleksandrovfb44cad2016-02-09 00:14:31 +010042 " [ mcast_last_member_count LAST_MEMBER_COUNT ]\n"
Nikolay Aleksandrovceb64862016-02-09 00:14:32 +010043 " [ mcast_startup_query_count STARTUP_QUERY_COUNT ]\n"
Nikolay Aleksandrov10082a22016-02-09 00:14:33 +010044 " [ mcast_last_member_interval LAST_MEMBER_INTERVAL ]\n"
Nikolay Aleksandrov7f3d5592016-02-09 00:14:34 +010045 " [ mcast_membership_interval MEMBERSHIP_INTERVAL ]\n"
Nikolay Aleksandrov1f2244b2016-02-09 00:14:35 +010046 " [ mcast_querier_interval QUERIER_INTERVAL ]\n"
Nikolay Aleksandrov5a323882016-02-09 00:14:36 +010047 " [ mcast_query_interval QUERY_INTERVAL ]\n"
Nikolay Aleksandrov483df112016-02-09 00:14:37 +010048 " [ mcast_query_response_interval QUERY_RESPONSE_INTERVAL ]\n"
Nikolay Aleksandrov178b1802016-02-09 00:14:38 +010049 " [ mcast_startup_query_interval STARTUP_QUERY_INTERVAL ]\n"
Nikolay Aleksandrov861c5da2016-02-09 00:14:39 +010050 " [ nf_call_iptables NF_CALL_IPTABLES ]\n"
51 " [ nf_call_ip6tables NF_CALL_IP6TABLES ]\n"
52 " [ nf_call_arptables NF_CALL_ARPTABLES ]\n"
Toshiaki Makita1eea5c42015-08-31 18:48:46 +090053 "\n"
54 "Where: VLAN_PROTOCOL := { 802.1Q | 802.1ad }\n"
Jiri Pirko28d84b42014-09-28 16:33:29 -070055 );
56}
57
Zhang Shengju43367ef2015-08-12 06:03:23 +000058static void explain(void)
59{
60 print_explain(stderr);
61}
62
Nikolay Aleksandrov70dfb0b2016-02-09 00:14:19 +010063static void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf,
64 size_t len)
65{
66 char eaddr[32];
67
68 ether_ntoa_r((const struct ether_addr *)id->addr, eaddr);
69 snprintf(buf, len, "%.2x%.2x.%s", id->prio[0], id->prio[1], eaddr);
70}
71
Jiri Pirko28d84b42014-09-28 16:33:29 -070072static int bridge_parse_opt(struct link_util *lu, int argc, char **argv,
73 struct nlmsghdr *n)
74{
75 __u32 val;
76
77 while (argc > 0) {
78 if (matches(*argv, "forward_delay") == 0) {
79 NEXT_ARG();
Zhang Shengju6a9ce302015-08-13 07:48:15 +000080 if (get_u32(&val, *argv, 0))
Jiri Pirko28d84b42014-09-28 16:33:29 -070081 invarg("invalid forward_delay", *argv);
Zhang Shengju6a9ce302015-08-13 07:48:15 +000082
Jiri Pirko28d84b42014-09-28 16:33:29 -070083 addattr32(n, 1024, IFLA_BR_FORWARD_DELAY, val);
84 } else if (matches(*argv, "hello_time") == 0) {
85 NEXT_ARG();
Zhang Shengju6a9ce302015-08-13 07:48:15 +000086 if (get_u32(&val, *argv, 0))
Jiri Pirko28d84b42014-09-28 16:33:29 -070087 invarg("invalid hello_time", *argv);
Zhang Shengju6a9ce302015-08-13 07:48:15 +000088
Jiri Pirko28d84b42014-09-28 16:33:29 -070089 addattr32(n, 1024, IFLA_BR_HELLO_TIME, val);
90 } else if (matches(*argv, "max_age") == 0) {
91 NEXT_ARG();
Zhang Shengju6a9ce302015-08-13 07:48:15 +000092 if (get_u32(&val, *argv, 0))
Jiri Pirko28d84b42014-09-28 16:33:29 -070093 invarg("invalid max_age", *argv);
Zhang Shengju6a9ce302015-08-13 07:48:15 +000094
Jiri Pirko28d84b42014-09-28 16:33:29 -070095 addattr32(n, 1024, IFLA_BR_MAX_AGE, val);
Nikolay Aleksandrov6c99fb62015-06-16 13:38:47 +030096 } else if (matches(*argv, "ageing_time") == 0) {
97 NEXT_ARG();
Zhang Shengju6a9ce302015-08-13 07:48:15 +000098 if (get_u32(&val, *argv, 0))
Nikolay Aleksandrov6c99fb62015-06-16 13:38:47 +030099 invarg("invalid ageing_time", *argv);
Zhang Shengju6a9ce302015-08-13 07:48:15 +0000100
Nikolay Aleksandrov6c99fb62015-06-16 13:38:47 +0300101 addattr32(n, 1024, IFLA_BR_AGEING_TIME, val);
Nikolay Aleksandrovdab04962015-06-16 13:38:48 +0300102 } else if (matches(*argv, "stp_state") == 0) {
103 NEXT_ARG();
Zhang Shengju6a9ce302015-08-13 07:48:15 +0000104 if (get_u32(&val, *argv, 0))
Nikolay Aleksandrovdab04962015-06-16 13:38:48 +0300105 invarg("invalid stp_state", *argv);
Zhang Shengju6a9ce302015-08-13 07:48:15 +0000106
Nikolay Aleksandrovdab04962015-06-16 13:38:48 +0300107 addattr32(n, 1024, IFLA_BR_STP_STATE, val);
Nikolay Aleksandrovb0197a02015-06-16 13:38:49 +0300108 } else if (matches(*argv, "priority") == 0) {
109 __u16 prio;
110
111 NEXT_ARG();
Zhang Shengju6a9ce302015-08-13 07:48:15 +0000112 if (get_u16(&prio, *argv, 0))
Nikolay Aleksandrovb0197a02015-06-16 13:38:49 +0300113 invarg("invalid priority", *argv);
Zhang Shengju6a9ce302015-08-13 07:48:15 +0000114
Nikolay Aleksandrovb0197a02015-06-16 13:38:49 +0300115 addattr16(n, 1024, IFLA_BR_PRIORITY, prio);
Nikolay Aleksandrove4d456f2015-08-12 09:19:06 -0700116 } else if (matches(*argv, "vlan_filtering") == 0) {
117 __u8 vlan_filter;
118
119 NEXT_ARG();
120 if (get_u8(&vlan_filter, *argv, 0)) {
121 invarg("invalid vlan_filtering", *argv);
122 return -1;
123 }
124 addattr8(n, 1024, IFLA_BR_VLAN_FILTERING, vlan_filter);
Toshiaki Makita1eea5c42015-08-31 18:48:46 +0900125 } else if (matches(*argv, "vlan_protocol") == 0) {
126 __u16 vlan_proto;
127
128 NEXT_ARG();
129 if (ll_proto_a2n(&vlan_proto, *argv)) {
130 invarg("invalid vlan_protocol", *argv);
131 return -1;
132 }
133 addattr16(n, 1024, IFLA_BR_VLAN_PROTOCOL, vlan_proto);
Nikolay Aleksandrov8caaf332016-02-09 00:14:22 +0100134 } else if (matches(*argv, "group_fwd_mask") == 0) {
135 __u16 fwd_mask;
136
137 NEXT_ARG();
138 if (get_u16(&fwd_mask, *argv, 0))
139 invarg("invalid group_fwd_mask", *argv);
140
141 addattr16(n, 1024, IFLA_BR_GROUP_FWD_MASK, fwd_mask);
Nikolay Aleksandrov0a61aa32016-02-09 00:14:23 +0100142 } else if (matches(*argv, "group_address") == 0) {
143 char llabuf[32];
144 int len;
145
146 NEXT_ARG();
147 len = ll_addr_a2n(llabuf, sizeof(llabuf), *argv);
148 if (len < 0)
149 return -1;
150 addattr_l(n, 1024, IFLA_BR_GROUP_ADDR, llabuf, len);
Nikolay Aleksandrov719832a2016-02-09 00:14:24 +0100151 } else if (matches(*argv, "vlan_default_pvid") == 0) {
152 __u16 default_pvid;
153
154 NEXT_ARG();
155 if (get_u16(&default_pvid, *argv, 0))
156 invarg("invalid vlan_default_pvid", *argv);
157
158 addattr16(n, 1024, IFLA_BR_VLAN_DEFAULT_PVID,
159 default_pvid);
Nikolay Aleksandrov963d1372016-02-09 00:14:25 +0100160 } else if (matches(*argv, "mcast_router") == 0) {
161 __u8 mcast_router;
162
163 NEXT_ARG();
164 if (get_u8(&mcast_router, *argv, 0))
165 invarg("invalid mcast_router", *argv);
166
167 addattr8(n, 1024, IFLA_BR_MCAST_ROUTER, mcast_router);
Nikolay Aleksandrov7ddd2d92016-02-09 00:14:26 +0100168 } else if (matches(*argv, "mcast_snooping") == 0) {
169 __u8 mcast_snoop;
170
171 NEXT_ARG();
172 if (get_u8(&mcast_snoop, *argv, 0))
173 invarg("invalid mcast_snooping", *argv);
174
175 addattr8(n, 1024, IFLA_BR_MCAST_SNOOPING, mcast_snoop);
Nikolay Aleksandrov449843d2016-02-09 00:14:27 +0100176 } else if (matches(*argv, "mcast_query_use_ifaddr") == 0) {
177 __u8 mcast_qui;
178
179 NEXT_ARG();
180 if (get_u8(&mcast_qui, *argv, 0))
181 invarg("invalid mcast_query_use_ifaddr",
182 *argv);
183
184 addattr8(n, 1024, IFLA_BR_MCAST_QUERY_USE_IFADDR,
185 mcast_qui);
Nikolay Aleksandrov0778b742016-02-09 00:14:28 +0100186 } else if (matches(*argv, "mcast_querier") == 0) {
187 __u8 mcast_querier;
188
189 NEXT_ARG();
190 if (get_u8(&mcast_querier, *argv, 0))
191 invarg("invalid mcast_querier", *argv);
192
193 addattr8(n, 1024, IFLA_BR_MCAST_QUERIER, mcast_querier);
Nikolay Aleksandrov92c0ef72016-02-09 00:14:29 +0100194 } else if (matches(*argv, "mcast_hash_elasticity") == 0) {
195 __u32 mcast_hash_el;
196
197 NEXT_ARG();
198 if (get_u32(&mcast_hash_el, *argv, 0))
199 invarg("invalid mcast_hash_elasticity",
200 *argv);
201
202 addattr32(n, 1024, IFLA_BR_MCAST_HASH_ELASTICITY,
203 mcast_hash_el);
Nikolay Aleksandrov8b9eb7c2016-02-09 00:14:30 +0100204 } else if (matches(*argv, "mcast_hash_max") == 0) {
205 __u32 mcast_hash_max;
206
207 NEXT_ARG();
208 if (get_u32(&mcast_hash_max, *argv, 0))
209 invarg("invalid mcast_hash_max", *argv);
210
211 addattr32(n, 1024, IFLA_BR_MCAST_HASH_MAX,
212 mcast_hash_max);
Nikolay Aleksandrovfb44cad2016-02-09 00:14:31 +0100213 } else if (matches(*argv, "mcast_last_member_count") == 0) {
214 __u32 mcast_lmc;
215
216 NEXT_ARG();
217 if (get_u32(&mcast_lmc, *argv, 0))
218 invarg("invalid mcast_last_member_count",
219 *argv);
220
221 addattr32(n, 1024, IFLA_BR_MCAST_LAST_MEMBER_CNT,
222 mcast_lmc);
Nikolay Aleksandrovceb64862016-02-09 00:14:32 +0100223 } else if (matches(*argv, "mcast_startup_query_count") == 0) {
224 __u32 mcast_sqc;
225
226 NEXT_ARG();
227 if (get_u32(&mcast_sqc, *argv, 0))
228 invarg("invalid mcast_startup_query_count",
229 *argv);
230
231 addattr32(n, 1024, IFLA_BR_MCAST_STARTUP_QUERY_CNT,
232 mcast_sqc);
Nikolay Aleksandrov10082a22016-02-09 00:14:33 +0100233 } else if (matches(*argv, "mcast_last_member_interval") == 0) {
234 __u64 mcast_last_member_intvl;
235
236 NEXT_ARG();
237 if (get_u64(&mcast_last_member_intvl, *argv, 0))
238 invarg("invalid mcast_last_member_interval",
239 *argv);
240
241 addattr64(n, 1024, IFLA_BR_MCAST_LAST_MEMBER_INTVL,
242 mcast_last_member_intvl);
Nikolay Aleksandrov7f3d5592016-02-09 00:14:34 +0100243 } else if (matches(*argv, "mcast_membership_interval") == 0) {
244 __u64 mcast_membership_intvl;
245
246 NEXT_ARG();
247 if (get_u64(&mcast_membership_intvl, *argv, 0)) {
248 invarg("invalid mcast_membership_interval",
249 *argv);
250 return -1;
251 }
252 addattr64(n, 1024, IFLA_BR_MCAST_MEMBERSHIP_INTVL,
253 mcast_membership_intvl);
Nikolay Aleksandrov1f2244b2016-02-09 00:14:35 +0100254 } else if (matches(*argv, "mcast_querier_interval") == 0) {
255 __u64 mcast_querier_intvl;
256
257 NEXT_ARG();
258 if (get_u64(&mcast_querier_intvl, *argv, 0)) {
259 invarg("invalid mcast_querier_interval",
260 *argv);
261 return -1;
262 }
263 addattr64(n, 1024, IFLA_BR_MCAST_QUERIER_INTVL,
264 mcast_querier_intvl);
Nikolay Aleksandrov5a323882016-02-09 00:14:36 +0100265 } else if (matches(*argv, "mcast_query_interval") == 0) {
266 __u64 mcast_query_intvl;
267
268 NEXT_ARG();
269 if (get_u64(&mcast_query_intvl, *argv, 0)) {
270 invarg("invalid mcast_query_interval",
271 *argv);
272 return -1;
273 }
274 addattr64(n, 1024, IFLA_BR_MCAST_QUERY_INTVL,
275 mcast_query_intvl);
Nikolay Aleksandrov483df112016-02-09 00:14:37 +0100276 } else if (!matches(*argv, "mcast_query_response_interval")) {
277 __u64 mcast_query_resp_intvl;
278
279 NEXT_ARG();
280 if (get_u64(&mcast_query_resp_intvl, *argv, 0)) {
281 invarg("invalid mcast_query_response_interval",
282 *argv);
283 return -1;
284 }
285 addattr64(n, 1024, IFLA_BR_MCAST_QUERY_RESPONSE_INTVL,
286 mcast_query_resp_intvl);
Nikolay Aleksandrov178b1802016-02-09 00:14:38 +0100287 } else if (!matches(*argv, "mcast_startup_query_interval")) {
288 __u64 mcast_startup_query_intvl;
289
290 NEXT_ARG();
291 if (get_u64(&mcast_startup_query_intvl, *argv, 0)) {
292 invarg("invalid mcast_startup_query_interval",
293 *argv);
294 return -1;
295 }
296 addattr64(n, 1024, IFLA_BR_MCAST_STARTUP_QUERY_INTVL,
297 mcast_startup_query_intvl);
Nikolay Aleksandrov861c5da2016-02-09 00:14:39 +0100298 } else if (matches(*argv, "nf_call_iptables") == 0) {
299 __u8 nf_call_ipt;
300
301 NEXT_ARG();
302 if (get_u8(&nf_call_ipt, *argv, 0)) {
303 invarg("invalid nf_call_iptables", *argv);
304 return -1;
305 }
306 addattr8(n, 1024, IFLA_BR_NF_CALL_IPTABLES,
307 nf_call_ipt);
308 } else if (matches(*argv, "nf_call_ip6tables") == 0) {
309 __u8 nf_call_ip6t;
310
311 NEXT_ARG();
312 if (get_u8(&nf_call_ip6t, *argv, 0)) {
313 invarg("invalid nf_call_ip6tables", *argv);
314 return -1;
315 }
316 addattr8(n, 1024, IFLA_BR_NF_CALL_IP6TABLES,
317 nf_call_ip6t);
318 } else if (matches(*argv, "nf_call_arptables") == 0) {
319 __u8 nf_call_arpt;
320
321 NEXT_ARG();
322 if (get_u8(&nf_call_arpt, *argv, 0)) {
323 invarg("invalid nf_call_arptables", *argv);
324 return -1;
325 }
326 addattr8(n, 1024, IFLA_BR_NF_CALL_ARPTABLES,
327 nf_call_arpt);
Jiri Pirko28d84b42014-09-28 16:33:29 -0700328 } else if (matches(*argv, "help") == 0) {
329 explain();
330 return -1;
331 } else {
332 fprintf(stderr, "bridge: unknown command \"%s\"?\n", *argv);
333 explain();
334 return -1;
335 }
336 argc--, argv++;
337 }
338
339 return 0;
340}
341
342static void bridge_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
343{
344 if (!tb)
345 return;
346
347 if (tb[IFLA_BR_FORWARD_DELAY])
348 fprintf(f, "forward_delay %u ",
349 rta_getattr_u32(tb[IFLA_BR_FORWARD_DELAY]));
350
351 if (tb[IFLA_BR_HELLO_TIME])
352 fprintf(f, "hello_time %u ",
353 rta_getattr_u32(tb[IFLA_BR_HELLO_TIME]));
354
355 if (tb[IFLA_BR_MAX_AGE])
356 fprintf(f, "max_age %u ",
357 rta_getattr_u32(tb[IFLA_BR_MAX_AGE]));
Nikolay Aleksandrovfdba0512015-08-12 09:11:30 -0700358
359 if (tb[IFLA_BR_AGEING_TIME])
360 fprintf(f, "ageing_time %u ",
361 rta_getattr_u32(tb[IFLA_BR_AGEING_TIME]));
362
363 if (tb[IFLA_BR_STP_STATE])
364 fprintf(f, "stp_state %u ",
365 rta_getattr_u32(tb[IFLA_BR_STP_STATE]));
366
367 if (tb[IFLA_BR_PRIORITY])
368 fprintf(f, "priority %u ",
369 rta_getattr_u16(tb[IFLA_BR_PRIORITY]));
Nikolay Aleksandrove4d456f2015-08-12 09:19:06 -0700370
371 if (tb[IFLA_BR_VLAN_FILTERING])
372 fprintf(f, "vlan_filtering %u ",
373 rta_getattr_u8(tb[IFLA_BR_VLAN_FILTERING]));
Toshiaki Makita1eea5c42015-08-31 18:48:46 +0900374
375 if (tb[IFLA_BR_VLAN_PROTOCOL]) {
376 SPRINT_BUF(b1);
377
378 fprintf(f, "vlan_protocol %s ",
379 ll_proto_n2a(rta_getattr_u16(tb[IFLA_BR_VLAN_PROTOCOL]),
380 b1, sizeof(b1)));
381 }
Nikolay Aleksandrov70dfb0b2016-02-09 00:14:19 +0100382
383 if (tb[IFLA_BR_BRIDGE_ID]) {
384 char bridge_id[32];
385
386 br_dump_bridge_id(RTA_DATA(tb[IFLA_BR_BRIDGE_ID]), bridge_id,
387 sizeof(bridge_id));
388 fprintf(f, "bridge_id %s ", bridge_id);
389 }
390
391 if (tb[IFLA_BR_ROOT_ID]) {
392 char root_id[32];
393
394 br_dump_bridge_id(RTA_DATA(tb[IFLA_BR_BRIDGE_ID]), root_id,
395 sizeof(root_id));
396 fprintf(f, "designated_root %s ", root_id);
397 }
Nikolay Aleksandrov4e3bbc62016-02-09 00:14:20 +0100398
399 if (tb[IFLA_BR_ROOT_PORT])
400 fprintf(f, "root_port %u ",
401 rta_getattr_u16(tb[IFLA_BR_ROOT_PORT]));
402
403 if (tb[IFLA_BR_ROOT_PATH_COST])
404 fprintf(f, "root_path_cost %u ",
405 rta_getattr_u32(tb[IFLA_BR_ROOT_PATH_COST]));
406
407 if (tb[IFLA_BR_TOPOLOGY_CHANGE])
408 fprintf(f, "topology_change %u ",
409 rta_getattr_u8(tb[IFLA_BR_TOPOLOGY_CHANGE]));
410
411 if (tb[IFLA_BR_TOPOLOGY_CHANGE_DETECTED])
412 fprintf(f, "topology_change_detected %u ",
413 rta_getattr_u8(tb[IFLA_BR_TOPOLOGY_CHANGE_DETECTED]));
Nikolay Aleksandrov8c0f7a12016-02-09 00:14:21 +0100414
415 if (tb[IFLA_BR_HELLO_TIMER]) {
416 struct timeval tv;
417
418 __jiffies_to_tv(&tv, rta_getattr_u64(tb[IFLA_BR_HELLO_TIMER]));
419 fprintf(f, "hello_timer %4i.%.2i ", (int)tv.tv_sec,
420 (int)tv.tv_usec/10000);
421 }
422
423 if (tb[IFLA_BR_TCN_TIMER]) {
424 struct timeval tv;
425
426 __jiffies_to_tv(&tv, rta_getattr_u64(tb[IFLA_BR_TCN_TIMER]));
427 fprintf(f, "tcn_timer %4i.%.2i ", (int)tv.tv_sec,
428 (int)tv.tv_usec/10000);
429 }
430
431 if (tb[IFLA_BR_TOPOLOGY_CHANGE_TIMER]) {
432 unsigned long jiffies;
433 struct timeval tv;
434
435 jiffies = rta_getattr_u64(tb[IFLA_BR_TOPOLOGY_CHANGE_TIMER]);
436 __jiffies_to_tv(&tv, jiffies);
437 fprintf(f, "topology_change_timer %4i.%.2i ", (int)tv.tv_sec,
438 (int)tv.tv_usec/10000);
439 }
440
441 if (tb[IFLA_BR_GC_TIMER]) {
442 struct timeval tv;
443
444 __jiffies_to_tv(&tv, rta_getattr_u64(tb[IFLA_BR_GC_TIMER]));
445 fprintf(f, "gc_timer %4i.%.2i ", (int)tv.tv_sec,
446 (int)tv.tv_usec/10000);
447 }
Nikolay Aleksandrov8caaf332016-02-09 00:14:22 +0100448
Nikolay Aleksandrov719832a2016-02-09 00:14:24 +0100449 if (tb[IFLA_BR_VLAN_DEFAULT_PVID])
450 fprintf(f, "vlan_default_pvid %u ",
451 rta_getattr_u16(tb[IFLA_BR_VLAN_DEFAULT_PVID]));
452
Nikolay Aleksandrov8caaf332016-02-09 00:14:22 +0100453 if (tb[IFLA_BR_GROUP_FWD_MASK])
454 fprintf(f, "group_fwd_mask %#x ",
455 rta_getattr_u16(tb[IFLA_BR_GROUP_FWD_MASK]));
Nikolay Aleksandrov0a61aa32016-02-09 00:14:23 +0100456
457 if (tb[IFLA_BR_GROUP_ADDR]) {
458 SPRINT_BUF(mac);
459
460 fprintf(f, "group_address %s ",
461 ll_addr_n2a(RTA_DATA(tb[IFLA_BR_GROUP_ADDR]),
462 RTA_PAYLOAD(tb[IFLA_BR_GROUP_ADDR]),
463 1 /*ARPHDR_ETHER*/, mac, sizeof(mac)));
464 }
Nikolay Aleksandrov963d1372016-02-09 00:14:25 +0100465
Nikolay Aleksandrov7ddd2d92016-02-09 00:14:26 +0100466 if (tb[IFLA_BR_MCAST_SNOOPING])
467 fprintf(f, "mcast_snooping %u ",
468 rta_getattr_u8(tb[IFLA_BR_MCAST_SNOOPING]));
469
Nikolay Aleksandrov963d1372016-02-09 00:14:25 +0100470 if (tb[IFLA_BR_MCAST_ROUTER])
471 fprintf(f, "mcast_router %u ",
472 rta_getattr_u8(tb[IFLA_BR_MCAST_ROUTER]));
Nikolay Aleksandrov449843d2016-02-09 00:14:27 +0100473
474 if (tb[IFLA_BR_MCAST_QUERY_USE_IFADDR])
475 fprintf(f, "mcast_query_use_ifaddr %u ",
476 rta_getattr_u8(tb[IFLA_BR_MCAST_QUERY_USE_IFADDR]));
Nikolay Aleksandrov0778b742016-02-09 00:14:28 +0100477
478 if (tb[IFLA_BR_MCAST_QUERIER])
479 fprintf(f, "mcast_querier %u ",
480 rta_getattr_u8(tb[IFLA_BR_MCAST_QUERIER]));
Nikolay Aleksandrov92c0ef72016-02-09 00:14:29 +0100481
482 if (tb[IFLA_BR_MCAST_HASH_ELASTICITY])
483 fprintf(f, "mcast_hash_elasticity %u ",
484 rta_getattr_u32(tb[IFLA_BR_MCAST_HASH_ELASTICITY]));
Nikolay Aleksandrov8b9eb7c2016-02-09 00:14:30 +0100485
486 if (tb[IFLA_BR_MCAST_HASH_MAX])
487 fprintf(f, "mcast_hash_max %u ",
488 rta_getattr_u32(tb[IFLA_BR_MCAST_HASH_MAX]));
Nikolay Aleksandrovfb44cad2016-02-09 00:14:31 +0100489
490 if (tb[IFLA_BR_MCAST_LAST_MEMBER_CNT])
491 fprintf(f, "mcast_last_member_count %u ",
492 rta_getattr_u32(tb[IFLA_BR_MCAST_LAST_MEMBER_CNT]));
Nikolay Aleksandrovceb64862016-02-09 00:14:32 +0100493
494 if (tb[IFLA_BR_MCAST_STARTUP_QUERY_CNT])
495 fprintf(f, "mcast_startup_query_count %u ",
496 rta_getattr_u32(tb[IFLA_BR_MCAST_STARTUP_QUERY_CNT]));
Nikolay Aleksandrov10082a22016-02-09 00:14:33 +0100497
498 if (tb[IFLA_BR_MCAST_LAST_MEMBER_INTVL])
499 fprintf(f, "mcast_last_member_interval %llu ",
500 rta_getattr_u64(tb[IFLA_BR_MCAST_LAST_MEMBER_INTVL]));
Nikolay Aleksandrov7f3d5592016-02-09 00:14:34 +0100501
502 if (tb[IFLA_BR_MCAST_MEMBERSHIP_INTVL])
503 fprintf(f, "mcast_membership_interval %llu ",
504 rta_getattr_u64(tb[IFLA_BR_MCAST_MEMBERSHIP_INTVL]));
Nikolay Aleksandrov1f2244b2016-02-09 00:14:35 +0100505
506 if (tb[IFLA_BR_MCAST_QUERIER_INTVL])
507 fprintf(f, "mcast_querier_interval %llu ",
508 rta_getattr_u64(tb[IFLA_BR_MCAST_QUERIER_INTVL]));
Nikolay Aleksandrov5a323882016-02-09 00:14:36 +0100509
510 if (tb[IFLA_BR_MCAST_QUERY_INTVL])
511 fprintf(f, "mcast_query_interval %llu ",
512 rta_getattr_u64(tb[IFLA_BR_MCAST_QUERY_INTVL]));
Nikolay Aleksandrov483df112016-02-09 00:14:37 +0100513
514 if (tb[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL])
515 fprintf(f, "mcast_query_response_interval %llu ",
516 rta_getattr_u64(tb[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL]));
Nikolay Aleksandrov178b1802016-02-09 00:14:38 +0100517
518 if (tb[IFLA_BR_MCAST_STARTUP_QUERY_INTVL])
519 fprintf(f, "mcast_startup_query_interval %llu ",
520 rta_getattr_u64(tb[IFLA_BR_MCAST_STARTUP_QUERY_INTVL]));
Nikolay Aleksandrov861c5da2016-02-09 00:14:39 +0100521
522 if (tb[IFLA_BR_NF_CALL_IPTABLES])
523 fprintf(f, "nf_call_iptables %u ",
524 rta_getattr_u8(tb[IFLA_BR_NF_CALL_IPTABLES]));
525
526 if (tb[IFLA_BR_NF_CALL_IP6TABLES])
527 fprintf(f, "nf_call_ip6tables %u ",
528 rta_getattr_u8(tb[IFLA_BR_NF_CALL_IP6TABLES]));
529
530 if (tb[IFLA_BR_NF_CALL_ARPTABLES])
531 fprintf(f, "nf_call_arptables %u ",
532 rta_getattr_u8(tb[IFLA_BR_NF_CALL_ARPTABLES]));
Jiri Pirko28d84b42014-09-28 16:33:29 -0700533}
534
Zhang Shengju43367ef2015-08-12 06:03:23 +0000535static void bridge_print_help(struct link_util *lu, int argc, char **argv,
536 FILE *f)
537{
538 print_explain(f);
539}
540
Jiri Pirko28d84b42014-09-28 16:33:29 -0700541struct link_util bridge_link_util = {
542 .id = "bridge",
543 .maxattr = IFLA_BR_MAX,
544 .parse_opt = bridge_parse_opt,
545 .print_opt = bridge_print_opt,
Zhang Shengju43367ef2015-08-12 06:03:23 +0000546 .print_help = bridge_print_help,
Jiri Pirko28d84b42014-09-28 16:33:29 -0700547};