Skip to contentSkip to conversation

lib: suppress error msg when filling the cache

PATCH In review Nicolas Dichtel 3 participants 5 messages May 24, 2019 – May 30, 2019

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib: suppress error msg when filling the cache

Before the patch:

$ ip netns add foo
$ ip link add name veth1 address 2a:a5:5c:b9:52:89 type veth peer name veth2 address 2a:a5:5c:b9:53:90 netns foo
RTNETLINK answers: No such device
RTNETLINK answers: No such device

But the command was successful. This may break script. Let's remove those error messages.

Fixes 55870dfe7f8b ("Improve batch and dump times by caching link lookups")
---
 lib/ll_map.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/ll_map.c +1 -1
index 2d7b65dcb8f7..e0ed54bf77c9 100644
@@ -177,7 +177,7 @@ static int ll_link_get(const char *name, int index)
 		addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name,
 			  strlen(name) + 1);
 
-	if (rtnl_talk(&rth, &req.n, &answer) < 0)
+	if (rtnl_talk_suppress_rtnl_errmsg(&rth, &req.n, &answer) < 0)
 		goto out;
 
 	/* add entry to cache */
Signature · 1 line
2.21.0
#1 lore raw
Quoted 22 lines · Nicolas Dichtel

Before the patch:

$ ip netns add foo
$ ip link add name veth1 address 2a:a5:5c:b9:52:89 type veth peer name veth2 address 2a:a5:5c:b9:53:90 netns foo
RTNETLINK answers: No such device
RTNETLINK answers: No such device

But the command was successful. This may break script. Let's remove those error messages.

Fixes 55870dfe7f8b ("Improve batch and dump times by caching link lookups")
---
 lib/ll_map.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/ll_map.c +0 -0
index 2d7b65dcb8f7..e0ed54bf77c9 100644

lib/ll_map.c static int ll_link_get(const char *name, int index) · line 183

Quoted 8 lines
lib/ll_map.c +1 -1
@@ -177,7 +177,7 @@ static int ll_link_get(const char *name, int index)
 		addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name,
 			  strlen(name) + 1);
 
-	if (rtnl_talk(&rth, &req.n, &answer) < 0)
+	if (rtnl_talk_suppress_rtnl_errmsg(&rth, &req.n, &answer) < 0)
 		goto out;
 
 	/* add entry to cache */

In general, ll_link_get suppressing the error message seems like the right thing to do.

For the example above, seems like nl_get_ll_addr_len is the cause of the error messages, and it should not be called for this use case (NEWLINK with NLM_F_CREATE set)

#2 lore raw
Quoted 35 lines · On Fri, 24 May 2019 10:08:28 -0600 David Ahern <[email protected]> wrote:
Quoted 22 lines · Nicolas Dichtel

Before the patch:

$ ip netns add foo
$ ip link add name veth1 address 2a:a5:5c:b9:52:89 type veth peer name veth2 address 2a:a5:5c:b9:53:90 netns foo
RTNETLINK answers: No such device
RTNETLINK answers: No such device

But the command was successful. This may break script. Let's remove those error messages.

Fixes 55870dfe7f8b ("Improve batch and dump times by caching link lookups")
---
 lib/ll_map.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/ll_map.c +0 -0
index 2d7b65dcb8f7..e0ed54bf77c9 100644

lib/ll_map.c static int ll_link_get(const char *name, int index) · line 183

Quoted 8 lines
lib/ll_map.c +1 -1
@@ -177,7 +177,7 @@ static int ll_link_get(const char *name, int index)
 		addattr_l(&req.n, sizeof(req), IFLA_IFNAME, name,
 			  strlen(name) + 1);
 
-	if (rtnl_talk(&rth, &req.n, &answer) < 0)
+	if (rtnl_talk_suppress_rtnl_errmsg(&rth, &req.n, &answer) < 0)
 		goto out;
 
 	/* add entry to cache */

In general, ll_link_get suppressing the error message seems like the right thing to do.

Quoted 3 lines

For the example above, seems like nl_get_ll_addr_len is the cause of the error messages, and it should not be called for this use case (NEWLINK with NLM_F_CREATE set)

Agree. I merged the patch to ll_link_get but send another to avoid the cause of unnecessary query.

#3 lore raw

PATCH 1/1 iplink: don't try to get ll addr len when creating an iface

It will obviously fail. This is a follow up of the commit 757837230a65 ("lib: suppress error msg when filling the cache").

---
 ip/iplink.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ip/iplink.c +2 -1
index 7952cb2be364..d275efa9d087 100644
@@ -945,7 +945,8 @@ int iplink_parse(int argc, char **argv, struct iplink_req *req, char **type)
 	else if (!strcmp(name, dev))
 		name = dev;
 
-	if (dev && addr_len) {
+	if (dev && addr_len &&
+	    !(req->n.nlmsg_flags & NLM_F_CREATE)) {
 		int halen = nl_get_ll_addr_len(dev);
 
 		if (halen >= 0 && halen != addr_len) {
Signature · 1 line
2.21.0