netifd: Add old style vlan devices to device list
[project/netifd.git] / system-linux.c
index 2b52cea..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 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>
@@ -374,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];
@@ -382,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;
 
@@ -782,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)
@@ -801,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);
@@ -1470,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);