]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - ip/iplink_hsr.c
Merge branch 'iproute2-master' into iproute2-next
[mirror_iproute2.git] / ip / iplink_hsr.c
index 65fbec8e5e79febc3f1a225be783a3712afe6354..c673ccf7727197a8d97ba2a90427f7a7ee774c04 100644 (file)
@@ -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 ]\n"
+"\t[ supervision ADDR-BYTE ] [version VERSION]\n"
 "\n"
 "NAME\n"
 "      name of new hsr device (e.g. hsr0)\n"
@@ -33,7 +33,9 @@ static void print_usage(FILE *f)
 "      the two slave devices bound to the HSR device\n"
 "ADDR-BYTE\n"
 "      0-255; the last byte of the multicast address used for HSR supervision\n"
-"      frames (default = 0)\n");
+"      frames (default = 0)\n"
+"VERSION\n"
+"      0,1; the protocol version to be used. (default = 0)\n");
 }
 
 static void usage(void)
@@ -46,6 +48,7 @@ static int hsr_parse_opt(struct link_util *lu, int argc, char **argv,
 {
        int ifindex;
        unsigned char multicast_spec;
+       unsigned char protocol_version;
 
        while (argc > 0) {
                if (matches(*argv, "supervision") == 0) {
@@ -54,6 +57,13 @@ static int hsr_parse_opt(struct link_util *lu, int argc, char **argv,
                                invarg("ADDR-BYTE is invalid", *argv);
                        addattr_l(n, 1024, IFLA_HSR_MULTICAST_SPEC,
                                  &multicast_spec, 1);
+               } else if (matches(*argv, "version") == 0) {
+                       NEXT_ARG();
+                       if (!(get_u8(&protocol_version, *argv, 0) == 0 ||
+                             get_u8(&protocol_version, *argv, 0) == 1))
+                               invarg("version is invalid", *argv);
+                       addattr_l(n, 1024, IFLA_HSR_VERSION,
+                                 &protocol_version, 1);
                } else if (matches(*argv, "slave1") == 0) {
                        NEXT_ARG();
                        ifindex = ll_name_to_index(*argv);
@@ -100,30 +110,36 @@ static void hsr_print_opt(struct link_util *lu, FILE *f, struct rtattr *tb[])
            RTA_PAYLOAD(tb[IFLA_HSR_SUPERVISION_ADDR]) < ETH_ALEN)
                return;
 
-       fprintf(f, "slave1 ");
        if (tb[IFLA_HSR_SLAVE1])
-               fprintf(f, "%s ",
-                       ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE1])));
+               print_string(PRINT_ANY,
+                            "slave1",
+                            "slave1 %s ",
+                            ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE1])));
        else
-               fprintf(f, "<none> ");
+               print_null(PRINT_ANY, "slave1", "slave1 %s ", "<none>");
 
-       fprintf(f, "slave2 ");
        if (tb[IFLA_HSR_SLAVE2])
-               fprintf(f, "%s ",
-                       ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE2])));
+               print_string(PRINT_ANY,
+                            "slave2",
+                            "slave2 %s ",
+                            ll_index_to_name(rta_getattr_u32(tb[IFLA_HSR_SLAVE2])));
        else
-               fprintf(f, "<none> ");
+               print_null(PRINT_ANY, "slave2", "slave2 %s ", "<none>");
 
        if (tb[IFLA_HSR_SEQ_NR])
-               fprintf(f, "sequence %d ",
-                       rta_getattr_u16(tb[IFLA_HSR_SEQ_NR]));
+               print_int(PRINT_ANY,
+                         "seq_nr",
+                         "sequence %d ",
+                         rta_getattr_u16(tb[IFLA_HSR_SEQ_NR]));
 
        if (tb[IFLA_HSR_SUPERVISION_ADDR])
-               fprintf(f, "supervision %s ",
-                       ll_addr_n2a(RTA_DATA(tb[IFLA_HSR_SUPERVISION_ADDR]),
-                                   RTA_PAYLOAD(tb[IFLA_HSR_SUPERVISION_ADDR]),
-                                   ARPHRD_VOID,
-                                   b1, sizeof(b1)));
+               print_string(PRINT_ANY,
+                            "supervision_addr",
+                            "supervision %s ",
+                            ll_addr_n2a(RTA_DATA(tb[IFLA_HSR_SUPERVISION_ADDR]),
+                                        RTA_PAYLOAD(tb[IFLA_HSR_SUPERVISION_ADDR]),
+                                        ARPHRD_VOID,
+                                        b1, sizeof(b1)));
 }
 
 static void hsr_print_help(struct link_util *lu, int argc, char **argv,
@@ -134,7 +150,7 @@ static void hsr_print_help(struct link_util *lu, int argc, char **argv,
 
 struct link_util hsr_link_util = {
        .id             = "hsr",
-       .maxattr        = IFLA_VLAN_MAX,
+       .maxattr        = IFLA_HSR_MAX,
        .parse_opt      = hsr_parse_opt,
        .print_opt      = hsr_print_opt,
        .print_help     = hsr_print_help,