]> git.proxmox.com Git - mirror_iproute2.git/blobdiff - ip/ipnexthop.c
Merge branch 'main' into next
[mirror_iproute2.git] / ip / ipnexthop.c
index 97f09e74d01b5311f4379fbe60b48bb806b10f3b..22c664918fccfd7b3ce9979317e6b420ff43e582 100644 (file)
@@ -19,6 +19,8 @@ static struct {
        unsigned int groups;
        unsigned int ifindex;
        unsigned int master;
+       unsigned int proto;
+       unsigned int fdb;
 } filter;
 
 enum {
@@ -34,11 +36,11 @@ static void usage(void) __attribute__((noreturn));
 static void usage(void)
 {
        fprintf(stderr,
-               "Usage: ip nexthop { list | flush } SELECTOR\n"
+               "Usage: ip nexthop { list | flush } [ protocol ID ] SELECTOR\n"
                "       ip nexthop { add | replace } id ID NH [ protocol ID ]\n"
                "       ip nexthop { get| del } id ID\n"
                "SELECTOR := [ id ID ] [ dev DEV ] [ vrf NAME ] [ master DEV ]\n"
-               "            [ groups ]\n"
+               "            [ groups ] [ fdb ]\n"
                "NH := { blackhole | [ via ADDRESS ] [ dev DEV ] [ onlink ]\n"
                "      [ encap ENCAPTYPE ENCAPHDR ] | group GROUP ] }\n"
                "GROUP := [ id[,weight]>/<id[,weight]>/... ]\n"
@@ -58,13 +60,19 @@ static int nh_dump_filter(struct nlmsghdr *nlh, int reqlen)
        }
 
        if (filter.groups) {
-               addattr_l(nlh, reqlen, NHA_GROUPS, NULL, 0);
+               err = addattr_l(nlh, reqlen, NHA_GROUPS, NULL, 0);
                if (err)
                        return err;
        }
 
        if (filter.master) {
-               addattr32(nlh, reqlen, NHA_MASTER, filter.master);
+               err = addattr32(nlh, reqlen, NHA_MASTER, filter.master);
+               if (err)
+                       return err;
+       }
+
+       if (filter.fdb) {
+               err = addattr_l(nlh, reqlen, NHA_FDB, NULL, 0);
                if (err)
                        return err;
        }
@@ -109,6 +117,9 @@ static int flush_nexthop(struct nlmsghdr *nlh, void *arg)
                return -1;
        }
 
+       if (filter.proto && nhm->nh_protocol != filter.proto)
+               return 0;
+
        parse_rtattr(tb, NHA_MAX, RTM_NHA(nhm), len);
        if (tb[NHA_ID])
                id = rta_getattr_u32(tb[NHA_ID]);
@@ -186,6 +197,7 @@ static void print_nh_group(FILE *fp, const struct rtattr *grps_attr)
 
                close_json_object();
        }
+       print_string(PRINT_FP, NULL, "%s", " ");
        close_json_array(PRINT_JSON, NULL);
 }
 
@@ -212,11 +224,14 @@ int print_nexthop(struct nlmsghdr *n, void *arg)
                return -1;
        }
 
+       if (filter.proto && filter.proto != nhm->nh_protocol)
+               return 0;
+
        parse_rtattr(tb, NHA_MAX, RTM_NHA(nhm), len);
 
        open_json_object(NULL);
 
-       if (n->nlmsg_type == RTM_DELROUTE)
+       if (n->nlmsg_type == RTM_DELNEXTHOP)
                print_bool(PRINT_ANY, "deleted", "Deleted ", true);
 
        if (tb[NHA_ID])
@@ -241,7 +256,7 @@ int print_nexthop(struct nlmsghdr *n, void *arg)
        }
 
        if (tb[NHA_BLACKHOLE])
-               print_null(PRINT_ANY, "blackhole", "blackhole", NULL);
+               print_null(PRINT_ANY, "blackhole", "blackhole ", NULL);
 
        if (nhm->nh_protocol != RTPROT_UNSPEC || show_details > 0) {
                print_string(PRINT_ANY, "protocol", "proto %s ",
@@ -251,6 +266,9 @@ int print_nexthop(struct nlmsghdr *n, void *arg)
        if (tb[NHA_OIF])
                print_rt_flags(fp, nhm->nh_flags);
 
+       if (tb[NHA_FDB])
+               print_null(PRINT_ANY, "fdb", "fdb", NULL);
+
        print_string(PRINT_FP, NULL, "%s", "\n");
        close_json_object();
        fflush(fp);
@@ -377,6 +395,8 @@ static int ipnh_modify(int cmd, unsigned int flags, int argc, char **argv)
                        addattr_l(&req.n, sizeof(req), NHA_BLACKHOLE, NULL, 0);
                        if (req.nhm.nh_family == AF_UNSPEC)
                                req.nhm.nh_family = AF_INET;
+               } else if (!strcmp(*argv, "fdb")) {
+                       addattr_l(&req.n, sizeof(req), NHA_FDB, NULL, 0);
                } else if (!strcmp(*argv, "onlink")) {
                        nh_flags |= RTNH_F_ONLINK;
                } else if (!strcmp(*argv, "group")) {
@@ -472,6 +492,15 @@ static int ipnh_list_flush(int argc, char **argv, int action)
                        if (get_unsigned(&id, *argv, 0))
                                invarg("invalid id value", *argv);
                        return ipnh_get_id(id);
+               } else if (!matches(*argv, "protocol")) {
+                       __u32 proto;
+
+                       NEXT_ARG();
+                       if (get_unsigned(&proto, *argv, 0))
+                               invarg("invalid protocol value", *argv);
+                       filter.proto = proto;
+               } else if (!matches(*argv, "fdb")) {
+                       filter.fdb = 1;
                } else if (matches(*argv, "help") == 0) {
                        usage();
                } else {