IPv6: fix address-lifetime overflows on 64-bit architectures
[project/netifd.git] / system-linux.c
index efda0d5..c6d81e6 100644 (file)
@@ -918,17 +918,21 @@ static int system_addr(struct device *dev, struct device_addr *addr, int cmd)
                struct ifa_cacheinfo cinfo = {0xffffffffU, 0xffffffffU, 0, 0};
 
                if (addr->preferred_until) {
-                       int preferred = addr->preferred_until - now;
+                       int64_t preferred = addr->preferred_until - now;
                        if (preferred < 0)
                                preferred = 0;
+                       else if (preferred > UINT32_MAX)
+                               preferred = UINT32_MAX;
 
                        cinfo.ifa_prefered = preferred;
                }
 
                if (addr->valid_until) {
-                       int valid = addr->valid_until - now;
+                       int64_t valid = addr->valid_until - now;
                        if (valid <= 0)
                                return -1;
+                       else if (valid > UINT32_MAX)
+                               valid = UINT32_MAX;
 
                        cinfo.ifa_valid = valid;
                }
@@ -1342,9 +1346,14 @@ int system_add_ip_tunnel(const char *name, struct blob_attr *attr)
                return -EINVAL;
 
        unsigned int link = 0;
-       if ((cur = tb[TUNNEL_ATTR_LINK]) &&
-                       !(link = if_nametoindex((const char*)blobmsg_data(cur))))
-               return -EINVAL;
+       if ((cur = tb[TUNNEL_ATTR_LINK])) {
+               struct interface *iface = vlist_find(&interfaces, blobmsg_data(cur), iface, node);
+               if (!iface)
+                       return -EINVAL;
+
+               if (iface->l3_dev.dev)
+                       link = iface->l3_dev.dev->ifindex;
+       }
 
 
        if (!strcmp(str, "sit")) {