Skip to contentSkip to conversation

net/hsr: add protocol version to fill_info output

PATCH Superseded Jan Vaclav 4 participants 9 messages Sep 22, 2025 – Sep 26, 2025

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jan Vaclav

author
#0 lore raw

PATCH v2 1/1 net/hsr: add protocol version to fill_info output

Currently, it is possible to configure IFLA_HSR_VERSION, but there is no way to check in userspace what the currently configured HSR protocol version is.

Add it to the output of hsr_fill_info().

This info could then be used by e.g. ip(8), like so:

$ ip -d link show hsr0
12: hsr0: <BROADCAST,MULTICAST> mtu ...
    ...
    hsr slave1 veth0 slave2 veth1 ... proto 0 version 1

---
v2: Added an example to the commit message to show
how userspace programs could use this property.

v1: https://lore.kernel.org/netdev/[email protected]/

 net/hsr/hsr_netlink.c | 2 ++
 1 file changed, 2 insertions(+)
net/hsr/hsr_netlink.c +2 -0
index b12047024..3d0bd24c6 100644
@@ -166,6 +166,8 @@ static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev)
 		goto nla_put_failure;
 	if (hsr->prot_version == PRP_V1)
 		proto = HSR_PROTOCOL_PRP;
+	if (nla_put_u8(skb, IFLA_HSR_VERSION, hsr->prot_version))
+		goto nla_put_failure;
 	if (nla_put_u8(skb, IFLA_HSR_PROTOCOL, proto))
 		goto nla_put_failure;
 
Signature · 1 line
2.51.0
reviewer Reviewed-by on v2 1/1
#1 lore raw
Quoted 12 lines · Jan Vaclav

Currently, it is possible to configure IFLA_HSR_VERSION, but there is no way to check in userspace what the currently configured HSR protocol version is.

Add it to the output of hsr_fill_info().

This info could then be used by e.g. ip(8), like so:

$ ip -d link show hsr0
12: hsr0: <BROADCAST,MULTICAST> mtu ...
    ...
    hsr slave1 veth0 slave2 veth1 ... proto 0 version 1
Quoted 6 lines

---
v2: Added an example to the commit message to show
how userspace programs could use this property.

v1: https://lore.kernel.org/netdev/[email protected]/

Hi Jan,

thanks for the update.

maintainer
#2 lore raw
In reply to Jan Vaclav

net/hsr/hsr_netlink.c static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev) · line 170

Quoted 4 lines · On Mon, 22 Sep 2025 11:37:45 +0200 Jan Vaclav wrote:
net/hsr/hsr_netlink.c +2 -0
 	if (hsr->prot_version == PRP_V1)
 		proto = HSR_PROTOCOL_PRP;
+	if (nla_put_u8(skb, IFLA_HSR_VERSION, hsr->prot_version))
+		goto nla_put_failure;

Looks like configuration path does not allow setting version if proto is PRP. Should we add an else before the if? since previous if is checking for PRP already

#3 lore raw
Quoted 11 lines · Jakub Kicinski

net/hsr/hsr_netlink.c static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev) · line 170

Quoted 4 lines · On Mon, 22 Sep 2025 11:37:45 +0200 Jan Vaclav wrote:
      if (hsr->prot_version == PRP_V1)
              proto = HSR_PROTOCOL_PRP;
net/hsr/hsr_netlink.c +2 -0
+     if (nla_put_u8(skb, IFLA_HSR_VERSION, hsr->prot_version))
+             goto nla_put_failure;

Looks like configuration path does not allow setting version if proto is PRP. Should we add an else before the if? since previous if is checking for PRP already

The way HSR configuration is currently handled seems very confusing to me, because it allows setting the protocol version, but for PRP_V1 only as a byproduct of setting the protocol to PRP. If you configure an interface with (proto = PRP, version = PRP_V1), it will fail, which seems wrong to me, considering this is the end result of configuring only with proto = PRP anyways.

I think the best solution would be to introduce another change that allows explicitly setting the version to PRP_V1 if the protocol is set to PRP.

What do you think?

