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 <yashvardhan@netexperience.com>
This commit is contained in:
Yashvardhan
2021-03-22 08:15:27 -07:00
committed by Rick Sommerville
parent ea470687cc
commit 9d7beae903
4 changed files with 41 additions and 36 deletions

View File

@@ -6,7 +6,9 @@
#include "netifd.h"
#include "inet_iface.h"
struct netifd_iface *netifd_add_inet_conf(struct schema_Wifi_Inet_Config *iconf);
#define DHCP_SNIFF_MAX_VLAN 4
void netifd_add_inet_conf(struct schema_Wifi_Inet_Config *iconf);
void netifd_del_inet_conf(struct schema_Wifi_Inet_Config *old_rec);
struct netifd_iface *netifd_modify_inet_conf(struct schema_Wifi_Inet_Config *iconf);
bool netifd_inet_config_set(struct netifd_iface *piface);

View File

@@ -6,30 +6,43 @@
#include "inet_conf.h"
struct netifd_iface* netifd_add_inet_conf(struct schema_Wifi_Inet_Config *iconf)
{
static int vlan_count = 0;
void netifd_add_inet_conf(struct schema_Wifi_Inet_Config *iconf)
{
struct netifd_iface *piface = NULL;
piface = netifd_iface_get_by_name(iconf->if_name);
if (piface == NULL)
{
piface = netifd_iface_new(iconf->if_name, iconf->if_type);
if (piface == NULL)
{
LOG(ERR, "netifd_add_inet_conf: %s: Unable to create interface.", iconf->if_name);
return NULL;
}
if (strcmp(iconf->if_type, "bridge") && strcmp(iconf->if_type, "vlan")) {
return;
}
if (!strcmp(iconf->if_type, "bridge") || !strcmp(iconf->if_type, "vlan"))
{
LOGN("Setting up dhsnif for %s", piface->if_base->inet.in_ifname);
piface = netifd_iface_get_by_name(iconf->if_name);
if (piface)
return;
if (!strcmp(iconf->if_name, "wan") || !strcmp(iconf->if_name, "lan")) {
piface = netifd_iface_new(iconf->if_name, iconf->if_type);
if (!piface) {
LOG(ERR, "netifd_add_inet_conf: %s: Unable to create interface.", iconf->if_name);
return;
}
netifd_inet_config_set(piface);
netifd_inet_config_apply(piface);
} else if (iconf->vlan_id_exists && iconf->vlan_id > 2) {
if (vlan_count < DHCP_SNIFF_MAX_VLAN && !strstr(iconf->if_name,"lan_")) {
piface = netifd_iface_new(iconf->if_name, iconf->if_type);
if (!piface) {
LOG(ERR, "netifd_add_inet_conf: %s: Unable to create interface.", iconf->if_name);
return;
}
netifd_inet_config_set(piface);
netifd_inet_config_apply(piface);
vlan_count++;
}
}
return piface;
return;
}
void netifd_del_inet_conf(struct schema_Wifi_Inet_Config *old_rec)
@@ -37,14 +50,14 @@ void netifd_del_inet_conf(struct schema_Wifi_Inet_Config *old_rec)
struct netifd_iface *piface = NULL;
piface = netifd_iface_get_by_name(old_rec->if_name);
if (piface == NULL)
{
LOG(ERR, "netifd_del_inet_conf: Unable to delete non-existent interface %s.",
old_rec->if_name);
}
if (piface != NULL && !netifd_iface_del(piface))
{
if (!piface)
return;
if (netifd_iface_del(piface)) {
if (old_rec->vlan_id_exists && old_rec->vlan_id > 2)
vlan_count--;
} else {
LOG(ERR, "netifd_del_inet_conf: Error during destruction of interface %s.",
old_rec->if_name);
}

View File

@@ -24,8 +24,6 @@ struct netifd_iface *netifd_iface_get_by_name(char *_ifname)
if (piface != NULL)
return piface;
LOG(ERR, "netifd_iface_get_by_name: Couldn't find the interface(%s)", ifname);
return NULL;
}
@@ -102,7 +100,7 @@ inet_base_t *netifd_iface_new_inet(const char *ifname, const char *iftype)
goto error;
}
memset(self, 0, sizeof(inet_base_t));
if((!strcmp(ifname, "wan") && !strcmp(iftype,"bridge")) || (!strcmp(ifname, "lan") && !strcmp(iftype,"bridge"))) {
if(!strcmp(iftype,"bridge")) {
snprintf(self->inet.in_ifname, sizeof(self->inet.in_ifname), "br-%s", ifname);
} else if (!strcmp(iftype,"vlan")) {
char name[15]= {};

View File

@@ -368,16 +368,14 @@ static void callback_Wifi_Inet_Config(ovsdb_update_monitor_t *mon,
struct schema_Wifi_Inet_Config *old_rec,
struct schema_Wifi_Inet_Config *iconf)
{
struct netifd_iface *piface = NULL;
switch (mon->mon_type) {
case OVSDB_UPDATE_NEW:
wifi_inet_conf_add(iconf);
piface = netifd_add_inet_conf(iconf);
netifd_add_inet_conf(iconf);
break;
case OVSDB_UPDATE_MODIFY:
wifi_inet_conf_add(iconf);
piface = netifd_modify_inet_conf(iconf);
netifd_modify_inet_conf(iconf);
break;
case OVSDB_UPDATE_DEL:
wifi_inet_conf_del(old_rec);
@@ -387,12 +385,6 @@ static void callback_Wifi_Inet_Config(ovsdb_update_monitor_t *mon,
LOG(ERR, "Invalid Wifi_Inet_Config mon_type(%d)", mon->mon_type);
}
if(!piface) {
LOG(ERR, "callback_Wifi_Inet_Config: Couldn't get the netifd interface(%s)",
iconf->if_name);
return;
}
return;
}