[PATCH net-next 1/5] net: gro: remove is_ipv6 from napi_gro_cb

Richard Gobert posted 5 patches 1 month, 3 weeks ago
There is a newer version of this series
[PATCH net-next 1/5] net: gro: remove is_ipv6 from napi_gro_cb
Posted by Richard Gobert 1 month, 3 weeks ago
Remove is_ipv6 from napi_gro_cb and use sk->sk_family instead.
This frees up space for another ip_fixedid bit that will be added
in the next commit.

udp_sock_create always creates either a AP_INET or a AF_INET6 socket,
so using sk->sk_family is reliable.

Signed-off-by: Richard Gobert <richardbgobert@gmail.com>
---
 include/net/gro.h      | 3 ---
 net/ipv4/fou_core.c    | 8 ++++----
 net/ipv4/udp_offload.c | 2 --
 net/ipv6/udp_offload.c | 2 --
 4 files changed, 4 insertions(+), 11 deletions(-)

diff --git a/include/net/gro.h b/include/net/gro.h
index a0fca7ac6e7e..87c68007f949 100644
--- a/include/net/gro.h
+++ b/include/net/gro.h
@@ -71,9 +71,6 @@ struct napi_gro_cb {
 		/* Free the skb? */
 		u8	free:2;
 
-		/* Used in foo-over-udp, set in udp[46]_gro_receive */
-		u8	is_ipv6:1;
-
 		/* Used in GRE, set in fou/gue_gro_receive */
 		u8	is_fou:1;
 
diff --git a/net/ipv4/fou_core.c b/net/ipv4/fou_core.c
index 3e30745e2c09..efd3bf6ec3ae 100644
--- a/net/ipv4/fou_core.c
+++ b/net/ipv4/fou_core.c
@@ -254,7 +254,7 @@ static struct sk_buff *fou_gro_receive(struct sock *sk,
 	/* Flag this frame as already having an outer encap header */
 	NAPI_GRO_CB(skb)->is_fou = 1;
 
-	offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads;
+	offloads = sk->sk_family == AF_INET6 ? inet6_offloads : inet_offloads;
 	ops = rcu_dereference(offloads[proto]);
 	if (!ops || !ops->callbacks.gro_receive)
 		goto out;
@@ -281,7 +281,7 @@ static int fou_gro_complete(struct sock *sk, struct sk_buff *skb,
 
 	proto = fou->protocol;
 
-	offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads;
+	offloads = sk->sk_family == AF_INET6 ? inet6_offloads : inet_offloads;
 	ops = rcu_dereference(offloads[proto]);
 	if (WARN_ON(!ops || !ops->callbacks.gro_complete)) {
 		err = -ENOSYS;
@@ -450,7 +450,7 @@ static struct sk_buff *gue_gro_receive(struct sock *sk,
 	/* Flag this frame as already having an outer encap header */
 	NAPI_GRO_CB(skb)->is_fou = 1;
 
-	offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads;
+	offloads = sk->sk_family == AF_INET6 ? inet6_offloads : inet_offloads;
 	ops = rcu_dereference(offloads[proto]);
 	if (!ops || !ops->callbacks.gro_receive)
 		goto out;
@@ -494,7 +494,7 @@ static int gue_gro_complete(struct sock *sk, struct sk_buff *skb, int nhoff)
 		return err;
 	}
 
-	offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads;
+	offloads = sk->sk_family == AF_INET6 ? inet6_offloads : inet_offloads;
 	ops = rcu_dereference(offloads[proto]);
 	if (WARN_ON(!ops || !ops->callbacks.gro_complete))
 		goto out;
diff --git a/net/ipv4/udp_offload.c b/net/ipv4/udp_offload.c
index 5128e2a5b00a..683689cf4293 100644
--- a/net/ipv4/udp_offload.c
+++ b/net/ipv4/udp_offload.c
@@ -891,8 +891,6 @@ struct sk_buff *udp4_gro_receive(struct list_head *head, struct sk_buff *skb)
 		skb_gro_checksum_try_convert(skb, IPPROTO_UDP,
 					     inet_gro_compute_pseudo);
 skip:
-	NAPI_GRO_CB(skb)->is_ipv6 = 0;
-
 	if (static_branch_unlikely(&udp_encap_needed_key))
 		sk = udp4_gro_lookup_skb(skb, uh->source, uh->dest);
 
diff --git a/net/ipv6/udp_offload.c b/net/ipv6/udp_offload.c
index d8445ac1b2e4..046f13b1d77a 100644
--- a/net/ipv6/udp_offload.c
+++ b/net/ipv6/udp_offload.c
@@ -154,8 +154,6 @@ struct sk_buff *udp6_gro_receive(struct list_head *head, struct sk_buff *skb)
 					     ip6_gro_compute_pseudo);
 
 skip:
-	NAPI_GRO_CB(skb)->is_ipv6 = 1;
-
 	if (static_branch_unlikely(&udpv6_encap_needed_key))
 		sk = udp6_gro_lookup_skb(skb, uh->source, uh->dest);
 
-- 
2.36.1
Re: [PATCH net-next 1/5] net: gro: remove is_ipv6 from napi_gro_cb
Posted by Willem de Bruijn 1 month, 2 weeks ago
Richard Gobert wrote:
> Remove is_ipv6 from napi_gro_cb and use sk->sk_family instead.
> This frees up space for another ip_fixedid bit that will be added
> in the next commit.
> 
> udp_sock_create always creates either a AP_INET or a AF_INET6 socket,
> so using sk->sk_family is reliable.

In general, IPv6 socket can accept IPv4 packets. See also
cfg->ipv6_v6only in udp_sock_create6.

Not sure about fou, but are we sure that such AF_INET6 sockets
cannot receive flows with !is_ipv6.
 
> Signed-off-by: Richard Gobert <richardbgobert@gmail.com>
Re: [PATCH net-next 1/5] net: gro: remove is_ipv6 from napi_gro_cb
Posted by Richard Gobert 1 month, 2 weeks ago
Willem de Bruijn wrote:
> Richard Gobert wrote:
>> Remove is_ipv6 from napi_gro_cb and use sk->sk_family instead.
>> This frees up space for another ip_fixedid bit that will be added
>> in the next commit.
>>
>> udp_sock_create always creates either a AP_INET or a AF_INET6 socket,
>> so using sk->sk_family is reliable.
> 
> In general, IPv6 socket can accept IPv4 packets. See also
> cfg->ipv6_v6only in udp_sock_create6.
> 
> Not sure about fou, but are we sure that such AF_INET6 sockets
> cannot receive flows with !is_ipv6.
>  

FOU sets cfg->ipv6_v6only for IPv6 sockets in parse_nl_config.
I'll clarify this in v2.

>> Signed-off-by: Richard Gobert <richardbgobert@gmail.com>
Re: [PATCH net-next 1/5] net: gro: remove is_ipv6 from napi_gro_cb
Posted by Florian Fainelli 1 month, 2 weeks ago
On 8/14/25 04:40, Richard Gobert wrote:
> Remove is_ipv6 from napi_gro_cb and use sk->sk_family instead.
> This frees up space for another ip_fixedid bit that will be added
> in the next commit.
> 
> udp_sock_create always creates either a AP_INET or a AF_INET6 socket,
> so using sk->sk_family is reliable.
> 
> Signed-off-by: Richard Gobert <richardbgobert@gmail.com>

Complete drive by review here.

> ---
>   include/net/gro.h      | 3 ---
>   net/ipv4/fou_core.c    | 8 ++++----
>   net/ipv4/udp_offload.c | 2 --
>   net/ipv6/udp_offload.c | 2 --
>   4 files changed, 4 insertions(+), 11 deletions(-)
> 
> diff --git a/include/net/gro.h b/include/net/gro.h
> index a0fca7ac6e7e..87c68007f949 100644
> --- a/include/net/gro.h
> +++ b/include/net/gro.h
> @@ -71,9 +71,6 @@ struct napi_gro_cb {
>   		/* Free the skb? */
>   		u8	free:2;
>   
> -		/* Used in foo-over-udp, set in udp[46]_gro_receive */
> -		u8	is_ipv6:1;
> -
>   		/* Used in GRE, set in fou/gue_gro_receive */
>   		u8	is_fou:1;
>   
> diff --git a/net/ipv4/fou_core.c b/net/ipv4/fou_core.c
> index 3e30745e2c09..efd3bf6ec3ae 100644
> --- a/net/ipv4/fou_core.c
> +++ b/net/ipv4/fou_core.c
> @@ -254,7 +254,7 @@ static struct sk_buff *fou_gro_receive(struct sock *sk,
>   	/* Flag this frame as already having an outer encap header */
>   	NAPI_GRO_CB(skb)->is_fou = 1;
>   
> -	offloads = NAPI_GRO_CB(skb)->is_ipv6 ? inet6_offloads : inet_offloads;
> +	offloads = sk->sk_family == AF_INET6 ? inet6_offloads : inet_offloads;

Since this pattern repeats, you could create a static inline helper that 
returns the adequate offloads reference depending upon being passed a 
socket reference?
-- 
Florian