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?
This commit is contained in:
Thomas Haller 2018-11-29 12:35:51 +01:00
parent 945c904f95
commit f94142284d

View file

@ -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);
}