Skip to content

Commit

Permalink
netfilter: nf_tables_offload: unbind if multi-device binding fails
Browse files Browse the repository at this point in the history
nft_flow_block_chain() needs to unbind in case of error when performing
the multi-device binding.

Fixes: d54725c ("netfilter: nf_tables: support for multiple devices per netdev hook")
Reported-by: wenxu <wenxu@ucloud.cn>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
  • Loading branch information
Pablo Neira Ayuso committed Oct 26, 2019
1 parent 75ceaf8 commit 671312e
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions net/netfilter/nf_tables_offload.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,19 +336,34 @@ static int nft_flow_block_chain(struct nft_base_chain *basechain,
{
struct net_device *dev;
struct nft_hook *hook;
int err;
int err, i = 0;

list_for_each_entry(hook, &basechain->hook_list, list) {
dev = hook->ops.dev;
if (this_dev && this_dev != dev)
continue;

err = nft_chain_offload_cmd(basechain, dev, cmd);
if (err < 0)
if (err < 0 && cmd == FLOW_BLOCK_BIND) {
if (!this_dev)
goto err_flow_block;

return err;
}
i++;
}

return 0;

err_flow_block:
list_for_each_entry(hook, &basechain->hook_list, list) {
if (i-- <= 0)
break;

dev = hook->ops.dev;
nft_chain_offload_cmd(basechain, dev, FLOW_BLOCK_UNBIND);
}
return err;
}

static int nft_flow_offload_chain(struct nft_chain *chain, u8 *ppolicy,
Expand Down

0 comments on commit 671312e

Please sign in to comment.