From patchwork Mon Apr 3 12:12:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Ehrig X-Patchwork-Id: 7630 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2222024vqo; Mon, 3 Apr 2023 04:19:15 -0700 (PDT) X-Google-Smtp-Source: AKy350Z1ibOAZLALyG9vemr5P8+XatuDKdLcrFxJobJjmZi3UzHqrbjlO/oAN3midEYLzZOX1Aci X-Received: by 2002:aa7:c50b:0:b0:4fd:29e4:ccfe with SMTP id o11-20020aa7c50b000000b004fd29e4ccfemr32919578edq.18.1680520755399; Mon, 03 Apr 2023 04:19:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680520755; cv=none; d=google.com; s=arc-20160816; b=y9vcXCGqP/OnuOBX3U6jLH0swYJcUZozAVBFunbQHIrJYH4Av6Ncd2Vy3bbm8FAItT RCOpv7/zGXaGO++bqMqt9vTuVmEAoOFFXS1EOXw4a5mYuj3lxAASa9WnpNV1WpDsUaID +X16hbDC5ZJpXiPDf+Ygu8zJHmKOCevtz8WnzJo3u9lL1vIbTk9SjQJAipkCLj0/FX49 ct+nALXgNiyRqJ32MfI4rxTxxIagkmhQF+li4zv2Nl0RXIymyaPfBPTCC3k69RvJiCzw huDZQNyUqspOr1i4ADLSfVbJRei6pk1K9ip2k2TZUruNL1v79On0dsFHAQUSUColbDlE fniA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=XDScleNPhVPO54kxOKxQumxr8xmhVAhL3xX9seLkjNI=; b=QcWvVFRaJBY6DZtbwgHRJV/dLZf+KteJf5g8VzCcmDANk3R5EiHxK966uNqYeA1cdR ZltSzRLm241nUCZK3B1QZMG3LH3UsIOFHhLn1SbWtc//xFa8VdfZ02iuw57V37Czhhr5 Lzc1F9MMAWQof8H/zVJakcOPYt/pLZoWyGbudwt7J5oouz1QZv1nQcZjuwSV9Q8NIYgR O6f+K25SBGpTfATYAWRf2nUKQeM+ZxGQRNd/Db7rNRWdOz5c9B3QnQcZFEwb5Cy5tg9y AdDiXazhj5bHBgRpE0Of5orkERii3CAOAjE1hLXo5Yg+smzfXkA9UPBz0Fa/xwBxIzRW wrsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=HgabHVAE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u10-20020aa7d98a000000b005021cd581a0si7372131eds.402.2023.04.03.04.18.50; Mon, 03 Apr 2023 04:19:15 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=HgabHVAE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=cloudflare.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232269AbjDCLNL (ORCPT + 99 others); Mon, 3 Apr 2023 07:13:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36732 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232117AbjDCLNE (ORCPT ); Mon, 3 Apr 2023 07:13:04 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 04DF31A941 for ; Mon, 3 Apr 2023 04:12:31 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id h17so28914754wrt.8 for ; Mon, 03 Apr 2023 04:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; t=1680520347; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=XDScleNPhVPO54kxOKxQumxr8xmhVAhL3xX9seLkjNI=; b=HgabHVAEwxuQvMaYMbnLI6gcoQaR6MCVEcwO9KWwr+XCrszcTScNEkOgZh53S7rCGL lx0H65pMjpwzz2zOZTxxF+i5WB9RciFYT1s/ORth0tyPdpo60cphbJb08QY15hQC5tnv LJ5cMuSNL6e4s38Qa4zvct2xAA6wj31Zvg8Nc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680520347; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XDScleNPhVPO54kxOKxQumxr8xmhVAhL3xX9seLkjNI=; b=MOxkTBwJh47PezU4+TlhRafTM1wTaBrVBCPIfQC7W6YEN277QtBj/Kzw5PLn2YBkpG 2A/OkA8cqbcF76GiauTBfQiaYMVFJohO7medlXbGFtlcCudMMGfyCNXRu+T7SSqLPpsG tFMj1k0Gr9ABs6J1/vHi0RWH/PWXzSnHRWTfH2UANqI7Kfz1Lw9T1ufvmhHPIpgM87wX s6VHbw7wIqg002zH/wJtI5e4YnowemCysQge8TfLeM6YOkchr7Ltl0DNZ3rUm7Co98b+ +M/xACktsFAaI1Rqxg+jYGfjnk+IpxipG9/GeBYEA2RfVTriqffE4o7lN/8R184TeUMK +bCQ== X-Gm-Message-State: AAQBX9e7muIWEcQ3jBoID4OPhqr6Fsv0p2YurAXNC198DJtAOVxdzJEO /9kzS1wCXrVUuCo/UH+YM/+MmA== X-Received: by 2002:a5d:67cd:0:b0:2d7:babe:104c with SMTP id n13-20020a5d67cd000000b002d7babe104cmr25864956wrw.15.1680520347373; Mon, 03 Apr 2023 04:12:27 -0700 (PDT) Received: from workstation.ehrig.io (tmo-066-125.customers.d1-online.com. [80.187.66.125]) by smtp.gmail.com with ESMTPSA id y11-20020adffa4b000000b002c7066a6f77sm9505517wrr.31.2023.04.03.04.12.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 04:12:26 -0700 (PDT) From: Christian Ehrig To: bpf@vger.kernel.org Cc: cehrig@cloudflare.com, kernel-team@cloudflare.com, Alexei Starovoitov , Andrii Nakryiko , Daniel Borkmann , Dave Marchevsky , Hao Luo , Jiri Olsa , John Fastabend , Kaixi Fan , KP Singh , linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Martin KaFai Lau , Mykola Lysenko , netdev@vger.kernel.org, Paul Chaignon , Shmulik Ladkani , Song Liu , Stanislav Fomichev , Yonghong Song Subject: [PATCH bpf-next v2 0/3] Add FOU support for externally controlled ipip devices Date: Mon, 3 Apr 2023 14:12:06 +0200 Message-Id: X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIMWL_WL_MED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762153731710413922?= X-GMAIL-MSGID: =?utf-8?q?1762153731710413922?= This patch set adds support for using FOU or GUE encapsulation with an ipip device operating in collect-metadata mode and a set of kfuncs for controlling encap parameters exposed to a BPF tc-hook. BPF tc-hooks allow us to read tunnel metadata (like remote IP addresses) in the ingress path of an externally controlled tunnel interface via the bpf_skb_get_tunnel_{key,opt} bpf-helpers. Packets can then be redirected to the same or a different externally controlled tunnel interface by overwriting metadata via the bpf_skb_set_tunnel_{key,opt} helpers and a call to bpf_redirect. This enables us to redirect packets between tunnel interfaces - and potentially change the encapsulation type - using only a single BPF program. Today this approach works fine for a couple of tunnel combinations. For example: redirecting packets between Geneve and GRE interfaces or GRE and plain ipip interfaces. However, redirecting using FOU or GUE is not supported today. The ip_tunnel module does not allow us to egress packets using additional UDP encapsulation from an ipip device in collect-metadata mode. Patch 1 lifts this restriction by adding a struct ip_tunnel_encap to the tunnel metadata. It can be filled by a new BPF kfunc introduced in Patch 2 and evaluated by the ip_tunnel egress path. This will allow us to use FOU and GUE encap with externally controlled ipip devices. Patch 2 introduces two new BPF kfuncs: bpf_skb_{set,get}_fou_encap. These helpers can be used to set and get UDP encap parameters from the BPF tc-hook doing the packet redirect. Patch 3 adds BPF tunnel selftests using the two kfuncs. --- v2: - Fixes for checkpatch.pl - Fixes for kernel test robot Christian Ehrig (3): ipip,ip_tunnel,sit: Add FOU support for externally controlled ipip devices bpf,fou: Add bpf_skb_{set,get}_fou_encap kfuncs selftests/bpf: Test FOU kfuncs for externally controlled ipip devices include/net/fou.h | 2 + include/net/ip_tunnels.h | 28 +++-- net/ipv4/Makefile | 2 +- net/ipv4/fou_bpf.c | 119 ++++++++++++++++++ net/ipv4/fou_core.c | 5 + net/ipv4/ip_tunnel.c | 22 +++- net/ipv4/ipip.c | 1 + net/ipv6/sit.c | 2 +- .../selftests/bpf/progs/test_tunnel_kern.c | 117 +++++++++++++++++ tools/testing/selftests/bpf/test_tunnel.sh | 81 ++++++++++++ 10 files changed, 362 insertions(+), 17 deletions(-) create mode 100644 net/ipv4/fou_bpf.c