Skip to content

Commit 983c4fc

Browse files
committed
netfilter: nf_tables: extended netlink error reporting for chain type
Users that forget to select the NAT chain type in netfilter's Kconfig hit ENOENT when adding the basechain. This report is however sparse since it might be the table, the chain or the kernel module that is missing/does not exist. This patch provides extended netlink error reporting for the NFTA_CHAIN_TYPE netlink attribute, which conveys the basechain type. If the user selects a basechain that his custom kernel does not support, the netlink extended error provides a more accurate hint on the described issue. Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent c781471 commit 983c4fc

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

net/netfilter/nf_tables_api.c

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1905,7 +1905,7 @@ static int nft_chain_parse_netdev(struct net *net,
19051905
static int nft_chain_parse_hook(struct net *net,
19061906
const struct nlattr * const nla[],
19071907
struct nft_chain_hook *hook, u8 family,
1908-
bool autoload)
1908+
struct netlink_ext_ack *extack, bool autoload)
19091909
{
19101910
struct nftables_pernet *nft_net = nft_pernet(net);
19111911
struct nlattr *ha[NFTA_HOOK_MAX + 1];
@@ -1935,8 +1935,10 @@ static int nft_chain_parse_hook(struct net *net,
19351935
if (nla[NFTA_CHAIN_TYPE]) {
19361936
type = nf_tables_chain_type_lookup(net, nla[NFTA_CHAIN_TYPE],
19371937
family, autoload);
1938-
if (IS_ERR(type))
1938+
if (IS_ERR(type)) {
1939+
NL_SET_BAD_ATTR(extack, nla[NFTA_CHAIN_TYPE]);
19391940
return PTR_ERR(type);
1941+
}
19401942
}
19411943
if (hook->num >= NFT_MAX_HOOKS || !(type->hook_mask & (1 << hook->num)))
19421944
return -EOPNOTSUPP;
@@ -1945,8 +1947,11 @@ static int nft_chain_parse_hook(struct net *net,
19451947
hook->priority <= NF_IP_PRI_CONNTRACK)
19461948
return -EOPNOTSUPP;
19471949

1948-
if (!try_module_get(type->owner))
1950+
if (!try_module_get(type->owner)) {
1951+
if (nla[NFTA_CHAIN_TYPE])
1952+
NL_SET_BAD_ATTR(extack, nla[NFTA_CHAIN_TYPE]);
19491953
return -ENOENT;
1954+
}
19501955

19511956
hook->type = type;
19521957

@@ -2057,7 +2062,8 @@ static int nft_chain_add(struct nft_table *table, struct nft_chain *chain)
20572062
static u64 chain_id;
20582063

20592064
static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
2060-
u8 policy, u32 flags)
2065+
u8 policy, u32 flags,
2066+
struct netlink_ext_ack *extack)
20612067
{
20622068
const struct nlattr * const *nla = ctx->nla;
20632069
struct nft_table *table = ctx->table;
@@ -2079,7 +2085,8 @@ static int nf_tables_addchain(struct nft_ctx *ctx, u8 family, u8 genmask,
20792085
if (flags & NFT_CHAIN_BINDING)
20802086
return -EOPNOTSUPP;
20812087

2082-
err = nft_chain_parse_hook(net, nla, &hook, family, true);
2088+
err = nft_chain_parse_hook(net, nla, &hook, family, extack,
2089+
true);
20832090
if (err < 0)
20842091
return err;
20852092

@@ -2234,7 +2241,7 @@ static int nf_tables_updchain(struct nft_ctx *ctx, u8 genmask, u8 policy,
22342241
return -EEXIST;
22352242
}
22362243
err = nft_chain_parse_hook(ctx->net, nla, &hook, ctx->family,
2237-
false);
2244+
extack, false);
22382245
if (err < 0)
22392246
return err;
22402247

@@ -2447,7 +2454,7 @@ static int nf_tables_newchain(struct sk_buff *skb, const struct nfnl_info *info,
24472454
extack);
24482455
}
24492456

2450-
return nf_tables_addchain(&ctx, family, genmask, policy, flags);
2457+
return nf_tables_addchain(&ctx, family, genmask, policy, flags, extack);
24512458
}
24522459

24532460
static int nf_tables_delchain(struct sk_buff *skb, const struct nfnl_info *info,

0 commit comments

Comments
 (0)