From 4cbee5033f851f7beb09b323ac1617abbc89736c Mon Sep 17 00:00:00 2001 From: Stanislaw Gruszka <stanislaw.gruszka@iopsys.eu> Date: Sat, 19 Feb 2022 15:16:03 +0100 Subject: [PATCH] ts: support for setting eth vlanctl rules --- src/agent.c | 23 +++++++++++++++++++++++ src/agent.h | 7 +++++++ src/agent_map.c | 36 ++++++++++++++++++++++++++---------- 3 files changed, 56 insertions(+), 10 deletions(-) diff --git a/src/agent.c b/src/agent.c index af436895e..1f41c13db 100644 --- a/src/agent.c +++ b/src/agent.c @@ -4076,6 +4076,19 @@ 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) { @@ -4107,6 +4120,7 @@ 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; @@ -4123,6 +4137,14 @@ 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"); + } } } } @@ -5554,6 +5576,7 @@ int agent_init_defaults(struct agent *a) { INIT_LIST_HEAD(&a->fhlist); INIT_LIST_HEAD(&a->bklist); + INIT_LIST_HEAD(&a->ethlist); INIT_LIST_HEAD(&a->framelist); a->cntlr_select.local = CONTROLLER_SELECT_LOCAL; diff --git a/src/agent.h b/src/agent.h index 58b213bf7..715987e3e 100644 --- a/src/agent.h +++ b/src/agent.h @@ -299,6 +299,11 @@ struct netif_bk { unsigned int vid; }; +struct netif_eth { + char name[16]; + struct list_head list; +}; + #if 0 struct agent_msg { void *ctx; @@ -563,6 +568,8 @@ struct agent { struct list_head fhlist; struct list_head bklist; struct list_head framelist; + struct list_head ethlist; + wifi_object_t wifi; int num_radios; struct wifi_radio_element radios[WIFI_DEVICE_MAX_NUM]; diff --git a/src/agent_map.c b/src/agent_map.c index 46a1022c3..69b157ae6 100644 --- a/src/agent_map.c +++ b/src/agent_map.c @@ -1379,10 +1379,14 @@ 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; if (!a) return -1; @@ -1493,21 +1497,33 @@ 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) { + if (!is_vid_valid(fh->vid)) + continue; + if (fh->vid == c->pvid) + continue; + + len = snprintf(vids_buf, vids_len, " %u", fh->vid); + 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 eth %s %u %u %s %s", VLAN_IFACE, c->pvid, c->pcp_default, cfg->al_bridge, "br-lan"); agent_exec_platform_scripts(cmd); - list_for_each_entry(fh, &a->fhlist, list) { - if (is_vid_valid(fh->vid)) { - if (fh->vid == c->pvid) - continue; - /* secondary networks */ - snprintf(cmd, sizeof(cmd), "ts populate eth %s %u", - VLAN_IFACE, fh->vid); - agent_exec_platform_scripts(cmd); - } + list_for_each_entry(eth, &a->ethlist, list) { + snprintf(cmd, sizeof(cmd), "ts create eth_lei %s %u %s %s", + eth->name, c->pvid, cfg->al_bridge, vids); + agent_exec_platform_scripts(cmd); } a->ts.active = true; -- GitLab