]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - ip/iplink_bridge_slave.c
vdpa: add .gitignore
[mirror_iproute2.git] / ip / iplink_bridge_slave.c
index fdf8e89943e3c28daf7f5344fe5776a75ce02d3e..717875864b18ba73320bce3fc66e1849f9bc3940 100644 (file)
@@ -23,20 +23,26 @@ static void print_explain(FILE *f)
 {
        fprintf(f,
                "Usage: ... bridge_slave [ fdb_flush ]\n"
-               "                        [ state STATE ]\n"
-               "                        [ priority PRIO ]\n"
-               "                        [ cost COST ]\n"
-               "                        [ guard {on | off} ]\n"
-               "                        [ hairpin {on | off} ]\n"
-               "                        [ fastleave {on | off} ]\n"
-               "                        [ root_block {on | off} ]\n"
-               "                        [ learning {on | off} ]\n"
-               "                        [ flood {on | off} ]\n"
-               "                        [ proxy_arp {on | off} ]\n"
-               "                        [ proxy_arp_wifi {on | off} ]\n"
-               "                        [ mcast_router MULTICAST_ROUTER ]\n"
-               "                        [ mcast_fast_leave {on | off} ]\n"
-               "                        [ mcast_flood {on | off} ]\n"
+               "                       [ state STATE ]\n"
+               "                       [ priority PRIO ]\n"
+               "                       [ cost COST ]\n"
+               "                       [ guard {on | off} ]\n"
+               "                       [ hairpin {on | off} ]\n"
+               "                       [ fastleave {on | off} ]\n"
+               "                       [ root_block {on | off} ]\n"
+               "                       [ learning {on | off} ]\n"
+               "                       [ flood {on | off} ]\n"
+               "                       [ proxy_arp {on | off} ]\n"
+               "                       [ proxy_arp_wifi {on | off} ]\n"
+               "                       [ mcast_router MULTICAST_ROUTER ]\n"
+               "                       [ mcast_fast_leave {on | off} ]\n"
+               "                       [ mcast_flood {on | off} ]\n"
+               "                       [ mcast_to_unicast {on | off} ]\n"
+               "                       [ group_fwd_mask MASK ]\n"
+               "                       [ neigh_suppress {on | off} ]\n"
+               "                       [ vlan_tunnel {on | off} ]\n"
+               "                       [ isolated {on | off} ]\n"
+               "                       [ backup_port DEVICE ] [ nobackup_port ]\n"
        );
 }
 
@@ -53,6 +59,12 @@ static const char *port_states[] = {
        [BR_STATE_BLOCKING] = "blocking",
 };
 
+static const char *fwd_mask_tbl[16] = {
+       [0]     = "stp",
+       [2]     = "lacp",
+       [14]    = "lldp"
+};
+
 static void print_portstate(FILE *f, __u8 state)
 {
        if (state <= BR_STATE_BLOCKING)
@@ -64,29 +76,6 @@ static void print_portstate(FILE *f, __u8 state)
                print_int(PRINT_ANY, "state_index", "state (%d) ", state);
 }
 
-static void _print_onoff(FILE *f, char *json_flag, char *flag, __u8 val)
-{
-       if (is_json_context())
-               print_bool(PRINT_JSON, flag, NULL, val);
-       else
-               fprintf(f, "%s %s ", flag, val ? "on" : "off");
-}
-
-static void _print_hex(FILE *f,
-                      const char *json_attr,
-                      const char *attr,
-                      __u16 val)
-{
-       if (is_json_context()) {
-               SPRINT_BUF(b1);
-
-               snprintf(b1, sizeof(b1), "0x%x", val);
-               print_string(PRINT_JSON, json_attr, NULL, b1);
-       } else {
-               fprintf(f, "%s 0x%x ", attr, val);
-       }
-}
-
 static void _print_timer(FILE *f, const char *attr, struct rtattr *timer)
 {
        struct timeval tv;
@@ -104,6 +93,28 @@ static void _print_timer(FILE *f, const char *attr, struct rtattr *timer)
        }
 }
 
+static void _bitmask2str(__u16 bitmask, char *dst, size_t dst_size,
+                        const char **tbl)
+{
+       int len, i;
+
+       for (i = 0, len = 0; bitmask; i++, bitmask >>= 1) {
+               if (bitmask & 0x1) {
+                       if (tbl[i])
+                               len += snprintf(dst + len, dst_size - len, "%s,",
+                                               tbl[i]);
+                       else
+                               len += snprintf(dst + len, dst_size - len, "0x%x,",
+                                               (1 << i));
+               }
+       }
+
+       if (!len)
+               snprintf(dst, dst_size, "0x0");
+       else
+               dst[len - 1] = 0;
+}
+
 static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
                                   struct rtattr *tb[])
 {
@@ -126,35 +137,35 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
                          rta_getattr_u32(tb[IFLA_BRPORT_COST]));
 
        if (tb[IFLA_BRPORT_MODE])
-               _print_onoff(f, "mode", "hairpin",
+               print_on_off(PRINT_ANY, "hairpin", "hairpin %s ",
                             rta_getattr_u8(tb[IFLA_BRPORT_MODE]));
 
        if (tb[IFLA_BRPORT_GUARD])
-               _print_onoff(f, "guard", "guard",
+               print_on_off(PRINT_ANY, "guard", "guard %s ",
                             rta_getattr_u8(tb[IFLA_BRPORT_GUARD]));
 
        if (tb[IFLA_BRPORT_PROTECT])
-               _print_onoff(f, "protect", "root_block",
+               print_on_off(PRINT_ANY, "root_block", "root_block %s ",
                             rta_getattr_u8(tb[IFLA_BRPORT_PROTECT]));
 
        if (tb[IFLA_BRPORT_FAST_LEAVE])
-               _print_onoff(f, "fast_leave", "fastleave",
+               print_on_off(PRINT_ANY, "fastleave", "fastleave %s ",
                             rta_getattr_u8(tb[IFLA_BRPORT_FAST_LEAVE]));
 
        if (tb[IFLA_BRPORT_LEARNING])
-               _print_onoff(f, "learning", "learning",
+               print_on_off(PRINT_ANY, "learning", "learning %s ",
                             rta_getattr_u8(tb[IFLA_BRPORT_LEARNING]));
 
        if (tb[IFLA_BRPORT_UNICAST_FLOOD])
-               _print_onoff(f, "unicast_flood", "flood",
+               print_on_off(PRINT_ANY, "flood", "flood %s ",
                             rta_getattr_u8(tb[IFLA_BRPORT_UNICAST_FLOOD]));
 
        if (tb[IFLA_BRPORT_ID])
-               _print_hex(f, "id", "port_id",
-                          rta_getattr_u16(tb[IFLA_BRPORT_ID]));
+               print_0xhex(PRINT_ANY, "id", "port_id %#llx ",
+                           rta_getattr_u16(tb[IFLA_BRPORT_ID]));
 
        if (tb[IFLA_BRPORT_NO])
-               _print_hex(f, "no", "port_no",
+               print_0xhex(PRINT_ANY, "no", "port_no %#llx ",
                           rta_getattr_u16(tb[IFLA_BRPORT_NO]));
 
        if (tb[IFLA_BRPORT_DESIGNATED_PORT])
@@ -214,11 +225,11 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
                           rta_getattr_u8(tb[IFLA_BRPORT_CONFIG_PENDING]));
 
        if (tb[IFLA_BRPORT_PROXYARP])
-               _print_onoff(f, "proxyarp", "proxy_arp",
+               print_on_off(PRINT_ANY, "proxy_arp", "proxy_arp %s ",
                             rta_getattr_u8(tb[IFLA_BRPORT_PROXYARP]));
 
        if (tb[IFLA_BRPORT_PROXYARP_WIFI])
-               _print_onoff(f, "proxyarp_wifi", "proxy_arp_wifi",
+               print_on_off(PRINT_ANY, "proxy_arp_wifi", "proxy_arp_wifi %s ",
                             rta_getattr_u8(tb[IFLA_BRPORT_PROXYARP_WIFI]));
 
        if (tb[IFLA_BRPORT_MULTICAST_ROUTER])
@@ -236,26 +247,53 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
                             rta_getattr_u8(tb[IFLA_BRPORT_FAST_LEAVE]) ? "on" : "off");
 
        if (tb[IFLA_BRPORT_MCAST_FLOOD])
-               _print_onoff(f, "mcast_flood", "mcast_flood",
+               print_on_off(PRINT_ANY, "mcast_flood", "mcast_flood %s ",
                             rta_getattr_u8(tb[IFLA_BRPORT_MCAST_FLOOD]));
 
+       if (tb[IFLA_BRPORT_MCAST_TO_UCAST])
+               print_on_off(PRINT_ANY, "mcast_to_unicast", "mcast_to_unicast %s ",
+                            rta_getattr_u8(tb[IFLA_BRPORT_MCAST_TO_UCAST]));
+
        if (tb[IFLA_BRPORT_NEIGH_SUPPRESS])
-               _print_onoff(f, "neigh_suppress", "neigh_suppress",
+               print_on_off(PRINT_ANY, "neigh_suppress", "neigh_suppress %s ",
                             rta_getattr_u8(tb[IFLA_BRPORT_NEIGH_SUPPRESS]));
+
+       if (tb[IFLA_BRPORT_GROUP_FWD_MASK]) {
+               char convbuf[256];
+               __u16 fwd_mask;
+
+               fwd_mask = rta_getattr_u16(tb[IFLA_BRPORT_GROUP_FWD_MASK]);
+               print_0xhex(PRINT_ANY, "group_fwd_mask",
+                           "group_fwd_mask %#llx ", fwd_mask);
+               _bitmask2str(fwd_mask, convbuf, sizeof(convbuf), fwd_mask_tbl);
+               print_string(PRINT_ANY, "group_fwd_mask_str",
+                            "group_fwd_mask_str %s ", convbuf);
+       }
+
+       if (tb[IFLA_BRPORT_VLAN_TUNNEL])
+               print_on_off(PRINT_ANY, "vlan_tunnel", "vlan_tunnel %s ",
+                            rta_getattr_u8(tb[IFLA_BRPORT_VLAN_TUNNEL]));
+
+       if (tb[IFLA_BRPORT_ISOLATED])
+               print_on_off(PRINT_ANY, "isolated", "isolated %s ",
+                            rta_getattr_u8(tb[IFLA_BRPORT_ISOLATED]));
+
+       if (tb[IFLA_BRPORT_BACKUP_PORT]) {
+               int backup_p = rta_getattr_u32(tb[IFLA_BRPORT_BACKUP_PORT]);
+
+               print_string(PRINT_ANY, "backup_port", "backup_port %s ",
+                            ll_index_to_name(backup_p));
+       }
 }
 
 static void bridge_slave_parse_on_off(char *arg_name, char *arg_val,
                                      struct nlmsghdr *n, int type)
 {
-       __u8 val;
-
-       if (strcmp(arg_val, "on") == 0)
-               val = 1;
-       else if (strcmp(arg_val, "off") == 0)
-               val = 0;
-       else
-               invarg("should be \"on\" or \"off\"", arg_name);
+       int ret;
+       __u8 val = parse_on_off(arg_name, arg_val, &ret);
 
+       if (ret)
+               exit(1);
        addattr8(n, 1024, type, val);
 }
 
@@ -312,6 +350,10 @@ static int bridge_slave_parse_opt(struct link_util *lu, int argc, char **argv,
                        NEXT_ARG();
                        bridge_slave_parse_on_off("mcast_flood", *argv, n,
                                                  IFLA_BRPORT_MCAST_FLOOD);
+               } else if (matches(*argv, "mcast_to_unicast") == 0) {
+                       NEXT_ARG();
+                       bridge_slave_parse_on_off("mcast_to_unicast", *argv, n,
+                                                 IFLA_BRPORT_MCAST_TO_UCAST);
                } else if (matches(*argv, "proxy_arp") == 0) {
                        NEXT_ARG();
                        bridge_slave_parse_on_off("proxy_arp", *argv, n,
@@ -336,6 +378,31 @@ static int bridge_slave_parse_opt(struct link_util *lu, int argc, char **argv,
                        NEXT_ARG();
                        bridge_slave_parse_on_off("neigh_suppress", *argv, n,
                                                  IFLA_BRPORT_NEIGH_SUPPRESS);
+               } else if (matches(*argv, "group_fwd_mask") == 0) {
+                       __u16 mask;
+
+                       NEXT_ARG();
+                       if (get_u16(&mask, *argv, 0))
+                               invarg("invalid group_fwd_mask", *argv);
+                       addattr16(n, 1024, IFLA_BRPORT_GROUP_FWD_MASK, mask);
+               } else if (matches(*argv, "vlan_tunnel") == 0) {
+                       NEXT_ARG();
+                       bridge_slave_parse_on_off("vlan_tunnel", *argv, n,
+                                                 IFLA_BRPORT_VLAN_TUNNEL);
+               } else if (matches(*argv, "isolated") == 0) {
+                       NEXT_ARG();
+                       bridge_slave_parse_on_off("isolated", *argv, n,
+                                                 IFLA_BRPORT_ISOLATED);
+               } else if (matches(*argv, "backup_port") == 0) {
+                       int ifindex;
+
+                       NEXT_ARG();
+                       ifindex = ll_name_to_index(*argv);
+                       if (!ifindex)
+                               invarg("Device does not exist\n", *argv);
+                       addattr32(n, 1024, IFLA_BRPORT_BACKUP_PORT, ifindex);
+               } else if (matches(*argv, "nobackup_port") == 0) {
+                       addattr32(n, 1024, IFLA_BRPORT_BACKUP_PORT, 0);
                } else if (matches(*argv, "help") == 0) {
                        explain();
                        return -1;