ip_tunnel: allow not to count pkts on tstats by setting skb’s dev to NULL [Linux 4.14.136]

This Linux kernel change "ip_tunnel: allow not to count pkts on tstats by setting skb’s dev to NULL" is included in the Linux 4.14.136 release. This change is authored by Xin Long <lucien.xin [at] gmail.com> on Mon Jun 17 21:34:13 2019 +0800. The commit for this change in Linux stable tree is b72fd56 (patch) which is from upstream commit 5684abf. The same Linux upstream change may have been applied to various maintained Linux releases and you can find all Linux releases containing changes from upstream 5684abf.

ip_tunnel: allow not to count pkts on tstats by setting skb's dev to NULL

commit 5684abf7020dfc5f0b6ba1d68eda3663871fce52 upstream.

iptunnel_xmit() works as a common function, also used by a udp tunnel
which doesn't have to have a tunnel device, like how TIPC works with
udp media.

In these cases, we should allow not to count pkts on dev's tstats, so
that udp tunnel can work with no tunnel device safely.

Signed-off-by: Xin Long <lucien.xin@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Cc: Tommi Rantala <tommi.t.rantala@nokia.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

There are 9 lines of Linux source code added/deleted in this change. Code changes to Linux kernel are as follows.

 net/ipv4/ip_tunnel_core.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
index 4230917..2aaf7f8 100644
--- a/net/ipv4/ip_tunnel_core.c
+++ b/net/ipv4/ip_tunnel_core.c
@@ -89,9 +89,12 @@ void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
    __ip_select_ident(net, iph, skb_shinfo(skb)->gso_segs ?: 1);

    err = ip_local_out(net, sk, skb);
-   if (unlikely(net_xmit_eval(err)))
-       pkt_len = 0;
-   iptunnel_xmit_stats(dev, pkt_len);
+
+   if (dev) {
+       if (unlikely(net_xmit_eval(err)))
+           pkt_len = 0;
+       iptunnel_xmit_stats(dev, pkt_len);
+   }
 }
 EXPORT_SYMBOL_GPL(iptunnel_xmit);

Leave a Reply

Your email address will not be published. Required fields are marked *