Skip to content

Commit 8930046

Browse files
xli98kuba-moo
authored andcommitted
IPv6/GRO: generic helper to remove temporary HBH/jumbo header in driver
IPv6/TCP and GRO stacks can build big TCP packets with an added temporary Hop By Hop header. Is GSO is not involved, then the temporary header needs to be removed in the driver. This patch provides a generic helper for drivers that need to modify their headers in place. Tested: Compiled and ran with ethtool -K eth1 tso off Could send Big TCP packets Signed-off-by: Coco Li <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 8150f0c commit 8930046

File tree

2 files changed

+37
-23
lines changed

2 files changed

+37
-23
lines changed

include/net/ipv6.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,39 @@ static inline int ipv6_has_hopopt_jumbo(const struct sk_buff *skb)
500500
return jhdr->nexthdr;
501501
}
502502

503+
/* Return 0 if HBH header is successfully removed
504+
* Or if HBH removal is unnecessary (packet is not big TCP)
505+
* Return error to indicate dropping the packet
506+
*/
507+
static inline int ipv6_hopopt_jumbo_remove(struct sk_buff *skb)
508+
{
509+
const int hophdr_len = sizeof(struct hop_jumbo_hdr);
510+
int nexthdr = ipv6_has_hopopt_jumbo(skb);
511+
struct ipv6hdr *h6;
512+
513+
if (!nexthdr)
514+
return 0;
515+
516+
if (skb_cow_head(skb, 0))
517+
return -1;
518+
519+
/* Remove the HBH header.
520+
* Layout: [Ethernet header][IPv6 header][HBH][L4 Header]
521+
*/
522+
memmove(skb_mac_header(skb) + hophdr_len, skb_mac_header(skb),
523+
skb_network_header(skb) - skb_mac_header(skb) +
524+
sizeof(struct ipv6hdr));
525+
526+
__skb_pull(skb, hophdr_len);
527+
skb->network_header += hophdr_len;
528+
skb->mac_header += hophdr_len;
529+
530+
h6 = ipv6_hdr(skb);
531+
h6->nexthdr = nexthdr;
532+
533+
return 0;
534+
}
535+
503536
static inline bool ipv6_accept_ra(struct inet6_dev *idev)
504537
{
505538
/* If forwarding is enabled, RA are not accepted unless the special

net/ipv6/ip6_offload.c

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
7777
struct sk_buff *segs = ERR_PTR(-EINVAL);
7878
struct ipv6hdr *ipv6h;
7979
const struct net_offload *ops;
80-
int proto, nexthdr;
80+
int proto, err;
8181
struct frag_hdr *fptr;
8282
unsigned int payload_len;
8383
u8 *prevhdr;
@@ -87,28 +87,9 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
8787
bool gso_partial;
8888

8989
skb_reset_network_header(skb);
90-
nexthdr = ipv6_has_hopopt_jumbo(skb);
91-
if (nexthdr) {
92-
const int hophdr_len = sizeof(struct hop_jumbo_hdr);
93-
int err;
94-
95-
err = skb_cow_head(skb, 0);
96-
if (err < 0)
97-
return ERR_PTR(err);
98-
99-
/* remove the HBH header.
100-
* Layout: [Ethernet header][IPv6 header][HBH][TCP header]
101-
*/
102-
memmove(skb_mac_header(skb) + hophdr_len,
103-
skb_mac_header(skb),
104-
ETH_HLEN + sizeof(struct ipv6hdr));
105-
skb->data += hophdr_len;
106-
skb->len -= hophdr_len;
107-
skb->network_header += hophdr_len;
108-
skb->mac_header += hophdr_len;
109-
ipv6h = (struct ipv6hdr *)skb->data;
110-
ipv6h->nexthdr = nexthdr;
111-
}
90+
err = ipv6_hopopt_jumbo_remove(skb);
91+
if (err)
92+
return ERR_PTR(err);
11293
nhoff = skb_network_header(skb) - skb_mac_header(skb);
11394
if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h))))
11495
goto out;

0 commit comments

Comments
 (0)