If nft_handle is available, use its 'ops' field instead of performing a
new lookup. For the same reason, there is no need to pass ops pointer to
__nft_print_header().

Signed-off-by: Phil Sutter <p...@nwl.cc>
---
 iptables/nft.c | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/iptables/nft.c b/iptables/nft.c
index 458dededaca29..28e63aad15878 100644
--- a/iptables/nft.c
+++ b/iptables/nft.c
@@ -1663,11 +1663,8 @@ static const char *policy_name[NF_ACCEPT+1] = {
 int nft_chain_save(struct nft_handle *h, struct nftnl_chain_list *list)
 {
        struct nftnl_chain_list_iter *iter;
-       struct nft_family_ops *ops;
        struct nftnl_chain *c;
 
-       ops = nft_family_ops_lookup(h->family);
-
        iter = nftnl_chain_list_iter_create(list);
        if (iter == NULL)
                return 0;
@@ -1693,8 +1690,8 @@ int nft_chain_save(struct nft_handle *h, struct 
nftnl_chain_list *list)
                        }
                }
 
-               if (ops->save_chain)
-                       ops->save_chain(c, policy);
+               if (h->ops->save_chain)
+                       h->ops->save_chain(c, policy);
 
                c = nftnl_chain_list_iter_next(iter);
        }
@@ -2484,7 +2481,6 @@ static int nft_rule_count(struct nft_handle *h, struct 
nftnl_chain *c)
 }
 
 static void __nft_print_header(struct nft_handle *h,
-                              const struct nft_family_ops *ops,
                               struct nftnl_chain *c, unsigned int format)
 {
        const char *chain_name = nftnl_chain_get_str(c, NFTNL_CHAIN_NAME);
@@ -2500,14 +2496,13 @@ static void __nft_print_header(struct nft_handle *h,
        if (nftnl_chain_is_set(c, NFTNL_CHAIN_POLICY))
                pname = policy_name[nftnl_chain_get_u32(c, NFTNL_CHAIN_POLICY)];
 
-       ops->print_header(format, chain_name, pname,
+       h->ops->print_header(format, chain_name, pname,
                        &ctrs, basechain, refs - entries, entries);
 }
 
 int nft_rule_list(struct nft_handle *h, const char *chain, const char *table,
                  int rulenum, unsigned int format)
 {
-       const struct nft_family_ops *ops;
        struct nftnl_chain_list *list;
        struct nftnl_chain_list_iter *iter;
        struct nftnl_chain *c;
@@ -2515,8 +2510,6 @@ int nft_rule_list(struct nft_handle *h, const char 
*chain, const char *table,
 
        nft_xt_builtin_init(h, table);
 
-       ops = nft_family_ops_lookup(h->family);
-
        if (!nft_is_table_compatible(h, table)) {
                xtables_error(OTHER_PROBLEM, "table `%s' is incompatible, use 
'nft' tool.\n", table);
                return 0;
@@ -2532,11 +2525,11 @@ int nft_rule_list(struct nft_handle *h, const char 
*chain, const char *table,
                        return 0;
 
                if (!rulenum) {
-                       if (ops->print_table_header)
-                               ops->print_table_header(table);
-                       __nft_print_header(h, ops, c, format);
+                       if (h->ops->print_table_header)
+                               h->ops->print_table_header(table);
+                       __nft_print_header(h, c, format);
                }
-               __nft_rule_list(h, c, rulenum, format, ops->print_rule);
+               __nft_rule_list(h, c, rulenum, format, h->ops->print_rule);
                return 1;
        }
 
@@ -2544,16 +2537,16 @@ int nft_rule_list(struct nft_handle *h, const char 
*chain, const char *table,
        if (iter == NULL)
                return 0;
 
-       if (ops->print_table_header)
-               ops->print_table_header(table);
+       if (h->ops->print_table_header)
+               h->ops->print_table_header(table);
 
        c = nftnl_chain_list_iter_next(iter);
        while (c != NULL) {
                if (found)
                        printf("\n");
 
-               __nft_print_header(h, ops, c, format);
-               __nft_rule_list(h, c, rulenum, format, ops->print_rule);
+               __nft_print_header(h, c, format);
+               __nft_rule_list(h, c, rulenum, format, h->ops->print_rule);
 
                found = true;
                c = nftnl_chain_list_iter_next(iter);
-- 
2.22.0

Reply via email to