netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] L2TP:Adjust intf MTU, add underlay L3, overlay L2
@ 2016-09-21 21:11 R. Parameswaran
  2016-09-22  8:53 ` Derek Fawcus
  0 siblings, 1 reply; 3+ messages in thread
From: R. Parameswaran @ 2016-09-21 21:11 UTC (permalink / raw)
  To: kleptog, jchapman, mostrows, acme, netdev
  Cc: davem, linux-kernel, nprachan, rshearma, dfawcus, stephen


Take into account all of the tunnel encapsulation headers when setting
up the MTU on the L2TP logical interface device. Otherwise, packets
created by the applications on top of the L2TP layer are larger
than they ought to be, relative to the underlay MTU, leading to
needless fragmentation once the outer IP encap is added.

Specifically, take into account the (outer, underlay) IP header
imposed on the encapsulated L2TP packet, and the Layer 2 header
imposed on the inner IP packet prior to L2TP encapsulation.

Do not assume an Ethernet (non-jumbo) underlay. Use the PMTU mechanism
and the dst entry in the L2TP tunnel socket to directly pull up
the underlay MTU (as the baseline number on top of which the
encapsulation headers are factored in).  Fall back to Ethernet MTU
if this fails.

Signed-off-by: Ramkumar Parameswaran <rparames@brocade.com>

Reviewed-by: N. Prachanda <nprachan@brocade.com>,
              R. Shearman  <rshearma@brocade.com>,
              D. Fawcus    <dfawcus@brocade.com>


---
  net/l2tp/l2tp_eth.c | 48 ++++++++++++++++++++++++++++++++++++++++++++----
  1 file changed, 44 insertions(+), 4 deletions(-)

diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
index 57fc5a4..dbcd6bd 100644
--- a/net/l2tp/l2tp_eth.c
+++ b/net/l2tp/l2tp_eth.c
@@ -30,6 +30,9 @@
  #include <net/xfrm.h>
  #include <net/net_namespace.h>
  #include <net/netns/generic.h>
+#include <linux/ip.h>
+#include <linux/ipv6.h>
+#include <linux/udp.h>

  #include "l2tp_core.h"

@@ -206,6 +209,46 @@ static void l2tp_eth_show(struct seq_file *m, void 
*arg)
  }
  #endif

+static void l2tp_eth_adjust_mtu(struct l2tp_tunnel *tunnel,
+				struct l2tp_session *session,
+				struct net_device *dev)
+{
+	unsigned int overhead = 0;
+	struct dst_entry *dst;
+
+	if (session->mtu != 0) {
+		dev->mtu = session->mtu;
+		dev->needed_headroom += session->hdr_len;
+		if (tunnel->encap == L2TP_ENCAPTYPE_UDP)
+			dev->needed_headroom += sizeof(struct udphdr);
+		return;
+	}
+	overhead = session->hdr_len;
+	/* Adjust MTU, factor overhead - underlay L3 hdr, overlay L2 hdr*/
+	if (tunnel->sock->sk_family == AF_INET)
+		overhead += (ETH_HLEN + sizeof(struct iphdr));
+	else if (tunnel->sock->sk_family == AF_INET6)
+		overhead += (ETH_HLEN + sizeof(struct ipv6hdr));
+	/* Additionally, if the encap is UDP, account for UDP header size */
+	if (tunnel->encap == L2TP_ENCAPTYPE_UDP)
+		overhead += sizeof(struct udphdr);
+	/* If PMTU discovery was enabled, use discovered MTU on L2TP device */
+	dst = sk_dst_get(tunnel->sock);
+	if (dst) {
+		u32 pmtu = dst_mtu(dst);
+
+		if (pmtu != 0)
+			dev->mtu = pmtu;
+		dst_release(dst);
+	}
+	/* else (no PMTUD) L2TP dev MTU defaulted to Ethernet MTU in caller */
+	session->mtu = dev->mtu - overhead;
+	dev->mtu = session->mtu;
+	dev->needed_headroom += session->hdr_len;
+	if (tunnel->encap == L2TP_ENCAPTYPE_UDP)
+		dev->needed_headroom += sizeof(struct udphdr);
+}
+
  static int l2tp_eth_create(struct net *net, u32 tunnel_id, u32 
session_id, u32 peer_session_id, struct l2tp_session_cfg *cfg)
  {
  	struct net_device *dev;
@@ -255,11 +298,8 @@ static int l2tp_eth_create(struct net *net, u32 
tunnel_id, u32 session_id, u32 p
  	}

  	dev_net_set(dev, net);
-	if (session->mtu == 0)
-		session->mtu = dev->mtu - session->hdr_len;
-	dev->mtu = session->mtu;
-	dev->needed_headroom += session->hdr_len;

+	l2tp_eth_adjust_mtu(tunnel, session, dev);
  	priv = netdev_priv(dev);
  	priv->dev = dev;
  	priv->session = session;
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] L2TP:Adjust intf MTU, add underlay L3, overlay L2
  2016-09-21 21:11 [PATCH] L2TP:Adjust intf MTU, add underlay L3, overlay L2 R. Parameswaran
@ 2016-09-22  8:53 ` Derek Fawcus
  2016-09-22 21:19   ` R. Parameswaran
  0 siblings, 1 reply; 3+ messages in thread
From: Derek Fawcus @ 2016-09-22  8:53 UTC (permalink / raw)
  To: R. Parameswaran
  Cc: kleptog, jchapman, mostrows, acme, netdev, davem, linux-kernel,
	nprachan, rshearma, stephen

On Wed, Sep 21, 2016 at 02:11:04pm -0700, R. Parameswaran wrote:
> 
[snip]

> @@ -206,6 +209,46 @@ static void l2tp_eth_show(struct seq_file *m, void
> *arg)
>  }
>  #endif
[snip]

> +
>  static int l2tp_eth_create(struct net *net, u32 tunnel_id, u32 session_id,
> u32 peer_session_id, struct l2tp_session_cfg *cfg)
>  {
>  	struct net_device *dev;
> @@ -255,11 +298,8 @@ static int l2tp_eth_create(struct net *net, u32
> tunnel_id, u32 session_id, u32 p
>  	}
> 

Your diff has whitespace errors,  probably where your MUA has decided to do
'intelligent' line wrapping.
You should (re)send from a proper MUA which does not suffer from this issue.

DF

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] L2TP:Adjust intf MTU, add underlay L3, overlay L2
  2016-09-22  8:53 ` Derek Fawcus
