[ovs-dev,ERSPAN,RFC,06/25] ip_gre: get key from session_id correctly in erspan_rcv

Message ID 1521756461-3870-7-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: Xin Long <lucien.xin@gmail.com>

Upstream commit:
    commit 935a9749a36828af0e8be224a5cd4bc758112c34
    Author: Xin Long <lucien.xin@gmail.com>
    Date:   Sun Oct 1 22:00:53 2017 +0800

    ip_gre: get key from session_id correctly in erspan_rcv

    erspan only uses the first 10 bits of session_id as the key to look
    up the tunnel. But in erspan_rcv, it missed 'session_id & ID_MASK'
    when getting the key from session_id.

    If any other flag is also set in session_id in a packet, it would
    fail to find the tunnel due to incorrect key in erspan_rcv.

    This patch is to add 'session_id & ID_MASK' there and also remove
    the unnecessary variable session_id.

    Fixes: 84e54fe0a5ea ("gre: introduce native tunnel support for ERSPAN")
    Signed-off-by: Xin Long <lucien.xin@gmail.com>
    Signed-off-by: David S. Miller <davem@davemloft.net>

Cc: Xin Long <lucien.xin@gmail.com>
Signed-off-by: Greg Rose <gvrose8192@gmail.com>
---
 datapath/linux/compat/ip_gre.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

Patch

diff --git a/datapath/linux/compat/ip_gre.c b/datapath/linux/compat/ip_gre.c
index af9fbb3..2fc4659 100644
--- a/datapath/linux/compat/ip_gre.c
+++ b/datapath/linux/compat/ip_gre.c
@@ -141,7 +141,6 @@  static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 	struct ip_tunnel *tunnel;
 	struct erspanhdr *ershdr;
 	const struct iphdr *iph;
-	__be32 session_id;
 	__be32 index;
 	int len;
 
@@ -158,8 +157,7 @@  static int erspan_rcv(struct sk_buff *skb, struct tnl_ptk_info *tpi,
 	/* The original GRE header does not have key field,
 	 * Use ERSPAN 10-bit session ID as key.
 	 */
-	session_id = cpu_to_be32(ntohs(ershdr->session_id));
-	tpi->key = session_id;
+	tpi->key = cpu_to_be32(ntohs(ershdr->session_id) & ID_MASK);
 	index = ershdr->md.index;
 	tunnel = ip_tunnel_lookup(itn, skb->dev->ifindex,
 				  tpi->flags | TUNNEL_KEY,