Skip to contentSkip to conversation

Changes for PMTU Discovery

PATCH In review Julian Anastasov 3 participants 8 messages Jul 20, 2012 – Jul 23, 2012

Subsystems (4)
lore
Share & tools
lore

Julian Anastasov

author maintainer
#0 lore raw

cover Changes for PMTU Discovery

This patchset implements PMTU Discovery for TUN
packets and option to disable it.

Julian Anastasov (2):
ipvs: implement passive PMTUD for IPIP packets
ipvs: add pmtu_disc option to disable IP DF for TUN packets

 include/net/ip_vs.h             |   11 +++++
 net/netfilter/ipvs/ip_vs_core.c |   76 ++++++++++++++++++++++++++++++++++-
 net/netfilter/ipvs/ip_vs_ctl.c  |    8 ++++
 net/netfilter/ipvs/ip_vs_xmit.c |   83 ++++++++++++++++++++++++++------------
 4 files changed, 149 insertions(+), 29 deletions(-)
Signature · 1 line
1.7.3.4
author maintainer
#1 lore raw

PATCH 1/2 ipvs: implement passive PMTUD for IPIP packets

IPVS is missing the logic to update PMTU in routing
for its IPIP packets. We monitor the dst_mtu and can return FRAG_NEEDED messages but if the tunneled packets get ICMP error we can not rely on other traffic to save the lowest MTU.

The following patch adds ICMP handling for IPIP
packets in incoming direction, from some remote host to our local IP used as saddr in the outer header. By this way we can forward any related ICMP traffic if it is for IPVS TUN connection. For the special case of PMTUD we update the routing and if client requested DF we can forward the error.

To properly update the routing we have to bind
the cached route (dest->dst_cache) to the selected saddr because ipv4_update_pmtu uses saddr for dst lookup. Add IP_VS_RT_MODE_CONNECT flag to force such binding with second route.

Update ip_vs_tunnel_xmit to provide IP_VS_RT_MODE_CONNECT
and change the code to copy DF. For now we prefer not to force PMTU discovery (outer DF=1) because we don't have configuration option to enable or disable PMTUD. As we do not keep any packets to resend, we prefer not to play games with packets without DF bit because the sender is not informed when they are rejected.

	Also, change ops->update_pmtu to be called only

for local clients because there is no point to update MTU for input routes, in our case skb->dst->dev is lo. It seems the code is copied from ipip.c where the skb dst points to tunnel device.

---
 net/netfilter/ipvs/ip_vs_core.c |   76 ++++++++++++++++++++++++++++++++++++-
 net/netfilter/ipvs/ip_vs_xmit.c |   79 +++++++++++++++++++++++++++------------
 2 files changed, 128 insertions(+), 27 deletions(-)
net/netfilter/ipvs/ip_vs_core.c +73 -3
index b54ecce..58918e2 100644
@@ -1303,7 +1303,8 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)
 	struct ip_vs_conn *cp;
 	struct ip_vs_protocol *pp;
 	struct ip_vs_proto_data *pd;
-	unsigned int offset, ihl, verdict;
+	unsigned int offset, offset2, ihl, verdict;
+	bool ipip;
 
 	*related = 1;
 
@@ -1345,6 +1346,21 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)
 
 	net = skb_net(skb);
 
+	/* Special case for errors for IPIP packets */
+	ipip = false;
+	if (cih->protocol == IPPROTO_IPIP) {
+		if (unlikely(cih->frag_off & htons(IP_OFFSET)))
+			return NF_ACCEPT;
+		/* Error for our IPIP must arrive at LOCAL_IN */
+		if (!(skb_rtable(skb)->rt_flags & RTCF_LOCAL))
+			return NF_ACCEPT;
+		offset += cih->ihl * 4;
+		cih = skb_header_pointer(skb, offset, sizeof(_ciph), &_ciph);
+		if (cih == NULL)
+			return NF_ACCEPT; /* The packet looks wrong, ignore */
+		ipip = true;
+	}
+
 	pd = ip_vs_proto_data_get(net, cih->protocol);
 	if (!pd)
 		return NF_ACCEPT;
@@ -1358,11 +1374,14 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)
 	IP_VS_DBG_PKT(11, AF_INET, pp, skb, offset,
 		      "Checking incoming ICMP for");
 
+	offset2 = offset;
 	offset += cih->ihl * 4;
 
 	ip_vs_fill_iphdr(AF_INET, cih, &ciph);
-	/* The embedded headers contain source and dest in reverse order */
-	cp = pp->conn_in_get(AF_INET, skb, &ciph, offset, 1);
+	/* The embedded headers contain source and dest in reverse order.
+	 * For IPIP this is error for request, not for reply.
+	 */
+	cp = pp->conn_in_get(AF_INET, skb, &ciph, offset, ipip ? 0 : 1);
 	if (!cp)
 		return NF_ACCEPT;
 
