Commit 946fcfdb authored by Beniamino Galvani's avatar Beniamino Galvani Committed by David S. Miller

ipv6: add new arguments to udp_tunnel6_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).

This is similar to what already done for IPv4 in commit 72fc68c6
("ipv4: add new arguments to udp_tunnel_dst_lookup()").
Suggested-by: default avatarGuillaume Nault <gnault@redhat.com>
Signed-off-by: default avatarBeniamino Galvani <b.galvani@gmail.com>
Reviewed-by: default avatarDavid Ahern <dsahern@kernel.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 7e937dcf
...@@ -371,8 +371,10 @@ static int bareudp6_xmit_skb(struct sk_buff *skb, struct net_device *dev, ...@@ -371,8 +371,10 @@ static int bareudp6_xmit_skb(struct sk_buff *skb, struct net_device *dev,
if (!sock) if (!sock)
return -ESHUTDOWN; return -ESHUTDOWN;
dst = udp_tunnel6_dst_lookup(skb, dev, bareudp->net, sock, &saddr, info, dst = udp_tunnel6_dst_lookup(skb, dev, bareudp->net, sock, 0, &saddr,
use_cache); key, 0, 0, key->tos,
use_cache ?
(struct dst_cache *) &info->dst_cache : NULL);
if (IS_ERR(dst)) if (IS_ERR(dst))
return PTR_ERR(dst); return PTR_ERR(dst);
...@@ -499,7 +501,9 @@ static int bareudp_fill_metadata_dst(struct net_device *dev, ...@@ -499,7 +501,9 @@ static int bareudp_fill_metadata_dst(struct net_device *dev,
struct socket *sock = rcu_dereference(bareudp->sock); struct socket *sock = rcu_dereference(bareudp->sock);
dst = udp_tunnel6_dst_lookup(skb, dev, bareudp->net, sock, dst = 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)) if (IS_ERR(dst))
return PTR_ERR(dst); return PTR_ERR(dst);
......
...@@ -172,10 +172,11 @@ struct rtable *udp_tunnel_dst_lookup(struct sk_buff *skb, ...@@ -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 dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb,
struct net_device *dev, struct net_device *dev,
struct net *net, struct net *net,
struct socket *sock, struct socket *sock, int oif,
struct in6_addr *saddr, struct in6_addr *saddr,
const struct ip_tunnel_info *info, const struct ip_tunnel_key *key,
bool use_cache); __be16 sport, __be16 dport, u8 dsfield,
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,
......
...@@ -119,9 +119,13 @@ EXPORT_SYMBOL_GPL(udp_tunnel6_xmit_skb); ...@@ -119,9 +119,13 @@ EXPORT_SYMBOL_GPL(udp_tunnel6_xmit_skb);
* @dev: Tunnel device * @dev: Tunnel device
* @net: Network namespace of tunnel device * @net: Network namespace of tunnel device
* @sock: Socket which provides route info * @sock: Socket which provides route info
* @oif: Index of the output interface
* @saddr: Memory to store the src ip address * @saddr: Memory to store the src ip address
* @info: Tunnel information * @key: Tunnel information
* @use_cache: Flag to enable cache usage * @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 * This function performs a route lookup on a UDP tunnel
* *
* It returns a valid dst pointer and stores src address to be used in * 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_buff *skb, ...@@ -132,20 +136,17 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb,
struct net_device *dev, struct net_device *dev,
struct net *net, struct net *net,
struct socket *sock, struct socket *sock,
int oif,
struct in6_addr *saddr, struct in6_addr *saddr,
const struct ip_tunnel_info *info, const struct ip_tunnel_key *key,
bool use_cache) __be16 sport, __be16 dport, u8 dsfield,
struct dst_cache *dst_cache)
{ {
struct dst_entry *dst = NULL; struct dst_entry *dst = NULL;
#ifdef CONFIG_DST_CACHE
struct dst_cache *dst_cache;
#endif
struct flowi6 fl6; struct flowi6 fl6;
__u8 prio;
#ifdef CONFIG_DST_CACHE #ifdef CONFIG_DST_CACHE
dst_cache = (struct dst_cache *)&info->dst_cache; if (dst_cache) {
if (use_cache) {
dst = dst_cache_get_ip6(dst_cache, saddr); dst = dst_cache_get_ip6(dst_cache, saddr);
if (dst) if (dst)
return dst; return dst;
...@@ -154,10 +155,12 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb, ...@@ -154,10 +155,12 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb,
memset(&fl6, 0, sizeof(fl6)); memset(&fl6, 0, sizeof(fl6));
fl6.flowi6_mark = skb->mark; fl6.flowi6_mark = skb->mark;
fl6.flowi6_proto = IPPROTO_UDP; fl6.flowi6_proto = IPPROTO_UDP;
fl6.daddr = info->key.u.ipv6.dst; fl6.flowi6_oif = oif;
fl6.saddr = info->key.u.ipv6.src; fl6.daddr = key->u.ipv6.dst;
prio = info->key.tos; fl6.saddr = key->u.ipv6.src;
fl6.flowlabel = ip6_make_flowinfo(prio, info->key.label); fl6.fl6_sport = sport;
fl6.fl6_dport = dport;
fl6.flowlabel = ip6_make_flowinfo(dsfield, key->label);
dst = ipv6_stub->ipv6_dst_lookup_flow(net, sock->sk, &fl6, dst = ipv6_stub->ipv6_dst_lookup_flow(net, sock->sk, &fl6,
NULL); NULL);
...@@ -171,7 +174,7 @@ struct dst_entry *udp_tunnel6_dst_lookup(struct sk_buff *skb, ...@@ -171,7 +174,7 @@ struct dst_entry *udp_tunnel6_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_ip6(dst_cache, dst, &fl6.saddr); dst_cache_set_ip6(dst_cache, dst, &fl6.saddr);
#endif #endif
*saddr = fl6.saddr; *saddr = fl6.saddr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment