From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_PASS,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E3E1C169C4 for ; Thu, 7 Feb 2019 00:37:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1D1932175B for ; Thu, 7 Feb 2019 00:37:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="TUvp66YU" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726813AbfBGAhg (ORCPT ); Wed, 6 Feb 2019 19:37:36 -0500 Received: from mail-ot1-f74.google.com ([209.85.210.74]:47323 "EHLO mail-ot1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726424AbfBGAhf (ORCPT ); Wed, 6 Feb 2019 19:37:35 -0500 Received: by mail-ot1-f74.google.com with SMTP id g4so7841780otl.14 for ; Wed, 06 Feb 2019 16:37:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=dIbhQHoe6O/9EqKWUeE2/HxmnorKw5UGDYrO8fORLeU=; b=TUvp66YUzH8Or13RllpM1Jhy9XaHEiFHz5WUt2F6ZULsKn1QRoNLsFnZtQ8LVRbZRA 8LlTREWT1bAW/Ug6Wuq/dJfBO9PtuF66BifUbhU5wtzGVDrZ0VyjzYC46/48pImeraAI ls+RKJXHYpQW59BnDdh+rbEZSlEE6Jf2HP1ZgVaES0OSDQzAxLVgxiVikc7Kzuf8UC1O xk1Fd/SSpyLtYlhYR4EECmubl/vHaLVcWwvMk/cit39p1uPOqqTWi7B4IyILRvGz3Fi6 h9u5yNMG9fKrOauonVc4CShAcKQG/g+SDGEARty3vh8RVNwvKPqRxK0N5VOLxzTIhIP5 pJBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=dIbhQHoe6O/9EqKWUeE2/HxmnorKw5UGDYrO8fORLeU=; b=hg7T8MB8NDu+UieHw+qPEKrQ+OCKsPnf6/AAfVeWlBwZGebONEwYmotOw1XFdPxfA3 6q/ca263pAtiJMMQsxWFtnlhRjJXAstzYYelbv3chvCSQjHezceYrxjbWT9ZgmLKHMpk 3y7fHyH2dOyR1DfE+spzUCR43tCk58ggo+CGA83Y8CvhW4uzvH5ajCJruclB0nm/VtIf vNc4IzoYqgPWGvKNPAj91ZkmiO0jGiRunrnOvdmdalxuBEJrak0tv8/TUV8vc41/K7zo 5FXiGrj2e6YbjdNs3FHT6ZdhG/2zmD2xmEwC28VRmOuGdYuaD9L8RmpQOjQObr2BSCVp lM7Q== X-Gm-Message-State: AHQUAuaO/MV0iBMNsbK0X7R7Nd6qO6dXTTUoKTKtfVn4Izzv+IAwNPdx aiSahs2je+2aGmNT7q1mUg09WBjh X-Google-Smtp-Source: AHgI3IZ5/8X/4DmyKy8uOb7Rpy6liq681MSYksBB5OE4zFKKhuKKaB7WgGCmqz/pqOMFCfQ/DNt/zymm X-Received: by 2002:a54:458c:: with SMTP id z12mr8179177oib.48.1549499854248; Wed, 06 Feb 2019 16:37:34 -0800 (PST) Date: Wed, 6 Feb 2019 16:37:17 -0800 In-Reply-To: <20190207003720.51096-1-posk@google.com> Message-Id: <20190207003720.51096-4-posk@google.com> Mime-Version: 1.0 References: <20190207003720.51096-1-posk@google.com> X-Mailer: git-send-email 2.20.1.611.gfbb209baf1-goog Subject: [PATCH bpf-next v7 3/6] bpf: handle GSO in bpf_lwt_push_encap From: Peter Oskolkov To: Alexei Starovoitov , Daniel Borkmann , netdev@vger.kernel.org Cc: Peter Oskolkov , David Ahern , Willem de Bruijn , Peter Oskolkov Content-Type: text/plain; charset="UTF-8" Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch adds handling of GSO packets in bpf_lwt_push_ip_encap() (called from bpf_lwt_push_encap): * IPIP, GRE, and UDP encapsulation types are deduced by looking into iphdr->protocol or ipv6hdr->next_header; * an error is returned if the same GSO encap type is set on the skb; * SCTP GSO packets are not supported (as bpf_skb_proto_4_to_6 and similar do); * UDP_L4 GSO packets are also not supported (although they are not blocked in bpf_skb_proto_4_to_6 and similar), as skb_decrease_gso_size() will break it; * SKB_GSO_DODGY bit is set. Note: it may be possible to support SCTP and UDP_L4 gso packets; but as these cases seem to be not well handled by other tunneling/encapping code paths, the solution should be generic enough to apply to all tunneling/encapping code. Signed-off-by: Peter Oskolkov --- net/core/lwt_bpf.c | 62 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 3 deletions(-) diff --git a/net/core/lwt_bpf.c b/net/core/lwt_bpf.c index 786b96148937..4ff60757bf23 100644 --- a/net/core/lwt_bpf.c +++ b/net/core/lwt_bpf.c @@ -16,6 +16,7 @@ #include #include #include +#include struct bpf_lwt_prog { struct bpf_prog *prog; @@ -390,15 +391,70 @@ static const struct lwtunnel_encap_ops bpf_encap_ops = { .owner = THIS_MODULE, }; -static int handle_gso_encap(struct sk_buff *skb, bool ipv4, int encap_len) +static int handle_gso_type(struct sk_buff *skb, unsigned int gso_type, + int encap_len) { - /* Handling of GSO-enabled packets is added in the next patch. */ - if (unlikely(skb_is_gso(skb))) + struct skb_shared_info *shinfo = skb_shinfo(skb); + + /* Refuse to double-encap with the same type. */ + if (shinfo->gso_type & gso_type) return -EINVAL; + gso_type |= SKB_GSO_DODGY; + shinfo->gso_type |= gso_type; + skb_decrease_gso_size(shinfo, encap_len); + shinfo->gso_segs = 0; return 0; } +static int handle_gso_encap(struct sk_buff *skb, bool ipv4, int encap_len) +{ + void *next_hdr; + __u8 protocol; + + if (!skb_is_gso(skb)) + return 0; + + /* SCTP and UDP_L4 gso need more nuanced handling than what + * handle_gso_type() does above: skb_decrease_gso_size() is not enough. + */ + if (unlikely(skb_shinfo(skb)->gso_type & + (SKB_GSO_SCTP | SKB_GSO_UDP_L4))) + return -ENOTSUPP; + + if (ipv4) { + protocol = ip_hdr(skb)->protocol; + next_hdr = skb_network_header(skb) + sizeof(struct iphdr); + } else { + protocol = ipv6_hdr(skb)->nexthdr; + next_hdr = skb_network_header(skb) + sizeof(struct ipv6hdr); + } + + switch (protocol) { + case IPPROTO_GRE: + if (((struct gre_base_hdr *)next_hdr)->flags & GRE_CSUM) + return handle_gso_type(skb, SKB_GSO_GRE_CSUM, + encap_len); + return handle_gso_type(skb, SKB_GSO_GRE, encap_len); + + case IPPROTO_UDP: + if (((struct udphdr *)next_hdr)->check) + return handle_gso_type(skb, SKB_GSO_UDP_TUNNEL_CSUM, + encap_len); + return handle_gso_type(skb, SKB_GSO_UDP_TUNNEL, encap_len); + + case IPPROTO_IP: + case IPPROTO_IPV6: + if (ipv4) + return handle_gso_type(skb, SKB_GSO_IPXIP4, encap_len); + else + return handle_gso_type(skb, SKB_GSO_IPXIP6, encap_len); + + default: + return -EPROTONOSUPPORT; + } +} + int bpf_lwt_push_ip_encap(struct sk_buff *skb, void *hdr, u32 len, bool ingress) { struct iphdr *iph; -- 2.20.1.611.gfbb209baf1-goog