From 800e5e5f50b62af1b7054f41331a4cc0d7802f65 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 5 Apr 2013 13:45:08 +0200 Subject: [PATCH] Maintain config order of ip rules unless user explicitely provides priority --- iprule.c | 4 ++++ iprule.h | 1 + system-linux.c | 2 ++ 3 files changed, 7 insertions(+) diff --git a/iprule.c b/iprule.c index 7172f29..c3fdcfc 100644 --- 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); } diff --git a/iprule.h b/iprule.h index 75c6a2b..4b10760 100644 --- 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; diff --git a/system-linux.c b/system-linux.c index 87a4efa..d788a01 100644 --- a/system-linux.c +++ b/system-linux.c @@ -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); -- 2.30.2