This patch enhances the iplink command to add a proto parameters to
create PRP device/interface similar to HSR. Both protocols are
quite similar and requires a pair of Ethernet interfaces. So re-use
the existing HSR iplink command to create PRP device/interface as
well. Use proto parameter to differentiate the two protocols.
Signed-off-by: Murali Karicheri <[email protected]>
---
ip/iplink_hsr.c | 19 +++++++++++++++++--
1 file changed, 17 insertions(+), 2 deletions(-)
diff --git a/ip/iplink_hsr.c b/ip/iplink_hsr.c
index 7d9167d4e6a3..6ea138a23cbc 100644
--- a/ip/iplink_hsr.c
+++ b/ip/iplink_hsr.c
@@ -25,7 +25,7 @@ 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]\n"
+ "\t[ supervision ADDR-BYTE ] [version VERSION] [proto PROTOCOL]\n"
"\n"
"NAME\n"
" name of new hsr device (e.g. hsr0)\n"
@@ -35,7 +35,9 @@ static void print_usage(FILE *f)
" 0-255; the last byte of the multicast address used for HSR supervision\n"
" frames (default = 0)\n"
"VERSION\n"
- " 0,1; the protocol version to be used. (default = 0)\n");
+ " 0,1; the protocol version to be used. (default = 0)\n"
+ "PROTOCOL\n"
+ " 0 - HSR, 1 - PRP. (default = 0 - HSR)\n");
}
static void usage(void)
@@ -49,6 +51,7 @@ static int hsr_parse_opt(struct link_util *lu, int argc, char **argv,
int ifindex;
unsigned char multicast_spec;
unsigned char protocol_version;
+ unsigned char protocol = HSR_PROTOCOL_HSR;
while (argc > 0) {
if (matches(*argv, "supervision") == 0) {
@@ -64,6 +67,13 @@ static int hsr_parse_opt(struct link_util *lu, int argc, char **argv,
invarg("version is invalid", *argv);
addattr_l(n, 1024, IFLA_HSR_VERSION,
&protocol_version, 1);
+ } else if (matches(*argv, "proto") == 0) {
+ NEXT_ARG();
+ if (!(get_u8(&protocol, *argv, 0) == HSR_PROTOCOL_HSR ||
+ get_u8(&protocol, *argv, 0) == HSR_PROTOCOL_PRP))
+ invarg("protocol is invalid", *argv);
+ addattr_l(n, 1024, IFLA_HSR_PROTOCOL,
+ &protocol, 1);
} else if (matches(*argv, "slave1") == 0) {
NEXT_ARG();
ifindex = ll_name_to_index(*argv);
@@ -140,6 +150,11 @@ static void hsr_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
RTA_PAYLOAD(tb[IFLA_HSR_SUPERVISION_ADDR]),
ARPHRD_VOID,
b1, sizeof(b1)));
+ if (tb[IFLA_HSR_PROTOCOL])
+ print_int(PRINT_ANY,
+ "proto",
+ "proto %d ",
+ rta_getattr_u8(tb[IFLA_HSR_PROTOCOL]));
}
static void hsr_print_help(struct link_util *lu, int argc, char **argv,
--
2.17.1
On Thu, 6 Aug 2020 16:37:11 -0400
Murali Karicheri <[email protected]> wrote:
> +
> + print_int(PRINT_ANY,
> + "proto",
> + "proto %d ",
> + rta_getattr_u8(tb[IFLA_HSR_PROTOCOL]));
Since this unsigned value, you probably want to use print_uint, or print_hhu.
Also please put as many arguments on one line that will fit in 80 (to 90) characters.
if (tb[IFLA_HSR_PROTOCOL])
print_hhu(PRINT_ANY, "proto", "proto %hhu ",
rta_getattr_u8(tb[IFLA_HSR_PROTOCOL]));
On 8/16/20 6:46 PM, Stephen Hemminger wrote:
> On Thu, 6 Aug 2020 16:37:11 -0400
> Murali Karicheri <[email protected]> wrote:
>
>> +
>
>> + print_int(PRINT_ANY,
>> + "proto",
>> + "proto %d ",
>> + rta_getattr_u8(tb[IFLA_HSR_PROTOCOL]));
>
> Since this unsigned value, you probably want to use print_uint, or print_hhu.
> Also please put as many arguments on one line that will fit in 80 (to 90) characters.
>
> if (tb[IFLA_HSR_PROTOCOL])
> print_hhu(PRINT_ANY, "proto", "proto %hhu ",
> rta_getattr_u8(tb[IFLA_HSR_PROTOCOL]));
>
Ok. Will send v5 shortly for this.
--
Murali Karicheri
Texas Instruments