summaryrefslogtreecommitdiffstats
path: root/iptables/nft-cache.c
diff options
context:
space:
mode:
authorPhil Sutter <phil@nwl.cc>2020-07-30 10:24:10 +0200
committerPhil Sutter <phil@nwl.cc>2020-12-21 18:33:21 +0100
commita599efa74dd98c70332428b68970ae0e218600da (patch)
treea35fc992f01d1b4f01e3c071a48588c8861154e5 /iptables/nft-cache.c
parent176c92c26bfc9b4a36b99c58b66e117fbe5ae706 (diff)
nft: cache: Sort custom chains by name
With base chains no longer residing in the tables' chain lists, they can easily be sorted upon insertion. This on one hand aligns custom chain ordering with legacy iptables and on the other makes it predictable, which is very helpful when manually comparing ruleset dumps for instance. Adjust the one ebtables-nft test case this change breaks (as wrong ordering is expected in there). The manual output sorting done for tests which apply to legacy as well as nft is removed in a separate patch. Signed-off-by: Phil Sutter <phil@nwl.cc>
Diffstat (limited to 'iptables/nft-cache.c')
-rw-r--r--iptables/nft-cache.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/iptables/nft-cache.c b/iptables/nft-cache.c
index bd19b6df..6b6e6da4 100644
--- a/iptables/nft-cache.c
+++ b/iptables/nft-cache.c
@@ -223,8 +223,19 @@ int nft_cache_add_chain(struct nft_handle *h, const struct builtin_table *t,
h->cache->table[t->type].base_chains[hooknum] = nc;
} else {
- list_add_tail(&nc->head,
- &h->cache->table[t->type].chains->list);
+ struct nft_chain_list *clist = h->cache->table[t->type].chains;
+ struct list_head *pos = &clist->list;
+ struct nft_chain *cur;
+ const char *n;
+
+ list_for_each_entry(cur, &clist->list, head) {
+ n = nftnl_chain_get_str(cur->nftnl, NFTNL_CHAIN_NAME);
+ if (strcmp(cname, n) <= 0) {
+ pos = &cur->head;
+ break;
+ }
+ }
+ list_add_tail(&nc->head, pos);
}
hlist_add_head(&nc->hnode, chain_name_hlist(h, t, cname));
return 0;