2 * iplink_bridge.c Bridge device support
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.
9 * Authors: Jiri Pirko <jiri@resnulli.us>
15 #include <netinet/in.h>
16 #include <netinet/ether.h>
17 #include <linux/if_link.h>
18 #include <linux/if_bridge.h>
23 #include "ip_common.h"
25 static unsigned int xstats_print_attr
;
26 static int filter_index
;
28 static void print_explain(FILE *f
)
31 "Usage: ... bridge [ fdb_flush ]\n"
32 " [ forward_delay FORWARD_DELAY ]\n"
33 " [ hello_time HELLO_TIME ]\n"
34 " [ max_age MAX_AGE ]\n"
35 " [ ageing_time AGEING_TIME ]\n"
36 " [ stp_state STP_STATE ]\n"
37 " [ priority PRIORITY ]\n"
38 " [ group_fwd_mask MASK ]\n"
39 " [ group_address ADDRESS ]\n"
40 " [ vlan_filtering VLAN_FILTERING ]\n"
41 " [ vlan_protocol VLAN_PROTOCOL ]\n"
42 " [ vlan_default_pvid VLAN_DEFAULT_PVID ]\n"
43 " [ vlan_stats_enabled VLAN_STATS_ENABLED ]\n"
44 " [ mcast_snooping MULTICAST_SNOOPING ]\n"
45 " [ mcast_router MULTICAST_ROUTER ]\n"
46 " [ mcast_query_use_ifaddr MCAST_QUERY_USE_IFADDR ]\n"
47 " [ mcast_querier MULTICAST_QUERIER ]\n"
48 " [ mcast_hash_elasticity HASH_ELASTICITY ]\n"
49 " [ mcast_hash_max HASH_MAX ]\n"
50 " [ mcast_last_member_count LAST_MEMBER_COUNT ]\n"
51 " [ mcast_startup_query_count STARTUP_QUERY_COUNT ]\n"
52 " [ mcast_last_member_interval LAST_MEMBER_INTERVAL ]\n"
53 " [ mcast_membership_interval MEMBERSHIP_INTERVAL ]\n"
54 " [ mcast_querier_interval QUERIER_INTERVAL ]\n"
55 " [ mcast_query_interval QUERY_INTERVAL ]\n"
56 " [ mcast_query_response_interval QUERY_RESPONSE_INTERVAL ]\n"
57 " [ mcast_startup_query_interval STARTUP_QUERY_INTERVAL ]\n"
58 " [ mcast_stats_enabled MCAST_STATS_ENABLED ]\n"
59 " [ mcast_igmp_version IGMP_VERSION ]\n"
60 " [ mcast_mld_version MLD_VERSION ]\n"
61 " [ nf_call_iptables NF_CALL_IPTABLES ]\n"
62 " [ nf_call_ip6tables NF_CALL_IP6TABLES ]\n"
63 " [ nf_call_arptables NF_CALL_ARPTABLES ]\n"
65 "Where: VLAN_PROTOCOL := { 802.1Q | 802.1ad }\n"
69 static void explain(void)
71 print_explain(stderr
);
74 void br_dump_bridge_id(const struct ifla_bridge_id
*id
, char *buf
, size_t len
)
78 ether_ntoa_r((const struct ether_addr
*)id
->addr
, eaddr
);
79 snprintf(buf
, len
, "%.2x%.2x.%s", id
->prio
[0], id
->prio
[1], eaddr
);
82 static int bridge_parse_opt(struct link_util
*lu
, int argc
, char **argv
,
88 if (matches(*argv
, "forward_delay") == 0) {
90 if (get_u32(&val
, *argv
, 0))
91 invarg("invalid forward_delay", *argv
);
93 addattr32(n
, 1024, IFLA_BR_FORWARD_DELAY
, val
);
94 } else if (matches(*argv
, "hello_time") == 0) {
96 if (get_u32(&val
, *argv
, 0))
97 invarg("invalid hello_time", *argv
);
99 addattr32(n
, 1024, IFLA_BR_HELLO_TIME
, val
);
100 } else if (matches(*argv
, "max_age") == 0) {
102 if (get_u32(&val
, *argv
, 0))
103 invarg("invalid max_age", *argv
);
105 addattr32(n
, 1024, IFLA_BR_MAX_AGE
, val
);
106 } else if (matches(*argv
, "ageing_time") == 0) {
108 if (get_u32(&val
, *argv
, 0))
109 invarg("invalid ageing_time", *argv
);
111 addattr32(n
, 1024, IFLA_BR_AGEING_TIME
, val
);
112 } else if (matches(*argv
, "stp_state") == 0) {
114 if (get_u32(&val
, *argv
, 0))
115 invarg("invalid stp_state", *argv
);
117 addattr32(n
, 1024, IFLA_BR_STP_STATE
, val
);
118 } else if (matches(*argv
, "priority") == 0) {
122 if (get_u16(&prio
, *argv
, 0))
123 invarg("invalid priority", *argv
);
125 addattr16(n
, 1024, IFLA_BR_PRIORITY
, prio
);
126 } else if (matches(*argv
, "vlan_filtering") == 0) {
130 if (get_u8(&vlan_filter
, *argv
, 0))
131 invarg("invalid vlan_filtering", *argv
);
133 addattr8(n
, 1024, IFLA_BR_VLAN_FILTERING
, vlan_filter
);
134 } else if (matches(*argv
, "vlan_protocol") == 0) {
138 if (ll_proto_a2n(&vlan_proto
, *argv
))
139 invarg("invalid vlan_protocol", *argv
);
141 addattr16(n
, 1024, IFLA_BR_VLAN_PROTOCOL
, vlan_proto
);
142 } else if (matches(*argv
, "group_fwd_mask") == 0) {
146 if (get_u16(&fwd_mask
, *argv
, 0))
147 invarg("invalid group_fwd_mask", *argv
);
149 addattr16(n
, 1024, IFLA_BR_GROUP_FWD_MASK
, fwd_mask
);
150 } else if (matches(*argv
, "group_address") == 0) {
155 len
= ll_addr_a2n(llabuf
, sizeof(llabuf
), *argv
);
158 addattr_l(n
, 1024, IFLA_BR_GROUP_ADDR
, llabuf
, len
);
159 } else if (matches(*argv
, "fdb_flush") == 0) {
160 addattr(n
, 1024, IFLA_BR_FDB_FLUSH
);
161 } else if (matches(*argv
, "vlan_default_pvid") == 0) {
165 if (get_u16(&default_pvid
, *argv
, 0))
166 invarg("invalid vlan_default_pvid", *argv
);
168 addattr16(n
, 1024, IFLA_BR_VLAN_DEFAULT_PVID
,
170 } else if (matches(*argv
, "vlan_stats_enabled") == 0) {
171 __u8 vlan_stats_enabled
;
174 if (get_u8(&vlan_stats_enabled
, *argv
, 0))
175 invarg("invalid vlan_stats_enabled", *argv
);
176 addattr8(n
, 1024, IFLA_BR_VLAN_STATS_ENABLED
,
178 } else if (matches(*argv
, "mcast_router") == 0) {
182 if (get_u8(&mcast_router
, *argv
, 0))
183 invarg("invalid mcast_router", *argv
);
185 addattr8(n
, 1024, IFLA_BR_MCAST_ROUTER
, mcast_router
);
186 } else if (matches(*argv
, "mcast_snooping") == 0) {
190 if (get_u8(&mcast_snoop
, *argv
, 0))
191 invarg("invalid mcast_snooping", *argv
);
193 addattr8(n
, 1024, IFLA_BR_MCAST_SNOOPING
, mcast_snoop
);
194 } else if (matches(*argv
, "mcast_query_use_ifaddr") == 0) {
198 if (get_u8(&mcast_qui
, *argv
, 0))
199 invarg("invalid mcast_query_use_ifaddr",
202 addattr8(n
, 1024, IFLA_BR_MCAST_QUERY_USE_IFADDR
,
204 } else if (matches(*argv
, "mcast_querier") == 0) {
208 if (get_u8(&mcast_querier
, *argv
, 0))
209 invarg("invalid mcast_querier", *argv
);
211 addattr8(n
, 1024, IFLA_BR_MCAST_QUERIER
, mcast_querier
);
212 } else if (matches(*argv
, "mcast_hash_elasticity") == 0) {
216 if (get_u32(&mcast_hash_el
, *argv
, 0))
217 invarg("invalid mcast_hash_elasticity",
220 addattr32(n
, 1024, IFLA_BR_MCAST_HASH_ELASTICITY
,
222 } else if (matches(*argv
, "mcast_hash_max") == 0) {
223 __u32 mcast_hash_max
;
226 if (get_u32(&mcast_hash_max
, *argv
, 0))
227 invarg("invalid mcast_hash_max", *argv
);
229 addattr32(n
, 1024, IFLA_BR_MCAST_HASH_MAX
,
231 } else if (matches(*argv
, "mcast_last_member_count") == 0) {
235 if (get_u32(&mcast_lmc
, *argv
, 0))
236 invarg("invalid mcast_last_member_count",
239 addattr32(n
, 1024, IFLA_BR_MCAST_LAST_MEMBER_CNT
,
241 } else if (matches(*argv
, "mcast_startup_query_count") == 0) {
245 if (get_u32(&mcast_sqc
, *argv
, 0))
246 invarg("invalid mcast_startup_query_count",
249 addattr32(n
, 1024, IFLA_BR_MCAST_STARTUP_QUERY_CNT
,
251 } else if (matches(*argv
, "mcast_last_member_interval") == 0) {
252 __u64 mcast_last_member_intvl
;
255 if (get_u64(&mcast_last_member_intvl
, *argv
, 0))
256 invarg("invalid mcast_last_member_interval",
259 addattr64(n
, 1024, IFLA_BR_MCAST_LAST_MEMBER_INTVL
,
260 mcast_last_member_intvl
);
261 } else if (matches(*argv
, "mcast_membership_interval") == 0) {
262 __u64 mcast_membership_intvl
;
265 if (get_u64(&mcast_membership_intvl
, *argv
, 0))
266 invarg("invalid mcast_membership_interval",
269 addattr64(n
, 1024, IFLA_BR_MCAST_MEMBERSHIP_INTVL
,
270 mcast_membership_intvl
);
271 } else if (matches(*argv
, "mcast_querier_interval") == 0) {
272 __u64 mcast_querier_intvl
;
275 if (get_u64(&mcast_querier_intvl
, *argv
, 0))
276 invarg("invalid mcast_querier_interval",
279 addattr64(n
, 1024, IFLA_BR_MCAST_QUERIER_INTVL
,
280 mcast_querier_intvl
);
281 } else if (matches(*argv
, "mcast_query_interval") == 0) {
282 __u64 mcast_query_intvl
;
285 if (get_u64(&mcast_query_intvl
, *argv
, 0))
286 invarg("invalid mcast_query_interval",
289 addattr64(n
, 1024, IFLA_BR_MCAST_QUERY_INTVL
,
291 } else if (!matches(*argv
, "mcast_query_response_interval")) {
292 __u64 mcast_query_resp_intvl
;
295 if (get_u64(&mcast_query_resp_intvl
, *argv
, 0))
296 invarg("invalid mcast_query_response_interval",
299 addattr64(n
, 1024, IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
,
300 mcast_query_resp_intvl
);
301 } else if (!matches(*argv
, "mcast_startup_query_interval")) {
302 __u64 mcast_startup_query_intvl
;
305 if (get_u64(&mcast_startup_query_intvl
, *argv
, 0))
306 invarg("invalid mcast_startup_query_interval",
309 addattr64(n
, 1024, IFLA_BR_MCAST_STARTUP_QUERY_INTVL
,
310 mcast_startup_query_intvl
);
311 } else if (matches(*argv
, "mcast_stats_enabled") == 0) {
312 __u8 mcast_stats_enabled
;
315 if (get_u8(&mcast_stats_enabled
, *argv
, 0))
316 invarg("invalid mcast_stats_enabled", *argv
);
317 addattr8(n
, 1024, IFLA_BR_MCAST_STATS_ENABLED
,
318 mcast_stats_enabled
);
319 } else if (matches(*argv
, "mcast_igmp_version") == 0) {
323 if (get_u8(&igmp_version
, *argv
, 0))
324 invarg("invalid mcast_igmp_version", *argv
);
325 addattr8(n
, 1024, IFLA_BR_MCAST_IGMP_VERSION
,
327 } else if (matches(*argv
, "mcast_mld_version") == 0) {
331 if (get_u8(&mld_version
, *argv
, 0))
332 invarg("invalid mcast_mld_version", *argv
);
333 addattr8(n
, 1024, IFLA_BR_MCAST_MLD_VERSION
,
335 } else if (matches(*argv
, "nf_call_iptables") == 0) {
339 if (get_u8(&nf_call_ipt
, *argv
, 0))
340 invarg("invalid nf_call_iptables", *argv
);
342 addattr8(n
, 1024, IFLA_BR_NF_CALL_IPTABLES
,
344 } else if (matches(*argv
, "nf_call_ip6tables") == 0) {
348 if (get_u8(&nf_call_ip6t
, *argv
, 0))
349 invarg("invalid nf_call_ip6tables", *argv
);
351 addattr8(n
, 1024, IFLA_BR_NF_CALL_IP6TABLES
,
353 } else if (matches(*argv
, "nf_call_arptables") == 0) {
357 if (get_u8(&nf_call_arpt
, *argv
, 0))
358 invarg("invalid nf_call_arptables", *argv
);
360 addattr8(n
, 1024, IFLA_BR_NF_CALL_ARPTABLES
,
362 } else if (matches(*argv
, "help") == 0) {
366 fprintf(stderr
, "bridge: unknown command \"%s\"?\n", *argv
);
376 static void bridge_print_opt(struct link_util
*lu
, FILE *f
, struct rtattr
*tb
[])
381 if (tb
[IFLA_BR_FORWARD_DELAY
])
382 fprintf(f
, "forward_delay %u ",
383 rta_getattr_u32(tb
[IFLA_BR_FORWARD_DELAY
]));
385 if (tb
[IFLA_BR_HELLO_TIME
])
386 fprintf(f
, "hello_time %u ",
387 rta_getattr_u32(tb
[IFLA_BR_HELLO_TIME
]));
389 if (tb
[IFLA_BR_MAX_AGE
])
390 fprintf(f
, "max_age %u ",
391 rta_getattr_u32(tb
[IFLA_BR_MAX_AGE
]));
393 if (tb
[IFLA_BR_AGEING_TIME
])
394 fprintf(f
, "ageing_time %u ",
395 rta_getattr_u32(tb
[IFLA_BR_AGEING_TIME
]));
397 if (tb
[IFLA_BR_STP_STATE
])
398 fprintf(f
, "stp_state %u ",
399 rta_getattr_u32(tb
[IFLA_BR_STP_STATE
]));
401 if (tb
[IFLA_BR_PRIORITY
])
402 fprintf(f
, "priority %u ",
403 rta_getattr_u16(tb
[IFLA_BR_PRIORITY
]));
405 if (tb
[IFLA_BR_VLAN_FILTERING
])
406 fprintf(f
, "vlan_filtering %u ",
407 rta_getattr_u8(tb
[IFLA_BR_VLAN_FILTERING
]));
409 if (tb
[IFLA_BR_VLAN_PROTOCOL
]) {
412 fprintf(f
, "vlan_protocol %s ",
413 ll_proto_n2a(rta_getattr_u16(tb
[IFLA_BR_VLAN_PROTOCOL
]),
417 if (tb
[IFLA_BR_BRIDGE_ID
]) {
420 br_dump_bridge_id(RTA_DATA(tb
[IFLA_BR_BRIDGE_ID
]), bridge_id
,
422 fprintf(f
, "bridge_id %s ", bridge_id
);
425 if (tb
[IFLA_BR_ROOT_ID
]) {
428 br_dump_bridge_id(RTA_DATA(tb
[IFLA_BR_BRIDGE_ID
]), root_id
,
430 fprintf(f
, "designated_root %s ", root_id
);
433 if (tb
[IFLA_BR_ROOT_PORT
])
434 fprintf(f
, "root_port %u ",
435 rta_getattr_u16(tb
[IFLA_BR_ROOT_PORT
]));
437 if (tb
[IFLA_BR_ROOT_PATH_COST
])
438 fprintf(f
, "root_path_cost %u ",
439 rta_getattr_u32(tb
[IFLA_BR_ROOT_PATH_COST
]));
441 if (tb
[IFLA_BR_TOPOLOGY_CHANGE
])
442 fprintf(f
, "topology_change %u ",
443 rta_getattr_u8(tb
[IFLA_BR_TOPOLOGY_CHANGE
]));
445 if (tb
[IFLA_BR_TOPOLOGY_CHANGE_DETECTED
])
446 fprintf(f
, "topology_change_detected %u ",
447 rta_getattr_u8(tb
[IFLA_BR_TOPOLOGY_CHANGE_DETECTED
]));
449 if (tb
[IFLA_BR_HELLO_TIMER
]) {
452 __jiffies_to_tv(&tv
, rta_getattr_u64(tb
[IFLA_BR_HELLO_TIMER
]));
453 fprintf(f
, "hello_timer %4i.%.2i ", (int)tv
.tv_sec
,
454 (int)tv
.tv_usec
/10000);
457 if (tb
[IFLA_BR_TCN_TIMER
]) {
460 __jiffies_to_tv(&tv
, rta_getattr_u64(tb
[IFLA_BR_TCN_TIMER
]));
461 fprintf(f
, "tcn_timer %4i.%.2i ", (int)tv
.tv_sec
,
462 (int)tv
.tv_usec
/10000);
465 if (tb
[IFLA_BR_TOPOLOGY_CHANGE_TIMER
]) {
466 unsigned long jiffies
;
469 jiffies
= rta_getattr_u64(tb
[IFLA_BR_TOPOLOGY_CHANGE_TIMER
]);
470 __jiffies_to_tv(&tv
, jiffies
);
471 fprintf(f
, "topology_change_timer %4i.%.2i ", (int)tv
.tv_sec
,
472 (int)tv
.tv_usec
/10000);
475 if (tb
[IFLA_BR_GC_TIMER
]) {
478 __jiffies_to_tv(&tv
, rta_getattr_u64(tb
[IFLA_BR_GC_TIMER
]));
479 fprintf(f
, "gc_timer %4i.%.2i ", (int)tv
.tv_sec
,
480 (int)tv
.tv_usec
/10000);
483 if (tb
[IFLA_BR_VLAN_DEFAULT_PVID
])
484 fprintf(f
, "vlan_default_pvid %u ",
485 rta_getattr_u16(tb
[IFLA_BR_VLAN_DEFAULT_PVID
]));
487 if (tb
[IFLA_BR_VLAN_STATS_ENABLED
])
488 fprintf(f
, "vlan_stats_enabled %u ",
489 rta_getattr_u8(tb
[IFLA_BR_VLAN_STATS_ENABLED
]));
491 if (tb
[IFLA_BR_GROUP_FWD_MASK
])
492 fprintf(f
, "group_fwd_mask %#x ",
493 rta_getattr_u16(tb
[IFLA_BR_GROUP_FWD_MASK
]));
495 if (tb
[IFLA_BR_GROUP_ADDR
]) {
498 fprintf(f
, "group_address %s ",
499 ll_addr_n2a(RTA_DATA(tb
[IFLA_BR_GROUP_ADDR
]),
500 RTA_PAYLOAD(tb
[IFLA_BR_GROUP_ADDR
]),
501 1 /*ARPHDR_ETHER*/, mac
, sizeof(mac
)));
504 if (tb
[IFLA_BR_MCAST_SNOOPING
])
505 fprintf(f
, "mcast_snooping %u ",
506 rta_getattr_u8(tb
[IFLA_BR_MCAST_SNOOPING
]));
508 if (tb
[IFLA_BR_MCAST_ROUTER
])
509 fprintf(f
, "mcast_router %u ",
510 rta_getattr_u8(tb
[IFLA_BR_MCAST_ROUTER
]));
512 if (tb
[IFLA_BR_MCAST_QUERY_USE_IFADDR
])
513 fprintf(f
, "mcast_query_use_ifaddr %u ",
514 rta_getattr_u8(tb
[IFLA_BR_MCAST_QUERY_USE_IFADDR
]));
516 if (tb
[IFLA_BR_MCAST_QUERIER
])
517 fprintf(f
, "mcast_querier %u ",
518 rta_getattr_u8(tb
[IFLA_BR_MCAST_QUERIER
]));
520 if (tb
[IFLA_BR_MCAST_HASH_ELASTICITY
])
521 fprintf(f
, "mcast_hash_elasticity %u ",
522 rta_getattr_u32(tb
[IFLA_BR_MCAST_HASH_ELASTICITY
]));
524 if (tb
[IFLA_BR_MCAST_HASH_MAX
])
525 fprintf(f
, "mcast_hash_max %u ",
526 rta_getattr_u32(tb
[IFLA_BR_MCAST_HASH_MAX
]));
528 if (tb
[IFLA_BR_MCAST_LAST_MEMBER_CNT
])
529 fprintf(f
, "mcast_last_member_count %u ",
530 rta_getattr_u32(tb
[IFLA_BR_MCAST_LAST_MEMBER_CNT
]));
532 if (tb
[IFLA_BR_MCAST_STARTUP_QUERY_CNT
])
533 fprintf(f
, "mcast_startup_query_count %u ",
534 rta_getattr_u32(tb
[IFLA_BR_MCAST_STARTUP_QUERY_CNT
]));
536 if (tb
[IFLA_BR_MCAST_LAST_MEMBER_INTVL
])
537 fprintf(f
, "mcast_last_member_interval %llu ",
538 rta_getattr_u64(tb
[IFLA_BR_MCAST_LAST_MEMBER_INTVL
]));
540 if (tb
[IFLA_BR_MCAST_MEMBERSHIP_INTVL
])
541 fprintf(f
, "mcast_membership_interval %llu ",
542 rta_getattr_u64(tb
[IFLA_BR_MCAST_MEMBERSHIP_INTVL
]));
544 if (tb
[IFLA_BR_MCAST_QUERIER_INTVL
])
545 fprintf(f
, "mcast_querier_interval %llu ",
546 rta_getattr_u64(tb
[IFLA_BR_MCAST_QUERIER_INTVL
]));
548 if (tb
[IFLA_BR_MCAST_QUERY_INTVL
])
549 fprintf(f
, "mcast_query_interval %llu ",
550 rta_getattr_u64(tb
[IFLA_BR_MCAST_QUERY_INTVL
]));
552 if (tb
[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
])
553 fprintf(f
, "mcast_query_response_interval %llu ",
554 rta_getattr_u64(tb
[IFLA_BR_MCAST_QUERY_RESPONSE_INTVL
]));
556 if (tb
[IFLA_BR_MCAST_STARTUP_QUERY_INTVL
])
557 fprintf(f
, "mcast_startup_query_interval %llu ",
558 rta_getattr_u64(tb
[IFLA_BR_MCAST_STARTUP_QUERY_INTVL
]));
560 if (tb
[IFLA_BR_MCAST_STATS_ENABLED
])
561 fprintf(f
, "mcast_stats_enabled %u ",
562 rta_getattr_u8(tb
[IFLA_BR_MCAST_STATS_ENABLED
]));
564 if (tb
[IFLA_BR_MCAST_IGMP_VERSION
])
565 fprintf(f
, "mcast_igmp_version %u ",
566 rta_getattr_u8(tb
[IFLA_BR_MCAST_IGMP_VERSION
]));
568 if (tb
[IFLA_BR_MCAST_MLD_VERSION
])
569 fprintf(f
, "mcast_mld_version %u ",
570 rta_getattr_u8(tb
[IFLA_BR_MCAST_MLD_VERSION
]));
572 if (tb
[IFLA_BR_NF_CALL_IPTABLES
])
573 fprintf(f
, "nf_call_iptables %u ",
574 rta_getattr_u8(tb
[IFLA_BR_NF_CALL_IPTABLES
]));
576 if (tb
[IFLA_BR_NF_CALL_IP6TABLES
])
577 fprintf(f
, "nf_call_ip6tables %u ",
578 rta_getattr_u8(tb
[IFLA_BR_NF_CALL_IP6TABLES
]));
580 if (tb
[IFLA_BR_NF_CALL_ARPTABLES
])
581 fprintf(f
, "nf_call_arptables %u ",
582 rta_getattr_u8(tb
[IFLA_BR_NF_CALL_ARPTABLES
]));
585 static void bridge_print_help(struct link_util
*lu
, int argc
, char **argv
,
591 static void bridge_print_xstats_help(struct link_util
*lu
, FILE *f
)
593 fprintf(f
, "Usage: ... %s [ igmp ] [ dev DEVICE ]\n", lu
->id
);
596 static void bridge_print_stats_attr(FILE *f
, struct rtattr
*attr
, int ifindex
)
598 struct rtattr
*brtb
[LINK_XSTATS_TYPE_MAX
+1];
599 struct br_mcast_stats
*mstats
;
600 struct rtattr
*i
, *list
;
601 const char *ifname
= "";
604 parse_rtattr(brtb
, LINK_XSTATS_TYPE_MAX
, RTA_DATA(attr
),
606 if (!brtb
[LINK_XSTATS_TYPE_BRIDGE
])
609 list
= brtb
[LINK_XSTATS_TYPE_BRIDGE
];
610 rem
= RTA_PAYLOAD(list
);
611 for (i
= RTA_DATA(list
); RTA_OK(i
, rem
); i
= RTA_NEXT(i
, rem
)) {
612 if (xstats_print_attr
&& i
->rta_type
!= xstats_print_attr
)
614 switch (i
->rta_type
) {
615 case BRIDGE_XSTATS_MCAST
:
616 mstats
= RTA_DATA(i
);
617 ifname
= ll_index_to_name(ifindex
);
618 fprintf(f
, "%-16s\n", ifname
);
619 fprintf(f
, "%-16s IGMP queries:\n", "");
620 fprintf(f
, "%-16s RX: v1 %llu v2 %llu v3 %llu\n",
622 mstats
->igmp_v1queries
[BR_MCAST_DIR_RX
],
623 mstats
->igmp_v2queries
[BR_MCAST_DIR_RX
],
624 mstats
->igmp_v3queries
[BR_MCAST_DIR_RX
]);
625 fprintf(f
, "%-16s TX: v1 %llu v2 %llu v3 %llu\n",
627 mstats
->igmp_v1queries
[BR_MCAST_DIR_TX
],
628 mstats
->igmp_v2queries
[BR_MCAST_DIR_TX
],
629 mstats
->igmp_v3queries
[BR_MCAST_DIR_TX
]);
631 fprintf(f
, "%-16s IGMP reports:\n", "");
632 fprintf(f
, "%-16s RX: v1 %llu v2 %llu v3 %llu\n",
634 mstats
->igmp_v1reports
[BR_MCAST_DIR_RX
],
635 mstats
->igmp_v2reports
[BR_MCAST_DIR_RX
],
636 mstats
->igmp_v3reports
[BR_MCAST_DIR_RX
]);
637 fprintf(f
, "%-16s TX: v1 %llu v2 %llu v3 %llu\n",
639 mstats
->igmp_v1reports
[BR_MCAST_DIR_TX
],
640 mstats
->igmp_v2reports
[BR_MCAST_DIR_TX
],
641 mstats
->igmp_v3reports
[BR_MCAST_DIR_TX
]);
643 fprintf(f
, "%-16s IGMP leaves: RX: %llu TX: %llu\n",
645 mstats
->igmp_leaves
[BR_MCAST_DIR_RX
],
646 mstats
->igmp_leaves
[BR_MCAST_DIR_TX
]);
648 fprintf(f
, "%-16s IGMP parse errors: %llu\n",
649 "", mstats
->igmp_parse_errors
);
651 fprintf(f
, "%-16s MLD queries:\n", "");
652 fprintf(f
, "%-16s RX: v1 %llu v2 %llu\n",
654 mstats
->mld_v1queries
[BR_MCAST_DIR_RX
],
655 mstats
->mld_v2queries
[BR_MCAST_DIR_RX
]);
656 fprintf(f
, "%-16s TX: v1 %llu v2 %llu\n",
658 mstats
->mld_v1queries
[BR_MCAST_DIR_TX
],
659 mstats
->mld_v2queries
[BR_MCAST_DIR_TX
]);
661 fprintf(f
, "%-16s MLD reports:\n", "");
662 fprintf(f
, "%-16s RX: v1 %llu v2 %llu\n",
664 mstats
->mld_v1reports
[BR_MCAST_DIR_RX
],
665 mstats
->mld_v2reports
[BR_MCAST_DIR_RX
]);
666 fprintf(f
, "%-16s TX: v1 %llu v2 %llu\n",
668 mstats
->mld_v1reports
[BR_MCAST_DIR_TX
],
669 mstats
->mld_v2reports
[BR_MCAST_DIR_TX
]);
671 fprintf(f
, "%-16s MLD leaves: RX: %llu TX: %llu\n",
673 mstats
->mld_leaves
[BR_MCAST_DIR_RX
],
674 mstats
->mld_leaves
[BR_MCAST_DIR_TX
]);
676 fprintf(f
, "%-16s MLD parse errors: %llu\n",
677 "", mstats
->mld_parse_errors
);
683 int bridge_print_xstats(const struct sockaddr_nl
*who
,
684 struct nlmsghdr
*n
, void *arg
)
686 struct if_stats_msg
*ifsm
= NLMSG_DATA(n
);
687 struct rtattr
*tb
[IFLA_STATS_MAX
+1];
688 int len
= n
->nlmsg_len
;
691 len
-= NLMSG_LENGTH(sizeof(*ifsm
));
693 fprintf(stderr
, "BUG: wrong nlmsg len %d\n", len
);
696 if (filter_index
&& filter_index
!= ifsm
->ifindex
)
699 parse_rtattr(tb
, IFLA_STATS_MAX
, IFLA_STATS_RTA(ifsm
), len
);
700 if (tb
[IFLA_STATS_LINK_XSTATS
])
701 bridge_print_stats_attr(fp
, tb
[IFLA_STATS_LINK_XSTATS
],
704 if (tb
[IFLA_STATS_LINK_XSTATS_SLAVE
])
705 bridge_print_stats_attr(fp
, tb
[IFLA_STATS_LINK_XSTATS_SLAVE
],
711 int bridge_parse_xstats(struct link_util
*lu
, int argc
, char **argv
)
714 if (strcmp(*argv
, "igmp") == 0 || strcmp(*argv
, "mcast") == 0) {
715 xstats_print_attr
= BRIDGE_XSTATS_MCAST
;
716 } else if (strcmp(*argv
, "dev") == 0) {
718 filter_index
= if_nametoindex(*argv
);
719 if (filter_index
== 0) {
720 fprintf(stderr
, "Cannot find device \"%s\"\n",
724 } else if (strcmp(*argv
, "help") == 0) {
725 bridge_print_xstats_help(lu
, stdout
);
728 invarg("unknown attribute", *argv
);
736 struct link_util bridge_link_util
= {
738 .maxattr
= IFLA_BR_MAX
,
739 .parse_opt
= bridge_parse_opt
,
740 .print_opt
= bridge_print_opt
,
741 .print_help
= bridge_print_help
,
742 .parse_ifla_xstats
= bridge_parse_xstats
,
743 .print_ifla_xstats
= bridge_print_xstats
,