Skip to contentSkip to conversation

ipv6: use interface mtu for determining if packet-too-big should be send

PATCH In review Hannes Frederic Sowa 3 participants 5 messages Dec 16, 2013 – Dec 17, 2013

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ipv6: use interface mtu for determining if packet-too-big should be send

IPv6 forwarding path should also not depend on the path mtu values to judge if a packet should get dropped and an ICMP PTB should be returned.

For the accompanying change in IPv4, have a look at "ipv4: introduce ip_dst_mtu_secure and protect forwarding path against pmtu spoofing".

I needed to move in6_dev_dev around to keep ip6_dst_mtu_secure as a static inline function in the header and to keep header dependencies happy.

For the IPv4 change, see patch "ipv4: introduce ip_dst_mtu_secure and protect forwarding path against pmtu spoofing".

---
 include/net/addrconf.h     | 32 --------------------------------
 include/net/ip6_route.h    | 31 ++++++++++++++++++++++++++++---
 include/net/ipv6.h         | 32 ++++++++++++++++++++++++++++++++
 include/net/netns/ipv6.h   |  1 +
 net/ipv6/ip6_output.c      |  3 ++-
 net/ipv6/sysctl_net_ipv6.c |  8 ++++++++
 6 files changed, 71 insertions(+), 36 deletions(-)
include/net/addrconf.h +0 -32
index 66c4a44..d2db1be 100644
@@ -216,38 +216,6 @@ int inet6addr_notifier_call_chain(unsigned long val, void *v);
 void inet6_netconf_notify_devconf(struct net *net, int type, int ifindex,
 				  struct ipv6_devconf *devconf);
 
-/**
- * __in6_dev_get - get inet6_dev pointer from netdevice
- * @dev: network device
- *
- * Caller must hold rcu_read_lock or RTNL, because this function
- * does not take a reference on the inet6_dev.
- */
-static inline struct inet6_dev *__in6_dev_get(const struct net_device *dev)
-{
-	return rcu_dereference_rtnl(dev->ip6_ptr);
-}
-
-/**
- * in6_dev_get - get inet6_dev pointer from netdevice
- * @dev: network device
- *
- * This version can be used in any context, and takes a reference
- * on the inet6_dev. Callers must use in6_dev_put() later to
- * release this reference.
- */
-static inline struct inet6_dev *in6_dev_get(const struct net_device *dev)
-{
-	struct inet6_dev *idev;
-
-	rcu_read_lock();
-	idev = rcu_dereference(dev->ip6_ptr);
-	if (idev)
-		atomic_inc(&idev->refcnt);
-	rcu_read_unlock();
-	return idev;
-}
-
 static inline struct neigh_parms *__in6_dev_nd_parms_get_rcu(const struct net_device *dev)
 {
 	struct inet6_dev *idev = __in6_dev_get(dev);
include/net/ip6_route.h +28 -3
index c2626ce..7b5039d 100644
@@ -174,12 +174,37 @@ static inline bool ipv6_unicast_destination(const struct sk_buff *skb)
 
 int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *));
 
-static inline int ip6_skb_dst_mtu(struct sk_buff *skb)
+static inline unsigned int ip6_dst_mtu_secure(const struct dst_entry *dst,
+					      bool forward)
+{
+	unsigned int mtu;
+	struct inet6_dev *idev;
+	struct net *net = dev_net(dst->dev);
+
+	if (net->ipv6.sysctl.fwd_use_pmtu ||
+	    dst_metric_locked(dst, RTAX_MTU))
+		return dst_mtu(dst);
+
+	mtu = IPV6_MIN_MTU;
+	rcu_read_lock();
+	idev = __in6_dev_get(dst->dev);
+	if (idev)
+		mtu = idev->cnf.mtu6;
+	rcu_read_unlock();
+
+	return mtu;
+}
+
+static inline unsigned int ip6_skb_dst_mtu(struct sk_buff *skb)
 {
 	struct ipv6_pinfo *np = skb->sk ? inet6_sk(skb->sk) : NULL;
 
-	return (np && np->pmtudisc >= IPV6_PMTUDISC_PROBE) ?
-	       skb_dst(skb)->dev->mtu : dst_mtu(skb_dst(skb));
+	if (np && np->pmtudisc >= IPV6_PMTUDISC_PROBE) {
+		return skb_dst(skb)->dev->mtu;
+	} else {
+		bool forward = !!(IP6CB(skb)->flags & IP6SKB_FORWARDED);
+		return ip6_dst_mtu_secure(skb_dst(skb), forward);
+	}
 }
 
 static inline bool ip6_sk_accept_pmtu(const struct sock *sk)
include/net/ipv6.h +32 -0
index d0bfe3e..34e11db 100644
@@ -684,6 +684,38 @@ static inline __be32 ip6_flowlabel(const struct ipv6hdr *hdr)
 	return *(__be32 *)hdr & IPV6_FLOWLABEL_MASK;
 }
 
+/**
+ * __in6_dev_get - get inet6_dev pointer from netdevice
+ * @dev: network device
+ *
+ * Caller must hold rcu_read_lock or RTNL, because this function
+ * does not take a reference on the inet6_dev.
+ */
+static inline struct inet6_dev *__in6_dev_get(const struct net_device *dev)
+{
+	return rcu_dereference_rtnl(dev->ip6_ptr);
+}
+
+/**
+ * in6_dev_get - get inet6_dev pointer from netdevice
+ * @dev: network device
+ *
+ * This version can be used in any context, and takes a reference
+ * on the inet6_dev. Callers must use in6_dev_put() later to
+ * release this reference.
+ */
+static inline struct inet6_dev *in6_dev_get(const struct net_device *dev)
+{
+	struct inet6_dev *idev;
+
+	rcu_read_lock();
+	idev = rcu_dereference(dev->ip6_ptr);
+	if (idev)
+		atomic_inc(&idev->refcnt);
+	rcu_read_unlock();
+	return idev;
+}
+
 /*
  *	Prototypes exported by ipv6
  */
include/net/netns/ipv6.h +1 -0
index 0fb2401..05fef12 100644
@@ -19,6 +19,7 @@ struct netns_sysctl_ipv6 {
 	struct ctl_table_header *xfrm6_hdr;
 #endif
 	int bindv6only;
+	int fwd_use_pmtu;
 	int flush_delay;
 	int ip6_rt_max_size;
 	int ip6_rt_gc_min_interval;
net/ipv6/ip6_output.c +2 -1
index bc4e1bc..668a567 100644
@@ -441,7 +441,8 @@ int ip6_forward(struct sk_buff *skb)
 		}
 	}
 
-	mtu = dst_mtu(dst);
+	IP6CB(skb)->flags |= IP6SKB_FORWARDED;
+	mtu = ip6_dst_mtu_secure(dst, true);
 	if (mtu < IPV6_MIN_MTU)
 		mtu = IPV6_MIN_MTU;
 
net/ipv6/sysctl_net_ipv6.c +8 -0
index 107b2f1..ac0e838 100644
@@ -24,6 +24,13 @@ static struct ctl_table ipv6_table_template[] = {
 		.mode		= 0644,
 		.proc_handler	= proc_dointvec
 	},
+	{
+		.procname	= "forward_use_pmtu",
+		.data		= &init_net.ipv6.sysctl.fwd_use_pmtu,
+		.maxlen		= sizeof(int),
+		.mode		= 0644,
+		.proc_handler	= proc_dointvec
+	},
 	{ }
 };
 
@@ -51,6 +58,7 @@ static int __net_init ipv6_sysctl_net_init(struct net *net)
 	if (!ipv6_table)
 		goto out;
 	ipv6_table[0].data = &net->ipv6.sysctl.bindv6only;
