diff options
author | Thomas Haller <thaller@redhat.com> | 2014-11-10 15:05:58 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-11-19 22:55:32 +0100 |
commit | 6d4bb29781065f24efb8b055865f27b7e34f183a (patch) | |
tree | 2b1fee3d0db9f5acff9718776027e97d5197a49b /src/nm-default-route-manager.c | |
parent | 57dd4a125b93587d982c8f0d7e9955217997e2f2 (diff) | |
download | NetworkManager-6d4bb29781065f24efb8b055865f27b7e34f183a.tar.gz |
policy: minor refactoring in NMDefaultRouteManager to access routes generically
Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'src/nm-default-route-manager.c')
-rw-r--r-- | src/nm-default-route-manager.c | 22 |
1 files changed, 14 insertions, 8 deletions
diff --git a/src/nm-default-route-manager.c b/src/nm-default-route-manager.c index 0cd7c1b582..0ca7166172 100644 --- a/src/nm-default-route-manager.c +++ b/src/nm-default-route-manager.c @@ -100,6 +100,7 @@ typedef struct { int addr_family; GPtrArray *(*get_entries) (NMDefaultRouteManagerPrivate *priv); const char *(*platform_route_to_string) (const NMPlatformIPRoute *route); + GArray *(*platform_route_get_all) (int ifindex, NMPlatformGetRouteMode mode); gboolean (*platform_route_delete_default) (int ifindex, guint32 metric); guint32 (*route_metric_normalize) (guint32 metric); } VTableIP; @@ -108,6 +109,15 @@ static const VTableIP vtable_ip4, vtable_ip6; #define VTABLE_IS_IP4 (vtable->addr_family == AF_INET) +static NMPlatformIPRoute * +_vt_route_index (const VTableIP *vtable, GArray *routes, guint index) +{ + if (VTABLE_IS_IP4) + return (NMPlatformIPRoute *) &g_array_index (routes, NMPlatformIP4Route, index); + else + return (NMPlatformIPRoute *) &g_array_index (routes, NMPlatformIP6Route, index); +} + static void _entry_free (Entry *entry) { @@ -206,20 +216,14 @@ _platform_route_sync_flush (const VTableIP *vtable, NMDefaultRouteManager *self) guint i, j; /* prune all other default routes from this device. */ - if (VTABLE_IS_IP4) - routes = nm_platform_ip4_route_get_all (0, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT); - else - routes = nm_platform_ip6_route_get_all (0, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT); + routes = vtable->platform_route_get_all (0, NM_PLATFORM_GET_ROUTE_MODE_ONLY_DEFAULT); for (i = 0; i < routes->len; i++) { const NMPlatformIPRoute *route; gboolean has_ifindex_synced = FALSE; Entry *entry = NULL; - if (VTABLE_IS_IP4) - route = (const NMPlatformIPRoute *) &g_array_index (routes, NMPlatformIP4Route, i); - else - route = (const NMPlatformIPRoute *) &g_array_index (routes, NMPlatformIP6Route, i); + route = _vt_route_index (vtable, routes, i); /* look at all entires and see if the route for this ifindex pair is * a known entry. */ @@ -902,6 +906,7 @@ static const VTableIP vtable_ip4 = { .addr_family = AF_INET, .get_entries = _v4_get_entries, .platform_route_to_string = (const char *(*)(const NMPlatformIPRoute *)) nm_platform_ip4_route_to_string, + .platform_route_get_all = nm_platform_ip4_route_get_all, .platform_route_delete_default = _v4_platform_route_delete_default, .route_metric_normalize = _v4_route_metric_normalize, }; @@ -910,6 +915,7 @@ static const VTableIP vtable_ip6 = { .addr_family = AF_INET6, .get_entries = _v6_get_entries, .platform_route_to_string = (const char *(*)(const NMPlatformIPRoute *)) nm_platform_ip6_route_to_string, + .platform_route_get_all = nm_platform_ip6_route_get_all, .platform_route_delete_default = _v6_platform_route_delete_default, .route_metric_normalize = nm_utils_ip6_route_metric_normalize, }; |