IPv6: fix prefix assignment with continuous hints
[project/netifd.git] / system-linux.c
index 76740f7..4299a61 100644 (file)
 #include <linux/ethtool.h>
 #include <linux/fib_rules.h>
 
+#ifndef RTN_FAILED_POLICY
+#define RTN_FAILED_POLICY 12
+#endif
+
 #include <unistd.h>
 #include <string.h>
 #include <fcntl.h>
@@ -65,8 +69,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 +922,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 +1185,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);
 }
 
@@ -1260,6 +1259,8 @@ bool system_resolve_iprule_action(const char *action, unsigned int *id)
                n = RTN_UNICAST;
        else if (!strcmp(action, "throw"))
                n = RTN_THROW;
+       else if (!strcmp(action, "failed_policy"))
+               n = RTN_FAILED_POLICY;
        else {
                n = strtoul(action, &e, 0);
                if (!e || *e || e == action || n > 255)