net: ip/tnl: Set iph->id only when don't fragment is not set
Subsystems (3)
PATCH 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. 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.
--- net/ipv4/ip_tunnel_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
net/ipv4/ip_tunnel_core.c +3 -1
@@ -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);
Signature · 1 line
2.19.1
Quoted 3 lines · Oliver Herms
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 ?
Quoted 14 lines
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 <[email protected]>--- net/ipv4/ip_tunnel_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/ipv4/ip_tunnel_core.c +0
-0
net/ipv4/ip_tunnel_core.c void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb, · line 77
Quoted 6 lines
net/ipv4/ip_tunnel_core.c +2
-1@@ -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.
net/ipv4/ip_tunnel_core.c void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb, · line 81
Quoted 5 lines
net/ipv4/ip_tunnel_core.c +1
-0+__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.
Quoted 18 lines · Eric Dumazet
Quoted 3 lines · Oliver Herms
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 ?
Quoted 9 lines
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 <[email protected]>--- net/ipv4/ip_tunnel_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Quoted 13 lines
net/ipv4/ip_tunnel_core.c void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb, · line 77
Quoted 11 lines
net/ipv4/ip_tunnel_core.c +2
-1@@ -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.
Quoted 2 lines · Eric Dumazet
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."
Quoted 17 lines
Quoted 8 lines
net/ipv4/ip_tunnel_core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)net/ipv4/ip_tunnel_core.c +0
-0net/ipv4/ip_tunnel_core.c void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb, · line 77
Quoted 6 lines
net/ipv4/ip_tunnel_core.c +2
-1@@ -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.
Quoted 1 line
You do not know what are the odds of
IP_DFbeing set or not.
Right. I'll send a corrected patch.
Quoted 4 lines
net/ipv4/ip_tunnel_core.c void iptunnel_xmit(struct sock *sk, struct rtable *rt, struct sk_buff *skb, · line 78
Quoted 1 line
net/ipv4/ip_tunnel_core.c +1
-0+__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.