* [PATCH net-next v2 1/1] net: ipv4: Refine the ipv4_default_advmss
@ 2017-04-12 2:32 gfree.wind
2017-04-12 3:57 ` Joe Perches
0 siblings, 1 reply; 3+ messages in thread
From: gfree.wind @ 2017-04-12 2:32 UTC (permalink / raw)
To: davem, kuznet, jmorris, netdev; +Cc: Gao Feng
From: Gao Feng <fgao@ikuai8.com>
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>
---
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(-)
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 <net/flow.h>
#include <net/flow_dissector.h>
+#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..2d414b0 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -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;
}
--
1.9.1
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH net-next v2 1/1] net: ipv4: Refine the ipv4_default_advmss
2017-04-12 2:32 [PATCH net-next v2 1/1] net: ipv4: Refine the ipv4_default_advmss gfree.wind
@ 2017-04-12 3:57 ` Joe Perches
2017-04-12 4:13 ` Gao Feng
0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2017-04-12 3:57 UTC (permalink / raw)
To: gfree.wind, davem, kuznet, jmorris, netdev; +Cc: Gao Feng
On Wed, 2017-04-12 at 10:32 +0800, gfree.wind@foxmail.com wrote:
> diff --git a/net/ipv4/route.c b/net/ipv4/route.c
more trivia:
> @@ -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;
> }
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.
^ permalink raw reply [flat|nested] 3+ messages in thread
* RE: [PATCH net-next v2 1/1] net: ipv4: Refine the ipv4_default_advmss
2017-04-12 3:57 ` Joe Perches
@ 2017-04-12 4:13 ` Gao Feng
0 siblings, 0 replies; 3+ messages in thread
From: Gao Feng @ 2017-04-12 4:13 UTC (permalink / raw)
To: 'Joe Perches', davem, kuznet, jmorris, netdev; +Cc: 'Gao Feng'
> -----Original Message-----
> From: netdev-owner@vger.kernel.org [mailto:netdev-owner@vger.kernel.org]
> On Behalf Of Joe Perches
> Sent: Wednesday, April 12, 2017 11:57 AM
> To: gfree.wind@foxmail.com; davem@davemloft.net; kuznet@ms2.inr.ac.ru;
> jmorris@namei.org; netdev@vger.kernel.org
> Cc: Gao Feng <fgao@ikuai8.com>
> Subject: Re: [PATCH net-next v2 1/1] net: ipv4: Refine the
ipv4_default_advmss
>
> On Wed, 2017-04-12 at 10:32 +0800, gfree.wind@foxmail.com wrote:
> > diff --git a/net/ipv4/route.c b/net/ipv4/route.c
>
> more trivia:
>
> > @@ -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;
> > }
>
> 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.
Yes. I thought about writing it with the way you mentioned, but gave up.
But i could follow you this time.
Best Regards
Feng
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-04-12 4:14 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-12 2:32 [PATCH net-next v2 1/1] net: ipv4: Refine the ipv4_default_advmss gfree.wind
2017-04-12 3:57 ` Joe Perches
2017-04-12 4:13 ` Gao Feng
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.