From nobody Wed Dec 17 07:59:58 2025 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 18EDFCDB474 for ; Fri, 20 Oct 2023 11:55:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377299AbjJTLz4 (ORCPT ); Fri, 20 Oct 2023 07:55:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46194 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377172AbjJTLzw (ORCPT ); Fri, 20 Oct 2023 07:55:52 -0400 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55C291A4; Fri, 20 Oct 2023 04:55:50 -0700 (PDT) Received: by mail-ej1-x62e.google.com with SMTP id a640c23a62f3a-9bdf5829000so115266966b.0; Fri, 20 Oct 2023 04:55:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697802949; x=1698407749; 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=LJaq2EZd8Vvzu5pwf4n3wyGJ15uytfaOKajlHE8rtbc=; b=lPCqcA97rdWCqxfKR3YIo06CE03BvkWabXPmI46iqWHXHq10r17ex84wWU43XFzF4Z TBEH23XB86VO1MnrDqSRYEEoSxkcHwAJf0RFbzEwAUR7WjrZZiwYXA56SMteUhrMPLo4 qk0SEwzRt0XW9sxnSu21BQGCEEa2BQVGEqHbLZKjKY2td6BxUj/7l6xvPmz3xBbyPVrC KQ21i4jNv6tDAJlzI8A8wDxWtRhhyz7/9rCpJ5l+Cii6RsdaisYyT0DId+NB3H+M6VOn aEAUtqxwNUu+CcvXD0trUtifeLGeER6iI0AyOfZzJU4lqyBOH2uQ/CkCDe4NIXqXCxKY aAEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697802949; x=1698407749; 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=LJaq2EZd8Vvzu5pwf4n3wyGJ15uytfaOKajlHE8rtbc=; b=NN8P/jzAIfALxJBBFu0dU27TYaji1K6ddTrMO+BZ22KfUZFCIKJuxkyhfj/LBvcxNI WSP8PAVXvRiVTjv6NjghyFw4EX7Q701vBuhKEkqSvShiHUJO3TsDKPqtTl21kx+Qzhox omyelFovIgMB9dMnrEMtAir1YdtbUJhU9ukzcI770l4HQbF8hnCLRW9NOxpCtr46khZU 8UMj2fSPoFzU0oZBTd9Ig9M3iG4/ZHbteA/t6VHFc1PnymN7mKIYXUiquzjORSe4Estr JRVje9LHx9kIsBUQ+0Bhby5+ipFvep15qWvXRDXIgGoX/gwNlkutIf/bjHUtEcLuR0N8 Bu2A== X-Gm-Message-State: AOJu0YzCVIkqe4psan2Cl/G3Zn9iTyfgokzV5F56MfnRvvsgQsYcDVYB mkgZWy5yk69d6G1u1RGQeU6blM+b3LQkrQ== X-Google-Smtp-Source: AGHT+IF68nYXdfN14OvlpSZ8dKhEnaeTP081JrfHwfsIdkKCSTXCf+r4cSehaRRr9pGDnmJJyFwxPA== X-Received: by 2002:a17:907:6e91:b0:9a1:f81f:d0d5 with SMTP id sh17-20020a1709076e9100b009a1f81fd0d5mr1432843ejc.54.1697802948512; Fri, 20 Oct 2023 04:55:48 -0700 (PDT) Received: from tp.home.arpa (host-95-239-66-218.retail.telecomitalia.it. [95.239.66.218]) by smtp.gmail.com with ESMTPSA id v21-20020a170906489500b009b928eb8dd3sm1342014ejq.163.2023.10.20.04.55.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 04:55:48 -0700 (PDT) From: Beniamino Galvani To: netdev@vger.kernel.org Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern , Guillaume Nault , linux-kernel@vger.kernel.org Subject: [PATCH net-next 1/5] ipv6: rename and move ip6_dst_lookup_tunnel() Date: Fri, 20 Oct 2023 13:55:25 +0200 Message-Id: <20231020115529.3344878-2-b.galvani@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231020115529.3344878-1-b.galvani@gmail.com> References: <20231020115529.3344878-1-b.galvani@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" At the moment ip6_dst_lookup_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_tunnel6_dst_lookup() and move it to file net/ipv6/ip6_udp_tunnel.c. This is similar to what already done for IPv4 in commit bf3fcbf7e7a0 ("ipv4: rename and move ip_route_output_tunnel()"). Suggested-by: Guillaume Nault Signed-off-by: Beniamino Galvani Reviewed-by: David Ahern --- drivers/net/bareudp.c | 10 +++--- include/net/ipv6.h | 6 ---- include/net/udp_tunnel.h | 7 ++++ net/ipv6/ip6_output.c | 68 -------------------------------------- net/ipv6/ip6_udp_tunnel.c | 69 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 81 insertions(+), 79 deletions(-) diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c index 47a9c2a5583c..9a0a1a9f6cfe 100644 --- a/drivers/net/bareudp.c +++ b/drivers/net/bareudp.c @@ -371,8 +371,8 @@ static int bareudp6_xmit_skb(struct sk_buff *skb, struc= t net_device *dev, if (!sock) return -ESHUTDOWN; =20 - dst =3D ip6_dst_lookup_tunnel(skb, dev, bareudp->net, sock, &saddr, info, - IPPROTO_UDP, use_cache); + dst =3D udp_tunnel6_dst_lookup(skb, dev, bareudp->net, sock, &saddr, info, + IPPROTO_UDP, use_cache); if (IS_ERR(dst)) return PTR_ERR(dst); =20 @@ -498,9 +498,9 @@ static int bareudp_fill_metadata_dst(struct net_device = *dev, struct in6_addr saddr; struct socket *sock =3D rcu_dereference(bareudp->sock); =20 - dst =3D ip6_dst_lookup_tunnel(skb, dev, bareudp->net, sock, - &saddr, info, IPPROTO_UDP, - use_cache); + dst =3D udp_tunnel6_dst_lookup(skb, dev, bareudp->net, sock, + &saddr, info, IPPROTO_UDP, + use_cache); if (IS_ERR(dst)) return PTR_ERR(dst); =20 diff --git a/include/net/ipv6.h b/include/net/ipv6.h index b3444c8a6f74..78d38dd88aba 100644 --- a/include/net/ipv6.h +++ b/include/net/ipv6.h @@ -1133,12 +1133,6 @@ struct dst_entry *ip6_dst_lookup_flow(struct net *ne= t, const struct sock *sk, st struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *f= l6, const struct in6_addr *final_dst, bool connected); -struct dst_entry *ip6_dst_lookup_tunnel(struct sk_buff *skb, - struct net_device *dev, - struct net *net, struct socket *sock, - struct in6_addr *saddr, - const struct ip_tunnel_info *info, - u8 protocol, bool use_cache); struct dst_entry *ip6_blackhole_route(struct net *net, struct dst_entry *orig_dst); =20 diff --git a/include/net/udp_tunnel.h b/include/net/udp_tunnel.h index 4d0578fab01a..1dac296d8449 100644 --- a/include/net/udp_tunnel.h +++ b/include/net/udp_tunnel.h @@ -169,6 +169,13 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *s= kb, const struct ip_tunnel_key *key, __be16 sport, __be16 dport, u8 tos, struct dst_cache *dst_cache); +struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb, + struct net_device *dev, + struct net *net, + struct socket *sock, + struct in6_addr *saddr, + const struct ip_tunnel_info *info, + u8 protocol, bool use_cache); =20 struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short fa= mily, __be16 flags, __be64 tunnel_id, diff --git a/net/ipv6/ip6_output.c b/net/ipv6/ip6_output.c index a471c7e91761..6df8b13d4595 100644 --- a/net/ipv6/ip6_output.c +++ b/net/ipv6/ip6_output.c @@ -1281,74 +1281,6 @@ struct dst_entry *ip6_sk_dst_lookup_flow(struct sock= *sk, struct flowi6 *fl6, } EXPORT_SYMBOL_GPL(ip6_sk_dst_lookup_flow); =20 -/** - * ip6_dst_lookup_tunnel - perform route lookup on tunnel - * @skb: Packet for which lookup is done - * @dev: Tunnel device - * @net: Network namespace of tunnel device - * @sock: Socket which provides route info - * @saddr: Memory to store the src ip address - * @info: Tunnel information - * @protocol: IP protocol - * @use_cache: Flag to enable cache usage - * This function performs a route lookup on a tunnel - * - * It returns a valid dst pointer and stores src address to be used in - * tunnel in param saddr on success, else a pointer encoded error cod= e. - */ - -struct dst_entry *ip6_dst_lookup_tunnel(struct sk_buff *skb, - struct net_device *dev, - struct net *net, - struct socket *sock, - struct in6_addr *saddr, - const struct ip_tunnel_info *info, - u8 protocol, - bool use_cache) -{ - struct dst_entry *dst =3D NULL; -#ifdef CONFIG_DST_CACHE - struct dst_cache *dst_cache; -#endif - struct flowi6 fl6; - __u8 prio; - -#ifdef CONFIG_DST_CACHE - dst_cache =3D (struct dst_cache *)&info->dst_cache; - if (use_cache) { - dst =3D dst_cache_get_ip6(dst_cache, saddr); - if (dst) - return dst; - } -#endif - memset(&fl6, 0, sizeof(fl6)); - fl6.flowi6_mark =3D skb->mark; - fl6.flowi6_proto =3D protocol; - fl6.daddr =3D info->key.u.ipv6.dst; - fl6.saddr =3D info->key.u.ipv6.src; - prio =3D info->key.tos; - fl6.flowlabel =3D ip6_make_flowinfo(prio, info->key.label); - - dst =3D ipv6_stub->ipv6_dst_lookup_flow(net, sock->sk, &fl6, - NULL); - if (IS_ERR(dst)) { - netdev_dbg(dev, "no route to %pI6\n", &fl6.daddr); - return ERR_PTR(-ENETUNREACH); - } - if (dst->dev =3D=3D dev) { /* is this necessary? */ - netdev_dbg(dev, "circular route to %pI6\n", &fl6.daddr); - dst_release(dst); - return ERR_PTR(-ELOOP); - } -#ifdef CONFIG_DST_CACHE - if (use_cache) - dst_cache_set_ip6(dst_cache, dst, &fl6.saddr); -#endif - *saddr =3D fl6.saddr; - return dst; -} -EXPORT_SYMBOL_GPL(ip6_dst_lookup_tunnel); - static inline struct ipv6_opt_hdr *ip6_opt_dup(struct ipv6_opt_hdr *src, gfp_t gfp) { diff --git a/net/ipv6/ip6_udp_tunnel.c b/net/ipv6/ip6_udp_tunnel.c index 70d38705c92f..fc122abf6b75 100644 --- a/net/ipv6/ip6_udp_tunnel.c +++ b/net/ipv6/ip6_udp_tunnel.c @@ -1,3 +1,4 @@ + // SPDX-License-Identifier: GPL-2.0-only #include #include @@ -112,4 +113,72 @@ int udp_tunnel6_xmit_skb(struct dst_entry *dst, struct= sock *sk, } EXPORT_SYMBOL_GPL(udp_tunnel6_xmit_skb); =20 +/** + * udp_tunnel6_dst_lookup - perform route lookup on UDP tunnel + * @skb: Packet for which lookup is done + * @dev: Tunnel device + * @net: Network namespace of tunnel device + * @sock: Socket which provides route info + * @saddr: Memory to store the src ip address + * @info: Tunnel information + * @protocol: IP protocol + * @use_cache: Flag to enable cache usage + * This function performs a route lookup on a UDP tunnel + * + * It returns a valid dst pointer and stores src address to be used in + * tunnel in param saddr on success, else a pointer encoded error cod= e. + */ + +struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb, + struct net_device *dev, + struct net *net, + struct socket *sock, + struct in6_addr *saddr, + const struct ip_tunnel_info *info, + u8 protocol, + bool use_cache) +{ + struct dst_entry *dst =3D NULL; +#ifdef CONFIG_DST_CACHE + struct dst_cache *dst_cache; +#endif + struct flowi6 fl6; + __u8 prio; + +#ifdef CONFIG_DST_CACHE + dst_cache =3D (struct dst_cache *)&info->dst_cache; + if (use_cache) { + dst =3D dst_cache_get_ip6(dst_cache, saddr); + if (dst) + return dst; + } +#endif + memset(&fl6, 0, sizeof(fl6)); + fl6.flowi6_mark =3D skb->mark; + fl6.flowi6_proto =3D protocol; + fl6.daddr =3D info->key.u.ipv6.dst; + fl6.saddr =3D info->key.u.ipv6.src; + prio =3D info->key.tos; + fl6.flowlabel =3D ip6_make_flowinfo(prio, info->key.label); + + dst =3D ipv6_stub->ipv6_dst_lookup_flow(net, sock->sk, &fl6, + NULL); + if (IS_ERR(dst)) { + netdev_dbg(dev, "no route to %pI6\n", &fl6.daddr); + return ERR_PTR(-ENETUNREACH); + } + if (dst->dev =3D=3D dev) { /* is this necessary? */ + netdev_dbg(dev, "circular route to %pI6\n", &fl6.daddr); + dst_release(dst); + return ERR_PTR(-ELOOP); + } +#ifdef CONFIG_DST_CACHE + if (use_cache) + dst_cache_set_ip6(dst_cache, dst, &fl6.saddr); +#endif + *saddr =3D fl6.saddr; + return dst; +} +EXPORT_SYMBOL_GPL(udp_tunnel6_dst_lookup); + MODULE_LICENSE("GPL"); --=20 2.40.1 From nobody Wed Dec 17 07:59:58 2025 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 8B347CDB47E for ; Fri, 20 Oct 2023 11:55:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377249AbjJTLz6 (ORCPT ); Fri, 20 Oct 2023 07:55:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377255AbjJTLzx (ORCPT ); Fri, 20 Oct 2023 07:55:53 -0400 Received: from mail-ej1-x634.google.com (mail-ej1-x634.google.com [IPv6:2a00:1450:4864:20::634]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAD93D4C; Fri, 20 Oct 2023 04:55:50 -0700 (PDT) Received: by mail-ej1-x634.google.com with SMTP id a640c23a62f3a-98377c5d53eso114549466b.0; Fri, 20 Oct 2023 04:55:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697802949; x=1698407749; 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=0KmtVFbWzplAw+DN7VSv0tLTduS4IgtLHBkgos/qD5o=; b=StImGmkem5m8rrsjcMA+ra3GkMVm9Zd3EhcKncY9WmccXhXpkLK6LaeTrUHWCkFR+y pc1VtDQkNlpI4kHocLBC0mbo180WgtHrr77vY1QB8FAEAx8bjQ1e7kf9s4iXPwUQBbxI gLzSgbwJtv6TcyiGGAYvX8qcQL6JkP4lcy2po0bYeDYzcIWnrZ0vNuTmqtMgMAV56ZBt +WyuZjJ+frdl6FdntZiwU9bJb+l+YdvgF6Lw1JnkS7fqsAuRjcyjqKE4YWSSryPXFUW5 CJnxnzRWJC30P5ZlXmXFBpZssD0Ke4YRGGNzYikmFmrcF4TmL5jPKfnMG9CuRwKjIjG0 S1FQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697802949; x=1698407749; 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=0KmtVFbWzplAw+DN7VSv0tLTduS4IgtLHBkgos/qD5o=; b=tXx0poAjfTzhGcR0my6h86PAHZeF1tQu97b2D01fIzRGGJCeqJbMkRNKe79MkU85fg Mb2HtLye5JFcbjW2Zf+4rowu2JYQtzf74Z8kpvgK5v0o+ptHCB6k0RlfZV7rqLLVcpNy U3i984wXBDL0dczrdJOO8LnR71pv5LXbzlym4rI2CTVN8R6MlFpxxznlaSWgATJlOrVe v/rU3UbT+xY4g8h/v46t/qjIzlA3Wrok1PxhZHE8haACerNrk7xdSzeQ0jF0Ht51F6Dj d9qKL/jIBxR4ACu3J2gm+KnyL/DptC6ako9GhP0/3ua1zkKhQA5qVijLBy+3rZyGWyu2 pWLA== X-Gm-Message-State: AOJu0YzNruPchcMN+n/EFkHsApi13ZNfxYz4aTStVlnoWktv/W+5IJGJ EPJSNSwgiFfxS8jFI9UwQjONXtNERnUThg== X-Google-Smtp-Source: AGHT+IGVcQBTH98uCK/zjTmDdZOn/3s4Sc2VQ0aDMYMmIDUn2iqBUFr7LfiPbXXISD54pRZAiT7H/g== X-Received: by 2002:a17:906:9c83:b0:9b2:b691:9b5f with SMTP id fj3-20020a1709069c8300b009b2b6919b5fmr1135159ejc.41.1697802949331; Fri, 20 Oct 2023 04:55:49 -0700 (PDT) Received: from tp.home.arpa (host-95-239-66-218.retail.telecomitalia.it. [95.239.66.218]) by smtp.gmail.com with ESMTPSA id v21-20020a170906489500b009b928eb8dd3sm1342014ejq.163.2023.10.20.04.55.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 04:55:49 -0700 (PDT) From: Beniamino Galvani To: netdev@vger.kernel.org Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern , Guillaume Nault , linux-kernel@vger.kernel.org Subject: [PATCH net-next 2/5] ipv6: remove "proto" argument from udp_tunnel6_dst_lookup() Date: Fri, 20 Oct 2023 13:55:26 +0200 Message-Id: <20231020115529.3344878-3-b.galvani@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231020115529.3344878-1-b.galvani@gmail.com> References: <20231020115529.3344878-1-b.galvani@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The function is now UDP-specific, the protocol is always IPPROTO_UDP. This is similar to what already done for IPv4 in commit 78f3655adcb5 ("ipv4: remove "proto" argument from udp_tunnel_dst_lookup()"). Suggested-by: Guillaume Nault Signed-off-by: Beniamino Galvani Reviewed-by: David Ahern --- drivers/net/bareudp.c | 5 ++--- include/net/udp_tunnel.h | 2 +- net/ipv6/ip6_udp_tunnel.c | 4 +--- 3 files changed, 4 insertions(+), 7 deletions(-) diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c index 9a0a1a9f6cfe..9eb5e11c09b4 100644 --- a/drivers/net/bareudp.c +++ b/drivers/net/bareudp.c @@ -372,7 +372,7 @@ static int bareudp6_xmit_skb(struct sk_buff *skb, struc= t net_device *dev, return -ESHUTDOWN; =20 dst =3D udp_tunnel6_dst_lookup(skb, dev, bareudp->net, sock, &saddr, info, - IPPROTO_UDP, use_cache); + use_cache); if (IS_ERR(dst)) return PTR_ERR(dst); =20 @@ -499,8 +499,7 @@ static int bareudp_fill_metadata_dst(struct net_device = *dev, struct socket *sock =3D rcu_dereference(bareudp->sock); =20 dst =3D udp_tunnel6_dst_lookup(skb, dev, bareudp->net, sock, - &saddr, info, IPPROTO_UDP, - use_cache); + &saddr, info, use_cache); if (IS_ERR(dst)) return PTR_ERR(dst); =20 diff --git a/include/net/udp_tunnel.h b/include/net/udp_tunnel.h index 1dac296d8449..583867643bd1 100644 --- a/include/net/udp_tunnel.h +++ b/include/net/udp_tunnel.h @@ -175,7 +175,7 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff= *skb, struct socket *sock, struct in6_addr *saddr, const struct ip_tunnel_info *info, - u8 protocol, bool use_cache); + bool use_cache); =20 struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short fa= mily, __be16 flags, __be64 tunnel_id, diff --git a/net/ipv6/ip6_udp_tunnel.c b/net/ipv6/ip6_udp_tunnel.c index fc122abf6b75..b9c906518ce2 100644 --- a/net/ipv6/ip6_udp_tunnel.c +++ b/net/ipv6/ip6_udp_tunnel.c @@ -121,7 +121,6 @@ EXPORT_SYMBOL_GPL(udp_tunnel6_xmit_skb); * @sock: Socket which provides route info * @saddr: Memory to store the src ip address * @info: Tunnel information - * @protocol: IP protocol * @use_cache: Flag to enable cache usage * This function performs a route lookup on a UDP tunnel * @@ -135,7 +134,6 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff= *skb, struct socket *sock, struct in6_addr *saddr, const struct ip_tunnel_info *info, - u8 protocol, bool use_cache) { struct dst_entry *dst =3D NULL; @@ -155,7 +153,7 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff= *skb, #endif memset(&fl6, 0, sizeof(fl6)); fl6.flowi6_mark =3D skb->mark; - fl6.flowi6_proto =3D protocol; + fl6.flowi6_proto =3D IPPROTO_UDP; fl6.daddr =3D info->key.u.ipv6.dst; fl6.saddr =3D info->key.u.ipv6.src; prio =3D info->key.tos; --=20 2.40.1 From nobody Wed Dec 17 07:59:58 2025 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 DFEB6CDB47E for ; Fri, 20 Oct 2023 11:56:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377334AbjJTL4B (ORCPT ); Fri, 20 Oct 2023 07:56:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377277AbjJTLzx (ORCPT ); Fri, 20 Oct 2023 07:55:53 -0400 Received: from mail-ej1-x62b.google.com (mail-ej1-x62b.google.com [IPv6:2a00:1450:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AD795D51; Fri, 20 Oct 2023 04:55:51 -0700 (PDT) Received: by mail-ej1-x62b.google.com with SMTP id a640c23a62f3a-9c3aec5f326so394230466b.1; Fri, 20 Oct 2023 04:55:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697802950; x=1698407750; 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=+AZ5ktdIxmIZ0T//vBhcoP9HGHOtenHtQrb+zrnkeE8=; b=P9IsK8s0TPjcnGMWqdxYPaZRTDjZI7zYj+DqWjNqznJpxkMmjbjfAH8yM6HmNniROU z81FP4CLImQjpNGYYNKsbDn+6eoMYhFCaKw6BqKX7LCPFgQh7HI6ynSW2lstFVzr0VJX jTZ5zh+xqYrGk6/3Vfu1brQZG/1jg8SkxJeGqyuCuqe8o23WDN1gP319q8uooZfiQy1M v9llCdQWm659ZG5FzL6Mwwn7LQsKiKMmP6gddlb18A3qLBplRMHaH3gok0oEdlhnaqDo 9tcGZX6D4LB3nlylsITnDvK+iJcYv7rf7wJc6GZ5oWIX4jlH9JEtZ4QHb69C1g7j2FTa s9Og== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697802950; x=1698407750; 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=+AZ5ktdIxmIZ0T//vBhcoP9HGHOtenHtQrb+zrnkeE8=; b=t7jRRBZYRL6xgtL5wXBL504HmVqn1e0+vQH0sVshfaAcXGOb1stqQoQmc0iivdT0KQ aj4wnVzoNAGqkb2ATLeMLUuVFQfKy6WLxd16IHCf+PiAWN2d9wbfGo4VVY7EgPHg5WNu j5i2caY6weHkBHdyl/8MYM9tN/9M7JQTJmATTN9RLM6Ft8ksZ8FC4VYlKV/Kr8Re5oWY bUQTwHJsGCXEj7oOgkNjqIJh5yiXjR4hpg1SkYy3+Zk5BpB+AXcQkAN72jXIvVOo40LK 2yCVoEB74V2t7Abdg2z8jxr+DRJRrg6JIUQ4QdJGhpKuSuRCUXwomJPvNq/+SI8L3Qh3 s+QA== X-Gm-Message-State: AOJu0YwCluYHCcZIiNS+hNf/eGZUpZ8HFmDEoZogHklvE9jUPMuKytO7 QOwGKVeidi2yZAQ0c84d1XiggfITgGOAxQ== X-Google-Smtp-Source: AGHT+IG/LQK2PjfUAih+Cmlbsti+riWldSkcSTZ+NZYrOpRaoVmXlB2n8qBG4EXuvoJFTYS+HTq/Hg== X-Received: by 2002:a17:906:c14d:b0:9a9:f0e6:904e with SMTP id dp13-20020a170906c14d00b009a9f0e6904emr1274727ejc.16.1697802950144; Fri, 20 Oct 2023 04:55:50 -0700 (PDT) Received: from tp.home.arpa (host-95-239-66-218.retail.telecomitalia.it. [95.239.66.218]) by smtp.gmail.com with ESMTPSA id v21-20020a170906489500b009b928eb8dd3sm1342014ejq.163.2023.10.20.04.55.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 04:55:49 -0700 (PDT) From: Beniamino Galvani To: netdev@vger.kernel.org Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern , Guillaume Nault , linux-kernel@vger.kernel.org Subject: [PATCH net-next 3/5] ipv6: add new arguments to udp_tunnel6_dst_lookup() Date: Fri, 20 Oct 2023 13:55:27 +0200 Message-Id: <20231020115529.3344878-4-b.galvani@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231020115529.3344878-1-b.galvani@gmail.com> References: <20231020115529.3344878-1-b.galvani@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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). This is similar to what already done for IPv4 in commit 72fc68c6356b ("ipv4: add new arguments to udp_tunnel_dst_lookup()"). Suggested-by: Guillaume Nault Signed-off-by: Beniamino Galvani Reviewed-by: David Ahern --- drivers/net/bareudp.c | 10 +++++++--- include/net/udp_tunnel.h | 7 ++++--- net/ipv6/ip6_udp_tunnel.c | 33 ++++++++++++++++++--------------- 3 files changed, 29 insertions(+), 21 deletions(-) diff --git a/drivers/net/bareudp.c b/drivers/net/bareudp.c index 9eb5e11c09b4..9c11a0d0273b 100644 --- a/drivers/net/bareudp.c +++ b/drivers/net/bareudp.c @@ -371,8 +371,10 @@ static int bareudp6_xmit_skb(struct sk_buff *skb, stru= ct net_device *dev, if (!sock) return -ESHUTDOWN; =20 - dst =3D udp_tunnel6_dst_lookup(skb, dev, bareudp->net, sock, &saddr, info, - use_cache); + dst =3D udp_tunnel6_dst_lookup(skb, dev, bareudp->net, sock, 0, &saddr, + key, 0, 0, key->tos, + use_cache ? + (struct dst_cache *) &info->dst_cache : NULL); if (IS_ERR(dst)) return PTR_ERR(dst); =20 @@ -499,7 +501,9 @@ static int bareudp_fill_metadata_dst(struct net_device = *dev, struct socket *sock =3D rcu_dereference(bareudp->sock); =20 dst =3D udp_tunnel6_dst_lookup(skb, dev, bareudp->net, sock, - &saddr, info, use_cache); + 0, &saddr, &info->key, + 0, 0, info->key.tos, + use_cache ? &info->dst_cache : NULL); if (IS_ERR(dst)) return PTR_ERR(dst); =20 diff --git a/include/net/udp_tunnel.h b/include/net/udp_tunnel.h index 583867643bd1..d716214fe03d 100644 --- a/include/net/udp_tunnel.h +++ b/include/net/udp_tunnel.h @@ -172,10 +172,11 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *= skb, struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb, struct net_device *dev, struct net *net, - struct socket *sock, + struct socket *sock, int oif, struct in6_addr *saddr, - const struct ip_tunnel_info *info, - bool use_cache); + const struct ip_tunnel_key *key, + __be16 sport, __be16 dport, u8 dsfield, + struct dst_cache *dst_cache); =20 struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short fa= mily, __be16 flags, __be64 tunnel_id, diff --git a/net/ipv6/ip6_udp_tunnel.c b/net/ipv6/ip6_udp_tunnel.c index b9c906518ce2..a7bf0327b380 100644 --- a/net/ipv6/ip6_udp_tunnel.c +++ b/net/ipv6/ip6_udp_tunnel.c @@ -119,9 +119,13 @@ EXPORT_SYMBOL_GPL(udp_tunnel6_xmit_skb); * @dev: Tunnel device * @net: Network namespace of tunnel device * @sock: Socket which provides route info + * @oif: Index of the output interface * @saddr: Memory to store the src ip address - * @info: Tunnel information - * @use_cache: Flag to enable cache usage + * @key: Tunnel information + * @sport: UDP source port + * @dport: UDP destination port + * @dsfield: The traffic class field + * @dst_cache: The dst cache to use for lookup * This function performs a route lookup on a UDP tunnel * * It returns a valid dst pointer and stores src address to be used in @@ -132,20 +136,17 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_bu= ff *skb, struct net_device *dev, struct net *net, struct socket *sock, + int oif, struct in6_addr *saddr, - const struct ip_tunnel_info *info, - bool use_cache) + const struct ip_tunnel_key *key, + __be16 sport, __be16 dport, u8 dsfield, + struct dst_cache *dst_cache) { struct dst_entry *dst =3D NULL; -#ifdef CONFIG_DST_CACHE - struct dst_cache *dst_cache; -#endif struct flowi6 fl6; - __u8 prio; =20 #ifdef CONFIG_DST_CACHE - dst_cache =3D (struct dst_cache *)&info->dst_cache; - if (use_cache) { + if (dst_cache) { dst =3D dst_cache_get_ip6(dst_cache, saddr); if (dst) return dst; @@ -154,10 +155,12 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_bu= ff *skb, memset(&fl6, 0, sizeof(fl6)); fl6.flowi6_mark =3D skb->mark; fl6.flowi6_proto =3D IPPROTO_UDP; - fl6.daddr =3D info->key.u.ipv6.dst; - fl6.saddr =3D info->key.u.ipv6.src; - prio =3D info->key.tos; - fl6.flowlabel =3D ip6_make_flowinfo(prio, info->key.label); + fl6.flowi6_oif =3D oif; + fl6.daddr =3D key->u.ipv6.dst; + fl6.saddr =3D key->u.ipv6.src; + fl6.fl6_sport =3D sport; + fl6.fl6_dport =3D dport; + fl6.flowlabel =3D ip6_make_flowinfo(dsfield, key->label); =20 dst =3D ipv6_stub->ipv6_dst_lookup_flow(net, sock->sk, &fl6, NULL); @@ -171,7 +174,7 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff= *skb, return ERR_PTR(-ELOOP); } #ifdef CONFIG_DST_CACHE - if (use_cache) + if (dst_cache) dst_cache_set_ip6(dst_cache, dst, &fl6.saddr); #endif *saddr =3D fl6.saddr; --=20 2.40.1 From nobody Wed Dec 17 07:59:58 2025 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 0D5BFCDB474 for ; Fri, 20 Oct 2023 11:56:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377231AbjJTL4E (ORCPT ); Fri, 20 Oct 2023 07:56:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377216AbjJTLzy (ORCPT ); Fri, 20 Oct 2023 07:55:54 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 96098D41; Fri, 20 Oct 2023 04:55:52 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id a640c23a62f3a-9be3b66f254so109312066b.3; Fri, 20 Oct 2023 04:55:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697802951; x=1698407751; 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=kWj5oDx/S8VI79K/5zPzRbyb5BIBjkraIKsv8+HW9jw=; b=Fgs+4JHTgRlbd337hz0dkGPepyTSpCm2kqnkt7O4RMFiaadxUr7vy3Xnp2XME+FBYi H3abMP5etF3pSCa2lkebjAcPyTV5Eeg9I32gO8GFkKXPsfO6Z6Fowj14mPTSKHj/Ng46 Q3NoXczDtfuBhFw1Ny8VNxam5Yh0f7CV32wvKuxxAP+DIAiD10LC87vxnMMd6EWYDy22 +5k8h9cNyKOgXAs2J4f7U3uye+iI/3tSVQnsz2hAdNrPnxPO0KAav6Mg8CV4HDetQsIB doI5fJtotpLQVDYvrA5FlALgOF8Z4p0bah4gojNriLLhGgxirUPLzgf95aZK9tUmpio4 heEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697802951; x=1698407751; 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=kWj5oDx/S8VI79K/5zPzRbyb5BIBjkraIKsv8+HW9jw=; b=IF5zvGFgeGR6lUubL59xjkNhFsug1TydFqylwuDDDQHdATrNOOQYtUg9u/50KUronZ wGVYk14flef/OtIq+eMKhE2b2qKTMiqaEuxJECmFhRIdxQ82Hduh07lS7ZfLWiFgl7C0 t4rRC6sSJi8KveAaT7OtHG91SnwvzWxbcI463WjJlC+pzTllJifp/u/o76KzjtGABo8a vewLS/0Vb7J1b5zVA9yxGNAVVJem4xEk7srl4AcyD6Wr2eN8Yokv048MHRYIOzgDiT77 LQcVbHK65x7PqAy7P023fNMXZ1Y49ElFtI6h6simB4WgYRUKtJz9WtqyANHH6g+E82t6 9WEQ== X-Gm-Message-State: AOJu0YyuRGiU+yNcKyEgVJYTThkC2/jLQ68hVHnGJFNw29olJTI3F8CM PTEhohe1UKI6Dkq4xNiTFJ4UofeCJ+f5/Q== X-Google-Smtp-Source: AGHT+IGWiuo+BHibTMEtAeo39fIn1N+aYYfcaD+z0tvqx6QvcOaBsN1y2R/XEe2t/wEnpaV2Lfzxgw== X-Received: by 2002:a17:907:2d8b:b0:9c7:5a01:ffe5 with SMTP id gt11-20020a1709072d8b00b009c75a01ffe5mr983076ejc.5.1697802950999; Fri, 20 Oct 2023 04:55:50 -0700 (PDT) Received: from tp.home.arpa (host-95-239-66-218.retail.telecomitalia.it. [95.239.66.218]) by smtp.gmail.com with ESMTPSA id v21-20020a170906489500b009b928eb8dd3sm1342014ejq.163.2023.10.20.04.55.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 04:55:50 -0700 (PDT) From: Beniamino Galvani To: netdev@vger.kernel.org Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern , Guillaume Nault , linux-kernel@vger.kernel.org Subject: [PATCH net-next 4/5] geneve: use generic function for tunnel IPv6 route lookup Date: Fri, 20 Oct 2023 13:55:28 +0200 Message-Id: <20231020115529.3344878-5-b.galvani@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231020115529.3344878-1-b.galvani@gmail.com> References: <20231020115529.3344878-1-b.galvani@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The route lookup can be done now via generic function udp_tunnel6_dst_lookup() to replace the custom implementation in geneve_get_v6_dst(). This is similar to what already done for IPv4 in commit daa2ba7ed1d1 ("geneve: use generic function for tunnel IPv4 route lookup"). Suggested-by: Guillaume Nault Signed-off-by: Beniamino Galvani Reviewed-by: David Ahern --- drivers/net/geneve.c | 96 ++++++++++++++------------------------------ 1 file changed, 31 insertions(+), 65 deletions(-) diff --git a/drivers/net/geneve.c b/drivers/net/geneve.c index 23041eeec121..acd9c615d1f4 100644 --- a/drivers/net/geneve.c +++ b/drivers/net/geneve.c @@ -800,57 +800,6 @@ static u8 geneve_get_dsfield(struct sk_buff *skb, stru= ct net_device *dev, return dsfield; } =20 -#if IS_ENABLED(CONFIG_IPV6) -static struct dst_entry *geneve_get_v6_dst(struct sk_buff *skb, - struct net_device *dev, - struct geneve_sock *gs6, - struct flowi6 *fl6, - const struct ip_tunnel_info *info, - __be16 dport, __be16 sport) -{ - bool use_cache =3D ip_tunnel_dst_cache_usable(skb, info); - struct geneve_dev *geneve =3D netdev_priv(dev); - struct dst_entry *dst =3D NULL; - struct dst_cache *dst_cache; - __u8 prio; - - if (!gs6) - return ERR_PTR(-EIO); - - memset(fl6, 0, sizeof(*fl6)); - fl6->flowi6_mark =3D skb->mark; - fl6->flowi6_proto =3D IPPROTO_UDP; - fl6->daddr =3D info->key.u.ipv6.dst; - fl6->saddr =3D info->key.u.ipv6.src; - fl6->fl6_dport =3D dport; - fl6->fl6_sport =3D sport; - - prio =3D geneve_get_dsfield(skb, dev, info, &use_cache); - fl6->flowlabel =3D ip6_make_flowinfo(prio, info->key.label); - dst_cache =3D (struct dst_cache *)&info->dst_cache; - if (use_cache) { - dst =3D dst_cache_get_ip6(dst_cache, &fl6->saddr); - if (dst) - return dst; - } - dst =3D ipv6_stub->ipv6_dst_lookup_flow(geneve->net, gs6->sock->sk, fl6, - NULL); - if (IS_ERR(dst)) { - netdev_dbg(dev, "no route to %pI6\n", &fl6->daddr); - return ERR_PTR(-ENETUNREACH); - } - if (dst->dev =3D=3D dev) { /* is this necessary? */ - netdev_dbg(dev, "circular route to %pI6\n", &fl6->daddr); - dst_release(dst); - return ERR_PTR(-ELOOP); - } - - if (use_cache) - dst_cache_set_ip6(dst_cache, dst, &fl6->saddr); - return dst; -} -#endif - static int geneve_xmit_skb(struct sk_buff *skb, struct net_device *dev, struct geneve_dev *geneve, const struct ip_tunnel_info *info) @@ -967,7 +916,8 @@ static int geneve6_xmit_skb(struct sk_buff *skb, struct= net_device *dev, struct geneve_sock *gs6 =3D rcu_dereference(geneve->sock6); const struct ip_tunnel_key *key =3D &info->key; struct dst_entry *dst =3D NULL; - struct flowi6 fl6; + struct in6_addr saddr; + bool use_cache; __u8 prio, ttl; __be16 sport; int err; @@ -975,9 +925,18 @@ static int geneve6_xmit_skb(struct sk_buff *skb, struc= t net_device *dev, if (!pskb_inet_may_pull(skb)) return -EINVAL; =20 + if (!gs6) + return -EIO; + + use_cache =3D ip_tunnel_dst_cache_usable(skb, info); + prio =3D geneve_get_dsfield(skb, dev, info, &use_cache); sport =3D udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true); - dst =3D geneve_get_v6_dst(skb, dev, gs6, &fl6, info, - geneve->cfg.info.key.tp_dst, sport); + + dst =3D udp_tunnel6_dst_lookup(skb, dev, geneve->net, gs6->sock, 0, + &saddr, key, sport, + geneve->cfg.info.key.tp_dst, prio, + use_cache ? + (struct dst_cache *)&info->dst_cache : NULL); if (IS_ERR(dst)) return PTR_ERR(dst); =20 @@ -999,8 +958,8 @@ static int geneve6_xmit_skb(struct sk_buff *skb, struct= net_device *dev, return -ENOMEM; } =20 - unclone->key.u.ipv6.dst =3D fl6.saddr; - unclone->key.u.ipv6.src =3D fl6.daddr; + unclone->key.u.ipv6.dst =3D saddr; + unclone->key.u.ipv6.src =3D info->key.u.ipv6.dst; } =20 if (!pskb_may_pull(skb, ETH_HLEN)) { @@ -1014,12 +973,10 @@ static int geneve6_xmit_skb(struct sk_buff *skb, str= uct net_device *dev, return -EMSGSIZE; } =20 + prio =3D ip_tunnel_ecn_encap(prio, ip_hdr(skb), skb); if (geneve->cfg.collect_md) { - prio =3D ip_tunnel_ecn_encap(key->tos, ip_hdr(skb), skb); ttl =3D key->ttl; } else { - prio =3D ip_tunnel_ecn_encap(ip6_tclass(fl6.flowlabel), - ip_hdr(skb), skb); if (geneve->cfg.ttl_inherit) ttl =3D ip_tunnel_get_ttl(ip_hdr(skb), skb); else @@ -1032,7 +989,7 @@ static int geneve6_xmit_skb(struct sk_buff *skb, struc= t net_device *dev, return err; =20 udp_tunnel6_xmit_skb(dst, gs6->sock->sk, skb, dev, - &fl6.saddr, &fl6.daddr, prio, ttl, + &saddr, &key->u.ipv6.dst, prio, ttl, info->key.label, sport, geneve->cfg.info.key.tp_dst, !(info->key.tun_flags & TUNNEL_CSUM)); return 0; @@ -1126,19 +1083,28 @@ static int geneve_fill_metadata_dst(struct net_devi= ce *dev, struct sk_buff *skb) #if IS_ENABLED(CONFIG_IPV6) } else if (ip_tunnel_info_af(info) =3D=3D AF_INET6) { struct dst_entry *dst; - struct flowi6 fl6; - struct geneve_sock *gs6 =3D rcu_dereference(geneve->sock6); + struct in6_addr saddr; + bool use_cache; + u8 prio; + + if (!gs6) + return -EIO; + + use_cache =3D ip_tunnel_dst_cache_usable(skb, info); + prio =3D geneve_get_dsfield(skb, dev, info, &use_cache); sport =3D udp_flow_src_port(geneve->net, skb, 1, USHRT_MAX, true); =20 - dst =3D geneve_get_v6_dst(skb, dev, gs6, &fl6, info, - geneve->cfg.info.key.tp_dst, sport); + dst =3D udp_tunnel6_dst_lookup(skb, dev, geneve->net, gs6->sock, 0, + &saddr, &info->key, sport, + geneve->cfg.info.key.tp_dst, prio, + use_cache ? &info->dst_cache : NULL); if (IS_ERR(dst)) return PTR_ERR(dst); =20 dst_release(dst); - info->key.u.ipv6.src =3D fl6.saddr; + info->key.u.ipv6.src =3D saddr; #endif } else { return -EINVAL; --=20 2.40.1 From nobody Wed Dec 17 07:59:58 2025 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 0C9FBCDB47E for ; Fri, 20 Oct 2023 11:56:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377391AbjJTL4I (ORCPT ); Fri, 20 Oct 2023 07:56:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59162 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1377294AbjJTLz4 (ORCPT ); Fri, 20 Oct 2023 07:55:56 -0400 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE43C1BF; Fri, 20 Oct 2023 04:55:53 -0700 (PDT) Received: by mail-ej1-x635.google.com with SMTP id a640c23a62f3a-9c603e2354fso159060166b.1; Fri, 20 Oct 2023 04:55:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697802952; x=1698407752; 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=70UyLOondynQ9UoUBHNCV+hwoRw2E4n6LYozqYQifYc=; b=aii8k1vjHZGisANWo1RRAcxjrIWta2KRpCOxVW2oGGc4xxSn9L6qVSeGuMirDJ961x LhW1huUSE/PtwvIu0kqDHKBu2OZYMVllw/XCAaoaVjrm6XlxWpUkpT5LMVo/Jo5eXLud W4TMuJEvdG16g2i8VYNNEaLsVKlbvmUQp/WsQWDND7ciVYRK46nGGvuj8Lp1HSBGLQTD TUDJygo2X+x0QIi0Ezz8/ISzNLeAXPcwXdagZOr5R284F9OAM0LPLTKk4HxohctrqiCS tdUZBKdIDRF7MA2NZvYSlORCMX2WheCyhFrpRWXLqvC+1D+A5H2lHNxbsubtEO9gYlCr FgTw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697802952; x=1698407752; 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=70UyLOondynQ9UoUBHNCV+hwoRw2E4n6LYozqYQifYc=; b=ZOJMdNYhUAlOSeXlW85LHtUs8kwlBjssh0sSUrkJXE+a7gsEERkJL6g1dzJvAK53Ur TUTy11OX34mxsQ9vEIvKrvh7ZQo+DYVcEKZR3Ea3SiaWXNIwSYJQtYRh4t+U8IrgrjKr au5vEk6dnVOPeC7GwVSS6th8B3wSchMM7ik7HIV95kpRqSlP3nRRBUfPJnL1rbPU722/ 9PLgVQyqLvi1JNKGWTudvljrApvG5GGMQDwfbVWGyX+rK/6+uqfnngoMA/QJQxrREpan EuzuxFQFBI2zOPdzn/QbMW1evMt0WCKoA7ogAT+/01kUDx9IUzD6hAkxKdQeiRWW8JEB 9V8A== X-Gm-Message-State: AOJu0Yx08kEJScdy5HTZc2jTOAxyxus4kP2kB4qht3WIJVhysGtiUi65 bQWW2wY6nlM6Mo93Yq+ZWY8TTRA3HH9WLw== X-Google-Smtp-Source: AGHT+IHlwrkZ7lOpoBia6Qx8zJ6+ZowQKfdb9FM+RBV3/5EcV5sbt7LEmsLZnZYR6jimtqlBOjEXaA== X-Received: by 2002:a17:907:3e1c:b0:9b2:bcea:e517 with SMTP id hp28-20020a1709073e1c00b009b2bceae517mr1617344ejc.10.1697802951953; Fri, 20 Oct 2023 04:55:51 -0700 (PDT) Received: from tp.home.arpa (host-95-239-66-218.retail.telecomitalia.it. [95.239.66.218]) by smtp.gmail.com with ESMTPSA id v21-20020a170906489500b009b928eb8dd3sm1342014ejq.163.2023.10.20.04.55.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 04:55:51 -0700 (PDT) From: Beniamino Galvani To: netdev@vger.kernel.org Cc: "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , David Ahern , Guillaume Nault , linux-kernel@vger.kernel.org Subject: [PATCH net-next 5/5] vxlan: use generic function for tunnel IPv6 route lookup Date: Fri, 20 Oct 2023 13:55:29 +0200 Message-Id: <20231020115529.3344878-6-b.galvani@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231020115529.3344878-1-b.galvani@gmail.com> References: <20231020115529.3344878-1-b.galvani@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The route lookup can be done now via generic function udp_tunnel6_dst_lookup() to replace the custom implementation in vxlan6_get_route(). This is similar to what already done for IPv4 in commit 6f19b2c136d9 ("vxlan: use generic function for tunnel IPv4 route lookup"). Suggested-by: Guillaume Nault Signed-off-by: Beniamino Galvani Reviewed-by: David Ahern --- drivers/net/vxlan/vxlan_core.c | 136 ++++++++------------------------- 1 file changed, 30 insertions(+), 106 deletions(-) diff --git a/drivers/net/vxlan/vxlan_core.c b/drivers/net/vxlan/vxlan_core.c index 6f7d45e3cfa2..7b526ae16ed0 100644 --- a/drivers/net/vxlan/vxlan_core.c +++ b/drivers/net/vxlan/vxlan_core.c @@ -2215,63 +2215,6 @@ static int vxlan_build_skb(struct sk_buff *skb, stru= ct dst_entry *dst, return 0; } =20 -#if IS_ENABLED(CONFIG_IPV6) -static struct dst_entry *vxlan6_get_route(struct vxlan_dev *vxlan, - struct net_device *dev, - struct vxlan_sock *sock6, - struct sk_buff *skb, int oif, u8 tos, - __be32 label, - const struct in6_addr *daddr, - struct in6_addr *saddr, - __be16 dport, __be16 sport, - struct dst_cache *dst_cache, - const struct ip_tunnel_info *info) -{ - bool use_cache =3D ip_tunnel_dst_cache_usable(skb, info); - struct dst_entry *ndst; - struct flowi6 fl6; - - if (!sock6) - return ERR_PTR(-EIO); - - if (tos && !info) - use_cache =3D false; - if (use_cache) { - ndst =3D dst_cache_get_ip6(dst_cache, saddr); - if (ndst) - return ndst; - } - - memset(&fl6, 0, sizeof(fl6)); - fl6.flowi6_oif =3D oif; - fl6.daddr =3D *daddr; - fl6.saddr =3D *saddr; - fl6.flowlabel =3D ip6_make_flowinfo(tos, label); - fl6.flowi6_mark =3D skb->mark; - fl6.flowi6_proto =3D IPPROTO_UDP; - fl6.fl6_dport =3D dport; - fl6.fl6_sport =3D sport; - - ndst =3D ipv6_stub->ipv6_dst_lookup_flow(vxlan->net, sock6->sock->sk, - &fl6, NULL); - if (IS_ERR(ndst)) { - netdev_dbg(dev, "no route to %pI6\n", daddr); - return ERR_PTR(-ENETUNREACH); - } - - if (unlikely(ndst->dev =3D=3D dev)) { - netdev_dbg(dev, "circular route to %pI6\n", daddr); - dst_release(ndst); - return ERR_PTR(-ELOOP); - } - - *saddr =3D fl6.saddr; - if (use_cache) - dst_cache_set_ip6(dst_cache, ndst, saddr); - return ndst; -} -#endif - /* Bypass encapsulation if the destination is local */ static void vxlan_encap_bypass(struct sk_buff *skb, struct vxlan_dev *src_= vxlan, struct vxlan_dev *dst_vxlan, __be32 vni, @@ -2325,7 +2268,7 @@ static void vxlan_encap_bypass(struct sk_buff *skb, s= truct vxlan_dev *src_vxlan, =20 static int encap_bypass_if_local(struct sk_buff *skb, struct net_device *d= ev, struct vxlan_dev *vxlan, - union vxlan_addr *daddr, + int addr_family, __be16 dst_port, int dst_ifindex, __be32 vni, struct dst_entry *dst, u32 rt_flags) @@ -2345,7 +2288,7 @@ static int encap_bypass_if_local(struct sk_buff *skb,= struct net_device *dev, =20 dst_release(dst); dst_vxlan =3D vxlan_find_vni(vxlan->net, dst_ifindex, vni, - daddr->sa.sa_family, dst_port, + addr_family, dst_port, vxlan->cfg.flags); if (!dst_vxlan) { dev->stats.tx_errors++; @@ -2371,13 +2314,12 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net= _device *dev, struct ip_tunnel_key key; struct vxlan_dev *vxlan =3D netdev_priv(dev); const struct iphdr *old_iph =3D ip_hdr(skb); - union vxlan_addr *dst; - union vxlan_addr remote_ip; struct vxlan_metadata _md; struct vxlan_metadata *md =3D &_md; unsigned int pkt_len =3D skb->len; __be16 src_port =3D 0, dst_port; struct dst_entry *ndst =3D NULL; + int addr_family; __u8 tos, ttl; int ifindex; int err; @@ -2386,20 +2328,15 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net= _device *dev, bool udp_sum =3D false; bool xnet =3D !net_eq(vxlan->net, dev_net(vxlan->dev)); __be32 vni =3D 0; -#if IS_ENABLED(CONFIG_IPV6) - union vxlan_addr local_ip; - __be32 label; -#endif =20 info =3D skb_tunnel_info(skb); use_cache =3D ip_tunnel_dst_cache_usable(skb, info); =20 if (rdst) { - dst =3D &rdst->remote_ip; memset(&key, 0, sizeof(key)); pkey =3D &key; =20 - if (vxlan_addr_any(dst)) { + if (vxlan_addr_any(&rdst->remote_ip)) { if (did_rsc) { /* short-circuited back to local bridge */ vxlan_encap_bypass(skb, vxlan, vxlan, @@ -2409,11 +2346,12 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net= _device *dev, goto drop; } =20 + addr_family =3D vxlan->cfg.saddr.sa.sa_family; dst_port =3D rdst->remote_port ? rdst->remote_port : vxlan->cfg.dst_port; vni =3D (rdst->remote_vni) ? : default_vni; ifindex =3D rdst->remote_ifindex; =20 - if (dst->sa.sa_family =3D=3D AF_INET) { + if (addr_family =3D=3D AF_INET) { key.u.ipv4.src =3D vxlan->cfg.saddr.sin.sin_addr.s_addr; key.u.ipv4.dst =3D rdst->remote_ip.sin.sin_addr.s_addr; } else { @@ -2427,23 +2365,21 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net= _device *dev, ttl =3D ip_tunnel_get_ttl(old_iph, skb); } else { ttl =3D vxlan->cfg.ttl; - if (!ttl && vxlan_addr_multicast(dst)) + if (!ttl && vxlan_addr_multicast(&rdst->remote_ip)) ttl =3D 1; } - tos =3D vxlan->cfg.tos; if (tos =3D=3D 1) tos =3D ip_tunnel_get_dsfield(old_iph, skb); if (tos && !info) use_cache =3D false; =20 - if (dst->sa.sa_family =3D=3D AF_INET) + if (addr_family =3D=3D AF_INET) udp_sum =3D !(flags & VXLAN_F_UDP_ZERO_CSUM_TX); else udp_sum =3D !(flags & VXLAN_F_UDP_ZERO_CSUM6_TX); #if IS_ENABLED(CONFIG_IPV6) - local_ip =3D vxlan->cfg.saddr; - label =3D vxlan->cfg.label; + key.label =3D vxlan->cfg.label; #endif } else { if (!info) { @@ -2451,17 +2387,8 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_= device *dev, dev->name); goto drop; } - remote_ip.sa.sa_family =3D ip_tunnel_info_af(info); - if (remote_ip.sa.sa_family =3D=3D AF_INET) { - remote_ip.sin.sin_addr.s_addr =3D info->key.u.ipv4.dst; - } else { - remote_ip.sin6.sin6_addr =3D info->key.u.ipv6.dst; -#if IS_ENABLED(CONFIG_IPV6) - local_ip.sin6.sin6_addr =3D info->key.u.ipv6.src; -#endif - } - dst =3D &remote_ip; pkey =3D &info->key; + addr_family =3D ip_tunnel_info_af(info); dst_port =3D info->key.tp_dst ? : vxlan->cfg.dst_port; vni =3D tunnel_id_to_key32(info->key.tun_id); ifindex =3D 0; @@ -2473,16 +2400,13 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net= _device *dev, } ttl =3D info->key.ttl; tos =3D info->key.tos; -#if IS_ENABLED(CONFIG_IPV6) - label =3D info->key.label; -#endif udp_sum =3D !!(info->key.tun_flags & TUNNEL_CSUM); } src_port =3D udp_flow_src_port(dev_net(dev), skb, vxlan->cfg.port_min, vxlan->cfg.port_max, true); =20 rcu_read_lock(); - if (dst->sa.sa_family =3D=3D AF_INET) { + if (addr_family =3D=3D AF_INET) { struct vxlan_sock *sock4 =3D rcu_dereference(vxlan->vn4_sock); struct rtable *rt; __be16 df =3D 0; @@ -2501,7 +2425,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_d= evice *dev, =20 if (!info) { /* Bypass encapsulation if the destination is local */ - err =3D encap_bypass_if_local(skb, dev, vxlan, dst, + err =3D encap_bypass_if_local(skb, dev, vxlan, AF_INET, dst_port, ifindex, vni, &rt->dst, rt->rt_flags); if (err) @@ -2555,15 +2479,15 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net= _device *dev, #if IS_ENABLED(CONFIG_IPV6) } else { struct vxlan_sock *sock6 =3D rcu_dereference(vxlan->vn6_sock); + struct in6_addr saddr; =20 if (!ifindex) ifindex =3D sock6->sock->sk->sk_bound_dev_if; =20 - ndst =3D vxlan6_get_route(vxlan, dev, sock6, skb, ifindex, tos, - label, &dst->sin6.sin6_addr, - &local_ip.sin6.sin6_addr, - dst_port, src_port, - dst_cache, info); + ndst =3D udp_tunnel6_dst_lookup(skb, dev, vxlan->net, sock6->sock, + ifindex, &saddr, pkey, + src_port, dst_port, tos, + use_cache ? dst_cache : NULL); if (IS_ERR(ndst)) { err =3D PTR_ERR(ndst); ndst =3D NULL; @@ -2573,7 +2497,7 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_d= evice *dev, if (!info) { u32 rt6i_flags =3D ((struct rt6_info *)ndst)->rt6i_flags; =20 - err =3D encap_bypass_if_local(skb, dev, vxlan, dst, + err =3D encap_bypass_if_local(skb, dev, vxlan, AF_INET6, dst_port, ifindex, vni, ndst, rt6i_flags); if (err) @@ -2588,16 +2512,13 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net= _device *dev, } else if (err) { if (info) { struct ip_tunnel_info *unclone; - struct in6_addr src, dst; =20 unclone =3D skb_tunnel_info_unclone(skb); if (unlikely(!unclone)) goto tx_error; =20 - src =3D remote_ip.sin6.sin6_addr; - dst =3D local_ip.sin6.sin6_addr; - unclone->key.u.ipv6.src =3D src; - unclone->key.u.ipv6.dst =3D dst; + unclone->key.u.ipv6.src =3D pkey->u.ipv6.dst; + unclone->key.u.ipv6.dst =3D saddr; } =20 vxlan_encap_bypass(skb, vxlan, vxlan, vni, false); @@ -2614,9 +2535,8 @@ void vxlan_xmit_one(struct sk_buff *skb, struct net_d= evice *dev, goto tx_error; =20 udp_tunnel6_xmit_skb(ndst, sock6->sock->sk, skb, dev, - &local_ip.sin6.sin6_addr, - &dst->sin6.sin6_addr, tos, ttl, - label, src_port, dst_port, !udp_sum); + &saddr, &pkey->u.ipv6.dst, tos, ttl, + pkey->label, src_port, dst_port, !udp_sum); #endif } vxlan_vnifilter_count(vxlan, vni, NULL, VXLAN_VNI_STATS_TX, pkt_len); @@ -3267,10 +3187,14 @@ static int vxlan_fill_metadata_dst(struct net_devic= e *dev, struct sk_buff *skb) struct vxlan_sock *sock6 =3D rcu_dereference(vxlan->vn6_sock); struct dst_entry *ndst; =20 - ndst =3D vxlan6_get_route(vxlan, dev, sock6, skb, 0, info->key.tos, - info->key.label, &info->key.u.ipv6.dst, - &info->key.u.ipv6.src, dport, sport, - &info->dst_cache, info); + if (!sock6) + return -EIO; + + ndst =3D udp_tunnel6_dst_lookup(skb, dev, vxlan->net, sock6->sock, + 0, &info->key.u.ipv6.src, + &info->key, + sport, dport, info->key.tos, + &info->dst_cache); if (IS_ERR(ndst)) return PTR_ERR(ndst); dst_release(ndst); --=20 2.40.1