]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
nft: Add potentially missing init_cs calls
authorPhil Sutter <phil@nwl.cc>
Sat, 27 Jul 2024 13:08:08 +0000 (15:08 +0200)
committerPhil Sutter <phil@nwl.cc>
Wed, 31 Jul 2024 21:13:55 +0000 (23:13 +0200)
The callback is there for arptables only, so other family specific code
does not need it. Not calling it from family-agnostic code is wrong
though, as is ignoring it in arptables-specific code.

Fixes: cfdda18044d81 ("nft-shared: Introduce init_cs family ops callback")
Signed-off-by: Phil Sutter <phil@nwl.cc>
iptables/nft-arp.c
iptables/nft.c

index 5d66e271720ecd4f3093dcd7d01207dfd5e26003..2784f12ae33a90cab11b0208809c14818121e30d 100644 (file)
@@ -356,6 +356,8 @@ nft_arp_save_rule(const struct iptables_command_state *cs, unsigned int format)
        printf("\n");
 }
 
+static void nft_arp_init_cs(struct iptables_command_state *cs);
+
 static void
 nft_arp_print_rule(struct nft_handle *h, struct nftnl_rule *r,
                   unsigned int num, unsigned int format)
@@ -365,6 +367,7 @@ nft_arp_print_rule(struct nft_handle *h, struct nftnl_rule *r,
        if (format & FMT_LINENUMBERS)
                printf("%u ", num);
 
+       nft_arp_init_cs(&cs);
        nft_rule_to_iptables_command_state(h, r, &cs);
 
        nft_arp_print_rule_details(&cs, format);
index 243b794f3d826c42c55611e6fd1b4b85b26eb355..8b1803181b207969ca5efcb82215233ec020c878 100644 (file)
@@ -1797,6 +1797,8 @@ nft_rule_print_save(struct nft_handle *h, const struct nftnl_rule *r,
        struct nft_family_ops *ops = h->ops;
        bool ret;
 
+       if (ops->init_cs)
+               ops->init_cs(&cs);
        ret = ops->rule_to_cs(h, r, &cs);
 
        if (!(format & (FMT_NOCOUNTS | FMT_C_COUNTS)))
@@ -2395,6 +2397,11 @@ static bool nft_rule_cmp(struct nft_handle *h, struct nftnl_rule *r,
        struct iptables_command_state _cs = {}, this = {}, *cs = &_cs;
        bool ret = false, ret_this, ret_that;
 
+       if (h->ops->init_cs) {
+               h->ops->init_cs(&this);
+               h->ops->init_cs(cs);
+       }
+
        ret_this = h->ops->rule_to_cs(h, r, &this);
        ret_that = h->ops->rule_to_cs(h, rule, cs);
 
@@ -2679,6 +2686,8 @@ static int nft_rule_change_counters(struct nft_handle *h, const char *table,
                (unsigned long long)
                nftnl_rule_get_u64(r, NFTNL_RULE_HANDLE));
 
+       if (h->ops->init_cs)
+               h->ops->init_cs(&cs);
        h->ops->rule_to_cs(h, r, &cs);
 
        if (counter_op & CTR_OP_INC_PKTS)
@@ -2976,6 +2985,8 @@ int nft_rule_zero_counters(struct nft_handle *h, const char *chain,
                goto error;
        }
 
+       if (h->ops->init_cs)
+               h->ops->init_cs(&cs);
        h->ops->rule_to_cs(h, r, &cs);
        cs.counters.pcnt = cs.counters.bcnt = 0;
        new_rule = nft_rule_new(h, &ctx, chain, table, &cs);