netifd: Add old style vlan devices to device list
[project/netifd.git] / system-linux.c
index e45fc69..6dc9acd 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/rtnetlink.h>
 #include <linux/sockios.h>
 #include <linux/ip.h>
+#include <linux/if_addr.h>
 #include <linux/if_link.h>
 #include <linux/if_vlan.h>
 #include <linux/if_bridge.h>
 #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
+
+#ifndef IFA_FLAGS
+#define IFA_FLAGS (IFA_MULTICAST + 1)
+#endif
+
+
 #include <string.h>
 #include <fcntl.h>
 #include <glob.h>
@@ -370,7 +384,6 @@ static int system_get_neigh6reachabletime(struct device *dev, char *buf, const s
 static int cb_rtnl_event(struct nl_msg *msg, void *arg)
 {
        struct nlmsghdr *nh = nlmsg_hdr(msg);
-       struct ifinfomsg *ifi = NLMSG_DATA(nh);
        struct nlattr *nla[__IFLA_MAX];
        int link_state = 0;
        char buf[10];
@@ -378,7 +391,7 @@ static int cb_rtnl_event(struct nl_msg *msg, void *arg)
        if (nh->nlmsg_type != RTM_NEWLINK)
                goto out;
 
-       nlmsg_parse(nh, sizeof(*ifi), nla, __IFLA_MAX - 1, NULL);
+       nlmsg_parse(nh, sizeof(struct ifinfomsg), nla, __IFLA_MAX - 1, NULL);
        if (!nla[IFLA_IFNAME])
                goto out;
 
@@ -778,6 +791,7 @@ sec_to_jiffies(int val)
 
 int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg)
 {
+       char buf[64];
        unsigned long args[4] = {};
 
        if (ioctl(sock_ioctl, SIOCBRADDBR, bridge->ifname) < 0)
@@ -797,6 +811,10 @@ int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg)
        system_set_dev_sysctl("/sys/devices/virtual/net/%s/bridge/multicast_querier",
                bridge->ifname, cfg->multicast_querier ? "1" : "0");
 
+       snprintf(buf, sizeof(buf), "%i", cfg->hash_max);
+       system_set_dev_sysctl("/sys/devices/virtual/net/%s/bridge/hash_max",
+               bridge->ifname, buf);
+
        args[0] = BRCTL_SET_BRIDGE_PRIORITY;
        args[1] = cfg->priority;
        system_bridge_if(bridge->ifname, NULL, SIOCDEVPRIVATE, &args);
@@ -1466,6 +1484,9 @@ static int system_addr(struct device *dev, struct device_addr *addr, int cmd)
                }
 
                nla_put(msg, IFA_CACHEINFO, sizeof(cinfo), &cinfo);
+
+               if (cmd == RTM_NEWADDR && (addr->flags & DEVADDR_OFFLINK))
+                       nla_put_u32(msg, IFA_FLAGS, IFA_F_NOPREFIXROUTE);
        }
 
        return system_rtnl_call(msg);
@@ -1638,6 +1659,8 @@ 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)
@@ -1798,7 +1821,11 @@ int system_flush_iprules(void)
 
        rule.flags = IPRULE_INET4 | IPRULE_PRIORITY | IPRULE_LOOKUP;
 
-       rule.priority = 128;
+       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);
 
@@ -1813,7 +1840,11 @@ int system_flush_iprules(void)
 
        rule.flags = IPRULE_INET6 | IPRULE_PRIORITY | IPRULE_LOOKUP;
 
-       rule.priority = 128;
+       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);