net-gro: Prepare GRO stack for the upcoming tunneling support
Subsystems (4)
PATCH v2 1/1 net-gro: Prepare GRO stack for the upcoming tunneling support
From: Jerry Chu <[email protected]>
This patch modifies the GRO stack to avoid the use of "network_header" and associated macros like ip_hdr() and ipv6_hdr() in order to allow an arbitary number of IP hdrs (v4 or v6) to be used in the encapsulation chain. This lays the foundation for various IP tunneling support (IP-in-IP, GRE, VXLAN, SIT,...) to be added later.
With this patch, the GRO stack traversing now is mostly based on skb_gro_offset rather than special hdr offsets saved in skb (e.g., skb->network_header). As a result all but the top layer (i.e., the the transport layer) must have hdrs of the same length in order for a pkt to be considered for aggregation. Therefore when adding a new encap layer (e.g., for tunneling), one must check and skip flows (e.g., by setting NAPI_GRO_CB(p)->same_flow to 0) that have a different hdr length.
Note that unlike the network header, the transport header can and will continue to be set by the GRO code since there will be at most one "transport layer" in the encap chain.
--- include/linux/netdevice.h | 2 +- include/net/tcp.h | 1 + net/core/dev.c | 76 ++++++++++++++++------------------------------- net/ipv4/af_inet.c | 26 +++++++++++----- net/ipv4/tcp_offload.c | 28 ++++++++++------- net/ipv6/ip6_offload.c | 64 +++++++++++++++++++++++++++++---------- net/ipv6/tcpv6_offload.c | 10 +++---- 7 files changed, 117 insertions(+), 90 deletions(-)
include/linux/netdevice.h +1 -1
@@ -1673,7 +1673,7 @@ struct offload_callbacks {int (*gso_send_check)(struct sk_buff *skb);struct sk_buff **(*gro_receive)(struct sk_buff **head,struct sk_buff *skb); -int (*gro_complete)(struct sk_buff *skb); +int (*gro_complete)(struct sk_buff *skb,int nhoff); };struct packet_offload {
include/net/tcp.h +1 -0
@@ -1549,6 +1549,7 @@ void tcp_v4_destroy_sock(struct sock *sk);struct sk_buff *tcp_gso_segment (struct sk_buff *skb,netdev_features_t features);struct sk_buff **tcp_gro_receive (struct sk_buff **head,struct sk_buff *skb); +int __tcp_gro_complete (struct sk_buff *skb,struct tcphdr *th);int tcp_gro_complete (struct sk_buff *skb);void __tcp_v4_send_check (struct sk_buff *skb,__be32 saddr,__be32 daddr);
net/core/dev.c +25 -51
125 lines not on this page · raw message
net/ipv4/af_inet.c +19 -7
@@ -1377,8 +1377,12 @@ static struct sk_buff **inet_gro_receive(struct sk_buff **head,if (!NAPI_GRO_CB (p)->same_flow)continue ; - iph2 =ip_hdr (p); - + iph2 = (struct iphdr *)(p->data + off); +/* The above works because, with the exception of the top +* (inner most) layer, we only aggregate pkts with the same +* hdr length so all the hdrs we'll need to verify will start +* at the same offset. +*/ if ((iph->protocol ^ iph2->protocol) | ((__force u32 )iph->saddr ^ (__force u32 )iph2->saddr) | ((__force u32 )iph->daddr ^ (__force u32 )iph2->daddr)) {
@@ -1397,8 +1401,12 @@ static struct sk_buff **inet_gro_receive(struct sk_buff **head, }NAPI_GRO_CB (skb)->flush |= flush; +skb_set_network_header (skb, off); +/* The above will be needed by the transport layer if there is one +* immediately following this IP hdr. +*/ +skb_gro_pull (skb,sizeof (*iph)); -skb_set_transport_header (skb,skb_gro_offset (skb)); pp = ops->callbacks.gro_receive (head, skb);
@@ -1411,10 +1419,10 @@ out:return pp; } -static int inet_gro_complete (struct sk_buff *skb) +static int inet_gro_complete (struct sk_buff *skb,int nhoff) { -__be16 newlen =htons (skb->len -skb_network_offset (skb)); -struct iphdr *iph =ip_hdr (skb); +__be16 newlen =htons (skb->len - nhoff); +struct iphdr *iph = (struct iphdr *)(skb->data + nhoff);const struct net_offload *ops;int proto = iph->protocol;int err = -ENOSYS ;
@@ -1427,7 +1435,11 @@ static int inet_gro_complete(struct sk_buff *skb)if (WARN_ON (!ops || !ops->callbacks.gro_complete)) goto out_unlock; - err = ops->callbacks.gro_complete (skb); +/* Only need to add sizeof(*iph) to get to the next hdr below +* because any hdr with option will have been flushed in +* inet_gro_receive(). +*/ + err = ops->callbacks.gro_complete (skb, nhoff +sizeof (*iph)); out_unlock:rcu_read_unlock ();
net/ipv4/tcp_offload.c +17 -11
@@ -175,6 +175,7 @@ struct sk_buff **tcp_gro_receive(struct sk_buff **head, struct sk_buff *skb) goto out; } +skb_set_transport_header (skb, off);skb_gro_pull (skb, thlen); len =skb_gro_len (skb);
@@ -184,7 +185,7 @@ struct sk_buff **tcp_gro_receive(struct sk_buff **head, struct sk_buff *skb)if (!NAPI_GRO_CB (p)->same_flow)continue ; - th2 =tcp_hdr (p); + th2 = (struct tcphdr *)(p->data + off);if (*(u32 *)&th->source ^ *(u32 *)&th2->source) {NAPI_GRO_CB (p)->same_flow =0 ;
@@ -217,7 +218,7 @@ found: } p = *head; - th2 =tcp_hdr (p); + th2 = (struct tcphdr *)(p->data + off);tcp_flag_word (th2) |= flags & (TCP_FLAG_FIN |TCP_FLAG_PSH ); out_check_final:
@@ -236,11 +237,9 @@ out: }EXPORT_SYMBOL (tcp_gro_receive); -int tcp_gro_complete (struct sk_buff *skb) +int __tcp_gro_complete (struct sk_buff *skb,struct tcphdr *th) { -struct tcphdr *th =tcp_hdr (skb); - - skb->csum_start =skb_transport_header (skb) - skb->head; + skb->csum_start = (unsigned char *)th - skb->head; skb->csum_offset = offsetof(struct tcphdr , check); skb->ip_summed =CHECKSUM_PARTIAL ;
@@ -251,6 +250,12 @@ int tcp_gro_complete(struct sk_buff *skb)return 0 ; } +EXPORT_SYMBOL (__tcp_gro_complete); + +int tcp_gro_complete (struct sk_buff *skb) +{ +return __tcp_gro_complete (skb,tcp_hdr (skb)); +}EXPORT_SYMBOL (tcp_gro_complete);static int tcp_v4_gso_send_check (struct sk_buff *skb)
@@ -272,6 +277,7 @@ static int tcp_v4_gso_send_check(struct sk_buff *skb)static struct sk_buff **tcp4_gro_receive (struct sk_buff **head,struct sk_buff *skb) { +/* Use the IP hdr immediately proceeding for this transport */ const struct iphdr *iph =skb_gro_network_header (skb);__wsum wsum;
@@ -303,16 +309,16 @@ skip_csum:return tcp_gro_receive (head, skb); } -static int tcp4_gro_complete (struct sk_buff *skb) +static int tcp4_gro_complete (struct sk_buff *skb,int thoff) {const struct iphdr *iph =ip_hdr (skb); -struct tcphdr *th =tcp_hdr (skb); +struct tcphdr *th = (struct tcphdr *)(skb->data + thoff); - th->check = ~tcp_v4_check (skb->len -skb_transport_offset (skb), - iph->saddr, iph->daddr,0 ); + th->check = ~tcp_v4_check (skb->len - thoff, iph->saddr, + iph->daddr,0 );skb_shinfo (skb)->gso_type =SKB_GSO_TCPV4 ; -return tcp_gro_complete (skb); +return __tcp_gro_complete (skb, th); }static const struct net_offload tcpv4_offload = {
net/ipv6/ip6_offload.c +49 -15
118 lines not on this page · raw message
net/ipv6/tcpv6_offload.c +5 -5
@@ -66,16 +66,16 @@ skip_csum:return tcp_gro_receive (head, skb); } -static int tcp6_gro_complete (struct sk_buff *skb) +static int tcp6_gro_complete (struct sk_buff *skb,int thoff) {const struct ipv6hdr *iph =ipv6_hdr (skb); -struct tcphdr *th =tcp_hdr (skb); +struct tcphdr *th = (struct tcphdr *)(skb->data + thoff); - th->check = ~tcp_v6_check (skb->len -skb_transport_offset (skb), - &iph->saddr, &iph->daddr,0 ); + th->check = ~tcp_v6_check (skb->len - thoff, &iph->saddr, + &iph->daddr,0 );skb_shinfo (skb)->gso_type =SKB_GSO_TCPV6 ; -return tcp_gro_complete (skb); +return __tcp_gro_complete (skb, th); }static const struct net_offload tcpv6_offload = {
Signature · 1 line
1.8.5.1
Quoted 11 lines · H.K. Jerry Chu
net/ipv4/tcp_offload.c +2
-4-int tcp_gro_complete (struct sk_buff *skb) +int __tcp_gro_complete (struct sk_buff *skb,struct tcphdr *th) { -struct tcphdr *th =tcp_hdr (skb); - - skb->csum_start =skb_transport_header (skb) - skb->head; + skb->csum_start = (unsigned char *)th - skb->head; skb->csum_offset = offsetof(struct tcphdr , check); skb->ip_summed =CHECKSUM_PARTIAL ;
net/ipv4/tcp_offload.c int tcp_gro_complete(struct sk_buff *skb) · line 258
Quoted 9 lines
net/ipv4/tcp_offload.c +6
-0@@ -251,6 +250,12 @@ int tcp_gro_complete(struct sk_buff *skb)return 0 ; } +EXPORT_SYMBOL (__tcp_gro_complete); + +int tcp_gro_complete (struct sk_buff *skb) +{ +return __tcp_gro_complete (skb,tcp_hdr (skb)); +}
I have no idea why you kept this change.
As we said, the transport offset is set, so it looks like a lot of your changes can be removed to ease the review
tcp_gro_receive() sets the transport header, so the xxx_complete() handlers can rely on it.
The only part that you could keep is the following optim :
- skb->csum_start = skb_transport_header(skb) - skb->head;
+ skb->csum_start = (unsigned char *)th - skb->head;
Quoted 26 lines · Eric Dumazet
Quoted 11 lines · H.K. Jerry Chu
net/ipv4/tcp_offload.c +2
-4-int tcp_gro_complete (struct sk_buff *skb) +int __tcp_gro_complete (struct sk_buff *skb,struct tcphdr *th) { -struct tcphdr *th =tcp_hdr (skb); - - skb->csum_start =skb_transport_header (skb) - skb->head; + skb->csum_start = (unsigned char *)th - skb->head; skb->csum_offset = offsetof(struct tcphdr , check); skb->ip_summed =CHECKSUM_PARTIAL ;net/ipv4/tcp_offload.c int tcp_gro_complete(struct sk_buff *skb) · line 258
Quoted 9 lines
net/ipv4/tcp_offload.c +6
-0@@ -251,6 +250,12 @@ int tcp_gro_complete(struct sk_buff *skb)return 0 ; } +EXPORT_SYMBOL (__tcp_gro_complete); + +int tcp_gro_complete (struct sk_buff *skb) +{ +return __tcp_gro_complete (skb,tcp_hdr (skb)); +}I have no idea why you kept this change.
Quoted 2 lines
As we said, the transport offset is set, so it looks like a lot of your changes can be removed to ease the review
Yes I know but you were the one who suggested not setting the transport header a while back, and seemed to prefer avoiding the use of saved headers in skb.
Then you discovered the transport header must be set by the GRO stack. That leaves the question should I still try to avoid using headers saved in skb in case you may attempt to get rid of all the header setting in GRO completely in the future. I decided last night to use the new way (nhoff). But obviously the other way (to simply use skb_transport_header to the extent possible) can be easily done and will avoid much of the code change too. I'll send out v3 soon.
Quoted 11 lines
tcp_gro_receive()sets the transport header, so thexxx_complete()handlers can rely on it.The only part that you could keep is the following optim :
-
skb->csum_start=skb_transport_header(skb)-skb->head;
+skb->csum_start= (unsigned char *)th -skb->head;