netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] rtnetlink: add needed_{head,tail}room attributes
@ 2025-09-15 16:32 Alasdair McWilliam
  2025-09-15 16:49 ` Daniel Borkmann
  0 siblings, 1 reply; 5+ messages in thread
From: Alasdair McWilliam @ 2025-09-15 16:32 UTC (permalink / raw)
  To: netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni

Various network interface types make use of needed_{head,tail}room values
to efficiently reserve buffer space for additional encapsulation headers,
such as VXLAN, Geneve, IPSec, etc. However, it is not currently possible
to query these values in a generic way.

Introduce ability to query the needed_{head,tail}room values of a network
device via rtnetlink, such that applications that may wish to use these
values can do so.

Signed-off-by: Alasdair McWilliam <alasdair@mcwilliam.dev>
---
 include/uapi/linux/if_link.h |  2 ++
 net/core/rtnetlink.c         | 10 +++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
index 45f56c9f95d9..3b491d96e52e 100644
--- a/include/uapi/linux/if_link.h
+++ b/include/uapi/linux/if_link.h
@@ -379,6 +379,8 @@ enum {
 	IFLA_DPLL_PIN,
 	IFLA_MAX_PACING_OFFLOAD_HORIZON,
 	IFLA_NETNS_IMMUTABLE,
+	IFLA_HEADROOM,
+	IFLA_TAILROOM,
 	__IFLA_MAX
 };
 
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index 094b085cff20..c68e20a36daa 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1326,6 +1326,8 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
 	       + rtnl_devlink_port_size(dev)
 	       + rtnl_dpll_pin_size(dev)
 	       + nla_total_size(8)  /* IFLA_MAX_PACING_OFFLOAD_HORIZON */
+	       + nla_total_size(2)  /* IFLA_HEADROOM */
+	       + nla_total_size(2)  /* IFLA_TAILROOM */
 	       + 0;
 }
 
@@ -2091,7 +2093,11 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
 	    nla_put_u32(skb, IFLA_CARRIER_UP_COUNT,
 			atomic_read(&dev->carrier_up_count)) ||
 	    nla_put_u32(skb, IFLA_CARRIER_DOWN_COUNT,
-			atomic_read(&dev->carrier_down_count)))
+			atomic_read(&dev->carrier_down_count)) ||
+	    nla_put_u16(skb, IFLA_HEADROOM,
+			READ_ONCE(dev->needed_headroom)) ||
+	    nla_put_u16(skb, IFLA_TAILROOM,
+			READ_ONCE(dev->needed_tailroom)))
 		goto nla_put_failure;
 
 	if (rtnl_fill_proto_down(skb, dev))
@@ -2243,6 +2249,8 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = {
 	[IFLA_GSO_IPV4_MAX_SIZE]	= NLA_POLICY_MIN(NLA_U32, MAX_TCP_HEADER + 1),
 	[IFLA_GRO_IPV4_MAX_SIZE]	= { .type = NLA_U32 },
 	[IFLA_NETNS_IMMUTABLE]	= { .type = NLA_REJECT },
+	[IFLA_HEADROOM]		= { .type = NLA_U16 },
+	[IFLA_TAILROOM]		= { .type = NLA_U16 },
 };
 
 static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
-- 
2.47.3


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] rtnetlink: add needed_{head,tail}room attributes
  2025-09-15 16:32 [PATCH] rtnetlink: add needed_{head,tail}room attributes Alasdair McWilliam
@ 2025-09-15 16:49 ` Daniel Borkmann
  2025-09-15 17:20   ` Stephen Hemminger
  2025-09-16 10:56   ` Alasdair McWilliam
  0 siblings, 2 replies; 5+ messages in thread
From: Daniel Borkmann @ 2025-09-15 16:49 UTC (permalink / raw)
  To: Alasdair McWilliam, netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni

Hi Alasdair,

