From patchwork Mon Oct 9 08:20:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beniamino Galvani X-Patchwork-Id: 13413065 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7EFE14F8F for ; Mon, 9 Oct 2023 08:26:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AioNfOgH" Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0062A3; Mon, 9 Oct 2023 01:26:15 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-9ba081173a3so345776966b.1; Mon, 09 Oct 2023 01:26:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696839974; x=1697444774; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Opywzopv/cnUh7Yw86K3XXL6gpkdH/O5UwAJEnT8/MY=; b=AioNfOgHKfpjl+LngYXQPJE+fwxO1DTyFXQbylQUl6TMxs29TkCGz4hkTcC2rL1XLQ gVGytWeC0Yu05XaUilVrP4RhayKZwFEkXPHPT9PTSSg2TR1Yzah+38mxH9FIb/+mcKr3 v7Y/yFrVURCJFoo6ZFkRRULlvdD2edKfhbaDkB0xqgnZtZ44z75vvgZMnAhkcoJXpr6L QgIzJGFq3tAbLDXjQ0J9kuJkAFdCW4w6zdrd2wI/uS3UtoT9xjjBeRmRF4g0rIzQBqwL DggccEqfKyOu+8eYZ3LUE5LAWQ9lg5NoFguvZMzxkGZ85Y34gj2kyK15b1cEmZ1p0JpQ 09Hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696839974; x=1697444774; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Opywzopv/cnUh7Yw86K3XXL6gpkdH/O5UwAJEnT8/MY=; b=Fzv5ufWa1zdogVBsAywIfiDFU0CN35HfERUtCMULNUA8VUM87Erl3v+FFmRpkUDFB4 d2avSzb5vyjkH4XMM4w0RZBtXZk+9VdClw9xOmOqDysU4gaLxBNIMTfnwAjQCJzSZXRR Dcgpd6Nww4Rr8/TMsw4i4RgXGt+cbCADK7rlhEqbQaZTUU7nly7sTVeGBrKFnicoSdvN FiQKLl9CYZyqhCpou0vyPY5GG6QFdazq+lYo276f4FDTSwJw2t4MngqZuB0BVaqMWrA8 F8/i0zGptWhKGZ7QDMRk4le+VPlu+8c/KJXtiT/m7M4UetqC+Um0OhTL/IgumvwMCweS h3Ag== X-Gm-Message-State: AOJu0YyK16HSFkXly6RaPCa47UyxQDOvXz4T9ZhINybtq0u4Zz5zbvpc 0YfdRqpLAkh4qsQDAN4DwkW6uWxgW8g= X-Google-Smtp-Source: AGHT+IHKQ+URUWHDu65yyUqVpyP8fZ8v2rTvsID+c3SvKSQOU2A35ogl6EU1qLjeoRao1ZMEkIwMAw== X-Received: by 2002:a17:906:305a:b0:9ae:5487:c71c with SMTP id d26-20020a170906305a00b009ae5487c71cmr12804086ejd.49.1696839974220; Mon, 09 Oct 2023 01:26:14 -0700 (PDT) Received: from tp.home.arpa (host-79-24-102-58.retail.telecomitalia.it. [79.24.102.58]) by smtp.gmail.com with ESMTPSA id p22-20020a05640210d600b00530a9488623sm5844810edu.46.2023.10.09.01.26.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 01:26:14 -0700 (PDT) From: Beniamino Galvani To: netdev@vger.kernel.org Cc: "David S . Miller" , Jakub Kicinski , Paolo Abeni , David Ahern , Guillaume Nault , linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/7] ipv4: rename and move ip_route_output_tunnel() Date: Mon, 9 Oct 2023 10:20:53 +0200 Message-Id: <20231009082059.2500217-2-b.galvani@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231009082059.2500217-1-b.galvani@gmail.com> References: <20231009082059.2500217-1-b.galvani@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org At the moment ip_route_output_tunnel() is used only by bareudp. Ideally, other UDP tunnel implementations should use it, but to do so the function needs to accept new parameters that are specific for UDP tunnels, such as the ports. Prepare for these changes by renaming the function to udp_tunnel_dst_lookup() and move it to file net/ipv4/udp_tunnel_core.c. Suggested-by: Guillaume Nault Signed-off-by: Beniamino Galvani Reviewed-by: David Ahern --- drivers/net/bareudp.c | 8 +++---- include/net/route.h | 6 ----- include/net/udp_tunnel.h | 6 +++++ net/ipv4/route.c | 48 -------------------------------------- net/ipv4/udp_tunnel_core.c | 48 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 58 insertions(+), 58 deletions(-) diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c index 683203f87ae2..63fc32fa1af5 100644 --- a/drivers/net/bareudp.c +++ b/drivers/net/bareudp.c @@ -306,8 +306,8 @@ static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev, if (!sock) return -ESHUTDOWN; - rt = ip_route_output_tunnel(skb, dev, bareudp->net, &saddr, info, - IPPROTO_UDP, use_cache); + rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr, info, + IPPROTO_UDP, use_cache); if (IS_ERR(rt)) return PTR_ERR(rt); @@ -483,8 +483,8 @@ static int bareudp_fill_metadata_dst(struct net_device *dev, struct rtable *rt; __be32 saddr; - rt = ip_route_output_tunnel(skb, dev, bareudp->net, &saddr, - info, IPPROTO_UDP, use_cache); + rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr, + info, IPPROTO_UDP, use_cache); if (IS_ERR(rt)) return PTR_ERR(rt); diff --git a/include/net/route.h b/include/net/route.h index 5c248a8e3d0e..980ab474eabd 100644 --- a/include/net/route.h +++ b/include/net/route.h @@ -136,12 +136,6 @@ static inline struct rtable *__ip_route_output_key(struct net *net, struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp, const struct sock *sk); -struct rtable *ip_route_output_tunnel(struct sk_buff *skb, - struct net_device *dev, - struct net *net, __be32 *saddr, - const struct ip_tunnel_info *info, - u8 protocol, bool use_cache); - struct dst_entry *ipv4_blackhole_route(struct net *net, struct dst_entry *dst_orig); diff --git a/include/net/udp_tunnel.h b/include/net/udp_tunnel.h index 21ba0a25f936..11e810ca5088 100644 --- a/include/net/udp_tunnel.h +++ b/include/net/udp_tunnel.h @@ -162,6 +162,12 @@ int udp_tunnel6_xmit_skb(struct dst_entry *dst, struct sock *sk, void udp_tunnel_sock_release(struct socket *sock); +struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb, + struct net_device *dev, + struct net *net, __be32 *saddr, + const struct ip_tunnel_info *info, + u8 protocol, bool use_cache); + struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family, __be16 flags, __be64 tunnel_id, int md_size); diff --git a/net/ipv4/route.c b/net/ipv4/route.c index e2bf4602b559..3290a4442b4a 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -2885,54 +2885,6 @@ struct rtable *ip_route_output_flow(struct net *net, struct flowi4 *flp4, } EXPORT_SYMBOL_GPL(ip_route_output_flow); -struct rtable *ip_route_output_tunnel(struct sk_buff *skb, - struct net_device *dev, - struct net *net, __be32 *saddr, - const struct ip_tunnel_info *info, - u8 protocol, bool use_cache) -{ -#ifdef CONFIG_DST_CACHE - struct dst_cache *dst_cache; -#endif - struct rtable *rt = NULL; - struct flowi4 fl4; - __u8 tos; - -#ifdef CONFIG_DST_CACHE - dst_cache = (struct dst_cache *)&info->dst_cache; - if (use_cache) { - rt = dst_cache_get_ip4(dst_cache, saddr); - if (rt) - return rt; - } -#endif - memset(&fl4, 0, sizeof(fl4)); - fl4.flowi4_mark = skb->mark; - fl4.flowi4_proto = protocol; - fl4.daddr = info->key.u.ipv4.dst; - fl4.saddr = info->key.u.ipv4.src; - tos = info->key.tos; - fl4.flowi4_tos = RT_TOS(tos); - - rt = ip_route_output_key(net, &fl4); - if (IS_ERR(rt)) { - netdev_dbg(dev, "no route to %pI4\n", &fl4.daddr); - return ERR_PTR(-ENETUNREACH); - } - if (rt->dst.dev == dev) { /* is this necessary? */ - netdev_dbg(dev, "circular route to %pI4\n", &fl4.daddr); - ip_rt_put(rt); - return ERR_PTR(-ELOOP); - } -#ifdef CONFIG_DST_CACHE - if (use_cache) - dst_cache_set_ip4(dst_cache, &rt->dst, fl4.saddr); -#endif - *saddr = fl4.saddr; - return rt; -} -EXPORT_SYMBOL_GPL(ip_route_output_tunnel); - /* called with rcu_read_lock held */ static int rt_fill_info(struct net *net, __be32 dst, __be32 src, struct rtable *rt, u32 table_id, struct flowi4 *fl4, diff --git a/net/ipv4/udp_tunnel_core.c b/net/ipv4/udp_tunnel_core.c index 1e7e4aecdc48..96f93f92b6ce 100644 --- a/net/ipv4/udp_tunnel_core.c +++ b/net/ipv4/udp_tunnel_core.c @@ -204,4 +204,52 @@ struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family, } EXPORT_SYMBOL_GPL(udp_tun_rx_dst); +struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb, + struct net_device *dev, + struct net *net, __be32 *saddr, + const struct ip_tunnel_info *info, + u8 protocol, bool use_cache) +{ +#ifdef CONFIG_DST_CACHE + struct dst_cache *dst_cache; +#endif + struct rtable *rt = NULL; + struct flowi4 fl4; + __u8 tos; + +#ifdef CONFIG_DST_CACHE + dst_cache = (struct dst_cache *)&info->dst_cache; + if (use_cache) { + rt = dst_cache_get_ip4(dst_cache, saddr); + if (rt) + return rt; + } +#endif + memset(&fl4, 0, sizeof(fl4)); + fl4.flowi4_mark = skb->mark; + fl4.flowi4_proto = protocol; + fl4.daddr = info->key.u.ipv4.dst; + fl4.saddr = info->key.u.ipv4.src; + tos = info->key.tos; + fl4.flowi4_tos = RT_TOS(tos); + + rt = ip_route_output_key(net, &fl4); + if (IS_ERR(rt)) { + netdev_dbg(dev, "no route to %pI4\n", &fl4.daddr); + return ERR_PTR(-ENETUNREACH); + } + if (rt->dst.dev == dev) { /* is this necessary? */ + netdev_dbg(dev, "circular route to %pI4\n", &fl4.daddr); + ip_rt_put(rt); + return ERR_PTR(-ELOOP); + } +#ifdef CONFIG_DST_CACHE + if (use_cache) + dst_cache_set_ip4(dst_cache, &rt->dst, fl4.saddr); +#endif + *saddr = fl4.saddr; + return rt; +} +EXPORT_SYMBOL_GPL(udp_tunnel_dst_lookup); + MODULE_LICENSE("GPL"); From patchwork Mon Oct 9 08:20:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beniamino Galvani X-Patchwork-Id: 13413066 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2D341156D6 for ; Mon, 9 Oct 2023 08:26:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="N3C5cU4F" Received: from mail-ed1-x52d.google.com (mail-ed1-x52d.google.com [IPv6:2a00:1450:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9478DA6; Mon, 9 Oct 2023 01:26:16 -0700 (PDT) Received: by mail-ed1-x52d.google.com with SMTP id 4fb4d7f45d1cf-533c8f8f91dso7398395a12.0; Mon, 09 Oct 2023 01:26:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696839975; x=1697444775; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Os97uJkJsOrtu1p2tFHU0znx2hLK/XLtOzuWt/ufDjM=; b=N3C5cU4FqpPgupmpRkwNj5ye1+wZkBcGTYetrNx9WkZAK1rYqbfawkHSqdwMG3K3RE HkOV3SgJPON0/i1cHwG7pFCzUcx3S/WKceLLH43UI1oDMG3dBcXkj+yMei01/+hunRdD hs1UdetnOUmNjWmrM+DnVT45fBan0bk0zQROlkGLMQbqwUj8lTAbMIfvKWgSD8H44uTm AcbSXtS8A1aOW+kNsZSJmRHCjOLeOOTfzLFAX5swsXm62v64PngZ1doLerdJy3NbgKU3 8QdscxLFnC/I39c6JTXXLzs6XazU6jhToJhKkyc2MXH469UHNM/b5HKGYtXKK74TvjTB r9yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696839975; x=1697444775; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Os97uJkJsOrtu1p2tFHU0znx2hLK/XLtOzuWt/ufDjM=; b=EVsmCwv5AcMl7le+N4QQXhshl1lWW47VcJXpU0qxXkHWnPwQ6Go18ctBHbp2SlFo5m 9oMZ6hi4O1A+5aXhu3t44cODxaTb1QBCjWLvzlnEymRk3BIXbDwzH0llHLK1Bbql9EgQ lnRy8OM+q6+hlsAhjTQ7moSpKu2g3vWN33cDlBqcWr/Un47CsoOQvASVxYjmxTbiQ0x3 RdLlsdx1BXCLpSKYhST21nreWLcMNmYSBRuhI3MsyuxXxM1XNDJJz1Me5J8lLOB8qNBr b2xUiSQpWf/XOtXlHZN3gDXJV9qfuLaMPdDclaokI4LuO5BiDROpRH0qGDvMW4vYvPYo rWJQ== X-Gm-Message-State: AOJu0YyR9e3QgcSzrmdS95Cspyct93mVM5o1tvQ9B36FPX4fig4iT0ut JGon9GPqEqT0DI6/6kss+xCliLxNSIg= X-Google-Smtp-Source: AGHT+IHVbSbHzTw0t3kXZPAeQfB7tNuAcPJxTru1b461a2301Jo93Irw/iY8dgHDGybRmc8CO3hxng== X-Received: by 2002:aa7:c746:0:b0:52a:38c3:1b49 with SMTP id c6-20020aa7c746000000b0052a38c31b49mr11361653eds.40.1696839974917; Mon, 09 Oct 2023 01:26:14 -0700 (PDT) Received: from tp.home.arpa (host-79-24-102-58.retail.telecomitalia.it. [79.24.102.58]) by smtp.gmail.com with ESMTPSA id p22-20020a05640210d600b00530a9488623sm5844810edu.46.2023.10.09.01.26.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 01:26:14 -0700 (PDT) From: Beniamino Galvani To: netdev@vger.kernel.org Cc: "David S . Miller" , Jakub Kicinski , Paolo Abeni , David Ahern , Guillaume Nault , linux-kernel@vger.kernel.org Subject: [PATCH net-next 2/7] ipv4: remove "proto" argument from udp_tunnel_dst_lookup() Date: Mon, 9 Oct 2023 10:20:54 +0200 Message-Id: <20231009082059.2500217-3-b.galvani@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231009082059.2500217-1-b.galvani@gmail.com> References: <20231009082059.2500217-1-b.galvani@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org The function is now UDP-specific, the protocol is always IPPROTO_UDP. Suggested-by: Guillaume Nault Signed-off-by: Beniamino Galvani Reviewed-by: David Ahern --- drivers/net/bareudp.c | 4 ++-- include/net/udp_tunnel.h | 2 +- net/ipv4/udp_tunnel_core.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c index 63fc32fa1af5..6af67cac6bde 100644 --- a/drivers/net/bareudp.c +++ b/drivers/net/bareudp.c @@ -307,7 +307,7 @@ static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev, return -ESHUTDOWN; rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr, info, - IPPROTO_UDP, use_cache); + use_cache); if (IS_ERR(rt)) return PTR_ERR(rt); @@ -484,7 +484,7 @@ static int bareudp_fill_metadata_dst(struct net_device *dev, __be32 saddr; rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr, - info, IPPROTO_UDP, use_cache); + info, use_cache); if (IS_ERR(rt)) return PTR_ERR(rt); diff --git a/include/net/udp_tunnel.h b/include/net/udp_tunnel.h index 11e810ca5088..8f110dbd3784 100644 --- a/include/net/udp_tunnel.h +++ b/include/net/udp_tunnel.h @@ -166,7 +166,7 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb, struct net_device *dev, struct net *net, __be32 *saddr, const struct ip_tunnel_info *info, - u8 protocol, bool use_cache); + bool use_cache); struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family, __be16 flags, __be64 tunnel_id, diff --git a/net/ipv4/udp_tunnel_core.c b/net/ipv4/udp_tunnel_core.c index 96f93f92b6ce..9b0cfd72d5fd 100644 --- a/net/ipv4/udp_tunnel_core.c +++ b/net/ipv4/udp_tunnel_core.c @@ -208,7 +208,7 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb, struct net_device *dev, struct net *net, __be32 *saddr, const struct ip_tunnel_info *info, - u8 protocol, bool use_cache) + bool use_cache) { #ifdef CONFIG_DST_CACHE struct dst_cache *dst_cache; @@ -227,7 +227,7 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb, #endif memset(&fl4, 0, sizeof(fl4)); fl4.flowi4_mark = skb->mark; - fl4.flowi4_proto = protocol; + fl4.flowi4_proto = IPPROTO_UDP; fl4.daddr = info->key.u.ipv4.dst; fl4.saddr = info->key.u.ipv4.src; tos = info->key.tos; From patchwork Mon Oct 9 08:20:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beniamino Galvani X-Patchwork-Id: 13413069 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 88B30156DE for ; Mon, 9 Oct 2023 08:26:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fcf95qot" Received: from mail-ed1-x531.google.com (mail-ed1-x531.google.com [IPv6:2a00:1450:4864:20::531]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 856CDAB; Mon, 9 Oct 2023 01:26:17 -0700 (PDT) Received: by mail-ed1-x531.google.com with SMTP id 4fb4d7f45d1cf-536b39daec1so7218314a12.2; Mon, 09 Oct 2023 01:26:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696839975; x=1697444775; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EyObhFDaQNlftjPmA42QI8DJSxQ8P2np8YChl5TvP6A=; b=fcf95qotundpBmuGOPoRZNN+LI8HrEkKwl3IgridkWnZlyPEaSiL37npkotqWcO5BY LgljhpECnJ+fuB5dj2ZYeY7fYZGLVXmWslYiF7U25VzPqAzUfXn6Xgp9yLsYvTjkau08 +DsSTIiGeaJTroxsoS8ypMpcVO9LEKz4II/DSZ9yAG1mEb2MvkBEWYI1j93HAVGuSaCG plMf/v6WCp+mQnUXnQslvAuAO7UlJlUY/pF4je/+0yAHcDdjgFt+Tl5l3P/2Oo20/vFW 6Mv1e1sDw/a8GNqLtmfVb+BA2zWRmEbNdcPGaKeW4Gc/P/juaQ4jyaAoG30cpWBULyPW wfCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696839975; x=1697444775; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EyObhFDaQNlftjPmA42QI8DJSxQ8P2np8YChl5TvP6A=; b=wMGtkBuGKHooslv3PUN0QBl3Nms7L0+Kop3nsiuyb2pI8IDbEJvFqoktW03yaY6uhv L11TMT2z4jl3zcAAjwXroCNiYYJRNf6jRfXhiN1srtAJ3nd+GRJErhm9KqMU2hpNWpJX tmlBzFiwJrP6HgVaInH2GnCktPmeUkj/hDUE9TO4cHtbW4mKxxrooB8svHmL+WwcKF1L koKE/8joplBx64yerzoVO9Q0mtALvBcikFclKvg6vEgljoqy6WBwMHoie00AS8VbQSzl NUdbyvNzpvfQm0keskixmge+6rvn9IAZy6ZtGqjBUbDuq6b/IdMB7xPBYLWzY6MIN188 IwIg== X-Gm-Message-State: AOJu0Yx0Ust0qbHjZVqwk6vHzBXVXu46lcogNbXk+1Tj/MYc0R/vNEEr CNvfXO+x/Nx/N/o25815vRvM3RnI9+0= X-Google-Smtp-Source: AGHT+IFT9vlPZ1jcLtiVVmYWzThL5CE+T6YV6iD1UjZv2n6KHxKuwBDo/UcVqlhwwDyJoRmEm8F2CA== X-Received: by 2002:aa7:d902:0:b0:52c:9f89:4447 with SMTP id a2-20020aa7d902000000b0052c9f894447mr12963676edr.4.1696839975523; Mon, 09 Oct 2023 01:26:15 -0700 (PDT) Received: from tp.home.arpa (host-79-24-102-58.retail.telecomitalia.it. [79.24.102.58]) by smtp.gmail.com with ESMTPSA id p22-20020a05640210d600b00530a9488623sm5844810edu.46.2023.10.09.01.26.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 01:26:15 -0700 (PDT) From: Beniamino Galvani To: netdev@vger.kernel.org Cc: "David S . Miller" , Jakub Kicinski , Paolo Abeni , David Ahern , Guillaume Nault , linux-kernel@vger.kernel.org Subject: [PATCH net-next 3/7] ipv4: add new arguments to udp_tunnel_dst_lookup() Date: Mon, 9 Oct 2023 10:20:55 +0200 Message-Id: <20231009082059.2500217-4-b.galvani@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231009082059.2500217-1-b.galvani@gmail.com> References: <20231009082059.2500217-1-b.galvani@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org We want to make the function more generic so that it can be used by other UDP tunnel implementations such as geneve and vxlan. To do that, add the following arguments: - source and destination UDP port; - ifindex of the output interface, needed by vxlan; - the tos, because in some cases it is not taken from struct ip_tunnel_info (for example, when it's inherited from the inner packet); - the dst cache, because not all tunnel types (e.g. vxlan) want to use the one from struct ip_tunnel_info. With these parameters, the function no longer needs the full struct ip_tunnel_info as argument and we can pass only the relevant part of it (struct ip_tunnel_key). Suggested-by: Guillaume Nault Signed-off-by: Beniamino Galvani Reviewed-by: David Ahern --- drivers/net/bareudp.c | 11 +++++++---- include/net/udp_tunnel.h | 8 +++++--- net/ipv4/udp_tunnel_core.c | 26 +++++++++++++------------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c index 6af67cac6bde..47a9c2a5583c 100644 --- a/drivers/net/bareudp.c +++ b/drivers/net/bareudp.c @@ -306,8 +306,10 @@ static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev, if (!sock) return -ESHUTDOWN; - rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr, info, - use_cache); + rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, 0, &saddr, &info->key, + 0, 0, key->tos, + use_cache ? + (struct dst_cache *)&info->dst_cache : NULL); if (IS_ERR(rt)) return PTR_ERR(rt); @@ -483,8 +485,9 @@ static int bareudp_fill_metadata_dst(struct net_device *dev, struct rtable *rt; __be32 saddr; - rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr, - info, use_cache); + rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, 0, &saddr, + &info->key, 0, 0, info->key.tos, + use_cache ? &info->dst_cache : NULL); if (IS_ERR(rt)) return PTR_ERR(rt); diff --git a/include/net/udp_tunnel.h b/include/net/udp_tunnel.h index 8f110dbd3784..4d0578fab01a 100644 --- a/include/net/udp_tunnel.h +++ b/include/net/udp_tunnel.h @@ -164,9 +164,11 @@ void udp_tunnel_sock_release(struct socket *sock); struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb, struct net_device *dev, - struct net *net, __be32 *saddr, - const struct ip_tunnel_info *info, - bool use_cache); + struct net *net, int oif, + __be32 *saddr, + const struct ip_tunnel_key *key, + __be16 sport, __be16 dport, u8 tos, + struct dst_cache *dst_cache); struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family, __be16 flags, __be64 tunnel_id, diff --git a/net/ipv4/udp_tunnel_core.c b/net/ipv4/udp_tunnel_core.c index 9b0cfd72d5fd..494685e82856 100644 --- a/net/ipv4/udp_tunnel_core.c +++ b/net/ipv4/udp_tunnel_core.c @@ -206,31 +206,31 @@ EXPORT_SYMBOL_GPL(udp_tun_rx_dst); struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb, struct net_device *dev, - struct net *net, __be32 *saddr, - const struct ip_tunnel_info *info, - bool use_cache) + struct net *net, int oif, + __be32 *saddr, + const struct ip_tunnel_key *key, + __be16 sport, __be16 dport, u8 tos, + struct dst_cache *dst_cache) { -#ifdef CONFIG_DST_CACHE - struct dst_cache *dst_cache; -#endif struct rtable *rt = NULL; struct flowi4 fl4; - __u8 tos; #ifdef CONFIG_DST_CACHE - dst_cache = (struct dst_cache *)&info->dst_cache; - if (use_cache) { + if (dst_cache) { rt = dst_cache_get_ip4(dst_cache, saddr); if (rt) return rt; } #endif + memset(&fl4, 0, sizeof(fl4)); fl4.flowi4_mark = skb->mark; fl4.flowi4_proto = IPPROTO_UDP; - fl4.daddr = info->key.u.ipv4.dst; - fl4.saddr = info->key.u.ipv4.src; - tos = info->key.tos; + fl4.flowi4_oif = oif; + fl4.daddr = key->u.ipv4.dst; + fl4.saddr = key->u.ipv4.src; + fl4.fl4_dport = dport; + fl4.fl4_sport = sport; fl4.flowi4_tos = RT_TOS(tos); rt = ip_route_output_key(net, &fl4); @@ -244,7 +244,7 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb, return ERR_PTR(-ELOOP); } #ifdef CONFIG_DST_CACHE - if (use_cache) + if (dst_cache) dst_cache_set_ip4(dst_cache, &rt->dst, fl4.saddr); #endif *saddr = fl4.saddr; From patchwork Mon Oct 9 08:20:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beniamino Galvani X-Patchwork-Id: 13413067 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19B3F156EF for ; Mon, 9 Oct 2023 08:26:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="JzYE4dew" Received: from mail-ed1-x535.google.com (mail-ed1-x535.google.com [IPv6:2a00:1450:4864:20::535]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBC24AC; Mon, 9 Oct 2023 01:26:17 -0700 (PDT) Received: by mail-ed1-x535.google.com with SMTP id 4fb4d7f45d1cf-538575a38ffso6894114a12.1; Mon, 09 Oct 2023 01:26:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696839976; x=1697444776; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=wZtyZM5UwNK1vdlTVhqvX8FdpSesET9nnywzUTMvlnU=; b=JzYE4dewsSL83JkXoc2qr0pwUqhP3gCxdCHkK9ZZ+IJu56+daDgZz6zv7J4PWIePdb h3kC6N0N7VtlVl7Ug82GCHDGnxD4qhtdbeXJQTeJksQMyCgQd4XAIvcgsFO4f6GDPACY X8L/tPZWN9MObSm1MLzcOjhvxCU7XBs/+8erSfsnooQGox2i2ROC8K7Xf1e5Fn0yEr4O MtlQj2npwNznCxO3ytbcdCkUXdQrZzvQZnIUtdbvvS+EWg0B8N44K7iuyI5lfp8gw7qT UlJlAGv3zjl5iQGpoxEORUrdAaimkBe06i3gF/0Z4dcStvDQXr/2nO5VLSkGIN6JxRdk xyug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696839976; x=1697444776; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=wZtyZM5UwNK1vdlTVhqvX8FdpSesET9nnywzUTMvlnU=; b=HmBsX3q6dAL0uH6ed8O8f8LtZfkF+znM4GrRvALV2OBVVzeVlUkl0qfN0uZ1a2oBp+ DRjuVIjYFZf4FyviMBIgxCwvX/pcbmVOC11GqS6m2gHlAIxss4P1ewE5NyAVco73uy4u FpRh6GwdMtyS6qf58WTYE/vYYep3pXQJUaesBQO5NDHJzwuYOo5e2S/6o0gvH+Ch0bf5 eJTyXyk09alNEpmpu3w496aigNBfpqlS39+oralT7gazxQM+N7PWSTVnZHn+FbyPF3F6 gCEKSddG9rD3VHvP6I43db2j48JPgp3ooso2KwBRCeC/RTRCBA6o7AGoYBxKRotGy+gA fjeg== X-Gm-Message-State: AOJu0YzXHBBH7Egogugpqg5BRS05nteL766AQuPoc7oyISYorAOvZypC d1Z3obs/ZvVOk+UmotRLIIg5fWRyO+g= X-Google-Smtp-Source: AGHT+IGIbhGzFHVEyX2qL3XYXw9TNxMLPN8Qz0eEfIbGrSAzMf+0laqRxwW5pbhv5wkyAyr/ofTqDQ== X-Received: by 2002:aa7:cf92:0:b0:523:102f:3ce1 with SMTP id z18-20020aa7cf92000000b00523102f3ce1mr12742631edx.10.1696839976258; Mon, 09 Oct 2023 01:26:16 -0700 (PDT) Received: from tp.home.arpa (host-79-24-102-58.retail.telecomitalia.it. [79.24.102.58]) by smtp.gmail.com with ESMTPSA id p22-20020a05640210d600b00530a9488623sm5844810edu.46.2023.10.09.01.26.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 01:26:16 -0700 (PDT) From: Beniamino Galvani To: netdev@vger.kernel.org Cc: "David S . Miller" , Jakub Kicinski , Paolo Abeni , David Ahern , Guillaume Nault , linux-kernel@vger.kernel.org Subject: [PATCH net-next 4/7] ipv4: use tunnel flow flags for tunnel route lookups Date: Mon, 9 Oct 2023 10:20:56 +0200 Message-Id: <20231009082059.2500217-5-b.galvani@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231009082059.2500217-1-b.galvani@gmail.com> References: <20231009082059.2500217-1-b.galvani@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Commit 451ef36bd229 ("ip_tunnels: Add new flow flags field to ip_tunnel_key") added a new field to struct ip_tunnel_key to control route lookups. Currently the flag is used by vxlan and geneve tunnels; use it also in udp_tunnel_dst_lookup() so that it affects all tunnel types relying on this function. Signed-off-by: Beniamino Galvani Reviewed-by: David Ahern --- net/ipv4/udp_tunnel_core.c | 1 + 1 file changed, 1 insertion(+) diff --git a/net/ipv4/udp_tunnel_core.c b/net/ipv4/udp_tunnel_core.c index 494685e82856..a87defb2b167 100644 --- a/net/ipv4/udp_tunnel_core.c +++ b/net/ipv4/udp_tunnel_core.c @@ -232,6 +232,7 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb, fl4.fl4_dport = dport; fl4.fl4_sport = sport; fl4.flowi4_tos = RT_TOS(tos); + fl4.flowi4_flags = key->flow_flags; rt = ip_route_output_key(net, &fl4); if (IS_ERR(rt)) { From patchwork Mon Oct 9 08:20:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beniamino Galvani X-Patchwork-Id: 13413068 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 19BC5156F0 for ; Mon, 9 Oct 2023 08:26:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iaR+4tJ0" Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 848B2B6; Mon, 9 Oct 2023 01:26:18 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-533c5d10dc7so7345409a12.3; Mon, 09 Oct 2023 01:26:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696839977; x=1697444777; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=owZcEmAsFdnN8HKDvbp9Goa51e2ivCQAo3bw3SJCz0I=; b=iaR+4tJ0aTLMAb2Q3pCq53cY4VSkV0xmjR/4hp4U9CSxXJu95E7khnBnEddGEJDeb0 SmbEzA4jfaIkiSfJkIWGV36AS6U3m+OLNNONUpVc4skw5HGUKpAwtJB05YoD0zmYwynZ pQ01ljk6aKpYDs8Jf718H1cEd0CeSz/od6mQE5tIlubBi4P9OPJL72uBgXmM18OQAix/ r6YtpjJrINO7/9+9OJXy30/iFDAY/WkZEm3bm/7RENx1skztwOds5Zu/GMO3clVaowbh OKNDmBquIm/fQOsHuDS3Fya/ZUAaV3uGnqvJsczliSfiJIG9vfot3mNyVe01DUDZcS0k XUqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696839977; x=1697444777; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=owZcEmAsFdnN8HKDvbp9Goa51e2ivCQAo3bw3SJCz0I=; b=wmttCGXYY+DkNk0kQSLvHjbE0HWkVm4qj4WMy+NnCJz/6vGtugCeOtH1KN2d1omJAm D60b+CVBsuteMhbHOGwsW4SuAeewxW9sraDB1cts16cOL973+4L4fYEounHZ/CMEy4fS 9UPTGydY9PvCtbnyv2Pncr0zrate/K7rdDIrOqerj9/ZtUt0AnzhNKwPAcgqRL6LlOco qqJgcphI1LHDG4R40pMnHkppOhunZZBev4kxhGx2b0CVzOlxGfSqjQ0pXNU/oZ8f6iIZ iplarwjPzS7+kvVPoQA/9IpHA5zOvxF/LI6B9LoGMgPR9aweVVcjieo83SmGvH/Zd7KN ok4Q== X-Gm-Message-State: AOJu0Ywdtr2qowBDTASot2l/jtHKpJIDzLErt0tS0+RNIbxtoy6xmhql H6b4gRAe7xhOL1UnKr1D6EL6hc8dmm4= X-Google-Smtp-Source: AGHT+IHPgo2UaEnqpB7MU1D11ZGnLn8MHmAsbVr1gfJ6Y+aIuhETe25/EiAThILS6QVpbC9HUpnxYg== X-Received: by 2002:aa7:d415:0:b0:522:1d30:efce with SMTP id z21-20020aa7d415000000b005221d30efcemr12933263edq.22.1696839976943; Mon, 09 Oct 2023 01:26:16 -0700 (PDT) Received: from tp.home.arpa (host-79-24-102-58.retail.telecomitalia.it. [79.24.102.58]) by smtp.gmail.com with ESMTPSA id p22-20020a05640210d600b00530a9488623sm5844810edu.46.2023.10.09.01.26.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 01:26:16 -0700 (PDT) From: Beniamino Galvani To: netdev@vger.kernel.org Cc: "David S . Miller" , Jakub Kicinski , Paolo Abeni , David Ahern , Guillaume Nault , linux-kernel@vger.kernel.org Subject: [PATCH net-next 5/7] geneve: add dsfield helper function Date: Mon, 9 Oct 2023 10:20:57 +0200 Message-Id: <20231009082059.2500217-6-b.galvani@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231009082059.2500217-1-b.galvani@gmail.com> References: <20231009082059.2500217-1-b.galvani@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org Add a helper function to compute the tos/dsfield. In this way, we can factor out some duplicate code. Also, the helper will be called from more places in the next commit. Suggested-by: Guillaume Nault Signed-off-by: Beniamino Galvani --- drivers/net/geneve.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c index 78f9d588f712..572c3e36b209 100644 --- a/drivers/net/geneve.c +++ b/drivers/net/geneve.c @@ -784,6 +784,22 @@ static int geneve_build_skb(struct dst_entry *dst, struct sk_buff *skb, return err; } +static u8 geneve_get_dsfield(struct sk_buff *skb, struct net_device *dev, + const struct ip_tunnel_info *info, + bool *use_cache) +{ + struct geneve_dev *geneve = netdev_priv(dev); + u8 dsfield; + + dsfield = info->key.tos; + if (dsfield == 1 && !geneve->cfg.collect_md) { + dsfield = ip_tunnel_get_dsfield(ip_hdr(skb), skb); + *use_cache = false; + } + + return dsfield; +} + static struct rtable *geneve_get_v4_rt(struct sk_buff *skb, struct net_device *dev, struct geneve_sock *gs4, @@ -810,11 +826,7 @@ static struct rtable *geneve_get_v4_rt(struct sk_buff *skb, fl4->fl4_sport = sport; fl4->flowi4_flags = info->key.flow_flags; - tos = info->key.tos; - if ((tos == 1) && !geneve->cfg.collect_md) { - tos = ip_tunnel_get_dsfield(ip_hdr(skb), skb); - use_cache = false; - } + tos = geneve_get_dsfield(skb, dev, info, &use_cache); fl4->flowi4_tos = RT_TOS(tos); if (full_tos) *full_tos = tos; @@ -865,12 +877,7 @@ static struct dst_entry *geneve_get_v6_dst(struct sk_buff *skb, fl6->fl6_dport = dport; fl6->fl6_sport = sport; - prio = info->key.tos; - if ((prio == 1) && !geneve->cfg.collect_md) { - prio = ip_tunnel_get_dsfield(ip_hdr(skb), skb); - use_cache = false; - } - + prio = geneve_get_dsfield(skb, dev, info, &use_cache); fl6->flowlabel = ip6_make_flowinfo(prio, info->key.label); dst_cache = (struct dst_cache *)&info->dst_cache; if (use_cache) { From patchwork Mon Oct 9 08:20:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beniamino Galvani X-Patchwork-Id: 13413070 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 77B9015AC4 for ; Mon, 9 Oct 2023 08:26:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="dxHMO/OB" Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 410968F; Mon, 9 Oct 2023 01:26:19 -0700 (PDT) Received: by mail-ed1-x52c.google.com with SMTP id 4fb4d7f45d1cf-53627feca49so7026448a12.1; Mon, 09 Oct 2023 01:26:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696839977; x=1697444777; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=n0AxUwpswyDtB5yjnz9mIbeKoD0NUiZwXlK+ltnPKKo=; b=dxHMO/OBd86X8swbyWv1UwZAsnVkgeaUHcaOJEJA9+d5Vuvy7dhX+AeQBrEsWqBdst a/8yZFxAREg3UWnJmL6mGN2TH9UtMG6sdqNu/r3a3025JtSFA456aTUflCnlzhyfRjS2 SBeAwBSLSFwc1sxt0rdfKV4xeE9LKEx24zJdGiNKeLd1JZtH15peVPDTbqou//+0T9cY Q1ijohN/PN5EgX+9ax67Zcaln4W9aLjTWYjuvvZMUiPkNVzX5InpKn3OFvpV4juSRQZ9 t4CPiG9Pci4mqNSNnCzQmXzxbpkb3D0YUMSWSEEeXf2LQCDTNxrm2v5ZRL4Gc28zKCBZ VUSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696839977; x=1697444777; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=n0AxUwpswyDtB5yjnz9mIbeKoD0NUiZwXlK+ltnPKKo=; b=TN4y/EWSDG8CKW6I5yPmW3MTkC2BDg3Zff4zHMAdAGyg/1BeUr3BuXeVEGgs4KJMtj abIy1u60B98dKYG2wBz0xFRRjh8bnXM6Ey3LyHKeSEkYFC+i3dJk4wC3HAaCKzgZECxT GN/X9MFe0S0KW72A68v0cJ/7E4KhWwKymsmH9MuHqAN6hPd4OqPWrveIq6YjrfzOD2Cg aZXBbCnDZffNn3+0PusZODrD7SU1M5nSODSxPLOT5fnd4fg/oXAMTdLlkkr96jqJVFbg +rC+7W/tqPKd/b7xWbmQSyDMCQaYIt9DMWO5HiNrrtdE3s7z/mk7ONvcbxQlJQIPpou/ x3Yw== X-Gm-Message-State: AOJu0Yz9/TsrkSDn4NYdcBUH29xG+IgakITaongdEcOQNXJTFfWWmlDn dDR7qoK6OLa4W2WZVCir/rW97Ue/okA= X-Google-Smtp-Source: AGHT+IH/5ttIGxaK75UhSvVL6xyF2eq3UmszhLyNTcZan2CCYR9O0RD5ppPEN+L+uPD/PB29lQL54g== X-Received: by 2002:aa7:d503:0:b0:538:ae5:6138 with SMTP id y3-20020aa7d503000000b005380ae56138mr14404566edq.34.1696839977674; Mon, 09 Oct 2023 01:26:17 -0700 (PDT) Received: from tp.home.arpa (host-79-24-102-58.retail.telecomitalia.it. [79.24.102.58]) by smtp.gmail.com with ESMTPSA id p22-20020a05640210d600b00530a9488623sm5844810edu.46.2023.10.09.01.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 01:26:17 -0700 (PDT) From: Beniamino Galvani To: netdev@vger.kernel.org Cc: "David S . Miller" , Jakub Kicinski , Paolo Abeni , David Ahern , Guillaume Nault , linux-kernel@vger.kernel.org Subject: [PATCH net-next 6/7] geneve: use generic function for tunnel IPv4 route lookup Date: Mon, 9 Oct 2023 10:20:58 +0200 Message-Id: <20231009082059.2500217-7-b.galvani@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231009082059.2500217-1-b.galvani@gmail.com> References: <20231009082059.2500217-1-b.galvani@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org The route lookup can be done now via generic function udp_tunnel_dst_lookup() to replace the custom implementation in geneve_get_v4_rt(). Suggested-by: Guillaume Nault Signed-off-by: Beniamino Galvani --- drivers/net/geneve.c | 98 +++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 66 deletions(-) diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c index 572c3e36b209..23041eeec121 100644 --- a/drivers/net/geneve.c +++ b/drivers/net/geneve.c @@ -800,58 +800,6 @@ static u8 geneve_get_dsfield(struct sk_buff *skb, struct net_device *dev, return dsfield; } -static struct rtable *geneve_get_v4_rt(struct sk_buff *skb, - struct net_device *dev, - struct geneve_sock *gs4, - struct flowi4 *fl4, - const struct ip_tunnel_info *info, - __be16 dport, __be16 sport, - __u8 *full_tos) -{ - bool use_cache = ip_tunnel_dst_cache_usable(skb, info); - struct geneve_dev *geneve = netdev_priv(dev); - struct dst_cache *dst_cache; - struct rtable *rt = NULL; - __u8 tos; - - if (!gs4) - return ERR_PTR(-EIO); - - memset(fl4, 0, sizeof(*fl4)); - fl4->flowi4_mark = skb->mark; - fl4->flowi4_proto = IPPROTO_UDP; - fl4->daddr = info->key.u.ipv4.dst; - fl4->saddr = info->key.u.ipv4.src; - fl4->fl4_dport = dport; - fl4->fl4_sport = sport; - fl4->flowi4_flags = info->key.flow_flags; - - tos = geneve_get_dsfield(skb, dev, info, &use_cache); - fl4->flowi4_tos = RT_TOS(tos); - if (full_tos) - *full_tos = tos; - - dst_cache = (struct dst_cache *)&info->dst_cache; - if (use_cache) { - rt = dst_cache_get_ip4(dst_cache, &fl4->saddr); - if (rt) - return rt; - } - rt = ip_route_output_key(geneve->net, fl4); - if (IS_ERR(rt)) { - netdev_dbg(dev, "no route to %pI4\n", &fl4->daddr); - return ERR_PTR(-ENETUNREACH); - } - if (rt->dst.dev == dev) { /* is this necessary? */ - netdev_dbg(dev, "circular route to %pI4\n", &fl4->daddr); - ip_rt_put(rt); - return ERR_PTR(-ELOOP); - } - if (use_cache) - dst_cache_set_ip4(dst_cache, &rt->dst, fl4->saddr); - return rt; -} - #if IS_ENABLED(CONFIG_IPV6) static struct dst_entry *geneve_get_v6_dst(struct sk_buff *skb, struct net_device *dev, @@ -911,19 +859,28 @@ static int geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev, struct geneve_sock *gs4 = rcu_dereference(geneve->sock4); const struct ip_tunnel_key *key = &info->key; struct rtable *rt; - struct flowi4 fl4; - __u8 full_tos; + bool use_cache; __u8 tos, ttl; __be16 df = 0; + __be32 saddr; __be16 sport; int err; if (!pskb_inet_may_pull(skb)) return -EINVAL; + if (!gs4) + return -EIO; + + use_cache = ip_tunnel_dst_cache_usable(skb, info); + tos = geneve_get_dsfield(skb, dev, info, &use_cache); sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true); - rt = geneve_get_v4_rt(skb, dev, gs4, &fl4, info, - geneve->cfg.info.key.tp_dst, sport, &full_tos); + + rt = udp_tunnel_dst_lookup(skb, dev, geneve->net, 0, &saddr, + &info->key, + sport, geneve->cfg.info.key.tp_dst, tos, + use_cache ? + (struct dst_cache *)&info->dst_cache : NULL); if (IS_ERR(rt)) return PTR_ERR(rt); @@ -946,8 +903,8 @@ static int geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev, return -ENOMEM; } - unclone->key.u.ipv4.dst = fl4.saddr; - unclone->key.u.ipv4.src = fl4.daddr; + unclone->key.u.ipv4.dst = saddr; + unclone->key.u.ipv4.src = info->key.u.ipv4.dst; } if (!pskb_may_pull(skb, ETH_HLEN)) { @@ -961,13 +918,12 @@ static int geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev, return -EMSGSIZE; } + tos = ip_tunnel_ecn_encap(tos, ip_hdr(skb), skb); if (geneve->cfg.collect_md) { - tos = ip_tunnel_ecn_encap(key->tos, ip_hdr(skb), skb); ttl = key->ttl; df = key->tun_flags & TUNNEL_DONT_FRAGMENT ? htons(IP_DF) : 0; } else { - tos = ip_tunnel_ecn_encap(full_tos, ip_hdr(skb), skb); if (geneve->cfg.ttl_inherit) ttl = ip_tunnel_get_ttl(ip_hdr(skb), skb); else @@ -995,7 +951,7 @@ static int geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev, if (unlikely(err)) return err; - udp_tunnel_xmit_skb(rt, gs4->sock->sk, skb, fl4.saddr, fl4.daddr, + udp_tunnel_xmit_skb(rt, gs4->sock->sk, skb, saddr, info->key.u.ipv4.dst, tos, ttl, df, sport, geneve->cfg.info.key.tp_dst, !net_eq(geneve->net, dev_net(geneve->dev)), !(info->key.tun_flags & TUNNEL_CSUM)); @@ -1144,19 +1100,29 @@ static int geneve_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb) if (ip_tunnel_info_af(info) == AF_INET) { struct rtable *rt; - struct flowi4 fl4; - struct geneve_sock *gs4 = rcu_dereference(geneve->sock4); + bool use_cache; + __be32 saddr; + u8 tos; + + if (!gs4) + return -EIO; + + use_cache = ip_tunnel_dst_cache_usable(skb, info); + tos = geneve_get_dsfield(skb, dev, info, &use_cache); sport = udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true); - rt = geneve_get_v4_rt(skb, dev, gs4, &fl4, info, - geneve->cfg.info.key.tp_dst, sport, NULL); + rt = udp_tunnel_dst_lookup(skb, dev, geneve->net, 0, &saddr, + &info->key, + sport, geneve->cfg.info.key.tp_dst, + tos, + use_cache ? &info->dst_cache : NULL); if (IS_ERR(rt)) return PTR_ERR(rt); ip_rt_put(rt); - info->key.u.ipv4.src = fl4.saddr; + info->key.u.ipv4.src = saddr; #if IS_ENABLED(CONFIG_IPV6) } else if (ip_tunnel_info_af(info) == AF_INET6) { struct dst_entry *dst; From patchwork Mon Oct 9 08:20:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Beniamino Galvani X-Patchwork-Id: 13413071 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10A3F16420 for ; Mon, 9 Oct 2023 08:26:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="FPfTd4+G" Received: from mail-ed1-x52a.google.com (mail-ed1-x52a.google.com [IPv6:2a00:1450:4864:20::52a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3061C6; Mon, 9 Oct 2023 01:26:19 -0700 (PDT) Received: by mail-ed1-x52a.google.com with SMTP id 4fb4d7f45d1cf-523100882f2so6873234a12.2; Mon, 09 Oct 2023 01:26:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1696839978; x=1697444778; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=0s72RvFaniS1wfJfHEoKR77J7vnemSkLaDM40NAQW2o=; b=FPfTd4+GRXgspQ3JqMupsmFfN2ShR/ex+awMbXDeWhuOWVwTRbR1wg9QvrkEaz5al2 RlcSU4fXx93CV/lmTy7plcej+v1nvaJbH9sv2tF4WwfWgUqPkImgXuE1Ye5q2aLaBqyB /poYEDodrA+mhDF9ozhCNSek4+h8DfsegUbJKZCpNQl4rtL5UCWZyiM/NmW8i9dnC5sB s+fQciwN5MRBuz5a5UmBjMAN35NVQPzd0QM/aJYf+BLsuUX9pEdwuMcaTIgE4XyYH5w2 AX8KTXgi6dX0l/yd9exrsSOJFezW9s81pq6AoG/lJQX+3HnI8iLHP6Dbx80IbIA92uN1 4tLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696839978; x=1697444778; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=0s72RvFaniS1wfJfHEoKR77J7vnemSkLaDM40NAQW2o=; b=poFkYWc2jiofF3jKhYo95ZdV+jLLZEfhQF9WrQYHDqoo9cmeoGC1f9m8qvNr2Lh6Vd a/A8EobOLVM7SJjBEtVX6APYef6NvNrqtps+bcxm8Qf/eMC9C0b4NcN+HRK1x0uG3bD6 JpfOg9S4Pd7WAf5CaQr498koOS+cMWli0AatlHvTPqrJcGQFt3GWep8UDNuQTMnpMEhk D411n8bXUcHLdakWrx/1MyFCFH8wqSjzWYODzzAStb3w0t0EL9D+ekn9LJ2I/R/yn7Xa n6LLZD94Nap223dwOv/1dPPI0OkSR61xTfcXZlzPoaYFJKecW2x8Yk0G8R8dfOihp4JZ KFhw== X-Gm-Message-State: AOJu0Yz8Xwaq3JXIgeC03zDgBKdUi19NZEN3mZngCcnD5YbyfVY37sIq j97acqeRQaU7Yll99Woc82Po102DE6E= X-Google-Smtp-Source: AGHT+IGz4lnMXkPUjcJhuJkK/48YNj8mmmLRaYwQnfMeRbn2qj6bKzFMeuQNlPU7LGxs5OX3vvil0Q== X-Received: by 2002:aa7:cf92:0:b0:523:102f:3ce1 with SMTP id z18-20020aa7cf92000000b00523102f3ce1mr12742705edx.10.1696839978291; Mon, 09 Oct 2023 01:26:18 -0700 (PDT) Received: from tp.home.arpa (host-79-24-102-58.retail.telecomitalia.it. [79.24.102.58]) by smtp.gmail.com with ESMTPSA id p22-20020a05640210d600b00530a9488623sm5844810edu.46.2023.10.09.01.26.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Oct 2023 01:26:18 -0700 (PDT) From: Beniamino Galvani To: netdev@vger.kernel.org Cc: "David S . Miller" , Jakub Kicinski , Paolo Abeni , David Ahern , Guillaume Nault , linux-kernel@vger.kernel.org Subject: [PATCH net-next 7/7] vxlan: use generic function for tunnel IPv4 route lookup Date: Mon, 9 Oct 2023 10:20:59 +0200 Message-Id: <20231009082059.2500217-8-b.galvani@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231009082059.2500217-1-b.galvani@gmail.com> References: <20231009082059.2500217-1-b.galvani@gmail.com> Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net X-Patchwork-Delegate: kuba@kernel.org The route lookup can be done now via generic function udp_tunnel_dst_lookup() to replace the custom implementations in vxlan_get_route(). Note that this patch only touches IPv4, while IPv6 still uses vxlan6_get_route(). After IPv6 route lookup gets converted as well, vxlan_xmit_one() can be simplified by removing local variables that will be passed via "struct ip_tunnel_key", such as remote_ip, local_ip, flow_flags, label. Suggested-by: Guillaume Nault Signed-off-by: Beniamino Galvani --- drivers/net/vxlan/vxlan_core.c | 103 +++++++++++---------------------- 1 file changed, 35 insertions(+), 68 deletions(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 5b5597073b00..a37a84fae64e 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -2215,57 +2215,6 @@ static int vxlan_build_skb(struct sk_buff *skb, struct dst_entry *dst, return 0; } -static struct rtable *vxlan_get_route(struct vxlan_dev *vxlan, struct net_device *dev, - struct vxlan_sock *sock4, - struct sk_buff *skb, int oif, u8 tos, - __be32 daddr, __be32 *saddr, __be16 dport, __be16 sport, - __u8 flow_flags, struct dst_cache *dst_cache, - const struct ip_tunnel_info *info) -{ - bool use_cache = ip_tunnel_dst_cache_usable(skb, info); - struct rtable *rt = NULL; - struct flowi4 fl4; - - if (!sock4) - return ERR_PTR(-EIO); - - if (tos && !info) - use_cache = false; - if (use_cache) { - rt = dst_cache_get_ip4(dst_cache, saddr); - if (rt) - return rt; - } - - memset(&fl4, 0, sizeof(fl4)); - fl4.flowi4_oif = oif; - fl4.flowi4_tos = RT_TOS(tos); - fl4.flowi4_mark = skb->mark; - fl4.flowi4_proto = IPPROTO_UDP; - fl4.daddr = daddr; - 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)) { - if (rt->dst.dev == dev) { - netdev_dbg(dev, "circular route to %pI4\n", &daddr); - ip_rt_put(rt); - return ERR_PTR(-ELOOP); - } - - *saddr = fl4.saddr; - if (use_cache) - dst_cache_set_ip4(dst_cache, &rt->dst, fl4.saddr); - } else { - netdev_dbg(dev, "no route to %pI4\n", &daddr); - return ERR_PTR(-ENETUNREACH); - } - return rt; -} - #if IS_ENABLED(CONFIG_IPV6) static struct dst_entry *vxlan6_get_route(struct vxlan_dev *vxlan, struct net_device *dev, @@ -2418,6 +2367,8 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, { struct dst_cache *dst_cache; struct ip_tunnel_info *info; + struct ip_tunnel_key *pkey; + struct ip_tunnel_key key; struct vxlan_dev *vxlan = netdev_priv(dev); const struct iphdr *old_iph = ip_hdr(skb); union vxlan_addr *dst; @@ -2431,6 +2382,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, int ifindex; int err; u32 flags = vxlan->cfg.flags; + bool use_cache; bool udp_sum = false; bool xnet = !net_eq(vxlan->net, dev_net(vxlan->dev)); __be32 vni = 0; @@ -2439,9 +2391,13 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, #endif info = skb_tunnel_info(skb); + use_cache = ip_tunnel_dst_cache_usable(skb, info); if (rdst) { dst = &rdst->remote_ip; + memset(&key, 0, sizeof(key)); + pkey = &key; + if (vxlan_addr_any(dst)) { if (did_rsc) { /* short-circuited back to local bridge */ @@ -2456,6 +2412,15 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, vni = (rdst->remote_vni) ? : default_vni; ifindex = rdst->remote_ifindex; local_ip = vxlan->cfg.saddr; + + if (dst->sa.sa_family == AF_INET) { + key.u.ipv4.src = vxlan->cfg.saddr.sin.sin_addr.s_addr; + key.u.ipv4.dst = rdst->remote_ip.sin.sin_addr.s_addr; + } else { + key.u.ipv6.src = vxlan->cfg.saddr.sin6.sin6_addr; + key.u.ipv6.dst = rdst->remote_ip.sin6.sin6_addr; + } + dst_cache = &rdst->dst_cache; md->gbp = skb->mark; if (flags & VXLAN_F_TTL_INHERIT) { @@ -2469,6 +2434,8 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, tos = vxlan->cfg.tos; if (tos == 1) tos = ip_tunnel_get_dsfield(old_iph, skb); + if (tos && !info) + use_cache = false; if (dst->sa.sa_family == AF_INET) udp_sum = !(flags & VXLAN_F_UDP_ZERO_CSUM_TX); @@ -2492,6 +2459,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, local_ip.sin6.sin6_addr = info->key.u.ipv6.src; } dst = &remote_ip; + pkey = &info->key; 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); @@ -2517,15 +2485,14 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock); struct rtable *rt; __be16 df = 0; + __be32 saddr; if (!ifindex) ifindex = sock4->sock->sk->sk_bound_dev_if; - 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, flow_flags, - dst_cache, info); + rt = udp_tunnel_dst_lookup(skb, dev, vxlan->net, ifindex, + &saddr, pkey, src_port, dst_port, + tos, use_cache ? dst_cache : NULL); if (IS_ERR(rt)) { err = PTR_ERR(rt); goto tx_error; @@ -2561,16 +2528,13 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, } else if (err) { if (info) { struct ip_tunnel_info *unclone; - struct in_addr src, dst; unclone = skb_tunnel_info_unclone(skb); if (unlikely(!unclone)) goto tx_error; - src = remote_ip.sin.sin_addr; - dst = local_ip.sin.sin_addr; - unclone->key.u.ipv4.src = src.s_addr; - unclone->key.u.ipv4.dst = dst.s_addr; + unclone->key.u.ipv4.src = pkey->u.ipv4.dst; + unclone->key.u.ipv4.dst = saddr; } vxlan_encap_bypass(skb, vxlan, vxlan, vni, false); dst_release(ndst); @@ -2584,8 +2548,8 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_device *dev, if (err < 0) goto tx_error; - udp_tunnel_xmit_skb(rt, sock4->sock->sk, skb, local_ip.sin.sin_addr.s_addr, - dst->sin.sin_addr.s_addr, tos, ttl, df, + udp_tunnel_xmit_skb(rt, sock4->sock->sk, skb, saddr, + pkey->u.ipv4.dst, tos, ttl, df, src_port, dst_port, xnet, !udp_sum); #if IS_ENABLED(CONFIG_IPV6) } else { @@ -3100,11 +3064,14 @@ static int vxlan_fill_metadata_dst(struct net_device *dev, struct sk_buff *skb) struct vxlan_sock *sock4 = rcu_dereference(vxlan->vn4_sock); struct rtable *rt; - 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->key.flow_flags, &info->dst_cache, - info); + if (!sock4) + return -EIO; + + rt = udp_tunnel_dst_lookup(skb, dev, vxlan->net, 0, + &info->key.u.ipv4.src, + &info->key, + sport, dport, info->key.tos, + &info->dst_cache); if (IS_ERR(rt)) return PTR_ERR(rt); ip_rt_put(rt);