Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

netfilter: nft_tunnel: fix geneve_opt dump

When dumping a nft_tunnel with more than one geneve_opt configured the
netlink attribute hierarchy should be as follow:

NFTA_TUNNEL_KEY_OPTS
|
|--NFTA_TUNNEL_KEY_OPTS_GENEVE
| |
| |--NFTA_TUNNEL_KEY_GENEVE_CLASS
| |--NFTA_TUNNEL_KEY_GENEVE_TYPE
| |--NFTA_TUNNEL_KEY_GENEVE_DATA
|
|--NFTA_TUNNEL_KEY_OPTS_GENEVE
| |
| |--NFTA_TUNNEL_KEY_GENEVE_CLASS
| |--NFTA_TUNNEL_KEY_GENEVE_TYPE
| |--NFTA_TUNNEL_KEY_GENEVE_DATA
|
|--NFTA_TUNNEL_KEY_OPTS_GENEVE
...

Otherwise, userspace tools won't be able to fetch the geneve options
configured correctly.

Fixes: 925d844696d9 ("netfilter: nft_tunnel: add support for geneve opts")
Signed-off-by: Fernando Fernandez Mancera <fmancera@suse.de>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>

authored by

Fernando Fernandez Mancera and committed by
Pablo Neira Ayuso
22a9613d 996d62ec

+4 -4
+4 -4
net/netfilter/nft_tunnel.c
··· 621 621 struct geneve_opt *opt; 622 622 int offset = 0; 623 623 624 - inner = nla_nest_start_noflag(skb, NFTA_TUNNEL_KEY_OPTS_GENEVE); 625 - if (!inner) 626 - goto failure; 627 624 while (opts->len > offset) { 625 + inner = nla_nest_start_noflag(skb, NFTA_TUNNEL_KEY_OPTS_GENEVE); 626 + if (!inner) 627 + goto failure; 628 628 opt = (struct geneve_opt *)(opts->u.data + offset); 629 629 if (nla_put_be16(skb, NFTA_TUNNEL_KEY_GENEVE_CLASS, 630 630 opt->opt_class) || ··· 634 634 opt->length * 4, opt->opt_data)) 635 635 goto inner_failure; 636 636 offset += sizeof(*opt) + opt->length * 4; 637 + nla_nest_end(skb, inner); 637 638 } 638 - nla_nest_end(skb, inner); 639 639 } 640 640 nla_nest_end(skb, nest); 641 641 return 0;