On 9/15/25 6:32 PM, Alasdair McWilliam wrote:
> Various network interface types make use of needed_{head,tail}room values
> to efficiently reserve buffer space for additional encapsulation headers,
> such as VXLAN, Geneve, IPSec, etc. However, it is not currently possible
> to query these values in a generic way.
> 
> Introduce ability to query the needed_{head,tail}room values of a network
> device via rtnetlink, such that applications that may wish to use these
> values can do so.
> 
> Signed-off-by: Alasdair McWilliam <alasdair@mcwilliam.dev>
> ---
>   include/uapi/linux/if_link.h |  2 ++
>   net/core/rtnetlink.c         | 10 +++++++++-
>   2 files changed, 11 insertions(+), 1 deletion(-)
> 
> diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h
> index 45f56c9f95d9..3b491d96e52e 100644
> --- a/include/uapi/linux/if_link.h
> +++ b/include/uapi/linux/if_link.h
> @@ -379,6 +379,8 @@ enum {
>   	IFLA_DPLL_PIN,
>   	IFLA_MAX_PACING_OFFLOAD_HORIZON,
>   	IFLA_NETNS_IMMUTABLE,
> +	IFLA_HEADROOM,
> +	IFLA_TAILROOM,
>   	__IFLA_MAX
>   };
>   
> diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
> index 094b085cff20..c68e20a36daa 100644
> --- a/net/core/rtnetlink.c
> +++ b/net/core/rtnetlink.c
> @@ -1326,6 +1326,8 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev,
>   	       + rtnl_devlink_port_size(dev)
>   	       + rtnl_dpll_pin_size(dev)
>   	       + nla_total_size(8)  /* IFLA_MAX_PACING_OFFLOAD_HORIZON */
> +	       + nla_total_size(2)  /* IFLA_HEADROOM */
> +	       + nla_total_size(2)  /* IFLA_TAILROOM */
>   	       + 0;
>   }
>   
> @@ -2091,7 +2093,11 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb,
>   	    nla_put_u32(skb, IFLA_CARRIER_UP_COUNT,
>   			atomic_read(&dev->carrier_up_count)) ||
>   	    nla_put_u32(skb, IFLA_CARRIER_DOWN_COUNT,
> -			atomic_read(&dev->carrier_down_count)))
> +			atomic_read(&dev->carrier_down_count)) ||
> +	    nla_put_u16(skb, IFLA_HEADROOM,
> +			READ_ONCE(dev->needed_headroom)) ||
> +	    nla_put_u16(skb, IFLA_TAILROOM,
> +			READ_ONCE(dev->needed_tailroom)))
>   		goto nla_put_failure;
>   
>   	if (rtnl_fill_proto_down(skb, dev))
> @@ -2243,6 +2249,8 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = {
>   	[IFLA_GSO_IPV4_MAX_SIZE]	= NLA_POLICY_MIN(NLA_U32, MAX_TCP_HEADER + 1),
>   	[IFLA_GRO_IPV4_MAX_SIZE]	= { .type = NLA_U32 },
>   	[IFLA_NETNS_IMMUTABLE]	= { .type = NLA_REJECT },
> +	[IFLA_HEADROOM]		= { .type = NLA_U16 },
> +	[IFLA_TAILROOM]		= { .type = NLA_U16 },

Given this is for dumping only, we'd need to replace NLA_U16 above with NLA_REJECT
like in case of IFLA_NETNS_IMMUTABLE.

Also the Documentation/netlink/specs/rt_link.yaml needs an extension, otherwise lgtm.
$subj should have [PATCH net-next] to indicate the target tree.

Thanks,
Daniel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rtnetlink: add needed_{head,tail}room attributes
  2025-09-15 16:49 ` Daniel Borkmann
@ 2025-09-15 17:20   ` Stephen Hemminger
  2025-09-15 18:30     ` Daniel Borkmann
  2025-09-16 10:56   ` Alasdair McWilliam
  1 sibling, 1 reply; 5+ messages in thread
From: Stephen Hemminger @ 2025-09-15 17:20 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Alasdair McWilliam, netdev, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni

On Mon, 15 Sep 2025 18:49:55 +0200
Daniel Borkmann <daniel@iogearbox.net> wrote:

> Hi Alasdair,
> 
> On 9/15/25 6:32 PM, Alasdair McWilliam wrote:
> > Various network interface types make use of needed_{head,tail}room values
> > to efficiently reserve buffer space for additional encapsulation headers,
> > such as VXLAN, Geneve, IPSec, etc. However, it is not currently possible
> > to query these values in a generic way.
> > 
> > Introduce ability to query the needed_{head,tail}room values of a network
> > device via rtnetlink, such that applications that may wish to use these
> > values can do so.
> > 
> > Signed-off-by: Alasdair McWilliam <alasdair@mcwilliam.dev>

Why is this info needed in user space?
How would an application use this?
Seems like a hardware specific optimization that should be hidden in driver.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rtnetlink: add needed_{head,tail}room attributes
  2025-09-15 17:20   ` Stephen Hemminger
@ 2025-09-15 18:30     ` Daniel Borkmann
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel Borkmann @ 2025-09-15 18:30 UTC (permalink / raw)
  To: Stephen Hemminger
  Cc: Alasdair McWilliam, netdev, Andrew Lunn, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni

On 9/15/25 7:20 PM, Stephen Hemminger wrote:
> On Mon, 15 Sep 2025 18:49:55 +0200
> Daniel Borkmann <daniel@iogearbox.net> wrote:
>> On 9/15/25 6:32 PM, Alasdair McWilliam wrote:
>>> Various network interface types make use of needed_{head,tail}room values
>>> to efficiently reserve buffer space for additional encapsulation headers,
>>> such as VXLAN, Geneve, IPSec, etc. However, it is not currently possible
>>> to query these values in a generic way.
>>>
>>> Introduce ability to query the needed_{head,tail}room values of a network
>>> device via rtnetlink, such that applications that may wish to use these
>>> values can do so.
>>>
>>> Signed-off-by: Alasdair McWilliam <alasdair@mcwilliam.dev>
> 
> Why is this info needed in user space?
> How would an application use this?
> Seems like a hardware specific optimization that should be hidden in driver.

We would like to use this in Cilium. Basically our Cilium agent iterates over
the present devices based on the Cilium user config (e.g. direct routing/vxlan/
geneve/wireguard/etc) to then configure netkit in order to expose the
needed_{head,tail}room into K8s Pods, see also b9ed315d3c4c ("netkit: Allow
for configuring needed_{head,tail}room").

Thanks,
Daniel

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] rtnetlink: add needed_{head,tail}room attributes
  2025-09-15 16:49 ` Daniel Borkmann
  2025-09-15 17:20   ` Stephen Hemminger
@ 2025-09-16 10:56   ` Alasdair McWilliam
  1 sibling, 0 replies; 5+ messages in thread
From: Alasdair McWilliam @ 2025-09-16 10:56 UTC (permalink / raw)
  To: Daniel Borkmann, netdev
  Cc: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni

Hi Daniel,

On 15/09/2025 17:49, Daniel Borkmann wrote:
> Hi Alasdair,
> 

>> @@ -2243,6 +2249,8 @@ static const struct nla_policy
>> ifla_policy[IFLA_MAX+1] = {
>>       [IFLA_GSO_IPV4_MAX_SIZE]    = NLA_POLICY_MIN(NLA_U32,
>> MAX_TCP_HEADER + 1),
>>       [IFLA_GRO_IPV4_MAX_SIZE]    = { .type = NLA_U32 },
>>       [IFLA_NETNS_IMMUTABLE]    = { .type = NLA_REJECT },
>> +    [IFLA_HEADROOM]        = { .type = NLA_U16 },
>> +    [IFLA_TAILROOM]        = { .type = NLA_U16 },
> 
> Given this is for dumping only, we'd need to replace NLA_U16 above with
> NLA_REJECT
> like in case of IFLA_NETNS_IMMUTABLE.
> 
> Also the Documentation/netlink/specs/rt_link.yaml needs an extension,
> otherwise lgtm.
> $subj should have [PATCH net-next] to indicate the target tree.
> 

Acknowledged. I will revise and re-submit. I will also include
additional context in the commit log as per your later email in this thread.

> Thanks,
> Daniel

Thanks!
Alasdair

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-09-16 10:56 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-15 16:32 [PATCH] rtnetlink: add needed_{head,tail}room attributes Alasdair McWilliam
2025-09-15 16:49 ` Daniel Borkmann
2025-09-15 17:20   ` Stephen Hemminger
2025-09-15 18:30     ` Daniel Borkmann
2025-09-16 10:56   ` Alasdair McWilliam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).