platform: do not check for _exists() before deleting addresses and routes

Before, nm_platform_ip4_address_exists(), et al. look into the cache to see
whether the address/route already exists and returned an error if it
did.

Change the semantic of the delete functions, to return success in case of
"nothing to delete". Also always try to delete the object in the
kernel. The reason is, that the cache might be out of date and the
caller really wants to delete it. So, to be sure, we always delete.

In most cases the object is actually in the cache (because that is
how the caller came to know that such an object might exist).
In those cases, the lookup was not useful either, because the object
was actually cached.

Signed-off-by: Thomas Haller <thaller@redhat.com>
This commit is contained in:
Thomas Haller
2014-02-13 14:56:38 +01:00
parent 5f5c7284d1
commit 2bc90a5f2d
4 changed files with 20 additions and 48 deletions

View File

@@ -827,7 +827,7 @@ ip4_address_delete (NMPlatform *platform, int ifindex, in_addr_t addr, int plen)
}
}
g_assert_not_reached ();
return TRUE;
}
static gboolean
@@ -850,7 +850,7 @@ ip6_address_delete (NMPlatform *platform, int ifindex, struct in6_addr addr, int
}
}
g_assert_not_reached ();
return TRUE;
}
static gboolean
@@ -1064,11 +1064,11 @@ ip4_route_delete (NMPlatform *platform, int ifindex, in_addr_t network, int plen
NMPlatformIP4Route *route = ip4_route_get (platform, ifindex, network, plen, metric);
NMPlatformIP4Route deleted_route;
g_assert (route);
memcpy (&deleted_route, route, sizeof (deleted_route));
memset (route, 0, sizeof (*route));
g_signal_emit_by_name (platform, NM_PLATFORM_IP4_ROUTE_REMOVED, ifindex, &deleted_route, NM_PLATFORM_REASON_INTERNAL);
if (route) {
memcpy (&deleted_route, route, sizeof (deleted_route));
memset (route, 0, sizeof (*route));
g_signal_emit_by_name (platform, NM_PLATFORM_IP4_ROUTE_REMOVED, ifindex, &deleted_route, NM_PLATFORM_REASON_INTERNAL);
}
return TRUE;
}
@@ -1079,11 +1079,11 @@ ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, in
NMPlatformIP6Route *route = ip6_route_get (platform, ifindex, network, plen, metric);
NMPlatformIP6Route deleted_route;
g_assert (route);
memcpy (&deleted_route, route, sizeof (deleted_route));
memset (route, 0, sizeof (*route));
g_signal_emit_by_name (platform, NM_PLATFORM_IP6_ROUTE_REMOVED, ifindex, &deleted_route, NM_PLATFORM_REASON_INTERNAL);
if (route) {
memcpy (&deleted_route, route, sizeof (deleted_route));
memset (route, 0, sizeof (*route));
g_signal_emit_by_name (platform, NM_PLATFORM_IP6_ROUTE_REMOVED, ifindex, &deleted_route, NM_PLATFORM_REASON_INTERNAL);
}
return TRUE;
}

View File

@@ -1282,13 +1282,6 @@ nm_platform_ip4_address_delete (int ifindex, in_addr_t address, int plen)
g_return_val_if_fail (klass->ip4_address_delete, FALSE);
debug ("address: deleting IPv4 address %s/%d", nm_utils_inet4_ntop (address, NULL), plen);
if (!nm_platform_ip4_address_exists (ifindex, address, plen)) {
debug ("address doesn't exists");
platform->error = NM_PLATFORM_ERROR_NOT_FOUND;
return FALSE;
}
return klass->ip4_address_delete (platform, ifindex, address, plen);
}
@@ -1302,13 +1295,6 @@ nm_platform_ip6_address_delete (int ifindex, struct in6_addr address, int plen)
g_return_val_if_fail (klass->ip6_address_delete, FALSE);
debug ("address: deleting IPv6 address %s/%d", nm_utils_inet6_ntop (&address, NULL), plen);
if (!nm_platform_ip6_address_exists (ifindex, address, plen)) {
debug ("address doesn't exists");
platform->error = NM_PLATFORM_ERROR_NOT_FOUND;
return FALSE;
}
return klass->ip6_address_delete (platform, ifindex, address, plen);
}
@@ -1581,13 +1567,6 @@ nm_platform_ip4_route_delete (int ifindex, in_addr_t network, int plen, int metr
g_return_val_if_fail (klass->ip4_route_delete, FALSE);
debug ("route: deleting IPv4 route %s/%d, metric=%d", nm_utils_inet4_ntop (network, NULL), plen, metric);
if (!nm_platform_ip4_route_exists (ifindex, network, plen, metric)) {
debug ("route not found");
platform->error = NM_PLATFORM_ERROR_NOT_FOUND;
return FALSE;
}
return klass->ip4_route_delete (platform, ifindex, network, plen, metric);
}
@@ -1601,13 +1580,6 @@ nm_platform_ip6_route_delete (int ifindex,
g_return_val_if_fail (klass->ip6_route_delete, FALSE);
debug ("route: deleting IPv6 route %s/%d, metric=%d", nm_utils_inet6_ntop (&network, NULL), plen, metric);
if (!nm_platform_ip6_route_exists (ifindex, network, plen, metric)) {
debug ("route not found");
platform->error = NM_PLATFORM_ERROR_NOT_FOUND;
return FALSE;
}
return klass->ip6_route_delete (platform, ifindex, network, plen, metric);
}

View File

@@ -89,8 +89,8 @@ test_ip4_address (void)
accept_signal (address_removed);
/* Remove address again */
g_assert (!nm_platform_ip4_address_delete (ifindex, addr, IP4_PLEN));
error (NM_PLATFORM_ERROR_NOT_FOUND);
g_assert (nm_platform_ip4_address_delete (ifindex, addr, IP4_PLEN));
no_error ();
free_signal (address_added);
free_signal (address_changed);
@@ -145,8 +145,8 @@ test_ip6_address (void)
accept_signal (address_removed);
/* Remove address again */
g_assert (!nm_platform_ip6_address_delete (ifindex, addr, IP6_PLEN));
error (NM_PLATFORM_ERROR_NOT_FOUND);
g_assert (nm_platform_ip6_address_delete (ifindex, addr, IP6_PLEN));
no_error ();
free_signal (address_added);
free_signal (address_changed);

View File

@@ -113,8 +113,8 @@ test_ip4_route ()
accept_signal (route_removed);
/* Remove route again */
g_assert (!nm_platform_ip4_route_delete (ifindex, network, plen, metric));
error (NM_PLATFORM_ERROR_NOT_FOUND);
g_assert (nm_platform_ip4_route_delete (ifindex, network, plen, metric));
no_error ();
free_signal (route_added);
free_signal (route_changed);
@@ -196,8 +196,8 @@ test_ip6_route ()
accept_signal (route_removed);
/* Remove route again */
g_assert (!nm_platform_ip6_route_delete (ifindex, network, plen, metric));
error (NM_PLATFORM_ERROR_NOT_FOUND);
g_assert (nm_platform_ip6_route_delete (ifindex, network, plen, metric));
no_error ();
free_signal (route_added);
free_signal (route_changed);