summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-02-13 14:56:38 +0100
committerThomas Haller <thaller@redhat.com>2014-02-14 21:41:25 +0100
commit2bc90a5f2d3dabc84a6ce3a8eb6a0e2582c1c9f2 (patch)
treec1248c7c1e8370f7f1a04b1b165656a85bf58b23
parent5f5c7284d16c5f24200bbbd40c5e9a83f84516cd (diff)
downloadNetworkManager-2bc90a5f2d3dabc84a6ce3a8eb6a0e2582c1c9f2.tar.gz
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>
-rw-r--r--src/platform/nm-fake-platform.c24
-rw-r--r--src/platform/nm-platform.c28
-rw-r--r--src/platform/tests/test-address.c8
-rw-r--r--src/platform/tests/test-route.c8
4 files changed, 20 insertions, 48 deletions
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index 43944721cd..d0127c4733 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -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;
}
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index 8bdfaf42f1..8485e74ebe 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -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);
}
diff --git a/src/platform/tests/test-address.c b/src/platform/tests/test-address.c
index 0f0ccc81eb..20f1bd9ed6 100644
--- a/src/platform/tests/test-address.c
+++ b/src/platform/tests/test-address.c
@@ -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);
diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c
index 6c764ad3c3..f333ffc3c1 100644
--- a/src/platform/tests/test-route.c
+++ b/src/platform/tests/test-route.c
@@ -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);