bridge: check port bpdu filter status and apply it to the config
authorFelix Fietkau <nbd@nbd.name>
Fri, 27 Aug 2021 10:19:29 +0000 (12:19 +0200)
committerFelix Fietkau <nbd@nbd.name>
Fri, 27 Aug 2021 10:19:30 +0000 (12:19 +0200)
Signed-off-by: Felix Fietkau <nbd@nbd.name>
bridge_track.c
netif_utils.c
netif_utils.h

index 9b9f02f399ea08bc049c2bf507fd100dd7f9ccee..151a03cba1d01f27d4be4aed61585e71136b3d88 100644 (file)
@@ -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,
index 66241b2c5a229125dc28562dc66e485db0762ec1..a842bf7f337934f87694f0e985b6e7a738cd4a22 100644 (file)
@@ -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");
+}
index 2da8418ec58a9af310854ad78af3cd364730b231..e68832ac41b49c4cf7b3c9f08dc62c7196e86574 100644 (file)
@@ -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 */