From patchwork Sat Apr 1 20:33:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Ehrig X-Patchwork-Id: 7587 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1400873vqo; Sat, 1 Apr 2023 12:43:27 -0700 (PDT) X-Google-Smtp-Source: AKy350YtKbYb5pBQw07uZVNs7pf4rk3uVjB/lV8rEO852SLeytUnx5jDrUou4U9CbyXKTzKJGzss X-Received: by 2002:a17:902:f315:b0:19e:9849:1767 with SMTP id c21-20020a170902f31500b0019e98491767mr25891732ple.42.1680378207487; Sat, 01 Apr 2023 12:43:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680378207; cv=none; d=google.com; s=arc-20160816; b=ca5Vx3vD8f76dtFuA1HDybYoL/cuk+I86fY1UBkIzd78uyqe/tu+grhq52naaWYnma svv2cgtT8+ZXuZduG6jndpOCRs/RNoN9b1FqlTVJKHSjVYu5rfKeXr6VzykxTCCDKEtd zsW/dxaD8E90yuFtuGc6dHZJoOMboTM9WU3XS7oKiYesoKlNo/MIqfLTsDBvHAOe7q1h a3cHCdHJlIeVghnbTIALuAsrCg0Kz/4NngdLeCDo1miAqlqBPaesgexz0boMYm2g+CL+ YC3xWfYIYQPrKAyIeSGF9bDYgi4YLfoAYJ5eUr0g2PinBj/5cUNa1CPMiKfPgfsq2HFT Qy7A== 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=T8nk4QZgWJg4nXeLh4FKwCEMlZL89Q2/gxR+wnUlYKE=; b=pDtoDOhv7Hrqj4lVoGTVNDJUI3eRy2IW6LqI4tC2a/yNh/AIYUcMdDp+gZxIA3g+z6 94GKN60JN7OhDBrdw+UVW5eLYGPfj8EB1EqvlsmRH5F4Iuy3mTpM5+qzl59eTqmzwUfs 5xCrKth46BQZ5+1/5U5ckONAFbimHSf11rcsAtZh9dEFEZDo+gOJCXezOHatEK8RLy87 MraOKi7ycl+1rmPwFh8LkcEFK9249e1uhdZRaVmfFIQk+yOxv6OctDLXHb4POJCYr9j2 1cK7QP+riKCwd0GtIiyTVptjn4CqM7GLlEmCsT5YrSPAQnY18eiUOvusYCAe9R/5y860 Z1qA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cloudflare.com header.s=google header.b=HGKGh54Y; 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 z190-20020a6365c7000000b0050c0305bcc3si5096152pgb.872.2023.04.01.12.43.14; Sat, 01 Apr 2023 12:43:27 -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=HGKGh54Y; 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 S230037AbjDATeK (ORCPT + 99 others); Sat, 1 Apr 2023 15:34:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbjDATeH (ORCPT ); Sat, 1 Apr 2023 15:34:07 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8FA01A969 for ; Sat, 1 Apr 2023 12:34:04 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id e18so25555862wra.9 for ; Sat, 01 Apr 2023 12:34:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cloudflare.com; s=google; t=1680377643; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=T8nk4QZgWJg4nXeLh4FKwCEMlZL89Q2/gxR+wnUlYKE=; b=HGKGh54YFhrvPb37yH8hOS5CsqeTujyV4VL3WbkXqVVrUDuuVS7v90zKoJMmRRdeaa eGde5sjydMFGflefdX1gjRpbpA8Ef5k8g5MedMHSnytb2/pU57TWhqccC0lzljcR7jyT hu9oW2uNzKlsPDcK8AX+juNDSJKqo4W4DS0RE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680377643; 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=T8nk4QZgWJg4nXeLh4FKwCEMlZL89Q2/gxR+wnUlYKE=; b=ELHk6eGTi4xCyQ2kJL+NjcnVVF3MiH4rltwb+GpiTdZAhyDDWkbWm9dSV84F6m9MTM v9jUeHYFH3iVAVT+mFKoNWwGiXVabR0Cs9CIqkcWG7cpjsMld2tQZo4x5tmj8zavkSdY 98GFONf/LKnCkVU/4LUJxFQHc0Y5E5LOzAMm9NlLwpur1ez7VgKZgDddjoDRNVbdmVtE hLVAxFjTUS1j/B8v3Jfixtc4RGimRfs2TkxQrLQ4JOm6jqmshwJjFRK9LfA8m/VA4N6P mxgFL0KBIQV9d8EsWLWNIw0iSZKNTrK1HPoHSs9XhL78Hy11qY1E7jMUM3M3fF5UQ3XS 7lxg== X-Gm-Message-State: AAQBX9dPLtygqGecSuMf30CJuoIJyLpGvwfYMRU+2Mnw9pkHYuzbqMiG 2/5gQRMAlgRY1jf/7tVf4gVVig== X-Received: by 2002:a5d:538d:0:b0:2cf:e023:5915 with SMTP id d13-20020a5d538d000000b002cfe0235915mr21430570wrv.61.1680377643121; Sat, 01 Apr 2023 12:34:03 -0700 (PDT) Received: from workstation.ehrig.io (tmo-065-106.customers.d1-online.com. [80.187.65.106]) by smtp.gmail.com with ESMTPSA id b5-20020a5d4b85000000b002c559843748sm5600416wrt.10.2023.04.01.12.34.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 01 Apr 2023 12:34:02 -0700 (PDT) From: Christian Ehrig To: bpf@vger.kernel.org Cc: cehrig@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 0/3] Add FOU support for externally controlled ipip devices Date: Sat, 1 Apr 2023 22:33:25 +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?1762004259191652490?= X-GMAIL-MSGID: =?utf-8?q?1762004259191652490?= 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. 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 | 27 ++-- net/ipv4/Makefile | 2 +- net/ipv4/fou_bpf.c | 118 ++++++++++++++++++ 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, 360 insertions(+), 17 deletions(-) create mode 100644 net/ipv4/fou_bpf.c