From: dv1tas Date: Tue, 27 Sep 2011 15:26:11 +0000 (+0000) Subject: Translate new ageing time to the kernel bridge code X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=18a06fea40eb87e5b5e524d2034af9dd255962bf;p=people%2Fms%2Fmstpd.git Translate new ageing time to the kernel bridge code git-svn-id: svn://svn.code.sf.net/p/mstpd/code/trunk@10 fbe50366-0c72-4402-a84b-5d246361dba7 --- diff --git a/bridge_track.c b/bridge_track.c index 048a62c..9b5e5b8 100644 --- a/bridge_track.c +++ b/bridge_track.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -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) diff --git a/driver.h b/driver.h index 9fae78f..53ca58c 100644 --- 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 */ diff --git a/driver_deps.c b/driver_deps.c index 102f799..edc6e98 100644 --- a/driver_deps.c +++ b/driver_deps.c @@ -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 6ffd40f..bbc6b10 100644 --- 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 0a5d36b..54d3f2c 100644 --- 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 */