Re: [PATCH net-next v2 1/2] IPv6/GRO: generic helper to remove temporary HBH/jumbo header in driver

From: Paolo Abeni
Date: Tue Nov 29 2022 - 04:35:12 EST


Hello,

Only a couple of minor things below, reporting them as this is still a
RFC, right ? ;)

On Wed, 2022-11-23 at 11:16 -0800, Coco Li wrote:
> 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.
>
> Signed-off-by: Coco Li <lixiaoyan@xxxxxxxxxx>
> ---
> include/net/ipv6.h | 36 ++++++++++++++++++++++++++++++++++++
> net/ipv6/ip6_offload.c | 26 ++++----------------------
> 2 files changed, 40 insertions(+), 22 deletions(-)
>
> diff --git a/include/net/ipv6.h b/include/net/ipv6.h
> index d383c895592a..c5a1daaf5056 100644
> --- a/include/net/ipv6.h
> +++ b/include/net/ipv6.h
> @@ -500,6 +500,42 @@ 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;
> + int err = 0;
> +
> + if (!nexthdr)
> + return err;

You can help a bit the compiler avoiding err initialization:

int err;

if (!nexthdr)
return 0;

> +
> + err = skb_cow_head(skb, 0);
> + if (err)
> + return err;
> +
> + /* 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) +

The have could be:

skb_mac_header_len(skb)

which is IMHO a little more clear.

Thanks!

Paolo