From: Phil Sutter <phil@nwl.cc>
To: Pablo Neira Ayuso <pablo@netfilter.org>
Cc: netfilter-devel@vger.kernel.org
Subject: [iptables PATCH v3 7/9] nft: cache: Sort custom chains by name
Date: Thu, 10 Dec 2020 14:06:34 +0100 [thread overview]
Message-ID: <20201210130636.26379-8-phil@nwl.cc> (raw)
In-Reply-To: <20201210130636.26379-1-phil@nwl.cc>
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>
---
iptables/nft-cache.c | 15 +++++++++++++--
.../ebtables/0002-ebtables-save-restore_0 | 2 +-
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/iptables/nft-cache.c b/iptables/nft-cache.c
index bd19b6dfc4d8a..6b6e6da40a826 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;
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.28.0
next prev parent reply other threads:[~2020-12-10 13:07 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-12-10 13:06 [iptables PATCH v3 0/9] nft: Sorted chain listing et al Phil Sutter
2020-12-10 13:06 ` [iptables PATCH v3 1/9] nft: Fix selective chain compatibility checks Phil Sutter
2020-12-10 13:06 ` [iptables PATCH v3 2/9] nft: cache: Introduce nft_cache_add_chain() Phil Sutter
2020-12-10 13:06 ` [iptables PATCH v3 3/9] nft: Implement nft_chain_foreach() Phil Sutter
2020-12-10 13:06 ` [iptables PATCH v3 4/9] nft: cache: Move nft_chain_find() over Phil Sutter
2020-12-10 13:06 ` [iptables PATCH v3 5/9] nft: Introduce struct nft_chain Phil Sutter
2020-12-10 13:06 ` [iptables PATCH v3 6/9] nft: Introduce a dedicated base chain array Phil Sutter
2020-12-10 13:06 ` Phil Sutter [this message]
2020-12-10 13:06 ` [iptables PATCH v3 8/9] tests: shell: Drop any dump sorting in place Phil Sutter
2020-12-10 13:06 ` [iptables PATCH v3 9/9] nft: Avoid pointless table/chain creation Phil Sutter
2020-12-14 13:24 ` [iptables PATCH v3 0/9] nft: Sorted chain listing et al Phil Sutter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20201210130636.26379-8-phil@nwl.cc \
--to=phil@nwl.cc \
--cc=netfilter-devel@vger.kernel.org \
--cc=pablo@netfilter.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).