diff options
author | Thomas Haller <thaller@redhat.com> | 2015-03-25 11:28:19 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-04-08 14:39:16 +0200 |
commit | 290faa003db0aac8686bd6d624c782a4a35523c5 (patch) | |
tree | eec1bff8a5671373732a7167ce6b8c4d7283b33a | |
parent | 57453189e05067be831d61805fbd45c7565b0085 (diff) | |
download | NetworkManager-290faa003db0aac8686bd6d624c782a4a35523c5.tar.gz |
platform: add VTable to handle IPv4 and IPv6 routes generically
-rw-r--r-- | src/platform/nm-platform.c | 91 | ||||
-rw-r--r-- | src/platform/nm-platform.h | 17 |
2 files changed, 108 insertions, 0 deletions
diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index e4e5dbaa6a..6397061b00 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -2637,6 +2637,97 @@ log_ip6_route (NMPlatform *p, int ifindex, NMPlatformIP6Route *route, NMPlatform /******************************************************************/ +static gboolean +_vtr_v4_route_add (int ifindex, const NMPlatformIPXRoute *route, guint32 v4_pref_src) +{ + return nm_platform_ip4_route_add (ifindex > 0 ? ifindex : route->rx.ifindex, + route->rx.source, + route->r4.network, + route->rx.plen, + route->r4.gateway, + v4_pref_src, + route->rx.metric, + route->rx.mss); +} + +static gboolean +_vtr_v6_route_add (int ifindex, const NMPlatformIPXRoute *route, guint32 v4_pref_src) +{ + return nm_platform_ip6_route_add (ifindex > 0 ? ifindex : route->rx.ifindex, + route->rx.source, + route->r6.network, + route->rx.plen, + route->r6.gateway, + route->rx.metric, + route->rx.mss); +} + +static gboolean +_vtr_v4_route_delete (int ifindex, const NMPlatformIPXRoute *route) +{ + return nm_platform_ip4_route_delete (ifindex > 0 ? ifindex : route->rx.ifindex, + route->r4.network, + route->rx.plen, + route->rx.metric); +} + +static gboolean +_vtr_v6_route_delete (int ifindex, const NMPlatformIPXRoute *route) +{ + return nm_platform_ip6_route_delete (ifindex > 0 ? ifindex : route->rx.ifindex, + route->r6.network, + route->rx.plen, + route->rx.metric); +} + +static guint32 +_vtr_v4_metric_normalize (guint32 metric) +{ + return metric; +} + +static gboolean +_vtr_v4_route_delete_default (int ifindex, guint32 metric) +{ + return nm_platform_ip4_route_delete (ifindex, 0, 0, metric); +} + +static gboolean +_vtr_v6_route_delete_default (int ifindex, guint32 metric) +{ + return nm_platform_ip6_route_delete (ifindex, in6addr_any, 0, metric); +} + +/******************************************************************/ + +const NMPlatformVTableRoute nm_platform_vtable_route_v4 = { + .is_ip4 = TRUE, + .addr_family = AF_INET, + .sizeof_route = sizeof (NMPlatformIP4Route), + .route_cmp = (int (*) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b)) nm_platform_ip4_route_cmp, + .route_to_string = (const char *(*) (const NMPlatformIPXRoute *route)) nm_platform_ip4_route_to_string, + .route_get_all = nm_platform_ip4_route_get_all, + .route_add = _vtr_v4_route_add, + .route_delete = _vtr_v4_route_delete, + .route_delete_default = _vtr_v4_route_delete_default, + .metric_normalize = _vtr_v4_metric_normalize, +}; + +const NMPlatformVTableRoute nm_platform_vtable_route_v6 = { + .is_ip4 = FALSE, + .addr_family = AF_INET6, + .sizeof_route = sizeof (NMPlatformIP6Route), + .route_cmp = (int (*) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b)) nm_platform_ip6_route_cmp, + .route_to_string = (const char *(*) (const NMPlatformIPXRoute *route)) nm_platform_ip6_route_to_string, + .route_get_all = nm_platform_ip6_route_get_all, + .route_add = _vtr_v6_route_add, + .route_delete = _vtr_v6_route_delete, + .route_delete_default = _vtr_v6_route_delete_default, + .metric_normalize = nm_utils_ip6_route_metric_normalize, +}; + +/******************************************************************/ + static void nm_platform_init (NMPlatform *object) { diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index b90343d79f..920d9cec8c 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -247,6 +247,23 @@ typedef union { typedef struct { + gboolean is_ip4; + int addr_family; + gsize sizeof_route; + int (*route_cmp) (const NMPlatformIPXRoute *a, const NMPlatformIPXRoute *b); + const char *(*route_to_string) (const NMPlatformIPXRoute *route); + GArray *(*route_get_all) (int ifindex, NMPlatformGetRouteMode mode); + gboolean (*route_add) (int ifindex, const NMPlatformIPXRoute *route, guint32 v4_pref_src); + gboolean (*route_delete) (int ifindex, const NMPlatformIPXRoute *route); + gboolean (*route_delete_default) (int ifindex, guint32 metric); + guint32 (*metric_normalize) (guint32 metric); +} NMPlatformVTableRoute; + +extern const NMPlatformVTableRoute nm_platform_vtable_route_v4; +extern const NMPlatformVTableRoute nm_platform_vtable_route_v6; + + +typedef struct { int peer; } NMPlatformVethProperties; |