]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/commitdiff
netfilter: nf_tables: add nft_set_lookup()
authorPablo Neira Ayuso <pablo@netfilter.org>
Mon, 6 Mar 2017 16:46:20 +0000 (17:46 +0100)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 6 Mar 2017 17:23:23 +0000 (18:23 +0100)
This new function consolidates set lookup via either name or ID by
introducing a new nft_set_lookup() function. Replace existing spots
where we can use this too.

Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
include/net/netfilter/nf_tables.h
net/netfilter/nf_tables_api.c
net/netfilter/nft_dynset.c
net/netfilter/nft_lookup.c
net/netfilter/nft_objref.c

index 2aa8a9d80fbe8263a4b0e1c65f44e1ee2d9295d4..f0d46726d06ec7c79f40eede10dd32034662bed8 100644 (file)
@@ -385,10 +385,11 @@ static inline struct nft_set *nft_set_container_of(const void *priv)
        return (void *)priv - offsetof(struct nft_set, data);
 }
 
-struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
-                                    const struct nlattr *nla, u8 genmask);
-struct nft_set *nf_tables_set_lookup_byid(const struct net *net,
-                                         const struct nlattr *nla, u8 genmask);
+struct nft_set *nft_set_lookup(const struct net *net,
+                              const struct nft_table *table,
+                              const struct nlattr *nla_set_name,
+                              const struct nlattr *nla_set_id,
+                              u8 genmask);
 
 static inline unsigned long nft_set_gc_interval(const struct nft_set *set)
 {
index fd8789eccc926a76f4779b1788f4f651382cb3fc..4559f5d66bccf7764ba34add84dd2c96ae08f328 100644 (file)
@@ -2534,8 +2534,8 @@ static int nft_ctx_init_from_setattr(struct nft_ctx *ctx, struct net *net,
        return 0;
 }
 
-struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
-                                    const struct nlattr *nla, u8 genmask)
+static struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
+                                           const struct nlattr *nla, u8 genmask)
 {
        struct nft_set *set;
 
@@ -2549,11 +2549,10 @@ struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
        }
        return ERR_PTR(-ENOENT);
 }
-EXPORT_SYMBOL_GPL(nf_tables_set_lookup);
 
-struct nft_set *nf_tables_set_lookup_byid(const struct net *net,
-                                         const struct nlattr *nla,
-                                         u8 genmask)
+static struct nft_set *nf_tables_set_lookup_byid(const struct net *net,
+                                                const struct nlattr *nla,
+                                                u8 genmask)
 {
        struct nft_trans *trans;
        u32 id = ntohl(nla_get_be32(nla));
@@ -2568,7 +2567,25 @@ struct nft_set *nf_tables_set_lookup_byid(const struct net *net,
        }
        return ERR_PTR(-ENOENT);
 }
-EXPORT_SYMBOL_GPL(nf_tables_set_lookup_byid);
+
+struct nft_set *nft_set_lookup(const struct net *net,
+                              const struct nft_table *table,
+                              const struct nlattr *nla_set_name,
+                              const struct nlattr *nla_set_id,
+                              u8 genmask)
+{
+       struct nft_set *set;
+
+       set = nf_tables_set_lookup(table, nla_set_name, genmask);
+       if (IS_ERR(set)) {
+               if (!nla_set_id)
+                       return set;
+
+               set = nf_tables_set_lookup_byid(net, nla_set_id, genmask);
+       }
+       return set;
+}
+EXPORT_SYMBOL_GPL(nft_set_lookup);
 
 static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,
                                    const char *name)
index 049ad2d9ee66959367a051903563dca6ba654edb..3948da380259538c2fd4823f65a9407241f8af4e 100644 (file)
@@ -133,16 +133,10 @@ static int nft_dynset_init(const struct nft_ctx *ctx,
                        priv->invert = true;
        }
 
-       set = nf_tables_set_lookup(ctx->table, tb[NFTA_DYNSET_SET_NAME],
-                                  genmask);
-       if (IS_ERR(set)) {
-               if (tb[NFTA_DYNSET_SET_ID])
-                       set = nf_tables_set_lookup_byid(ctx->net,
-                                                       tb[NFTA_DYNSET_SET_ID],
-                                                       genmask);
-               if (IS_ERR(set))
-                       return PTR_ERR(set);
-       }
+       set = nft_set_lookup(ctx->net, ctx->table, tb[NFTA_DYNSET_SET_NAME],
+                            tb[NFTA_DYNSET_SET_ID], genmask);
+       if (IS_ERR(set))
+               return PTR_ERR(set);
 
        if (set->ops->update == NULL)
                return -EOPNOTSUPP;
index e21aea7e5ec8f141ea3155d1da3c491484c00a73..475570e89ede710b323868792bb16fd5f09d1b09 100644 (file)
@@ -71,16 +71,10 @@ static int nft_lookup_init(const struct nft_ctx *ctx,
            tb[NFTA_LOOKUP_SREG] == NULL)
                return -EINVAL;
 
-       set = nf_tables_set_lookup(ctx->table, tb[NFTA_LOOKUP_SET], genmask);
-       if (IS_ERR(set)) {
-               if (tb[NFTA_LOOKUP_SET_ID]) {
-                       set = nf_tables_set_lookup_byid(ctx->net,
-                                                       tb[NFTA_LOOKUP_SET_ID],
-                                                       genmask);
-               }
-               if (IS_ERR(set))
-                       return PTR_ERR(set);
-       }
+       set = nft_set_lookup(ctx->net, ctx->table, tb[NFTA_LOOKUP_SET],
+                            tb[NFTA_LOOKUP_SET_ID], genmask);
+       if (IS_ERR(set))
+               return PTR_ERR(set);
 
        if (set->flags & NFT_SET_EVAL)
                return -EOPNOTSUPP;
index 1ae8c49ca4a1fac06f69c41f68a36b7e85593adb..1dd428fbaaa3f836e7bcecb50355f60c14d8faad 100644 (file)
@@ -116,16 +116,10 @@ static int nft_objref_map_init(const struct nft_ctx *ctx,
        struct nft_set *set;
        int err;
 
-       set = nf_tables_set_lookup(ctx->table, tb[NFTA_OBJREF_SET_NAME], genmask);
-       if (IS_ERR(set)) {
-               if (tb[NFTA_OBJREF_SET_ID]) {
-                       set = nf_tables_set_lookup_byid(ctx->net,
-                                                       tb[NFTA_OBJREF_SET_ID],
-                                                       genmask);
-               }
-               if (IS_ERR(set))
-                       return PTR_ERR(set);
-       }
+       set = nft_set_lookup(ctx->net, ctx->table, tb[NFTA_OBJREF_SET_NAME],
+                            tb[NFTA_OBJREF_SET_ID], genmask);
+       if (IS_ERR(set))
+               return PTR_ERR(set);
 
        if (!(set->flags & NFT_SET_OBJECT))
                return -EINVAL;