]> git.ipfire.org Git - thirdparty/iptables.git/commitdiff
xtables: Use new callbacks in nft_rule_print_save()
authorPhil Sutter <phil@nwl.cc>
Thu, 19 Jul 2018 16:31:58 +0000 (18:31 +0200)
committerFlorian Westphal <fw@strlen.de>
Thu, 19 Jul 2018 21:05:56 +0000 (23:05 +0200)
This relieves callers from having to prepare iptables_command_state,
which often happens just for the sake of passing it to this function.

Signed-off-by: Phil Sutter <phil@nwl.cc>
Signed-off-by: Florian Westphal <fw@strlen.de>
iptables/nft-shared.c
iptables/nft.c
iptables/nft.h
iptables/xtables-monitor.c

index 87d48bf620bb5b300e511e8408d065743bbb216c..24287e9762a9a655be6596bd665067c4206ae87a 100644 (file)
@@ -933,7 +933,7 @@ bool nft_ipv46_rule_find(struct nft_family_ops *ops,
 
        DEBUGP("comparing with... ");
 #ifdef DEBUG_DEL
-       nft_rule_print_save(&this, r, NFT_RULE_APPEND, 0);
+       nft_rule_print_save(r, NFT_RULE_APPEND, 0);
 #endif
        if (!ops->is_same(cs, &this))
                return false;
index e1788dbadddd54842bef8cddebc2bf4c324fa57f..0cf325db040cce01774c2f666253e8416e9747e5 100644 (file)
@@ -327,9 +327,7 @@ static int mnl_append_error(const struct nft_handle *h,
                         nftnl_rule_get_str(o->rule, NFTNL_RULE_CHAIN));
 #if 0
                {
-                       struct iptables_command_state cs = {};
-                       nft_rule_to_iptables_command_state(o->rule, &cs);
-                       nft_rule_print_save(&cs, o->rule, NFT_RULE_APPEND, FMT_NOCOUNTS);
+                       nft_rule_print_save(o->rule, NFT_RULE_APPEND, FMT_NOCOUNTS);
                }
 #endif
                break;
@@ -1185,18 +1183,19 @@ nft_rule_append(struct nft_handle *h, const char *chain, const char *table,
 }
 
 void
-nft_rule_print_save(const void *data,
-                   struct nftnl_rule *r, enum nft_rule_print type,
+nft_rule_print_save(const struct nftnl_rule *r, enum nft_rule_print type,
                    unsigned int format)
 {
        const char *chain = nftnl_rule_get_str(r, NFTNL_RULE_CHAIN);
        int family = nftnl_rule_get_u32(r, NFTNL_RULE_FAMILY);
+       struct iptables_command_state cs = {};
        struct nft_family_ops *ops;
 
        ops = nft_family_ops_lookup(family);
+       ops->rule_to_cs(r, &cs);
 
        if (!(format & FMT_NOCOUNTS) && ops->save_counters)
-               ops->save_counters(data);
+               ops->save_counters(&cs);
 
        /* print chain name */
        switch(type) {
@@ -1209,8 +1208,10 @@ nft_rule_print_save(const void *data,
        }
 
        if (ops->save_firewall)
-               ops->save_firewall(data, format);
+               ops->save_firewall(&cs, format);
 
+       if (ops->clear_cs)
+               ops->clear_cs(&cs);
 }
 
 static int nftnl_chain_list_cb(const struct nlmsghdr *nlh, void *data)
@@ -1399,14 +1400,11 @@ int nft_rule_save(struct nft_handle *h, const char *table, bool counters)
        while (r != NULL) {
                const char *rule_table =
                        nftnl_rule_get_str(r, NFTNL_RULE_TABLE);
-               struct iptables_command_state cs = {};
 
                if (strcmp(table, rule_table) != 0)
                        goto next;
 
-               nft_rule_to_iptables_command_state(r, &cs);
-
-               nft_rule_print_save(&cs, r, NFT_RULE_APPEND,
+               nft_rule_print_save(r, NFT_RULE_APPEND,
                                    counters ? 0 : FMT_NOCOUNTS);
 
 next:
@@ -2282,11 +2280,7 @@ err:
 static void
 list_save(struct nftnl_rule *r, unsigned int num, unsigned int format)
 {
-       struct iptables_command_state cs = {};
-
-       nft_rule_to_iptables_command_state(r, &cs);
-
-       nft_rule_print_save(&cs, r, NFT_RULE_APPEND, !(format & FMT_NOCOUNTS));
+       nft_rule_print_save(r, NFT_RULE_APPEND, !(format & FMT_NOCOUNTS));
 }
 
 static int
index ffae84f22008f8c70576637ea2ea6a68f4f9d791..a3f5c202d8f57aa44c6ed5a5cfd1f66bd885a5c2 100644 (file)
@@ -119,8 +119,7 @@ enum nft_rule_print {
        NFT_RULE_DEL,
 };
 
-void nft_rule_print_save(const void *data,
-                        struct nftnl_rule *r, enum nft_rule_print type,
+void nft_rule_print_save(const struct nftnl_rule *r, enum nft_rule_print type,
                         unsigned int format);
 
 uint32_t nft_invflags2cmp(uint32_t invflags, uint32_t flag);
index e491b4db82bd7a2af9f0be3deca9a7034eaf7c1d..a43a69af327e073a77793fc51331fa4fcd1eebb9 100644 (file)
@@ -73,7 +73,6 @@ static bool events;
 
 static int rule_cb(const struct nlmsghdr *nlh, void *data)
 {
-       struct iptables_command_state cs = {};
        uint32_t type = nlh->nlmsg_type & 0xFF;
        const struct cb_arg *arg = data;
        struct nftnl_rule *r;
@@ -96,19 +95,16 @@ static int rule_cb(const struct nlmsghdr *nlh, void *data)
        case AF_INET:
        case AF_INET6:
                printf("-%c ", family == AF_INET ? '4' : '6');
-               nft_rule_to_iptables_command_state(r, &cs);
                break;
        case NFPROTO_ARP:
                printf("-0 ");
-               nft_rule_to_arptables_command_state(r, &cs);
                break;
        default:
                goto err_free;
        }
 
        printf("-t %s ", nftnl_rule_get_str(r, NFTNL_RULE_TABLE));
-       nft_rule_print_save(&cs, r,
-                           type == NFT_MSG_NEWRULE ? NFT_RULE_APPEND :
+       nft_rule_print_save(r, type == NFT_MSG_NEWRULE ? NFT_RULE_APPEND :
                                                           NFT_RULE_DEL,
                            counters ? 0 : FMT_NOCOUNTS);
 err_free: