Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ipv4: rename and move ip_route_output_tunnel()

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 <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>

authored by

Beniamino Galvani and committed by
David S. Miller
bf3fcbf7 3c4fe898

+58 -58
+4 -4
drivers/net/bareudp.c
··· 306 306 if (!sock) 307 307 return -ESHUTDOWN; 308 308 309 - rt = ip_route_output_tunnel(skb, dev, bareudp->net, &saddr, info, 310 - IPPROTO_UDP, use_cache); 309 + rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr, info, 310 + IPPROTO_UDP, use_cache); 311 311 312 312 if (IS_ERR(rt)) 313 313 return PTR_ERR(rt); ··· 483 483 struct rtable *rt; 484 484 __be32 saddr; 485 485 486 - rt = ip_route_output_tunnel(skb, dev, bareudp->net, &saddr, 487 - info, IPPROTO_UDP, use_cache); 486 + rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr, 487 + info, IPPROTO_UDP, use_cache); 488 488 if (IS_ERR(rt)) 489 489 return PTR_ERR(rt); 490 490
-6
include/net/route.h
··· 136 136 137 137 struct rtable *ip_route_output_flow(struct net *, struct flowi4 *flp, 138 138 const struct sock *sk); 139 - struct rtable *ip_route_output_tunnel(struct sk_buff *skb, 140 - struct net_device *dev, 141 - struct net *net, __be32 *saddr, 142 - const struct ip_tunnel_info *info, 143 - u8 protocol, bool use_cache); 144 - 145 139 struct dst_entry *ipv4_blackhole_route(struct net *net, 146 140 struct dst_entry *dst_orig); 147 141
+6
include/net/udp_tunnel.h
··· 162 162 163 163 void udp_tunnel_sock_release(struct socket *sock); 164 164 165 + struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb, 166 + struct net_device *dev, 167 + struct net *net, __be32 *saddr, 168 + const struct ip_tunnel_info *info, 169 + u8 protocol, bool use_cache); 170 + 165 171 struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family, 166 172 __be16 flags, __be64 tunnel_id, 167 173 int md_size);
-48
net/ipv4/route.c
··· 2885 2885 } 2886 2886 EXPORT_SYMBOL_GPL(ip_route_output_flow); 2887 2887 2888 - struct rtable *ip_route_output_tunnel(struct sk_buff *skb, 2889 - struct net_device *dev, 2890 - struct net *net, __be32 *saddr, 2891 - const struct ip_tunnel_info *info, 2892 - u8 protocol, bool use_cache) 2893 - { 2894 - #ifdef CONFIG_DST_CACHE 2895 - struct dst_cache *dst_cache; 2896 - #endif 2897 - struct rtable *rt = NULL; 2898 - struct flowi4 fl4; 2899 - __u8 tos; 2900 - 2901 - #ifdef CONFIG_DST_CACHE 2902 - dst_cache = (struct dst_cache *)&info->dst_cache; 2903 - if (use_cache) { 2904 - rt = dst_cache_get_ip4(dst_cache, saddr); 2905 - if (rt) 2906 - return rt; 2907 - } 2908 - #endif 2909 - memset(&fl4, 0, sizeof(fl4)); 2910 - fl4.flowi4_mark = skb->mark; 2911 - fl4.flowi4_proto = protocol; 2912 - fl4.daddr = info->key.u.ipv4.dst; 2913 - fl4.saddr = info->key.u.ipv4.src; 2914 - tos = info->key.tos; 2915 - fl4.flowi4_tos = RT_TOS(tos); 2916 - 2917 - rt = ip_route_output_key(net, &fl4); 2918 - if (IS_ERR(rt)) { 2919 - netdev_dbg(dev, "no route to %pI4\n", &fl4.daddr); 2920 - return ERR_PTR(-ENETUNREACH); 2921 - } 2922 - if (rt->dst.dev == dev) { /* is this necessary? */ 2923 - netdev_dbg(dev, "circular route to %pI4\n", &fl4.daddr); 2924 - ip_rt_put(rt); 2925 - return ERR_PTR(-ELOOP); 2926 - } 2927 - #ifdef CONFIG_DST_CACHE 2928 - if (use_cache) 2929 - dst_cache_set_ip4(dst_cache, &rt->dst, fl4.saddr); 2930 - #endif 2931 - *saddr = fl4.saddr; 2932 - return rt; 2933 - } 2934 - EXPORT_SYMBOL_GPL(ip_route_output_tunnel); 2935 - 2936 2888 /* called with rcu_read_lock held */ 2937 2889 static int rt_fill_info(struct net *net, __be32 dst, __be32 src, 2938 2890 struct rtable *rt, u32 table_id, struct flowi4 *fl4,
+48
net/ipv4/udp_tunnel_core.c
··· 204 204 } 205 205 EXPORT_SYMBOL_GPL(udp_tun_rx_dst); 206 206 207 + struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb, 208 + struct net_device *dev, 209 + struct net *net, __be32 *saddr, 210 + const struct ip_tunnel_info *info, 211 + u8 protocol, bool use_cache) 212 + { 213 + #ifdef CONFIG_DST_CACHE 214 + struct dst_cache *dst_cache; 215 + #endif 216 + struct rtable *rt = NULL; 217 + struct flowi4 fl4; 218 + __u8 tos; 219 + 220 + #ifdef CONFIG_DST_CACHE 221 + dst_cache = (struct dst_cache *)&info->dst_cache; 222 + if (use_cache) { 223 + rt = dst_cache_get_ip4(dst_cache, saddr); 224 + if (rt) 225 + return rt; 226 + } 227 + #endif 228 + memset(&fl4, 0, sizeof(fl4)); 229 + fl4.flowi4_mark = skb->mark; 230 + fl4.flowi4_proto = protocol; 231 + fl4.daddr = info->key.u.ipv4.dst; 232 + fl4.saddr = info->key.u.ipv4.src; 233 + tos = info->key.tos; 234 + fl4.flowi4_tos = RT_TOS(tos); 235 + 236 + rt = ip_route_output_key(net, &fl4); 237 + if (IS_ERR(rt)) { 238 + netdev_dbg(dev, "no route to %pI4\n", &fl4.daddr); 239 + return ERR_PTR(-ENETUNREACH); 240 + } 241 + if (rt->dst.dev == dev) { /* is this necessary? */ 242 + netdev_dbg(dev, "circular route to %pI4\n", &fl4.daddr); 243 + ip_rt_put(rt); 244 + return ERR_PTR(-ELOOP); 245 + } 246 + #ifdef CONFIG_DST_CACHE 247 + if (use_cache) 248 + dst_cache_set_ip4(dst_cache, &rt->dst, fl4.saddr); 249 + #endif 250 + *saddr = fl4.saddr; 251 + return rt; 252 + } 253 + EXPORT_SYMBOL_GPL(udp_tunnel_dst_lookup); 254 + 207 255 MODULE_LICENSE("GPL");