From patchwork Mon Jul 25 14:31:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Chaignon X-Patchwork-Id: 12928128 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2074CCA473 for ; Mon, 25 Jul 2022 14:31:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234629AbiGYObn (ORCPT ); Mon, 25 Jul 2022 10:31:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58770 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235198AbiGYObm (ORCPT ); Mon, 25 Jul 2022 10:31:42 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C35AAE0D9 for ; Mon, 25 Jul 2022 07:31:41 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id i205-20020a1c3bd6000000b003a2fa488efdso3754940wma.4 for ; Mon, 25 Jul 2022 07:31:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=NLgMl3DrugPZ8RbHPgrSGm9F8IPwIYTU5UgW6M92CPM=; b=s2bl6qwF1AJUNo+Yb+dGRnBG8YIUI2+azMc9GwkpBY1lPtacEhK41PtkCs7z/hECnU pdQXDQFcaERx65eVxTPx86+qam4gThF82mEXV2sZVYEyTIJoIEs43fBOmg+MzMzaReu9 VYKF1jEs2h/BNgcBAq1Y+DXhX/h2iwbBNuPGRJQ6FMRv8dORBNfyo/5ScBC621BRI658 dmpHzyy46LTN4WKO4J6143Tp6x3FeF/+f/kxgTLOKk8G15OrI/Ho3DRoT1sCC4UHIpzJ +19cOj3u5sfz7bOH2LnPOaQjrDbud0rx03tsWdwPsf+rEUyZsdCcOkuAeZSmKckC96Wr ouaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=NLgMl3DrugPZ8RbHPgrSGm9F8IPwIYTU5UgW6M92CPM=; b=7G+xasEpXqT9bIrKwDpRp0r8ux34V/gwCLTGxRgvLs+JXCTGP/oXaEBzuxq24WSNFp SmCW+vciuC4HtCZ+MV7RziN0Iyp/gn50/49WHWd/KdV2ocEgZxBnjddwC5iHQ7AbWmSb dQh/TldmwT0ejdO575xYnWLPnTeXju5S97TYutg4eTdjpU8jv74i36MnIvbeBQ87tXZ6 isaCV8ErwOWSp8IU2g+l2PAXdcvQs0b9H0wtCECZUCvONIUWba1b/Ga2wCGJcJdOcFbP 5A5awXWQ0+e0aoHWiZh3imvl7SAMS52MfGcMw0A0161uf0BxxmT2zINsQYIfc9T9aQpp cf3w== X-Gm-Message-State: AJIora8R4QuLJu6Yug7UxJANRiQ6/eJv/sWHhGL4a4AD+br6MmE/HSzw 4EfI/e9Lz1cQzTm9JhW0Z96w X-Google-Smtp-Source: AGRyM1so26EZeGHMsXB+PNCerdHirkQM03vHgsy+0JJKJL88foAnlKkmkyRBMZaFNDu0nVUtVpaT3Q== X-Received: by 2002:a05:600c:3b29:b0:3a3:1fa6:768 with SMTP id m41-20020a05600c3b2900b003a31fa60768mr8867870wms.193.1658759500305; Mon, 25 Jul 2022 07:31:40 -0700 (PDT) Received: from Mem (pop.92-184-116-22.mobile.abo.orange.fr. [92.184.116.22]) by smtp.gmail.com with ESMTPSA id z11-20020a05600c0a0b00b003a17ab4e7c8sm22262167wmp.39.2022.07.25.07.31.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:31:40 -0700 (PDT) Date: Mon, 25 Jul 2022 16:31:37 +0200 From: Paul Chaignon To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Martin KaFai Lau , John Fastabend , Kaixi Fan , Nikolay Aleksandrov , Yonghong Song Subject: [PATCH bpf-next v3 1/5] ip_tunnels: Add new flow flags field to ip_tunnel_key Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net This commit extends the ip_tunnel_key struct with a new field for the flow flags, to pass them to the route lookups. This new field will be populated and used in subsequent commits. Acked-by: Martin KaFai Lau Reviewed-by: Nikolay Aleksandrov Signed-off-by: Paul Chaignon --- include/net/ip_tunnels.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h index 20db95055db3..63fac94f9ace 100644 --- a/include/net/ip_tunnels.h +++ b/include/net/ip_tunnels.h @@ -54,6 +54,7 @@ struct ip_tunnel_key { __be32 label; /* Flow Label for IPv6 */ __be16 tp_src; __be16 tp_dst; + __u8 flow_flags; }; /* Flags for ip_tunnel_info mode. */ From patchwork Mon Jul 25 14:31:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Chaignon X-Patchwork-Id: 12928129 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 52167C43334 for ; Mon, 25 Jul 2022 14:32:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235545AbiGYOcE (ORCPT ); Mon, 25 Jul 2022 10:32:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235198AbiGYOcD (ORCPT ); Mon, 25 Jul 2022 10:32:03 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 984A5CE32 for ; Mon, 25 Jul 2022 07:32:02 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id b26so16254522wrc.2 for ; Mon, 25 Jul 2022 07:32:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=/kAJxldbrmsnL1tLj1jaIBuGNwFFERk4HzZ6Ldyv2Nk=; b=jcF7mq68LW3Zo55ZInonw3SxO28xxzG6Nk3iAk2CwXITIkKG3s4Tq70ULDSFzZjOgj uJ93S3Kt4aNbUaPBTYKpx7hb2EcYr/bDw7DFmMaNWeh4IbaF6zGfrmtwB6FOZR2UxJhK dgX+abQ6SP/mGfyo/01yXloU+YzxknvHzDuQoVEKz43k+OZ1vtBkCk8mxdfrtaPYlR8t WM0n9eIlBpB/TPlKJEnEWqDlTfXVTePtD2dNaygBTI6sh3rA2W/RdnpWg20HmtGsGK8X VMEzQAiXZJn84R1g6dzV1oMcMJGFVrgJDKldBa7YK95Eu4BsYAzevzj3Zf9pmagXTE5+ YU/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=/kAJxldbrmsnL1tLj1jaIBuGNwFFERk4HzZ6Ldyv2Nk=; b=A2HQNZIGTkUUBlmaVI+oUbY4QQj6pSSB+gTif5LPPy0mFGwUa1BWKZhuO+DuxNeqt6 QTSmhC0jBoC84zN2vpm0zX4ZqdYvFn0obBiUKfL+NyQG83Xt7mS4HrGXiMex4xka5att qB92ufSkR4cewDkiSs2SpKEw5TofkKhmuVDrUSKDRvPsGUhB8s7JEDg2rNFR6yttf6ZC b78AoxXv+n7SclIzaIR2nDhxGphzs1H/sh/qWUJ4q5D8mzr9ufTgzCj07shusUY5iP36 Ik2CI2/Py1H4guW5fXx4Dg1hAx6epeth8Kk+uoq0HxzR6hBXiSWS+XW0+9YKc8eBpPtY I/Sw== X-Gm-Message-State: AJIora/UBeX/PmfuXEWgi5JKsNv1sINtuE67K0F/D54iGfPRte/5hsow I+8DSyTNucpBab5RuPpE9e6P X-Google-Smtp-Source: AGRyM1tNTpI0TL5iWQyrhR4IyCetObr6eYaKTaSYBV4jG7xGS+smroXkJ9VPt0jBJAuVgTh/KNi2kQ== X-Received: by 2002:a05:6000:1541:b0:21d:b298:96be with SMTP id 1-20020a056000154100b0021db29896bemr7695910wry.206.1658759521203; Mon, 25 Jul 2022 07:32:01 -0700 (PDT) Received: from Mem (pop.92-184-116-22.mobile.abo.orange.fr. [92.184.116.22]) by smtp.gmail.com with ESMTPSA id c4-20020adffb04000000b0021db7b0162esm8172529wrr.105.2022.07.25.07.32.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:32:00 -0700 (PDT) Date: Mon, 25 Jul 2022 16:31:58 +0200 From: Paul Chaignon To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Martin KaFai Lau , John Fastabend , Kaixi Fan , Nikolay Aleksandrov , Yonghong Song Subject: [PATCH bpf-next v3 2/5] vxlan: Use ip_tunnel_key flow flags in route lookups Message-ID: <1ffc95c3d60182fd5ec0cf6602083f8f68afe98f.1658759380.git.paul@isovalent.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Use the new ip_tunnel_key field with the flow flags in the IPv4 route lookups for the encapsulated packet. This will be used by the bpf_skb_set_tunnel_key helper in a subsequent commit. Acked-by: Martin KaFai Lau Reviewed-by: Nikolay Aleksandrov Signed-off-by: Paul Chaignon --- drivers/net/vxlan/vxlan_core.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 8b0710b576c2..90811ab851fd 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -2243,7 +2243,7 @@ static struct rtable *vxlan_get_route(struct vxlan_dev *vxlan, struct net_device struct vxlan_sock *sock4, struct sk_buff *skb, int oif, u8 tos, __be32 daddr, __be32 *saddr, __be16 dport, __be16 sport, - struct dst_cache *dst_cache, + __u8 flow_flags, struct dst_cache *dst_cache, const struct ip_tunnel_info *info) { bool use_cache = ip_tunnel_dst_cache_usable(skb, info); @@ -2270,6 +2270,7 @@ static struct rtable *vxlan_get_route(struct vxlan_dev *vxlan, struct net_device fl4.saddr = *saddr; fl4.fl4_dport = dport; fl4.fl4_sport = sport; + fl4.flowi4_flags = flow_flags; rt = ip_route_output_key(vxlan->net, &fl4); if (!IS_ERR(rt)) { @@ -2459,7 +2460,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, unsigned int pkt_len = skb->len; __be16 src_port = 0, dst_port; struct dst_entry *ndst = NULL; - __u8 tos, ttl; + __u8 tos, ttl, flow_flags = 0; int ifindex; int err; u32 flags = vxlan->cfg.flags; @@ -2525,6 +2526,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, } dst = &remote_ip; dst_port = info->key.tp_dst ? : vxlan->cfg.dst_port; + flow_flags = info->key.flow_flags; vni = tunnel_id_to_key32(info->key.tun_id); ifindex = 0; dst_cache = &info->dst_cache; @@ -2555,7 +2557,7 @@ static void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, rt = vxlan_get_route(vxlan, dev, sock4, skb, ifindex, tos, dst->sin.sin_addr.s_addr, &local_ip.sin.sin_addr.s_addr, - dst_port, src_port, + dst_port, src_port, flow_flags, dst_cache, info); if (IS_ERR(rt)) { err = PTR_ERR(rt); @@ -3061,7 +3063,8 @@ static int vxlan_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb) rt = vxlan_get_route(vxlan, dev, sock4, skb, 0, info->key.tos, info->key.u.ipv4.dst, &info->key.u.ipv4.src, dport, sport, - &info->dst_cache, info); + info->key.flow_flags, &info->dst_cache, + info); if (IS_ERR(rt)) return PTR_ERR(rt); ip_rt_put(rt); From patchwork Mon Jul 25 14:32:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Chaignon X-Patchwork-Id: 12928130 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5778C433EF for ; Mon, 25 Jul 2022 14:32:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235604AbiGYOcZ (ORCPT ); Mon, 25 Jul 2022 10:32:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59260 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235587AbiGYOcU (ORCPT ); Mon, 25 Jul 2022 10:32:20 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82CD6CE32 for ; Mon, 25 Jul 2022 07:32:19 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id d8so16174722wrp.6 for ; Mon, 25 Jul 2022 07:32:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=47FS747aKSVHMGN4K0Lm+GZNrHYtD3EonHeKad+pVjE=; b=fSgPqjRtxxHT6FXrRf8MlvY8Qi4eaGJ63JQtrk+oFtu1zhCDwsItbCbkK5r/2YRYiy 6kchFdsQPAtVn4y/PFl3RebWETR4TFFY/QGWG3Tx7ttep+zZG+6ldEnT5Jx6EDmpyxgK S2oPm0nj9d58EPmAhifsJVd5FD6GbOJBBeq81SNTVs3Xs/uVkPR3oTX9SLbegmxnLL9W ehEJGM8v+ONkkIpHspXH71Z8oy7Y5nE52Z094GT0RIiRRbwMRKEnQ9csfNW+cSEVzDv7 j4JPUQCVfzC1OYsuam3O1LNFopF+iXCvrrXVtVWW98S80Y/z1MsOcelimPo93rtAKWlC Pvag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=47FS747aKSVHMGN4K0Lm+GZNrHYtD3EonHeKad+pVjE=; b=h10s2KwQeN0+KIwu8XWoGgObpqyCKRmfuPgSr+d4vHlwEhK07ZM1z1mdtMlAPZTjg7 SXBwqBZSWkAW1fJJKLMZr7NMLSmD8qqdvUBHP3vXwnhgl0HGk69VYK46RTjk98PjutBC VIdZ7E6gez6laTqslEaV5PdGjAFtSKnQKLcvhwKgDtUrtvmOzDEc0PZVGScQMH0wkbn0 cwe6PR13vQEDu8QjZcKIv0Qntcoo5lB6Y+jlYmNJZ4MsTkXSYa/9eXwGScCgrG8HzfxR 5j516d+Qsq8Uv9PMZNjgNje6qWVZ579KUQZEO+keoAt+oOm4dzphikltZdBeiSD7rTy/ CHfw== X-Gm-Message-State: AJIora9AfVPLGKk3c12e05JQrRcl+1XI690BIV5u6aUpsQHqqPbm+a0O p7tsT8iFi0neHraZHBz4WnvD X-Google-Smtp-Source: AGRyM1t2/6Dsd3sC15jbmdPl45Mnr+p2VKHZz82Ki7Zb9V/jleCF7UjhBMeKZnNyh6zFGyGYjHJL2g== X-Received: by 2002:adf:f94b:0:b0:21e:46fe:bcdb with SMTP id q11-20020adff94b000000b0021e46febcdbmr7468891wrr.143.1658759538131; Mon, 25 Jul 2022 07:32:18 -0700 (PDT) Received: from Mem (pop.92-184-116-22.mobile.abo.orange.fr. [92.184.116.22]) by smtp.gmail.com with ESMTPSA id o15-20020a05600c510f00b003a30fbde91dsm20469620wms.20.2022.07.25.07.32.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:32:17 -0700 (PDT) Date: Mon, 25 Jul 2022 16:32:15 +0200 From: Paul Chaignon To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Martin KaFai Lau , John Fastabend , Kaixi Fan , Nikolay Aleksandrov , Yonghong Song Subject: [PATCH bpf-next v3 3/5] geneve: Use ip_tunnel_key flow flags in route lookups Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Use the new ip_tunnel_key field with the flow flags in the IPv4 route lookups for the encapsulated packet. This will be used by the bpf_skb_set_tunnel_key helper in the subsequent commit. Acked-by: Martin KaFai Lau Reviewed-by: Nikolay Aleksandrov Signed-off-by: Paul Chaignon --- drivers/net/geneve.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c index 2495a5719e1c..018d365f9deb 100644 --- a/drivers/net/geneve.c +++ b/drivers/net/geneve.c @@ -815,6 +815,7 @@ static struct rtable *geneve_get_v4_rt(struct sk_buff *skb, fl4->saddr = info->key.u.ipv4.src; fl4->fl4_dport = dport; fl4->fl4_sport = sport; + fl4->flowi4_flags = info->key.flow_flags; tos = info->key.tos; if ((tos == 1) && !geneve->cfg.collect_md) { From patchwork Mon Jul 25 14:32:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Chaignon X-Patchwork-Id: 12928131 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD45AC43334 for ; Mon, 25 Jul 2022 14:32:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232874AbiGYOcl (ORCPT ); Mon, 25 Jul 2022 10:32:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233500AbiGYOck (ORCPT ); Mon, 25 Jul 2022 10:32:40 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD937165B0 for ; Mon, 25 Jul 2022 07:32:39 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id n185so6941802wmn.4 for ; Mon, 25 Jul 2022 07:32:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=QYoALPWI5Qsln9dmrFvoAidHpX5YHf+zqZU94kESlow=; b=V5Gs58VwFGzY9otr8BKSX11vsDCp4IhCt3XRJQaD5Q5y/EmK381NGzLDdKXQq9t6Dp JXwGHwhBYj+gmWxdUyqloGBFsHfSwuDfdFyj1Pb7LrXoXIjcVmsjmiVZGAzXDsvOFKGq ytiadrr5Kwez+N8awH4k6CvAyS87p9M2E6J7D8Y1ubnaXTrjd5ZtPakXvHYSxtqiWZjN l+4izIW69ITIPRPIFALrDNyfh2kPoXv75aycHqoqcwn0pff99SpPknnqZZ+viEv5E/7N UMDZhsQFHEncljXR7VcRCQBXvO7BIJq/vFNCeXn5SqSvk+wae/IeINpRDaeEXqEXDA5y 1d+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=QYoALPWI5Qsln9dmrFvoAidHpX5YHf+zqZU94kESlow=; b=m2muCGQeastJG5YACAIriLHYzocce3TH/0LSUWmhNBP1kGkq9OGz7YmA2kcTLe1r1s zZ/2ACY/d8jZmWW4eiAQLoLEUPLKkPIWERbQphhAnXIBfB4pOlb7awjNIuAfQ7byz5rx bBeSUT6WFJfmcOcttzvHvqau1zSVPUpPCJJn9EQQR7c0dy0XRt6IZg4qgY8jzKimoK7L waAFQiHGB4kYwffUcXS7G6R4hyKfbCQ0NeucLoVYmFI/lU4EO195Lh3gS7i1VeskehCV YI3GnIBcwdHnq6nsvJr38P949/RaV8U1KtCau3gfMx+JFhBwFwrjGHg51F7i9l7v44F3 REcg== X-Gm-Message-State: AJIora/WrSWpfKidAY0C4kIF8ldZNJzMt1C/w41sxx9egOFIKlYV6zj6 WVsLxexkbjFMIh63d3zwzkHN X-Google-Smtp-Source: AGRyM1s5ShNgR4PtxFOd1NS6ezM6veQ3HyG6raMpgH6BBpwtnIFdwFGgRY6obihOYjik8vJSV1HFIA== X-Received: by 2002:a05:600c:4e4d:b0:3a3:1fe6:6b20 with SMTP id e13-20020a05600c4e4d00b003a31fe66b20mr8807391wmq.197.1658759558279; Mon, 25 Jul 2022 07:32:38 -0700 (PDT) Received: from Mem (pop.92-184-116-22.mobile.abo.orange.fr. [92.184.116.22]) by smtp.gmail.com with ESMTPSA id o4-20020a056000010400b0021d83eed0e9sm11977573wrx.30.2022.07.25.07.32.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:32:37 -0700 (PDT) Date: Mon, 25 Jul 2022 16:32:34 +0200 From: Paul Chaignon To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Martin KaFai Lau , John Fastabend , Kaixi Fan , Nikolay Aleksandrov , Yonghong Song Subject: [PATCH bpf-next v3 4/5] bpf: Set flow flag to allow any source IP in bpf_tunnel_key Message-ID: <76873d384e21288abe5767551a0799ac93ec07fb.1658759380.git.paul@isovalent.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net Commit 26101f5ab6bd ("bpf: Add source ip in "struct bpf_tunnel_key"") added support for getting and setting the outer source IP of encapsulated packets via the bpf_skb_{get,set}_tunnel_key BPF helper. This change allows BPF programs to set any IP address as the source, including for example the IP address of a container running on the same host. In that last case, however, the encapsulated packets are dropped when looking up the route because the source IP address isn't assigned to any interface on the host. To avoid this, we need to set the FLOWI_FLAG_ANYSRC flag. Fixes: 26101f5ab6bd ("bpf: Add source ip in "struct bpf_tunnel_key"") Acked-by: Martin KaFai Lau Reviewed-by: Nikolay Aleksandrov Signed-off-by: Paul Chaignon --- net/core/filter.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/core/filter.c b/net/core/filter.c index 57c5e4c4efd2..dffc7dcda96a 100644 --- a/net/core/filter.c +++ b/net/core/filter.c @@ -4653,6 +4653,7 @@ BPF_CALL_4(bpf_skb_set_tunnel_key, struct sk_buff *, skb, } else { info->key.u.ipv4.dst = cpu_to_be32(from->remote_ipv4); info->key.u.ipv4.src = cpu_to_be32(from->local_ipv4); + info->key.flow_flags = FLOWI_FLAG_ANYSRC; } return 0; From patchwork Mon Jul 25 14:32:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Chaignon X-Patchwork-Id: 12928132 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4D476C433EF for ; Mon, 25 Jul 2022 14:33:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235608AbiGYOdH (ORCPT ); Mon, 25 Jul 2022 10:33:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235628AbiGYOc7 (ORCPT ); Mon, 25 Jul 2022 10:32:59 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 489D417A9F for ; Mon, 25 Jul 2022 07:32:58 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id k11so15787209wrx.5 for ; Mon, 25 Jul 2022 07:32:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=isovalent-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=xJRtKzZh4YAASphocIV+FMs7Bp3+I3tVnHMfvS4XvB8=; b=QEzXRXMq3fG3hJct4TYLUZr/WR+3yS2Fhn71EZ3vAHso2CfjKtoZ7ZVUQRLB6v0l6e um1zf++CFgAcCjJ3FjMwSeJJMV7GrJzeFJwDNaLyz072xweMKzqVsFYXLRtDJ5K7ykc1 htJ3ImOIwmXntVVAuD4mbNEfvGv/9ZT+xCYoLF5q1ODARvdJqXGTGeGn2YkIVr9ZmPrr MIB3jeuKja3+9WZ4QYwibq1c7XyHmR7QghgfLC6H6C8h+xJgiCDn3LwqG6QSrpBL/RPD DCgHvZuol7PcLamOXdzcl0zIK1LCIwvMAqM0+NemaIH+bAT0y+T/Uxpjg7HZql5NtDdz BlVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=xJRtKzZh4YAASphocIV+FMs7Bp3+I3tVnHMfvS4XvB8=; b=dmZi48A44O/fD54klwgZEPEbHG9HWGROPWuJnt3k1+L9HLlWU1eHUgDhb5y4IH2yqH x6NLPXg3vQFjBy96PKiT8XQFxiFDka+uRd70Ynwzpfx2gNgoLlCAFTpeI133ZgE3B7ID Gx9XDgwGt56nP6YqC+8RhX7ATo0OCLMBNh1i39SDGxTUsAEIgxE1srn0oIJDaYNc91tl 8FQu5dV112yCEwKEhTCwHSMQdSBHiY15y1EqHKTjQfXcul/RQl5xrWx/P9A2VVx+7fki mDk8xiLQMmad4okbatKjE0RJLwkFpPVacnzUFH0B+XTcHAKtGvHXFz+gohwnRA/qJ+BH kLBw== X-Gm-Message-State: AJIora/p+wdZe5WhW2zO1W2W+KOwVTI4DaXZUzd/S/MEk+8r7nZ9wB+f 4nqyYClK7tXfYE0WixtTmsS/ X-Google-Smtp-Source: AGRyM1sfGH32Ar/UiL1CH12pzb9Bkl48yS7kmzKcmSxd8BBKa+ya9fqXO+XtXy5V/Cz3OypxRutGCw== X-Received: by 2002:a5d:64eb:0:b0:21d:75bb:a2f3 with SMTP id g11-20020a5d64eb000000b0021d75bba2f3mr8069597wri.118.1658759576553; Mon, 25 Jul 2022 07:32:56 -0700 (PDT) Received: from Mem (pop.92-184-116-22.mobile.abo.orange.fr. [92.184.116.22]) by smtp.gmail.com with ESMTPSA id q9-20020adfaa49000000b0021e7e050404sm7291871wrd.117.2022.07.25.07.32.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Jul 2022 07:32:56 -0700 (PDT) Date: Mon, 25 Jul 2022 16:32:53 +0200 From: Paul Chaignon To: Alexei Starovoitov , Daniel Borkmann , Andrii Nakryiko Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, Martin KaFai Lau , John Fastabend , Kaixi Fan , Nikolay Aleksandrov , Yonghong Song Subject: [PATCH bpf-next v3 5/5] selftests/bpf: Don't assign outer source IP to host Message-ID: <4addde76eaf3477a58975bef15ed2788c44e5f55.1658759380.git.paul@isovalent.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net The previous commit fixed a bug in the bpf_skb_set_tunnel_key helper to avoid dropping packets whose outer source IP address isn't assigned to a host interface. This commit changes the corresponding selftest to not assign the outer source IP address to an interface. Not assigning the source IP to an interface causes two issues in the existing test: 1. The ARP requests will fail for that IP address so we need to add the ARP entry manually. 2. The encapsulated ICMP echo reply traffic will not reach the VXLAN device. It will be dropped by the stack before, because the outer destination IP is unknown. To solve 2., we have two choices. Either we perform decapsulation ourselves in a BPF program attached at veth1 (the base device for the VXLAN device), or we switch the outer destination address when we receive the packet at veth1, such that the stack properly demultiplexes it to the VXLAN device afterward. This commit implements the second approach, where we switch the outer destination address from the unassigned IP address to the assigned one, only for VXLAN traffic ingressing veth1. Then, at the vxlan device, the BPF program that checks the output of bpf_skb_get_tunnel_key needs to be updated as the expected local IP address is now the unassigned one. Signed-off-by: Paul Chaignon --- .../selftests/bpf/prog_tests/test_tunnel.c | 17 +++- .../selftests/bpf/progs/test_tunnel_kern.c | 80 ++++++++++++++++--- 2 files changed, 86 insertions(+), 11 deletions(-) diff --git a/tools/testing/selftests/bpf/prog_tests/test_tunnel.c b/tools/testing/selftests/bpf/prog_tests/test_tunnel.c index 3bba4a2a0530..eea274110267 100644 --- a/tools/testing/selftests/bpf/prog_tests/test_tunnel.c +++ b/tools/testing/selftests/bpf/prog_tests/test_tunnel.c @@ -82,6 +82,7 @@ #define MAC_TUNL_DEV0 "52:54:00:d9:01:00" #define MAC_TUNL_DEV1 "52:54:00:d9:02:00" +#define MAC_VETH1 "52:54:00:d9:03:00" #define VXLAN_TUNL_DEV0 "vxlan00" #define VXLAN_TUNL_DEV1 "vxlan11" @@ -108,10 +109,9 @@ static int config_device(void) { SYS("ip netns add at_ns0"); - SYS("ip link add veth0 type veth peer name veth1"); + SYS("ip link add veth0 address " MAC_VETH1 " type veth peer name veth1"); SYS("ip link set veth0 netns at_ns0"); SYS("ip addr add " IP4_ADDR1_VETH1 "/24 dev veth1"); - SYS("ip addr add " IP4_ADDR2_VETH1 "/24 dev veth1"); SYS("ip link set dev veth1 up mtu 1500"); SYS("ip netns exec at_ns0 ip addr add " IP4_ADDR_VETH0 "/24 dev veth0"); SYS("ip netns exec at_ns0 ip link set dev veth0 up mtu 1500"); @@ -140,6 +140,8 @@ static int add_vxlan_tunnel(void) VXLAN_TUNL_DEV0, IP4_ADDR_TUNL_DEV0); SYS("ip netns exec at_ns0 ip neigh add %s lladdr %s dev %s", IP4_ADDR_TUNL_DEV1, MAC_TUNL_DEV1, VXLAN_TUNL_DEV0); + SYS("ip netns exec at_ns0 ip neigh add %s lladdr %s dev veth0", + IP4_ADDR2_VETH1, MAC_VETH1); /* root namespace */ SYS("ip link add dev %s type vxlan external gbp dstport 4789", @@ -277,6 +279,17 @@ static void test_vxlan_tunnel(void) if (attach_tc_prog(&tc_hook, get_src_prog_fd, set_src_prog_fd)) goto done; + /* load and attach bpf prog to veth dev tc hook point */ + ifindex = if_nametoindex("veth1"); + if (!ASSERT_NEQ(ifindex, 0, "veth1 ifindex")) + goto done; + tc_hook.ifindex = ifindex; + set_dst_prog_fd = bpf_program__fd(skel->progs.veth_set_outer_dst); + if (!ASSERT_GE(set_dst_prog_fd, 0, "bpf_program__fd")) + goto done; + if (attach_tc_prog(&tc_hook, set_dst_prog_fd, -1)) + goto done; + /* load and attach prog set_md to tunnel dev tc hook point at_ns0 */ nstoken = open_netns("at_ns0"); if (!ASSERT_OK_PTR(nstoken, "setns src")) diff --git a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c index 17f2f325b3f3..df0673c4ecbe 100644 --- a/tools/testing/selftests/bpf/progs/test_tunnel_kern.c +++ b/tools/testing/selftests/bpf/progs/test_tunnel_kern.c @@ -14,15 +14,24 @@ #include #include #include +#include #include #include #include #include +#include #include #include #define log_err(__ret) bpf_printk("ERROR line:%d ret:%d\n", __LINE__, __ret) +#define VXLAN_UDP_PORT 4789 + +/* Only IPv4 address assigned to veth1. + * 172.16.1.200 + */ +#define ASSIGNED_ADDR_VETH1 0xac1001c8 + struct geneve_opt { __be16 opt_class; __u8 type; @@ -33,6 +42,11 @@ struct geneve_opt { __u8 opt_data[8]; /* hard-coded to 8 byte */ }; +struct vxlanhdr { + __be32 vx_flags; + __be32 vx_vni; +} __attribute__((packed)); + struct vxlan_metadata { __u32 gbp; }; @@ -369,14 +383,8 @@ int vxlan_get_tunnel_src(struct __sk_buff *skb) int ret; struct bpf_tunnel_key key; struct vxlan_metadata md; + __u32 orig_daddr; __u32 index = 0; - __u32 *local_ip = NULL; - - local_ip = bpf_map_lookup_elem(&local_ip_map, &index); - if (!local_ip) { - log_err(ret); - return TC_ACT_SHOT; - } ret = bpf_skb_get_tunnel_key(skb, &key, sizeof(key), 0); if (ret < 0) { @@ -390,11 +398,10 @@ int vxlan_get_tunnel_src(struct __sk_buff *skb) return TC_ACT_SHOT; } - if (key.local_ipv4 != *local_ip || md.gbp != 0x800FF) { + if (key.local_ipv4 != ASSIGNED_ADDR_VETH1 || md.gbp != 0x800FF) { bpf_printk("vxlan key %d local ip 0x%x remote ip 0x%x gbp 0x%x\n", key.tunnel_id, key.local_ipv4, key.remote_ipv4, md.gbp); - bpf_printk("local_ip 0x%x\n", *local_ip); log_err(ret); return TC_ACT_SHOT; } @@ -402,6 +409,61 @@ int vxlan_get_tunnel_src(struct __sk_buff *skb) return TC_ACT_OK; } +SEC("tc") +int veth_set_outer_dst(struct __sk_buff *skb) +{ + struct ethhdr *eth = (struct ethhdr *)(long)skb->data; + __u32 assigned_ip = bpf_htonl(ASSIGNED_ADDR_VETH1); + void *data_end = (void *)(long)skb->data_end; + struct udphdr *udph; + struct iphdr *iph; + __u32 index = 0; + int ret = 0; + int shrink; + __s64 csum; + + if ((void *)eth + sizeof(*eth) > data_end) { + log_err(ret); + return TC_ACT_SHOT; + } + + if (eth->h_proto != bpf_htons(ETH_P_IP)) + return TC_ACT_OK; + + iph = (struct iphdr *)(eth + 1); + if ((void *)iph + sizeof(*iph) > data_end) { + log_err(ret); + return TC_ACT_SHOT; + } + if (iph->protocol != IPPROTO_UDP) + return TC_ACT_OK; + + udph = (struct udphdr *)(iph + 1); + if ((void *)udph + sizeof(*udph) > data_end) { + log_err(ret); + return TC_ACT_SHOT; + } + if (udph->dest != bpf_htons(VXLAN_UDP_PORT)) + return TC_ACT_OK; + + if (iph->daddr != assigned_ip) { + csum = bpf_csum_diff(&iph->daddr, sizeof(__u32), &assigned_ip, + sizeof(__u32), 0); + if (bpf_skb_store_bytes(skb, ETH_HLEN + offsetof(struct iphdr, daddr), + &assigned_ip, sizeof(__u32), 0) < 0) { + log_err(ret); + return TC_ACT_SHOT; + } + if (bpf_l3_csum_replace(skb, ETH_HLEN + offsetof(struct iphdr, check), + 0, csum, 0) < 0) { + log_err(ret); + return TC_ACT_SHOT; + } + bpf_skb_change_type(skb, PACKET_HOST); + } + return TC_ACT_OK; +} + SEC("tc") int ip6vxlan_set_tunnel_dst(struct __sk_buff *skb) {