]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ipaddress: Add support for address metric
authorDavid Ahern <dsahern@gmail.com>
Sun, 27 May 2018 15:10:00 +0000 (08:10 -0700)
committerDavid Ahern <dsahern@gmail.com>
Wed, 30 May 2018 15:20:04 +0000 (08:20 -0700)
Add support for IFA_RT_PRIORITY using the same keywords as iproute for
RTA_PRIORITY.

Signed-off-by: David Ahern <dsahern@gmail.com>
ip/ipaddress.c
man/man8/ip-address.8.in

index 75539e057f6a7b11e70749192c4dd4689730bf1d..6b53b753ead9448299b5509896386c35791e76d2 100644 (file)
@@ -63,7 +63,7 @@ static void usage(void)
        fprintf(stderr, "       ip address {showdump|restore}\n");
        fprintf(stderr, "IFADDR := PREFIX | ADDR peer PREFIX\n");
        fprintf(stderr, "          [ broadcast ADDR ] [ anycast ADDR ]\n");
-       fprintf(stderr, "          [ label IFNAME ] [ scope SCOPE-ID ]\n");
+       fprintf(stderr, "          [ label IFNAME ] [ scope SCOPE-ID ] [ metric METRIC ]\n");
        fprintf(stderr, "SCOPE-ID := [ host | link | global | NUMBER ]\n");
        fprintf(stderr, "FLAG-LIST := [ FLAG-LIST ] FLAG\n");
        fprintf(stderr, "FLAG  := [ permanent | dynamic | secondary | primary |\n");
@@ -1328,6 +1328,10 @@ int print_addrinfo(const struct sockaddr_nl *who, struct nlmsghdr *n,
                                                           rta_tb[IFA_ADDRESS]));
                }
                print_int(PRINT_ANY, "prefixlen", "/%d ", ifa->ifa_prefixlen);
+
+               if (rta_tb[IFA_RT_PRIORITY])
+                       print_uint(PRINT_ANY, "metric", "metric %u ",
+                                  rta_getattr_u32(rta_tb[IFA_RT_PRIORITY]));
        }
 
        if (brief)
@@ -2119,6 +2123,15 @@ static int ipaddr_modify(int cmd, int flags, int argc, char **argv)
                        NEXT_ARG();
                        l = *argv;
                        addattr_l(&req.n, sizeof(req), IFA_LABEL, l, strlen(l)+1);
+               } else if (matches(*argv, "metric") == 0 ||
+                          matches(*argv, "priority") == 0 ||
+                          matches(*argv, "preference") == 0) {
+                       __u32 metric;
+
+                       NEXT_ARG();
+                       if (get_u32(&metric, *argv, 0))
+                               invarg("\"metric\" value is invalid\n", *argv);
+                       addattr32(&req.n, sizeof(req), IFA_RT_PRIORITY, metric);
                } else if (matches(*argv, "valid_lft") == 0) {
                        if (valid_lftp)
                                duparg("valid_lft", *argv);
index 7ebf0bc98dcd77b46b3037cb70117ed7707de362..c3861b3725ccbd5db876dcf672beb6f46126a72e 100644 (file)
@@ -27,6 +27,8 @@ ip-address \- protocol address management
 .IR IFNAME " ] [ "
 .B  scope
 .IR SCOPE-ID " ] [ "
+.B  metric
+.IR METRIC " ] [ "
 .B  to
 .IR PREFIX " ] [ " FLAG-LIST " ] [ "
 .B  label
@@ -214,6 +216,10 @@ valid inside this site.
 - the address is valid only inside this host.
 .in -8
 
+.TP
+.BI metric " NUMBER"
+priority of prefix route associated with address.
+
 .TP
 .BI valid_lft " LFT"
 the valid lifetime of this address; see section 5.5.4 of