Skip to contentSkip to conversation

net: ipv4: Refine the ipv4_default_advmss

PATCH Superseded [email protected] 2 participants 3 messages Apr 12, 2017

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: ipv4: Refine the ipv4_default_advmss

From: Gao Feng <[email protected]>

1. Don't get the metric RTAX_ADVMSS of dst.
There are two reasons.
1) Its caller dst_metric_advmss has already invoke dst_metric_advmss before invoke default_advmss.
2) The ipv4_default_advmss is used to get the default mss, it should not try to get the metric like ip6_default_advmss.

2. Use sizeof(tcphdr)+sizeof(iphdr) instead of literal 40.

3. Define one new macro IPV4_MAX_PMTU instead of 65535 according to RFC 2675, section 5.1.

---
v2: Use min instead of unnecessary min_t, per Joe
v1: initial version

 include/net/ip.h |  2 ++
 net/ipv4/route.c | 11 ++++-------
 2 files changed, 6 insertions(+), 7 deletions(-)
include/net/ip.h +2 -0
index bf264a8..821cedc 100644
@@ -33,6 +33,8 @@
 #include <net/flow.h>
 #include <net/flow_dissector.h>
 
+#define IPV4_MAX_PMTU		65535U		/* RFC 2675, Section 5.1 */
+
 struct sock;
 
 struct inet_skb_parm {
net/ipv4/route.c +4 -7
index 5e1e605..2d414b0 100644
@@ -1250,14 +1250,11 @@ static void set_class_tag(struct rtable *rt, u32 tag)
 
 static unsigned int ipv4_default_advmss(const struct dst_entry *dst)
 {
-	unsigned int advmss = dst_metric_raw(dst, RTAX_ADVMSS);
+	unsigned int header_size = sizeof(struct tcphdr) + sizeof(struct iphdr);
+	unsigned int advmss = max_t(unsigned int, dst->dev->mtu - header_size,
+				    ip_rt_min_advmss);
 
-	if (advmss == 0) {
-		advmss = max_t(unsigned int, dst->dev->mtu - 40,
-			       ip_rt_min_advmss);
-		if (advmss > 65535 - 40)
-			advmss = 65535 - 40;
-	}
+	advmss = min(advmss, IPV4_MAX_PMTU - header_size);
 	return advmss;
 }
 
Signature · 1 line
1.9.1
#1 lore raw

net/ipv4/route.c

Quoted 1 line · On Wed, 2017-04-12 at 10:32 +0800, [email protected] wrote:
net/ipv4/route.c +0 -0

more trivia:

Quoted 8 lines
net/ipv4/route.c +3 -1
@@ -1250,14 +1250,11 @@ static void set_class_tag(struct rtable *rt, u32 tag)
 
 static unsigned int ipv4_default_advmss(const struct dst_entry *dst)
 {
-	unsigned int advmss = dst_metric_raw(dst, RTAX_ADVMSS);
+	unsigned int header_size = sizeof(struct tcphdr) + sizeof(struct iphdr);
+	unsigned int advmss = max_t(unsigned int, dst->dev->mtu - header_size,
+				    ip_rt_min_advmss);

net/ipv4/route.c static void set_class_tag(struct rtable *rt, u32 tag) · line 1259

Quoted 10 lines
net/ipv4/route.c +1 -6
 
-	if (advmss == 0) {
-		advmss = max_t(unsigned int, dst->dev->mtu - 40,
-			       ip_rt_min_advmss);
-		if (advmss > 65535 - 40)
-			advmss = 65535 - 40;
-	}
+	advmss = min(advmss, IPV4_MAX_PMTU - header_size);
 	return advmss;
 }

This would probably be simpler to read as:

	return min(advmss, IPV4_MAX_PMTU - header_size);

though it's almost certain that the compiler emits identical object code.

author
#2 lore raw
Quoted 8 lines

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Joe Perches
Sent: Wednesday, April 12, 2017 11:57 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Cc: Gao Feng <[email protected]>
Subject: Re: [PATCH net-next v2 1/1] net: ipv4: Refine the

ipv4_default_advmss

Quoted 6 lines · On Wed, 2017-04-12 at 10:32 +0800, [email protected] wrote:

net/ipv4/route.c

Quoted 1 line
net/ipv4/route.c +0 -0

more trivia:

Quoted 7 lines

net/ipv4/route.c static void set_class_tag(struct rtable *rt, · line 1254

Quoted 7 lines
net/ipv4/route.c +1 -1
@@ -1250,14 +1250,11 @@ static void set_class_tag(struct rtable *rt,
 u32 tag)
 
 static unsigned int ipv4_default_advmss(const struct dst_entry *dst)
 {
-	unsigned int advmss = dst_metric_raw(dst, RTAX_ADVMSS);
+	unsigned int header_size = sizeof(struct tcphdr) + sizeof(struct

iphdr);

Quoted 1 line

net/ipv4/route.c static void set_class_tag(struct rtable *rt, · line 1255

Quoted 1 line
net/ipv4/route.c +1 -0
+	unsigned int advmss = max_t(unsigned int, dst->dev->mtu -

header_size,

Quoted 14 lines

net/ipv4/route.c static void set_class_tag(struct rtable *rt, u32 tag) · line 1259

Quoted 11 lines
net/ipv4/route.c +2 -6
+				    ip_rt_min_advmss);
 
-	if (advmss == 0) {
-		advmss = max_t(unsigned int, dst->dev->mtu - 40,
-			       ip_rt_min_advmss);
-		if (advmss > 65535 - 40)
-			advmss = 65535 - 40;
-	}
+	advmss = min(advmss, IPV4_MAX_PMTU - header_size);
 	return advmss;
 }

This would probably be simpler to read as:

Quoted 3 lines
	return min(advmss, IPV4_MAX_PMTU - header_size);

though it's almost certain that the compiler emits identical object code.

Yes. I thought about writing it with the way you mentioned, but gave up. But i could follow you this time.

Best Regards
Feng