@@ -1376,6 +1395,57 @@ ip_vs_in_icmp(struct sk_buff *skb, int *related, unsigned int hooknum)
 		goto out;
 	}
 
+	if (ipip) {
+		__be32 info = ic->un.gateway;
+
+		/* Update the MTU */
+		if (ic->type == ICMP_DEST_UNREACH &&
+		    ic->code == ICMP_FRAG_NEEDED) {
+			struct ip_vs_dest *dest = cp->dest;
+			u32 mtu = ntohs(ic->un.frag.mtu);
+
+			/* Strip outer IP and ICMP, go to IPIP header */
+			__skb_pull(skb, ihl + sizeof(_icmph));
+			offset2 -= ihl + sizeof(_icmph);
+			skb_reset_network_header(skb);
+			IP_VS_DBG(12, "ICMP for IPIP %pI4->%pI4: mtu=%u\n",
+				&ip_hdr(skb)->saddr, &ip_hdr(skb)->daddr, mtu);
+			rcu_read_lock();
+			ipv4_update_pmtu(skb, dev_net(skb->dev),
+					 mtu, 0, 0, 0, 0);
+			rcu_read_unlock();
+			/* Client uses PMTUD? */
+			if (!(cih->frag_off & htons(IP_DF)))
+				goto ignore_ipip;
+			/* Prefer the resulting PMTU */
+			if (dest) {
+				spin_lock(&dest->dst_lock);
+				if (dest->dst_cache)
+					mtu = dst_mtu(dest->dst_cache);
+				spin_unlock(&dest->dst_lock);
+			}
+			if (mtu > 68 + sizeof(struct iphdr))
+				mtu -= sizeof(struct iphdr);
+			info = htonl(mtu);
+		}
+		/* Strip outer IP, ICMP and IPIP, go to IP header of
+		 * original request.
+		 */
+		__skb_pull(skb, offset2);
+		skb_reset_network_header(skb);
+		IP_VS_DBG(12, "Sending ICMP for %pI4->%pI4: t=%u, c=%u, i=%u\n",
+			&ip_hdr(skb)->saddr, &ip_hdr(skb)->daddr,
+			ic->type, ic->code, ntohl(info));
+		icmp_send(skb, ic->type, ic->code, info);
+		/* ICMP can be shorter but anyways, account it */
+		ip_vs_out_stats(cp, skb);
+
+ignore_ipip:
+		consume_skb(skb);
+		verdict = NF_STOLEN;
+		goto out;
+	}
+
 	/* do the statistics and put it back */
 	ip_vs_in_stats(cp, skb);
 	if (IPPROTO_TCP == cih->protocol || IPPROTO_UDP == cih->protocol)
net/netfilter/ipvs/ip_vs_xmit.c +55 -24

136 lines not on this page · raw message

Signature · 1 line
1.7.3.4
author maintainer
#2 lore raw

PATCH 2/2 ipvs: add pmtu_disc option to disable IP DF for TUN packets

In reply to Julian Anastasov

Disabling PMTU discovery can increase the output packet
rate but some users have enough resources and prefer to fragment than to drop traffic. By default, we copy the DF bit but if pmtu_disc is disabled we do not send FRAG_NEEDED messages anymore.

---
 include/net/ip_vs.h             |   11 +++++++++++
 net/netfilter/ipvs/ip_vs_ctl.c  |    8 ++++++++
 net/netfilter/ipvs/ip_vs_xmit.c |    6 +++---
 3 files changed, 22 insertions(+), 3 deletions(-)
include/net/ip_vs.h +11 -0
index 95374d1..f6741ed 100644
@@ -890,6 +890,7 @@ struct netns_ipvs {
 	unsigned int		sysctl_sync_refresh_period;
 	int			sysctl_sync_retries;
 	int			sysctl_nat_icmp_send;
+	int			sysctl_pmtu_disc;
 
 	/* ip_vs_lblc */
 	int			sysctl_lblc_expiration;
@@ -976,6 +977,11 @@ static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
 	return ipvs->sysctl_sync_sock_size;
 }
 
+static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
+{
+	return ipvs->sysctl_pmtu_disc;
+}
+
 #else
 
 static inline int sysctl_sync_threshold(struct netns_ipvs *ipvs)
@@ -1018,6 +1024,11 @@ static inline int sysctl_sync_sock_size(struct netns_ipvs *ipvs)
 	return 0;
 }
 
