net: ipv4: Refine the ipv4_default_advmss
authorGao Feng <fgao@ikuai8.com>
Wed, 12 Apr 2017 04:34:03 +0000 (12:34 +0800)
committerDavid S. Miller <davem@davemloft.net>
Thu, 13 Apr 2017 17:19:48 +0000 (13:19 -0400)
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.

Signed-off-by: Gao Feng <fgao@ikuai8.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/ip.h
net/ipv4/route.c

index bf264a8db1ce3b1b29b9a5cc9732df323154e7e5..821cedcc8e73b68af72d1918242c25d757c63d24 100644 (file)
@@ -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 {
index 5e1e60546fce7db5092c816e51ec38f6975ff0d2..0fcc2d5192bde9c1a24c0919c408dc09eef7551c 100644 (file)
@@ -1250,15 +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;
-       }
-       return advmss;
+       return min(advmss, IPV4_MAX_PMTU - header_size);
 }
 
 static unsigned int ipv4_mtu(const struct dst_entry *dst)