Commit 8e1c3cbc authored by Hangbin Liu's avatar Hangbin Liu Committed by sanglipeng
Browse files

ip_gre: do not report erspan version on GRE interface

stable inclusion
from stable-v5.10.159
commit a5cfbc199536d853abd45a9105fe097202c4f0ca
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I7NTXH

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?id=a5cfbc199536d853abd45a9105fe097202c4f0ca



--------------------------------

[ Upstream commit ee496694 ]

Although the type I ERSPAN is based on the barebones IP + GRE
encapsulation and no extra ERSPAN header. Report erspan version on GRE
interface looks unreasonable. Fix this by separating the erspan and gre
fill info.

IPv6 GRE does not have this info as IPv6 only supports erspan version
1 and 2.

Reported-by: default avatarJianlin Shi <jishi@redhat.com>
Fixes: f989d546 ("erspan: Add type I version 0 support.")
Signed-off-by: default avatarHangbin Liu <liuhangbin@gmail.com>
Acked-by: default avatarWilliam Tu <u9012063@gmail.com>
Link: https://lore.kernel.org/r/20221203032858.3130339-1-liuhangbin@gmail.com


Signed-off-by: default avatarPaolo Abeni <pabeni@redhat.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarsanglipeng <sanglipeng1@jd.com>
parent dee6a47c
Loading
Loading
Loading
Loading
+29 −19
Original line number Diff line number Diff line
@@ -1493,24 +1493,6 @@ static int ipgre_fill_info(struct sk_buff *skb, const struct net_device *dev)
	struct ip_tunnel_parm *p = &t->parms;
	__be16 o_flags = p->o_flags;

	if (t->erspan_ver <= 2) {
		if (t->erspan_ver != 0 && !t->collect_md)
			o_flags |= TUNNEL_KEY;

		if (nla_put_u8(skb, IFLA_GRE_ERSPAN_VER, t->erspan_ver))
			goto nla_put_failure;

		if (t->erspan_ver == 1) {
			if (nla_put_u32(skb, IFLA_GRE_ERSPAN_INDEX, t->index))
				goto nla_put_failure;
		} else if (t->erspan_ver == 2) {
			if (nla_put_u8(skb, IFLA_GRE_ERSPAN_DIR, t->dir))
				goto nla_put_failure;
			if (nla_put_u16(skb, IFLA_GRE_ERSPAN_HWID, t->hwid))
				goto nla_put_failure;
		}
	}

	if (nla_put_u32(skb, IFLA_GRE_LINK, p->link) ||
	    nla_put_be16(skb, IFLA_GRE_IFLAGS,
			 gre_tnl_flags_to_gre_flags(p->i_flags)) ||
@@ -1551,6 +1533,34 @@ static int ipgre_fill_info(struct sk_buff *skb, const struct net_device *dev)
	return -EMSGSIZE;
}

static int erspan_fill_info(struct sk_buff *skb, const struct net_device *dev)
{
	struct ip_tunnel *t = netdev_priv(dev);

	if (t->erspan_ver <= 2) {
		if (t->erspan_ver != 0 && !t->collect_md)
			t->parms.o_flags |= TUNNEL_KEY;

		if (nla_put_u8(skb, IFLA_GRE_ERSPAN_VER, t->erspan_ver))
			goto nla_put_failure;

		if (t->erspan_ver == 1) {
			if (nla_put_u32(skb, IFLA_GRE_ERSPAN_INDEX, t->index))
				goto nla_put_failure;
		} else if (t->erspan_ver == 2) {
			if (nla_put_u8(skb, IFLA_GRE_ERSPAN_DIR, t->dir))
				goto nla_put_failure;
			if (nla_put_u16(skb, IFLA_GRE_ERSPAN_HWID, t->hwid))
				goto nla_put_failure;
		}
	}

	return ipgre_fill_info(skb, dev);

nla_put_failure:
	return -EMSGSIZE;
}

static void erspan_setup(struct net_device *dev)
{
	struct ip_tunnel *t = netdev_priv(dev);
@@ -1629,7 +1639,7 @@ static struct rtnl_link_ops erspan_link_ops __read_mostly = {
	.changelink	= erspan_changelink,
	.dellink	= ip_tunnel_dellink,
	.get_size	= ipgre_get_size,
	.fill_info	= ipgre_fill_info,
	.fill_info	= erspan_fill_info,
	.get_link_net	= ip_tunnel_get_link_net,
};