]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
IPv6/GRO: generic helper to remove temporary HBH/jumbo header in driver
authorCoco Li <lixiaoyan@google.com>
Sat, 10 Dec 2022 04:16:45 +0000 (04:16 +0000)
committerJakub Kicinski <kuba@kernel.org>
Mon, 12 Dec 2022 23:41:44 +0000 (15:41 -0800)
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 <lixiaoyan@google.com>
Link: https://lore.kernel.org/r/20221210041646.3587757-1-lixiaoyan@google.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
include/net/ipv6.h
net/ipv6/ip6_offload.c

index d383c895592a9ef2db644db72931ecf5d2d2fb52..03f3af02a9a645b49c1de1272caf5d8d8277d0c1 100644 (file)
@@ -500,6 +500,39 @@ static inline int ipv6_has_hopopt_jumbo(const struct sk_buff *skb)
        return jhdr->nexthdr;
 }
 
+/* Return 0 if HBH header is successfully removed
+ * Or if HBH removal is unnecessary (packet is not big TCP)
+ * Return error to indicate dropping the packet
+ */
+static inline int ipv6_hopopt_jumbo_remove(struct sk_buff *skb)
+{
+       const int hophdr_len = sizeof(struct hop_jumbo_hdr);
+       int nexthdr = ipv6_has_hopopt_jumbo(skb);
+       struct ipv6hdr *h6;
+
+       if (!nexthdr)
+               return 0;
+
+       if (skb_cow_head(skb, 0))
+               return -1;
+
+       /* Remove the HBH header.
+        * Layout: [Ethernet header][IPv6 header][HBH][L4 Header]
+        */
+       memmove(skb_mac_header(skb) + hophdr_len, skb_mac_header(skb),
+               skb_network_header(skb) - skb_mac_header(skb) +
+               sizeof(struct ipv6hdr));
+
+       __skb_pull(skb, hophdr_len);
+       skb->network_header += hophdr_len;
+       skb->mac_header += hophdr_len;
+
+       h6 = ipv6_hdr(skb);
+       h6->nexthdr = nexthdr;
+
+       return 0;
+}
+
 static inline bool ipv6_accept_ra(struct inet6_dev *idev)
 {
        /* If forwarding is enabled, RA are not accepted unless the special
index 3ee345672849a8f1489e0adeb7a10b62e5860165..00dc2e3b018451f40cccbff16b25c8f29ba1b110 100644 (file)
@@ -77,7 +77,7 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
        struct sk_buff *segs = ERR_PTR(-EINVAL);
        struct ipv6hdr *ipv6h;
        const struct net_offload *ops;
-       int proto, nexthdr;
+       int proto, err;
        struct frag_hdr *fptr;
        unsigned int payload_len;
        u8 *prevhdr;
@@ -87,28 +87,9 @@ static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb,
        bool gso_partial;
 
        skb_reset_network_header(skb);
-       nexthdr = ipv6_has_hopopt_jumbo(skb);
-       if (nexthdr) {
-               const int hophdr_len = sizeof(struct hop_jumbo_hdr);
-               int err;
-
-               err = skb_cow_head(skb, 0);
-               if (err < 0)
-                       return ERR_PTR(err);
-
-               /* remove the HBH header.
-                * Layout: [Ethernet header][IPv6 header][HBH][TCP header]
-                */
-               memmove(skb_mac_header(skb) + hophdr_len,
-                       skb_mac_header(skb),
-                       ETH_HLEN + sizeof(struct ipv6hdr));
-               skb->data += hophdr_len;
-               skb->len -= hophdr_len;
-               skb->network_header += hophdr_len;
-               skb->mac_header += hophdr_len;
-               ipv6h = (struct ipv6hdr *)skb->data;
-               ipv6h->nexthdr = nexthdr;
-       }
+       err = ipv6_hopopt_jumbo_remove(skb);
+       if (err)
+               return ERR_PTR(err);
        nhoff = skb_network_header(skb) - skb_mac_header(skb);
        if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h))))
                goto out;