IPv6: fix address-lifetime overflows on 64-bit architectures
[project/netifd.git] / system-linux.c
index 76740f7..c6d81e6 100644 (file)
@@ -65,8 +65,6 @@ static void handle_hotplug_event(struct uloop_fd *u, unsigned int events);
 
 static char dev_buf[256];
 
-static bool iprules_flushed = false;
-
 static void
 handler_nl_event(struct uloop_fd *u, unsigned int events)
 {
@@ -920,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;
                }
@@ -1179,13 +1181,6 @@ static int system_iprule(struct iprule *rule, int cmd)
 
 int system_add_iprule(struct iprule *rule)
 {
-       /* trigger flush of existing rules when adding first rule the first time */
-       if (!iprules_flushed)
-       {
-               system_flush_iprules();
-               iprules_flushed = true;
-       }
-
        return system_iprule(rule, RTM_NEWRULE);
 }