platform: change signature of nm_platform_ip{4,6}_route_add()

Change the functions to accept a platform route as argument. This will
make it easier to add new route options.
This commit is contained in:
Beniamino Galvani 2017-02-09 23:22:25 +01:00
parent 36d9e252d2
commit 63951cad7f
10 changed files with 216 additions and 215 deletions

View file

@ -301,25 +301,21 @@ _platform_route_sync_add (const VTableIP *vtable, NMDefaultRouteManager *self, g
return FALSE;
if (vtable->vt->is_ip4) {
success = nm_platform_ip4_route_add (priv->platform,
entry->route.rx.ifindex,
entry->route.rx.rt_source,
0,
0,
entry->route.r4.gateway,
0,
entry->effective_metric,
entry->route.rx.mss);
NMPlatformIP4Route rt = entry->route.r4;
rt.network = 0;
rt.plen = 0;
rt.metric = entry->effective_metric;
success = nm_platform_ip4_route_add (priv->platform, &rt);
} else {
success = nm_platform_ip6_route_add (priv->platform,
entry->route.rx.ifindex,
entry->route.rx.rt_source,
in6addr_any,
0,
entry->route.r6.gateway,
entry->route.r6.pref_src,
entry->effective_metric,
entry->route.rx.mss);
NMPlatformIP6Route rt = entry->route.r6;
rt.network = in6addr_any;
rt.plen = 0;
rt.metric = entry->effective_metric;
success = nm_platform_ip6_route_add (priv->platform, &rt);
}
if (!success) {
_LOGW (vtable->vt->addr_family, "failed to add default route %s with effective metric %u",

View file

@ -1225,42 +1225,29 @@ ip6_route_delete (NMPlatform *platform, int ifindex, struct in6_addr network, gu
}
static gboolean
ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
in_addr_t network, guint8 plen, in_addr_t gateway,
in_addr_t pref_src, guint32 metric, guint32 mss)
ip4_route_add (NMPlatform *platform, const NMPlatformIP4Route *route)
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE ((NMFakePlatform *) platform);
NMPlatformIP4Route route;
NMPlatformIP4Route rt = *route;
guint i;
guint8 scope;
g_assert (plen <= 32);
rt.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (rt.rt_source);
rt.network = nm_utils_ip4_address_clear_host_address (rt.network, rt.plen);
rt.scope_inv = nm_platform_route_scope_inv (rt.gateway ? RT_SCOPE_UNIVERSE : RT_SCOPE_LINK);
scope = gateway == 0 ? RT_SCOPE_LINK : RT_SCOPE_UNIVERSE;
memset (&route, 0, sizeof (route));
route.ifindex = ifindex;
route.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (source);
route.network = nm_utils_ip4_address_clear_host_address (network, plen);
route.plen = plen;
route.gateway = gateway;
route.metric = metric;
route.mss = mss;
route.scope_inv = nm_platform_route_scope_inv (scope);
if (gateway) {
if (rt.gateway) {
for (i = 0; i < priv->ip4_routes->len; i++) {
NMPlatformIP4Route *item = &g_array_index (priv->ip4_routes,
NMPlatformIP4Route, i);
guint32 gate = ntohl (item->network) >> (32 - item->plen);
guint32 host = ntohl (gateway) >> (32 - item->plen);
guint32 host = ntohl (rt.gateway) >> (32 - item->plen);
if (ifindex == item->ifindex && gate == host)
if (rt.ifindex == item->ifindex && gate == host)
break;
}
if (i == priv->ip4_routes->len) {
nm_log_warn (LOGD_PLATFORM, "Fake platform: failure adding ip4-route '%d: %s/%d %d': Network Unreachable",
route.ifindex, nm_utils_inet4_ntop (route.network, NULL), route.plen, route.metric);
rt.ifindex, nm_utils_inet4_ntop (rt.network, NULL), rt.plen, rt.metric);
return FALSE;
}
}
@ -1268,66 +1255,58 @@ ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
for (i = 0; i < priv->ip4_routes->len; i++) {
NMPlatformIP4Route *item = &g_array_index (priv->ip4_routes, NMPlatformIP4Route, i);
if (item->network != route.network)
if (item->network != rt.network)
continue;
if (item->plen != route.plen)
if (item->plen != rt.plen)
continue;
if (item->metric != metric)
if (item->metric != rt.metric)
continue;
if (item->ifindex != route.ifindex) {
if (item->ifindex != rt.ifindex) {
ip4_route_delete (platform, item->ifindex, item->network, item->plen, item->metric);
i--;
continue;
}
memcpy (item, &route, sizeof (route));
g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, (int) NMP_OBJECT_TYPE_IP4_ROUTE, ifindex, &route, (int) NM_PLATFORM_SIGNAL_CHANGED);
memcpy (item, &rt, sizeof (rt));
g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, (int) NMP_OBJECT_TYPE_IP4_ROUTE,
rt.ifindex, &rt, (int) NM_PLATFORM_SIGNAL_CHANGED);
return TRUE;
}
g_array_append_val (priv->ip4_routes, route);
g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, (int) NMP_OBJECT_TYPE_IP4_ROUTE, ifindex, &route, (int) NM_PLATFORM_SIGNAL_ADDED);
g_array_append_val (priv->ip4_routes, rt);
g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, (int) NMP_OBJECT_TYPE_IP4_ROUTE,
rt.ifindex, &rt, (int) NM_PLATFORM_SIGNAL_ADDED);
return TRUE;
}
static gboolean
ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
struct in6_addr network, guint8 plen, struct in6_addr gateway,
struct in6_addr pref_src, guint32 metric, guint32 mss)
ip6_route_add (NMPlatform *platform, const NMPlatformIP6Route *route)
{
NMFakePlatformPrivate *priv = NM_FAKE_PLATFORM_GET_PRIVATE ((NMFakePlatform *) platform);
NMPlatformIP6Route route;
NMPlatformIP6Route rt = *route;
guint i;
metric = nm_utils_ip6_route_metric_normalize (metric);
rt.metric = nm_utils_ip6_route_metric_normalize (rt.metric);
rt.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (rt.rt_source);
nm_utils_ip6_address_clear_host_address (&rt.network, &rt.network, rt.plen);
memset (&route, 0, sizeof (route));
route.ifindex = ifindex;
route.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (source);
nm_utils_ip6_address_clear_host_address (&route.network, &network, plen);
route.plen = plen;
route.gateway = gateway;
route.metric = metric;
route.mss = mss;
route.pref_src = pref_src;
if (!IN6_IS_ADDR_UNSPECIFIED(&gateway)) {
if (!IN6_IS_ADDR_UNSPECIFIED (&rt.gateway)) {
for (i = 0; i < priv->ip6_routes->len; i++) {
NMPlatformIP6Route *item = &g_array_index (priv->ip6_routes,
NMPlatformIP6Route, i);
guint8 gate_bits = gateway.s6_addr[item->plen / 8] >> (8 - item->plen % 8);
guint8 gate_bits = rt.gateway.s6_addr[item->plen / 8] >> (8 - item->plen % 8);
guint8 host_bits = item->network.s6_addr[item->plen / 8] >> (8 - item->plen % 8);
if ( ifindex == item->ifindex
&& memcmp (&gateway, &item->network, item->plen / 8) == 0
if ( rt.ifindex == item->ifindex
&& memcmp (&rt.gateway, &item->network, item->plen / 8) == 0
&& gate_bits == host_bits)
break;
}
if (i == priv->ip6_routes->len) {
nm_log_warn (LOGD_PLATFORM, "Fake platform: failure adding ip6-route '%d: %s/%d %d': Network Unreachable",
route.ifindex, nm_utils_inet6_ntop (&route.network, NULL), route.plen, route.metric);
rt.ifindex, nm_utils_inet6_ntop (&rt.network, NULL), rt.plen, rt.metric);
return FALSE;
}
}
@ -1335,26 +1314,28 @@ ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
for (i = 0; i < priv->ip6_routes->len; i++) {
NMPlatformIP6Route *item = &g_array_index (priv->ip6_routes, NMPlatformIP6Route, i);
if (!IN6_ARE_ADDR_EQUAL (&item->network, &route.network))
if (!IN6_ARE_ADDR_EQUAL (&item->network, &rt.network))
continue;
if (item->plen != route.plen)
if (item->plen != rt.plen)
continue;
if (item->metric != metric)
if (item->metric != rt.metric)
continue;
if (item->ifindex != route.ifindex) {
if (item->ifindex != rt.ifindex) {
ip6_route_delete (platform, item->ifindex, item->network, item->plen, item->metric);
i--;
continue;
}
memcpy (item, &route, sizeof (route));
g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, (int) NMP_OBJECT_TYPE_IP6_ROUTE, ifindex, &route, (int) NM_PLATFORM_SIGNAL_CHANGED);
memcpy (item, &rt, sizeof (rt));
g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, (int) NMP_OBJECT_TYPE_IP6_ROUTE,
rt.ifindex, &rt, (int) NM_PLATFORM_SIGNAL_CHANGED);
return TRUE;
}
g_array_append_val (priv->ip6_routes, route);
g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, (int) NMP_OBJECT_TYPE_IP6_ROUTE, ifindex, &route, (int) NM_PLATFORM_SIGNAL_ADDED);
g_array_append_val (priv->ip6_routes, rt);
g_signal_emit_by_name (platform, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, (int) NMP_OBJECT_TYPE_IP6_ROUTE,
rt.ifindex, &rt, (int) NM_PLATFORM_SIGNAL_ADDED);
return TRUE;
}