#4 lore raw
Quoted 13 lines · Ján Václav
Quoted 11 lines · Jakub Kicinski

net/hsr/hsr_netlink.c static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev) · line 170

Quoted 4 lines · On Mon, 22 Sep 2025 11:37:45 +0200 Jan Vaclav wrote:
       if (hsr->prot_version == PRP_V1)
               proto = HSR_PROTOCOL_PRP;
net/hsr/hsr_netlink.c +2 -0
+     if (nla_put_u8(skb, IFLA_HSR_VERSION, hsr->prot_version))
+             goto nla_put_failure;

Looks like configuration path does not allow setting version if proto is PRP. Should we add an else before the if? since previous if is checking for PRP already

Quoted 7 lines

The way HSR configuration is currently handled seems very confusing to me, because it allows setting the protocol version, but for PRP_V1 only as a byproduct of setting the protocol to PRP. If you configure an interface with (proto = PRP, version = PRP_V1), it will fail, which seems wrong to me, considering this is the end result of configuring only with proto = PRP anyways.

IMO, that is a good point.

Quoted 4 lines

I think the best solution would be to introduce another change that allows explicitly setting the version to PRP_V1 if the protocol is set to PRP.

I think it would be nice to unify the logic inside the else statement when parsing IFLA_HSR_VERSION and the later check for HSR_PROTOCOL_PRP. It could be simplified while supporting PRP_V1 explicitly set when PRP protocol is set.

Which also makes me wonder, should the enum hsr_version be exposed as UAPI? Currently it is under include/linux/if_hsr.h. But then, the naming should be something like "HSR_VERSION_HSR_0" or similar.

maintainer
#5 lore raw
In reply to Ján Václav
Quoted 12 lines · On Wed, 24 Sep 2025 13:21:32 +0200 Ján Václav wrote:
Quoted 10 lines · Jakub Kicinski

net/hsr/hsr_netlink.c static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev) · line 170

Quoted 4 lines · On Mon, 22 Sep 2025 11:37:45 +0200 Jan Vaclav wrote:
      if (hsr->prot_version == PRP_V1)
              proto = HSR_PROTOCOL_PRP;
net/hsr/hsr_netlink.c +2 -0
+     if (nla_put_u8(skb, IFLA_HSR_VERSION, hsr->prot_version))
+             goto nla_put_failure;  

Looks like configuration path does not allow setting version if proto is PRP. Should we add an else before the if? since previous if is checking for PRP already

Quoted 6 lines

The way HSR configuration is currently handled seems very confusing to me, because it allows setting the protocol version, but for PRP_V1 only as a byproduct of setting the protocol to PRP. If you configure an interface with (proto = PRP, version = PRP_V1), it will fail, which seems wrong to me, considering this is the end result of configuring only with proto = PRP anyways.

I'm not very familiar with HSR or PRP. But The PRP_V1 which has value of 3 looks like a kernel-internal hack. Or does the protocol actually specify value 3 to mean PRP?

I don't think there's anything particularly wrong with the code. The version is for HSR because PRP only has one version, there's no ambiguity.

But again, I'm just glancing at the code I could be wrong..

#6 lore raw
Quoted 24 lines · Jakub Kicinski
Quoted 12 lines · On Wed, 24 Sep 2025 13:21:32 +0200 Ján Václav wrote:
Quoted 10 lines · Jakub Kicinski

net/hsr/hsr_netlink.c static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev) · line 170

Quoted 4 lines · On Mon, 22 Sep 2025 11:37:45 +0200 Jan Vaclav wrote:
       if (hsr->prot_version == PRP_V1)
               proto = HSR_PROTOCOL_PRP;
net/hsr/hsr_netlink.c +2 -0
+     if (nla_put_u8(skb, IFLA_HSR_VERSION, hsr->prot_version))
+             goto nla_put_failure;

Looks like configuration path does not allow setting version if proto is PRP. Should we add an else before the if? since previous if is checking for PRP already

Quoted 6 lines

