net: bridge: add STP xstats
Subsystems (3)
PATCH v3 1/1 net: bridge: add STP xstats
This adds rx_bpdu, tx_bpdu, rx_tcn, tx_tcn, transition_blk, transition_fwd xstats counters to the bridge ports copied over via netlink, providing useful information for STP.
--- include/uapi/linux/if_bridge.h | 10 ++++++++++ net/bridge/br_netlink.c | 13 +++++++++++++ net/bridge/br_private.h | 2 ++ net/bridge/br_stp.c | 15 +++++++++++++++ net/bridge/br_stp_bpdu.c | 4 ++++ 5 files changed, 44 insertions(+)
include/uapi/linux/if_bridge.h +10 -0
@@ -156,6 +156,15 @@ struct bridge_vlan_xstats {__u32 pad2; }; +struct bridge_stp_xstats { +__u64 transition_blk; +__u64 transition_fwd; +__u64 rx_bpdu; +__u64 tx_bpdu; +__u64 rx_tcn; +__u64 tx_tcn; +}; +/* Bridge multicast database attributes * [MDBA_MDB] = { * [MDBA_MDB_ENTRY] = {
@@ -262,6 +271,7 @@ enum {BRIDGE_XSTATS_VLAN ,BRIDGE_XSTATS_MCAST ,BRIDGE_XSTATS_PAD , +BRIDGE_XSTATS_STP , __BRIDGE_XSTATS_MAX };#define BRIDGE_XSTATS_MAX (__BRIDGE_XSTATS_MAX - 1)
net/bridge/br_netlink.c +13 -0
@@ -1607,6 +1607,19 @@ static int br_fill_linkxstats(struct sk_buff *skb,br_multicast_get_stats (br, p,nla_data (nla)); }#endif + +if (p) { + nla =nla_reserve_64bit (skb,BRIDGE_XSTATS_STP , +sizeof (p->stp_xstats), +BRIDGE_XSTATS_PAD ); +if (!nla) + goto nla_put_failure; + +spin_lock_bh (&br->lock); +memcpy (nla_data (nla), &p->stp_xstats,sizeof (p->stp_xstats)); +spin_unlock_bh (&br->lock); + } +nla_nest_end (skb, nest); *prividx =0 ;
net/bridge/br_private.h +2 -0
@@ -283,6 +283,8 @@ struct net_bridge_port {#endif u16 group_fwd_mask;u16 backup_redirected_cnt; + +struct bridge_stp_xstats stp_xstats; };#define kobj_to_brport (obj) container_of(obj, struct net_bridge_port, kobj)
net/bridge/br_stp.c +15 -0
@@ -45,6 +45,17 @@ void br_set_state(struct net_bridge_port *p, unsigned int state)br_info (p->br,"port %u(%s) entered %s state\n" , (unsigned int ) p->port_no, p->dev->name, br_port_state_names[p->state]); + +if (p->br->stp_enabled ==BR_KERNEL_STP ) { +switch (p->state) { +case BR_STATE_BLOCKING : + p->stp_xstats.transition_blk++; +break ; +case BR_STATE_FORWARDING : + p->stp_xstats.transition_fwd++; +break ; + } + } }/* called under bridge lock */
@@ -484,6 +495,8 @@ void br_received_config_bpdu(struct net_bridge_port *p,struct net_bridge *br;int was_root; + p->stp_xstats.rx_bpdu++; + br = p->br; was_root =br_is_root_bridge (br);
@@ -517,6 +530,8 @@ void br_received_config_bpdu(struct net_bridge_port *p,/* called under bridge lock */ void br_received_tcn_bpdu (struct net_bridge_port *p) { + p->stp_xstats.rx_tcn++; +if (br_is_designated_port (p)) {br_info (p->br,"port %u(%s) received tcn bpdu\n" , (unsigned int ) p->port_no, p->dev->name);
net/bridge/br_stp_bpdu.c +4 -0
@@ -118,6 +118,8 @@ void br_send_config_bpdu(struct net_bridge_port *p, struct br_config_bpdu *bpdu)br_set_ticks (buf+33 , bpdu->forward_delay);br_send_bpdu (p, buf,35 ); + + p->stp_xstats.tx_bpdu++; }/* called under bridge lock */
@@ -133,6 +135,8 @@ void br_send_tcn_bpdu(struct net_bridge_port *p) buf[2 ] =0 ; buf[3 ] =BPDU_TYPE_TCN ;br_send_bpdu (p, buf,4 ); + + p->stp_xstats.tx_tcn++; }/*
Signature · 1 line
2.24.0
PATCH v4 1/1 iplink: add support for STP xstats
Add support for the BRIDGE_XSTATS_STP xstats, as follow:
# ip link xstats type bridge_slave dev lan4 stp
lan4
STP BPDU: RX: 0 TX: 61
STP TCN: RX: 0 TX: 0
STP Transitions: Blocked: 2 Forwarding: 1Or below as JSON:
# ip -j -p link xstats type bridge_slave dev lan0 stp
[ {
"ifname": "lan0",
"stp": {
"rx_bpdu": 0,
"tx_bpdu": 500,
"rx_tcn": 0,
"tx_tcn": 0,
"transition_blk": 0,
"transition_fwd": 0
}
} ]--- include/uapi/linux/if_bridge.h | 10 ++++++++++ ip/iplink_bridge.c | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)
include/uapi/linux/if_bridge.h +10 -0
@@ -156,6 +156,15 @@ struct bridge_vlan_xstats {__u32 pad2; }; +struct bridge_stp_xstats { +__u64 transition_blk; +__u64 transition_fwd; +__u64 rx_bpdu; +__u64 tx_bpdu; +__u64 rx_tcn; +__u64 tx_tcn; +}; +/* Bridge multicast database attributes * [MDBA_MDB] = { * [MDBA_MDB_ENTRY] = {
@@ -262,6 +271,7 @@ enum {BRIDGE_XSTATS_VLAN ,BRIDGE_XSTATS_MCAST ,BRIDGE_XSTATS_PAD , +BRIDGE_XSTATS_STP , __BRIDGE_XSTATS_MAX };#define BRIDGE_XSTATS_MAX (__BRIDGE_XSTATS_MAX - 1)
ip/iplink_bridge.c +26 -0
@@ -688,6 +688,7 @@ static void bridge_print_xstats_help(struct link_util *lu, FILE *f)static void bridge_print_stats_attr (struct rtattr *attr,int ifindex) {struct rtattr *brtb[LINK_XSTATS_TYPE_MAX +1 ]; +struct bridge_stp_xstats *sstats;struct br_mcast_stats *mstats;struct rtattr *i, *list;const char *ifname ="" ;
@@ -807,6 +808,29 @@ static void bridge_print_stats_attr(struct rtattr *attr, int ifindex) mstats->mld_parse_errors);close_json_object ();break ; +case BRIDGE_XSTATS_STP : + sstats =RTA_DATA (i); +open_json_object ("stp" ); +print_string (PRINT_FP ,NULL , +"%-16s STP BPDU: " ,"" ); +print_u64 (PRINT_ANY ,"rx_bpdu" ,"RX: %llu " , + sstats->rx_bpdu); +print_u64 (PRINT_ANY ,"tx_bpdu" ,"TX: %llu\n" , + sstats->tx_bpdu); +print_string (PRINT_FP ,NULL , +"%-16s STP TCN: " ,"" ); +print_u64 (PRINT_ANY ,"rx_tcn" ,"RX: %llu " , + sstats->rx_tcn); +print_u64 (PRINT_ANY ,"tx_tcn" ,"TX: %llu\n" , + sstats->tx_tcn); +print_string (PRINT_FP ,NULL , +"%-16s STP Transitions: " ,"" ); +print_u64 (PRINT_ANY ,"transition_blk" ,"Blocked: %llu " , + sstats->transition_blk); +print_u64 (PRINT_ANY ,"transition_fwd" ,"Forwarding: %llu\n" , + sstats->transition_fwd); +close_json_object (); +break ; } }close_json_object ();
@@ -843,6 +867,8 @@ int bridge_parse_xstats(struct link_util *lu, int argc, char **argv)while (argc >0 ) {if (strcmp (*argv,"igmp" ) ==0 ||strcmp (*argv,"mcast" ) ==0 ) { xstats_print_attr =BRIDGE_XSTATS_MCAST ; + }else if (strcmp (*argv,"stp" ) ==0 ) { + xstats_print_attr =BRIDGE_XSTATS_STP ; }else if (strcmp (*argv,"dev" ) ==0 ) {NEXT_ARG (); filter_index =ll_name_to_index (*argv);
Signature · 1 line
2.24.0
Re: [PATCH iproute2 v4] iplink: add support for STP xstats
Quoted 23 lines · On Wed, 11 Dec 2019 20:07:11 -0500 Vivien Didelot <[email protected]>…
Add support for the
BRIDGE_XSTATS_STPxstats, as follow:# ip link xstats type bridge_slave dev lan4 stp lan4 STP BPDU: RX: 0 TX: 61 STP TCN: RX: 0 TX: 0 STP Transitions: Blocked: 2 Forwarding: 1Or below as JSON:
# ip -j -p link xstats type bridge_slave dev lan0 stp [ { "ifname": "lan0", "stp": { "rx_bpdu": 0, "tx_bpdu": 500, "rx_tcn": 0, "tx_tcn": 0, "transition_blk": 0, "transition_fwd": 0 } } ]
Quoted 1 line
Signed-off-by Vivien Didelot <[email protected]>
This patch depends on new kernel features, should be to iproute2-next
David Ahern
AppliedRe: [PATCH iproute2 v4] iplink: add support for STP xstats
In reply to Vivien DidelotQuoted 23 lines · Vivien Didelot
Add support for the
BRIDGE_XSTATS_STPxstats, as follow:# ip link xstats type bridge_slave dev lan4 stp lan4 STP BPDU: RX: 0 TX: 61 STP TCN: RX: 0 TX: 0 STP Transitions: Blocked: 2 Forwarding: 1Or below as JSON:
# ip -j -p link xstats type bridge_slave dev lan0 stp [ { "ifname": "lan0", "stp": { "rx_bpdu": 0, "tx_bpdu": 500, "rx_tcn": 0, "tx_tcn": 0, "transition_blk": 0, "transition_fwd": 0 } } ]
Quoted 6 lines
Signed-off-by Vivien Didelot <[email protected]>--- include/uapi/linux/if_bridge.h | 10 ++++++++++ ip/iplink_bridge.c | 26 ++++++++++++++++++++++++++ 2 files changed, 36 insertions(+)
applied to iproute2-next. Thanks
Quoted 4 lines · Vivien Didelot
This adds
rx_bpdu,tx_bpdu,rx_tcn,tx_tcn,transition_blk,transition_fwdxstats counters to the bridge ports copied over via netlink, providing useful information for STP.
Quoted 9 lines
Signed-off-by Vivien Didelot <[email protected]>--- include/uapi/linux/if_bridge.h | 10 ++++++++++ net/bridge/br_netlink.c | 13 +++++++++++++ net/bridge/br_private.h | 2 ++ net/bridge/br_stp.c | 15 +++++++++++++++ net/bridge/br_stp_bpdu.c | 4 ++++ 5 files changed, 44 insertions(+)
Looks good to me, thanks!
Jakub Kicinski
AppliedQuoted 5 lines · Vivien Didelot
This adds
rx_bpdu,tx_bpdu,rx_tcn,tx_tcn,transition_blk,transition_fwdxstats counters to the bridge ports copied over via netlink, providing useful information for STP.Signed-off-by Vivien Didelot <[email protected]>
Applied, thank you!