Commit 504882db authored by wenxu's avatar wenxu Committed by Pablo Neira Ayuso

netfilter: nf_tables_offload: add __nft_offload_get_chain function

Add __nft_offload_get_chain function to get basechain from device. This
function requires that caller holds the per-netns nftables mutex. This
patch implicitly fixes missing offload flags check and proper mutex from
nft_indr_block_cb().

Fixes: 9a32669f ("netfilter: nf_tables_offload: support indr block call")
Signed-off-by: default avatarwenxu <wenxu@ucloud.cn>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent be2861dc
...@@ -369,33 +369,49 @@ int nft_flow_rule_offload_commit(struct net *net) ...@@ -369,33 +369,49 @@ int nft_flow_rule_offload_commit(struct net *net)
return err; return err;
} }
static void nft_indr_block_cb(struct net_device *dev, static struct nft_chain *__nft_offload_get_chain(struct net_device *dev)
flow_indr_block_bind_cb_t *cb, void *cb_priv,
enum flow_block_command command)
{ {
struct nft_base_chain *basechain;
struct net *net = dev_net(dev); struct net *net = dev_net(dev);
const struct nft_table *table; const struct nft_table *table;
const struct nft_chain *chain; struct nft_chain *chain;
list_for_each_entry_rcu(table, &net->nft.tables, list) { list_for_each_entry(table, &net->nft.tables, list) {
if (table->family != NFPROTO_NETDEV) if (table->family != NFPROTO_NETDEV)
continue; continue;
list_for_each_entry_rcu(chain, &table->chains, list) { list_for_each_entry(chain, &table->chains, list) {
if (nft_is_base_chain(chain)) { if (!nft_is_base_chain(chain) ||
struct nft_base_chain *basechain; !(chain->flags & NFT_CHAIN_HW_OFFLOAD))
continue;
basechain = nft_base_chain(chain);
if (!strncmp(basechain->dev_name, dev->name, basechain = nft_base_chain(chain);
IFNAMSIZ)) { if (strncmp(basechain->dev_name, dev->name, IFNAMSIZ))
nft_indr_block_ing_cmd(dev, basechain, continue;
cb, cb_priv,
command); return chain;
return;
}
}
} }
} }
return NULL;
}
static void nft_indr_block_cb(struct net_device *dev,
flow_indr_block_bind_cb_t *cb, void *cb_priv,
enum flow_block_command cmd)
{
struct net *net = dev_net(dev);
struct nft_chain *chain;
mutex_lock(&net->nft.commit_mutex);
chain = __nft_offload_get_chain(dev);
if (chain) {
struct nft_base_chain *basechain;
basechain = nft_base_chain(chain);
nft_indr_block_ing_cmd(dev, basechain, cb, cb_priv, cmd);
}
mutex_unlock(&net->nft.commit_mutex);
} }
static struct flow_indr_block_ing_entry block_ing_entry = { static struct flow_indr_block_ing_entry block_ing_entry = {
......
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