From: Felix Fietkau Date: Fri, 27 Aug 2021 10:19:29 +0000 (+0200) Subject: bridge: check port bpdu filter status and apply it to the config X-Git-Url: http://git.openwrt.org/project/luci.git%5Ed3f0685d63c1291359dc5dd089c82fa1e150e0c6?a=commitdiff_plain;h=c62d85cf7a0db267030e0ac2138e685b5e8f7017;p=project%2Fustp.git bridge: check port bpdu filter status and apply it to the config Signed-off-by: Felix Fietkau --- diff --git a/bridge_track.c b/bridge_track.c index 9b9f02f..151a03c 100644 --- a/bridge_track.c +++ b/bridge_track.c @@ -217,6 +217,7 @@ static void set_if_up(port_t *prt, bool up) int speed = -1; int duplex = -1; bool changed = false; + bool bpdu_filter; if(check_mac_address(prt->sysdeps.name, prt->sysdeps.macaddr)) { @@ -261,6 +262,16 @@ static void set_if_up(port_t *prt, bool up) prt->sysdeps.up = true; changed = true; } + + bpdu_filter = get_bpdu_filter(prt->sysdeps.name); + if (bpdu_filter != prt->bpduFilterPort) { + CIST_PortConfig cfg = { + .bpdu_filter_port = bpdu_filter, + .set_bpdu_filter_port = true + }; + + MSTP_IN_set_cist_port_config(prt, &cfg); + } } if(changed) MSTP_IN_set_port_enable(prt, prt->sysdeps.up, prt->sysdeps.speed, diff --git a/netif_utils.c b/netif_utils.c index 66241b2..a842bf7 100644 --- a/netif_utils.c +++ b/netif_utils.c @@ -134,10 +134,10 @@ bool is_bridge(char *if_name) return (0 == access(path, R_OK)); } -int get_bridge_portno(char *if_name) +static int get_port_file(const char *if_name, const char *file) { char path[32 + IFNAMSIZ]; - sprintf(path, SYSFS_CLASS_NET "/%s/brport/port_no", if_name); + sprintf(path, SYSFS_CLASS_NET "/%s/brport/%s", if_name, file); char buf[128]; int fd; long res = -1; @@ -146,12 +146,12 @@ int get_bridge_portno(char *if_name) TSTM((l = read(fd, buf, sizeof(buf) - 1)) >= 0, -1, "%m"); if(0 == l) { - ERROR("Empty port index file"); + ERROR("Empty %s file", file); goto out; } else if((sizeof(buf) - 1) == l) { - ERROR("port_index file too long"); + ERROR("%s file too long", file); goto out; } buf[l] = 0; @@ -161,10 +161,20 @@ int get_bridge_portno(char *if_name) res = strtoul(buf, &end, 0); if(0 != *end || INT_MAX < res) { - ERROR("Invalid port index %s", buf); + ERROR("Invalid %s %s", file, buf); res = -1; } out: close(fd); return res; } + +int get_bpdu_filter(char *if_name) +{ + return get_port_file(if_name, "bpdu_filter"); +} + +int get_bridge_portno(char *if_name) +{ + return get_port_file(if_name, "port_no"); +} diff --git a/netif_utils.h b/netif_utils.h index 2da8418..e68832a 100644 --- a/netif_utils.h +++ b/netif_utils.h @@ -38,6 +38,7 @@ int ethtool_get_speed_duplex(char *ifname, int *speed, int *duplex); bool is_bridge(char *if_name); +int get_bpdu_filter(char *if_name); int get_bridge_portno(char *if_name); #endif /* NETIF_UTILS_H */