The way HSR configuration is currently handled seems very confusing to me, because it allows setting the protocol version, but for PRP_V1 only as a byproduct of setting the protocol to PRP. If you configure an interface with (proto = PRP, version = PRP_V1), it will fail, which seems wrong to me, considering this is the end result of configuring only with proto = PRP anyways.

I'm not very familiar with HSR or PRP. But The PRP_V1 which has value of 3 looks like a kernel-internal hack. Or does the protocol actually specify value 3 to mean PRP?

Quoted 6 lines

I don't think there's anything particularly wrong with the code. The version is for HSR because PRP only has one version, there's no ambiguity.

But again, I'm just glancing at the code I could be wrong..

No you are right, this is a hack made to integrate PRP with HSR driver. PRP does not have a version other than PRP_V1 therefore it does not make much sense to configure it. Having said that, I think it's weird to report HSR_VERSION 3 but fail when configuring it.

IMHO HSR_VERSION should be hidden for PRP or it should be possible to configure it to "3" (which now that you say it, it looks weird).

maintainer
#7 lore raw
Quoted 11 lines · On Thu, 25 Sep 2025 10:37:38 +0200 Fernando Fernandez Mancera wrote:
Quoted 10 lines

I'm not very familiar with HSR or PRP. But The PRP_V1 which has value of 3 looks like a kernel-internal hack. Or does the protocol actually specify value 3 to mean PRP?

I don't think there's anything particularly wrong with the code. The version is for HSR because PRP only has one version, there's no ambiguity.

But again, I'm just glancing at the code I could be wrong..

Quoted 7 lines

No you are right, this is a hack made to integrate PRP with HSR driver. PRP does not have a version other than PRP_V1 therefore it does not make much sense to configure it. Having said that, I think it's weird to report HSR_VERSION 3 but fail when configuring it.

IMHO HSR_VERSION should be hidden for PRP or it should be possible to configure it to "3" (which now that you say it, it looks weird).

I think we're in agreement then? i was suggesting:

net/hsr/hsr_netlink.c +2 -0
@@ -166,6 +166,8 @@ static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev)
 		goto nla_put_failure;
 	if (hsr->prot_version == PRP_V1)
 		proto = HSR_PROTOCOL_PRP;
+	else if (nla_put_u8(skb, IFLA_HSR_VERSION, hsr->prot_version))
+		goto nla_put_failure;
 	if (nla_put_u8(skb, IFLA_HSR_PROTOCOL, proto))
 		goto nla_put_failure;
 

This will not report the HSR version if prot is PRP

#8 lore raw
Quoted 33 lines · Jakub Kicinski
Quoted 11 lines · On Thu, 25 Sep 2025 10:37:38 +0200 Fernando Fernandez Mancera wrote:
Quoted 10 lines

I'm not very familiar with HSR or PRP. But The PRP_V1 which has value of 3 looks like a kernel-internal hack. Or does the protocol actually specify value 3 to mean PRP?

I don't think there's anything particularly wrong with the code. The version is for HSR because PRP only has one version, there's no ambiguity.

But again, I'm just glancing at the code I could be wrong..

Quoted 7 lines

No you are right, this is a hack made to integrate PRP with HSR driver. PRP does not have a version other than PRP_V1 therefore it does not make much sense to configure it. Having said that, I think it's weird to report HSR_VERSION 3 but fail when configuring it.

IMHO HSR_VERSION should be hidden for PRP or it should be possible to configure it to "3" (which now that you say it, it looks weird).

I think we're in agreement then? i was suggesting:

net/hsr/hsr_netlink.c +2 -0
@@ -166,6 +166,8 @@ static int hsr_fill_info(struct sk_buff *skb, const struct net_device *dev)
  		goto nla_put_failure;
  	if (hsr->prot_version == PRP_V1)
  		proto = HSR_PROTOCOL_PRP;
+	else if (nla_put_u8(skb, IFLA_HSR_VERSION, hsr->prot_version))
+		goto nla_put_failure;
  	if (nla_put_u8(skb, IFLA_HSR_PROTOCOL, proto))
  		goto nla_put_failure;
 
Quoted 1 line

This will not report the HSR version if prot is PRP

Looks good to me. Jan could you send a v3? Thanks!