Skip to contentSkip to conversation

net: ip/tnl: Set iph->id only when don't fragment is not set

PATCH In review Oliver Herms 3 participants 9 messages Nov 24, 2019 – Nov 27, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 net: ip/tnl: Set iph->id only when don't fragment is not set

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. From RFC 6864 "Updated Specification of the IPv4 ID Field" section 4.1:
"The IPv4 ID field MUST NOT be used for purposes other than fragmentation and reassembly."
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.
For security reason this patch will set ID to zero when ID is not needed to prevent leaking random information.

---
Changes in v2:
- Add source of assertion into commit message.
- Correct check of DF flag.
- Set iph->id to 0 when DF if not set to avoid leaking information.

 net/ipv4/ip_tunnel_core.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
net/ipv4/ip_tunnel_core.c +5 -1
index 1452a97914a0..ea12c8cc9e83 100644
@@ -73,7 +73,11 @@ 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 (likely((iph->frag_off & htons(IP_DF)) == htons(IP_DF)))
+		iph->id = 0;
+	else
+		__ip_select_ident(net, iph, skb_shinfo(skb)->gso_segs ?: 1);
 
 	err = ip_local_out(net, sk, skb);
 
Signature · 1 line
2.19.1
maintainer
#1 lore raw

From: Oliver Herms <[email protected]>
Date: Sun, 24 Nov 2019 14:24:18 +0100

Quoted 1 line

From RFC 6864 "Updated Specification of the IPv4 ID Field" section 4.1:

Just reading the abstract of this RFC I cannot take it seriously:

This document updates the specification of the IPv4 ID field in RFCs 791, 1122, and 2003 to more closely reflect current practice...

"more closely reflect current practice" ?!?!

That statement is a joke right?

Linux generates the bulk of the traffic on the internet and we've had the current behavior of the ID field for decades.

Therefore, I don't think even the premise of this document is valid.

These are all red flags to me, and I think we should keep the current behavior.

I'm not applying your patch, sorry.

#2 lore raw

Hi Dave,

Quoted 18 lines · David Miller

From: Oliver Herms <[email protected]>
Date: Sun, 24 Nov 2019 14:24:18 +0100

Quoted 1 line

From RFC 6864 "Updated Specification of the IPv4 ID Field" section 4.1:

Just reading the abstract of this RFC I cannot take it seriously:

This document updates the specification of the IPv4 ID field in RFCs 791, 1122, and 2003 to more closely reflect current practice...

"more closely reflect current practice" ?!?!

That statement is a joke right?

Linux generates the bulk of the traffic on the internet and we've had the current behavior of the ID field for decades.

Quoted 7 lines

Therefore, I don't think even the premise of this document is valid.

These are all red flags to me, and I think we should keep the current behavior.

I'm not applying your patch, sorry.

I totally understand your argument.

What do you think about making this configurable via sysctl and make the current behavior the default? I would also like to make this configurable for other payload types like TCP and UDP. IMHO there the ID is unnecessary, too, when DF is set.

Would you be willing to merge a patch that offers this?

Thanks
Oliver

maintainer
#3 lore raw

From: Oliver Herms <[email protected]>
Date: Tue, 26 Nov 2019 20:10:52 +0100

Quoted 1 line

Would you be willing to merge a patch that offers this?

No.

There is lots of precendence for incrementing the ID, look at SLIP compression:

	deltaS = ntohs(ip->id) - ntohs(cs->cs_ip.id);
	if(deltaS != 1){
		cp = encode(cp,deltaS);
		changes |= NEW_I;
	}

That's just one example, it won't compress unless the ID field is (unconditionally) incrementing.

The RFC being discussed here is poorly constructed and is founded on a false basis of reality. It's the usual tone deaf IETF stuff... and Linux will not participate.

Thanks.

#4 lore raw
In reply to Oliver Herms
Quoted 5 lines · Oliver Herms

What do you think about making this configurable via sysctl and make the current behavior the default? I would also like to make this configurable for other payload types like TCP and UDP. IMHO there the ID is unnecessary, too, when DF is set.

Certainly not.

I advise you to look at GRO layer (at various stages, depending on linux version)

You can not 'optimize [1]' the sender and break receivers ( including old ones )

[1] Look at ip_select_ident_segs() : the per-socket id generator makes ID generation quite low cost, there is no real issue here.

#5 lore raw

Hi everyone,

Quoted 9 lines · Eric Dumazet
Quoted 5 lines · Oliver Herms

What do you think about making this configurable via sysctl and make the current behavior the default? I would also like to make this configurable for other payload types like TCP and UDP. IMHO there the ID is unnecessary, too, when DF is set.

Quoted 9 lines

Certainly not.

I advise you to look at GRO layer (at various stages, depending on linux version)

You can not 'optimize [1]' the sender and break receivers ( including old ones )

[1] Look at ip_select_ident_segs() : the per-socket id generator makes ID generation quite low cost, there is no real issue here.

ip_select_ident_segs() is not the issue. The issue is with __ip_select_ident that calls ip_idents_reserve. That consumes significant amount of CPU time here while not adding any value (for my use case of company internal IPIP tunneling in a well defined environment to be fair).

Here is a flame graph: https://tinyurl.com/s9qv9fx
I'm curious for ideas on how to make this more efficient.
Using a simple incrementation here, as with sockets, would solve my problem well enough.

Thoughts?

Thanks
Oliver

#6 lore raw
Quoted 27 lines · Oliver Herms

Hi everyone,

Quoted 9 lines · Eric Dumazet
Quoted 5 lines · Oliver Herms

What do you think about making this configurable via sysctl and make the current behavior the default? I would also like to make this configurable for other payload types like TCP and UDP. IMHO there the ID is unnecessary, too, when DF is set.

Quoted 9 lines

Certainly not.

I advise you to look at GRO layer (at various stages, depending on linux version)

You can not 'optimize [1]' the sender and break receivers ( including old ones )

[1] Look at ip_select_ident_segs() : the per-socket id generator makes ID generation quite low cost, there is no real issue here.

ip_select_ident_segs() is not the issue. The issue is with __ip_select_ident that calls ip_idents_reserve. That consumes significant amount of CPU time here while not adding any value (for my use case of company internal IPIP tunneling in a well defined environment to be fair).

Quoted 6 lines

Here is a flame graph: https://tinyurl.com/s9qv9fx
I'm curious for ideas on how to make this more efficient.
Using a simple incrementation here, as with sockets, would solve my problem well enough.

Thoughts?

Oliver, TCP flows do not call __ip_select_ident()

Pleas do not touch TCP payload.

Thank you.

#7 lore raw
In reply to Oliver Herms
Quoted 2 lines · Oliver Herms

Using a simple incrementation here, as with sockets, would solve my problem well enough.

I have to ask : Are you aware that linux is SMP OS ?

If on a mostly idle host, two packets need a different ID, using a " simple incrementation" wont fit the need.

sockets are protected against concurrent increments by their lock.

#8 lore raw
Quoted 6 lines · Eric Dumazet
Quoted 2 lines · Oliver Herms

Using a simple incrementation here, as with sockets, would solve my problem well enough.

Quoted 7 lines

I have to ask : Are you aware that linux is SMP OS ?

If on a mostly idle host, two packets need a different ID, using a " simple incrementation" wont fit the need.

sockets are protected against concurrent increments by their lock.

I know and I'm not going to mess around with TCP.
I've double checked and found that for non IP tunnel traffic (UDP, TCP, etc.) the cheap function ip_select_ident_segs() is being used. That is absolutely fine. Nothing to optimize here.

For IP tunnels __ip_select_ident is being called.
And that one is way more expensive than ip_select_ident_segs().

ip_select_ident_segs() increments a counter (yes, I'm aware it is protected by lock). If somehow __ip_select_ident could be refactored to work in a similar fashion that would solve my problem.

Thanks
Oliver