diff mbox series

[v3] ip-nexthop: support flush by id

Message ID 20210406013323.24618-1-xuchunmei@linux.alibaba.com (mailing list archive)
State Accepted
Delegated to: David Ahern
Headers show
Series [v3] ip-nexthop: support flush by id | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Chunmei Xu April 6, 2021, 1:33 a.m. UTC
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>
---
 ip/ipnexthop.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

Comments

Ido Schimmel April 6, 2021, 12:19 p.m. UTC | #1
On Tue, Apr 06, 2021 at 09:33:23AM +0800, Chunmei Xu wrote:
> 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>

Thanks
David Ahern April 8, 2021, 3:39 p.m. UTC | #2
On 4/5/21 7:33 PM, Chunmei Xu wrote:
> 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>
> ---
>  ip/ipnexthop.c | 20 +++++++++++++++++++-
>  1 file changed, 19 insertions(+), 1 deletion(-)
> 

applied to iproute2-next. Thanks,
diff mbox series

Patch

diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
index 0263307c..e88feaf6 100644
--- a/ip/ipnexthop.c
+++ b/ip/ipnexthop.c
@@ -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;