View file

@ -5904,52 +5904,56 @@ ip6_route_get_all (NMPlatform *platform, int ifindex, NMPlatformGetRouteFlags fl
}
static gboolean
ip4_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
in_addr_t network, guint8 plen, in_addr_t gateway,
in_addr_t pref_src, guint32 metric, guint32 mss)
ip4_route_add (NMPlatform *platform, const NMPlatformIP4Route *route)
{
NMPObject obj_id;
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
in_addr_t network;
network = nm_utils_ip4_address_clear_host_address (route->network, route->plen);
/* FIXME: take the scope from route into account */
nlmsg = _nl_msg_new_route (RTM_NEWROUTE,
NLM_F_CREATE | NLM_F_REPLACE,
AF_INET,
ifindex,
source,
gateway ? RT_SCOPE_UNIVERSE : RT_SCOPE_LINK,
route->ifindex,
route->rt_source,
route->gateway ? RT_SCOPE_UNIVERSE : RT_SCOPE_LINK,
&network,
plen,
&gateway,
metric,
mss,
pref_src ? &pref_src : NULL);
route->plen,
&route->gateway,
route->metric,
route->mss,
route->pref_src ? &route->pref_src : NULL);
nmp_object_stackinit_id_ip4_route (&obj_id, ifindex, network, plen, metric);
nmp_object_stackinit_id_ip4_route (&obj_id, route->ifindex, network, route->plen, route->metric);
return do_add_addrroute (platform, &obj_id, nlmsg);
}
static gboolean
ip6_route_add (NMPlatform *platform, int ifindex, NMIPConfigSource source,
struct in6_addr network, guint8 plen, struct in6_addr gateway,
struct in6_addr pref_src, guint32 metric, guint32 mss)
ip6_route_add (NMPlatform *platform, const NMPlatformIP6Route *route)
{
NMPObject obj_id;
nm_auto_nlmsg struct nl_msg *nlmsg = NULL;
struct in6_addr network;
nm_utils_ip6_address_clear_host_address (&network, &route->network, route->plen);
/* FIXME: take the scope from route into account */
nlmsg = _nl_msg_new_route (RTM_NEWROUTE,
NLM_F_CREATE | NLM_F_REPLACE,
AF_INET6,
ifindex,
source,
!IN6_IS_ADDR_UNSPECIFIED (&gateway) ? RT_SCOPE_UNIVERSE : RT_SCOPE_LINK,
route->ifindex,
route->rt_source,
IN6_IS_ADDR_UNSPECIFIED (&route->gateway) ? RT_SCOPE_LINK : RT_SCOPE_UNIVERSE,
&network,
plen,
&gateway,
metric,
mss,
!IN6_IS_ADDR_UNSPECIFIED (&pref_src) ? &pref_src : NULL);
route->plen,
&route->gateway,
route->metric,
route->mss,
!IN6_IS_ADDR_UNSPECIFIED (&route->pref_src) ? &route->pref_src : NULL);
nmp_object_stackinit_id_ip6_route (&obj_id, ifindex, &network, plen, metric);
nmp_object_stackinit_id_ip6_route (&obj_id, route->ifindex, &network, route->plen, route->metric);
return do_add_addrroute (platform, &obj_id, nlmsg);
}

