mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	ipv4: add new arguments to udp_tunnel_dst_lookup()
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 <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>
This commit is contained in:
		
							parent
							
								
									78f3655adc
								
							
						
					
					
						commit
						72fc68c635
					
				
					 3 changed files with 25 additions and 20 deletions
				
			
		| 
						 | 
					@ -306,8 +306,10 @@ static int bareudp_xmit_skb(struct sk_buff *skb, struct net_device *dev,
 | 
				
			||||||
	if (!sock)
 | 
						if (!sock)
 | 
				
			||||||
		return -ESHUTDOWN;
 | 
							return -ESHUTDOWN;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr, info,
 | 
						rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, 0, &saddr, &info->key,
 | 
				
			||||||
				   use_cache);
 | 
									   0, 0, key->tos,
 | 
				
			||||||
 | 
									   use_cache ?
 | 
				
			||||||
 | 
									   (struct dst_cache *)&info->dst_cache : NULL);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (IS_ERR(rt))
 | 
						if (IS_ERR(rt))
 | 
				
			||||||
		return PTR_ERR(rt);
 | 
							return PTR_ERR(rt);
 | 
				
			||||||
| 
						 | 
					@ -483,8 +485,9 @@ static int bareudp_fill_metadata_dst(struct net_device *dev,
 | 
				
			||||||
		struct rtable *rt;
 | 
							struct rtable *rt;
 | 
				
			||||||
		__be32 saddr;
 | 
							__be32 saddr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, &saddr,
 | 
							rt = udp_tunnel_dst_lookup(skb, dev, bareudp->net, 0, &saddr,
 | 
				
			||||||
					   info, use_cache);
 | 
										   &info->key, 0, 0, info->key.tos,
 | 
				
			||||||
 | 
										   use_cache ? &info->dst_cache : NULL);
 | 
				
			||||||
		if (IS_ERR(rt))
 | 
							if (IS_ERR(rt))
 | 
				
			||||||
			return PTR_ERR(rt);
 | 
								return PTR_ERR(rt);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -164,9 +164,11 @@ void udp_tunnel_sock_release(struct socket *sock);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,
 | 
					struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,
 | 
				
			||||||
				     struct net_device *dev,
 | 
									     struct net_device *dev,
 | 
				
			||||||
				     struct net *net, __be32 *saddr,
 | 
									     struct net *net, int oif,
 | 
				
			||||||
				     const struct ip_tunnel_info *info,
 | 
									     __be32 *saddr,
 | 
				
			||||||
				     bool use_cache);
 | 
									     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,
 | 
					struct metadata_dst *udp_tun_rx_dst(struct sk_buff *skb, unsigned short family,
 | 
				
			||||||
				    __be16 flags, __be64 tunnel_id,
 | 
									    __be16 flags, __be64 tunnel_id,
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -206,31 +206,31 @@ EXPORT_SYMBOL_GPL(udp_tun_rx_dst);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,
 | 
					struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb,
 | 
				
			||||||
				     struct net_device *dev,
 | 
									     struct net_device *dev,
 | 
				
			||||||
				     struct net *net, __be32 *saddr,
 | 
									     struct net *net, int oif,
 | 
				
			||||||
				     const struct ip_tunnel_info *info,
 | 
									     __be32 *saddr,
 | 
				
			||||||
				     bool use_cache)
 | 
									     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 rtable *rt = NULL;
 | 
				
			||||||
	struct flowi4 fl4;
 | 
						struct flowi4 fl4;
 | 
				
			||||||
	__u8 tos;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef CONFIG_DST_CACHE
 | 
					#ifdef CONFIG_DST_CACHE
 | 
				
			||||||
	dst_cache = (struct dst_cache *)&info->dst_cache;
 | 
						if (dst_cache) {
 | 
				
			||||||
	if (use_cache) {
 | 
					 | 
				
			||||||
		rt = dst_cache_get_ip4(dst_cache, saddr);
 | 
							rt = dst_cache_get_ip4(dst_cache, saddr);
 | 
				
			||||||
		if (rt)
 | 
							if (rt)
 | 
				
			||||||
			return rt;
 | 
								return rt;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	memset(&fl4, 0, sizeof(fl4));
 | 
						memset(&fl4, 0, sizeof(fl4));
 | 
				
			||||||
	fl4.flowi4_mark = skb->mark;
 | 
						fl4.flowi4_mark = skb->mark;
 | 
				
			||||||
	fl4.flowi4_proto = IPPROTO_UDP;
 | 
						fl4.flowi4_proto = IPPROTO_UDP;
 | 
				
			||||||
	fl4.daddr = info->key.u.ipv4.dst;
 | 
						fl4.flowi4_oif = oif;
 | 
				
			||||||
	fl4.saddr = info->key.u.ipv4.src;
 | 
						fl4.daddr = key->u.ipv4.dst;
 | 
				
			||||||
	tos = info->key.tos;
 | 
						fl4.saddr = key->u.ipv4.src;
 | 
				
			||||||
 | 
						fl4.fl4_dport = dport;
 | 
				
			||||||
 | 
						fl4.fl4_sport = sport;
 | 
				
			||||||
	fl4.flowi4_tos = RT_TOS(tos);
 | 
						fl4.flowi4_tos = RT_TOS(tos);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	rt = ip_route_output_key(net, &fl4);
 | 
						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);
 | 
							return ERR_PTR(-ELOOP);
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
#ifdef CONFIG_DST_CACHE
 | 
					#ifdef CONFIG_DST_CACHE
 | 
				
			||||||
	if (use_cache)
 | 
						if (dst_cache)
 | 
				
			||||||
		dst_cache_set_ip4(dst_cache, &rt->dst, fl4.saddr);
 | 
							dst_cache_set_ip4(dst_cache, &rt->dst, fl4.saddr);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
	*saddr = fl4.saddr;
 | 
						*saddr = fl4.saddr;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue