netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ip/tnl: Set iph->id only when don't fragment is not set
@ 2019-11-23 14:58 Oliver Herms
  2019-11-23 17:53 ` Eric Dumazet
  0 siblings, 1 reply; 4+ messages in thread
From: Oliver Herms @ 2019-11-23 14:58 UTC (permalink / raw)
  To: davem, kuznet, yoshfuji; +Cc: netdev

In IPv4 the identification field ensures that fragments of different datagrams
are not mixed by the receiver. Packets with Don't Fragment (DF) flag set are not
to be fragmented in transit and thus don't need an identification.
Calculating the identification takes significant CPU time.
This patch will increase IP tunneling performance by ~10% unless DF is not set.
However, DF is set by default which is best practice.

Signed-off-by: Oliver Herms <oliver.peter.herms@gmail.com>
---
 net/ipv4/ip_tunnel_core.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
index 1452a97914a0..8636c1e0e7b7 100644
--- a/net/ipv4/ip_tunnel_core.c
+++ b/net/ipv4/ip_tunnel_core.c
@@ -73,7 +73,9 @@ void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
 	iph->daddr	=	dst;
 	iph->saddr	=	src;
 	iph->ttl	=	ttl;
-	__ip_select_ident(net, iph, skb_shinfo(skb)->gso_segs ?: 1);
+
+	if (unlikely((iph->frag_off & htons(IP_DF)) == false))
+		__ip_select_ident(net, iph, skb_shinfo(skb)->gso_segs ?: 1);
 
 	err = ip_local_out(net, sk, skb);
 
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: ip/tnl: Set iph->id only when don't fragment is not set
  2019-11-23 14:58 [PATCH] net: ip/tnl: Set iph->id only when don't fragment is not set Oliver Herms
@ 2019-11-23 17:53 ` Eric Dumazet
  2019-11-23 18:29   ` Joe Perches
  2019-11-24 13:02   ` Oliver Herms
  0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2019-11-23 17:53 UTC (permalink / raw)
  To: Oliver Herms, davem, kuznet, yoshfuji; +Cc: netdev



On 11/23/19 6:58 AM, Oliver Herms wrote:
> In IPv4 the identification field ensures that fragments of different datagrams
> are not mixed by the receiver. Packets with Don't Fragment (DF) flag set are not
> to be fragmented in transit and thus don't need an identification.

Official sources for this assertion please, so that we can double check if you
implemented the proper avoidance ?

> Calculating the identification takes significant CPU time.
> This patch will increase IP tunneling performance by ~10% unless DF is not set.
> However, DF is set by default which is best practice.
> 
> Signed-off-by: Oliver Herms <oliver.peter.herms@gmail.com>
> ---
>  net/ipv4/ip_tunnel_core.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
> index 1452a97914a0..8636c1e0e7b7 100644
> --- a/net/ipv4/ip_tunnel_core.c
> +++ b/net/ipv4/ip_tunnel_core.c
> @@ -73,7 +73,9 @@ void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
>  	iph->daddr	=	dst;
>  	iph->saddr	=	src;
>  	iph->ttl	=	ttl;
> -	__ip_select_ident(net, iph, skb_shinfo(skb)->gso_segs ?: 1);
> +
> +	if (unlikely((iph->frag_off & htons(IP_DF)) == false))

This unlikely() seems wrong to me.

You do not know what are the odds of IP_DF being set or not.



> +		__ip_select_ident(net, iph, skb_shinfo(skb)->gso_segs ?: 1);
>  
>  	err = ip_local_out(net, sk, skb);
>  
> 

So we are going to send 2 bytes with garbage if we do not call __ip_select_ident()

This would cause various security threats, since the garbage might reveal a secret.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: ip/tnl: Set iph->id only when don't fragment is not set
  2019-11-23 17:53 ` Eric Dumazet
@ 2019-11-23 18:29   ` Joe Perches
  2019-11-24 13:02   ` Oliver Herms
  1 sibling, 0 replies; 4+ messages in thread
From: Joe Perches @ 2019-11-23 18:29 UTC (permalink / raw)
  To: Eric Dumazet, Oliver Herms, davem, kuznet, yoshfuji; +Cc: netdev

On Sat, 2019-11-23 at 09:53 -0800, Eric Dumazet wrote:
> 
> On 11/23/19 6:58 AM, Oliver Herms wrote:
> > In IPv4 the identification field ensures that fragments of different datagrams
> > are not mixed by the receiver. Packets with Don't Fragment (DF) flag set are not
> > to be fragmented in transit and thus don't need an identification.
> 
> Official sources for this assertion please, so that we can double check if you
> implemented the proper avoidance ?
> 
> > Calculating the identification takes significant CPU time.
> > This patch will increase IP tunneling performance by ~10% unless DF is not set.
> > However, DF is set by default which is best practice.
> > 
> > Signed-off-by: Oliver Herms <oliver.peter.herms@gmail.com>
> > ---
> >  net/ipv4/ip_tunnel_core.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> > 
> > diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
> > index 1452a97914a0..8636c1e0e7b7 100644
> > --- a/net/ipv4/ip_tunnel_core.c
> > +++ b/net/ipv4/ip_tunnel_core.c
> > @@ -73,7 +73,9 @@ void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
> >  	iph->daddr	=	dst;
> >  	iph->saddr	=	src;
> >  	iph->ttl	=	ttl;
> > -	__ip_select_ident(net, iph, skb_shinfo(skb)->gso_segs ?: 1);
> > +
> > +	if (unlikely((iph->frag_off & htons(IP_DF)) == false))
> 
> This unlikely() seems wrong to me.

as does the comparison to false.



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] net: ip/tnl: Set iph->id only when don't fragment is not set
  2019-11-23 17:53 ` Eric Dumazet
  2019-11-23 18:29   ` Joe Perches
@ 2019-11-24 13:02   ` Oliver Herms
  1 sibling, 0 replies; 4+ messages in thread
From: Oliver Herms @ 2019-11-24 13:02 UTC (permalink / raw)
  To: Eric Dumazet, davem, kuznet, yoshfuji; +Cc: netdev

On 23.11.19 18:53, Eric Dumazet wrote:
> Official sources for this assertion please, so that we can double check if you
> implemented the proper avoidance ?
From RFC 6864 Section 4.1:
"The IPv4 ID field MUST NOT be used for purposes other than
      fragmentation and reassembly."

>>  net/ipv4/ip_tunnel_core.c | 4 +++-
>>  1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/net/ipv4/ip_tunnel_core.c b/net/ipv4/ip_tunnel_core.c
>> index 1452a97914a0..8636c1e0e7b7 100644
>> --- a/net/ipv4/ip_tunnel_core.c
>> +++ b/net/ipv4/ip_tunnel_core.c
>> @@ -73,7 +73,9 @@ void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb,
>>  	iph->daddr	=	dst;
>>  	iph->saddr	=	src;
>>  	iph->ttl	=	ttl;
>> -	__ip_select_ident(net, iph, skb_shinfo(skb)->gso_segs ?: 1);
>> +
>> +	if (unlikely((iph->frag_off & htons(IP_DF)) == false))
> 
> This unlikely() seems wrong to me.
> 
> You do not know what are the odds of IP_DF being set or not.
Right. I'll send a corrected patch.

>> +		__ip_select_ident(net, iph, skb_shinfo(skb)->gso_segs ?: 1);
> So we are going to send 2 bytes with garbage if we do not call __ip_select_ident()
> 
> This would cause various security threats, since the garbage might reveal a secret.
So we should set it to zero then.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-11-24 13:02 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-23 14:58 [PATCH] net: ip/tnl: Set iph->id only when don't fragment is not set Oliver Herms
2019-11-23 17:53 ` Eric Dumazet
2019-11-23 18:29   ` Joe Perches
2019-11-24 13:02   ` Oliver Herms

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).