netifd: Add old style vlan devices to device list
[project/netifd.git] / system-linux.c
index 21385fc..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>
 #include <time.h>
+#include <unistd.h>
 
 #include <netlink/msg.h>
 #include <netlink/attr.h>
@@ -373,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];
@@ -381,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;
 
@@ -781,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)
@@ -798,7 +809,11 @@ int system_bridge_addbr(struct device *bridge, struct bridge_config *cfg)
                bridge->ifname, cfg->igmp_snoop ? "1" : "0");
 
        system_set_dev_sysctl("/sys/devices/virtual/net/%s/bridge/multicast_querier",
-               bridge->ifname, cfg->igmp_snoop ? "1" : "0");
+               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;
@@ -1055,14 +1070,43 @@ system_if_get_settings(struct device *dev, struct device_settings *s)
        }
 }
 
+static void
+system_if_set_rps_xps_val(const char *path, int val)
+{
+       char val_buf[8];
+       glob_t gl;
+       int i;
+
+       if (glob(path, 0, NULL, &gl))
+               return;
+
+       snprintf(val_buf, sizeof(val_buf), "%x", val);
+       for (i = 0; i < gl.gl_pathc; i++)
+               system_set_sysctl(gl.gl_pathv[i], val_buf);
+}
+
+static void
+system_if_apply_rps_xps(struct device *dev, struct device_settings *s)
+{
+       long n_cpus = sysconf(_SC_NPROCESSORS_ONLN);
+       int val;
+
+       if (n_cpus < 2)
+               return;
+
+       val = (1 << n_cpus) - 1;
+       snprintf(dev_buf, sizeof(dev_buf), "/sys/class/net/%s/queues/*/rps_cpus", dev->ifname);
+       system_if_set_rps_xps_val(dev_buf, s->rps ? val : 0);
+
+       snprintf(dev_buf, sizeof(dev_buf), "/sys/class/net/%s/queues/*/xps_cpus", dev->ifname);
+       system_if_set_rps_xps_val(dev_buf, s->xps ? val : 0);
+}
+
 void
 system_if_apply_settings(struct device *dev, struct device_settings *s, unsigned int apply_mask)
 {
        struct ifreq ifr;
 
-       if (!apply_mask)
-               return;
-
        memset(&ifr, 0, sizeof(ifr));
        strncpy(ifr.ifr_name, dev->ifname, sizeof(ifr.ifr_name));
        if (s->flags & DEV_OPT_MTU & apply_mask) {
@@ -1116,6 +1160,8 @@ system_if_apply_settings(struct device *dev, struct device_settings *s, unsigned
                snprintf(buf, sizeof(buf), "%d", s->neigh6reachabletime);
                system_set_neigh6reachabletime(dev, buf);
        }
+
+       system_if_apply_rps_xps(dev, s);
 }
 
 int system_if_up(struct device *dev)
@@ -1438,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);