From: gfree.wind@foxmail.com Subject: [PATCH net-next v3 1/1] net: ipv4: Refine the ipv4_default_advmss Date: Wed, 12 Apr 2017 12:34:03 +0800 Message-ID: <1491971643-117736-1-git-send-email-gfree.wind@foxmail.com> Cc: Gao Feng To: davem@davemloft.net, kuznet@ms2.inr.ac.ru, jmorris@namei.org, netdev@vger.kernel.org Return-path: Received: from smtpbgau1.qq.com ([54.206.16.166]:59949 "EHLO smtpbgau1.qq.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751027AbdDLEeX (ORCPT ); Wed, 12 Apr 2017 00:34:23 -0400 Sender: netdev-owner@vger.kernel.org List-ID: From: Gao Feng 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 --- v3: Simplify the codes again, per Joe v2: Use min instead of unnecessary min_t, per Joe v1: initial version include/net/ip.h | 2 ++ net/ipv4/route.c | 12 ++++-------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/include/net/ip.h b/include/net/ip.h index bf264a8..821cedc 100644 --- a/include/net/ip.h +++ b/include/net/ip.h @@ -33,6 +33,8 @@ #include #include +#define IPV4_MAX_PMTU 65535U /* RFC 2675, Section 5.1 */ + struct sock; struct inet_skb_parm { diff --git a/net/ipv4/route.c b/net/ipv4/route.c index 5e1e605..0fcc2d5 100644 --- a/net/ipv4/route.c +++ b/net/ipv4/route.c @@ -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) -- 1.9.1