ip_tunnel: Add ip tunnel tun_info type dst_cache in ip_tunnel_xmit
ip l add dev tun type gretap key 1000 Non-tunnel-dst ip tunnel device can send packet through lwtunnel This patch provide the tun_inf dst cache support for this mode. Signed-off-by: wenxu <wenxu@ucloud.cn> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
169431ed16
commit
186d93669f
|
@ -654,14 +654,17 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
|
||||||
const struct iphdr *tnl_params, u8 protocol)
|
const struct iphdr *tnl_params, u8 protocol)
|
||||||
{
|
{
|
||||||
struct ip_tunnel *tunnel = netdev_priv(dev);
|
struct ip_tunnel *tunnel = netdev_priv(dev);
|
||||||
|
struct ip_tunnel_info *tun_info = NULL;
|
||||||
const struct iphdr *inner_iph;
|
const struct iphdr *inner_iph;
|
||||||
struct flowi4 fl4;
|
|
||||||
u8 tos, ttl;
|
|
||||||
__be16 df;
|
|
||||||
struct rtable *rt; /* Route to the other host */
|
|
||||||
unsigned int max_headroom; /* The extra header space needed */
|
unsigned int max_headroom; /* The extra header space needed */
|
||||||
__be32 dst;
|
struct rtable *rt = NULL; /* Route to the other host */
|
||||||
|
bool use_cache = false;
|
||||||
|
struct flowi4 fl4;
|
||||||
|
bool md = false;
|
||||||
bool connected;
|
bool connected;
|
||||||
|
u8 tos, ttl;
|
||||||
|
__be32 dst;
|
||||||
|
__be16 df;
|
||||||
|
|
||||||
inner_iph = (const struct iphdr *)skb_inner_network_header(skb);
|
inner_iph = (const struct iphdr *)skb_inner_network_header(skb);
|
||||||
connected = (tunnel->parms.iph.daddr != 0);
|
connected = (tunnel->parms.iph.daddr != 0);
|
||||||
|
@ -671,7 +674,6 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
|
||||||
dst = tnl_params->daddr;
|
dst = tnl_params->daddr;
|
||||||
if (dst == 0) {
|
if (dst == 0) {
|
||||||
/* NBMA tunnel */
|
/* NBMA tunnel */
|
||||||
struct ip_tunnel_info *tun_info;
|
|
||||||
|
|
||||||
if (!skb_dst(skb)) {
|
if (!skb_dst(skb)) {
|
||||||
dev->stats.tx_fifo_errors++;
|
dev->stats.tx_fifo_errors++;
|
||||||
|
@ -681,8 +683,11 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
|
||||||
tun_info = skb_tunnel_info(skb);
|
tun_info = skb_tunnel_info(skb);
|
||||||
if (tun_info && (tun_info->mode & IP_TUNNEL_INFO_TX) &&
|
if (tun_info && (tun_info->mode & IP_TUNNEL_INFO_TX) &&
|
||||||
ip_tunnel_info_af(tun_info) == AF_INET &&
|
ip_tunnel_info_af(tun_info) == AF_INET &&
|
||||||
tun_info->key.u.ipv4.dst)
|
tun_info->key.u.ipv4.dst) {
|
||||||
dst = tun_info->key.u.ipv4.dst;
|
dst = tun_info->key.u.ipv4.dst;
|
||||||
|
md = true;
|
||||||
|
connected = true;
|
||||||
|
}
|
||||||
else if (skb->protocol == htons(ETH_P_IP)) {
|
else if (skb->protocol == htons(ETH_P_IP)) {
|
||||||
rt = skb_rtable(skb);
|
rt = skb_rtable(skb);
|
||||||
dst = rt_nexthop(rt, inner_iph->daddr);
|
dst = rt_nexthop(rt, inner_iph->daddr);
|
||||||
|
@ -721,6 +726,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
|
||||||
else
|
else
|
||||||
goto tx_error;
|
goto tx_error;
|
||||||
|
|
||||||
|
if (!md)
|
||||||
connected = false;
|
connected = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -743,8 +749,15 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
|
||||||
if (ip_tunnel_encap(skb, tunnel, &protocol, &fl4) < 0)
|
if (ip_tunnel_encap(skb, tunnel, &protocol, &fl4) < 0)
|
||||||
goto tx_error;
|
goto tx_error;
|
||||||
|
|
||||||
rt = connected ? dst_cache_get_ip4(&tunnel->dst_cache, &fl4.saddr) :
|
if (connected && md) {
|
||||||
NULL;
|
use_cache = ip_tunnel_dst_cache_usable(skb, tun_info);
|
||||||
|
if (use_cache)
|
||||||
|
rt = dst_cache_get_ip4(&tun_info->dst_cache,
|
||||||
|
&fl4.saddr);
|
||||||
|
} else {
|
||||||
|
rt = connected ? dst_cache_get_ip4(&tunnel->dst_cache,
|
||||||
|
&fl4.saddr) : NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (!rt) {
|
if (!rt) {
|
||||||
rt = ip_route_output_key(tunnel->net, &fl4);
|
rt = ip_route_output_key(tunnel->net, &fl4);
|
||||||
|
@ -753,7 +766,10 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
|
||||||
dev->stats.tx_carrier_errors++;
|
dev->stats.tx_carrier_errors++;
|
||||||
goto tx_error;
|
goto tx_error;
|
||||||
}
|
}
|
||||||
if (connected)
|
if (use_cache)
|
||||||
|
dst_cache_set_ip4(&tun_info->dst_cache, &rt->dst,
|
||||||
|
fl4.saddr);
|
||||||
|
else if (!md && connected)
|
||||||
dst_cache_set_ip4(&tunnel->dst_cache, &rt->dst,
|
dst_cache_set_ip4(&tunnel->dst_cache, &rt->dst,
|
||||||
fl4.saddr);
|
fl4.saddr);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue