From f94142284d0e1e9e935468ad3580bda0baa47bf1 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 29 Nov 2018 12:35:51 +0100 Subject: platform: don't consult cache before invoking netlink operation 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? --- src/platform/nm-platform.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 0e0acf311..e11970700 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); } -- cgit v1.2.3