View file

@ -3109,14 +3109,7 @@ nm_platform_ip6_route_get_all (NMPlatform *self, int ifindex, NMPlatformGetRoute
/**
* nm_platform_ip4_route_add:
* @self:
* @ifindex:
* @source:
* network:
* plen:
* gateway:
* pref_src:
* metric:
* mss:
* @route:
*
* For kernel, a gateway can be either explicitly set or left
* at zero (0.0.0.0). In addition, there is the scope of the IPv4
@ -3137,58 +3130,29 @@ nm_platform_ip6_route_get_all (NMPlatform *self, int ifindex, NMPlatformGetRoute
* Returns: %TRUE in case of success.
*/
gboolean
nm_platform_ip4_route_add (NMPlatform *self,
int ifindex, NMIPConfigSource source,
in_addr_t network, guint8 plen,
in_addr_t gateway, in_addr_t pref_src,
guint32 metric, guint32 mss)
nm_platform_ip4_route_add (NMPlatform *self, const NMPlatformIP4Route *route)
{
_CHECK_SELF (self, klass, FALSE);
g_return_val_if_fail (plen <= 32, FALSE);
g_return_val_if_fail (route, FALSE);
g_return_val_if_fail (route->plen <= 32, FALSE);
if (_LOGD_ENABLED ()) {
NMPlatformIP4Route route = { 0 };
_LOGD ("route: adding or updating IPv4 route: %s", nm_platform_ip4_route_to_string (route, NULL, 0));
route.ifindex = ifindex;
route.rt_source = source;
route.network = network;
route.plen = plen;
route.gateway = gateway;
route.metric = metric;
route.mss = mss;
route.pref_src = pref_src;
_LOGD ("route: adding or updating IPv4 route: %s", nm_platform_ip4_route_to_string (&route, NULL, 0));
}
return klass->ip4_route_add (self, ifindex, source, network, plen, gateway, pref_src, metric, mss);
return klass->ip4_route_add (self, route);
}
gboolean
nm_platform_ip6_route_add (NMPlatform *self,
int ifindex, NMIPConfigSource source,
struct in6_addr network, guint8 plen, struct in6_addr gateway,
struct in6_addr pref_src, guint32 metric, guint32 mss)
nm_platform_ip6_route_add (NMPlatform *self, const NMPlatformIP6Route *route)
{
_CHECK_SELF (self, klass, FALSE);
g_return_val_if_fail (plen <= 128, FALSE);
g_return_val_if_fail (route, FALSE);
g_return_val_if_fail (route->plen <= 128, FALSE);
if (_LOGD_ENABLED ()) {
NMPlatformIP6Route route = { 0 };
_LOGD ("route: adding or updating IPv6 route: %s", nm_platform_ip6_route_to_string (route, NULL, 0));
route.ifindex = ifindex;
route.rt_source = source;
route.network = network;
route.plen = plen;
route.gateway = gateway;
route.pref_src = pref_src;
route.metric = metric;
route.mss = mss;
_LOGD ("route: adding or updating IPv6 route: %s", nm_platform_ip6_route_to_string (&route, NULL, 0));
}
return klass->ip6_route_add (self, ifindex, source, network, plen, gateway, pref_src, metric, mss);
return klass->ip6_route_add (self, route);
}
gboolean
@ -4421,29 +4385,27 @@ nm_platform_netns_push (NMPlatform *platform, NMPNetns **netns)
static gboolean
_vtr_v4_route_add (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route, gint64 metric)
{
return nm_platform_ip4_route_add (self,
ifindex > 0 ? ifindex : route->rx.ifindex,
route->rx.rt_source,
route->r4.network,
route->rx.plen,
route->r4.gateway,
route->r4.pref_src,
metric >= 0 ? (guint32) metric : route->rx.metric,
route->rx.mss);
NMPlatformIP4Route rt = route->r4;
if (ifindex > 0)
rt.ifindex = ifindex;
if (metric >= 0)
rt.metric = metric;
return nm_platform_ip4_route_add (self, &rt);
}
static gboolean
_vtr_v6_route_add (NMPlatform *self, int ifindex, const NMPlatformIPXRoute *route, gint64 metric)
{
return nm_platform_ip6_route_add (self,
ifindex > 0 ? ifindex : route->rx.ifindex,
route->rx.rt_source,
route->r6.network,
route->rx.plen,
route->r6.gateway,
route->r6.pref_src,
metric >= 0 ? (guint32) metric : route->rx.metric,
route->rx.mss);
NMPlatformIP6Route rt = route->r6;
if (ifindex > 0)
rt.ifindex = ifindex;
if (metric >= 0)
rt.metric = metric;
return nm_platform_ip6_route_add (self, &rt);
}
static gboolean

View file

@ -668,12 +668,8 @@ typedef struct {
GArray * (*ip4_route_get_all) (NMPlatform *, int ifindex, NMPlatformGetRouteFlags flags);
GArray * (*ip6_route_get_all) (NMPlatform *, int ifindex, NMPlatformGetRouteFlags flags);
gboolean (*ip4_route_add) (NMPlatform *, int ifindex, NMIPConfigSource source,
in_addr_t network, guint8 plen, in_addr_t gateway,
in_addr_t pref_src, guint32 metric, guint32 mss);
gboolean (*ip6_route_add) (NMPlatform *, int ifindex, NMIPConfigSource source,
struct in6_addr network, guint8 plen, struct in6_addr gateway,
struct in6_addr pref_src, guint32 metric, guint32 mss);
gboolean (*ip4_route_add) (NMPlatform *, const NMPlatformIP4Route *route);
gboolean (*ip6_route_add) (NMPlatform *, const NMPlatformIP6Route *route);
gboolean (*ip4_route_delete) (NMPlatform *, int ifindex, in_addr_t network, guint8 plen, guint32 metric);
gboolean (*ip6_route_delete) (NMPlatform *, int ifindex, struct in6_addr network, guint8 plen, guint32 metric);
const NMPlatformIP4Route *(*ip4_route_get) (NMPlatform *, int ifindex, in_addr_t network, guint8 plen, guint32 metric);
@ -970,12 +966,8 @@ const NMPlatformIP4Route *nm_platform_ip4_route_get (NMPlatform *self, int ifind
const NMPlatformIP6Route *nm_platform_ip6_route_get (NMPlatform *self, int ifindex, struct in6_addr network, guint8 plen, guint32 metric);
GArray *nm_platform_ip4_route_get_all (NMPlatform *self, int ifindex, NMPlatformGetRouteFlags flags);
GArray *nm_platform_ip6_route_get_all (NMPlatform *self, int ifindex, NMPlatformGetRouteFlags flags);
gboolean nm_platform_ip4_route_add (NMPlatform *self, int ifindex, NMIPConfigSource source,
in_addr_t network, guint8 plen, in_addr_t gateway,
in_addr_t pref_src, guint32 metric, guint32 mss);
gboolean nm_platform_ip6_route_add (NMPlatform *self, int ifindex, NMIPConfigSource source,
struct in6_addr network, guint8 plen, struct in6_addr gateway,
struct in6_addr pref_src, guint32 metric, guint32 mss);
gboolean nm_platform_ip4_route_add (NMPlatform *self, const NMPlatformIP4Route *route);
gboolean nm_platform_ip6_route_add (NMPlatform *self, const NMPlatformIP6Route *route);
gboolean nm_platform_ip4_route_delete (NMPlatform *self, int ifindex, in_addr_t network, guint8 plen, guint32 metric);
gboolean nm_platform_ip6_route_delete (NMPlatform *self, int ifindex, struct in6_addr network, guint8 plen, guint32 metric);

View file

@ -65,12 +65,12 @@ test_cleanup_internal (void)
/* Add routes and addresses */
g_assert (nm_platform_ip4_address_add (NM_PLATFORM_GET, ifindex, addr4, plen4, addr4, lifetime, preferred, 0, NULL));
g_assert (nm_platform_ip6_address_add (NM_PLATFORM_GET, ifindex, addr6, plen6, in6addr_any, lifetime, preferred, flags));
g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway4, 32, INADDR_ANY, 0, metric, mss));
g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network4, plen4, gateway4, 0, metric, mss));
g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway4, 0, metric, mss));
g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway6, 128, in6addr_any, in6addr_any, metric, mss));
g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network6, plen6, gateway6, in6addr_any, metric, mss));
g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway6, in6addr_any, metric, mss));
nmtstp_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway4, 32, INADDR_ANY, 0, metric, mss);
nmtstp_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network4, plen4, gateway4, 0, metric, mss);
nmtstp_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway4, 0, metric, mss);
nmtstp_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway6, 128, in6addr_any, in6addr_any, metric, mss);
nmtstp_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network6, plen6, gateway6, in6addr_any, metric, mss);
nmtstp_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway6, in6addr_any, metric, mss);
addresses4 = nm_platform_ip4_address_get_all (NM_PLATFORM_GET, ifindex);
addresses6 = nm_platform_ip6_address_get_all (NM_PLATFORM_GET, ifindex);

