Maintain config order of ip rules unless user explicitely provides priority
authorJo-Philipp Wich <jow@openwrt.org>
Fri, 5 Apr 2013 11:45:08 +0000 (13:45 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Fri, 5 Apr 2013 11:54:09 +0000 (13:54 +0200)
iprule.c
iprule.h
system-linux.c

index 7172f292079ff77a80b5999550632b72f3b37392..c3fdcfce6e046d42ca75e989f01faebb170d4eb6 100644 (file)
--- a/iprule.c
+++ b/iprule.c
@@ -29,6 +29,7 @@
 
 struct vlist_tree iprules;
 static bool iprules_flushed = false;
+static unsigned int iprules_counter[2];
 
 enum {
        RULE_INTERFACE_IN,
@@ -111,6 +112,7 @@ iprule_add(struct blob_attr *attr, bool v6)
                return;
 
        rule->flags = v6 ? IPRULE_INET6 : IPRULE_INET4;
+       rule->order = iprules_counter[rule->flags]++;
 
        if ((cur = tb[RULE_INVERT]) != NULL)
                rule->invert = blobmsg_get_bool(cur);
@@ -214,6 +216,8 @@ error:
 void
 iprule_update_start(void)
 {
+       iprules_counter[0] = 1;
+       iprules_counter[1] = 1;
        vlist_update(&iprules);
 }
 
index 75c6a2b6c104218ce5823cf33f2580bad2b15fab..4b10760c9096f687f269264e6f2f28cdda8b4d73 100644 (file)
--- a/iprule.h
+++ b/iprule.h
@@ -59,6 +59,7 @@ enum iprule_flags {
 
 struct iprule {
        struct vlist_node node;
+       unsigned int order;
 
        /* everything below is used as avl tree key */
        enum iprule_flags flags;
index 87a4efa2412ffdf9b0d3d765ec48adbf257d927f..d788a01a5d4b0b0e777130d68d31e60f865b370d 100644 (file)
@@ -1149,6 +1149,8 @@ static int system_iprule(struct iprule *rule, int cmd)
 
        if (rule->flags & IPRULE_PRIORITY)
                nla_put_u32(msg, FRA_PRIORITY, rule->priority);
+       else if (cmd == RTM_NEWRULE)
+               nla_put_u32(msg, FRA_PRIORITY, rule->order);
 
        if (rule->flags & IPRULE_FWMARK)
                nla_put_u32(msg, FRA_FWMARK, rule->fwmark);