use calloc_a for interface error allocations
[project/netifd.git] / system-linux.c
index eb26d20..eb73e95 100644 (file)
@@ -154,7 +154,7 @@ static void system_set_sysctl(const char *path, const char *val)
 
 static void system_set_dev_sysctl(const char *path, const char *device, const char *val)
 {
-       snprintf(dev_buf, sizeof(dev_buf), path, val);
+       snprintf(dev_buf, sizeof(dev_buf), path, device);
        system_set_sysctl(dev_buf, val);
 }
 
@@ -382,8 +382,13 @@ static bool check_ifaddr(struct nlmsghdr *hdr, int ifindex)
 
 static bool check_route(struct nlmsghdr *hdr, int ifindex)
 {
+       struct rtmsg *r = NLMSG_DATA(hdr);
        struct nlattr *tb[__RTA_MAX];
 
+       if (r->rtm_protocol == RTPROT_KERNEL &&
+           r->rtm_family == AF_INET6)
+               return false;
+
        nlmsg_parse(hdr, sizeof(struct rtmsg), tb, __RTA_MAX - 1, NULL);
        if (!tb[RTA_OIF])
                return false;
@@ -632,7 +637,7 @@ system_if_get_settings(struct device *dev, struct device_settings *s)
        }
 }
 
-static void
+void
 system_if_apply_settings(struct device *dev, struct device_settings *s)
 {
        struct ifreq ifr;
@@ -649,7 +654,7 @@ system_if_apply_settings(struct device *dev, struct device_settings *s)
                if (ioctl(sock_ioctl, SIOCSIFTXQLEN, &ifr) < 0)
                        s->flags &= ~DEV_OPT_TXQUEUELEN;
        }
-       if (s->flags & DEV_OPT_MACADDR) {
+       if ((s->flags & DEV_OPT_MACADDR) && !dev->external) {
                ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
                memcpy(&ifr.ifr_hwaddr.sa_data, s->macaddr, sizeof(s->macaddr));
                if (ioctl(sock_ioctl, SIOCSIFHWADDR, &ifr) < 0)
@@ -916,7 +921,7 @@ static int system_rt(struct device *dev, struct device_route *route, int cmd)
                .rtm_family = (alen == 4) ? AF_INET : AF_INET6,
                .rtm_dst_len = route->mask,
                .rtm_table = RT_TABLE_MAIN,
-               .rtm_protocol = (route->flags & DEVADDR_KERNEL) ? RTPROT_KERNEL : RTPROT_BOOT,
+               .rtm_protocol = (route->flags & DEVADDR_KERNEL) ? RTPROT_KERNEL : RTPROT_STATIC,
                .rtm_scope = scope,
                .rtm_type = (cmd == RTM_DELROUTE) ? 0: RTN_UNICAST,
        };