diff --git a/src/agent.h b/src/agent.h index 715987e3e6b52a6951fd7482e46af6b6fe7942e6..f1cc1e16374f884526e088ace3a41888ccbe917c 100644 --- a/src/agent.h +++ b/src/agent.h @@ -299,11 +299,6 @@ struct netif_bk { unsigned int vid; }; -struct netif_eth { - char name[16]; - struct list_head list; -}; - #if 0 struct agent_msg { void *ctx; diff --git a/src/agent_map.c b/src/agent_map.c index 619c57338428df235a491ffe3992897cedf45695..002487c592a4bbc1a806a331a0d57e7a856ed03e 100644 --- a/src/agent_map.c +++ b/src/agent_map.c @@ -1371,45 +1371,50 @@ 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) +static void agent_ts_setup_eths(struct agent *a, struct agent_config *cfg, + struct policy_cfg *c) { - struct netif_eth *e; + struct netif_fh *fh; + char cmd[128] = {0}; + char vids[64] = {0}; + char *vids_buf = vids; + int vids_len = sizeof(vids) - 1; + int len; - e = calloc(1, sizeof(struct netif_eth)); - if (!e) - return NULL; + bool have_vids = false; + /* secondary networks vlan id's*/ + list_for_each_entry(fh, &a->fhlist, list) { + char vid_str[8] = {0}; - snprintf(e->name, 15, "%s", ifname); + if (!is_vid_valid(fh->vid)) + continue; + if (fh->vid == c->pvid) + continue; - return e; -} + /* TODO keep table of secondary vids from config */ -static void setup_ethlist(struct agent *a) -{ - char out[128] = {0}; - char *str; - char *ifname; - struct netif_eth *e, *tmp; + snprintf(vid_str, sizeof(vid_str) - 1, " %u ", fh->vid); + if (strstr(vids, vid_str)) + continue; - /* TODO: better way to list/manage eth interfaces */ + len = snprintf(vids_buf, vids_len, "%s", vid_str); + if (len < 0) { + err("Fail to add secondary vlan id"); + break; + } - list_for_each_entry_safe(e, tmp, &a->ethlist, list) { - list_del(&e->list); - free(e); - } + vids_buf += len; + vids_len -= len; - Cmd(out, sizeof(out), "/lib/wifi/multiap ts get_eth_ifaces"); + have_vids = true; + } - for (str = out; (ifname = strtok(str, " ")) != NULL; str = NULL) { - if (strncmp(ifname, "lei_lan", sizeof("lei_lan")) == 0) - continue; + if (!have_vids) + return; - e = netif_alloc_eth(ifname); - if (e) - list_add_tail(&e->list, &a->ethlist); - else - err("Fail to alloc eth ifname"); - } + snprintf(cmd, sizeof(cmd), "ts create eths %u %s %s", + c->pvid, cfg->al_bridge, vids); + agent_exec_platform_scripts(cmd); } /* Set up Traffic Separation rules */ @@ -1420,14 +1425,9 @@ int agent_apply_traffic_separation(struct agent *a) struct policy_cfg *c; struct netif_fh *fh; struct netif_bk *bk; - struct netif_eth *eth; bool diff = false; - bool dhcp_reload = false; char cmd[128] = {0}; - char vids[64] = {0}; - char *vids_buf = vids; - int vids_len = sizeof(vids) - 1; - int len; + bool dhcp_reload = false; if (!a) return -1; @@ -1538,43 +1538,13 @@ int agent_apply_traffic_separation(struct agent *a) if (!diff && a->ts.active) return 0; - /* 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; - - /* 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; - } - - vids_buf += len; - vids_len -= len; - } - /* Logical Ethernet Interface */ /* Note: setup of LEI is already handled by init script */ 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); - agent_exec_platform_scripts(cmd); - } + agent_ts_setup_eths(a, cfg, c); a->ts.active = true;