+static inline int sysctl_pmtu_disc(struct netns_ipvs *ipvs)
+{
+	return 1;
+}
+
 #endif
 
 /*
net/netfilter/ipvs/ip_vs_ctl.c +8 -0
index 84444dd..df7432c 100644
@@ -1801,6 +1801,12 @@ static struct ctl_table vs_vars[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec,
 	},
+	{
+		.procname	= "pmtu_disc",
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec,
+	},
 #ifdef CONFIG_IP_VS_DEBUG
 	{
 		.procname	= "debug_level",
@@ -3726,6 +3732,8 @@ int __net_init ip_vs_control_net_init_sysctl(struct net *net)
 	ipvs->sysctl_sync_retries = clamp_t(int, DEFAULT_SYNC_RETRIES, 0, 3);
 	tbl[idx++].data = &ipvs->sysctl_sync_retries;
 	tbl[idx++].data = &ipvs->sysctl_nat_icmp_send;
+	ipvs->sysctl_pmtu_disc = 1;
+	tbl[idx++].data = &ipvs->sysctl_pmtu_disc;
 
 
 	ipvs->sysctl_hdr = register_net_sysctl(net, "net/ipv4/vs", tbl);
net/netfilter/ipvs/ip_vs_xmit.c +3 -3
index c2275ba..543a554 100644
@@ -795,6 +795,7 @@ int
 ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
 		  struct ip_vs_protocol *pp)
 {
+	struct netns_ipvs *ipvs = net_ipvs(skb_net(skb));
 	struct rtable *rt;			/* Route to the other host */
 	__be32 saddr;				/* Source for tunnel */
 	struct net_device *tdev;		/* Device to other host */
@@ -830,10 +831,9 @@ ip_vs_tunnel_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
 		skb_dst(skb)->ops->update_pmtu(skb_dst(skb), NULL, skb, mtu);
 
 	/* Copy DF, reset fragment offset and MF */
-	df = old_iph->frag_off & htons(IP_DF);
+	df = sysctl_pmtu_disc(ipvs) ? old_iph->frag_off & htons(IP_DF) : 0;
 
