netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: David Ahern <dsahern@kernel.org>
To: stephen@networkplumber.org
Cc: netdev@vger.kernel.org, David Ahern <dsahern@gmail.com>
Subject: [PATCH iproute2-next 2/3] ip link: Drop cache entry on name changes
Date: Mon,  7 Jan 2019 14:55:51 -0800	[thread overview]
Message-ID: <20190107225552.8441-3-dsahern@kernel.org> (raw)
In-Reply-To: <20190107225552.8441-1-dsahern@kernel.org>

From: David Ahern <dsahern@gmail.com>

If a link's name is changed remove any entry from the link cache.

Signed-off-by: David Ahern <dsahern@gmail.com>
---
 ip/ip_common.h    |  3 ++-
 ip/iplink.c       | 10 ++++++++--
 ip/iplink_vxcan.c |  3 ++-
 ip/link_veth.c    |  3 ++-
 4 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/ip/ip_common.h b/ip/ip_common.h
index d67575c63c24..ae2b2fb4e314 100644
--- a/ip/ip_common.h
+++ b/ip/ip_common.h
@@ -123,7 +123,8 @@ struct link_util {
 
 struct link_util *get_link_kind(const char *kind);
 
-int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type);
+int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type,
+		 bool *name_change);
 
 /* iplink_bridge.c */
 void br_dump_bridge_id(const struct ifla_bridge_id *id, char *buf, size_t len);
diff --git a/ip/iplink.c b/ip/iplink.c
index b5519201fef7..65838e2b3fe6 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -573,7 +573,8 @@ static int iplink_parse_vf(int vf, int *argcp, char ***argvp,
 	return 0;
 }
 
-int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
+int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type,
+		 bool *name_change)
 {
 	char *name = NULL;
 	char *dev = NULL;
@@ -943,6 +944,8 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
 		dev = name;
 	else if (!strcmp(name, dev))
 		name = dev;
+	else if (name_change)
+		*name_change = true;
 
 	if (dev && addr_len) {
 		int halen = nl_get_ll_addr_len(dev);
@@ -1030,9 +1033,10 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
 		.n.nlmsg_type = cmd,
 		.i.ifi_family = preferred_family,
 	};
+	bool name_change = false;
 	int ret;
 
-	ret = iplink_parse(argc, argv, &req, &type);
+	ret = iplink_parse(argc, argv, &req, &type, &name_change);
 	if (ret < 0)
 		return ret;
 
@@ -1082,6 +1086,8 @@ static int iplink_modify(int cmd, unsigned int flags, int argc, char **argv)
 
 	if (rtnl_talk(&rth, &req.n, NULL) < 0)
 		return -2;
+	else if (name_change)
+		ll_drop_by_index(req.i.ifi_index);
 
 	return 0;
 }
diff --git a/ip/iplink_vxcan.c b/ip/iplink_vxcan.c
index 8b08c9a70c65..bdd372037836 100644
--- a/ip/iplink_vxcan.c
+++ b/ip/iplink_vxcan.c
@@ -56,7 +56,8 @@ static int vxcan_parse_opt(struct link_util *lu, int argc, char **argv,
 
 	n->nlmsg_len += sizeof(struct ifinfomsg);
 
-	err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n, &type);
+	err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n, &type,
+			   NULL);
 	if (err < 0)
 		return err;
 
diff --git a/ip/link_veth.c b/ip/link_veth.c
index 33e8f2b102e7..ef0bc1948323 100644
--- a/ip/link_veth.c
+++ b/ip/link_veth.c
@@ -54,7 +54,8 @@ static int veth_parse_opt(struct link_util *lu, int argc, char **argv,
 
 	n->nlmsg_len += sizeof(struct ifinfomsg);
 
-	err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n, &type);
+	err = iplink_parse(argc - 1, argv + 1, (struct iplink_req *)n, &type,
+			   NULL);
 	if (err < 0)
 		return err;
 
-- 
2.11.0

  parent reply	other threads:[~2019-01-07 22:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-07 22:55 [PATCH iproute2-next 0/3] Improve batch times by caching link lookups David Ahern
2019-01-07 22:55 ` [PATCH iproute2-next 1/3] ll_map: Add function to remove link cache entry by index David Ahern
2019-01-07 22:55 ` David Ahern [this message]
2019-01-08  0:06   ` [PATCH iproute2-next 2/3] ip link: Drop cache entry on name changes Stephen Hemminger
2019-01-08  0:26     ` David Ahern
2019-01-07 22:55 ` [PATCH iproute2-next 3/3] Improve batch times by caching link lookups David Ahern
2019-01-08  0:05   ` Stephen Hemminger
2019-01-08  0:28     ` 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=20190107225552.8441-3-dsahern@kernel.org \
    --to=dsahern@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.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 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).