core: refactor nm_ip[46]_config_commit() not to make a copy of route

In nm_ip4_config_commit() and nm_ip6_config_commit() there is no need
to copy the route. Just use the pointer returned from nm_ip4_config_get_route()/
nm_ip6_config_get_route().

Signed-off-by: Thomas Haller <thaller@redhat.com>
(cherry picked from commit e273ff4fe7)
This commit is contained in:
Thomas Haller 2014-07-29 19:39:06 +02:00
parent 7dfdcd36ba
commit ce3b90d22c
2 changed files with 12 additions and 12 deletions

View file

@ -260,27 +260,27 @@ nm_ip4_config_commit (const NMIP4Config *config, int ifindex)
{
int count = nm_ip4_config_get_num_routes (config);
GArray *routes = g_array_sized_new (FALSE, FALSE, sizeof (NMPlatformIP4Route), count);
NMPlatformIP4Route route;
const NMPlatformIP4Route *route;
gboolean success;
for (i = 0; i < count; i++) {
memcpy (&route, nm_ip4_config_get_route (config, i), sizeof (route));
route = nm_ip4_config_get_route (config, i);
/* Don't add the route if it's more specific than one of the subnets
* the device already has an IP address on.
*/
if ( route.gateway == 0
&& nm_ip4_config_destination_is_direct (config, route.network, route.plen))
if ( route->gateway == 0
&& nm_ip4_config_destination_is_direct (config, route->network, route->plen))
continue;
/* Don't add the default route if the connection
* is never supposed to be the default connection.
*/
if ( nm_ip4_config_get_never_default (config)
&& NM_PLATFORM_IP_ROUTE_IS_DEFAULT (&route))
&& NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route))
continue;
g_array_append_val (routes, route);
g_array_append_vals (routes, route, 1);
}
success = nm_platform_ip4_route_sync (ifindex, routes);

View file

@ -372,26 +372,26 @@ nm_ip6_config_commit (const NMIP6Config *config, int ifindex)
{
int count = nm_ip6_config_get_num_routes (config);
GArray *routes = g_array_sized_new (FALSE, FALSE, sizeof (NMPlatformIP6Route), count);
NMPlatformIP6Route route;
const NMPlatformIP6Route *route;
for (i = 0; i < count; i++) {
memcpy (&route, nm_ip6_config_get_route (config, i), sizeof (route));
route = nm_ip6_config_get_route (config, i);
/* Don't add the route if it's more specific than one of the subnets
* the device already has an IP address on.
*/
if ( IN6_IS_ADDR_UNSPECIFIED (&route.gateway)
&& nm_ip6_config_destination_is_direct (config, &route.network, route.plen))
if ( IN6_IS_ADDR_UNSPECIFIED (&route->gateway)
&& nm_ip6_config_destination_is_direct (config, &route->network, route->plen))
continue;
/* Don't add the default route if the connection
* is never supposed to be the default connection.
*/
if ( nm_ip6_config_get_never_default (config)
&& NM_PLATFORM_IP_ROUTE_IS_DEFAULT (&route))
&& NM_PLATFORM_IP_ROUTE_IS_DEFAULT (route))
continue;
g_array_append_val (routes, route);
g_array_append_vals (routes, route, 1);
}
success = nm_platform_ip6_route_sync (ifindex, routes);