]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
bridge: Add backup nexthop ID support
authorIdo Schimmel <idosch@nvidia.com>
Wed, 2 Aug 2023 16:41:15 +0000 (19:41 +0300)
committerDavid Ahern <dsahern@kernel.org>
Fri, 4 Aug 2023 15:09:43 +0000 (09:09 -0600)
Extend the bridge and ip utilities to set and show the backup nexthop ID
bridge port attribute. A value of 0 (default) disables the feature, in
which case the attribute is not printed since it is not emitted by the
kernel.

Example:

 # bridge -d link show dev swp1 | grep -o "backup_nhid [0-9]*"
 # bridge -d -j -p link show dev swp1 | jq '.[]["backup_nhid"]'
 null

 # bridge link set dev swp1 backup_nhid 10
 # bridge -d link show dev swp1 | grep -o "backup_nhid [0-9]*"
 backup_nhid 10
 # bridge -d -j -p link show dev swp1 | jq '.[]["backup_nhid"]'
 10

 # bridge link set dev swp1 backup_nhid 0
 # bridge -d link show dev swp1 | grep -o "backup_nhid [0-9]*"
 # bridge -d -j -p link show dev swp1 | jq '.[]["backup_nhid"]'
 null

 # ip -d link show dev swp1 | grep -o "backup_nhid [0-9]*"
 # ip -d -j -p lin show dev swp1 | jq '.[]["linkinfo"]["info_slave_data"]["backup_nhid"]'
 null

 # ip link set dev swp1 type bridge_slave backup_nhid 10
 # ip -d link show dev swp1 | grep -o "backup_nhid [0-9]*"
 backup_nhid 10
 # ip -d -j -p lin show dev swp1 | jq '.[]["linkinfo"]["info_slave_data"]["backup_nhid"]'
 10

 # ip link set dev swp1 type bridge_slave backup_nhid 0
 # ip -d link show dev swp1 | grep -o "backup_nhid [0-9]*"
 # ip -d -j -p lin show dev swp1 | jq '.[]["linkinfo"]["info_slave_data"]["backup_nhid"]'
 null

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
bridge/link.c
ip/iplink_bridge_slave.c
man/man8/bridge.8
man/man8/ip-link.8.in

index af0457b6e04d86c388b960c736f60d95e792f0d6..1c8faa85e7a52b22d3bcd9a4551daab16615c1e4 100644 (file)
@@ -187,6 +187,10 @@ static void print_protinfo(FILE *fp, struct rtattr *attr)
                                     ll_index_to_name(ifidx));
                }
 
+               if (prtb[IFLA_BRPORT_BACKUP_NHID])
+                       print_uint(PRINT_ANY, "backup_nhid", "backup_nhid %u ",
+                                  rta_getattr_u32(prtb[IFLA_BRPORT_BACKUP_NHID]));
+
                if (prtb[IFLA_BRPORT_ISOLATED])
                        print_on_off(PRINT_ANY, "isolated", "isolated %s ",
                                     rta_getattr_u8(prtb[IFLA_BRPORT_ISOLATED]));
@@ -316,6 +320,7 @@ static void usage(void)
                "                               [ mab {on | off} ]\n"
                "                               [ hwmode {vepa | veb} ]\n"
                "                               [ backup_port DEVICE ] [ nobackup_port ]\n"
+               "                               [ backup_nhid NHID ]\n"
                "                               [ self ] [ master ]\n"
                "       bridge link show [dev DEV] [master DEVICE]\n");
        exit(-1);
@@ -334,6 +339,8 @@ static int brlink_modify(int argc, char **argv)
                .ifm.ifi_family = PF_BRIDGE,
        };
        char *d = NULL;
+       bool backup_nhid_set = false;
+       __u32 backup_nhid;
        int backup_port_idx = -1;
        __s8 neigh_suppress = -1;
        __s8 neigh_vlan_suppress = -1;
@@ -498,6 +505,11 @@ static int brlink_modify(int argc, char **argv)
                        }
                } else if (strcmp(*argv, "nobackup_port") == 0) {
                        backup_port_idx = 0;
+               } else if (strcmp(*argv, "backup_nhid") == 0) {
+                       NEXT_ARG();
+                       if (get_u32(&backup_nhid, *argv, 0))
+                               invarg("invalid backup_nhid", *argv);
+                       backup_nhid_set = true;
                } else {
                        usage();
                }
@@ -584,6 +596,10 @@ static int brlink_modify(int argc, char **argv)
                addattr32(&req.n, sizeof(req), IFLA_BRPORT_BACKUP_PORT,
                          backup_port_idx);
 
+       if (backup_nhid_set)
+               addattr32(&req.n, sizeof(req), IFLA_BRPORT_BACKUP_NHID,
+                         backup_nhid);
+
        addattr_nest_end(&req.n, nest);
 
        /* IFLA_AF_SPEC nested attribute. Contains IFLA_BRIDGE_FLAGS that
index 11ab2113fe96d6e1797724b224e36ff461b2b0ea..dc73c86574dacb223b04074820e28c186c63a9f8 100644 (file)
@@ -43,6 +43,7 @@ static void print_explain(FILE *f)
                "                       [ locked {on | off} ]\n"
                "                       [ mab {on | off} ]\n"
                "                       [ backup_port DEVICE ] [ nobackup_port ]\n"
+               "                       [ backup_nhid NHID ]\n"
        );
 }
 
@@ -301,6 +302,10 @@ static void bridge_slave_print_opt(struct link_util *lu, FILE *f,
                print_string(PRINT_ANY, "backup_port", "backup_port %s ",
                             ll_index_to_name(backup_p));
        }
+
+       if (tb[IFLA_BRPORT_BACKUP_NHID])
+               print_uint(PRINT_ANY, "backup_nhid", "backup_nhid %u ",
+                          rta_getattr_u32(tb[IFLA_BRPORT_BACKUP_NHID]));
 }
 
 static void bridge_slave_parse_on_off(char *arg_name, char *arg_val,
@@ -436,6 +441,14 @@ static int bridge_slave_parse_opt(struct link_util *lu, int argc, char **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 (strcmp(*argv, "backup_nhid") == 0) {
+                       __u32 backup_nhid;
+
+                       NEXT_ARG();
+                       if (get_u32(&backup_nhid, *argv, 0))
+                               invarg("backup_nhid is invalid", *argv);
+                       addattr32(n, 1024, IFLA_BRPORT_BACKUP_NHID,
+                                 backup_nhid);
                } else if (matches(*argv, "help") == 0) {
                        explain();
                        return -1;
index e05528199eab809e51f286f4fbb9363c3b5e7448..dd0659d37df2ddc5a63384c28384e6c315b468c3 100644 (file)
@@ -61,6 +61,8 @@ bridge \- show / manipulate bridge addresses and devices
 .B backup_port
 .IR  DEVICE " ] ["
 .BR nobackup_port " ] [ "
+.B backup_nhid
+.IR NHID " ] ["
 .BR self " ] [ " master " ]"
 
 .ti -8
@@ -647,6 +649,13 @@ configured backup port
 .B nobackup_port
 Removes the currently configured backup port
 
+.TP
+.BI backup_nhid " NHID"
+The FDB nexthop object ID (see \fBip-nexthop\fR(8)) to attach to packets being
+redirected to a backup port that has VLAN tunnel mapping enabled (via the
+\fBvlan_tunnel\fR option). Setting a value of 0 (default) has the effect of not
+attaching any ID.
+
 .TP
 .B self
 link setting is configured on specified physical device
index 8f07de9a8a2581c05f17aa89cb6f366aa456d66b..7365d0c6b14f90c396565c34a9959a28d8b2388e 100644 (file)
@@ -2540,7 +2540,10 @@ the following additional arguments are supported:
 ] [
 .BR backup_port " DEVICE"
 ] [
-.BR nobackup_port " ]"
+.BR nobackup_port
+] [
+.BR backup_nhid " NHID"
+]
 
 .in +8
 .sp
@@ -2679,6 +2682,12 @@ configured backup port
 .BR nobackup_port
 - removes the currently configured backup port
 
+.BI backup_nhid " NHID"
+- the FDB nexthop object ID (see \fBip-nexthop\fR(8)) to attach to packets
+being redirected to a backup port that has VLAN tunnel mapping enabled (via the
+\fBvlan_tunnel\fR option). Setting a value of 0 (default) has the effect of not
+attaching any ID.
+
 .in -8
 
 .TP