summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-11-29 12:35:51 +0100
committerThomas Haller <thaller@redhat.com>2018-11-30 14:39:14 +0100
commitd851d86719205b0b89a53e3ae4d03a2ff99b5c50 (patch)
tree07ca4090e848806f627cd544c55d57a315000193
parent575ee05eb077f0235d73b5798973aafb510c7d6d (diff)
downloadNetworkManager-th/platform-link-get-cleanup.tar.gz
platform: don't consult cache before invoking netlink operationth/platform-link-get-cleanup
Checking whether the link exists in the cache, before talking to kernel serves no purpose. - in all cases, the caller already has a good indication that the link in fact exists. That is, because the caller makes decisions on what to do, based on what platform told it earlier. Thus, the check usually succeeds anyway. - in the unexpected case it doesn't succeed, we - should not silently return without logging at least a message - we possibly still want to send the netlink message to kernel, just to have it fail. Note that the ifindex is indeed the identifier for the link, so there is no danger of accidentally killing the wrong link. Well, theoretically there is, because the kernel's ifindex counter can wrap or get reused when moving links between namespaces. But checking the cache would not protect against that anyway! Worst case, the cache would already have the impostor link and would not prevent from doing the wrong thing. After all, they do have the same identifier, so how would we know that this is in fact a different link?
-rw-r--r--src/platform/nm-platform.c12
1 files changed, 1 insertions, 11 deletions
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 0e0acf3114..e119707009 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -971,13 +971,9 @@ nm_platform_link_dummy_add (NMPlatform *self,
gboolean
nm_platform_link_delete (NMPlatform *self, int ifindex)
{
- const NMPlatformLink *pllink;
-
_CHECK_SELF (self, klass, FALSE);
- pllink = nm_platform_link_get (self, ifindex);
- if (!pllink)
- return FALSE;
+ g_return_val_if_fail (ifindex > 0, FALSE);
_LOG3D ("link: deleting");
return klass->link_delete (self, ifindex);
@@ -994,17 +990,11 @@ nm_platform_link_delete (NMPlatform *self, int ifindex)
gboolean
nm_platform_link_set_netns (NMPlatform *self, int ifindex, int netns_fd)
{
- const NMPlatformLink *pllink;
-
_CHECK_SELF (self, klass, FALSE);
g_return_val_if_fail (ifindex > 0, FALSE);
g_return_val_if_fail (netns_fd > 0, FALSE);
- pllink = nm_platform_link_get (self, ifindex);
- if (!pllink)
- return FALSE;
-
_LOG3D ("link: move link to network namespace with fd %d", netns_fd);
return klass->link_set_netns (self, ifindex, netns_fd);
}