Move initial iprule flushing to system_add_iprule() to not collide with generic multi...
[project/netifd.git] / system-linux.c
index efda0d5..76740f7 100644 (file)
@@ -65,6 +65,8 @@ 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)
 {
@@ -1177,6 +1179,13 @@ 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);
 }
 
@@ -1342,9 +1351,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")) {