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

netfilter: nf_tables: simplify lookup functions

Replace the nf_tables_ prefix by nft_ and merge code into single lookup
function whenever possible. In many cases we go over the 80-chars
boundary function names, this save us ~50 LoC.
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent df1e2025
...@@ -1015,7 +1015,7 @@ static inline void *nft_obj_data(const struct nft_object *obj) ...@@ -1015,7 +1015,7 @@ static inline void *nft_obj_data(const struct nft_object *obj)
#define nft_expr_obj(expr) *((struct nft_object **)nft_expr_priv(expr)) #define nft_expr_obj(expr) *((struct nft_object **)nft_expr_priv(expr))
struct nft_object *nf_tables_obj_lookup(const struct nft_table *table, struct nft_object *nft_obj_lookup(const struct nft_table *table,
const struct nlattr *nla, u32 objtype, const struct nlattr *nla, u32 objtype,
u8 genmask); u8 genmask);
...@@ -1106,7 +1106,7 @@ struct nft_flowtable { ...@@ -1106,7 +1106,7 @@ struct nft_flowtable {
struct nf_flowtable data; struct nf_flowtable data;
}; };
struct nft_flowtable *nf_tables_flowtable_lookup(const struct nft_table *table, struct nft_flowtable *nft_flowtable_lookup(const struct nft_table *table,
const struct nlattr *nla, const struct nlattr *nla,
u8 genmask); u8 genmask);
......
...@@ -386,13 +386,17 @@ static struct nft_table *nft_table_lookup(const struct net *net, ...@@ -386,13 +386,17 @@ static struct nft_table *nft_table_lookup(const struct net *net,
{ {
struct nft_table *table; struct nft_table *table;
if (nla == NULL)
return ERR_PTR(-EINVAL);
list_for_each_entry(table, &net->nft.tables, list) { list_for_each_entry(table, &net->nft.tables, list) {
if (!nla_strcmp(nla, table->name) && if (!nla_strcmp(nla, table->name) &&
table->family == family && table->family == family &&
nft_active_genmask(table, genmask)) nft_active_genmask(table, genmask))
return table; return table;
} }
return NULL;
return ERR_PTR(-ENOENT);
} }
static struct nft_table *nft_table_lookup_byhandle(const struct net *net, static struct nft_table *nft_table_lookup_byhandle(const struct net *net,
...@@ -406,37 +410,6 @@ static struct nft_table *nft_table_lookup_byhandle(const struct net *net, ...@@ -406,37 +410,6 @@ static struct nft_table *nft_table_lookup_byhandle(const struct net *net,
nft_active_genmask(table, genmask)) nft_active_genmask(table, genmask))
return table; return table;
} }
return NULL;
}
static struct nft_table *nf_tables_table_lookup(const struct net *net,
const struct nlattr *nla,
u8 family, u8 genmask)
{
struct nft_table *table;
if (nla == NULL)
return ERR_PTR(-EINVAL);
table = nft_table_lookup(net, nla, family, genmask);
if (table != NULL)
return table;
return ERR_PTR(-ENOENT);
}
static struct nft_table *nf_tables_table_lookup_byhandle(const struct net *net,
const struct nlattr *nla,
u8 genmask)
{
struct nft_table *table;
if (nla == NULL)
return ERR_PTR(-EINVAL);
table = nft_table_lookup_byhandle(net, nla, genmask);
if (table != NULL)
return table;
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
...@@ -608,8 +581,7 @@ static int nf_tables_gettable(struct net *net, struct sock *nlsk, ...@@ -608,8 +581,7 @@ static int nf_tables_gettable(struct net *net, struct sock *nlsk,
return netlink_dump_start(nlsk, skb, nlh, &c); return netlink_dump_start(nlsk, skb, nlh, &c);
} }
table = nf_tables_table_lookup(net, nla[NFTA_TABLE_NAME], family, table = nft_table_lookup(net, nla[NFTA_TABLE_NAME], family, genmask);
genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
...@@ -735,7 +707,7 @@ static int nf_tables_newtable(struct net *net, struct sock *nlsk, ...@@ -735,7 +707,7 @@ static int nf_tables_newtable(struct net *net, struct sock *nlsk,
int err; int err;
name = nla[NFTA_TABLE_NAME]; name = nla[NFTA_TABLE_NAME];
table = nf_tables_table_lookup(net, name, family, genmask); table = nft_table_lookup(net, name, family, genmask);
if (IS_ERR(table)) { if (IS_ERR(table)) {
if (PTR_ERR(table) != -ENOENT) if (PTR_ERR(table) != -ENOENT)
return PTR_ERR(table); return PTR_ERR(table);
...@@ -893,12 +865,11 @@ static int nf_tables_deltable(struct net *net, struct sock *nlsk, ...@@ -893,12 +865,11 @@ static int nf_tables_deltable(struct net *net, struct sock *nlsk,
return nft_flush(&ctx, family); return nft_flush(&ctx, family);
if (nla[NFTA_TABLE_HANDLE]) if (nla[NFTA_TABLE_HANDLE])
table = nf_tables_table_lookup_byhandle(net, table = nft_table_lookup_byhandle(net, nla[NFTA_TABLE_HANDLE],
nla[NFTA_TABLE_HANDLE],
genmask); genmask);
else else
table = nf_tables_table_lookup(net, nla[NFTA_TABLE_NAME], table = nft_table_lookup(net, nla[NFTA_TABLE_NAME], family,
family, genmask); genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
...@@ -949,8 +920,7 @@ EXPORT_SYMBOL_GPL(nft_unregister_chain_type); ...@@ -949,8 +920,7 @@ EXPORT_SYMBOL_GPL(nft_unregister_chain_type);
*/ */
static struct nft_chain * static struct nft_chain *
nf_tables_chain_lookup_byhandle(const struct nft_table *table, u64 handle, nft_chain_lookup_byhandle(const struct nft_table *table, u64 handle, u8 genmask)
u8 genmask)
{ {
struct nft_chain *chain; struct nft_chain *chain;
...@@ -963,9 +933,8 @@ nf_tables_chain_lookup_byhandle(const struct nft_table *table, u64 handle, ...@@ -963,9 +933,8 @@ nf_tables_chain_lookup_byhandle(const struct nft_table *table, u64 handle,
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
static struct nft_chain *nf_tables_chain_lookup(const struct nft_table *table, static struct nft_chain *nft_chain_lookup(const struct nft_table *table,
const struct nlattr *nla, const struct nlattr *nla, u8 genmask)
u8 genmask)
{ {
struct nft_chain *chain; struct nft_chain *chain;
...@@ -1194,12 +1163,11 @@ static int nf_tables_getchain(struct net *net, struct sock *nlsk, ...@@ -1194,12 +1163,11 @@ static int nf_tables_getchain(struct net *net, struct sock *nlsk,
return netlink_dump_start(nlsk, skb, nlh, &c); return netlink_dump_start(nlsk, skb, nlh, &c);
} }
table = nf_tables_table_lookup(net, nla[NFTA_CHAIN_TABLE], family, table = nft_table_lookup(net, nla[NFTA_CHAIN_TABLE], family, genmask);
genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
chain = nf_tables_chain_lookup(table, nla[NFTA_CHAIN_NAME], genmask); chain = nft_chain_lookup(table, nla[NFTA_CHAIN_NAME], genmask);
if (IS_ERR(chain)) if (IS_ERR(chain))
return PTR_ERR(chain); return PTR_ERR(chain);
...@@ -1513,8 +1481,7 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy, ...@@ -1513,8 +1481,7 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy,
nla[NFTA_CHAIN_NAME]) { nla[NFTA_CHAIN_NAME]) {
struct nft_chain *chain2; struct nft_chain *chain2;
chain2 = nf_tables_chain_lookup(table, nla[NFTA_CHAIN_NAME], chain2 = nft_chain_lookup(table, nla[NFTA_CHAIN_NAME], genmask);
genmask);
if (!IS_ERR(chain2)) if (!IS_ERR(chain2))
return -EEXIST; return -EEXIST;
} }
...@@ -1576,8 +1543,7 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk, ...@@ -1576,8 +1543,7 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,
create = nlh->nlmsg_flags & NLM_F_CREATE ? true : false; create = nlh->nlmsg_flags & NLM_F_CREATE ? true : false;
table = nf_tables_table_lookup(net, nla[NFTA_CHAIN_TABLE], family, table = nft_table_lookup(net, nla[NFTA_CHAIN_TABLE], family, genmask);
genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
...@@ -1586,11 +1552,11 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk, ...@@ -1586,11 +1552,11 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,
if (nla[NFTA_CHAIN_HANDLE]) { if (nla[NFTA_CHAIN_HANDLE]) {
handle = be64_to_cpu(nla_get_be64(nla[NFTA_CHAIN_HANDLE])); handle = be64_to_cpu(nla_get_be64(nla[NFTA_CHAIN_HANDLE]));
chain = nf_tables_chain_lookup_byhandle(table, handle, genmask); chain = nft_chain_lookup_byhandle(table, handle, genmask);
if (IS_ERR(chain)) if (IS_ERR(chain))
return PTR_ERR(chain); return PTR_ERR(chain);
} else { } else {
chain = nf_tables_chain_lookup(table, name, genmask); chain = nft_chain_lookup(table, name, genmask);
if (IS_ERR(chain)) { if (IS_ERR(chain)) {
if (PTR_ERR(chain) != -ENOENT) if (PTR_ERR(chain) != -ENOENT)
return PTR_ERR(chain); return PTR_ERR(chain);
...@@ -1647,16 +1613,15 @@ static int nf_tables_delchain(struct net *net, struct sock *nlsk, ...@@ -1647,16 +1613,15 @@ static int nf_tables_delchain(struct net *net, struct sock *nlsk,
u32 use; u32 use;
int err; int err;
table = nf_tables_table_lookup(net, nla[NFTA_CHAIN_TABLE], family, table = nft_table_lookup(net, nla[NFTA_CHAIN_TABLE], family, genmask);
genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
if (nla[NFTA_CHAIN_HANDLE]) { if (nla[NFTA_CHAIN_HANDLE]) {
handle = be64_to_cpu(nla_get_be64(nla[NFTA_CHAIN_HANDLE])); handle = be64_to_cpu(nla_get_be64(nla[NFTA_CHAIN_HANDLE]));
chain = nf_tables_chain_lookup_byhandle(table, handle, genmask); chain = nft_chain_lookup_byhandle(table, handle, genmask);
} else { } else {
chain = nf_tables_chain_lookup(table, nla[NFTA_CHAIN_NAME], genmask); chain = nft_chain_lookup(table, nla[NFTA_CHAIN_NAME], genmask);
} }
if (IS_ERR(chain)) if (IS_ERR(chain))
return PTR_ERR(chain); return PTR_ERR(chain);
...@@ -1939,7 +1904,7 @@ void nft_expr_destroy(const struct nft_ctx *ctx, struct nft_expr *expr) ...@@ -1939,7 +1904,7 @@ void nft_expr_destroy(const struct nft_ctx *ctx, struct nft_expr *expr)
* Rules * Rules
*/ */
static struct nft_rule *__nf_tables_rule_lookup(const struct nft_chain *chain, static struct nft_rule *__nft_rule_lookup(const struct nft_chain *chain,
u64 handle) u64 handle)
{ {
struct nft_rule *rule; struct nft_rule *rule;
...@@ -1953,13 +1918,13 @@ static struct nft_rule *__nf_tables_rule_lookup(const struct nft_chain *chain, ...@@ -1953,13 +1918,13 @@ static struct nft_rule *__nf_tables_rule_lookup(const struct nft_chain *chain,
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
static struct nft_rule *nf_tables_rule_lookup(const struct nft_chain *chain, static struct nft_rule *nft_rule_lookup(const struct nft_chain *chain,
const struct nlattr *nla) const struct nlattr *nla)
{ {
if (nla == NULL) if (nla == NULL)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
return __nf_tables_rule_lookup(chain, be64_to_cpu(nla_get_be64(nla))); return __nft_rule_lookup(chain, be64_to_cpu(nla_get_be64(nla)));
} }
static const struct nla_policy nft_rule_policy[NFTA_RULE_MAX + 1] = { static const struct nla_policy nft_rule_policy[NFTA_RULE_MAX + 1] = {
...@@ -2191,16 +2156,15 @@ static int nf_tables_getrule(struct net *net, struct sock *nlsk, ...@@ -2191,16 +2156,15 @@ static int nf_tables_getrule(struct net *net, struct sock *nlsk,
return netlink_dump_start(nlsk, skb, nlh, &c); return netlink_dump_start(nlsk, skb, nlh, &c);
} }
table = nf_tables_table_lookup(net, nla[NFTA_RULE_TABLE], family, table = nft_table_lookup(net, nla[NFTA_RULE_TABLE], family, genmask);
genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
chain = nf_tables_chain_lookup(table, nla[NFTA_RULE_CHAIN], genmask); chain = nft_chain_lookup(table, nla[NFTA_RULE_CHAIN], genmask);
if (IS_ERR(chain)) if (IS_ERR(chain))
return PTR_ERR(chain); return PTR_ERR(chain);
rule = nf_tables_rule_lookup(chain, nla[NFTA_RULE_HANDLE]); rule = nft_rule_lookup(chain, nla[NFTA_RULE_HANDLE]);
if (IS_ERR(rule)) if (IS_ERR(rule))
return PTR_ERR(rule); return PTR_ERR(rule);
...@@ -2265,18 +2229,17 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk, ...@@ -2265,18 +2229,17 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
create = nlh->nlmsg_flags & NLM_F_CREATE ? true : false; create = nlh->nlmsg_flags & NLM_F_CREATE ? true : false;
table = nf_tables_table_lookup(net, nla[NFTA_RULE_TABLE], family, table = nft_table_lookup(net, nla[NFTA_RULE_TABLE], family, genmask);
genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
chain = nf_tables_chain_lookup(table, nla[NFTA_RULE_CHAIN], genmask); chain = nft_chain_lookup(table, nla[NFTA_RULE_CHAIN], genmask);
if (IS_ERR(chain)) if (IS_ERR(chain))
return PTR_ERR(chain); return PTR_ERR(chain);
if (nla[NFTA_RULE_HANDLE]) { if (nla[NFTA_RULE_HANDLE]) {
handle = be64_to_cpu(nla_get_be64(nla[NFTA_RULE_HANDLE])); handle = be64_to_cpu(nla_get_be64(nla[NFTA_RULE_HANDLE]));
rule = __nf_tables_rule_lookup(chain, handle); rule = __nft_rule_lookup(chain, handle);
if (IS_ERR(rule)) if (IS_ERR(rule))
return PTR_ERR(rule); return PTR_ERR(rule);
...@@ -2300,7 +2263,7 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk, ...@@ -2300,7 +2263,7 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
return -EOPNOTSUPP; return -EOPNOTSUPP;
pos_handle = be64_to_cpu(nla_get_be64(nla[NFTA_RULE_POSITION])); pos_handle = be64_to_cpu(nla_get_be64(nla[NFTA_RULE_POSITION]));
old_rule = __nf_tables_rule_lookup(chain, pos_handle); old_rule = __nft_rule_lookup(chain, pos_handle);
if (IS_ERR(old_rule)) if (IS_ERR(old_rule))
return PTR_ERR(old_rule); return PTR_ERR(old_rule);
} }
...@@ -2435,14 +2398,12 @@ static int nf_tables_delrule(struct net *net, struct sock *nlsk, ...@@ -2435,14 +2398,12 @@ static int nf_tables_delrule(struct net *net, struct sock *nlsk,
int family = nfmsg->nfgen_family, err = 0; int family = nfmsg->nfgen_family, err = 0;
struct nft_ctx ctx; struct nft_ctx ctx;
table = nf_tables_table_lookup(net, nla[NFTA_RULE_TABLE], family, table = nft_table_lookup(net, nla[NFTA_RULE_TABLE], family, genmask);
genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
if (nla[NFTA_RULE_CHAIN]) { if (nla[NFTA_RULE_CHAIN]) {
chain = nf_tables_chain_lookup(table, nla[NFTA_RULE_CHAIN], chain = nft_chain_lookup(table, nla[NFTA_RULE_CHAIN], genmask);
genmask);
if (IS_ERR(chain)) if (IS_ERR(chain))
return PTR_ERR(chain); return PTR_ERR(chain);
} }
...@@ -2451,8 +2412,7 @@ static int nf_tables_delrule(struct net *net, struct sock *nlsk, ...@@ -2451,8 +2412,7 @@ static int nf_tables_delrule(struct net *net, struct sock *nlsk,
if (chain) { if (chain) {
if (nla[NFTA_RULE_HANDLE]) { if (nla[NFTA_RULE_HANDLE]) {
rule = nf_tables_rule_lookup(chain, rule = nft_rule_lookup(chain, nla[NFTA_RULE_HANDLE]);
nla[NFTA_RULE_HANDLE]);
if (IS_ERR(rule)) if (IS_ERR(rule))
return PTR_ERR(rule); return PTR_ERR(rule);
...@@ -2635,8 +2595,8 @@ static int nft_ctx_init_from_setattr(struct nft_ctx *ctx, struct net *net, ...@@ -2635,8 +2595,8 @@ static int nft_ctx_init_from_setattr(struct nft_ctx *ctx, struct net *net,
struct nft_table *table = NULL; struct nft_table *table = NULL;
if (nla[NFTA_SET_TABLE] != NULL) { if (nla[NFTA_SET_TABLE] != NULL) {
table = nf_tables_table_lookup(net, nla[NFTA_SET_TABLE], table = nft_table_lookup(net, nla[NFTA_SET_TABLE], family,
family, genmask); genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
} }
...@@ -2645,7 +2605,7 @@ static int nft_ctx_init_from_setattr(struct nft_ctx *ctx, struct net *net, ...@@ -2645,7 +2605,7 @@ static int nft_ctx_init_from_setattr(struct nft_ctx *ctx, struct net *net,
return 0; return 0;
} }
static struct nft_set *nf_tables_set_lookup(const struct nft_table *table, static struct nft_set *nft_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;
...@@ -2661,14 +2621,12 @@ static struct nft_set *nf_tables_set_lookup(const struct nft_table *table, ...@@ -2661,14 +2621,12 @@ static struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
static struct nft_set *nf_tables_set_lookup_byhandle(const struct nft_table *table, static struct nft_set *nft_set_lookup_byhandle(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;
if (nla == NULL)
return ERR_PTR(-EINVAL);
list_for_each_entry(set, &table->sets, list) { list_for_each_entry(set, &table->sets, list) {
if (be64_to_cpu(nla_get_be64(nla)) == set->handle && if (be64_to_cpu(nla_get_be64(nla)) == set->handle &&
nft_active_genmask(set, genmask)) nft_active_genmask(set, genmask))
...@@ -2677,9 +2635,8 @@ static struct nft_set *nf_tables_set_lookup_byhandle(const struct nft_table *tab ...@@ -2677,9 +2635,8 @@ static struct nft_set *nf_tables_set_lookup_byhandle(const struct nft_table *tab
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
static struct nft_set *nf_tables_set_lookup_byid(const struct net *net, static struct nft_set *nft_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));
...@@ -2703,12 +2660,12 @@ struct nft_set *nft_set_lookup_global(const struct net *net, ...@@ -2703,12 +2660,12 @@ struct nft_set *nft_set_lookup_global(const struct net *net,
{ {
struct nft_set *set; struct nft_set *set;
set = nf_tables_set_lookup(table, nla_set_name, genmask); set = nft_set_lookup(table, nla_set_name, genmask);
if (IS_ERR(set)) { if (IS_ERR(set)) {
if (!nla_set_id) if (!nla_set_id)
return set; return set;
set = nf_tables_set_lookup_byid(net, nla_set_id, genmask); set = nft_set_lookup_byid(net, nla_set_id, genmask);
} }
return set; return set;
} }
...@@ -2980,7 +2937,7 @@ static int nf_tables_getset(struct net *net, struct sock *nlsk, ...@@ -2980,7 +2937,7 @@ static int nf_tables_getset(struct net *net, struct sock *nlsk,
if (!nla[NFTA_SET_TABLE]) if (!nla[NFTA_SET_TABLE])
return -EINVAL; return -EINVAL;
set = nf_tables_set_lookup(ctx.table, nla[NFTA_SET_NAME], genmask); set = nft_set_lookup(ctx.table, nla[NFTA_SET_NAME], genmask);
if (IS_ERR(set)) if (IS_ERR(set))
return PTR_ERR(set); return PTR_ERR(set);
...@@ -3132,14 +3089,13 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk, ...@@ -3132,14 +3089,13 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
create = nlh->nlmsg_flags & NLM_F_CREATE ? true : false; create = nlh->nlmsg_flags & NLM_F_CREATE ? true : false;
table = nf_tables_table_lookup(net, nla[NFTA_SET_TABLE], family, table = nft_table_lookup(net, nla[NFTA_SET_TABLE], family, genmask);
genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
nft_ctx_init(&ctx, net, skb, nlh, family, table, NULL, nla); nft_ctx_init(&ctx, net, skb, nlh, family, table, NULL, nla);
set = nf_tables_set_lookup(table, nla[NFTA_SET_NAME], genmask); set = nft_set_lookup(table, nla[NFTA_SET_NAME], genmask);
if (IS_ERR(set)) { if (IS_ERR(set)) {
if (PTR_ERR(set) != -ENOENT) if (PTR_ERR(set) != -ENOENT)
return PTR_ERR(set); return PTR_ERR(set);
...@@ -3262,9 +3218,10 @@ static int nf_tables_delset(struct net *net, struct sock *nlsk, ...@@ -3262,9 +3218,10 @@ static int nf_tables_delset(struct net *net, struct sock *nlsk,
return err; return err;
if (nla[NFTA_SET_HANDLE]) if (nla[NFTA_SET_HANDLE])
set = nf_tables_set_lookup_byhandle(ctx.table, nla[NFTA_SET_HANDLE], genmask); set = nft_set_lookup_byhandle(ctx.table, nla[NFTA_SET_HANDLE],
genmask);
else else
set = nf_tables_set_lookup(ctx.table, nla[NFTA_SET_NAME], genmask); set = nft_set_lookup(ctx.table, nla[NFTA_SET_NAME], genmask);
if (IS_ERR(set)) if (IS_ERR(set))
return PTR_ERR(set); return PTR_ERR(set);
...@@ -3404,8 +3361,8 @@ static int nft_ctx_init_from_elemattr(struct nft_ctx *ctx, struct net *net, ...@@ -3404,8 +3361,8 @@ static int nft_ctx_init_from_elemattr(struct nft_ctx *ctx, struct net *net,
int family = nfmsg->nfgen_family; int family = nfmsg->nfgen_family;
struct nft_table *table; struct nft_table *table;
table = nf_tables_table_lookup(net, nla[NFTA_SET_ELEM_LIST_TABLE], table = nft_table_lookup(net, nla[NFTA_SET_ELEM_LIST_TABLE], family,
family, genmask); genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
...@@ -3741,8 +3698,7 @@ static int nf_tables_getsetelem(struct net *net, struct sock *nlsk, ...@@ -3741,8 +3698,7 @@ static int nf_tables_getsetelem(struct net *net, struct sock *nlsk,
if (err < 0) if (err < 0)
return err; return err;
set = nf_tables_set_lookup(ctx.table, nla[NFTA_SET_ELEM_LIST_SET], set = nft_set_lookup(ctx.table, nla[NFTA_SET_ELEM_LIST_SET], genmask);
genmask);
if (IS_ERR(set)) if (IS_ERR(set))
return PTR_ERR(set); return PTR_ERR(set);
...@@ -3954,7 +3910,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set, ...@@ -3954,7 +3910,7 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
err = -EINVAL; err = -EINVAL;
goto err2; goto err2;
} }
obj = nf_tables_obj_lookup(ctx->table, nla[NFTA_SET_ELEM_OBJREF], obj = nft_obj_lookup(ctx->table, nla[NFTA_SET_ELEM_OBJREF],
set->objtype, genmask); set->objtype, genmask);
if (IS_ERR(obj)) { if (IS_ERR(obj)) {
err = PTR_ERR(obj); err = PTR_ERR(obj);
...@@ -4284,8 +4240,7 @@ static int nf_tables_delsetelem(struct net *net, struct sock *nlsk, ...@@ -4284,8 +4240,7 @@ static int nf_tables_delsetelem(struct net *net, struct sock *nlsk,
if (err < 0) if (err < 0)
return err; return err;
set = nf_tables_set_lookup(ctx.table, nla[NFTA_SET_ELEM_LIST_SET], set = nft_set_lookup(ctx.table, nla[NFTA_SET_ELEM_LIST_SET], genmask);
genmask);
if (IS_ERR(set)) if (IS_ERR(set))
return PTR_ERR(set); return PTR_ERR(set);
if (!list_empty(&set->bindings) && set->flags & NFT_SET_CONSTANT) if (!list_empty(&set->bindings) && set->flags & NFT_SET_CONSTANT)
...@@ -4373,9 +4328,9 @@ void nft_unregister_obj(struct nft_object_type *obj_type) ...@@ -4373,9 +4328,9 @@ void nft_unregister_obj(struct nft_object_type *obj_type)
} }
EXPORT_SYMBOL_GPL(nft_unregister_obj); EXPORT_SYMBOL_GPL(nft_unregister_obj);
struct nft_object *nf_tables_obj_lookup(const struct nft_table *table, struct nft_object *nft_obj_lookup(const struct nft_table *table,
const struct nlattr *nla, const struct nlattr *nla, u32 objtype,
u32 objtype, u8 genmask) u8 genmask)
{ {
struct nft_object *obj; struct nft_object *obj;
...@@ -4387,9 +4342,9 @@ struct nft_object *nf_tables_obj_lookup(const struct nft_table *table, ...@@ -4387,9 +4342,9 @@ struct nft_object *nf_tables_obj_lookup(const struct nft_table *table,
} }
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
EXPORT_SYMBOL_GPL(nf_tables_obj_lookup); EXPORT_SYMBOL_GPL(nft_obj_lookup);
static struct nft_object *nf_tables_obj_lookup_byhandle(const struct nft_table *table, static struct nft_object *nft_obj_lookup_byhandle(const struct nft_table *table,
const struct nlattr *nla, const struct nlattr *nla,
u32 objtype, u8 genmask) u32 objtype, u8 genmask)
{ {
...@@ -4535,13 +4490,12 @@ static int nf_tables_newobj(struct net *net, struct sock *nlsk, ...@@ -4535,13 +4490,12 @@ static int nf_tables_newobj(struct net *net, struct sock *nlsk,
!nla[NFTA_OBJ_DATA]) !nla[NFTA_OBJ_DATA])
return -EINVAL; return -EINVAL;
table = nf_tables_table_lookup(net, nla[NFTA_OBJ_TABLE], family, table = nft_table_lookup(net, nla[NFTA_OBJ_TABLE], family, genmask);
genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
objtype = ntohl(nla_get_be32(nla[NFTA_OBJ_TYPE])); objtype = ntohl(nla_get_be32(nla[NFTA_OBJ_TYPE]));
obj = nf_tables_obj_lookup(table, nla[NFTA_OBJ_NAME], objtype, genmask); obj = nft_obj_lookup(table, nla[NFTA_OBJ_NAME], objtype, genmask);
if (IS_ERR(obj)) { if (IS_ERR(obj)) {
err = PTR_ERR(obj); err = PTR_ERR(obj);
if (err != -ENOENT) if (err != -ENOENT)
...@@ -4761,13 +4715,12 @@ static int nf_tables_getobj(struct net *net, struct sock *nlsk, ...@@ -4761,13 +4715,12 @@ static int nf_tables_getobj(struct net *net, struct sock *nlsk,
!nla[NFTA_OBJ_TYPE]) !nla[NFTA_OBJ_TYPE])
return -EINVAL; return -EINVAL;
table = nf_tables_table_lookup(net, nla[NFTA_OBJ_TABLE], family, table = nft_table_lookup(net, nla[NFTA_OBJ_TABLE], family, genmask);
genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
objtype = ntohl(nla_get_be32(nla[NFTA_OBJ_TYPE])); objtype = ntohl(nla_get_be32(nla[NFTA_OBJ_TYPE]));
obj = nf_tables_obj_lookup(table, nla[NFTA_OBJ_NAME], objtype, genmask); obj = nft_obj_lookup(table, nla[NFTA_OBJ_NAME], objtype, genmask);
if (IS_ERR(obj)) if (IS_ERR(obj))
return PTR_ERR(obj); return PTR_ERR(obj);
...@@ -4817,18 +4770,17 @@ static int nf_tables_delobj(struct net *net, struct sock *nlsk, ...@@ -4817,18 +4770,17 @@ static int nf_tables_delobj(struct net *net, struct sock *nlsk,
(!nla[NFTA_OBJ_NAME] && !nla[NFTA_OBJ_HANDLE])) (!nla[NFTA_OBJ_NAME] && !nla[NFTA_OBJ_HANDLE]))
return -EINVAL; return -EINVAL;
table = nf_tables_table_lookup(net, nla[NFTA_OBJ_TABLE], family, table = nft_table_lookup(net, nla[NFTA_OBJ_TABLE], family, genmask);
genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
objtype = ntohl(nla_get_be32(nla[NFTA_OBJ_TYPE])); objtype = ntohl(nla_get_be32(nla[NFTA_OBJ_TYPE]));
if (nla[NFTA_OBJ_HANDLE]) if (nla[NFTA_OBJ_HANDLE])
obj = nf_tables_obj_lookup_byhandle(table, nla[NFTA_OBJ_HANDLE], obj = nft_obj_lookup_byhandle(table, nla[NFTA_OBJ_HANDLE],
objtype, genmask); objtype, genmask);
else else
obj = nf_tables_obj_lookup(table, nla[NFTA_OBJ_NAME], obj = nft_obj_lookup(table, nla[NFTA_OBJ_NAME], objtype,
objtype, genmask); genmask);
if (IS_ERR(obj)) if (IS_ERR(obj))
return PTR_ERR(obj); return PTR_ERR(obj);
if (obj->use > 0) if (obj->use > 0)
...@@ -4903,9 +4855,8 @@ static const struct nla_policy nft_flowtable_policy[NFTA_FLOWTABLE_MAX + 1] = { ...@@ -4903,9 +4855,8 @@ static const struct nla_policy nft_flowtable_policy[NFTA_FLOWTABLE_MAX + 1] = {
[NFTA_FLOWTABLE_HANDLE] = { .type = NLA_U64 }, [NFTA_FLOWTABLE_HANDLE] = { .type = NLA_U64 },
}; };
struct nft_flowtable *nf_tables_flowtable_lookup(const struct nft_table *table, struct nft_flowtable *nft_flowtable_lookup(const struct nft_table *table,
const struct nlattr *nla, const struct nlattr *nla, u8 genmask)
u8 genmask)
{ {
struct nft_flowtable *flowtable; struct nft_flowtable *flowtable;
...@@ -4916,10 +4867,10 @@ struct nft_flowtable *nf_tables_flowtable_lookup(const struct nft_table *table, ...@@ -4916,10 +4867,10 @@ struct nft_flowtable *nf_tables_flowtable_lookup(const struct nft_table *table,
} }
return ERR_PTR(-ENOENT); return ERR_PTR(-ENOENT);
} }
EXPORT_SYMBOL_GPL(nf_tables_flowtable_lookup); EXPORT_SYMBOL_GPL(nft_flowtable_lookup);
static struct nft_flowtable * static struct nft_flowtable *
nf_tables_flowtable_lookup_byhandle(const struct nft_table *table, nft_flowtable_lookup_byhandle(const struct nft_table *table,
const struct nlattr *nla, u8 genmask) const struct nlattr *nla, u8 genmask)
{ {
struct nft_flowtable *flowtable; struct nft_flowtable *flowtable;
...@@ -5093,12 +5044,12 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk, ...@@ -5093,12 +5044,12 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk,
!nla[NFTA_FLOWTABLE_HOOK]) !nla[NFTA_FLOWTABLE_HOOK])
return -EINVAL; return -EINVAL;
table = nf_tables_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE], table = nft_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE], family,
family, genmask); genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
flowtable = nf_tables_flowtable_lookup(table, nla[NFTA_FLOWTABLE_NAME], flowtable = nft_flowtable_lookup(table, nla[NFTA_FLOWTABLE_NAME],
genmask); genmask);
if (IS_ERR(flowtable)) { if (IS_ERR(flowtable)) {
err = PTR_ERR(flowtable); err = PTR_ERR(flowtable);
...@@ -5210,17 +5161,17 @@ static int nf_tables_delflowtable(struct net *net, struct sock *nlsk, ...@@ -5210,17 +5161,17 @@ static int nf_tables_delflowtable(struct net *net, struct sock *nlsk,
!nla[NFTA_FLOWTABLE_HANDLE])) !nla[NFTA_FLOWTABLE_HANDLE]))
return -EINVAL; return -EINVAL;
table = nf_tables_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE], table = nft_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE], family,
family, genmask); genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
if (nla[NFTA_FLOWTABLE_HANDLE]) if (nla[NFTA_FLOWTABLE_HANDLE])
flowtable = nf_tables_flowtable_lookup_byhandle(table, flowtable = nft_flowtable_lookup_byhandle(table,
nla[NFTA_FLOWTABLE_HANDLE], nla[NFTA_FLOWTABLE_HANDLE],
genmask); genmask);
else else
flowtable = nf_tables_flowtable_lookup(table, flowtable = nft_flowtable_lookup(table,
nla[NFTA_FLOWTABLE_NAME], nla[NFTA_FLOWTABLE_NAME],
genmask); genmask);
if (IS_ERR(flowtable)) if (IS_ERR(flowtable))
...@@ -5407,12 +5358,12 @@ static int nf_tables_getflowtable(struct net *net, struct sock *nlsk, ...@@ -5407,12 +5358,12 @@ static int nf_tables_getflowtable(struct net *net, struct sock *nlsk,
if (!nla[NFTA_FLOWTABLE_NAME]) if (!nla[NFTA_FLOWTABLE_NAME])
return -EINVAL; return -EINVAL;
table = nf_tables_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE], table = nft_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE], family,
family, genmask); genmask);
if (IS_ERR(table)) if (IS_ERR(table))
return PTR_ERR(table); return PTR_ERR(table);
flowtable = nf_tables_flowtable_lookup(table, nla[NFTA_FLOWTABLE_NAME], flowtable = nft_flowtable_lookup(table, nla[NFTA_FLOWTABLE_NAME],
genmask); genmask);
if (IS_ERR(flowtable)) if (IS_ERR(flowtable))
return PTR_ERR(flowtable); return PTR_ERR(flowtable);
...@@ -6382,8 +6333,8 @@ static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data, ...@@ -6382,8 +6333,8 @@ static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data,
case NFT_GOTO: case NFT_GOTO:
if (!tb[NFTA_VERDICT_CHAIN]) if (!tb[NFTA_VERDICT_CHAIN])
return -EINVAL; return -EINVAL;
chain = nf_tables_chain_lookup(ctx->table, chain = nft_chain_lookup(ctx->table, tb[NFTA_VERDICT_CHAIN],
tb[NFTA_VERDICT_CHAIN], genmask); genmask);
if (IS_ERR(chain)) if (IS_ERR(chain))
return PTR_ERR(chain); return PTR_ERR(chain);
if (nft_is_base_chain(chain)) if (nft_is_base_chain(chain))
......
...@@ -142,8 +142,7 @@ static int nft_flow_offload_init(const struct nft_ctx *ctx, ...@@ -142,8 +142,7 @@ static int nft_flow_offload_init(const struct nft_ctx *ctx,
if (!tb[NFTA_FLOW_TABLE_NAME]) if (!tb[NFTA_FLOW_TABLE_NAME])
return -EINVAL; return -EINVAL;
flowtable = nf_tables_flowtable_lookup(ctx->table, flowtable = nft_flowtable_lookup(ctx->table, tb[NFTA_FLOW_TABLE_NAME],
tb[NFTA_FLOW_TABLE_NAME],
genmask); genmask);
if (IS_ERR(flowtable)) if (IS_ERR(flowtable))
return PTR_ERR(flowtable); return PTR_ERR(flowtable);
......
...@@ -38,7 +38,7 @@ static int nft_objref_init(const struct nft_ctx *ctx, ...@@ -38,7 +38,7 @@ static int nft_objref_init(const struct nft_ctx *ctx,
return -EINVAL; return -EINVAL;
objtype = ntohl(nla_get_be32(tb[NFTA_OBJREF_IMM_TYPE])); objtype = ntohl(nla_get_be32(tb[NFTA_OBJREF_IMM_TYPE]));
obj = nf_tables_obj_lookup(ctx->table, tb[NFTA_OBJREF_IMM_NAME], objtype, obj = nft_obj_lookup(ctx->table, tb[NFTA_OBJREF_IMM_NAME], objtype,
genmask); genmask);
if (IS_ERR(obj)) if (IS_ERR(obj))
return -ENOENT; return -ENOENT;
......
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