View file

@ -783,6 +783,54 @@ nmtstp_ip6_address_add (NMPlatform *platform,
NULL);
}
void nmtstp_ip4_route_add (NMPlatform *platform,
int ifindex,
NMIPConfigSource source,
in_addr_t network,
guint8 plen,
in_addr_t gateway,
in_addr_t pref_src,
guint32 metric,
guint32 mss)
{
NMPlatformIP4Route route = { };
route.ifindex = ifindex;
route.rt_source = source;
route.network = network;
route.plen = plen;
route.gateway = gateway;
route.pref_src = pref_src;
route.metric = metric;
route.mss = mss;
g_assert (nm_platform_ip4_route_add (platform, &route));
}
void nmtstp_ip6_route_add (NMPlatform *platform,
int ifindex,
NMIPConfigSource source,
struct in6_addr network,
guint8 plen,
struct in6_addr gateway,
struct in6_addr pref_src,
guint32 metric,
guint32 mss)
{
NMPlatformIP6Route route = { };
route.ifindex = ifindex;
route.rt_source = source;
route.network = network;
route.plen = plen;
route.gateway = gateway;
route.pref_src = pref_src;
route.metric = metric;
route.mss = mss;
g_assert (nm_platform_ip6_route_add (platform, &route));
}
/*****************************************************************************/
static void

