]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
nft: family_ops: Pass nft_handle to 'add' callback
authorPhil Sutter <phil@nwl.cc>
Tue, 20 Aug 2019 13:15:19 +0000 (15:15 +0200)
committerPhil Sutter <phil@nwl.cc>
Mon, 25 Nov 2019 22:30:40 +0000 (23:30 +0100)
In order for add_match() to create anonymous sets when converting
xtables matches it needs access to nft handle. So pass it along from
callers of family ops' add callback.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>
iptables/nft-arp.c
iptables/nft-bridge.c
iptables/nft-ipv4.c
iptables/nft-ipv6.c
iptables/nft-shared.h
iptables/nft.c
iptables/nft.h

index 7068f82c5495adebd6672af0ef2ff53a10d389c4..de7743392afa1c675e42993b85e73b03a930f423 100644 (file)
@@ -126,7 +126,7 @@ static bool need_devaddr(struct arpt_devaddr_info *info)
        return false;
 }
 
-static int nft_arp_add(struct nftnl_rule *r, void *data)
+static int nft_arp_add(struct nft_handle *h, struct nftnl_rule *r, void *data)
 {
        struct iptables_command_state *cs = data;
        struct arpt_entry *fw = &cs->arp;
index 2e4b309b86135946b36611c34e2efe69b7883fde..0fc21b3a3c0d6b5304a1aa5b07fae0100fdacd56 100644 (file)
@@ -126,7 +126,8 @@ static int _add_action(struct nftnl_rule *r, struct iptables_command_state *cs)
        return add_action(r, cs, false);
 }
 
-static int nft_bridge_add(struct nftnl_rule *r, void *data)
+static int nft_bridge_add(struct nft_handle *h,
+                         struct nftnl_rule *r, void *data)
 {
        struct iptables_command_state *cs = data;
        struct ebt_match *iter;
@@ -182,7 +183,7 @@ static int nft_bridge_add(struct nftnl_rule *r, void *data)
 
        for (iter = cs->match_list; iter; iter = iter->next) {
                if (iter->ismatch) {
-                       if (add_match(r, iter->u.match->m))
+                       if (add_match(h, r, iter->u.match->m))
                                break;
                } else {
                        if (add_target(r, iter->u.watcher->t))
index 4497eb9b9347c4ba18a7f32ec78d9c62f9201a09..57d1b3c6d2d0c91876d49302b33f7420b54c3d5b 100644 (file)
@@ -26,7 +26,7 @@
 #include "nft.h"
 #include "nft-shared.h"
 
-static int nft_ipv4_add(struct nftnl_rule *r, void *data)
+static int nft_ipv4_add(struct nft_handle *h, struct nftnl_rule *r, void *data)
 {
        struct iptables_command_state *cs = data;
        struct xtables_rule_match *matchp;
@@ -77,7 +77,7 @@ static int nft_ipv4_add(struct nftnl_rule *r, void *data)
        add_compat(r, cs->fw.ip.proto, cs->fw.ip.invflags & XT_INV_PROTO);
 
        for (matchp = cs->matches; matchp; matchp = matchp->next) {
-               ret = add_match(r, matchp->match->m);
+               ret = add_match(h, r, matchp->match->m);
                if (ret < 0)
                        return ret;
        }
index cacb1c9e141f27c3840d3e34ddcf0c34215175c0..0e2c4a2946e256339b32514ec8a18332855bbd1e 100644 (file)
@@ -25,7 +25,7 @@
 #include "nft.h"
 #include "nft-shared.h"
 
-static int nft_ipv6_add(struct nftnl_rule *r, void *data)
+static int nft_ipv6_add(struct nft_handle *h, struct nftnl_rule *r, void *data)
 {
        struct iptables_command_state *cs = data;
        struct xtables_rule_match *matchp;
@@ -66,7 +66,7 @@ static int nft_ipv6_add(struct nftnl_rule *r, void *data)
        add_compat(r, cs->fw6.ipv6.proto, cs->fw6.ipv6.invflags & XT_INV_PROTO);
 
        for (matchp = cs->matches; matchp; matchp = matchp->next) {
-               ret = add_match(r, matchp->match->m);
+               ret = add_match(h, r, matchp->match->m);
                if (ret < 0)
                        return ret;
        }
index 4ca551bddc081658df7ebb4a6d4143f6d209e776..1cb2ea70a409f5665f0c069cbed38b7a41dc2cf5 100644 (file)
@@ -35,6 +35,7 @@
 #define FMT(tab,notab) ((format) & FMT_NOTABLE ? (notab) : (tab))
 
 struct xtables_args;
+struct nft_handle;
 struct xt_xlate;
 
 enum {
@@ -69,7 +70,7 @@ struct nft_xt_ctx {
 };
 
 struct nft_family_ops {
-       int (*add)(struct nftnl_rule *r, void *data);
+       int (*add)(struct nft_handle *h, struct nftnl_rule *r, void *data);
        bool (*is_same)(const void *data_a,
                        const void *data_b);
        void (*print_payload)(struct nftnl_expr *e,
@@ -163,7 +164,6 @@ void save_matches_and_target(const struct iptables_command_state *cs,
 
 struct nft_family_ops *nft_family_ops_lookup(int family);
 
-struct nft_handle;
 void nft_ipv46_parse_target(struct xtables_target *t, void *data);
 bool nft_ipv46_rule_find(struct nft_family_ops *ops, struct nftnl_rule *r,
                         void *data);
index 599c2f7e4c08762fb0887edd42aa94c29bf6860c..e31f28347cbad9606c2dbe653ecc16e23dcb76fd 100644 (file)
@@ -930,7 +930,8 @@ static int add_nft_limit(struct nftnl_rule *r, struct xt_entry_match *m)
        return 0;
 }
 
-int add_match(struct nftnl_rule *r, struct xt_entry_match *m)
+int add_match(struct nft_handle *h,
+             struct nftnl_rule *r, struct xt_entry_match *m)
 {
        struct nftnl_expr *expr;
        int ret;
@@ -1152,7 +1153,7 @@ nft_rule_new(struct nft_handle *h, const char *chain, const char *table,
        nftnl_rule_set_str(r, NFTNL_RULE_TABLE, table);
        nftnl_rule_set_str(r, NFTNL_RULE_CHAIN, chain);
 
-       if (h->ops->add(r, data) < 0)
+       if (h->ops->add(h, r, data) < 0)
                goto err;
 
        return r;
index 4b8b3033a56c0d4d4bc5478f37cd228b83c6a790..94dc72d88b7db87779600dd250ebd38798df76a9 100644 (file)
@@ -135,7 +135,7 @@ int nft_rule_zero_counters(struct nft_handle *h, const char *chain, const char *
  */
 int add_counters(struct nftnl_rule *r, uint64_t packets, uint64_t bytes);
 int add_verdict(struct nftnl_rule *r, int verdict);
-int add_match(struct nftnl_rule *r, struct xt_entry_match *m);
+int add_match(struct nft_handle *h, struct nftnl_rule *r, struct xt_entry_match *m);
 int add_target(struct nftnl_rule *r, struct xt_entry_target *t);
 int add_jumpto(struct nftnl_rule *r, const char *name, int verdict);
 int add_action(struct nftnl_rule *r, struct iptables_command_state *cs, bool goto_set);