1 From ee496694b9eea651ae1aa4c4667d886cdf74aa3b Mon Sep 17 00:00:00 2001
2 From: Hangbin Liu <liuhangbin@gmail.com>
3 Date: Sat, 3 Dec 2022 11:28:58 +0800
4 Subject: ip_gre: do not report erspan version on GRE interface
6 From: Hangbin Liu <liuhangbin@gmail.com>
8 commit ee496694b9eea651ae1aa4c4667d886cdf74aa3b upstream.
10 Although the type I ERSPAN is based on the barebones IP + GRE
11 encapsulation and no extra ERSPAN header. Report erspan version on GRE
12 interface looks unreasonable. Fix this by separating the erspan and gre
15 IPv6 GRE does not have this info as IPv6 only supports erspan version
18 Reported-by: Jianlin Shi <jishi@redhat.com>
19 Fixes: f989d546a2d5 ("erspan: Add type I version 0 support.")
20 Signed-off-by: Hangbin Liu <liuhangbin@gmail.com>
21 Acked-by: William Tu <u9012063@gmail.com>
22 Link: https://lore.kernel.org/r/20221203032858.3130339-1-liuhangbin@gmail.com
23 Signed-off-by: Paolo Abeni <pabeni@redhat.com>
24 Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
26 net/ipv4/ip_gre.c | 48 +++++++++++++++++++++++++++++-------------------
27 1 file changed, 29 insertions(+), 19 deletions(-)
29 --- a/net/ipv4/ip_gre.c
30 +++ b/net/ipv4/ip_gre.c
31 @@ -1504,24 +1504,6 @@ static int ipgre_fill_info(struct sk_buf
32 struct ip_tunnel_parm *p = &t->parms;
33 __be16 o_flags = p->o_flags;
35 - if (t->erspan_ver <= 2) {
36 - if (t->erspan_ver != 0 && !t->collect_md)
37 - o_flags |= TUNNEL_KEY;
39 - if (nla_put_u8(skb, IFLA_GRE_ERSPAN_VER, t->erspan_ver))
40 - goto nla_put_failure;
42 - if (t->erspan_ver == 1) {
43 - if (nla_put_u32(skb, IFLA_GRE_ERSPAN_INDEX, t->index))
44 - goto nla_put_failure;
45 - } else if (t->erspan_ver == 2) {
46 - if (nla_put_u8(skb, IFLA_GRE_ERSPAN_DIR, t->dir))
47 - goto nla_put_failure;
48 - if (nla_put_u16(skb, IFLA_GRE_ERSPAN_HWID, t->hwid))
49 - goto nla_put_failure;
53 if (nla_put_u32(skb, IFLA_GRE_LINK, p->link) ||
54 nla_put_be16(skb, IFLA_GRE_IFLAGS,
55 gre_tnl_flags_to_gre_flags(p->i_flags)) ||
56 @@ -1562,6 +1544,34 @@ nla_put_failure:
60 +static int erspan_fill_info(struct sk_buff *skb, const struct net_device *dev)
62 + struct ip_tunnel *t = netdev_priv(dev);
64 + if (t->erspan_ver <= 2) {
65 + if (t->erspan_ver != 0 && !t->collect_md)
66 + t->parms.o_flags |= TUNNEL_KEY;
68 + if (nla_put_u8(skb, IFLA_GRE_ERSPAN_VER, t->erspan_ver))
69 + goto nla_put_failure;
71 + if (t->erspan_ver == 1) {
72 + if (nla_put_u32(skb, IFLA_GRE_ERSPAN_INDEX, t->index))
73 + goto nla_put_failure;
74 + } else if (t->erspan_ver == 2) {
75 + if (nla_put_u8(skb, IFLA_GRE_ERSPAN_DIR, t->dir))
76 + goto nla_put_failure;
77 + if (nla_put_u16(skb, IFLA_GRE_ERSPAN_HWID, t->hwid))
78 + goto nla_put_failure;
82 + return ipgre_fill_info(skb, dev);
88 static void erspan_setup(struct net_device *dev)
90 struct ip_tunnel *t = netdev_priv(dev);
91 @@ -1640,7 +1650,7 @@ static struct rtnl_link_ops erspan_link_
92 .changelink = erspan_changelink,
93 .dellink = ip_tunnel_dellink,
94 .get_size = ipgre_get_size,
95 - .fill_info = ipgre_fill_info,
96 + .fill_info = erspan_fill_info,
97 .get_link_net = ip_tunnel_get_link_net,