netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ip-nexthop: support flush by id
@ 2021-04-01  4:03 Chunmei Xu
  2021-04-03  1:17 ` David Ahern
  0 siblings, 1 reply; 2+ messages in thread
From: Chunmei Xu @ 2021-04-01  4:03 UTC (permalink / raw)
  To: idosch, dsahern; +Cc: netdev

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(-)

diff --git a/ip/ipnexthop.c b/ip/ipnexthop.c
index 20cde586..419bcb0a 100644
--- a/ip/ipnexthop.c
+++ b/ip/ipnexthop.c
@@ -460,6 +460,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);
@@ -490,7 +508,7 @@ static int ipnh_list_flush(int argc, char **argv, int action)
 			NEXT_ARG();
 			if (get_unsigned(&id, *argv, 0))
 				invarg("invalid id value", *argv);
-			return ipnh_get_id(id);
+			return ipnh_list_flush_id(id, action);
 		} else if (!matches(*argv, "protocol")) {
 			__u32 proto;
 
-- 
2.27.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] ip-nexthop: support flush by id
  2021-04-01  4:03 [PATCH v2] ip-nexthop: support flush by id Chunmei Xu
@ 2021-04-03  1:17 ` David Ahern
  0 siblings, 0 replies; 2+ messages in thread
From: David Ahern @ 2021-04-03  1:17 UTC (permalink / raw)
  To: Chunmei Xu, idosch; +Cc: netdev

On 3/31/21 10:03 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(-)
> 

this version does not apply to iproute2-next.


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-03  1:17 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-01  4:03 [PATCH v2] ip-nexthop: support flush by id Chunmei Xu
2021-04-03  1:17 ` David Ahern

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).