From patchwork Fri Apr 27 21:16:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 905964 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BsBeHmVa"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 40XmwH1D4gz9s06 for ; Sat, 28 Apr 2018 07:17:03 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932369AbeD0VQ5 (ORCPT ); Fri, 27 Apr 2018 17:16:57 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:42875 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1757592AbeD0VQ4 (ORCPT ); Fri, 27 Apr 2018 17:16:56 -0400 Received: by mail-pf0-f194.google.com with SMTP id a11so2331846pfn.9 for ; Fri, 27 Apr 2018 14:16:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id; bh=nzXIpwxX4VY1SuVpZrAnU383Q9Xd9EszLnKwphshGR8=; b=BsBeHmVaisEBzvXXAb9K3zwKyKaWFaJECRFI6SodofJXrWZwo1tYwWZl8H3BNyALTY 7aXr2oV17u9yDB/hGYJYb1RKIcPBmb567xa0S5iNC5k/n1Y28M+TQ34LRwKy/o/kEPco PG5Ly4AvYs979lZ6/mf3zez9dx0RVEdhLFmcSCCNSamd6t7gVBJlLcbEwPqVyrd0ZlYw A845v+rkEuo9s7Vvk/Pp2EbB/h1DYdpJ9enupysrRJr1C/k07dhA06Z1KGhzhA+sQuku tY1nf5Z39MunHItQmqR4GejViX9/8shBweb1hEOzwnS2P2t4RUm9HUAdMUCoGEvzF7p3 7MOw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=nzXIpwxX4VY1SuVpZrAnU383Q9Xd9EszLnKwphshGR8=; b=L6tM5ctfj89E5L8pB/QQ+Hy58SswjyZq6mtLFhHrmaXBR70GEDEvJTyYaU6Z+YTSGd sZs51PrZluvPTxPyKPVYBD4aAhHA8ADiQWpZ5X5/sG277+snLBSfrWiYOteCeC80U3Xx knH3HYpekgLsZc0dEQLM1oRSyVSETOcSmXjxEeH70PzVOgsCN69zCExSbixJdl6Aq4c6 INYv//qHIXk3q19pIEARhw+e8Xc1bEeJV42+yTLWh7DJbkd6nzlYD4muKnIffeVyLxrM JPZ4lZKIhci7LwXjp/nbFa4p2yInU0cdMxkNdkNqKEeNlDIwLvOY+qXCRrv88ES0ac2w KAyg== X-Gm-Message-State: ALQs6tAlyHxJjCj/A703gS/Reu19rqKoT5LjPaJk06Ng6Np2rqKG0kAG seNFi1b07tZ/2ZxZf1yvwuq3Uvr2 X-Google-Smtp-Source: AB8JxZp4oUZ1kaRpZ4kQ3KzYm3XsFrcQlZFzF7ocRgJKMX0zsOW9jj90zlaBAokpTG4mWj0gF2Kxfw== X-Received: by 2002:a17:902:b490:: with SMTP id y16-v6mr3613983plr.92.1524863815445; Fri, 27 Apr 2018 14:16:55 -0700 (PDT) Received: from sc9-mailhost2.vmware.com ([66.170.99.2]) by smtp.gmail.com with ESMTPSA id 204-v6sm4739777pgb.67.2018.04.27.14.16.54 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 27 Apr 2018 14:16:54 -0700 (PDT) From: William Tu To: netdev@vger.kernel.org Subject: [PATCH net-next] erspan: auto detect truncated packets. Date: Fri, 27 Apr 2018 14:16:32 -0700 Message-Id: <1524863792-66068-1-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently the truncated bit is set only when the mirrored packet is larger than mtu. For certain cases, the packet might already been truncated before sending to the erspan tunnel. In this case, the patch detect whether the IP header's total length is larger than the actual skb->len. If true, this indicated that the mirrored packet is truncated and set the erspan truncate bit. I tested the patch using bpf_skb_change_tail helper function to shrink the packet size and send to erspan tunnel. Reported-by: Xiaoyan Jin Signed-off-by: William Tu --- net/ipv4/ip_gre.c | 6 ++++++ net/ipv6/ip6_gre.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c index 9c169bb2444d..dfe5b22f6ed4 100644 --- a/net/ipv4/ip_gre.c +++ b/net/ipv4/ip_gre.c @@ -578,6 +578,7 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev, int tunnel_hlen; int version; __be16 df; + int nhoff; tun_info = skb_tunnel_info(skb); if (unlikely(!tun_info || !(tun_info->mode & IP_TUNNEL_INFO_TX) || @@ -605,6 +606,11 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev, truncate = true; } + nhoff = skb_network_header(skb) - skb_mac_header(skb); + if (skb->protocol == htons(ETH_P_IP) && + (ntohs(ip_hdr(skb)->tot_len) > skb->len - nhoff)) + truncate = true; + if (version == 1) { erspan_build_header(skb, ntohl(tunnel_id_to_key32(key->tun_id)), ntohl(md->u.index), truncate, true); diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c index 69727bc168cb..ac7ce85df667 100644 --- a/net/ipv6/ip6_gre.c +++ b/net/ipv6/ip6_gre.c @@ -896,6 +896,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb, struct flowi6 fl6; int err = -EINVAL; __u32 mtu; + int nhoff; if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr)) goto tx_err; @@ -908,6 +909,11 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb, truncate = true; } + nhoff = skb_network_header(skb) - skb_mac_header(skb); + if (skb->protocol == htons(ETH_P_IP) && + (ntohs(ip_hdr(skb)->tot_len) > skb->len - nhoff)) + truncate = true; + if (skb_cow_head(skb, dev->needed_headroom)) goto tx_err;