-	if ((old_iph->frag_off & htons(IP_DF) &&
-	    mtu < ntohs(old_iph->tot_len) && !skb_is_gso(skb))) {
+	if (df && mtu < ntohs(old_iph->tot_len) && !skb_is_gso(skb)) {
 		icmp_send(skb, ICMP_DEST_UNREACH,ICMP_FRAG_NEEDED, htonl(mtu));
 		IP_VS_DBG_RL("%s(): frag needed\n", __func__);
 		goto tx_error_put;
Signature · 1 line
1.7.3.4
maintainer
#3 lore raw
In reply to Julian Anastasov
Quoted 7 lines · Julian Anastasov

This patchset implements PMTU Discovery for TUN
packets and option to disable it.

Julian Anastasov (2):
ipvs: implement passive PMTUD for IPIP packets
ipvs: add pmtu_disc option to disable IP DF for TUN packets

Quoted 5 lines
 include/net/ip_vs.h             |   11 +++++
 net/netfilter/ipvs/ip_vs_core.c |   76 ++++++++++++++++++++++++++++++++++-
 net/netfilter/ipvs/ip_vs_ctl.c  |    8 ++++
 net/netfilter/ipvs/ip_vs_xmit.c |   83 ++++++++++++++++++++++++++------------
 4 files changed, 149 insertions(+), 29 deletions(-)

Thanks, I have applied these to ipvs-next.

There were some offsets when applying the patches
and a conflict in the last hunk of ip_vs_xmit.c (in the first patch). Could you check to make sure everything went in ok?

author maintainer
#4 lore raw

Hello,

Quoted 14 lines · Simon Horman
Quoted 7 lines · Julian Anastasov

This patchset implements PMTU Discovery for TUN
packets and option to disable it.

Julian Anastasov (2):
ipvs: implement passive PMTUD for IPIP packets
ipvs: add pmtu_disc option to disable IP DF for TUN packets

Quoted 5 lines
 include/net/ip_vs.h             |   11 +++++
 net/netfilter/ipvs/ip_vs_core.c |   76 ++++++++++++++++++++++++++++++++++-
 net/netfilter/ipvs/ip_vs_ctl.c  |    8 ++++
 net/netfilter/ipvs/ip_vs_xmit.c |   83 ++++++++++++++++++++++++++------------
 4 files changed, 149 insertions(+), 29 deletions(-)
Quoted 5 lines

Thanks, I have applied these to ipvs-next.

There were some offsets when applying the patches
and a conflict in the last hunk of ip_vs_xmit.c (in the first patch). Could you check to make sure everything went in ok?

I created it for net-next on the same day because
I saw this problem. Both patches apply even on net-next from today. May be ipvs-next is outdated, net-next changes rapidly last days. If you want to push these patches in this merge window you have to update ipvs-next. If it is not possible I'll resend after 2 weeks.

Regards

--
Julian Anastasov <[email protected]>

maintainer
#5 lore raw
Quoted 25 lines · Julian Anastasov

Hello,

Quoted 14 lines · Simon Horman
Quoted 7 lines · Julian Anastasov

This patchset implements PMTU Discovery for TUN
packets and option to disable it.

Julian Anastasov (2):
ipvs: implement passive PMTUD for IPIP packets
ipvs: add pmtu_disc option to disable IP DF for TUN packets

Quoted 5 lines
 include/net/ip_vs.h             |   11 +++++
 net/netfilter/ipvs/ip_vs_core.c |   76 ++++++++++++++++++++++++++++++++++-
 net/netfilter/ipvs/ip_vs_ctl.c  |    8 ++++
 net/netfilter/ipvs/ip_vs_xmit.c |   83 ++++++++++++++++++++++++++------------
 4 files changed, 149 insertions(+), 29 deletions(-)
Quoted 5 lines

Thanks, I have applied these to ipvs-next.

There were some offsets when applying the patches
and a conflict in the last hunk of ip_vs_xmit.c (in the first patch). Could you check to make sure everything went in ok?

Quoted 6 lines

I created it for net-next on the same day because
I saw this problem. Both patches apply even on net-next from today. May be ipvs-next is outdated, net-next changes rapidly last days. If you want to push these patches in this merge window you have to update ipvs-next. If it is not possible I'll resend after 2 weeks.

ipvs-next is based on Pablo's nf-next tree.
So the timing of updating is up to him.

#6 lore raw
Quoted 33 lines · Simon Horman
Quoted 25 lines · Julian Anastasov

Hello,

Quoted 14 lines · Simon Horman
Quoted 7 lines · Julian Anastasov

This patchset implements PMTU Discovery for TUN
packets and option to disable it.

Julian Anastasov (2):
ipvs: implement passive PMTUD for IPIP packets
ipvs: add pmtu_disc option to disable IP DF for TUN packets

Quoted 5 lines
 include/net/ip_vs.h             |   11 +++++
 net/netfilter/ipvs/ip_vs_core.c |   76 ++++++++++++++++++++++++++++++++++-
 net/netfilter/ipvs/ip_vs_ctl.c  |    8 ++++
 net/netfilter/ipvs/ip_vs_xmit.c |   83 ++++++++++++++++++++++++++------------
 4 files changed, 149 insertions(+), 29 deletions(-)
Quoted 5 lines

Thanks, I have applied these to ipvs-next.

There were some offsets when applying the patches
and a conflict in the last hunk of ip_vs_xmit.c (in the first patch). Could you check to make sure everything went in ok?

Quoted 6 lines

I created it for net-next on the same day because
I saw this problem. Both patches apply even on net-next from today. May be ipvs-next is outdated, net-next changes rapidly last days. If you want to push these patches in this merge window you have to update ipvs-next. If it is not possible I'll resend after 2 weeks.

Quoted 2 lines

ipvs-next is based on Pablo's nf-next tree.
So the timing of updating is up to him.

I just refreshed my tree. Let me know if this is what you needed.

Please, feel free to ping me whenever you need this.

maintainer
#7 lore raw
Quoted 34 lines · Pablo Neira Ayuso
Quoted 33 lines · Simon Horman
Quoted 31 lines · Julian Anastasov

Hello,

Quoted 14 lines · Simon Horman
Quoted 7 lines · Julian Anastasov

This patchset implements PMTU Discovery for TUN
packets and option to disable it.

Julian Anastasov (2):
ipvs: implement passive PMTUD for IPIP packets
ipvs: add pmtu_disc option to disable IP DF for TUN packets

Quoted 5 lines
 include/net/ip_vs.h             |   11 +++++
 net/netfilter/ipvs/ip_vs_core.c |   76 ++++++++++++++++++++++++++++++++++-
 net/netfilter/ipvs/ip_vs_ctl.c  |    8 ++++
 net/netfilter/ipvs/ip_vs_xmit.c |   83 ++++++++++++++++++++++++++------------
 4 files changed, 149 insertions(+), 29 deletions(-)
Quoted 5 lines

Thanks, I have applied these to ipvs-next.

There were some offsets when applying the patches
and a conflict in the last hunk of ip_vs_xmit.c (in the first patch). Could you check to make sure everything went in ok?

I created it for net-next on the same day because
I saw this problem. Both patches apply even on net-next from today. May be ipvs-next is outdated, net-next changes rapidly last days. If you want to push these patches in this merge window you have to update ipvs-next. If it is not possible I'll resend after 2 weeks.

Quoted 4 lines
Quoted 2 lines

ipvs-next is based on Pablo's nf-next tree.
So the timing of updating is up to him.

I just refreshed my tree. Let me know if this is what you needed.

Thanks, I'll rebase my tree.

Quoted 1 line

Please, feel free to ping me whenever you need this.

Sure, will do.