View file

@ -167,6 +167,26 @@ void nmtstp_ip6_address_del (NMPlatform *platform,
struct in6_addr address,
int plen);
void nmtstp_ip4_route_add (NMPlatform *platform,
int ifindex,
NMIPConfigSource source,
in_addr_t network,
guint8 plen,
in_addr_t gateway,
in_addr_t pref_src,
guint32 metric,
guint32 mss);
void nmtstp_ip6_route_add (NMPlatform *platform,
int ifindex,
NMIPConfigSource source,
struct in6_addr network,
guint8 plen,
struct in6_addr gateway,
struct in6_addr pref_src,
guint32 metric,
guint32 mss);
/*****************************************************************************/
const NMPlatformLink *nmtstp_link_get_typed (NMPlatform *platform, int ifindex, const char *name, NMLinkType link_type);

View file

@ -94,7 +94,7 @@ test_ip4_route_metric0 (void)
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, metric);
/* add the first route */
g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, INADDR_ANY, 0, metric, mss));
nmtstp_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, INADDR_ANY, 0, metric, mss);
accept_signal (route_added);
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, 0);
@ -108,7 +108,7 @@ test_ip4_route_metric0 (void)
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
/* add the second route */
g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, INADDR_ANY, 0, 0, mss));
nmtstp_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, INADDR_ANY, 0, 0, mss);
accept_signal (route_added);
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, 0);
@ -160,27 +160,27 @@ test_ip4_route (void)
inet_pton (AF_INET, "198.51.100.1", &gateway);
/* Add route to gateway */
g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway, 32, INADDR_ANY, 0, metric, mss));
nmtstp_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway, 32, INADDR_ANY, 0, metric, mss);
accept_signal (route_added);
/* Add route */
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, network, plen, metric);
g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, 0, metric, mss));
nmtstp_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, 0, metric, mss);
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, network, plen, metric);
accept_signal (route_added);
/* Add route again */
g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, 0, metric, mss));
nmtstp_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, 0, metric, mss);
accept_signals (route_changed, 0, 1);
/* Add default route */
nmtstp_assert_ip4_route_exists (NULL, FALSE, DEVICE_NAME, 0, 0, metric);
g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway, 0, metric, mss));
nmtstp_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway, 0, metric, mss);
nmtstp_assert_ip4_route_exists (NULL, TRUE, DEVICE_NAME, 0, 0, metric);
accept_signal (route_added);
/* Add default route again */
g_assert (nm_platform_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway, 0, metric, mss));
nmtstp_ip4_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, 0, 0, gateway, 0, metric, mss);
accept_signals (route_changed, 0, 1);
/* Test route listing */
@ -252,27 +252,27 @@ test_ip6_route (void)
accept_signals (route_added, 0, 1);
/* Add route to gateway */
g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway, 128, in6addr_any, in6addr_any, metric, mss));
nmtstp_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, gateway, 128, in6addr_any, in6addr_any, metric, mss);
accept_signal (route_added);
/* Add route */
g_assert (!nm_platform_ip6_route_get (NM_PLATFORM_GET, ifindex, network, plen, metric));
g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, pref_src, metric, mss));
nmtstp_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, pref_src, metric, mss);
g_assert (nm_platform_ip6_route_get (NM_PLATFORM_GET, ifindex, network, plen, metric));
accept_signal (route_added);
/* Add route again */
g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, pref_src, metric, mss));
nmtstp_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, network, plen, gateway, pref_src, metric, mss);
accept_signals (route_changed, 0, 1);
/* Add default route */
g_assert (!nm_platform_ip6_route_get (NM_PLATFORM_GET, ifindex, in6addr_any, 0, metric));
g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway, in6addr_any, metric, mss));
nmtstp_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway, in6addr_any, metric, mss);
g_assert (nm_platform_ip6_route_get (NM_PLATFORM_GET, ifindex, in6addr_any, 0, metric));
accept_signal (route_added);
/* Add default route again */
g_assert (nm_platform_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway, in6addr_any, metric, mss));
nmtstp_ip6_route_add (NM_PLATFORM_GET, ifindex, NM_IP_CONFIG_SOURCE_USER, in6addr_any, 0, gateway, in6addr_any, metric, mss);
accept_signals (route_changed, 0, 1);
/* Test route listing */

