|
@@ -386,13 +386,17 @@ static struct nft_table *nft_table_lookup(const struct net *net,
|
|
|
{
|
|
|
struct nft_table *table;
|
|
|
|
|
|
+ if (nla == NULL)
|
|
|
+ return ERR_PTR(-EINVAL);
|
|
|
+
|
|
|
list_for_each_entry(table, &net->nft.tables, list) {
|
|
|
if (!nla_strcmp(nla, table->name) &&
|
|
|
table->family == family &&
|
|
|
nft_active_genmask(table, genmask))
|
|
|
return table;
|
|
|
}
|
|
|
- return NULL;
|
|
|
+
|
|
|
+ return ERR_PTR(-ENOENT);
|
|
|
}
|
|
|
|
|
|
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))
|
|
|
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);
|
|
|
}
|
|
@@ -608,10 +581,11 @@ static int nf_tables_gettable(struct net *net, struct sock *nlsk,
|
|
|
return netlink_dump_start(nlsk, skb, nlh, &c);
|
|
|
}
|
|
|
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_TABLE_NAME], family,
|
|
|
- genmask);
|
|
|
- if (IS_ERR(table))
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_TABLE_NAME], family, genmask);
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_TABLE_NAME]);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
|
|
|
skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
|
|
|
if (!skb2)
|
|
@@ -727,21 +701,23 @@ static int nf_tables_newtable(struct net *net, struct sock *nlsk,
|
|
|
{
|
|
|
const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
|
|
|
u8 genmask = nft_genmask_next(net);
|
|
|
- const struct nlattr *name;
|
|
|
- struct nft_table *table;
|
|
|
int family = nfmsg->nfgen_family;
|
|
|
+ const struct nlattr *attr;
|
|
|
+ struct nft_table *table;
|
|
|
u32 flags = 0;
|
|
|
struct nft_ctx ctx;
|
|
|
int err;
|
|
|
|
|
|
- name = nla[NFTA_TABLE_NAME];
|
|
|
- table = nf_tables_table_lookup(net, name, family, genmask);
|
|
|
+ attr = nla[NFTA_TABLE_NAME];
|
|
|
+ table = nft_table_lookup(net, attr, family, genmask);
|
|
|
if (IS_ERR(table)) {
|
|
|
if (PTR_ERR(table) != -ENOENT)
|
|
|
return PTR_ERR(table);
|
|
|
} else {
|
|
|
- if (nlh->nlmsg_flags & NLM_F_EXCL)
|
|
|
+ if (nlh->nlmsg_flags & NLM_F_EXCL) {
|
|
|
+ NL_SET_BAD_ATTR(extack, attr);
|
|
|
return -EEXIST;
|
|
|
+ }
|
|
|
if (nlh->nlmsg_flags & NLM_F_REPLACE)
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
@@ -760,7 +736,7 @@ static int nf_tables_newtable(struct net *net, struct sock *nlsk,
|
|
|
if (table == NULL)
|
|
|
goto err_kzalloc;
|
|
|
|
|
|
- table->name = nla_strdup(name, GFP_KERNEL);
|
|
|
+ table->name = nla_strdup(attr, GFP_KERNEL);
|
|
|
if (table->name == NULL)
|
|
|
goto err_strdup;
|
|
|
|
|
@@ -883,8 +859,9 @@ static int nf_tables_deltable(struct net *net, struct sock *nlsk,
|
|
|
{
|
|
|
const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
|
|
|
u8 genmask = nft_genmask_next(net);
|
|
|
- struct nft_table *table;
|
|
|
int family = nfmsg->nfgen_family;
|
|
|
+ const struct nlattr *attr;
|
|
|
+ struct nft_table *table;
|
|
|
struct nft_ctx ctx;
|
|
|
|
|
|
nft_ctx_init(&ctx, net, skb, nlh, 0, NULL, NULL, nla);
|
|
@@ -892,16 +869,18 @@ static int nf_tables_deltable(struct net *net, struct sock *nlsk,
|
|
|
(!nla[NFTA_TABLE_NAME] && !nla[NFTA_TABLE_HANDLE]))
|
|
|
return nft_flush(&ctx, family);
|
|
|
|
|
|
- if (nla[NFTA_TABLE_HANDLE])
|
|
|
- table = nf_tables_table_lookup_byhandle(net,
|
|
|
- nla[NFTA_TABLE_HANDLE],
|
|
|
- genmask);
|
|
|
- else
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_TABLE_NAME],
|
|
|
- family, genmask);
|
|
|
+ if (nla[NFTA_TABLE_HANDLE]) {
|
|
|
+ attr = nla[NFTA_TABLE_HANDLE];
|
|
|
+ table = nft_table_lookup_byhandle(net, attr, genmask);
|
|
|
+ } else {
|
|
|
+ attr = nla[NFTA_TABLE_NAME];
|
|
|
+ table = nft_table_lookup(net, attr, family, genmask);
|
|
|
+ }
|
|
|
|
|
|
- if (IS_ERR(table))
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, attr);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
|
|
|
if (nlh->nlmsg_flags & NLM_F_NONREC &&
|
|
|
table->use > 0)
|
|
@@ -949,8 +928,7 @@ EXPORT_SYMBOL_GPL(nft_unregister_chain_type);
|
|
|
*/
|
|
|
|
|
|
static struct nft_chain *
|
|
|
-nf_tables_chain_lookup_byhandle(const struct nft_table *table, u64 handle,
|
|
|
- u8 genmask)
|
|
|
+nft_chain_lookup_byhandle(const struct nft_table *table, u64 handle, u8 genmask)
|
|
|
{
|
|
|
struct nft_chain *chain;
|
|
|
|
|
@@ -963,9 +941,8 @@ nf_tables_chain_lookup_byhandle(const struct nft_table *table, u64 handle,
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
}
|
|
|
|
|
|
-static struct nft_chain *nf_tables_chain_lookup(const struct nft_table *table,
|
|
|
- const struct nlattr *nla,
|
|
|
- u8 genmask)
|
|
|
+static struct nft_chain *nft_chain_lookup(const struct nft_table *table,
|
|
|
+ const struct nlattr *nla, u8 genmask)
|
|
|
{
|
|
|
struct nft_chain *chain;
|
|
|
|
|
@@ -1194,14 +1171,17 @@ static int nf_tables_getchain(struct net *net, struct sock *nlsk,
|
|
|
return netlink_dump_start(nlsk, skb, nlh, &c);
|
|
|
}
|
|
|
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_CHAIN_TABLE], family,
|
|
|
- genmask);
|
|
|
- if (IS_ERR(table))
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_CHAIN_TABLE], family, genmask);
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_CHAIN_TABLE]);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
|
|
|
- chain = nf_tables_chain_lookup(table, nla[NFTA_CHAIN_NAME], genmask);
|
|
|
- if (IS_ERR(chain))
|
|
|
+ chain = nft_chain_lookup(table, nla[NFTA_CHAIN_NAME], genmask);
|
|
|
+ if (IS_ERR(chain)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_CHAIN_NAME]);
|
|
|
return PTR_ERR(chain);
|
|
|
+ }
|
|
|
|
|
|
skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
|
|
|
if (!skb2)
|
|
@@ -1513,8 +1493,7 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy,
|
|
|
nla[NFTA_CHAIN_NAME]) {
|
|
|
struct nft_chain *chain2;
|
|
|
|
|
|
- chain2 = nf_tables_chain_lookup(table, nla[NFTA_CHAIN_NAME],
|
|
|
- genmask);
|
|
|
+ chain2 = nft_chain_lookup(table, nla[NFTA_CHAIN_NAME], genmask);
|
|
|
if (!IS_ERR(chain2))
|
|
|
return -EEXIST;
|
|
|
}
|
|
@@ -1564,9 +1543,9 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,
|
|
|
struct netlink_ext_ack *extack)
|
|
|
{
|
|
|
const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
|
|
|
- const struct nlattr * uninitialized_var(name);
|
|
|
u8 genmask = nft_genmask_next(net);
|
|
|
int family = nfmsg->nfgen_family;
|
|
|
+ const struct nlattr *attr;
|
|
|
struct nft_table *table;
|
|
|
struct nft_chain *chain;
|
|
|
u8 policy = NF_ACCEPT;
|
|
@@ -1576,36 +1555,46 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,
|
|
|
|
|
|
create = nlh->nlmsg_flags & NLM_F_CREATE ? true : false;
|
|
|
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_CHAIN_TABLE], family,
|
|
|
- genmask);
|
|
|
- if (IS_ERR(table))
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_CHAIN_TABLE], family, genmask);
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_CHAIN_TABLE]);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
|
|
|
chain = NULL;
|
|
|
- name = nla[NFTA_CHAIN_NAME];
|
|
|
+ attr = nla[NFTA_CHAIN_NAME];
|
|
|
|
|
|
if (nla[NFTA_CHAIN_HANDLE]) {
|
|
|
handle = be64_to_cpu(nla_get_be64(nla[NFTA_CHAIN_HANDLE]));
|
|
|
- chain = nf_tables_chain_lookup_byhandle(table, handle, genmask);
|
|
|
- if (IS_ERR(chain))
|
|
|
+ chain = nft_chain_lookup_byhandle(table, handle, genmask);
|
|
|
+ if (IS_ERR(chain)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_CHAIN_HANDLE]);
|
|
|
return PTR_ERR(chain);
|
|
|
+ }
|
|
|
+ attr = nla[NFTA_CHAIN_HANDLE];
|
|
|
} else {
|
|
|
- chain = nf_tables_chain_lookup(table, name, genmask);
|
|
|
+ chain = nft_chain_lookup(table, attr, genmask);
|
|
|
if (IS_ERR(chain)) {
|
|
|
- if (PTR_ERR(chain) != -ENOENT)
|
|
|
+ if (PTR_ERR(chain) != -ENOENT) {
|
|
|
+ NL_SET_BAD_ATTR(extack, attr);
|
|
|
return PTR_ERR(chain);
|
|
|
+ }
|
|
|
chain = NULL;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (nla[NFTA_CHAIN_POLICY]) {
|
|
|
if (chain != NULL &&
|
|
|
- !nft_is_base_chain(chain))
|
|
|
+ !nft_is_base_chain(chain)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_CHAIN_POLICY]);
|
|
|
return -EOPNOTSUPP;
|
|
|
+ }
|
|
|
|
|
|
if (chain == NULL &&
|
|
|
- nla[NFTA_CHAIN_HOOK] == NULL)
|
|
|
+ nla[NFTA_CHAIN_HOOK] == NULL) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_CHAIN_POLICY]);
|
|
|
return -EOPNOTSUPP;
|
|
|
+ }
|
|
|
|
|
|
policy = ntohl(nla_get_be32(nla[NFTA_CHAIN_POLICY]));
|
|
|
switch (policy) {
|
|
@@ -1620,8 +1609,10 @@ static int nf_tables_newchain(struct net *net, struct sock *nlsk,
|
|
|
nft_ctx_init(&ctx, net, skb, nlh, family, table, chain, nla);
|
|
|
|
|
|
if (chain != NULL) {
|
|
|
- if (nlh->nlmsg_flags & NLM_F_EXCL)
|
|
|
+ if (nlh->nlmsg_flags & NLM_F_EXCL) {
|
|
|
+ NL_SET_BAD_ATTR(extack, attr);
|
|
|
return -EEXIST;
|
|
|
+ }
|
|
|
if (nlh->nlmsg_flags & NLM_F_REPLACE)
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
@@ -1638,28 +1629,34 @@ static int nf_tables_delchain(struct net *net, struct sock *nlsk,
|
|
|
{
|
|
|
const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
|
|
|
u8 genmask = nft_genmask_next(net);
|
|
|
+ int family = nfmsg->nfgen_family;
|
|
|
+ const struct nlattr *attr;
|
|
|
struct nft_table *table;
|
|
|
struct nft_chain *chain;
|
|
|
struct nft_rule *rule;
|
|
|
- int family = nfmsg->nfgen_family;
|
|
|
struct nft_ctx ctx;
|
|
|
u64 handle;
|
|
|
u32 use;
|
|
|
int err;
|
|
|
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_CHAIN_TABLE], family,
|
|
|
- genmask);
|
|
|
- if (IS_ERR(table))
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_CHAIN_TABLE], family, genmask);
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_CHAIN_TABLE]);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
|
|
|
if (nla[NFTA_CHAIN_HANDLE]) {
|
|
|
- handle = be64_to_cpu(nla_get_be64(nla[NFTA_CHAIN_HANDLE]));
|
|
|
- chain = nf_tables_chain_lookup_byhandle(table, handle, genmask);
|
|
|
+ attr = nla[NFTA_CHAIN_HANDLE];
|
|
|
+ handle = be64_to_cpu(nla_get_be64(attr));
|
|
|
+ chain = nft_chain_lookup_byhandle(table, handle, genmask);
|
|
|
} else {
|
|
|
- chain = nf_tables_chain_lookup(table, nla[NFTA_CHAIN_NAME], genmask);
|
|
|
+ attr = nla[NFTA_CHAIN_NAME];
|
|
|
+ chain = nft_chain_lookup(table, attr, genmask);
|
|
|
}
|
|
|
- if (IS_ERR(chain))
|
|
|
+ if (IS_ERR(chain)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, attr);
|
|
|
return PTR_ERR(chain);
|
|
|
+ }
|
|
|
|
|
|
if (nlh->nlmsg_flags & NLM_F_NONREC &&
|
|
|
chain->use > 0)
|
|
@@ -1681,8 +1678,10 @@ static int nf_tables_delchain(struct net *net, struct sock *nlsk,
|
|
|
/* There are rules and elements that are still holding references to us,
|
|
|
* we cannot do a recursive removal in this case.
|
|
|
*/
|
|
|
- if (use > 0)
|
|
|
+ if (use > 0) {
|
|
|
+ NL_SET_BAD_ATTR(extack, attr);
|
|
|
return -EBUSY;
|
|
|
+ }
|
|
|
|
|
|
return nft_delchain(&ctx);
|
|
|
}
|
|
@@ -1939,8 +1938,8 @@ void nft_expr_destroy(const struct nft_ctx *ctx, struct nft_expr *expr)
|
|
|
* Rules
|
|
|
*/
|
|
|
|
|
|
-static struct nft_rule *__nf_tables_rule_lookup(const struct nft_chain *chain,
|
|
|
- u64 handle)
|
|
|
+static struct nft_rule *__nft_rule_lookup(const struct nft_chain *chain,
|
|
|
+ u64 handle)
|
|
|
{
|
|
|
struct nft_rule *rule;
|
|
|
|
|
@@ -1953,13 +1952,13 @@ static struct nft_rule *__nf_tables_rule_lookup(const struct nft_chain *chain,
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
}
|
|
|
|
|
|
-static struct nft_rule *nf_tables_rule_lookup(const struct nft_chain *chain,
|
|
|
- const struct nlattr *nla)
|
|
|
+static struct nft_rule *nft_rule_lookup(const struct nft_chain *chain,
|
|
|
+ const struct nlattr *nla)
|
|
|
{
|
|
|
if (nla == NULL)
|
|
|
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] = {
|
|
@@ -2191,18 +2190,23 @@ static int nf_tables_getrule(struct net *net, struct sock *nlsk,
|
|
|
return netlink_dump_start(nlsk, skb, nlh, &c);
|
|
|
}
|
|
|
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_RULE_TABLE], family,
|
|
|
- genmask);
|
|
|
- if (IS_ERR(table))
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_RULE_TABLE], family, genmask);
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_TABLE]);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
|
|
|
- chain = nf_tables_chain_lookup(table, nla[NFTA_RULE_CHAIN], genmask);
|
|
|
- if (IS_ERR(chain))
|
|
|
+ chain = nft_chain_lookup(table, nla[NFTA_RULE_CHAIN], genmask);
|
|
|
+ if (IS_ERR(chain)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_CHAIN]);
|
|
|
return PTR_ERR(chain);
|
|
|
+ }
|
|
|
|
|
|
- rule = nf_tables_rule_lookup(chain, nla[NFTA_RULE_HANDLE]);
|
|
|
- if (IS_ERR(rule))
|
|
|
+ rule = nft_rule_lookup(chain, nla[NFTA_RULE_HANDLE]);
|
|
|
+ if (IS_ERR(rule)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_HANDLE]);
|
|
|
return PTR_ERR(rule);
|
|
|
+ }
|
|
|
|
|
|
skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
|
|
|
if (!skb2)
|
|
@@ -2265,23 +2269,30 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
|
|
|
|
|
|
create = nlh->nlmsg_flags & NLM_F_CREATE ? true : false;
|
|
|
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_RULE_TABLE], family,
|
|
|
- genmask);
|
|
|
- if (IS_ERR(table))
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_RULE_TABLE], family, genmask);
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_TABLE]);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
|
|
|
- chain = nf_tables_chain_lookup(table, nla[NFTA_RULE_CHAIN], genmask);
|
|
|
- if (IS_ERR(chain))
|
|
|
+ chain = nft_chain_lookup(table, nla[NFTA_RULE_CHAIN], genmask);
|
|
|
+ if (IS_ERR(chain)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_CHAIN]);
|
|
|
return PTR_ERR(chain);
|
|
|
+ }
|
|
|
|
|
|
if (nla[NFTA_RULE_HANDLE]) {
|
|
|
handle = be64_to_cpu(nla_get_be64(nla[NFTA_RULE_HANDLE]));
|
|
|
- rule = __nf_tables_rule_lookup(chain, handle);
|
|
|
- if (IS_ERR(rule))
|
|
|
+ rule = __nft_rule_lookup(chain, handle);
|
|
|
+ if (IS_ERR(rule)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_HANDLE]);
|
|
|
return PTR_ERR(rule);
|
|
|
+ }
|
|
|
|
|
|
- if (nlh->nlmsg_flags & NLM_F_EXCL)
|
|
|
+ if (nlh->nlmsg_flags & NLM_F_EXCL) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_HANDLE]);
|
|
|
return -EEXIST;
|
|
|
+ }
|
|
|
if (nlh->nlmsg_flags & NLM_F_REPLACE)
|
|
|
old_rule = rule;
|
|
|
else
|
|
@@ -2300,9 +2311,11 @@ static int nf_tables_newrule(struct net *net, struct sock *nlsk,
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
pos_handle = be64_to_cpu(nla_get_be64(nla[NFTA_RULE_POSITION]));
|
|
|
- old_rule = __nf_tables_rule_lookup(chain, pos_handle);
|
|
|
- if (IS_ERR(old_rule))
|
|
|
+ old_rule = __nft_rule_lookup(chain, pos_handle);
|
|
|
+ if (IS_ERR(old_rule)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_POSITION]);
|
|
|
return PTR_ERR(old_rule);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
nft_ctx_init(&ctx, net, skb, nlh, family, table, chain, nla);
|
|
@@ -2440,32 +2453,37 @@ static int nf_tables_delrule(struct net *net, struct sock *nlsk,
|
|
|
int family = nfmsg->nfgen_family, err = 0;
|
|
|
struct nft_ctx ctx;
|
|
|
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_RULE_TABLE], family,
|
|
|
- genmask);
|
|
|
- if (IS_ERR(table))
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_RULE_TABLE], family, genmask);
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_TABLE]);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
|
|
|
if (nla[NFTA_RULE_CHAIN]) {
|
|
|
- chain = nf_tables_chain_lookup(table, nla[NFTA_RULE_CHAIN],
|
|
|
- genmask);
|
|
|
- if (IS_ERR(chain))
|
|
|
+ chain = nft_chain_lookup(table, nla[NFTA_RULE_CHAIN], genmask);
|
|
|
+ if (IS_ERR(chain)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_CHAIN]);
|
|
|
return PTR_ERR(chain);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
nft_ctx_init(&ctx, net, skb, nlh, family, table, chain, nla);
|
|
|
|
|
|
if (chain) {
|
|
|
if (nla[NFTA_RULE_HANDLE]) {
|
|
|
- rule = nf_tables_rule_lookup(chain,
|
|
|
- nla[NFTA_RULE_HANDLE]);
|
|
|
- if (IS_ERR(rule))
|
|
|
+ rule = nft_rule_lookup(chain, nla[NFTA_RULE_HANDLE]);
|
|
|
+ if (IS_ERR(rule)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_HANDLE]);
|
|
|
return PTR_ERR(rule);
|
|
|
+ }
|
|
|
|
|
|
err = nft_delrule(&ctx, rule);
|
|
|
} else if (nla[NFTA_RULE_ID]) {
|
|
|
rule = nft_rule_lookup_byid(net, nla[NFTA_RULE_ID]);
|
|
|
- if (IS_ERR(rule))
|
|
|
+ if (IS_ERR(rule)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_RULE_ID]);
|
|
|
return PTR_ERR(rule);
|
|
|
+ }
|
|
|
|
|
|
err = nft_delrule(&ctx, rule);
|
|
|
} else {
|
|
@@ -2510,14 +2528,12 @@ void nft_unregister_set(struct nft_set_type *type)
|
|
|
EXPORT_SYMBOL_GPL(nft_unregister_set);
|
|
|
|
|
|
#define NFT_SET_FEATURES (NFT_SET_INTERVAL | NFT_SET_MAP | \
|
|
|
- NFT_SET_TIMEOUT | NFT_SET_OBJECT)
|
|
|
+ NFT_SET_TIMEOUT | NFT_SET_OBJECT | \
|
|
|
+ NFT_SET_EVAL)
|
|
|
|
|
|
-static bool nft_set_ops_candidate(const struct nft_set_ops *ops, u32 flags)
|
|
|
+static bool nft_set_ops_candidate(const struct nft_set_type *type, u32 flags)
|
|
|
{
|
|
|
- if ((flags & NFT_SET_EVAL) && !ops->update)
|
|
|
- return false;
|
|
|
-
|
|
|
- return (flags & ops->features) == (flags & NFT_SET_FEATURES);
|
|
|
+ return (flags & type->features) == (flags & NFT_SET_FEATURES);
|
|
|
}
|
|
|
|
|
|
/*
|
|
@@ -2554,14 +2570,9 @@ nft_select_set_ops(const struct nft_ctx *ctx,
|
|
|
best.space = ~0;
|
|
|
|
|
|
list_for_each_entry(type, &nf_tables_set_types, list) {
|
|
|
- if (!type->select_ops)
|
|
|
- ops = type->ops;
|
|
|
- else
|
|
|
- ops = type->select_ops(ctx, desc, flags);
|
|
|
- if (!ops)
|
|
|
- continue;
|
|
|
+ ops = &type->ops;
|
|
|
|
|
|
- if (!nft_set_ops_candidate(ops, flags))
|
|
|
+ if (!nft_set_ops_candidate(type, flags))
|
|
|
continue;
|
|
|
if (!ops->estimate(desc, flags, &est))
|
|
|
continue;
|
|
@@ -2592,7 +2603,7 @@ nft_select_set_ops(const struct nft_ctx *ctx,
|
|
|
if (!try_module_get(type->owner))
|
|
|
continue;
|
|
|
if (bops != NULL)
|
|
|
- module_put(bops->type->owner);
|
|
|
+ module_put(to_set_type(bops)->owner);
|
|
|
|
|
|
bops = ops;
|
|
|
best = est;
|
|
@@ -2633,6 +2644,7 @@ static int nft_ctx_init_from_setattr(struct nft_ctx *ctx, struct net *net,
|
|
|
const struct sk_buff *skb,
|
|
|
const struct nlmsghdr *nlh,
|
|
|
const struct nlattr * const nla[],
|
|
|
+ struct netlink_ext_ack *extack,
|
|
|
u8 genmask)
|
|
|
{
|
|
|
const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
|
|
@@ -2640,18 +2652,20 @@ static int nft_ctx_init_from_setattr(struct nft_ctx *ctx, struct net *net,
|
|
|
struct nft_table *table = NULL;
|
|
|
|
|
|
if (nla[NFTA_SET_TABLE] != NULL) {
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_SET_TABLE],
|
|
|
- family, genmask);
|
|
|
- if (IS_ERR(table))
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_SET_TABLE], family,
|
|
|
+ genmask);
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_SET_TABLE]);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
nft_ctx_init(ctx, net, skb, nlh, family, table, NULL, nla);
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-static struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
|
|
|
- const struct nlattr *nla, u8 genmask)
|
|
|
+static struct nft_set *nft_set_lookup(const struct nft_table *table,
|
|
|
+ const struct nlattr *nla, u8 genmask)
|
|
|
{
|
|
|
struct nft_set *set;
|
|
|
|
|
@@ -2666,14 +2680,12 @@ static struct nft_set *nf_tables_set_lookup(const struct nft_table *table,
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
}
|
|
|
|
|
|
-static struct nft_set *nf_tables_set_lookup_byhandle(const struct nft_table *table,
|
|
|
- const struct nlattr *nla, u8 genmask)
|
|
|
+static struct nft_set *nft_set_lookup_byhandle(const struct nft_table *table,
|
|
|
+ const struct nlattr *nla,
|
|
|
+ u8 genmask)
|
|
|
{
|
|
|
struct nft_set *set;
|
|
|
|
|
|
- if (nla == NULL)
|
|
|
- return ERR_PTR(-EINVAL);
|
|
|
-
|
|
|
list_for_each_entry(set, &table->sets, list) {
|
|
|
if (be64_to_cpu(nla_get_be64(nla)) == set->handle &&
|
|
|
nft_active_genmask(set, genmask))
|
|
@@ -2682,9 +2694,8 @@ static struct nft_set *nf_tables_set_lookup_byhandle(const struct nft_table *tab
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
}
|
|
|
|
|
|
-static struct nft_set *nf_tables_set_lookup_byid(const struct net *net,
|
|
|
- const struct nlattr *nla,
|
|
|
- u8 genmask)
|
|
|
+static struct nft_set *nft_set_lookup_byid(const struct net *net,
|
|
|
+ const struct nlattr *nla, u8 genmask)
|
|
|
{
|
|
|
struct nft_trans *trans;
|
|
|
u32 id = ntohl(nla_get_be32(nla));
|
|
@@ -2708,12 +2719,12 @@ struct nft_set *nft_set_lookup_global(const struct net *net,
|
|
|
{
|
|
|
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 (!nla_set_id)
|
|
|
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;
|
|
|
}
|
|
@@ -2773,6 +2784,27 @@ cont:
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+static int nf_msecs_to_jiffies64(const struct nlattr *nla, u64 *result)
|
|
|
+{
|
|
|
+ u64 ms = be64_to_cpu(nla_get_be64(nla));
|
|
|
+ u64 max = (u64)(~((u64)0));
|
|
|
+
|
|
|
+ max = div_u64(max, NSEC_PER_MSEC);
|
|
|
+ if (ms >= max)
|
|
|
+ return -ERANGE;
|
|
|
+
|
|
|
+ ms *= NSEC_PER_MSEC;
|
|
|
+ *result = nsecs_to_jiffies64(ms);
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+static u64 nf_jiffies64_to_msecs(u64 input)
|
|
|
+{
|
|
|
+ u64 ms = jiffies64_to_nsecs(input);
|
|
|
+
|
|
|
+ return cpu_to_be64(div_u64(ms, NSEC_PER_MSEC));
|
|
|
+}
|
|
|
+
|
|
|
static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
|
|
|
const struct nft_set *set, u16 event, u16 flags)
|
|
|
{
|
|
@@ -2820,7 +2852,7 @@ static int nf_tables_fill_set(struct sk_buff *skb, const struct nft_ctx *ctx,
|
|
|
|
|
|
if (set->timeout &&
|
|
|
nla_put_be64(skb, NFTA_SET_TIMEOUT,
|
|
|
- cpu_to_be64(jiffies_to_msecs(set->timeout)),
|
|
|
+ nf_jiffies64_to_msecs(set->timeout),
|
|
|
NFTA_SET_PAD))
|
|
|
goto nla_put_failure;
|
|
|
if (set->gc_int &&
|
|
@@ -2958,7 +2990,8 @@ static int nf_tables_getset(struct net *net, struct sock *nlsk,
|
|
|
int err;
|
|
|
|
|
|
/* Verify existence before starting dump */
|
|
|
- err = nft_ctx_init_from_setattr(&ctx, net, skb, nlh, nla, genmask);
|
|
|
+ err = nft_ctx_init_from_setattr(&ctx, net, skb, nlh, nla, extack,
|
|
|
+ genmask);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
|
|
@@ -2985,7 +3018,7 @@ static int nf_tables_getset(struct net *net, struct sock *nlsk,
|
|
|
if (!nla[NFTA_SET_TABLE])
|
|
|
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))
|
|
|
return PTR_ERR(set);
|
|
|
|
|
@@ -3115,8 +3148,10 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
|
|
|
if (nla[NFTA_SET_TIMEOUT] != NULL) {
|
|
|
if (!(flags & NFT_SET_TIMEOUT))
|
|
|
return -EINVAL;
|
|
|
- timeout = msecs_to_jiffies(be64_to_cpu(nla_get_be64(
|
|
|
- nla[NFTA_SET_TIMEOUT])));
|
|
|
+
|
|
|
+ err = nf_msecs_to_jiffies64(nla[NFTA_SET_TIMEOUT], &timeout);
|
|
|
+ if (err)
|
|
|
+ return err;
|
|
|
}
|
|
|
gc_int = 0;
|
|
|
if (nla[NFTA_SET_GC_INTERVAL] != NULL) {
|
|
@@ -3137,22 +3172,28 @@ static int nf_tables_newset(struct net *net, struct sock *nlsk,
|
|
|
|
|
|
create = nlh->nlmsg_flags & NLM_F_CREATE ? true : false;
|
|
|
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_SET_TABLE], family,
|
|
|
- genmask);
|
|
|
- if (IS_ERR(table))
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_SET_TABLE], family, genmask);
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_SET_TABLE]);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
|
|
|
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 (PTR_ERR(set) != -ENOENT)
|
|
|
+ if (PTR_ERR(set) != -ENOENT) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_SET_NAME]);
|
|
|
return PTR_ERR(set);
|
|
|
+ }
|
|
|
} else {
|
|
|
- if (nlh->nlmsg_flags & NLM_F_EXCL)
|
|
|
+ if (nlh->nlmsg_flags & NLM_F_EXCL) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_SET_NAME]);
|
|
|
return -EEXIST;
|
|
|
+ }
|
|
|
if (nlh->nlmsg_flags & NLM_F_REPLACE)
|
|
|
return -EOPNOTSUPP;
|
|
|
+
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -3229,14 +3270,14 @@ err3:
|
|
|
err2:
|
|
|
kvfree(set);
|
|
|
err1:
|
|
|
- module_put(ops->type->owner);
|
|
|
+ module_put(to_set_type(ops)->owner);
|
|
|
return err;
|
|
|
}
|
|
|
|
|
|
static void nft_set_destroy(struct nft_set *set)
|
|
|
{
|
|
|
set->ops->destroy(set);
|
|
|
- module_put(set->ops->type->owner);
|
|
|
+ module_put(to_set_type(set->ops)->owner);
|
|
|
kfree(set->name);
|
|
|
kvfree(set);
|
|
|
}
|
|
@@ -3255,6 +3296,7 @@ static int nf_tables_delset(struct net *net, struct sock *nlsk,
|
|
|
{
|
|
|
const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
|
|
|
u8 genmask = nft_genmask_next(net);
|
|
|
+ const struct nlattr *attr;
|
|
|
struct nft_set *set;
|
|
|
struct nft_ctx ctx;
|
|
|
int err;
|
|
@@ -3264,20 +3306,28 @@ static int nf_tables_delset(struct net *net, struct sock *nlsk,
|
|
|
if (nla[NFTA_SET_TABLE] == NULL)
|
|
|
return -EINVAL;
|
|
|
|
|
|
- err = nft_ctx_init_from_setattr(&ctx, net, skb, nlh, nla, genmask);
|
|
|
+ err = nft_ctx_init_from_setattr(&ctx, net, skb, nlh, nla, extack,
|
|
|
+ genmask);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
|
|
|
- if (nla[NFTA_SET_HANDLE])
|
|
|
- set = nf_tables_set_lookup_byhandle(ctx.table, nla[NFTA_SET_HANDLE], genmask);
|
|
|
- else
|
|
|
- set = nf_tables_set_lookup(ctx.table, nla[NFTA_SET_NAME], genmask);
|
|
|
- if (IS_ERR(set))
|
|
|
- return PTR_ERR(set);
|
|
|
+ if (nla[NFTA_SET_HANDLE]) {
|
|
|
+ attr = nla[NFTA_SET_HANDLE];
|
|
|
+ set = nft_set_lookup_byhandle(ctx.table, attr, genmask);
|
|
|
+ } else {
|
|
|
+ attr = nla[NFTA_SET_NAME];
|
|
|
+ set = nft_set_lookup(ctx.table, attr, genmask);
|
|
|
+ }
|
|
|
|
|
|
+ if (IS_ERR(set)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, attr);
|
|
|
+ return PTR_ERR(set);
|
|
|
+ }
|
|
|
if (!list_empty(&set->bindings) ||
|
|
|
- (nlh->nlmsg_flags & NLM_F_NONREC && atomic_read(&set->nelems) > 0))
|
|
|
+ (nlh->nlmsg_flags & NLM_F_NONREC && atomic_read(&set->nelems) > 0)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, attr);
|
|
|
return -EBUSY;
|
|
|
+ }
|
|
|
|
|
|
return nft_delset(&ctx, set);
|
|
|
}
|
|
@@ -3367,8 +3417,8 @@ const struct nft_set_ext_type nft_set_ext_types[] = {
|
|
|
.align = __alignof__(u64),
|
|
|
},
|
|
|
[NFT_SET_EXT_EXPIRATION] = {
|
|
|
- .len = sizeof(unsigned long),
|
|
|
- .align = __alignof__(unsigned long),
|
|
|
+ .len = sizeof(u64),
|
|
|
+ .align = __alignof__(u64),
|
|
|
},
|
|
|
[NFT_SET_EXT_USERDATA] = {
|
|
|
.len = sizeof(struct nft_userdata),
|
|
@@ -3405,16 +3455,19 @@ static int nft_ctx_init_from_elemattr(struct nft_ctx *ctx, struct net *net,
|
|
|
const struct sk_buff *skb,
|
|
|
const struct nlmsghdr *nlh,
|
|
|
const struct nlattr * const nla[],
|
|
|
+ struct netlink_ext_ack *extack,
|
|
|
u8 genmask)
|
|
|
{
|
|
|
const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
|
|
|
int family = nfmsg->nfgen_family;
|
|
|
struct nft_table *table;
|
|
|
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_SET_ELEM_LIST_TABLE],
|
|
|
- family, genmask);
|
|
|
- if (IS_ERR(table))
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_SET_ELEM_LIST_TABLE], family,
|
|
|
+ genmask);
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_SET_ELEM_LIST_TABLE]);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
|
|
|
nft_ctx_init(ctx, net, skb, nlh, family, table, NULL, nla);
|
|
|
return 0;
|
|
@@ -3458,22 +3511,21 @@ static int nf_tables_fill_setelem(struct sk_buff *skb,
|
|
|
|
|
|
if (nft_set_ext_exists(ext, NFT_SET_EXT_TIMEOUT) &&
|
|
|
nla_put_be64(skb, NFTA_SET_ELEM_TIMEOUT,
|
|
|
- cpu_to_be64(jiffies_to_msecs(
|
|
|
- *nft_set_ext_timeout(ext))),
|
|
|
+ nf_jiffies64_to_msecs(*nft_set_ext_timeout(ext)),
|
|
|
NFTA_SET_ELEM_PAD))
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
if (nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION)) {
|
|
|
- unsigned long expires, now = jiffies;
|
|
|
+ u64 expires, now = get_jiffies_64();
|
|
|
|
|
|
expires = *nft_set_ext_expiration(ext);
|
|
|
- if (time_before(now, expires))
|
|
|
+ if (time_before64(now, expires))
|
|
|
expires -= now;
|
|
|
else
|
|
|
expires = 0;
|
|
|
|
|
|
if (nla_put_be64(skb, NFTA_SET_ELEM_EXPIRATION,
|
|
|
- cpu_to_be64(jiffies_to_msecs(expires)),
|
|
|
+ nf_jiffies64_to_msecs(expires),
|
|
|
NFTA_SET_ELEM_PAD))
|
|
|
goto nla_put_failure;
|
|
|
}
|
|
@@ -3744,12 +3796,12 @@ static int nf_tables_getsetelem(struct net *net, struct sock *nlsk,
|
|
|
struct nft_ctx ctx;
|
|
|
int rem, err = 0;
|
|
|
|
|
|
- err = nft_ctx_init_from_elemattr(&ctx, net, skb, nlh, nla, genmask);
|
|
|
+ err = nft_ctx_init_from_elemattr(&ctx, net, skb, nlh, nla, extack,
|
|
|
+ genmask);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
|
|
|
- set = nf_tables_set_lookup(ctx.table, nla[NFTA_SET_ELEM_LIST_SET],
|
|
|
- genmask);
|
|
|
+ set = nft_set_lookup(ctx.table, nla[NFTA_SET_ELEM_LIST_SET], genmask);
|
|
|
if (IS_ERR(set))
|
|
|
return PTR_ERR(set);
|
|
|
|
|
@@ -3848,7 +3900,7 @@ void *nft_set_elem_init(const struct nft_set *set,
|
|
|
memcpy(nft_set_ext_data(ext), data, set->dlen);
|
|
|
if (nft_set_ext_exists(ext, NFT_SET_EXT_EXPIRATION))
|
|
|
*nft_set_ext_expiration(ext) =
|
|
|
- jiffies + timeout;
|
|
|
+ get_jiffies_64() + timeout;
|
|
|
if (nft_set_ext_exists(ext, NFT_SET_EXT_TIMEOUT))
|
|
|
*nft_set_ext_timeout(ext) = timeout;
|
|
|
|
|
@@ -3935,8 +3987,10 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
|
|
|
if (nla[NFTA_SET_ELEM_TIMEOUT] != NULL) {
|
|
|
if (!(set->flags & NFT_SET_TIMEOUT))
|
|
|
return -EINVAL;
|
|
|
- timeout = msecs_to_jiffies(be64_to_cpu(nla_get_be64(
|
|
|
- nla[NFTA_SET_ELEM_TIMEOUT])));
|
|
|
+ err = nf_msecs_to_jiffies64(nla[NFTA_SET_ELEM_TIMEOUT],
|
|
|
+ &timeout);
|
|
|
+ if (err)
|
|
|
+ return err;
|
|
|
} else if (set->flags & NFT_SET_TIMEOUT) {
|
|
|
timeout = set->timeout;
|
|
|
}
|
|
@@ -3961,8 +4015,8 @@ static int nft_add_set_elem(struct nft_ctx *ctx, struct nft_set *set,
|
|
|
err = -EINVAL;
|
|
|
goto err2;
|
|
|
}
|
|
|
- obj = nf_tables_obj_lookup(ctx->table, nla[NFTA_SET_ELEM_OBJREF],
|
|
|
- set->objtype, genmask);
|
|
|
+ obj = nft_obj_lookup(ctx->table, nla[NFTA_SET_ELEM_OBJREF],
|
|
|
+ set->objtype, genmask);
|
|
|
if (IS_ERR(obj)) {
|
|
|
err = PTR_ERR(obj);
|
|
|
goto err2;
|
|
@@ -4099,7 +4153,8 @@ static int nf_tables_newsetelem(struct net *net, struct sock *nlsk,
|
|
|
if (nla[NFTA_SET_ELEM_LIST_ELEMENTS] == NULL)
|
|
|
return -EINVAL;
|
|
|
|
|
|
- err = nft_ctx_init_from_elemattr(&ctx, net, skb, nlh, nla, genmask);
|
|
|
+ err = nft_ctx_init_from_elemattr(&ctx, net, skb, nlh, nla, extack,
|
|
|
+ genmask);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
|
|
@@ -4287,12 +4342,12 @@ static int nf_tables_delsetelem(struct net *net, struct sock *nlsk,
|
|
|
struct nft_ctx ctx;
|
|
|
int rem, err = 0;
|
|
|
|
|
|
- err = nft_ctx_init_from_elemattr(&ctx, net, skb, nlh, nla, genmask);
|
|
|
+ err = nft_ctx_init_from_elemattr(&ctx, net, skb, nlh, nla, extack,
|
|
|
+ genmask);
|
|
|
if (err < 0)
|
|
|
return err;
|
|
|
|
|
|
- set = nf_tables_set_lookup(ctx.table, nla[NFTA_SET_ELEM_LIST_SET],
|
|
|
- genmask);
|
|
|
+ set = nft_set_lookup(ctx.table, nla[NFTA_SET_ELEM_LIST_SET], genmask);
|
|
|
if (IS_ERR(set))
|
|
|
return PTR_ERR(set);
|
|
|
if (!list_empty(&set->bindings) && set->flags & NFT_SET_CONSTANT)
|
|
@@ -4380,9 +4435,9 @@ void nft_unregister_obj(struct nft_object_type *obj_type)
|
|
|
}
|
|
|
EXPORT_SYMBOL_GPL(nft_unregister_obj);
|
|
|
|
|
|
-struct nft_object *nf_tables_obj_lookup(const struct nft_table *table,
|
|
|
- const struct nlattr *nla,
|
|
|
- u32 objtype, u8 genmask)
|
|
|
+struct nft_object *nft_obj_lookup(const struct nft_table *table,
|
|
|
+ const struct nlattr *nla, u32 objtype,
|
|
|
+ u8 genmask)
|
|
|
{
|
|
|
struct nft_object *obj;
|
|
|
|
|
@@ -4394,11 +4449,11 @@ struct nft_object *nf_tables_obj_lookup(const struct nft_table *table,
|
|
|
}
|
|
|
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,
|
|
|
- const struct nlattr *nla,
|
|
|
- u32 objtype, u8 genmask)
|
|
|
+static struct nft_object *nft_obj_lookup_byhandle(const struct nft_table *table,
|
|
|
+ const struct nlattr *nla,
|
|
|
+ u32 objtype, u8 genmask)
|
|
|
{
|
|
|
struct nft_object *obj;
|
|
|
|
|
@@ -4542,22 +4597,25 @@ static int nf_tables_newobj(struct net *net, struct sock *nlsk,
|
|
|
!nla[NFTA_OBJ_DATA])
|
|
|
return -EINVAL;
|
|
|
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_OBJ_TABLE], family,
|
|
|
- genmask);
|
|
|
- if (IS_ERR(table))
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_OBJ_TABLE], family, genmask);
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_OBJ_TABLE]);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
|
|
|
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)) {
|
|
|
err = PTR_ERR(obj);
|
|
|
- if (err != -ENOENT)
|
|
|
+ if (err != -ENOENT) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_OBJ_NAME]);
|
|
|
return err;
|
|
|
-
|
|
|
+ }
|
|
|
} else {
|
|
|
- if (nlh->nlmsg_flags & NLM_F_EXCL)
|
|
|
+ if (nlh->nlmsg_flags & NLM_F_EXCL) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_OBJ_NAME]);
|
|
|
return -EEXIST;
|
|
|
-
|
|
|
+ }
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
@@ -4768,15 +4826,18 @@ static int nf_tables_getobj(struct net *net, struct sock *nlsk,
|
|
|
!nla[NFTA_OBJ_TYPE])
|
|
|
return -EINVAL;
|
|
|
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_OBJ_TABLE], family,
|
|
|
- genmask);
|
|
|
- if (IS_ERR(table))
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_OBJ_TABLE], family, genmask);
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_OBJ_TABLE]);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
|
|
|
objtype = ntohl(nla_get_be32(nla[NFTA_OBJ_TYPE]));
|
|
|
- obj = nf_tables_obj_lookup(table, nla[NFTA_OBJ_NAME], objtype, genmask);
|
|
|
- if (IS_ERR(obj))
|
|
|
+ obj = nft_obj_lookup(table, nla[NFTA_OBJ_NAME], objtype, genmask);
|
|
|
+ if (IS_ERR(obj)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_OBJ_NAME]);
|
|
|
return PTR_ERR(obj);
|
|
|
+ }
|
|
|
|
|
|
skb2 = alloc_skb(NLMSG_GOODSIZE, GFP_KERNEL);
|
|
|
if (!skb2)
|
|
@@ -4815,6 +4876,7 @@ static int nf_tables_delobj(struct net *net, struct sock *nlsk,
|
|
|
const struct nfgenmsg *nfmsg = nlmsg_data(nlh);
|
|
|
u8 genmask = nft_genmask_next(net);
|
|
|
int family = nfmsg->nfgen_family;
|
|
|
+ const struct nlattr *attr;
|
|
|
struct nft_table *table;
|
|
|
struct nft_object *obj;
|
|
|
struct nft_ctx ctx;
|
|
@@ -4824,22 +4886,29 @@ static int nf_tables_delobj(struct net *net, struct sock *nlsk,
|
|
|
(!nla[NFTA_OBJ_NAME] && !nla[NFTA_OBJ_HANDLE]))
|
|
|
return -EINVAL;
|
|
|
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_OBJ_TABLE], family,
|
|
|
- genmask);
|
|
|
- if (IS_ERR(table))
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_OBJ_TABLE], family, genmask);
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_OBJ_TABLE]);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
|
|
|
objtype = ntohl(nla_get_be32(nla[NFTA_OBJ_TYPE]));
|
|
|
- if (nla[NFTA_OBJ_HANDLE])
|
|
|
- obj = nf_tables_obj_lookup_byhandle(table, nla[NFTA_OBJ_HANDLE],
|
|
|
- objtype, genmask);
|
|
|
- else
|
|
|
- obj = nf_tables_obj_lookup(table, nla[NFTA_OBJ_NAME],
|
|
|
- objtype, genmask);
|
|
|
- if (IS_ERR(obj))
|
|
|
+ if (nla[NFTA_OBJ_HANDLE]) {
|
|
|
+ attr = nla[NFTA_OBJ_HANDLE];
|
|
|
+ obj = nft_obj_lookup_byhandle(table, attr, objtype, genmask);
|
|
|
+ } else {
|
|
|
+ attr = nla[NFTA_OBJ_NAME];
|
|
|
+ obj = nft_obj_lookup(table, attr, objtype, genmask);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (IS_ERR(obj)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, attr);
|
|
|
return PTR_ERR(obj);
|
|
|
- if (obj->use > 0)
|
|
|
+ }
|
|
|
+ if (obj->use > 0) {
|
|
|
+ NL_SET_BAD_ATTR(extack, attr);
|
|
|
return -EBUSY;
|
|
|
+ }
|
|
|
|
|
|
nft_ctx_init(&ctx, net, skb, nlh, family, table, NULL, nla);
|
|
|
|
|
@@ -4910,9 +4979,8 @@ static const struct nla_policy nft_flowtable_policy[NFTA_FLOWTABLE_MAX + 1] = {
|
|
|
[NFTA_FLOWTABLE_HANDLE] = { .type = NLA_U64 },
|
|
|
};
|
|
|
|
|
|
-struct nft_flowtable *nf_tables_flowtable_lookup(const struct nft_table *table,
|
|
|
- const struct nlattr *nla,
|
|
|
- u8 genmask)
|
|
|
+struct nft_flowtable *nft_flowtable_lookup(const struct nft_table *table,
|
|
|
+ const struct nlattr *nla, u8 genmask)
|
|
|
{
|
|
|
struct nft_flowtable *flowtable;
|
|
|
|
|
@@ -4923,11 +4991,11 @@ struct nft_flowtable *nf_tables_flowtable_lookup(const struct nft_table *table,
|
|
|
}
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
}
|
|
|
-EXPORT_SYMBOL_GPL(nf_tables_flowtable_lookup);
|
|
|
+EXPORT_SYMBOL_GPL(nft_flowtable_lookup);
|
|
|
|
|
|
static struct nft_flowtable *
|
|
|
-nf_tables_flowtable_lookup_byhandle(const struct nft_table *table,
|
|
|
- const struct nlattr *nla, u8 genmask)
|
|
|
+nft_flowtable_lookup_byhandle(const struct nft_table *table,
|
|
|
+ const struct nlattr *nla, u8 genmask)
|
|
|
{
|
|
|
struct nft_flowtable *flowtable;
|
|
|
|
|
@@ -5026,7 +5094,7 @@ static int nf_tables_flowtable_parse_hook(const struct nft_ctx *ctx,
|
|
|
flowtable->ops[i].pf = NFPROTO_NETDEV;
|
|
|
flowtable->ops[i].hooknum = hooknum;
|
|
|
flowtable->ops[i].priority = priority;
|
|
|
- flowtable->ops[i].priv = &flowtable->data.rhashtable;
|
|
|
+ flowtable->ops[i].priv = &flowtable->data;
|
|
|
flowtable->ops[i].hook = flowtable->data.type->hook;
|
|
|
flowtable->ops[i].dev = dev_array[i];
|
|
|
flowtable->dev_name[i] = kstrdup(dev_array[i]->name,
|
|
@@ -5067,23 +5135,6 @@ static const struct nf_flowtable_type *nft_flowtable_type_get(u8 family)
|
|
|
return ERR_PTR(-ENOENT);
|
|
|
}
|
|
|
|
|
|
-void nft_flow_table_iterate(struct net *net,
|
|
|
- void (*iter)(struct nf_flowtable *flowtable, void *data),
|
|
|
- void *data)
|
|
|
-{
|
|
|
- struct nft_flowtable *flowtable;
|
|
|
- const struct nft_table *table;
|
|
|
-
|
|
|
- nfnl_lock(NFNL_SUBSYS_NFTABLES);
|
|
|
- list_for_each_entry(table, &net->nft.tables, list) {
|
|
|
- list_for_each_entry(flowtable, &table->flowtables, list) {
|
|
|
- iter(&flowtable->data, data);
|
|
|
- }
|
|
|
- }
|
|
|
- nfnl_unlock(NFNL_SUBSYS_NFTABLES);
|
|
|
-}
|
|
|
-EXPORT_SYMBOL_GPL(nft_flow_table_iterate);
|
|
|
-
|
|
|
static void nft_unregister_flowtable_net_hooks(struct net *net,
|
|
|
struct nft_flowtable *flowtable)
|
|
|
{
|
|
@@ -5117,20 +5168,26 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk,
|
|
|
!nla[NFTA_FLOWTABLE_HOOK])
|
|
|
return -EINVAL;
|
|
|
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE],
|
|
|
- family, genmask);
|
|
|
- if (IS_ERR(table))
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE], family,
|
|
|
+ genmask);
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_FLOWTABLE_TABLE]);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
|
|
|
- flowtable = nf_tables_flowtable_lookup(table, nla[NFTA_FLOWTABLE_NAME],
|
|
|
- genmask);
|
|
|
+ flowtable = nft_flowtable_lookup(table, nla[NFTA_FLOWTABLE_NAME],
|
|
|
+ genmask);
|
|
|
if (IS_ERR(flowtable)) {
|
|
|
err = PTR_ERR(flowtable);
|
|
|
- if (err != -ENOENT)
|
|
|
+ if (err != -ENOENT) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_FLOWTABLE_NAME]);
|
|
|
return err;
|
|
|
+ }
|
|
|
} else {
|
|
|
- if (nlh->nlmsg_flags & NLM_F_EXCL)
|
|
|
+ if (nlh->nlmsg_flags & NLM_F_EXCL) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_FLOWTABLE_NAME]);
|
|
|
return -EEXIST;
|
|
|
+ }
|
|
|
|
|
|
return 0;
|
|
|
}
|
|
@@ -5157,14 +5214,14 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk,
|
|
|
}
|
|
|
|
|
|
flowtable->data.type = type;
|
|
|
- err = rhashtable_init(&flowtable->data.rhashtable, type->params);
|
|
|
+ err = type->init(&flowtable->data);
|
|
|
if (err < 0)
|
|
|
goto err3;
|
|
|
|
|
|
err = nf_tables_flowtable_parse_hook(&ctx, nla[NFTA_FLOWTABLE_HOOK],
|
|
|
flowtable);
|
|
|
if (err < 0)
|
|
|
- goto err3;
|
|
|
+ goto err4;
|
|
|
|
|
|
for (i = 0; i < flowtable->ops_len; i++) {
|
|
|
if (!flowtable->ops[i].dev)
|
|
@@ -5178,37 +5235,35 @@ static int nf_tables_newflowtable(struct net *net, struct sock *nlsk,
|
|
|
if (flowtable->ops[i].dev == ft->ops[k].dev &&
|
|
|
flowtable->ops[i].pf == ft->ops[k].pf) {
|
|
|
err = -EBUSY;
|
|
|
- goto err4;
|
|
|
+ goto err5;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
err = nf_register_net_hook(net, &flowtable->ops[i]);
|
|
|
if (err < 0)
|
|
|
- goto err4;
|
|
|
+ goto err5;
|
|
|
}
|
|
|
|
|
|
err = nft_trans_flowtable_add(&ctx, NFT_MSG_NEWFLOWTABLE, flowtable);
|
|
|
if (err < 0)
|
|
|
- goto err5;
|
|
|
-
|
|
|
- INIT_DEFERRABLE_WORK(&flowtable->data.gc_work, type->gc);
|
|
|
- queue_delayed_work(system_power_efficient_wq,
|
|
|
- &flowtable->data.gc_work, HZ);
|
|
|
+ goto err6;
|
|
|
|
|
|
list_add_tail_rcu(&flowtable->list, &table->flowtables);
|
|
|
table->use++;
|
|
|
|
|
|
return 0;
|
|
|
-err5:
|
|
|
+err6:
|
|
|
i = flowtable->ops_len;
|
|
|
-err4:
|
|
|
+err5:
|
|
|
for (k = i - 1; k >= 0; k--) {
|
|
|
kfree(flowtable->dev_name[k]);
|
|
|
nf_unregister_net_hook(net, &flowtable->ops[k]);
|
|
|
}
|
|
|
|
|
|
kfree(flowtable->ops);
|
|
|
+err4:
|
|
|
+ flowtable->data.type->free(&flowtable->data);
|
|
|
err3:
|
|
|
module_put(type->owner);
|
|
|
err2:
|
|
@@ -5228,6 +5283,7 @@ static int nf_tables_delflowtable(struct net *net, struct sock *nlsk,
|
|
|
u8 genmask = nft_genmask_next(net);
|
|
|
int family = nfmsg->nfgen_family;
|
|
|
struct nft_flowtable *flowtable;
|
|
|
+ const struct nlattr *attr;
|
|
|
struct nft_table *table;
|
|
|
struct nft_ctx ctx;
|
|
|
|
|
@@ -5236,23 +5292,29 @@ static int nf_tables_delflowtable(struct net *net, struct sock *nlsk,
|
|
|
!nla[NFTA_FLOWTABLE_HANDLE]))
|
|
|
return -EINVAL;
|
|
|
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE],
|
|
|
- family, genmask);
|
|
|
- if (IS_ERR(table))
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE], family,
|
|
|
+ genmask);
|
|
|
+ if (IS_ERR(table)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, nla[NFTA_FLOWTABLE_TABLE]);
|
|
|
return PTR_ERR(table);
|
|
|
+ }
|
|
|
|
|
|
- if (nla[NFTA_FLOWTABLE_HANDLE])
|
|
|
- flowtable = nf_tables_flowtable_lookup_byhandle(table,
|
|
|
- nla[NFTA_FLOWTABLE_HANDLE],
|
|
|
- genmask);
|
|
|
- else
|
|
|
- flowtable = nf_tables_flowtable_lookup(table,
|
|
|
- nla[NFTA_FLOWTABLE_NAME],
|
|
|
- genmask);
|
|
|
- if (IS_ERR(flowtable))
|
|
|
- return PTR_ERR(flowtable);
|
|
|
- if (flowtable->use > 0)
|
|
|
+ if (nla[NFTA_FLOWTABLE_HANDLE]) {
|
|
|
+ attr = nla[NFTA_FLOWTABLE_HANDLE];
|
|
|
+ flowtable = nft_flowtable_lookup_byhandle(table, attr, genmask);
|
|
|
+ } else {
|
|
|
+ attr = nla[NFTA_FLOWTABLE_NAME];
|
|
|
+ flowtable = nft_flowtable_lookup(table, attr, genmask);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (IS_ERR(flowtable)) {
|
|
|
+ NL_SET_BAD_ATTR(extack, attr);
|
|
|
+ return PTR_ERR(flowtable);
|
|
|
+ }
|
|
|
+ if (flowtable->use > 0) {
|
|
|
+ NL_SET_BAD_ATTR(extack, attr);
|
|
|
return -EBUSY;
|
|
|
+ }
|
|
|
|
|
|
nft_ctx_init(&ctx, net, skb, nlh, family, table, NULL, nla);
|
|
|
|
|
@@ -5433,13 +5495,13 @@ static int nf_tables_getflowtable(struct net *net, struct sock *nlsk,
|
|
|
if (!nla[NFTA_FLOWTABLE_NAME])
|
|
|
return -EINVAL;
|
|
|
|
|
|
- table = nf_tables_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE],
|
|
|
- family, genmask);
|
|
|
+ table = nft_table_lookup(net, nla[NFTA_FLOWTABLE_TABLE], family,
|
|
|
+ genmask);
|
|
|
if (IS_ERR(table))
|
|
|
return PTR_ERR(table);
|
|
|
|
|
|
- flowtable = nf_tables_flowtable_lookup(table, nla[NFTA_FLOWTABLE_NAME],
|
|
|
- genmask);
|
|
|
+ flowtable = nft_flowtable_lookup(table, nla[NFTA_FLOWTABLE_NAME],
|
|
|
+ genmask);
|
|
|
if (IS_ERR(flowtable))
|
|
|
return PTR_ERR(flowtable);
|
|
|
|
|
@@ -5492,11 +5554,9 @@ err:
|
|
|
|
|
|
static void nf_tables_flowtable_destroy(struct nft_flowtable *flowtable)
|
|
|
{
|
|
|
- cancel_delayed_work_sync(&flowtable->data.gc_work);
|
|
|
kfree(flowtable->ops);
|
|
|
kfree(flowtable->name);
|
|
|
flowtable->data.type->free(&flowtable->data);
|
|
|
- rhashtable_destroy(&flowtable->data.rhashtable);
|
|
|
module_put(flowtable->data.type->owner);
|
|
|
}
|
|
|
|
|
@@ -6410,8 +6470,8 @@ static int nft_verdict_init(const struct nft_ctx *ctx, struct nft_data *data,
|
|
|
case NFT_GOTO:
|
|
|
if (!tb[NFTA_VERDICT_CHAIN])
|
|
|
return -EINVAL;
|
|
|
- chain = nf_tables_chain_lookup(ctx->table,
|
|
|
- tb[NFTA_VERDICT_CHAIN], genmask);
|
|
|
+ chain = nft_chain_lookup(ctx->table, tb[NFTA_VERDICT_CHAIN],
|
|
|
+ genmask);
|
|
|
if (IS_ERR(chain))
|
|
|
return PTR_ERR(chain);
|
|
|
if (nft_is_base_chain(chain))
|