[ovs-dev,ERSPAN,RFC,22/25] net: erspan: fix metadata extraction

Message ID 1521756461-3870-23-git-send-email-gvrose8192@gmail.com
State New
Headers show
Series
  • Introduce ERSPAN for OVS
Related show

Commit Message

Gregory Rose March 22, 2018, 10:07 p.m.
From: William Tu <u9012063@gmail.com>

Upstream commit:
    commit 3df1928302950dfa728ab2eade28eea0da291567
    Author: William Tu <u9012063@gmail.com>
    Date:   Mon Feb 5 13:35:34 2018 -0800

    net: erspan: fix metadata extraction

    Commit d350a823020e ("net: erspan: create erspan metadata uapi header")
    moves the erspan 'version' in front of the 'struct erspan_md2' for
    later extensibility reason.  This breaks the existing erspan metadata
    extraction code because the erspan_md2 then has a 4-byte offset
    to between the erspan_metadata and erspan_base_hdr.  This patch
    fixes it.

    Fixes: 1a66a836da63 ("gre: add collect_md mode to ERSPAN tunnel")
    Fixes: ef7baf5e083c ("ip6_gre: add ip6 erspan collect_md mode")
    Fixes: 1d7e2ed22f8d ("net: erspan: refactor existing erspan code")
    Signed-off-by: William Tu <u9012063@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

This is just the ip_gre portion of this upstream commit.  The portions
of the upstream commit that went to erpsan.h and ip6_gre.c were folded
in during a previous commit to introduce ip6 gre.

Cc: William Tu <u9012063@gmail.com>
Signed-off-by: Greg Rose <gvrose8192@gmail.com>
---
 datapath/linux/compat/ip_gre.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

Patch

diff --git a/datapath/linux/compat/ip_gre.c b/datapath/linux/compat/ip_gre.c
index f99ef1b..5ebbdb5 100644
--- a/datapath/linux/compat/ip_gre.c
+++ b/datapath/linux/compat/ip_gre.c
@@ -119,6 +119,7 @@  static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 	struct ip_tunnel_net *itn;
 	struct ip_tunnel *tunnel;
 	const struct iphdr *iph;
+	struct erspan_md2 *md2;
 	int ver;
 	int len;
 
@@ -169,8 +170,10 @@  static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 					  tun_id, sizeof(*md));
 
 			md = ip_tunnel_info_opts(&tun_dst->u.tun_info);
-			memcpy(md, pkt_md, sizeof(*md));
 			md->version = ver;
+			md2 = &md->u.md2;
+			memcpy(md2, pkt_md, ver == 1 ? ERSPAN_V1_MDSIZE :
+						       ERSPAN_V2_MDSIZE);
 
 			info = &tun_dst->u.tun_info;
 			info->key.tun_flags |= TUNNEL_ERSPAN_OPT;