+	ipv6_table[1].data = &net->ipv6.sysctl.fwd_use_pmtu;
 
 	ipv6_route_table = ipv6_route_sysctl_init(net);
 	if (!ipv6_route_table)
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 6 lines · Hannes Frederic Sowa

IPv6 forwarding path should also not depend on the path mtu values to judge if a packet should get dropped and an ICMP PTB should be returned.

For the accompanying change in IPv4, have a look at "ipv4: introduce ip_dst_mtu_secure and protect forwarding path against pmtu spoofing".

No commit sha1 (truncated to 12 digits) ?

Quoted 5 lines

I needed to move in6_dev_dev around to keep ip6_dst_mtu_secure as a static inline function in the header and to keep header dependencies happy.

For the IPv4 change, see patch "ipv4: introduce ip_dst_mtu_secure and protect forwarding path against pmtu spoofing".

Redundant sentence ?

And no documentation for the new setting.

git grep -n forward_use_pmtu Documentation

Thanks

#2 lore raw
Quoted 9 lines · Eric Dumazet
Quoted 6 lines · Hannes Frederic Sowa

IPv6 forwarding path should also not depend on the path mtu values to judge if a packet should get dropped and an ICMP PTB should be returned.

For the accompanying change in IPv4, have a look at "ipv4: introduce ip_dst_mtu_secure and protect forwarding path against pmtu spoofing".

No commit sha1 (truncated to 12 digits) ?

The patch is not yet committed.

Quoted 7 lines
Quoted 5 lines

I needed to move in6_dev_dev around to keep ip6_dst_mtu_secure as a static inline function in the header and to keep header dependencies happy.

For the IPv4 change, see patch "ipv4: introduce ip_dst_mtu_secure and protect forwarding path against pmtu spoofing".

Redundant sentence ?

Hehe, I have no idea how that happend. :)

Quoted 3 lines

And no documentation for the new setting.

git grep -n forward_use_pmtu Documentation

The IPv4 patch introduces the documentation for the flag but is in the wrong section (IPv4). I'll send a v2 later today and will duplicate it for the IPv6 section.

Thanks,

Hannes

maintainer
#3 lore raw

From: Hannes Frederic Sowa <[email protected]>
Date: Mon, 16 Dec 2013 15:01:24 +0100

Quoted 5 lines · Eric Dumazet
Quoted 4 lines · Hannes Frederic Sowa
Quoted 3 lines

IPv6 forwarding path should also not depend on the path mtu values to judge if a packet should get dropped and an ICMP PTB should be returned.

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

For the accompanying change in IPv4, have a look at "ipv4: introduce ip_dst_mtu_secure and protect forwarding path against pmtu spoofing".

No commit sha1 (truncated to 12 digits) ?

The patch is not yet committed.

It's confusing to propose an ipv6 version of an ipv4 patch that hasn't been integrated yet, please don't do this.

I would suggest instead fo post the ipv4 and ipv6 variants together when you want me to consider applying them, or to provide them as a unit for review.

#4 lore raw
Quoted 12 lines · David Miller

From: Hannes Frederic Sowa <[email protected]>
Date: Mon, 16 Dec 2013 15:01:24 +0100

Quoted 9 lines · Eric Dumazet
Quoted 8 lines · Hannes Frederic Sowa
Quoted 6 lines

IPv6 forwarding path should also not depend on the path mtu values to judge if a packet should get dropped and an ICMP PTB should be returned.

For the accompanying change in IPv4, have a look at "ipv4: introduce ip_dst_mtu_secure and protect forwarding path against pmtu spoofing".

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

No commit sha1 (truncated to 12 digits) ?

The patch is not yet committed.

It's confusing to propose an ipv6 version of an ipv4 patch that hasn't been integrated yet, please don't do this.

Ok, I'll do next time, sorry. I saw you still consider the IPv4 one, so I'll just wait and resubmit this one as soon as I have feedback.