summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPavel Šimerda <psimerda@redhat.com>2013-08-01 00:13:10 +0200
committerPavel Šimerda <psimerda@redhat.com>2013-08-01 18:09:03 +0200
commit5dd15bd4595dcc5ff838e10efbebbe1beff60edb (patch)
treedd89feb233a08d2df468f278cd971dc3d48e6a20 /src
parent42b4323902f21b15f7c9878524ddde4588d1dbc4 (diff)
downloadNetworkManager-5dd15bd4595dcc5ff838e10efbebbe1beff60edb.tar.gz
platform: don't check for route existence
This is the same we already did for nm-platform addresses in commit 68c3e1153c415111e9254c1086c82360c069bc92. It will help to avoid various issues and is also a step towards support for route lifetimes.
Diffstat (limited to 'src')
-rw-r--r--src/platform/nm-fake-platform.c34
-rw-r--r--src/platform/nm-platform.c32
-rw-r--r--src/platform/tests/test-route.c28
3 files changed, 58 insertions, 36 deletions
diff --git a/src/platform/nm-fake-platform.c b/src/platform/nm-fake-platform.c
index 8604f64aea..2027faa0d2 100644
--- a/src/platform/nm-fake-platform.c
+++ b/src/platform/nm-fake-platform.c
@@ -941,6 +941,7 @@ ip4_route_add (NMPlatform *platform, int ifindex, in_addr_t network, int plen,
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
NMPlatformIP4Route route;
+ guint i;
memset (&route, 0, sizeof (route));
route.ifindex = ifindex;
@@ -950,8 +951,22 @@ ip4_route_add (NMPlatform *platform, int ifindex, in_addr_t network, int plen,
route.metric = metric;
route.mss = mss;
- g_array_append_val (priv->ip4_routes, route);
+ for (i = 0; i < priv->ip4_routes->len; i++) {
+ NMPlatformIP4Route *item = &g_array_index (priv->ip4_routes, NMPlatformIP4Route, i);
+
+ if (item->ifindex != route.ifindex)
+ continue;
+ if (item->network != route.network)
+ continue;
+ if (item->plen != route.plen)
+ continue;
+ memcpy (item, &route, sizeof (route));
+ g_signal_emit_by_name (platform, NM_PLATFORM_IP4_ROUTE_CHANGED, ifindex, &route);
+ return TRUE;
+ }
+
+ g_array_append_val (priv->ip4_routes, route);
g_signal_emit_by_name (platform, NM_PLATFORM_IP4_ROUTE_ADDED, ifindex, &route);
return TRUE;
@@ -963,6 +978,7 @@ ip6_route_add (NMPlatform *platform, int ifindex, struct in6_addr network, int p
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE (platform);
NMPlatformIP6Route route;
+ guint i;
memset (&route, 0, sizeof (route));
route.ifindex = ifindex;
@@ -972,8 +988,22 @@ ip6_route_add (NMPlatform *platform, int ifindex, struct in6_addr network, int p
route.metric = metric;
route.mss = mss;
- g_array_append_val (priv->ip6_routes, route);
+ for (i = 0; i < priv->ip6_routes->len; i++) {
+ NMPlatformIP6Route *item = &g_array_index (priv->ip6_routes, NMPlatformIP6Route, i);
+
+ if (item->ifindex != route.ifindex)
+ continue;
+ if (!IN6_ARE_ADDR_EQUAL (&item->network, &route.network))
+ continue;
+ if (item->plen != route.plen)
+ continue;
+ memcpy (item, &route, sizeof (route));
+ g_signal_emit_by_name (platform, NM_PLATFORM_IP6_ROUTE_CHANGED, ifindex, &route);
+ return TRUE;
+ }
+
+ g_array_append_val (priv->ip6_routes, route);
g_signal_emit_by_name (platform, NM_PLATFORM_IP6_ROUTE_ADDED, ifindex, &route);
return TRUE;
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c
index cb1535dcd8..0e80d3db28 100644
--- a/src/platform/nm-platform.c
+++ b/src/platform/nm-platform.c
@@ -1362,12 +1362,6 @@ nm_platform_ip4_route_add (int ifindex,
if (!metric)
metric = 1024;
- if (nm_platform_ip4_route_exists (ifindex, network, plen, metric)) {
- debug ("route already exists");
- platform->error = NM_PLATFORM_ERROR_EXISTS;
- return FALSE;
- }
-
return klass->ip4_route_add (platform, ifindex, network, plen, gateway, metric, mss);
}
@@ -1384,12 +1378,6 @@ nm_platform_ip6_route_add (int ifindex,
if (!metric)
metric = 1024;
- if (nm_platform_ip6_route_exists (ifindex, network, plen, metric)) {
- debug ("route already exists");
- platform->error = NM_PLATFORM_ERROR_EXISTS;
- return FALSE;
- }
-
return klass->ip6_route_add (platform, ifindex, network, plen, gateway, metric, mss);
}
@@ -1517,12 +1505,10 @@ nm_platform_ip4_route_sync (int ifindex, const GArray *known_routes)
for (i = 0; i < known_routes->len; i++) {
known_route = &g_array_index (known_routes, NMPlatformIP4Route, i);
- if (!nm_platform_ip4_route_exists (ifindex,
- known_route->network, known_route->plen, known_route->metric))
- if (!nm_platform_ip4_route_add (ifindex,
- known_route->network, known_route->plen, known_route->gateway,
- known_route->metric, known_route->mss))
- return FALSE;
+ if (!nm_platform_ip4_route_add (ifindex,
+ known_route->network, known_route->plen, known_route->gateway,
+ known_route->metric, known_route->mss))
+ return FALSE;
}
return TRUE;
@@ -1569,12 +1555,10 @@ nm_platform_ip6_route_sync (int ifindex, const GArray *known_routes)
for (i = 0; i < known_routes->len; i++) {
known_route = &g_array_index (known_routes, NMPlatformIP6Route, i);
- if (!nm_platform_ip6_route_exists (ifindex,
- known_route->network, known_route->plen, known_route->metric))
- if (!nm_platform_ip6_route_add (ifindex,
- known_route->network, known_route->plen, known_route->gateway,
- known_route->metric, known_route->mss))
- return FALSE;
+ if (!nm_platform_ip6_route_add (ifindex,
+ known_route->network, known_route->plen, known_route->gateway,
+ known_route->metric, known_route->mss))
+ return FALSE;
}
return TRUE;
diff --git a/src/platform/tests/test-route.c b/src/platform/tests/test-route.c
index d74728e4ab..75ec392e8b 100644
--- a/src/platform/tests/test-route.c
+++ b/src/platform/tests/test-route.c
@@ -41,9 +41,10 @@ ip6_route_callback (NMPlatform *platform, int ifindex, NMPlatformIP6Route *recei
static void
test_ip4_route ()
{
+ int ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
SignalData *route_added = add_signal (NM_PLATFORM_IP4_ROUTE_ADDED, ip4_route_callback);
+ SignalData *route_changed = add_signal (NM_PLATFORM_IP4_ROUTE_CHANGED, ip4_route_callback);
SignalData *route_removed = add_signal (NM_PLATFORM_IP4_ROUTE_REMOVED, ip4_route_callback);
- int ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
GArray *routes;
NMPlatformIP4Route rts[4];
in_addr_t network;
@@ -66,8 +67,9 @@ test_ip4_route ()
accept_signal (route_added);
/* Add route again */
- g_assert (!nm_platform_ip4_route_add (ifindex, network, plen, gateway, metric, mss));
- error (NM_PLATFORM_ERROR_EXISTS);
+ g_assert (nm_platform_ip4_route_add (ifindex, network, plen, gateway, metric, mss));
+ no_error ();
+ accept_signal (route_changed);
/* Add default route */
g_assert (!nm_platform_ip4_route_exists (ifindex, 0, 0, metric)); no_error ();
@@ -76,8 +78,9 @@ test_ip4_route ()
accept_signal (route_added);
/* Add default route again */
- g_assert (!nm_platform_ip4_route_add (ifindex, 0, 0, gateway, metric, mss));
- error (NM_PLATFORM_ERROR_EXISTS);
+ g_assert (nm_platform_ip4_route_add (ifindex, 0, 0, gateway, metric, mss));
+ no_error ();
+ accept_signal (route_changed);
/* Test route listing */
routes = nm_platform_ip4_route_get_all (ifindex);
@@ -114,15 +117,17 @@ test_ip4_route ()
error (NM_PLATFORM_ERROR_NOT_FOUND);
free_signal (route_added);
+ free_signal (route_changed);
free_signal (route_removed);
}
static void
test_ip6_route ()
{
+ int ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
SignalData *route_added = add_signal (NM_PLATFORM_IP6_ROUTE_ADDED, ip6_route_callback);
+ SignalData *route_changed = add_signal (NM_PLATFORM_IP6_ROUTE_CHANGED, ip6_route_callback);
SignalData *route_removed = add_signal (NM_PLATFORM_IP6_ROUTE_REMOVED, ip6_route_callback);
- int ifindex = nm_platform_link_get_ifindex (DEVICE_NAME);
GArray *routes;
NMPlatformIP6Route rts[4];
struct in6_addr network;
@@ -145,8 +150,9 @@ test_ip6_route ()
accept_signal (route_added);
/* Add route again */
- g_assert (!nm_platform_ip6_route_add (ifindex, network, plen, gateway, metric, mss));
- error (NM_PLATFORM_ERROR_EXISTS);
+ g_assert (nm_platform_ip6_route_add (ifindex, network, plen, gateway, metric, mss));
+ no_error ();
+ accept_signal (route_changed);
/* Add default route */
g_assert (!nm_platform_ip6_route_exists (ifindex, in6addr_any, 0, metric)); no_error ();
@@ -155,8 +161,9 @@ test_ip6_route ()
accept_signal (route_added);
/* Add default route again */
- g_assert (!nm_platform_ip6_route_add (ifindex, in6addr_any, 0, gateway, metric, mss));
- error (NM_PLATFORM_ERROR_EXISTS);
+ g_assert (nm_platform_ip6_route_add (ifindex, in6addr_any, 0, gateway, metric, mss));
+ no_error ();
+ accept_signal (route_changed);
/* Test route listing */
routes = nm_platform_ip6_route_get_all (ifindex);
@@ -193,6 +200,7 @@ test_ip6_route ()
error (NM_PLATFORM_ERROR_NOT_FOUND);
free_signal (route_added);
+ free_signal (route_changed);
free_signal (route_removed);
}