bridge: make learning and unicast-flood configurable per bridge port
[project/netifd.git] / system-linux.c
index 7638086..621f99b 100644 (file)
 #define RTN_FAILED_POLICY 12
 #endif
 
-#ifndef RT_TABLE_PRELOCAL
-#define RT_TABLE_PRELOCAL 128
-#endif
-
 #ifndef IFA_F_NOPREFIXROUTE
 #define IFA_F_NOPREFIXROUTE 0x200
 #endif
@@ -376,6 +372,16 @@ static void system_bridge_set_startup_query_interval(struct device *dev, const c
                              dev->ifname, val);
 }
 
+static void system_bridge_set_learning(struct device *dev, const char *val)
+{
+       system_set_dev_sysctl("/sys/class/net/%s/brport/learning", dev->ifname, val);
+}
+
+static void system_bridge_set_unicast_flood(struct device *dev, const char *val)
+{
+       system_set_dev_sysctl("/sys/class/net/%s/brport/unicast_flood", dev->ifname, val);
+}
+
 static int system_get_sysctl(const char *path, char *buf, const size_t buf_sz)
 {
        int fd = -1, ret = -1;
@@ -652,6 +658,14 @@ int system_bridge_addif(struct device *bridge, struct device *dev)
                system_bridge_set_multicast_router(dev, buf, false);
        }
 
+       if (dev->settings.flags & DEV_OPT_LEARNING &&
+           !dev->settings.learning)
+               system_bridge_set_learning(dev, "0");
+
+       if (dev->settings.flags & DEV_OPT_UNICAST_FLOOD &&
+           !dev->settings.unicast_flood)
+               system_bridge_set_unicast_flood(dev, "0");
+
        return ret;
 }
 
@@ -1838,8 +1852,6 @@ bool system_resolve_rt_table(const char *name, unsigned int *id)
                table = RT_TABLE_MAIN;
        else if (!strcmp(name, "local"))
                table = RT_TABLE_LOCAL;
-       else if (!strcmp(name, "prelocal"))
-               table = RT_TABLE_PRELOCAL;
 
        /* try to look up name in /etc/iproute2/rt_tables */
        else if ((f = fopen("/etc/iproute2/rt_tables", "r")) != NULL)
@@ -1999,10 +2011,6 @@ int system_flush_iprules(void)
        rule.flags = IPRULE_INET4 | IPRULE_PRIORITY | IPRULE_LOOKUP;
 
        rule.priority = 0;
-       rule.lookup = RT_TABLE_PRELOCAL;
-       rv |= system_iprule(&rule, RTM_NEWRULE);
-
-       rule.priority = 1;
        rule.lookup = RT_TABLE_LOCAL;
        rv |= system_iprule(&rule, RTM_NEWRULE);
 
@@ -2018,10 +2026,6 @@ int system_flush_iprules(void)
        rule.flags = IPRULE_INET6 | IPRULE_PRIORITY | IPRULE_LOOKUP;
 
        rule.priority = 0;
-       rule.lookup = RT_TABLE_PRELOCAL;
-       rv |= system_iprule(&rule, RTM_NEWRULE);
-
-       rule.priority = 1;
        rule.lookup = RT_TABLE_LOCAL;
        rv |= system_iprule(&rule, RTM_NEWRULE);