All of lore.kernel.org
 help / color / mirror / Atom feed
From: Chunmei Xu <xuchunmei@linux.alibaba.com>
To: idosch@idosch.org, dsahern@gmail.com
Cc: netdev@vger.kernel.org
Subject: [PATCH v3] ip-nexthop: support flush by id
Date: Tue,  6 Apr 2021 09:33:23 +0800	[thread overview]
Message-ID: <20210406013323.24618-1-xuchunmei@linux.alibaba.com> (raw)

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 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;
 
-- 
2.27.0


             reply	other threads:[~2021-04-06  1:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-06  1:33 Chunmei Xu [this message]
2021-04-06 12:19 ` [PATCH v3] ip-nexthop: support flush by id Ido Schimmel
2021-04-08 15:39 ` David Ahern

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210406013323.24618-1-xuchunmei@linux.alibaba.com \
    --to=xuchunmei@linux.alibaba.com \
    --cc=dsahern@gmail.com \
    --cc=idosch@idosch.org \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.