diff --git a/src/agent.c b/src/agent.c index 1f41c13db42c6cde3776a8c71a4c7f64c7bbf962..5076003fd588a9cf06731129c072de3f792c168f 100644 --- a/src/agent.c +++ b/src/agent.c @@ -4076,19 +4076,6 @@ static int run_agent(struct agent *a) } #endif -static struct netif_eth *netif_alloc_eth(const char *ifname) -{ - struct netif_eth *e; - - e = calloc(1, sizeof(struct netif_eth)); - if (!e) - return NULL; - - snprintf(e->name, 15, "%s", ifname); - - return e; -} - static void parse_i1905_info(struct ubus_request *req, int type, struct blob_attr *msg) { @@ -4120,7 +4107,6 @@ static void parse_i1905_info(struct ubus_request *req, int type, }; char *ifname; char fmt[64] = {0}; - struct netif_eth *eth; if (blobmsg_type(cur) != BLOBMSG_TYPE_TABLE) continue; @@ -4137,14 +4123,6 @@ static void parse_i1905_info(struct ubus_request *req, int type, snprintf(fmt, sizeof(fmt), "ts multicast %s", ifname); agent_exec_platform_scripts(fmt); - - if (strncmp(ifname, "lei_lan", sizeof("lei_lan"))) { - eth = netif_alloc_eth(ifname); - if (eth) - list_add_tail(ð->list, &a->ethlist); - else - err("eth alloc fail"); - } } } } diff --git a/src/agent_map.c b/src/agent_map.c index e9484f69676e2fb064b15410aed44d3b3adefe4c..619c57338428df235a491ffe3992897cedf45695 100644 --- a/src/agent_map.c +++ b/src/agent_map.c @@ -1371,6 +1371,47 @@ static inline bool is_vid_valid(unsigned int vid) return (vid < TS_VID_INVALID) && (vid > 0); } +static struct netif_eth *netif_alloc_eth(const char *ifname) +{ + struct netif_eth *e; + + e = calloc(1, sizeof(struct netif_eth)); + if (!e) + return NULL; + + snprintf(e->name, 15, "%s", ifname); + + return e; +} + +static void setup_ethlist(struct agent *a) +{ + char out[128] = {0}; + char *str; + char *ifname; + struct netif_eth *e, *tmp; + + /* TODO: better way to list/manage eth interfaces */ + + list_for_each_entry_safe(e, tmp, &a->ethlist, list) { + list_del(&e->list); + free(e); + } + + Cmd(out, sizeof(out), "/lib/wifi/multiap ts get_eth_ifaces"); + + for (str = out; (ifname = strtok(str, " ")) != NULL; str = NULL) { + if (strncmp(ifname, "lei_lan", sizeof("lei_lan")) == 0) + continue; + + e = netif_alloc_eth(ifname); + if (e) + list_add_tail(&e->list, &a->ethlist); + else + err("Fail to alloc eth ifname"); + } +} + /* Set up Traffic Separation rules */ int agent_apply_traffic_separation(struct agent *a) { @@ -1499,12 +1540,20 @@ int agent_apply_traffic_separation(struct agent *a) /* secondary networks vlan id's*/ list_for_each_entry(fh, &a->fhlist, list) { + char vid_str[8] = {0}; + if (!is_vid_valid(fh->vid)) continue; if (fh->vid == c->pvid) continue; - len = snprintf(vids_buf, vids_len, " %u", fh->vid); + /* TODO keep table of secondary vids from config */ + + snprintf(vid_str, sizeof(vid_str) - 1, " %u ", fh->vid); + if (strstr(vids, vid_str)) + continue; + + len = snprintf(vids_buf, vids_len, "%s", vid_str); if (len < 0) { err("Fail to add secondary vlan id"); break; @@ -1516,10 +1565,11 @@ int agent_apply_traffic_separation(struct agent *a) /* Logical Ethernet Interface */ /* Note: setup of LEI is already handled by init script */ - snprintf(cmd, sizeof(cmd), "ts create lei %s %u %u %s %s", - VLAN_IFACE, c->pvid, c->pcp_default, cfg->al_bridge, "br-lan"); + snprintf(cmd, sizeof(cmd), "ts create lei %u %u %s %s", + c->pvid, c->pcp_default, cfg->al_bridge, "br-lan"); agent_exec_platform_scripts(cmd); + setup_ethlist(a); list_for_each_entry(eth, &a->ethlist, list) { snprintf(cmd, sizeof(cmd), "ts create eth %s %u %s %s", eth->name, c->pvid, cfg->al_bridge, vids);