core: ignore errors when replacing a default route that already exists

If  the route already exists and the kernel tells us that, we
don't need to do anything.  We certainly don't need to warn
about it in the logs.

There was a typo in the IPv6 default route replace function that
ignored a returned error, and thus we didn't suppress the NLE_EXIST
error like we wanted to.  Do the same for the IPv4 default route
while we're at it.
This commit is contained in:
Dan Williams 2012-01-16 10:27:21 -06:00
parent c4758ef30e
commit a24b9b5299

View file

@ -849,7 +849,7 @@ replace_default_ip4_route (int ifindex, guint32 gw, guint32 mss)
struct rtnl_route *route = NULL;
struct nl_sock *nlh;
int err = -1;
int dst=0;
int dst = 0;
g_return_val_if_fail (ifindex > 0, -ENODEV);
@ -864,6 +864,8 @@ replace_default_ip4_route (int ifindex, guint32 gw, guint32 mss)
/* Add the new default route */
err = nm_netlink_route_add (route, AF_INET, &dst, 0, &gw, NLM_F_REPLACE);
if (err == -NLE_EXIST)
err = 0;
rtnl_route_put (route);
return err;
@ -1033,7 +1035,7 @@ replace_default_ip6_route (int ifindex, const struct in6_addr *gw)
g_return_val_if_fail (route != NULL, -ENOMEM);
/* Add the new default route */
nm_netlink_route_add(route, AF_INET6, NULL, 0, gw, NLM_F_REPLACE);
err = nm_netlink_route_add (route, AF_INET6, NULL, 0, gw, NLM_F_REPLACE);
if (err == -NLE_EXIST) {
/* FIXME: even though we use NLM_F_REPLACE the kernel won't replace
* the route if it's the same. Should try to remove it first, then
@ -1064,6 +1066,9 @@ nm_system_replace_default_ip6_route (int ifindex, const struct in6_addr *gw)
if (err == 0)
return TRUE;
if (err == -NLE_EXIST)
return TRUE;
iface = nm_netlink_index_to_iface (ifindex);
if (!iface)
goto out;