Skip to content

Commit 7516b27

Browse files
nbd168Paolo Abeni
authored andcommitted
net: create tcp_gro_header_pull helper function
Pull the code out of tcp_gro_receive in order to access the tcp header from tcp4/6_gro_receive. Acked-by: Paolo Abeni <[email protected]> Reviewed-by: Eric Dumazet <[email protected]> Signed-off-by: Felix Fietkau <[email protected]> Reviewed-by: David Ahern <[email protected]> Reviewed-by: Willem de Bruijn <[email protected]> Signed-off-by: Paolo Abeni <[email protected]>
1 parent 80e85fb commit 7516b27

File tree

3 files changed

+50
-27
lines changed

3 files changed

+50
-27
lines changed

include/net/tcp.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2191,8 +2191,10 @@ void tcp_v4_destroy_sock(struct sock *sk);
21912191

21922192
struct sk_buff *tcp_gso_segment(struct sk_buff *skb,
21932193
netdev_features_t features);
2194+
struct tcphdr *tcp_gro_pull_header(struct sk_buff *skb);
21942195
struct sk_buff *tcp_gro_lookup(struct list_head *head, struct tcphdr *th);
2195-
struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb);
2196+
struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb,
2197+
struct tcphdr *th);
21962198
INDIRECT_CALLABLE_DECLARE(int tcp4_gro_complete(struct sk_buff *skb, int thoff));
21972199
INDIRECT_CALLABLE_DECLARE(struct sk_buff *tcp4_gro_receive(struct list_head *head, struct sk_buff *skb));
21982200
INDIRECT_CALLABLE_DECLARE(int tcp6_gro_complete(struct sk_buff *skb, int thoff));

net/ipv4/tcp_offload.c

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -266,40 +266,46 @@ struct sk_buff *tcp_gro_lookup(struct list_head *head, struct tcphdr *th)
266266
return NULL;
267267
}
268268

269-
struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb)
269+
struct tcphdr *tcp_gro_pull_header(struct sk_buff *skb)
270270
{
271-
struct sk_buff *pp = NULL;
272-
struct sk_buff *p;
271+
unsigned int thlen, hlen, off;
273272
struct tcphdr *th;
274-
struct tcphdr *th2;
275-
unsigned int len;
276-
unsigned int thlen;
277-
__be32 flags;
278-
unsigned int mss = 1;
279-
unsigned int hlen;
280-
unsigned int off;
281-
int flush = 1;
282-
int i;
283273

284274
off = skb_gro_offset(skb);
285275
hlen = off + sizeof(*th);
286276
th = skb_gro_header(skb, hlen, off);
287277
if (unlikely(!th))
288-
goto out;
278+
return NULL;
289279

290280
thlen = th->doff * 4;
291281
if (thlen < sizeof(*th))
292-
goto out;
282+
return NULL;
293283

294284
hlen = off + thlen;
295285
if (!skb_gro_may_pull(skb, hlen)) {
296286
th = skb_gro_header_slow(skb, hlen, off);
297287
if (unlikely(!th))
298-
goto out;
288+
return NULL;
299289
}
300290

301291
skb_gro_pull(skb, thlen);
302292

293+
return th;
294+
}
295+
296+
struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb,
297+
struct tcphdr *th)
298+
{
299+
unsigned int thlen = th->doff * 4;
300+
struct sk_buff *pp = NULL;
301+
struct sk_buff *p;
302+
struct tcphdr *th2;
303+
unsigned int len;
304+
__be32 flags;
305+
unsigned int mss = 1;
306+
int flush = 1;
307+
int i;
308+
303309
len = skb_gro_len(skb);
304310
flags = tcp_flag_word(th);
305311

@@ -376,7 +382,6 @@ struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb)
376382
if (p && (!NAPI_GRO_CB(skb)->same_flow || flush))
377383
pp = p;
378384

379-
out:
380385
NAPI_GRO_CB(skb)->flush |= (flush != 0);
381386

382387
return pp;
@@ -405,15 +410,23 @@ EXPORT_SYMBOL(tcp_gro_complete);
405410
INDIRECT_CALLABLE_SCOPE
406411
struct sk_buff *tcp4_gro_receive(struct list_head *head, struct sk_buff *skb)
407412
{
413+
struct tcphdr *th;
414+
408415
/* Don't bother verifying checksum if we're going to flush anyway. */
409416
if (!NAPI_GRO_CB(skb)->flush &&
410417
skb_gro_checksum_validate(skb, IPPROTO_TCP,
411-
inet_gro_compute_pseudo)) {
412-
NAPI_GRO_CB(skb)->flush = 1;
413-
return NULL;
414-
}
418+
inet_gro_compute_pseudo))
419+
goto flush;
420+
421+
th = tcp_gro_pull_header(skb);
422+
if (!th)
423+
goto flush;
415424

416-
return tcp_gro_receive(head, skb);
425+
return tcp_gro_receive(head, skb, th);
426+
427+
flush:
428+
NAPI_GRO_CB(skb)->flush = 1;
429+
return NULL;
417430
}
418431

419432
INDIRECT_CALLABLE_SCOPE int tcp4_gro_complete(struct sk_buff *skb, int thoff)

net/ipv6/tcpv6_offload.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,23 @@
1616
INDIRECT_CALLABLE_SCOPE
1717
struct sk_buff *tcp6_gro_receive(struct list_head *head, struct sk_buff *skb)
1818
{
19+
struct tcphdr *th;
20+
1921
/* Don't bother verifying checksum if we're going to flush anyway. */
2022
if (!NAPI_GRO_CB(skb)->flush &&
2123
skb_gro_checksum_validate(skb, IPPROTO_TCP,
22-
ip6_gro_compute_pseudo)) {
23-
NAPI_GRO_CB(skb)->flush = 1;
24-
return NULL;
25-
}
24+
ip6_gro_compute_pseudo))
25+
goto flush;
26+
27+
th = tcp_gro_pull_header(skb);
28+
if (!th)
29+
goto flush;
30+
31+
return tcp_gro_receive(head, skb, th);
2632

27-
return tcp_gro_receive(head, skb);
33+
flush:
34+
NAPI_GRO_CB(skb)->flush = 1;
35+
return NULL;
2836
}
2937

3038
INDIRECT_CALLABLE_SCOPE int tcp6_gro_complete(struct sk_buff *skb, int thoff)

0 commit comments

Comments
 (0)