Skip to content

Commit 9d7beae

Browse files
yashvardhan-netexRickSommerville
authored andcommitted
wifi-1737: Restrict DHCP Sniffing to a max of 4 vlans
Partial fix for wifi-1737: Use of current DHCP sniffing library from opensync increases memory footprint of nm with increased number of vlans. This patch restricts DHCP sniffing on a maximum of 4 vlans. This is a workaround and actual fix would be to use a better packet filter such as eBPF Signed-off-by: Yashvardhan <[email protected]>
1 parent ea47068 commit 9d7beae

File tree

4 files changed

+38
-33
lines changed

4 files changed

+38
-33
lines changed

feeds/wlan-ap/opensync/src/platform/openwrt/src/netifd/inc/inet_conf.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
#include "netifd.h"
77
#include "inet_iface.h"
88

9-
struct netifd_iface *netifd_add_inet_conf(struct schema_Wifi_Inet_Config *iconf);
9+
#define DHCP_SNIFF_MAX_VLAN 4
10+
11+
void netifd_add_inet_conf(struct schema_Wifi_Inet_Config *iconf);
1012
void netifd_del_inet_conf(struct schema_Wifi_Inet_Config *old_rec);
1113
struct netifd_iface *netifd_modify_inet_conf(struct schema_Wifi_Inet_Config *iconf);
1214
bool netifd_inet_config_set(struct netifd_iface *piface);

feeds/wlan-ap/opensync/src/platform/openwrt/src/netifd/src/inet_conf.c

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,58 @@
66

77
#include "inet_conf.h"
88

9-
struct netifd_iface* netifd_add_inet_conf(struct schema_Wifi_Inet_Config *iconf)
10-
{
9+
static int vlan_count = 0;
1110

11+
void netifd_add_inet_conf(struct schema_Wifi_Inet_Config *iconf)
12+
{
1213
struct netifd_iface *piface = NULL;
1314

15+
if (strcmp(iconf->if_type, "bridge") && strcmp(iconf->if_type, "vlan")) {
16+
return;
17+
}
18+
1419
piface = netifd_iface_get_by_name(iconf->if_name);
15-
if (piface == NULL)
16-
{
20+
21+
if (piface)
22+
return;
23+
24+
if (!strcmp(iconf->if_name, "wan") || !strcmp(iconf->if_name, "lan")) {
1725
piface = netifd_iface_new(iconf->if_name, iconf->if_type);
18-
if (piface == NULL)
19-
{
26+
if (!piface) {
2027
LOG(ERR, "netifd_add_inet_conf: %s: Unable to create interface.", iconf->if_name);
21-
return NULL;
28+
return;
2229
}
23-
24-
if (!strcmp(iconf->if_type, "bridge") || !strcmp(iconf->if_type, "vlan"))
25-
{
26-
LOGN("Setting up dhsnif for %s", piface->if_base->inet.in_ifname);
30+
netifd_inet_config_set(piface);
31+
netifd_inet_config_apply(piface);
32+
} else if (iconf->vlan_id_exists && iconf->vlan_id > 2) {
33+
if (vlan_count < DHCP_SNIFF_MAX_VLAN && !strstr(iconf->if_name,"lan_")) {
34+
piface = netifd_iface_new(iconf->if_name, iconf->if_type);
35+
if (!piface) {
36+
LOG(ERR, "netifd_add_inet_conf: %s: Unable to create interface.", iconf->if_name);
37+
return;
38+
}
2739
netifd_inet_config_set(piface);
2840
netifd_inet_config_apply(piface);
41+
vlan_count++;
2942
}
3043
}
3144

32-
return piface;
45+
return;
3346
}
3447

3548
void netifd_del_inet_conf(struct schema_Wifi_Inet_Config *old_rec)
3649
{
3750
struct netifd_iface *piface = NULL;
3851

3952
piface = netifd_iface_get_by_name(old_rec->if_name);
40-
if (piface == NULL)
41-
{
42-
LOG(ERR, "netifd_del_inet_conf: Unable to delete non-existent interface %s.",
43-
old_rec->if_name);
44-
}
4553

46-
if (piface != NULL && !netifd_iface_del(piface))
47-
{
54+
if (!piface)
55+
return;
56+
57+
if (netifd_iface_del(piface)) {
58+
if (old_rec->vlan_id_exists && old_rec->vlan_id > 2)
59+
vlan_count--;
60+
} else {
4861
LOG(ERR, "netifd_del_inet_conf: Error during destruction of interface %s.",
4962
old_rec->if_name);
5063
}

feeds/wlan-ap/opensync/src/platform/openwrt/src/netifd/src/inet_iface.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ struct netifd_iface *netifd_iface_get_by_name(char *_ifname)
2424
if (piface != NULL)
2525
return piface;
2626

27-
LOG(ERR, "netifd_iface_get_by_name: Couldn't find the interface(%s)", ifname);
28-
2927
return NULL;
3028
}
3129

@@ -102,7 +100,7 @@ inet_base_t *netifd_iface_new_inet(const char *ifname, const char *iftype)
102100
goto error;
103101
}
104102
memset(self, 0, sizeof(inet_base_t));
105-
if((!strcmp(ifname, "wan") && !strcmp(iftype,"bridge")) || (!strcmp(ifname, "lan") && !strcmp(iftype,"bridge"))) {
103+
if(!strcmp(iftype,"bridge")) {
106104
snprintf(self->inet.in_ifname, sizeof(self->inet.in_ifname), "br-%s", ifname);
107105
} else if (!strcmp(iftype,"vlan")) {
108106
char name[15]= {};

feeds/wlan-ap/opensync/src/platform/openwrt/src/netifd/src/wifi_inet_config.c

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -368,16 +368,14 @@ static void callback_Wifi_Inet_Config(ovsdb_update_monitor_t *mon,
368368
struct schema_Wifi_Inet_Config *old_rec,
369369
struct schema_Wifi_Inet_Config *iconf)
370370
{
371-
struct netifd_iface *piface = NULL;
372-
373371
switch (mon->mon_type) {
374372
case OVSDB_UPDATE_NEW:
375373
wifi_inet_conf_add(iconf);
376-
piface = netifd_add_inet_conf(iconf);
374+
netifd_add_inet_conf(iconf);
377375
break;
378376
case OVSDB_UPDATE_MODIFY:
379377
wifi_inet_conf_add(iconf);
380-
piface = netifd_modify_inet_conf(iconf);
378+
netifd_modify_inet_conf(iconf);
381379
break;
382380
case OVSDB_UPDATE_DEL:
383381
wifi_inet_conf_del(old_rec);
@@ -387,12 +385,6 @@ static void callback_Wifi_Inet_Config(ovsdb_update_monitor_t *mon,
387385
LOG(ERR, "Invalid Wifi_Inet_Config mon_type(%d)", mon->mon_type);
388386
}
389387

390-
if(!piface) {
391-
LOG(ERR, "callback_Wifi_Inet_Config: Couldn't get the netifd interface(%s)",
392-
iconf->if_name);
393-
return;
394-
}
395-
396388
return;
397389
}
398390

0 commit comments

Comments
 (0)