Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2469096imm; Mon, 10 Sep 2018 01:27:23 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZrZAmFGU8MO2ATc0cbCITL+iqbJrbRwXA7ul9UpzsP26LW+rnV9HA2UiY1ieAcnCdjsB2R X-Received: by 2002:a17:902:b688:: with SMTP id c8-v6mr20689433pls.114.1536568043463; Mon, 10 Sep 2018 01:27:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536568043; cv=none; d=google.com; s=arc-20160816; b=l69h0gqtms/wcQ5qsd9QUOGUcHu+aPPIoekEeIpIuOdyLF5SO0uW5BnS3PtMkz3gWe AddTftxIt8zUWZPVJfocTFP8lMTh2nulZVZNY61g4LSrMNbhiHUKEK2tZFBgFVChCOim 9jf9O8Kqhw8pWwnGPKniSvG1aA590PyR/DZtz7unh5z06enJAldEeHPeQAVYjDWT6fpX iRR+pgDntglbJNsPwixnz7Cl7lRQ7hJAuTeSwacJMmxUeJutWgvYd35IRiV4nsBcWBGZ wdf/sEhWamEU7vG38PLDC9gXEoiIzWUmkHtkGR4wXlf6pIF7E/hhet2gYVa8Yzq4ipkz 8/pA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=8rAVaKrbE3Aci/QfCy8ty/o2BQYuxS14111AypS4BCc=; b=e8CbHIggUO2p4K7HGGQg0Wwf6uyoHNiimxd2jWtFLRfl1G2RKpt27BGbMfeCEfiue8 dQfM8KLS8U7zYLGxiHfD5np7QCF71wTzeXNTY992fa2nItMm/YUJP2jbSRP+UQ+OrccQ wfOKDRjdTfXkIzy0+UBy2HOiS9xDFOoVxmfIYoHk7DRGqR+fHga0qKP9DNOb+diylG1S YvlCIfgw/CK1lCP6q3bOz0mUDQJEXuNDmzvgYhuaKj1f8f2ss+98GloYiPhM0WOtHzGv wKLn1NKgJQRSvno49YnXL9v/UgXozsPGfrud3BaSOHciciY5qEh3YD+vijOdwLe0NKBG 4M7w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c125-v6si17111326pga.268.2018.09.10.01.27.08; Mon, 10 Sep 2018 01:27:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728007AbeIJNSS (ORCPT + 99 others); Mon, 10 Sep 2018 09:18:18 -0400 Received: from cmccmta2.chinamobile.com ([221.176.66.80]:58091 "EHLO cmccmta2.chinamobile.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727969AbeIJNSR (ORCPT ); Mon, 10 Sep 2018 09:18:17 -0400 Received: from spf.mail.chinamobile.com (unknown[172.16.121.5]) by rmmx-syy-dmz-app08-12008 (RichMail) with SMTP id 2ee85b962a71b4c-55b0a; Mon, 10 Sep 2018 16:25:22 +0800 (CST) X-RM-TRANSID: 2ee85b962a71b4c-55b0a X-RM-TagInfo: emlType=0 X-RM-SPAM-FLAG: 00000000 Received: from localhost (unknown[223.105.0.240]) by rmsmtp-syy-appsvr03-12003 (RichMail) with SMTP id 2ee35b962a71a7f-d225e; Mon, 10 Sep 2018 16:25:22 +0800 (CST) X-RM-TRANSID: 2ee35b962a71a7f-d225e From: Haishuang Yan To: "David S. Miller" , Alexey Kuznetsov Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Haishuang Yan Subject: [PATCH] ip6_gre: simplify gre header parsing in ip6gre_err Date: Mon, 10 Sep 2018 16:25:09 +0800 Message-Id: <1536567909-25089-1-git-send-email-yanhaishuang@cmss.chinamobile.com> X-Mailer: git-send-email 1.8.3.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Same as ip_gre, use gre_parse_header to parse gre header in gre error handler code. Signed-off-by: Haishuang Yan --- net/ipv6/ip6_gre.c | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index 18a3794..505d891 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -427,35 +427,20 @@ static void ip6gre_err(struct sk_buff *skb, struct inet6_skb_parm *opt, u8 type, u8 code, int offset, __be32 info) { struct net *net = dev_net(skb->dev); - const struct gre_base_hdr *greh; const struct ipv6hdr *ipv6h; - int grehlen = sizeof(*greh); + struct tnl_ptk_info tpi; + bool csum_err = false; struct ip6_tnl *t; - int key_off = 0; - __be16 flags; - __be32 key; - if (!pskb_may_pull(skb, offset + grehlen)) - return; - greh = (const struct gre_base_hdr *)(skb->data + offset); - flags = greh->flags; - if (flags & (GRE_VERSION | GRE_ROUTING)) - return; - if (flags & GRE_CSUM) - grehlen += 4; - if (flags & GRE_KEY) { - key_off = grehlen + offset; - grehlen += 4; + if (gre_parse_header(skb, &tpi, &csum_err, htons(ETH_P_IPV6), + offset) < 0) { + if (!csum_err) /* ignore csum errors. */ + return; } - if (!pskb_may_pull(skb, offset + grehlen)) - return; ipv6h = (const struct ipv6hdr *)skb->data; - greh = (const struct gre_base_hdr *)(skb->data + offset); - key = key_off ? *(__be32 *)(skb->data + key_off) : 0; - t = ip6gre_tunnel_lookup(skb->dev, &ipv6h->daddr, &ipv6h->saddr, - key, greh->protocol); + tpi.key, tpi.proto); if (!t) return; -- 1.8.3.1