Commit c7a72e3f authored by Pablo Neira Ayuso's avatar Pablo Neira Ayuso

netfilter: nf_tables: add nft_set_lookup()

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: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent c56e3956
...@@ -385,10 +385,11 @@ static inline struct nft_set *nft_set_container_of(const void *priv) ...@@ -385,10 +385,11 @@ static inline struct nft_set *nft_set_container_of(const void *priv)
return (void *)priv - offsetof(struct nft_set, data); return (void *)priv - offsetof(struct nft_set, data);
} }
struct nft_set *nf_tables_set_lookup(const struct nft_table *table, struct nft_set *nft_set_lookup(const struct net *net,
const struct nlattr *nla, u8 genmask); const struct nft_table *table,
struct nft_set *nf_tables_set_lookup_byid(const struct net *net, const struct nlattr *nla_set_name,
const struct nlattr *nla, u8 genmask); const struct nlattr *nla_set_id,
u8 genmask);
static inline unsigned long nft_set_gc_interval(const struct nft_set *set) static inline unsigned long nft_set_gc_interval(const struct nft_set *set)
{ {
......
...@@ -2534,8 +2534,8 @@ static int nft_ctx_init_from_setattr(struct nft_ctx *ctx, struct net *net, ...@@ -2534,8 +2534,8 @@ static int nft_ctx_init_from_setattr(struct nft_ctx *ctx, struct net *net,
return 0; return 0;
} }
struct nft_set *nf_tables_set_lookup(const struct nft_table *table, static struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
const struct nlattr *nla, u8 genmask) const struct nlattr *nla, u8 genmask)
{ {
struct nft_set *set; struct nft_set *set;
...@@ -2549,11 +2549,10 @@ struct nft_set *nf_tables_set_lookup(const struct nft_table *table, ...@@ -2549,11 +2549,10 @@ struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
} }
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
EXPORT_SYMBOL_GPL(nf_tables_set_lookup);
struct nft_set *nf_tables_set_lookup_byid(const struct net *net, static struct nft_set *nf_tables_set_lookup_byid(const struct net *net,
const struct nlattr *nla, const struct nlattr *nla,
u8 genmask) u8 genmask)
{ {
struct nft_trans *trans; struct nft_trans *trans;
u32 id = ntohl(nla_get_be32(nla)); u32 id = ntohl(nla_get_be32(nla));
...@@ -2568,7 +2567,25 @@ struct nft_set *nf_tables_set_lookup_byid(const struct net *net, ...@@ -2568,7 +2567,25 @@ struct nft_set *nf_tables_set_lookup_byid(const struct net *net,
} }
return ERR_PTR(-ENOENT); 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, static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,
const char *name) const char *name)
......
...@@ -133,16 +133,10 @@ static int nft_dynset_init(const struct nft_ctx *ctx, ...@@ -133,16 +133,10 @@ static int nft_dynset_init(const struct nft_ctx *ctx,
priv->invert = true; priv->invert = true;
} }
set = nf_tables_set_lookup(ctx->table, tb[NFTA_DYNSET_SET_NAME], set = nft_set_lookup(ctx->net, ctx->table, tb[NFTA_DYNSET_SET_NAME],
genmask); tb[NFTA_DYNSET_SET_ID], genmask);
if (IS_ERR(set)) { if (IS_ERR(set))
if (tb[NFTA_DYNSET_SET_ID]) return PTR_ERR(set);
set = nf_tables_set_lookup_byid(ctx->net,
tb[NFTA_DYNSET_SET_ID],
genmask);
if (IS_ERR(set))
return PTR_ERR(set);
}
if (set->ops->update == NULL) if (set->ops->update == NULL)
return -EOPNOTSUPP; return -EOPNOTSUPP;
......
...@@ -71,16 +71,10 @@ static int nft_lookup_init(const struct nft_ctx *ctx, ...@@ -71,16 +71,10 @@ static int nft_lookup_init(const struct nft_ctx *ctx,
tb[NFTA_LOOKUP_SREG] == NULL) tb[NFTA_LOOKUP_SREG] == NULL)
return -EINVAL; return -EINVAL;
set = nf_tables_set_lookup(ctx->table, tb[NFTA_LOOKUP_SET], genmask); set = nft_set_lookup(ctx->net, ctx->table, tb[NFTA_LOOKUP_SET],
if (IS_ERR(set)) { tb[NFTA_LOOKUP_SET_ID], genmask);
if (tb[NFTA_LOOKUP_SET_ID]) { if (IS_ERR(set))
set = nf_tables_set_lookup_byid(ctx->net, return PTR_ERR(set);
tb[NFTA_LOOKUP_SET_ID],
genmask);
}
if (IS_ERR(set))
return PTR_ERR(set);
}
if (set->flags & NFT_SET_EVAL) if (set->flags & NFT_SET_EVAL)
return -EOPNOTSUPP; return -EOPNOTSUPP;
......
...@@ -116,16 +116,10 @@ static int nft_objref_map_init(const struct nft_ctx *ctx, ...@@ -116,16 +116,10 @@ static int nft_objref_map_init(const struct nft_ctx *ctx,
struct nft_set *set; struct nft_set *set;
int err; int err;
set = nf_tables_set_lookup(ctx->table, tb[NFTA_OBJREF_SET_NAME], genmask); set = nft_set_lookup(ctx->net, ctx->table, tb[NFTA_OBJREF_SET_NAME],
if (IS_ERR(set)) { tb[NFTA_OBJREF_SET_ID], genmask);
if (tb[NFTA_OBJREF_SET_ID]) { if (IS_ERR(set))
set = nf_tables_set_lookup_byid(ctx->net, return PTR_ERR(set);
tb[NFTA_OBJREF_SET_ID],
genmask);
}
if (IS_ERR(set))
return PTR_ERR(set);
}
if (!(set->flags & NFT_SET_OBJECT)) if (!(set->flags & NFT_SET_OBJECT))
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment