diff mbox series

[libnftnl] src: chain: Fix nftnl_chain_rule_insert_at()

Message ID 20190114164250.2035-1-phil@nwl.cc
State Accepted
Delegated to: Pablo Neira
Headers show
Series [libnftnl] src: chain: Fix nftnl_chain_rule_insert_at() | expand

Commit Message

Phil Sutter Jan. 14, 2019, 4:42 p.m. UTC
Extrapolating from iptables nomenclature, one would expect that "insert"
means to prepend the new item to the referenced one, not append. Change
nftnl_chain_rule_insert_at() to do just that and introduce
nftnl_chain_rule_append_at() to insert a rule after the referenced one.

Signed-off-by: Phil Sutter <phil@nwl.cc>
---
Given that per chain rule API has not yet made it into a release, I
guess we can still do that. If not, please feel free to reject and I'll
add two symbols with new names for insert/append operations and leave
the existing code alone.
---
 include/libnftnl/chain.h | 1 +
 src/chain.c              | 6 ++++++
 src/libnftnl.map         | 1 +
 3 files changed, 8 insertions(+)

Comments

Pablo Neira Ayuso Jan. 14, 2019, 9:36 p.m. UTC | #1
On Mon, Jan 14, 2019 at 05:42:50PM +0100, Phil Sutter wrote:
> Extrapolating from iptables nomenclature, one would expect that "insert"
> means to prepend the new item to the referenced one, not append. Change
> nftnl_chain_rule_insert_at() to do just that and introduce
> nftnl_chain_rule_append_at() to insert a rule after the referenced one.
> 
> Signed-off-by: Phil Sutter <phil@nwl.cc>
> ---
> Given that per chain rule API has not yet made it into a release, I
> guess we can still do that. If not, please feel free to reject and I'll
> add two symbols with new names for insert/append operations and leave
> the existing code alone.

Thanks fine. Applied, thanks.
diff mbox series

Patch

diff --git a/include/libnftnl/chain.h b/include/libnftnl/chain.h
index 163a824c457c2..31b48cf32bed8 100644
--- a/include/libnftnl/chain.h
+++ b/include/libnftnl/chain.h
@@ -59,6 +59,7 @@  void nftnl_chain_rule_add(struct nftnl_rule *rule, struct nftnl_chain *c);
 void nftnl_chain_rule_del(struct nftnl_rule *rule);
 void nftnl_chain_rule_add_tail(struct nftnl_rule *rule, struct nftnl_chain *c);
 void nftnl_chain_rule_insert_at(struct nftnl_rule *rule, struct nftnl_rule *pos);
+void nftnl_chain_rule_append_at(struct nftnl_rule *rule, struct nftnl_rule *pos);
 
 struct nlmsghdr;
 
diff --git a/src/chain.c b/src/chain.c
index 5f8eb5ca93e95..26f9b9d61053a 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -443,6 +443,12 @@  void nftnl_chain_rule_add_tail(struct nftnl_rule *rule, struct nftnl_chain *c)
 
 EXPORT_SYMBOL(nftnl_chain_rule_insert_at);
 void nftnl_chain_rule_insert_at(struct nftnl_rule *rule, struct nftnl_rule *pos)
+{
+	list_add_tail(&rule->head, &pos->head);
+}
+
+EXPORT_SYMBOL(nftnl_chain_rule_append_at);
+void nftnl_chain_rule_append_at(struct nftnl_rule *rule, struct nftnl_rule *pos)
 {
 	list_add(&rule->head, &pos->head);
 }
diff --git a/src/libnftnl.map b/src/libnftnl.map
index 0d3be32263eee..695b40ea920b5 100644
--- a/src/libnftnl.map
+++ b/src/libnftnl.map
@@ -341,6 +341,7 @@  LIBNFTNL_12 {
   nftnl_chain_rule_add;
   nftnl_chain_rule_add_tail;
   nftnl_chain_rule_insert_at;
+  nftnl_chain_rule_append_at;
   nftnl_rule_foreach;
   nftnl_rule_iter_create;
   nftnl_rule_iter_next;