diff mbox series

[v2] ip link: hsr: Add support for passing information about INTERLINK device

Message ID 20240308145729.490863-1-lukma@denx.de (mailing list archive)
State Changes Requested
Delegated to: David Ahern
Headers show
Series [v2] ip link: hsr: Add support for passing information about INTERLINK device | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Lukasz Majewski March 8, 2024, 2:57 p.m. UTC
The HSR capable device can operate in two modes of operations -
Doubly Attached Node for HSR (DANH) and RedBOX.

The latter one allows connection of non-HSR aware device to HSR network.
This node is called SAN (Singly Attached Network) and is connected via
INTERLINK network device.

This patch adds support for passing information about the INTERLINK device,
so the Linux driver can properly setup it.

Signed-off-by: Lukasz Majewski <lukma@denx.de>

---
Changes for v2:

- Rebase the patch on top of iproute2-next/main repo
- Replace matches() with strcmp() when interlink
- Use print_color_string() instead of just print_string()
---
 ip/iplink_hsr.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

Comments

David Ahern March 15, 2024, 2:45 a.m. UTC | #1
On 3/8/24 7:57 AM, Lukasz Majewski wrote:
> diff --git a/ip/iplink_hsr.c b/ip/iplink_hsr.c
> index 76f24a6a..dc802ed9 100644
> --- a/ip/iplink_hsr.c
> +++ b/ip/iplink_hsr.c
> @@ -21,12 +21,15 @@ static void print_usage(FILE *f)
>  {
>  	fprintf(f,
>  		"Usage:\tip link add name NAME type hsr slave1 SLAVE1-IF slave2 SLAVE2-IF\n"
> -		"\t[ supervision ADDR-BYTE ] [version VERSION] [proto PROTOCOL]\n"
> +		"\t[ interlink INTERLINK-IF ] [ supervision ADDR-BYTE ] [ version VERSION ]\n"
> +		"\t[ proto PROTOCOL ]\n"
>  		"\n"
>  		"NAME\n"
>  		"	name of new hsr device (e.g. hsr0)\n"
>  		"SLAVE1-IF, SLAVE2-IF\n"
>  		"	the two slave devices bound to the HSR device\n"
> +		"INTERLINK-IF\n"
> +		"	the interlink device bound to the HSR network to connect SAN device\n"
>  		"ADDR-BYTE\n"
>  		"	0-255; the last byte of the multicast address used for HSR supervision\n"
>  		"	frames (default = 0)\n"
> @@ -82,6 +85,12 @@ static int hsr_parse_opt(struct link_util *lu, int argc, char **argv,
>  			if (ifindex == 0)
>  				invarg("No such interface", *argv);
>  			addattr_l(n, 1024, IFLA_HSR_SLAVE2, &ifindex, 4);
> +		} else if (strcmp(*argv, "interlink") == 0) {
> +			NEXT_ARG();
> +			ifindex = ll_name_to_index(*argv);
> +			if (ifindex == 0)
> +				invarg("No such interface", *argv);
> +			addattr_l(n, 1024, IFLA_HSR_INTERLINK, &ifindex, 4);
>  		} else if (matches(*argv, "help") == 0) {
>  			usage();
>  			return -1;
> @@ -109,6 +118,9 @@ static void hsr_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
>  	if (tb[IFLA_HSR_SLAVE2] &&
>  	    RTA_PAYLOAD(tb[IFLA_HSR_SLAVE2]) < sizeof(__u32))
>  		return;
> +	if (tb[IFLA_HSR_INTERLINK] &&
> +	    RTA_PAYLOAD(tb[IFLA_HSR_INTERLINK]) < sizeof(__u32))
> +		return;
>  	if (tb[IFLA_HSR_SEQ_NR] &&
>  	    RTA_PAYLOAD(tb[IFLA_HSR_SEQ_NR]) < sizeof(__u16))
>  		return;
> @@ -132,6 +144,10 @@ static void hsr_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
>  	else
>  		print_null(PRINT_ANY, "slave2", "slave2 %s ", "<none>");
>  
> +	if (tb[IFLA_HSR_INTERLINK])
> +		print_color_string(PRINT_ANY, COLOR_IFNAME, "interlink", "interlink %s ",
> +				   ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_INTERLINK])));
> +
>  	if (tb[IFLA_HSR_SEQ_NR])
>  		print_int(PRINT_ANY,
>  			  "seq_nr",


Please update the man page as well, man/man8/ip-link.8.in.

pw-bot: cr
diff mbox series

Patch

diff --git a/ip/iplink_hsr.c b/ip/iplink_hsr.c
index 76f24a6a..dc802ed9 100644
--- a/ip/iplink_hsr.c
+++ b/ip/iplink_hsr.c
@@ -21,12 +21,15 @@  static void print_usage(FILE *f)
 {
 	fprintf(f,
 		"Usage:\tip link add name NAME type hsr slave1 SLAVE1-IF slave2 SLAVE2-IF\n"
-		"\t[ supervision ADDR-BYTE ] [version VERSION] [proto PROTOCOL]\n"
+		"\t[ interlink INTERLINK-IF ] [ supervision ADDR-BYTE ] [ version VERSION ]\n"
+		"\t[ proto PROTOCOL ]\n"
 		"\n"
 		"NAME\n"
 		"	name of new hsr device (e.g. hsr0)\n"
 		"SLAVE1-IF, SLAVE2-IF\n"
 		"	the two slave devices bound to the HSR device\n"
+		"INTERLINK-IF\n"
+		"	the interlink device bound to the HSR network to connect SAN device\n"
 		"ADDR-BYTE\n"
 		"	0-255; the last byte of the multicast address used for HSR supervision\n"
 		"	frames (default = 0)\n"
@@ -82,6 +85,12 @@  static int hsr_parse_opt(struct link_util *lu, int argc, char **argv,
 			if (ifindex == 0)
 				invarg("No such interface", *argv);
 			addattr_l(n, 1024, IFLA_HSR_SLAVE2, &ifindex, 4);
+		} else if (strcmp(*argv, "interlink") == 0) {
+			NEXT_ARG();
+			ifindex = ll_name_to_index(*argv);
+			if (ifindex == 0)
+				invarg("No such interface", *argv);
+			addattr_l(n, 1024, IFLA_HSR_INTERLINK, &ifindex, 4);
 		} else if (matches(*argv, "help") == 0) {
 			usage();
 			return -1;
@@ -109,6 +118,9 @@  static void hsr_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 	if (tb[IFLA_HSR_SLAVE2] &&
 	    RTA_PAYLOAD(tb[IFLA_HSR_SLAVE2]) < sizeof(__u32))
 		return;
+	if (tb[IFLA_HSR_INTERLINK] &&
+	    RTA_PAYLOAD(tb[IFLA_HSR_INTERLINK]) < sizeof(__u32))
+		return;
 	if (tb[IFLA_HSR_SEQ_NR] &&
 	    RTA_PAYLOAD(tb[IFLA_HSR_SEQ_NR]) < sizeof(__u16))
 		return;
@@ -132,6 +144,10 @@  static void hsr_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
 	else
 		print_null(PRINT_ANY, "slave2", "slave2 %s ", "<none>");
 
+	if (tb[IFLA_HSR_INTERLINK])
+		print_color_string(PRINT_ANY, COLOR_IFNAME, "interlink", "interlink %s ",
+				   ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_INTERLINK])));
+
 	if (tb[IFLA_HSR_SEQ_NR])
 		print_int(PRINT_ANY,
 			  "seq_nr",