diff mbox series

[net-next] ip_gre: Make none-tunnel-dst gre port work with lwtunnel

Message ID 1547520275-12982-1-git-send-email-wenxu@ucloud.cn
State Changes Requested
Delegated to: David Miller
Headers show
Series [net-next] ip_gre: Make none-tunnel-dst gre port work with lwtunnel | expand

Commit Message

wenxu Jan. 15, 2019, 2:44 a.m. UTC
From: wenxu <wenxu@ucloud.cn>

ip l add dev tun type gretap key 1000
ip a a dev tun 10.0.0.1/24

Packets with tun-id 1000 can be recived by tun dev. But packet can't
be sent through dev tun for non-tunnel-dst

With this patch: tunnel-dst can be get through lwtunnel like beflow:
ip r a 10.0.0.7 encap ip id 1000 dst 172.168.0.11 key dev tun

Signed-off-by: wenxu <wenxu@ucloud.cn>
---
 net/ipv4/ip_gre.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

Comments

wenxu Jan. 18, 2019, 12:10 a.m. UTC | #1
Hi David,

what about the status of this patch?

BR
wenxu
On 2019/1/15 上午10:44, wenxu@ucloud.cn wrote:
> From: wenxu <wenxu@ucloud.cn>
>
> ip l add dev tun type gretap key 1000
> ip a a dev tun 10.0.0.1/24
>
> Packets with tun-id 1000 can be recived by tun dev. But packet can't
> be sent through dev tun for non-tunnel-dst
>
> With this patch: tunnel-dst can be get through lwtunnel like beflow:
> ip r a 10.0.0.7 encap ip id 1000 dst 172.168.0.11 key dev tun
>
> Signed-off-by: wenxu <wenxu@ucloud.cn>
> ---
>  net/ipv4/ip_gre.c | 18 ++++++++++++++++++
>  1 file changed, 18 insertions(+)
>
> diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
> index c7a7bd5..d87f92e 100644
> --- a/net/ipv4/ip_gre.c
> +++ b/net/ipv4/ip_gre.c
> @@ -450,6 +450,24 @@ static void __gre_xmit(struct sk_buff *skb, struct net_device *dev,
>  			 tunnel->parms.o_flags, proto, tunnel->parms.o_key,
>  			 htonl(tunnel->o_seqno));
>  
> +	if (!tnl_params->daddr) {
> +		struct ip_tunnel_info *tun_info;
> +
> +		tun_info = skb_tunnel_info(skb);
> +		if (tun_info && (tun_info->mode & IP_TUNNEL_INFO_TX) &&
> +		    ip_tunnel_info_af(tun_info) == AF_INET &&
> +		    tun_info->key.u.ipv4.dst) {
> +			struct iphdr tnl_params_info;
> +
> +			memcpy(&tnl_params_info, tnl_params,
> +			       sizeof(tnl_params_info));
> +			tnl_params_info.daddr = tun_info->key.u.ipv4.dst;
> +
> +			return ip_tunnel_xmit(skb, dev, &tnl_params_info,
> +			       tnl_params_info.protocol);
> +		}
> +	}
> +
>  	ip_tunnel_xmit(skb, dev, tnl_params, tnl_params->protocol);
>  }
>
David Miller Jan. 18, 2019, 4 a.m. UTC | #2
From: wenxu <wenxu@ucloud.cn>
Date: Fri, 18 Jan 2019 08:10:55 +0800

> what about the status of this patch?

Why don't you look in patchwork and see for yourself?

https://patchwork.ozlabs.org/patch/1024965/
David Miller Jan. 18, 2019, 7:06 p.m. UTC | #3
From: wenxu@ucloud.cn
Date: Tue, 15 Jan 2019 10:44:35 +0800

> +		tun_info = skb_tunnel_info(skb);
> +		if (tun_info && (tun_info->mode & IP_TUNNEL_INFO_TX) &&
> +		    ip_tunnel_info_af(tun_info) == AF_INET &&
> +		    tun_info->key.u.ipv4.dst) {
> +			struct iphdr tnl_params_info;
> +
> +			memcpy(&tnl_params_info, tnl_params,
> +			       sizeof(tnl_params_info));

It is not at all reasonable to build and memcpy an entire extra iphdr
on the cpu stack, for every packet transmit.  That's terrible for
performance.

Please find a more minimal and efficient way to achieve the behavior
you are looking for.

Thank you.
diff mbox series

Patch

diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index c7a7bd5..d87f92e 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -450,6 +450,24 @@  static void __gre_xmit(struct sk_buff *skb, struct net_device *dev,
 			 tunnel->parms.o_flags, proto, tunnel->parms.o_key,
 			 htonl(tunnel->o_seqno));
 
+	if (!tnl_params->daddr) {
+		struct ip_tunnel_info *tun_info;
+
+		tun_info = skb_tunnel_info(skb);
+		if (tun_info && (tun_info->mode & IP_TUNNEL_INFO_TX) &&
+		    ip_tunnel_info_af(tun_info) == AF_INET &&
+		    tun_info->key.u.ipv4.dst) {
+			struct iphdr tnl_params_info;
+
+			memcpy(&tnl_params_info, tnl_params,
+			       sizeof(tnl_params_info));
+			tnl_params_info.daddr = tun_info->key.u.ipv4.dst;
+
+			return ip_tunnel_xmit(skb, dev, &tnl_params_info,
+			       tnl_params_info.protocol);
+		}
+	}
+
 	ip_tunnel_xmit(skb, dev, tnl_params, tnl_params->protocol);
 }