]> git.ipfire.org Git - people/ms/mstpd.git/commitdiff
Translate new ageing time to the kernel bridge code
authorVitalii Demianets <vitas@nppfactor.kiev.ua>
Tue, 27 Sep 2011 15:26:11 +0000 (15:26 +0000)
committerVitalii Demianets <vitas@nppfactor.kiev.ua>
Tue, 27 Sep 2011 15:26:11 +0000 (15:26 +0000)
git-svn-id: http://svn.code.sf.net/p/mstpd/code/trunk@10 fbe50366-0c72-4402-a84b-5d246361dba7

bridge_track.c
driver.h
driver_deps.c
mstp.c
mstp.h

index 048a62ca5b22e97e608907b927d4f31c3ab4bbff..9b5e5b82f64a9e1acc92be8de39200b2f3f8dd9a 100644 (file)
@@ -27,6 +27,7 @@
 #include <string.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <linux/param.h>
 #include <linux/if_bridge.h>
 #include <asm/byteorder.h>
 
@@ -469,6 +470,20 @@ static int br_flush_port(char *ifname)
     return 0;
 }
 
+static int br_set_ageing_time(char *brname, unsigned int ageing_time)
+{
+    char fname[128], str_time[32];
+    snprintf(fname, sizeof(fname), "/sys/class/net/%s/bridge/ageing_time",
+             brname);
+    int fd = open(fname, O_WRONLY);
+    TSTM(0 <= fd, -1, "Couldn't open file %s for write: %m", fname);
+    int len = sprintf(str_time, "%u", ageing_time * HZ);
+    int write_result = write(fd, str_time, len);
+    close(fd);
+    TST(len == write_result, -1);
+    return 0;
+}
+
 /* External actions for MSTP protocol */
 
 void MSTP_OUT_set_state(per_tree_port_t *ptp, int new_state)
@@ -537,10 +552,19 @@ void MSTP_OUT_flush_all_fids(per_tree_port_t * ptp)
     driver_flush_all_fids(ptp);
 }
 
-/* ageingTime < 0 => command driver to use its internal setting */
-void MSTP_OUT_set_ageing_time(bridge_t * br, int ageingTime)
+/* 802.1Q-2005 wants per-port ageing time.
+ * We do not support it, so set ageing time for the whole bridge.
+ */
+void MSTP_OUT_set_ageing_time(bridge_t * br, unsigned int ageingTime)
 {
-    /* TODO: do set new ageing time */
+    unsigned int actual_ageing_time;
+
+    actual_ageing_time = driver_set_ageing_time(br, ageingTime);
+    INFO_BRNAME(br, "Setting new ageing time to %u", actual_ageing_time);
+
+    /* Translate new ageing time to the kernel bridge code */
+    if(0 > br_set_ageing_time(br->sysdeps.name, actual_ageing_time))
+        ERROR_BRNAME(br, "Couldn't set new ageing time in kernel bridge");
 }
 
 void MSTP_OUT_tx_bpdu(port_t * ifc, bpdu_t * bpdu, int size)
index 9fae78f91e5f249d814bcc5e888ac174e6b7e9e4..53ca58c45ddab022c65cda190a47705adcb0c78e 100644 (file)
--- a/driver.h
+++ b/driver.h
@@ -14,5 +14,6 @@
 
 int driver_set_new_state(per_tree_port_t *ptp, int new_state);
 void driver_flush_all_fids(per_tree_port_t *ptp);
+unsigned int driver_set_ageing_time(bridge_t *br, unsigned int ageingTime);
 
 #endif /* _MSTP_DRIVER_H */
index 102f7999c35f8e583cda50e1a554ca4b41426ff6..edc6e98912379c1c868aefe0a043800298adf054 100644 (file)
@@ -35,3 +35,14 @@ void driver_flush_all_fids(per_tree_port_t *ptp)
      */
     MSTP_IN_all_fids_flushed(ptp);
 }
+
+/*
+ * Set new ageing time (in seconds) for the bridge.
+ * Return new actual ageing time from driver (the ageing timer granularity
+ *  in the hardware can be more than 1 sec)
+ */
+unsigned int driver_set_ageing_time(bridge_t *br, unsigned int ageingTime)
+{
+    /* TODO: do set new ageing time */
+    return ageingTime;
+}
diff --git a/mstp.c b/mstp.c
index 6ffd40f77d719c9f2bdda9ed8eb253b03d0a7aa2..bbc6b1056cb684b03c2fb806393f99e52701396a 100644 (file)
--- a/mstp.c
+++ b/mstp.c
@@ -196,6 +196,7 @@ bool MSTP_IN_bridge_create(bridge_t *br, __u8 *macaddr)
     assign(br->Max_Age, (__u8)20);       /* 17.14 of 802.1D */
     assign(br->Transmit_Hold_Count, 6u); /* 17.14 of 802.1D */
     assign(br->Migrate_Time, 3u); /* 17.14 of 802.1D */
+    assign(br->Ageing_Time, 300u);/* 8.8.3 Table 8-3 */
     assign(br->rapidAgeingWhile, 0u);
 
     br->uptime = 0;
@@ -438,7 +439,7 @@ void MSTP_IN_one_second(bridge_t *br)
     if(br->rapidAgeingWhile)
     {
         if((--(br->rapidAgeingWhile)) == 0)
-            MSTP_OUT_set_ageing_time(br, -1);
+            MSTP_OUT_set_ageing_time(br, br->Ageing_Time);
     }
 
     br_state_machines_run(br);
diff --git a/mstp.h b/mstp.h
index 0a5d36bd8ac9ca37645994fc8b6121e195193b96..54d3f2cc37f7a4514c21495887afcc3267afb736 100644 (file)
--- a/mstp.h
+++ b/mstp.h
@@ -392,6 +392,7 @@ typedef struct
     __u8 Max_Age;             /* 13.22.i */
     unsigned int Transmit_Hold_Count; /* 13.22.g */
     unsigned int Migrate_Time;        /* 13.22.h */
+    unsigned int Ageing_Time;  /* 8.8.3 */
     unsigned int rapidAgeingWhile;
 
     __u16 vid2fid[MAX_VID + 1];
@@ -562,7 +563,7 @@ void MSTP_IN_set_mst_config_id(bridge_t *br, __u16 revision, __u8 *name);
 /* External actions (outputs) */
 void MSTP_OUT_set_state(per_tree_port_t *ptp, int new_state);
 void MSTP_OUT_flush_all_fids(per_tree_port_t *ptp);
-void MSTP_OUT_set_ageing_time(bridge_t *br, int ageingTime);
+void MSTP_OUT_set_ageing_time(bridge_t *br, unsigned int ageingTime);
 void MSTP_OUT_tx_bpdu(port_t *prt, bpdu_t *bpdu, int size);
 
 /* Structures for communicating with user */