Commit 5c299454 authored by Thomas Haller's avatar Thomas Haller

core: rework tracking of gateway/default-route in ip-config

Instead of having 3 properties @gateway, @never_default and @has_gateway
on NMIP4Config/NMIP6Config that determine the default-route, track the
default-route as a regular route.

The gateway setting is the configuration knob for the default-route.
Since an NMIP4Config/NMIP6Config instance only has one gateway property,
it cannot track more then one default-routes (see related bug rh#1445417).
Especially with policy routing, it might be interesting to configure a
default-route in multiple tables.

Also, later it might be interesting to allow adding default-routes as
regular static routes in a connection, so that the user can configure additional
route parameters for the default-route or add default-routes in multiple tables.

With this patch, default-routes now have a rt_source property according to their
origin.

Also, the previous commits of this branch broke handling of the
default-route :) . That should be working now again.
parent 2bdfc092
......@@ -474,6 +474,15 @@ act_stage3_ip4_config_start (NMDevice *device,
}
priv->ppp_manager = nm_ppp_manager_create (ppp_iface, &err);
if (priv->ppp_manager) {
nm_ppp_manager_set_route_parameters (priv->ppp_manager,
nm_device_get_route_table (device, AF_INET, TRUE),
nm_device_get_route_metric (device, AF_INET),
nm_device_get_route_table (device, AF_INET6, TRUE),
nm_device_get_route_metric (device, AF_INET6));
}
if ( !priv->ppp_manager
|| !nm_ppp_manager_start (priv->ppp_manager, req,
nm_setting_adsl_get_username (s_adsl),
......
......@@ -999,6 +999,7 @@ ppp_ip4_config (NMPPPManager *ppp_manager,
static NMActStageReturn
pppoe_stage3_ip4_config_start (NMDeviceEthernet *self, NMDeviceStateReason *out_failure_reason)
{
NMDevice *device = NM_DEVICE (self);
NMDeviceEthernetPrivate *priv = NM_DEVICE_ETHERNET_GET_PRIVATE (self);
NMSettingPppoe *s_pppoe;
NMActRequest *req;
......@@ -1010,9 +1011,17 @@ pppoe_stage3_ip4_config_start (NMDeviceEthernet *self, NMDeviceStateReason *out_
s_pppoe = (NMSettingPppoe *) nm_device_get_applied_setting ((NMDevice *) self, NM_TYPE_SETTING_PPPOE);
g_return_val_if_fail (s_pppoe, NM_ACT_STAGE_RETURN_FAILURE);
priv->ppp_manager = nm_ppp_manager_create (nm_device_get_iface (NM_DEVICE (self)),
priv->ppp_manager = nm_ppp_manager_create (nm_device_get_iface (device),
&err);
if (priv->ppp_manager) {
nm_ppp_manager_set_route_parameters (priv->ppp_manager,
nm_device_get_route_table (device, AF_INET, TRUE),
nm_device_get_route_metric (device, AF_INET),
nm_device_get_route_table (device, AF_INET6, TRUE),
nm_device_get_route_metric (device, AF_INET6));
}
if ( !priv->ppp_manager
|| !nm_ppp_manager_start (priv->ppp_manager, req,
nm_setting_pppoe_get_username (s_pppoe),
......
......@@ -138,7 +138,7 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason)
NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE (self);
NMSettingPppoe *s_pppoe;
NMActRequest *req;
GError *err = NULL;
GError *error = NULL;
req = nm_device_get_act_request (NM_DEVICE (self));
g_return_val_if_fail (req, NM_ACT_STAGE_RETURN_FAILURE);
......@@ -149,14 +149,22 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason)
g_clear_object (&priv->pending_ip4_config);
nm_clear_g_free (&priv->pending_ifname);
priv->ppp_manager = nm_ppp_manager_create (nm_setting_pppoe_get_parent (s_pppoe), &err);
priv->ppp_manager = nm_ppp_manager_create (nm_setting_pppoe_get_parent (s_pppoe), &error);
if (priv->ppp_manager) {
nm_ppp_manager_set_route_parameters (priv->ppp_manager,
nm_device_get_route_table (device, AF_INET, TRUE),
nm_device_get_route_metric (device, AF_INET),
nm_device_get_route_table (device, AF_INET6, TRUE),
nm_device_get_route_metric (device, AF_INET6));
}
if ( !priv->ppp_manager
|| !nm_ppp_manager_start (priv->ppp_manager, req,
nm_setting_pppoe_get_username (s_pppoe),
30, 0, &err)) {
_LOGW (LOGD_DEVICE | LOGD_PPP, "PPPoE failed to start: %s", err->message);
g_error_free (err);
30, 0, &error)) {
_LOGW (LOGD_DEVICE | LOGD_PPP, "PPPoE failed to start: %s", error->message);
g_error_free (error);
g_clear_object (&priv->ppp_manager);
......
This diff is collapsed.
......@@ -912,8 +912,24 @@ static_stage3_ip4_done (NMModemBroadband *self)
_LOGI (" address %s/%d", address_string, address.plen);
if (gw) {
nm_ip4_config_set_gateway (config, gw);
_LOGI (" gateway %s", gw_string);
guint32 ip4_route_table, ip4_route_metric;
nm_modem_get_route_parameters (NM_MODEM (self),
&ip4_route_table,
&ip4_route_metric,
NULL,
NULL);
{
const NMPlatformIP4Route r = {
.rt_source = NM_IP_CONFIG_SOURCE_WWAN,
.gateway = gw,
.table_coerced = nm_platform_route_table_coerce (ip4_route_table),
.metric = ip4_route_metric,
};
_LOGI (" gateway %s", gw_string);
nm_ip4_config_add_route (config, &r, NULL);
}
}
/* DNS servers */
......@@ -1006,7 +1022,9 @@ stage3_ip6_done (NMModemBroadband *self)
address_string = mm_bearer_ip_config_get_gateway (self->_priv.ipv6_config);
if (address_string) {
if (!inet_pton (AF_INET6, address_string, (void *) &(address.address))) {
guint32 ip6_route_table, ip6_route_metric;
if (inet_pton (AF_INET6, address_string, &address.address) != 1) {
error = g_error_new (NM_DEVICE_ERROR,
NM_DEVICE_ERROR_INVALID_CONNECTION,
"(%s) retrieving IPv6 configuration failed: invalid gateway given '%s'",
......@@ -1014,8 +1032,23 @@ stage3_ip6_done (NMModemBroadband *self)
address_string);
goto out;
}
_LOGI (" gateway %s", address_string);
nm_ip6_config_set_gateway (config, &address.address);
nm_modem_get_route_parameters (NM_MODEM (self),
NULL,
NULL,
&ip6_route_table,
&ip6_route_metric);
{
const NMPlatformIP6Route r = {
.rt_source = NM_IP_CONFIG_SOURCE_WWAN,
.gateway = address.address,
.table_coerced = nm_platform_route_table_coerce (ip6_route_table),
.metric = ip6_route_metric,
};
_LOGI (" gateway %s", address_string);
nm_ip6_config_add_route (config, &r, NULL);
}
} else if (ip_method == NM_MODEM_IP_METHOD_STATIC) {
/* Gateway required for the 'static' method */
error = g_error_new (NM_DEVICE_ERROR,
......
......@@ -833,6 +833,7 @@ context_property_changed (GDBusProxy *proxy,
const gchar *s, *addr_s;
const gchar **array, **iter;
guint32 address_network, gateway_network;
guint32 ip4_route_table, ip4_route_metric;
guint prefix = 0;
_LOGD ("PropertyChanged: %s", property);
......@@ -938,16 +939,30 @@ context_property_changed (GDBusProxy *proxy,
nm_ip4_config_add_address (priv->ip4_config, &addr);
if (g_variant_lookup (v_dict, "Gateway", "&s", &s)) {
if ( s
&& nm_utils_parse_inaddr_bin (AF_INET, s, &gateway_network)) {
_LOGI ("Gateway: %s", s);
nm_ip4_config_set_gateway (priv->ip4_config, gateway_network);
} else {
if ( g_variant_lookup (v_dict, "Gateway", "&s", &s)
&& s) {
if (!nm_utils_parse_inaddr_bin (AF_INET, s, &gateway_network)) {
_LOGW ("invalid 'Gateway': %s", s);
goto out;
}
nm_ip4_config_set_gateway (priv->ip4_config, gateway_network);
nm_modem_get_route_parameters (NM_MODEM (self),
&ip4_route_table,
&ip4_route_metric,
NULL,
NULL);
{
const NMPlatformIP4Route r = {
.rt_source = NM_IP_CONFIG_SOURCE_WWAN,
.gateway = gateway_network,
.table_coerced = nm_platform_route_table_coerce (ip4_route_table),
.metric = ip4_route_metric,
};
_LOGI ("Gateway: %s", s);
nm_ip4_config_add_route (priv->ip4_config, &r, NULL);
}
} else {
_LOGW ("Settings 'Gateway' missing");
goto out;
......@@ -981,17 +996,23 @@ context_property_changed (GDBusProxy *proxy,
_LOGI ("MessageProxy: %s", s);
if ( s
&& nm_utils_parse_inaddr_bin (AF_INET, s, &address_network)) {
const NMPlatformIP4Route mms_route = {
.network = address_network,
.plen = 32,
.gateway = gateway_network,
.metric = 1,
};
/* FIXME: does not handle ipv4.route-table setting and always adds the
* route to RT_TABLE_MAIN table. */
nm_ip4_config_add_route (priv->ip4_config, &mms_route, NULL);
nm_modem_get_route_parameters (NM_MODEM (self),
&ip4_route_table,
&ip4_route_metric,
NULL,
NULL);
{
const NMPlatformIP4Route mms_route = {
.network = address_network,
.plen = 32,
.gateway = gateway_network,
.table_coerced = nm_platform_route_table_coerce (ip4_route_table),
.metric = ip4_route_metric,
};
nm_ip4_config_add_route (priv->ip4_config, &mms_route, NULL);
}
} else {
_LOGW ("invalid MessageProxy: %s", s);
}
......
......@@ -26,6 +26,7 @@
#include <fcntl.h>
#include <string.h>
#include <termios.h>
#include <linux/rtnetlink.h>
#include "nm-core-internal.h"
#include "platform/nm-platform.h"
......@@ -97,6 +98,11 @@ typedef struct _NMModemPrivate {
guint32 mm_ip_timeout;
guint32 ip4_route_table;
guint32 ip4_route_metric;
guint32 ip6_route_table;
guint32 ip6_route_metric;
/* PPP stats */
guint32 in_bytes;
guint32 out_bytes;
......@@ -610,6 +616,14 @@ ppp_stage3_ip_config_start (NMModem *self,
priv->ppp_manager = nm_ppp_manager_create (priv->data_port, &error);
if (priv->ppp_manager) {
nm_ppp_manager_set_route_parameters (priv->ppp_manager,
priv->ip4_route_table,
priv->ip4_route_metric,
priv->ip6_route_table,
priv->ip6_route_metric);
}
if ( !priv->ppp_manager
|| !nm_ppp_manager_start (priv->ppp_manager, req, ppp_name,
ip_timeout, baud_override, &error)) {
......@@ -706,6 +720,8 @@ nm_modem_ip4_pre_commit (NMModem *modem,
{
NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (modem);
nm_modem_set_route_parameters_from_device (modem, device);
/* If the modem has an ethernet-type data interface (ie, not PPP and thus
* not point-to-point) and IP config has a /32 prefix, then we assume that
* ARP will be pointless and we turn it off.
......@@ -1399,6 +1415,76 @@ nm_modem_get_iid (NMModem *self, NMUtilsIPv6IfaceId *out_iid)
/*****************************************************************************/
void
nm_modem_get_route_parameters (NMModem *self,
guint32 *out_ip4_route_table,
guint32 *out_ip4_route_metric,
guint32 *out_ip6_route_table,
guint32 *out_ip6_route_metric)
{
NMModemPrivate *priv;
g_return_if_fail (NM_IS_MODEM (self));
priv = NM_MODEM_GET_PRIVATE (self);
NM_SET_OUT (out_ip4_route_table, priv->ip4_route_table);
NM_SET_OUT (out_ip4_route_metric, priv->ip4_route_metric);
NM_SET_OUT (out_ip6_route_table, priv->ip6_route_table);
NM_SET_OUT (out_ip6_route_metric, priv->ip6_route_metric);
}
void
nm_modem_set_route_parameters (NMModem *self,
guint32 ip4_route_table,
guint32 ip4_route_metric,
guint32 ip6_route_table,
guint32 ip6_route_metric)
{
NMModemPrivate *priv;
g_return_if_fail (NM_IS_MODEM (self));
priv = NM_MODEM_GET_PRIVATE (self);
if ( priv->ip4_route_table != ip4_route_table
|| priv->ip4_route_metric != ip4_route_metric
|| priv->ip6_route_table != ip6_route_table
|| priv->ip6_route_metric != ip6_route_metric) {
priv->ip4_route_table = ip4_route_table;
priv->ip4_route_metric = ip4_route_metric;
priv->ip6_route_table = ip6_route_table;
priv->ip6_route_metric = ip6_route_metric;
_LOGT ("route-parameters: table-v4: %u, metric-v4: %u, table-v6: %u, metric-v6: %u",
priv->ip4_route_table,
priv->ip4_route_metric,
priv->ip6_route_table,
priv->ip6_route_metric);
}
if (priv->ppp_manager) {
nm_ppp_manager_set_route_parameters (priv->ppp_manager,
priv->ip4_route_table,
priv->ip4_route_metric,
priv->ip6_route_table,
priv->ip6_route_metric);
}
}
void
nm_modem_set_route_parameters_from_device (NMModem *self,
NMDevice *device)
{
g_return_if_fail (NM_IS_DEVICE (device));
nm_modem_set_route_parameters (self,
nm_device_get_route_table (device, AF_INET, TRUE),
nm_device_get_route_metric (device, AF_INET),
nm_device_get_route_table (device, AF_INET6, TRUE),
nm_device_get_route_metric (device, AF_INET6));
}
/*****************************************************************************/
void
nm_modem_get_capabilities (NMModem *self,
NMDeviceModemCapabilities *modem_caps,
......@@ -1533,7 +1619,15 @@ set_property (GObject *object, guint prop_id,
static void
nm_modem_init (NMModem *self)
{
NMModemPrivate *priv;
self->_priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_MODEM, NMModemPrivate);
priv = self->_priv;
priv->ip4_route_table = RT_TABLE_MAIN;
priv->ip4_route_metric = 700;
priv->ip6_route_table = RT_TABLE_MAIN;
priv->ip6_route_metric = 700;
}
static void
......
......@@ -187,6 +187,21 @@ gboolean nm_modem_complete_connection (NMModem *self,
const GSList *existing_connections,
GError **error);
void nm_modem_get_route_parameters (NMModem *self,
guint32 *out_ip4_route_table,
guint32 *out_ip4_route_metric,
guint32 *out_ip6_route_table,
guint32 *out_ip6_route_metric);
void nm_modem_set_route_parameters (NMModem *self,
guint32 ip4_route_table,
guint32 ip4_route_metric,
guint32 ip6_route_table,
guint32 ip6_route_metric);
void nm_modem_set_route_parameters_from_device (NMModem *modem,
NMDevice *device);
NMActStageReturn nm_modem_act_stage1_prepare (NMModem *modem,
NMActRequest *req,
NMDeviceStateReason *out_failure_reason);
......
......@@ -689,6 +689,8 @@ lease_validity_span (const char *str_expire, GDateTime *now)
* @addr_family: whether to read IPv4 or IPv6 leases
* @iface: the interface name to match leases with
* @ifindex: interface index of @iface
* @route_table: the route table for the default route.
* @route_metric: the route metric for the default route.
* @contents: the contents of a dhclient leasefile
* @now: the current UTC date/time; pass %NULL to automatically use current
* UTC time. Testcases may need a different value for 'now'
......@@ -704,6 +706,8 @@ nm_dhcp_dhclient_read_lease_ip_configs (NMDedupMultiIndex *multi_idx,
int addr_family,
const char *iface,
int ifindex,
guint32 route_table,
guint32 route_metric,
const char *contents,
GDateTime *now)
{
......@@ -814,7 +818,17 @@ nm_dhcp_dhclient_read_lease_ip_configs (NMDedupMultiIndex *multi_idx,
ip4 = nm_ip4_config_new (multi_idx, ifindex);
nm_ip4_config_add_address (ip4, &address);
nm_ip4_config_set_gateway (ip4, gw);
{
const NMPlatformIP4Route r = {
.rt_source = NM_IP_CONFIG_SOURCE_DHCP,
.gateway = gw,
.table_coerced = nm_platform_route_table_coerce (route_table),
.metric = route_metric,
};
nm_ip4_config_add_route (ip4, &r, NULL);
}
value = g_hash_table_lookup (hash, "option domain-name-servers");
if (value) {
......
......@@ -47,6 +47,8 @@ GSList *nm_dhcp_dhclient_read_lease_ip_configs (struct _NMDedupMultiIndex *multi
int addr_family,
const char *iface,
int ifindex,
guint32 route_table,
guint32 route_metric,
const char *contents,
GDateTime *now);
......
......@@ -167,9 +167,8 @@ nm_dhcp_dhclient_get_lease_ip_configs (NMDedupMultiIndex *multi_idx,
guint32 route_table,
guint32 route_metric)
{
char *contents = NULL;
char *leasefile;
GSList *leases = NULL;
gs_free char *contents = NULL;
gs_free char *leasefile = NULL;
leasefile = get_dhclient_leasefile (addr_family, iface, uuid, NULL);
if (!leasefile)
......@@ -178,13 +177,11 @@ nm_dhcp_dhclient_get_lease_ip_configs (NMDedupMultiIndex *multi_idx,
if ( g_file_test (leasefile, G_FILE_TEST_EXISTS)
&& g_file_get_contents (leasefile, &contents, NULL, NULL)
&& contents
&& contents[0])
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, addr_family, iface, ifindex, contents, NULL);
g_free (leasefile);
g_free (contents);
return leases;
&& contents[0]) {
return nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, addr_family, iface, ifindex,
route_table, route_metric, contents, NULL);
}
return NULL;
}
static gboolean
......
......@@ -243,6 +243,8 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
gsize data_len;
gboolean metered = FALSE;
gboolean static_default_gateway = FALSE;
gboolean gateway_has = FALSE;
in_addr_t gateway = 0;
g_return_val_if_fail (lease != NULL, NULL);
......@@ -369,7 +371,8 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
} else {
if (!static_default_gateway) {
static_default_gateway = TRUE;
nm_ip4_config_set_gateway (ip4_config, route.gateway);
gateway_has = TRUE;
gateway = route.gateway;
s = nm_utils_inet4_ntop (route.gateway, NULL);
LOG_LEASE (LOGD_DHCP4, "gateway %s", s);
......@@ -390,13 +393,25 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
if (!static_default_gateway) {
r = sd_dhcp_lease_get_router (lease, &tmp_addr);
if (r == 0) {
nm_ip4_config_set_gateway (ip4_config, tmp_addr.s_addr);
gateway_has = TRUE;
gateway = tmp_addr.s_addr;
s = nm_utils_inet4_ntop (tmp_addr.s_addr, NULL);
LOG_LEASE (LOGD_DHCP4, "gateway %s", s);
add_option (options, dhcp4_requests, SD_DHCP_OPTION_ROUTER, s);
}
}
if (gateway_has) {
const NMPlatformIP4Route rt = {
.rt_source = NM_IP_CONFIG_SOURCE_DHCP,
.gateway = gateway,
.table_coerced = nm_platform_route_table_coerce (route_table),
.metric = route_metric,
};
nm_ip4_config_add_route (ip4_config, &rt, NULL);
}
/* MTU */
r = sd_dhcp_lease_get_mtu (lease, &mtu);
if (r == 0 && mtu) {
......
......@@ -405,7 +405,8 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
in_addr_t addr;
NMPlatformIP4Address address;
char *str = NULL;
guint32 gwaddr = 0;
gboolean gateway_has = FALSE;
guint32 gateway = 0;
guint8 plen = 0;
g_return_val_if_fail (options != NULL, NULL);
......@@ -434,12 +435,12 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
/* Routes: if the server returns classless static routes, we MUST ignore
* the 'static_routes' option.
*/
if (!ip4_process_classless_routes (iface, options, route_table, route_metric, ip4_config, &gwaddr))
if (!ip4_process_classless_routes (iface, options, route_table, route_metric, ip4_config, &gateway))
process_classful_routes (iface, options, route_table, route_metric, ip4_config);
if (gwaddr) {
_LOG2I (LOGD_DHCP4, iface, " gateway %s", nm_utils_inet4_ntop (gwaddr, NULL));
nm_ip4_config_set_gateway (ip4_config, gwaddr);
if (gateway) {
_LOG2I (LOGD_DHCP4, iface, " gateway %s", nm_utils_inet4_ntop (gateway, NULL));
gateway_has = TRUE;
} else {
/* If the gateway wasn't provided as a classless static route with a
* subnet length of 0, try to find it using the old-style 'routers' option.
......@@ -451,9 +452,9 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
for (s = routers; *s; s++) {
/* FIXME: how to handle multiple routers? */
if (inet_pton (AF_INET, *s, &gwaddr) > 0) {
nm_ip4_config_set_gateway (ip4_config, gwaddr);
if (inet_pton (AF_INET, *s, &gateway) > 0) {
_LOG2I (LOGD_DHCP4, iface, " gateway %s", *s);
gateway_has = TRUE;
break;
} else
_LOG2W (LOGD_DHCP4, iface, "ignoring invalid gateway '%s'", *s);
......@@ -462,6 +463,17 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
}
}
if (gateway_has) {
const NMPlatformIP4Route r = {
.rt_source = NM_IP_CONFIG_SOURCE_DHCP,
.gateway = gateway,
.table_coerced = nm_platform_route_table_coerce (route_table),
.metric = route_metric,
};
nm_ip4_config_add_route (ip4_config, &r, NULL);
}
str = g_hash_table_lookup (options, "dhcp_lease_time");
if (str) {
address.lifetime = address.preferred = strtoul (str, NULL, 10);
......
......@@ -23,6 +23,7 @@
#include <string.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <linux/rtnetlink.h>
#include "nm-utils/nm-dedup-multi.h"
......@@ -38,6 +39,8 @@
#define DEBUG 1
static const int IFINDEX = 5;
static const guint32 ROUTE_TABLE = RT_TABLE_MAIN;
static const guint32 ROUTE_METRIC = 100;
static void
test_config (const char *orig,
......@@ -912,7 +915,7 @@ test_read_lease_ip4_config_basic (void)
/* Date from before the least expiration */
now = g_date_time_new_utc (2013, 11, 1, 19, 55, 32);
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, AF_INET, "wlan0", IFINDEX, contents, now);
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, AF_INET, "wlan0", IFINDEX, ROUTE_TABLE, ROUTE_METRIC, contents, now);
g_assert_cmpint (g_slist_length (leases), ==, 2);
/* IP4Config #1 */
......@@ -929,7 +932,7 @@ test_read_lease_ip4_config_basic (void)
/* Gateway */
expected_addr = nmtst_inet4_from_string ("192.168.1.1");
g_assert_cmpint (nm_ip4_config_get_gateway (config), ==, expected_addr);
g_assert_cmpint (nmtst_ip4_config_get_gateway (config), ==, expected_addr);
/* DNS */
g_assert_cmpint (nm_ip4_config_get_num_nameservers (config), ==, 1);
......@@ -952,7 +955,7 @@ test_read_lease_ip4_config_basic (void)
/* Gateway */
expected_addr = nmtst_inet4_from_string ("10.77.52.254");
g_assert_cmpint (nm_ip4_config_get_gateway (config), ==, expected_addr);
g_assert_cmpint (nmtst_ip4_config_get_gateway (config), ==, expected_addr);
/* DNS */
g_assert_cmpint (nm_ip4_config_get_num_nameservers (config), ==, 2);
......@@ -987,7 +990,7 @@ test_read_lease_ip4_config_expired (void)
/* Date from *after* the lease expiration */
now = g_date_time_new_utc (2013, 12, 1, 19, 55, 32);
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, AF_INET, "wlan0", IFINDEX, contents, now);
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, AF_INET, "wlan0", IFINDEX, ROUTE_TABLE, ROUTE_METRIC, contents, now);
g_assert (leases == NULL);
g_date_time_unref (now);
......@@ -1010,7 +1013,7 @@ test_read_lease_ip4_config_expect_failure (gconstpointer user_data)
/* Date from before the least expiration */
now = g_date_time_new_utc (2013, 11, 1, 1, 1, 1);
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, AF_INET, "wlan0", IFINDEX, contents, now);
leases = nm_dhcp_dhclient_read_lease_ip_configs (multi_idx, AF_INET, "wlan0", IFINDEX, ROUTE_TABLE, ROUTE_METRIC, contents, now);
g_assert (leases == NULL);
g_date_time_unref (now);
......
......@@ -114,7 +114,7 @@ test_generic_options (void)
/* Gateway */
g_assert (inet_pton (AF_INET, expected_gw, &tmp) > 0);
g_assert (nm_ip4_config_get_gateway (ip4_config) == tmp);
g_assert (nmtst_ip4_config_get_gateway (ip4_config) == tmp);
g_assert_cmpint (nm_ip4_config_get_num_wins (ip4_config), ==, 0);
......@@ -133,7 +133,7 @@ test_generic_options (void)
g_assert (nm_ip4_config_get_nameserver (ip4_config, 1) == tmp);
/* Routes */
g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2);
g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 3);
/* Route #1 */
route = _nmtst_ip4_config_get_route (ip4_config, 0);
......@@ -146,13 +146,17 @@ test_generic_options (void)
/* Route #2 */
route = _nmtst_ip4_config_get_route (ip4_config, 1);
g_assert (inet_pton (AF_INET, expected_route2_dest, &tmp) > 0);
g_assert (route->network == tmp);
g_assert (inet_pton (AF_INET, expected_route2_gw, &tmp) > 0);
g_assert (route->gateway == tmp);
g_assert (route->network == nmtst_inet4_from_string (expected_route2_dest));
g_assert (route->gateway == nmtst_inet4_from_string (expected_route2_gw));
g_assert_cmpint (route->plen, ==, 32);
g_assert_cmpint (route->metric, ==, 0);
route = _nmtst_ip4_config_get_route (ip4_config, 2);
g_assert (route->network == nmtst_inet4_from_string ("0.0.0.0"));
g_assert (route->gateway == nmtst_inet4_from_string ("192.168.1.1"));
g_assert_cmpint (route->plen, ==, 0);
g_assert_cmpint (route->metric, ==, 0);
g_hash_table_destroy (options);
}
......@@ -238,7 +242,7 @@ ip4_test_gateway (NMIP4Config *ip4_config, const char *expected_gw)
g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1);
g_assert (inet_pton (AF_INET, expected_gw, &tmp) > 0);
g_assert (nm_ip4_config_get_gateway (ip4_config) == tmp);
g_assert (nmtst_ip4_config_get_gateway (ip4_config) == tmp);
}
static void
......@@ -261,9 +265,10 @@ test_classless_static_routes_1 (void)
ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
/* IP4 routes */
g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2);
g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 3);
ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24);
ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 8);
ip4_test_route (ip4_config, 2, "0.0.0.0", "192.168.1.1", 0);
g_hash_table_destroy (options);
}
......@@ -288,9 +293,10 @@ test_classless_static_routes_2 (void)
ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
/* IP4 routes */
g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2);
g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 3);
ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24);
ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 8);
ip4_test_route (ip4_config, 2, "0.0.0.0", expected_route1_gw, 0);
g_hash_table_destroy (options);
}
......@@ -316,9 +322,10 @@ test_fedora_dhclient_classless_static_routes (void)
ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
/* IP4 routes */
g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2);
g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 3);
ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 25);
ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 7);
ip4_test_route (ip4_config, 2, "0.0.0.0", expected_route1_gw, 0);
/* Gateway */
ip4_test_gateway (ip4_config, expected_gateway);
......@@ -348,8 +355,9 @@ test_dhclient_invalid_classless_routes_1 (void)
g_test_assert_expected_messages ();
/* IP4 routes */
g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 1);
g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 2);
ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 24);
ip4_test_route (ip4_config, 1, "0.0.0.0", expected_route1_gw, 0);