[iptables PATCH 16/18] nft: cache: Sort custom chains by name

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Update nft_cache_add_chain() to make use of libnftnl's new
nftnl_chain_list_add_sorted() function and sort custom chains by name.

Signed-off-by: Phil Sutter <phil@xxxxxx>
---
 iptables/nft-cache.c                                     | 9 ++++++++-
 .../testcases/ebtables/0002-ebtables-save-restore_0      | 2 +-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/iptables/nft-cache.c b/iptables/nft-cache.c
index 5853bdce82f88..7949bc57b0e1b 100644
--- a/iptables/nft-cache.c
+++ b/iptables/nft-cache.c
@@ -181,6 +181,12 @@ static int fetch_table_cache(struct nft_handle *h)
 	return ret;
 }
 
+static int nftnl_chain_name_cmp(struct nftnl_chain *a, struct nftnl_chain *b)
+{
+	return strcmp(nftnl_chain_get_str(a, NFTNL_CHAIN_NAME),
+		      nftnl_chain_get_str(b, NFTNL_CHAIN_NAME));
+}
+
 int nft_cache_add_chain(struct nft_handle *h, const struct builtin_table *t,
 			struct nftnl_chain *c)
 {
@@ -197,7 +203,8 @@ int nft_cache_add_chain(struct nft_handle *h, const struct builtin_table *t,
 		return 0;
 	}
 
-	nftnl_chain_list_add_tail(c, h->cache->table[t->type].chains);
+	nftnl_chain_list_add_sorted(c, h->cache->table[t->type].chains,
+				    nftnl_chain_name_cmp);
 	return 0;
 }
 
diff --git a/iptables/tests/shell/testcases/ebtables/0002-ebtables-save-restore_0 b/iptables/tests/shell/testcases/ebtables/0002-ebtables-save-restore_0
index b84f63a7c3672..ccdef19cfb215 100755
--- a/iptables/tests/shell/testcases/ebtables/0002-ebtables-save-restore_0
+++ b/iptables/tests/shell/testcases/ebtables/0002-ebtables-save-restore_0
@@ -70,8 +70,8 @@ DUMP='*filter
 :INPUT ACCEPT
 :FORWARD DROP
 :OUTPUT ACCEPT
-:foo ACCEPT
 :bar RETURN
+:foo ACCEPT
 -A INPUT -p IPv4 -i lo -j ACCEPT
 -A FORWARD -j foo
 -A OUTPUT -s Broadcast -j DROP
-- 
2.27.0




[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux