]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
ip-nexthop: support flush by id
authorChunmei Xu <xuchunmei@linux.alibaba.com>
Tue, 6 Apr 2021 01:33:23 +0000 (09:33 +0800)
committerDavid Ahern <dsahern@kernel.org>
Thu, 8 Apr 2021 15:38:58 +0000 (15:38 +0000)
since id is unique for nexthop, it is heavy to dump all nexthops.
use existing delete_nexthop to support flush by id

Signed-off-by: Chunmei Xu <xuchunmei@linux.alibaba.com>
Reviewed-by: Ido Schimmel <idosch@nvidia.com>
Tested-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David Ahern <dsahern@kernel.org>
ip/ipnexthop.c

index 0263307c49df2149e06a829ea129429cfdb9e514..e88feaf6afe7eb3447673a110d348a2a454a204f 100644 (file)
@@ -740,6 +740,24 @@ static int ipnh_get_id(__u32 id)
        return 0;
 }
 
+static int ipnh_list_flush_id(__u32 id, int action)
+{
+       int err;
+
+       if (action == IPNH_LIST)
+               return ipnh_get_id(id);
+
+       if (rtnl_open(&rth_del, 0) < 0) {
+               fprintf(stderr, "Cannot open rtnetlink\n");
+               return EXIT_FAILURE;
+       }
+
+       err = delete_nexthop(id);
+       rtnl_close(&rth_del);
+
+       return err;
+}
+
 static int ipnh_list_flush(int argc, char **argv, int action)
 {
        unsigned int all = (argc == 0);
@@ -766,7 +784,7 @@ static int ipnh_list_flush(int argc, char **argv, int action)
                                invarg("VRF does not exist\n", *argv);
                } else if (!strcmp(*argv, "id")) {
                        NEXT_ARG();
-                       return ipnh_get_id(ipnh_parse_id(*argv));
+                       return ipnh_list_flush_id(ipnh_parse_id(*argv), action);
                } else if (!matches(*argv, "protocol")) {
                        __u32 proto;