@ 2016-09-22 21:19   ` R. Parameswaran
  0 siblings, 0 replies; 3+ messages in thread
From: R. Parameswaran @ 2016-09-22 21:19 UTC (permalink / raw)
  To: R. Parameswaran, kleptog, jchapman, mostrows, acme, netdev,
	davem, linux-kernel, nprachan, rshearma, stephen



On Thu, 22 Sep 2016, Derek Fawcus wrote:

> On Wed, Sep 21, 2016 at 02:11:04pm -0700, R. Parameswaran wrote:
> > 
> [snip]
> 
> > @@ -206,6 +209,46 @@ static void l2tp_eth_show(struct seq_file *m, void
> > *arg)
> >  }
> >  #endif
> [snip]
> 
> > +
> >  static int l2tp_eth_create(struct net *net, u32 tunnel_id, u32 session_id,
> > u32 peer_session_id, struct l2tp_session_cfg *cfg)
> >  {
> >  	struct net_device *dev;
> > @@ -255,11 +298,8 @@ static int l2tp_eth_create(struct net *net, u32
> > tunnel_id, u32 session_id, u32 p
> >  	}
> > 
> 
> Your diff has whitespace errors,  probably where your MUA has decided to do
> 'intelligent' line wrapping.
> You should (re)send from a proper MUA which does not suffer from this issue.
> 
> DF
> 

Reposted the patch fixing this, and after rebasing the patch to the 
dmiller 'net' tree, verified that 'git am -c' applies the reposted patch 
successfully (after email header is removed) - thanks for identifying 
this.

regards,

Ramkumar

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2016-09-22 21:19 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-21 21:11 [PATCH] L2TP:Adjust intf MTU, add underlay L3, overlay L2 R. Parameswaran
2016-09-22  8:53 ` Derek Fawcus
2016-09-22 21:19   ` R. Parameswaran

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).