ipv6: rename and move ip6_dst_lookup_tunnel()
authorBeniamino Galvani <b.galvani@gmail.com>
Fri, 20 Oct 2023 11:55:25 +0000 (13:55 +0200)
committerDavid S. Miller <davem@davemloft.net>
Mon, 23 Oct 2023 07:48:57 +0000 (08:48 +0100)
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 <gnault@redhat.com>
Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/bareudp.c
include/net/ipv6.h
include/net/udp_tunnel.h
net/ipv6/ip6_output.c
net/ipv6/ip6_udp_tunnel.c

index 47a9c2a5583cc37c296772d8609cf1bb382db6b3..9a0a1a9f6cfeb0560b53ac96b036bc9cc2b84c0b 100644 (file)
@@ -371,8 +371,8 @@ static int bareudp6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
        if (!sock)
                return -ESHUTDOWN;
 
-       dst = ip6_dst_lookup_tunnel(skb, dev, bareudp->net, sock, &saddr, info,
-                                   IPPROTO_UDP, use_cache);
+       dst = udp_tunnel6_dst_lookup(skb, dev, bareudp->net, sock, &saddr, info,
+                                    IPPROTO_UDP, use_cache);
        if (IS_ERR(dst))
                return PTR_ERR(dst);
 
@@ -498,9 +498,9 @@ static int bareudp_fill_metadata_dst(struct net_device *dev,
                struct in6_addr saddr;
                struct socket *sock = rcu_dereference(bareudp->sock);
 
-               dst = ip6_dst_lookup_tunnel(skb, dev, bareudp->net, sock,
-                                           &saddr, info, IPPROTO_UDP,
-                                           use_cache);
+               dst = udp_tunnel6_dst_lookup(skb, dev, bareudp->net, sock,
+                                            &saddr, info, IPPROTO_UDP,
+                                            use_cache);
                if (IS_ERR(dst))
                        return PTR_ERR(dst);
 
index b3444c8a6f744c17052a9fa1c85d54c6b08a1889..78d38dd88aba4ab9e1cf34e3f422b121e41a4618 100644 (file)
@@ -1133,12 +1133,6 @@ struct dst_entry *ip6_dst_lookup_flow(struct net *net, const struct sock *sk, st
 struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
                                         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);
 
index 4d0578fab01ab9145fa1550c9abc357df1a64b2e..1dac296d84490c52d7b7754fa2bc598b76561f40 100644 (file)
@@ -169,6 +169,13 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,
                                     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);
 
 struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family,
                                    __be16 flags, __be64 tunnel_id,
index 571c10fb00b1475aac1c3cc29c1c8ea9078fbbfb..3c7de89d6755a8155cc1ab6cbb60fb680b4dc93d 100644 (file)
@@ -1283,74 +1283,6 @@ struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
 }
 EXPORT_SYMBOL_GPL(ip6_sk_dst_lookup_flow);
 
-/**
- *      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 code.
- */
-
-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 = NULL;
-#ifdef CONFIG_DST_CACHE
-       struct dst_cache *dst_cache;
-#endif
-       struct flowi6 fl6;
-       __u8 prio;
-
-#ifdef CONFIG_DST_CACHE
-       dst_cache = (struct dst_cache *)&info->dst_cache;
-       if (use_cache) {
-               dst = dst_cache_get_ip6(dst_cache, saddr);
-               if (dst)
-                       return dst;
-       }
-#endif
-       memset(&fl6, 0, sizeof(fl6));
-       fl6.flowi6_mark = skb->mark;
-       fl6.flowi6_proto = protocol;
-       fl6.daddr = info->key.u.ipv6.dst;
-       fl6.saddr = info->key.u.ipv6.src;
-       prio = info->key.tos;
-       fl6.flowlabel = ip6_make_flowinfo(prio, info->key.label);
-
-       dst = 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 == 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 = 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)
 {
index 70d38705c92fa1b45e6af59abe54bd4c8e6bbf8c..fc122abf6b75f8a4e4edff8e6c329dc0deb4327c 100644 (file)
@@ -1,3 +1,4 @@
+
 // SPDX-License-Identifier: GPL-2.0-only
 #include <linux/module.h>
 #include <linux/errno.h>
@@ -112,4 +113,72 @@ int udp_tunnel6_xmit_skb(struct dst_entry *dst, struct sock *sk,
 }
 EXPORT_SYMBOL_GPL(udp_tunnel6_xmit_skb);
 
+/**
+ *      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 code.
+ */
+
+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 = NULL;
+#ifdef CONFIG_DST_CACHE
+       struct dst_cache *dst_cache;
+#endif
+       struct flowi6 fl6;
+       __u8 prio;
+
+#ifdef CONFIG_DST_CACHE
+       dst_cache = (struct dst_cache *)&info->dst_cache;
+       if (use_cache) {
+               dst = dst_cache_get_ip6(dst_cache, saddr);
+               if (dst)
+                       return dst;
+       }
+#endif
+       memset(&fl6, 0, sizeof(fl6));
+       fl6.flowi6_mark = skb->mark;
+       fl6.flowi6_proto = protocol;
+       fl6.daddr = info->key.u.ipv6.dst;
+       fl6.saddr = info->key.u.ipv6.src;
+       prio = info->key.tos;
+       fl6.flowlabel = ip6_make_flowinfo(prio, info->key.label);
+
+       dst = 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 == 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 = fl6.saddr;
+       return dst;
+}
+EXPORT_SYMBOL_GPL(udp_tunnel6_dst_lookup);
+
 MODULE_LICENSE("GPL");