View file

@ -75,16 +75,15 @@ setup_dev1_ip4 (int ifindex)
/* Add some route outside of route manager. The route manager
* should get rid of it upon sync. */
if (!nm_platform_ip4_route_add (NM_PLATFORM_GET,
route.ifindex,
NM_IP_CONFIG_SOURCE_USER,
nmtst_inet4_from_string ("9.0.0.0"),
8,
INADDR_ANY,
0,
10,
route.mss))
g_assert_not_reached ();
nmtstp_ip4_route_add (NM_PLATFORM_GET,
route.ifindex,
NM_IP_CONFIG_SOURCE_USER,
nmtst_inet4_from_string ("9.0.0.0"),
8,
INADDR_ANY,
0,
10,
route.mss);
route.rt_source = nmp_utils_ip_config_source_round_trip_rtprot (NM_IP_CONFIG_SOURCE_USER);
inet_pton (AF_INET, "6.6.6.0", &route.network);
@ -421,16 +420,15 @@ setup_dev1_ip6 (int ifindex)
/* Add some route outside of route manager. The route manager
* should get rid of it upon sync. */
if (!nm_platform_ip6_route_add (NM_PLATFORM_GET,
ifindex,
NM_IP_CONFIG_SOURCE_USER,
*nmtst_inet6_from_string ("2001:db8:8088::"),
48,
in6addr_any,
in6addr_any,
10,
0))
g_assert_not_reached ();
nmtstp_ip6_route_add (NM_PLATFORM_GET,
ifindex,
NM_IP_CONFIG_SOURCE_USER,
*nmtst_inet6_from_string ("2001:db8:8088::"),
48,
in6addr_any,
in6addr_any,
10,
0);
route = nmtst_platform_ip6_route_full ("2001:db8:8086::",
48,