summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-07-23 10:36:04 +0200
committerThomas Haller <thaller@redhat.com>2020-08-05 16:46:39 +0200
commit9ff7606aeaa43f71c0e59f3539fa397742f8d759 (patch)
treedc41082e4a35c25bcb7d2fa461d0fc455a24c1ea
parentcfb497e61ba02e6939fbb011bd151e177c69e348 (diff)
downloadNetworkManager-th/l3cfg-5.tar.gz
core: use NML3ConfigData (WIP)th/l3cfg-5
-rw-r--r--src/devices/nm-device.c85
-rw-r--r--src/dhcp/nm-dhcp-client.c47
-rw-r--r--src/dhcp/nm-dhcp-client.h2
-rw-r--r--src/dhcp/nm-dhcp-manager.c4
-rw-r--r--src/dhcp/nm-dhcp-nettools.c164
-rw-r--r--src/dhcp/nm-dhcp-systemd.c152
-rw-r--r--src/dhcp/nm-dhcp-utils.c171
-rw-r--r--src/dhcp/nm-dhcp-utils.h29
-rw-r--r--src/dhcp/tests/test-dhcp-utils.c368
-rw-r--r--src/nm-iface-helper.c3
-rw-r--r--src/nm-ip-config.c6
-rw-r--r--src/nm-ip4-config.h2
-rw-r--r--src/nm-ip6-config.h2
-rw-r--r--src/vpn/nm-vpn-connection.c53
14 files changed, 593 insertions, 495 deletions
diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c
index ad23d14ce4..f5f05f895c 100644
--- a/src/devices/nm-device.c
+++ b/src/devices/nm-device.c
@@ -30,6 +30,8 @@
#include "nm-device-private.h"
#include "NetworkManagerUtils.h"
#include "nm-manager.h"
+#include "nm-l3cfg.h"
+#include "nm-l3-config-data.h"
#include "platform/nm-platform.h"
#include "platform/nm-platform-utils.h"
#include "platform/nmp-object.h"
@@ -365,6 +367,7 @@ typedef struct _NMDevicePrivate {
NMActRequest * queued_act_request;
bool queued_act_request_is_waiting_for_carrier:1;
NMDBusTrackObjPath act_request;
+ const NML3ConfigData *act_l3cd;
union {
struct {
@@ -1778,6 +1781,8 @@ _set_ifindex (NMDevice *self, int ifindex, gboolean is_ip_ifindex)
gs_unref_object NML3Cfg *l3cfg_old = NULL;
NML3Cfg **p_l3cfg;
int *p_ifindex;
+ int old_ip_ifindex;
+ int new_ip_ifindex;
if (ifindex < 0)
ifindex = 0;
@@ -1789,16 +1794,27 @@ _set_ifindex (NMDevice *self, int ifindex, gboolean is_ip_ifindex)
if (*p_ifindex == ifindex)
return FALSE;
- *p_ifindex = ifindex;
-
p_l3cfg = is_ip_ifindex
? &priv->ip_l3cfg_
: &priv->l3cfg_;
+ old_ip_ifindex = priv->ip_ifindex > 0
+ ? priv->ip_ifindex
+ : priv->ifindex;
+ if (old_ip_ifindex < 0)
+ old_ip_ifindex = nm_assert_unreachable_val (0);
+
+ *p_ifindex = ifindex;
l3cfg_old = g_steal_pointer (p_l3cfg);
if (ifindex > 0)
*p_l3cfg = nm_netns_access_l3cfg (priv->netns, ifindex);
+ new_ip_ifindex = priv->ip_ifindex > 0
+ ? priv->ip_ifindex
+ : priv->ifindex;
+ if (new_ip_ifindex < 0)
+ new_ip_ifindex = nm_assert_unreachable_val (0);
+
_LOGD (LOGD_DEVICE,
"ifindex: set %sifindex %d%s%s%s%s%s%s",
is_ip_ifindex ? "ip-" : "",
@@ -1809,6 +1825,36 @@ _set_ifindex (NMDevice *self, int ifindex, gboolean is_ip_ifindex)
if (!is_ip_ifindex)
_notify (self, PROP_IFINDEX);
+ if (old_ip_ifindex != new_ip_ifindex) {
+ gs_unref_object NMIP4Config *old_ip_config_4 = NULL;
+ gs_unref_object NMIP6Config *old_ip_config_6 = NULL;
+ gs_unref_object NMIP4Config *new_ip_config_4 = NULL;
+ gs_unref_object NMIP6Config *new_ip_config_6 = NULL;
+
+ if (new_ip_ifindex > 0) {
+ new_ip_config_4 = NM_IP4_CONFIG (nm_ip_config_new (AF_INET, *p_l3cfg, FALSE));
+ new_ip_config_6 = NM_IP6_CONFIG (nm_ip_config_new (AF_INET6, *p_l3cfg, FALSE));
+ nm_dbus_object_export (NM_DBUS_OBJECT (new_ip_config_4));
+ nm_dbus_object_export (NM_DBUS_OBJECT (new_ip_config_6));
+ }
+
+ old_ip_config_4 = g_steal_pointer (&priv->ip_config_4);
+ old_ip_config_6 = g_steal_pointer (&priv->ip_config_6);
+ priv->ip_config_4 = g_steal_pointer (&new_ip_config_4);
+ priv->ip_config_6 = g_steal_pointer (&new_ip_config_6);
+ nm_gobject_notify_together (self,
+ PROP_IP4_CONFIG,
+ PROP_IP6_CONFIG);
+
+ if (old_ip_config_4) {
+ /* We unexport on an idle handler because the change notification could
+ * be frozen -- in that case, the object would wrongly be unexported
+ * before the PROP_IP4_CONFIG changes gets notified. */
+ nm_dbus_object_unexport_on_idle (NM_DBUS_OBJECT (g_steal_pointer (&old_ip_config_4)));
+ nm_dbus_object_unexport_on_idle (NM_DBUS_OBJECT (g_steal_pointer (&old_ip_config_4)));
+ }
+ }
+
return TRUE;
}
@@ -8389,7 +8435,7 @@ dhcp4_dad_cb (NMDevice *self, NMIP4Config **configs, gboolean success)
static void
dhcp4_state_changed (NMDhcpClient *client,
NMDhcpState state,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
GHashTable *options,
const char *event_id,
gpointer user_data)
@@ -8399,15 +8445,15 @@ dhcp4_state_changed (NMDhcpClient *client,
NMIP4Config *manual, **configs;
NMConnection *connection;
- g_return_if_fail (nm_dhcp_client_get_addr_family (client) == AF_INET);
- g_return_if_fail (!ip4_config || NM_IS_IP4_CONFIG (ip4_config));
+ nm_assert (nm_dhcp_client_get_addr_family (client) == AF_INET);
+ nm_assert (!l3cd || NM_IS_L3_CONFIG_DATA (l3cd));
_LOGD (LOGD_DHCP4, "new DHCPv4 client state %d", state);
switch (state) {
case NM_DHCP_STATE_BOUND:
case NM_DHCP_STATE_EXTENDED:
- if (!ip4_config) {
+ if (!l3cd) {
_LOGW (LOGD_DHCP4, "failed to get IPv4 config in response to DHCP event.");
dhcp4_fail (self, state);
break;
@@ -8434,7 +8480,7 @@ dhcp4_state_changed (NMDhcpClient *client,
if (priv->ip_state_4 == NM_DEVICE_IP_STATE_CONF) {
connection = nm_device_get_applied_connection (self);
- g_assert (connection);
+ nm_assert (connection);
manual = nm_device_ip4_config_new (self);
nm_ip4_config_merge_setting (manual,
@@ -9188,13 +9234,14 @@ clear_config:
static void
dhcp6_state_changed (NMDhcpClient *client,
NMDhcpState state,
- NMIP6Config *ip6_config,
+ NML3ConfigData *l3cd,
GHashTable *options,
const char *event_id,
gpointer user_data)
{
NMDevice *self = NM_DEVICE (user_data);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
+ NMIP6Config *ip6_config = NULL; //XXX
g_return_if_fail (nm_dhcp_client_get_addr_family (client) == AF_INET6);
g_return_if_fail (!ip6_config || NM_IS_IP6_CONFIG (ip6_config));
@@ -12413,6 +12460,9 @@ check_and_reapply_connection (NMDevice *self,
gs_unref_object NMConnection *applied_clone = NULL;
gs_unref_hashtable GHashTable *diffs = NULL;
NMConnection *con_old, *con_new;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd_keep_alive = NULL;
+ const NML3ConfigData *l3cd_old;
+ const NML3ConfigData *l3cd_new;
NMSettingIPConfig *s_ip4_old, *s_ip4_new;
NMSettingIPConfig *s_ip6_old, *s_ip6_new;
GHashTableIter iter;
@@ -12520,6 +12570,25 @@ check_and_reapply_connection (NMDevice *self,
priv->v4_route_table_initialized = FALSE;
priv->v6_route_table_initialized = FALSE;
+ l3cd_old = priv->act_l3cd;
+ if (con_old != con_new) {
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd_con = NULL;
+
+ l3cd_con = nm_l3_config_data_new_from_connection (priv->multi_idx,
+ nm_device_get_ip_ifindex (self),
+ con_new,
+ _get_route_table (self, AF_INET),
+ _get_route_table (self, AF_INET6),
+ nm_device_get_route_metric (self, AF_INET),
+ nm_device_get_route_metric (self, AF_INET6));
+ if (!nm_l3_config_data_equal (l3cd_con, priv->act_l3cd)) {
+ nm_l3_config_data_seal (l3cd_con);
+ l3cd_keep_alive = g_steal_pointer (&priv->act_l3cd);
+ priv->act_l3cd = g_steal_pointer (&l3cd_con);
+ }
+ }
+ l3cd_new = priv->act_l3cd;
+
/**************************************************************************
* Reapply changes
*
diff --git a/src/dhcp/nm-dhcp-client.c b/src/dhcp/nm-dhcp-client.c
index a1b786ca9b..644f483303 100644
--- a/src/dhcp/nm-dhcp-client.c
+++ b/src/dhcp/nm-dhcp-client.c
@@ -19,6 +19,7 @@
#include "NetworkManagerUtils.h"
#include "nm-utils.h"
+#include "nm-l3-config-data.h"
#include "nm-dhcp-utils.h"
#include "platform/nm-platform.h"
@@ -421,20 +422,23 @@ stop (NMDhcpClient *self, gboolean release)
void
nm_dhcp_client_set_state (NMDhcpClient *self,
NMDhcpState new_state,
- NMIPConfig *ip_config,
+ NML3ConfigData *l3cd,
GHashTable *options)
{
NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE (self);
gs_free char *event_id = NULL;
if (NM_IN_SET (new_state, NM_DHCP_STATE_BOUND, NM_DHCP_STATE_EXTENDED)) {
- g_return_if_fail (NM_IS_IP_CONFIG_ADDR_FAMILY (ip_config, priv->addr_family));
+ g_return_if_fail (NM_IS_L3_CONFIG_DATA (l3cd));
g_return_if_fail (options);
} else {
- g_return_if_fail (!ip_config);
+ g_return_if_fail (!l3cd);
g_return_if_fail (!options);
}
+ if (l3cd)
+ nm_l3_config_data_seal (l3cd);
+
if (new_state >= NM_DHCP_STATE_BOUND)
timeout_cleanup (self);
if (new_state >= NM_DHCP_STATE_TIMEOUT)
@@ -479,7 +483,7 @@ nm_dhcp_client_set_state (NMDhcpClient *self,
g_signal_emit (G_OBJECT (self),
signals[SIGNAL_STATE_CHANGED], 0,
new_state,
- ip_config,
+ l3cd,
options,
event_id);
}
@@ -869,7 +873,7 @@ nm_dhcp_client_handle_event (gpointer unused,
guint32 old_state;
guint32 new_state;
gs_unref_hashtable GHashTable *str_options = NULL;
- gs_unref_object NMIPConfig *ip_config = NULL;
+ nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
NMPlatformIP6Address prefix = { 0, };
g_return_val_if_fail (NM_IS_DHCP_CLIENT (self), FALSE);
@@ -906,19 +910,19 @@ nm_dhcp_client_handle_event (gpointer unused,
/* Create the IP config */
if (g_hash_table_size (str_options) > 0) {
if (priv->addr_family == AF_INET) {
- ip_config = NM_IP_CONFIG_CAST (nm_dhcp_utils_ip4_config_from_options (nm_dhcp_client_get_multi_idx (self),
- priv->ifindex,
- priv->iface,
- str_options,
- priv->route_table,
- priv->route_metric));
+ l3cd = nm_dhcp_utils_ip4_config_from_options (nm_dhcp_client_get_multi_idx (self),
+ priv->ifindex,
+ priv->iface,
+ str_options,
+ priv->route_table,
+ priv->route_metric);
} else {
prefix = nm_dhcp_utils_ip6_prefix_from_options (str_options);
- ip_config = NM_IP_CONFIG_CAST (nm_dhcp_utils_ip6_config_from_options (nm_dhcp_client_get_multi_idx (self),
- priv->ifindex,
- priv->iface,
- str_options,
- priv->info_only));
+ l3cd = nm_dhcp_utils_ip6_config_from_options (nm_dhcp_client_get_multi_idx (self),
+ priv->ifindex,
+ priv->iface,
+ str_options,
+ priv->info_only);
}
} else
g_warn_if_reached ();
@@ -932,13 +936,13 @@ nm_dhcp_client_handle_event (gpointer unused,
} else {
/* Fail if no valid IP config was received */
if ( NM_IN_SET (new_state, NM_DHCP_STATE_BOUND, NM_DHCP_STATE_EXTENDED)
- && !ip_config) {
+ && !l3cd) {
_LOGW ("client bound but IP config not received");
new_state = NM_DHCP_STATE_FAIL;
nm_clear_pointer (&str_options, g_hash_table_unref);
}
- nm_dhcp_client_set_state (self, new_state, ip_config, str_options);
+ nm_dhcp_client_set_state (self, new_state, l3cd, str_options);
}
return TRUE;
@@ -1245,7 +1249,12 @@ nm_dhcp_client_class_init (NMDhcpClientClass *client_class)
G_SIGNAL_RUN_FIRST,
0,
NULL, NULL, NULL,
- G_TYPE_NONE, 4, G_TYPE_UINT, G_TYPE_OBJECT, G_TYPE_HASH_TABLE, G_TYPE_STRING);
+ G_TYPE_NONE,
+ 4,
+ G_TYPE_UINT,
+ G_TYPE_POINTER /* NML3ConfigData */,
+ G_TYPE_HASH_TABLE,
+ G_TYPE_STRING);
signals[SIGNAL_PREFIX_DELEGATED] =
g_signal_new (NM_DHCP_CLIENT_SIGNAL_PREFIX_DELEGATED,
diff --git a/src/dhcp/nm-dhcp-client.h b/src/dhcp/nm-dhcp-client.h
index 479ea000a9..b57dd030ef 100644
--- a/src/dhcp/nm-dhcp-client.h
+++ b/src/dhcp/nm-dhcp-client.h
@@ -185,7 +185,7 @@ void nm_dhcp_client_watch_child (NMDhcpClient *self, pid_t pid);
void nm_dhcp_client_set_state (NMDhcpClient *self,
NMDhcpState new_state,
- NMIPConfig *ip_config,
+ NML3ConfigData *l3cd,
GHashTable *options); /* str:str hash */
gboolean nm_dhcp_client_handle_event (gpointer unused,
diff --git a/src/dhcp/nm-dhcp-manager.c b/src/dhcp/nm-dhcp-manager.c
index 9acf145a5a..04f820eb39 100644
--- a/src/dhcp/nm-dhcp-manager.c
+++ b/src/dhcp/nm-dhcp-manager.c
@@ -163,7 +163,7 @@ get_client_for_ifindex (NMDhcpManager *manager, int addr_family, int ifindex)
static void client_state_changed (NMDhcpClient *client,
NMDhcpState state,
- GObject *ip_config,
+ NML3ConfigData *l3cd,
GVariant *options,
const char *event_id,
NMDhcpManager *self);
@@ -190,7 +190,7 @@ remove_client_unref (NMDhcpManager *self, NMDhcpClient *client)
static void
client_state_changed (NMDhcpClient *client,
NMDhcpState state,
- GObject *ip_config,
+ NML3ConfigData *l3cd,
GVariant *options,
const char *event_id,
NMDhcpManager *self)
diff --git a/src/dhcp/nm-dhcp-nettools.c b/src/dhcp/nm-dhcp-nettools.c
index 8d7d021710..7b95f89556 100644
--- a/src/dhcp/nm-dhcp-nettools.c
+++ b/src/dhcp/nm-dhcp-nettools.c
@@ -18,6 +18,7 @@
#include "nm-glib-aux/nm-dedup-multi.h"
#include "nm-std-aux/unaligned.h"
+#include "nm-l3-config-data.h"
#include "nm-utils.h"
#include "nm-config.h"
#include "nm-dhcp-utils.h"
@@ -351,7 +352,7 @@ lease_get_u16 (NDhcp4ClientLease *lease,
static gboolean
lease_parse_address (NDhcp4ClientLease *lease,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
GHashTable *options,
GError **error)
{
@@ -453,23 +454,23 @@ lease_parse_address (NDhcp4ClientLease *lease,
addr_str);
}
- nm_ip4_config_add_address (ip4_config,
- &((const NMPlatformIP4Address) {
- .address = a_address.s_addr,
- .peer_address = a_address.s_addr,
- .plen = a_plen,
- .addr_source = NM_IP_CONFIG_SOURCE_DHCP,
- .timestamp = a_timestamp,
- .lifetime = a_lifetime,
- .preferred = a_lifetime,
- }));
+ nm_l3_config_data_add_address_4 (l3cd,
+ &((const NMPlatformIP4Address) {
+ .address = a_address.s_addr,
+ .peer_address = a_address.s_addr,
+ .plen = a_plen,
+ .addr_source = NM_IP_CONFIG_SOURCE_DHCP,
+ .timestamp = a_timestamp,
+ .lifetime = a_lifetime,
+ .preferred = a_lifetime,
+ }));
return TRUE;
}
static void
lease_parse_domain_name_servers (NDhcp4ClientLease *lease,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
GHashTable *options)
{
nm_auto_free_gstring GString *str = NULL;
@@ -496,7 +497,8 @@ lease_parse_domain_name_servers (NDhcp4ClientLease *lease,
* See https://github.com/systemd/systemd/issues/4524. */
continue;
}
- nm_ip4_config_add_nameserver (ip4_config, addr.s_addr);
+
+ nm_l3_config_data_add_nameserver (l3cd, AF_INET, &addr);
}
nm_dhcp_option_add_option (options,
@@ -507,7 +509,7 @@ lease_parse_domain_name_servers (NDhcp4ClientLease *lease,
static void
lease_parse_routes (NDhcp4ClientLease *lease,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
GHashTable *options,
guint32 route_table,
guint32 route_metric)
@@ -550,20 +552,18 @@ lease_parse_routes (NDhcp4ClientLease *lease,
default_route_metric++;
has_router_from_classless = TRUE;
- } else {
+ } else
m = route_metric;
- }
-
- nm_ip4_config_add_route (ip4_config,
- &((const NMPlatformIP4Route) {
- .network = dest.s_addr,
- .plen = plen,
- .gateway = gateway.s_addr,
- .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
- .metric = m,
- .table_coerced = nm_platform_route_table_coerce (route_table),
- }),
- NULL);
+
+ nm_l3_config_data_add_route_4 (l3cd,
+ &((const NMPlatformIP4Route) {
+ .network = dest.s_addr,
+ .plen = plen,
+ .gateway = gateway.s_addr,
+ .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
+ .metric = m,
+ .table_coerced = nm_platform_route_table_coerce (route_table),
+ }));
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,
@@ -601,16 +601,15 @@ lease_parse_routes (NDhcp4ClientLease *lease,
continue;
}
- nm_ip4_config_add_route (ip4_config,
- &((const NMPlatformIP4Route) {
- .network = dest.s_addr,
- .plen = plen,
- .gateway = gateway.s_addr,
- .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
- .metric = route_metric,
- .table_coerced = nm_platform_route_table_coerce (route_table),
- }),
- NULL);
+ nm_l3_config_data_add_route_4 (l3cd,
+ &((const NMPlatformIP4Route) {
+ .network = dest.s_addr,
+ .plen = plen,
+ .gateway = gateway.s_addr,
+ .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
+ .metric = route_metric,
+ .table_coerced = nm_platform_route_table_coerce (route_table),
+ }));
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,
@@ -647,14 +646,13 @@ lease_parse_routes (NDhcp4ClientLease *lease,
if (default_route_metric < G_MAXUINT32)
default_route_metric++;
- nm_ip4_config_add_route (ip4_config,
- &((const NMPlatformIP4Route) {
- .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
- .gateway = gateway.s_addr,
- .table_coerced = nm_platform_route_table_coerce (route_table),
- .metric = m,
- }),
- NULL);
+ nm_l3_config_data_add_route_4 (l3cd,
+ &((const NMPlatformIP4Route) {
+ .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
+ .gateway = gateway.s_addr,
+ .table_coerced = nm_platform_route_table_coerce (route_table),
+ .metric = m,
+ }));
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,
@@ -665,7 +663,7 @@ lease_parse_routes (NDhcp4ClientLease *lease,
static void
lease_parse_mtu (NDhcp4ClientLease *lease,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
GHashTable *options)
{
uint16_t mtu;
@@ -680,27 +678,25 @@ lease_parse_mtu (NDhcp4ClientLease *lease,
_nm_dhcp_option_dhcp4_options,
NM_DHCP_OPTION_DHCP4_INTERFACE_MTU,
mtu);
- nm_ip4_config_set_mtu (ip4_config, mtu, NM_IP_CONFIG_SOURCE_DHCP);
+ nm_l3_config_data_set_mtu (l3cd, mtu);
}
static void
lease_parse_metered (NDhcp4ClientLease *lease,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
GHashTable *options)
{
- gboolean metered = FALSE;
uint8_t *data;
size_t n_data;
int r;
r = n_dhcp4_client_lease_query (lease, NM_DHCP_OPTION_DHCP4_VENDOR_SPECIFIC, &data, &n_data);
- if (r)
- metered = FALSE;
- else
- metered = !!memmem (data, n_data, "ANDROID_METERED", NM_STRLEN ("ANDROID_METERED"));
+ if (r == 0) {
+ if (!!memmem (data, n_data, "ANDROID_METERED", NM_STRLEN ("ANDROID_METERED")))
+ nm_l3_config_data_set_metered (l3cd, TRUE);
+ }
/* TODO: expose the vendor specific option when present */
- nm_ip4_config_set_metered (ip4_config, metered);
}
static void
@@ -757,7 +753,7 @@ lease_parse_hostname (NDhcp4ClientLease *lease,
static void
lease_parse_domainname (NDhcp4ClientLease *lease,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
GHashTable *options)
{
nm_auto_free_gstring GString *str = NULL;
@@ -781,7 +777,7 @@ lease_parse_domainname (NDhcp4ClientLease *lease,
return;
g_string_append (nm_gstring_add_space_delimiter (str), *d);
- nm_ip4_config_add_domain (ip4_config, *d);
+ nm_l3_config_data_add_domain (l3cd, AF_INET, *d);
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,
@@ -820,7 +816,7 @@ nm_dhcp_parse_search_list (guint8 *data, size_t n_data)
static void
lease_parse_search_domains (NDhcp4ClientLease *lease,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
GHashTable *options)
{
nm_auto_free_gstring GString *str = NULL;
@@ -839,7 +835,7 @@ lease_parse_search_domains (NDhcp4ClientLease *lease,
for (i = 0; domains && domains[i]; i++) {
g_string_append (nm_gstring_add_space_delimiter (str), domains[i]);
- nm_ip4_config_add_search (ip4_config, domains[i]);
+ nm_l3_config_data_add_search (l3cd, AF_INET, domains[i]);
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,
@@ -920,7 +916,7 @@ lease_parse_private_options (NDhcp4ClientLease *lease,
}
}
-static NMIP4Config *
+static NML3ConfigData *
lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
@@ -930,23 +926,26 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
GHashTable **out_options,
GError **error)
{
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
gs_unref_hashtable GHashTable *options = NULL;
g_return_val_if_fail (lease != NULL, NULL);
- ip4_config = nm_ip4_config_new (multi_idx, ifindex);
+ l3cd = nm_l3_config_data_new (multi_idx, ifindex);
+
+ nm_l3_config_data_set_source (l3cd, NM_IP_CONFIG_SOURCE_DHCP);
+
options = nm_dhcp_option_create_options_dict ();
- if (!lease_parse_address (lease, ip4_config, options, error))
+ if (!lease_parse_address (lease, l3cd, options, error))
return NULL;
- lease_parse_routes (lease, ip4_config, options, route_table, route_metric);
- lease_parse_domain_name_servers (lease, ip4_config, options);
- lease_parse_domainname (lease, ip4_config, options);
- lease_parse_search_domains (lease, ip4_config, options);
- lease_parse_mtu (lease, ip4_config, options);
- lease_parse_metered (lease, ip4_config, options);
+ lease_parse_routes (lease, l3cd, options, route_table, route_metric);
+ lease_parse_domain_name_servers (lease, l3cd, options);
+ lease_parse_domainname (lease, l3cd, options);
+ lease_parse_search_domains (lease, l3cd, options);
+ lease_parse_mtu (lease, l3cd, options);
+ lease_parse_metered (lease, l3cd, options);
lease_parse_hostname (lease, options);
lease_parse_ntps (lease, options);
@@ -955,7 +954,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
lease_parse_private_options (lease, options);
NM_SET_OUT (out_options, g_steal_pointer (&options));
- return g_steal_pointer (&ip4_config);
+ return g_steal_pointer (&l3cd);
}
/*****************************************************************************/
@@ -992,22 +991,22 @@ bound4_handle (NMDhcpNettools *self, NDhcp4ClientLease *lease, gboolean extended
{
NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE (self);
const char *iface = nm_dhcp_client_get_iface (NM_DHCP_CLIENT (self));
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
gs_unref_hashtable GHashTable *options = NULL;
GError *error = NULL;
_LOGT ("lease available (%s)", extended ? "extended" : "new");
- ip4_config = lease_to_ip4_config (nm_dhcp_client_get_multi_idx (NM_DHCP_CLIENT (self)),
- iface,
- nm_dhcp_client_get_ifindex (NM_DHCP_CLIENT (self)),
- lease,
- nm_dhcp_client_get_route_table (NM_DHCP_CLIENT (self)),
- nm_dhcp_client_get_route_metric (NM_DHCP_CLIENT (self)),
- &options,
- &error);
- if (!ip4_config) {
- _LOGW ("%s", error->message);
+ l3cd = lease_to_ip4_config (nm_dhcp_client_get_multi_idx (NM_DHCP_CLIENT (self)),
+ iface,
+ nm_dhcp_client_get_ifindex (NM_DHCP_CLIENT (self)),
+ lease,
+ nm_dhcp_client_get_route_table (NM_DHCP_CLIENT (self)),
+ nm_dhcp_client_get_route_metric (NM_DHCP_CLIENT (self)),
+ &options,
+ &error);
+ if (!l3cd) {
+ _LOGW ("failure to parse lease: %s", error->message);
g_clear_error (&error);
nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_FAIL, NULL, NULL);
return;
@@ -1018,7 +1017,7 @@ bound4_handle (NMDhcpNettools *self, NDhcp4ClientLease *lease, gboolean extended
nm_dhcp_client_set_state (NM_DHCP_CLIENT (self),
extended ? NM_DHCP_STATE_EXTENDED : NM_DHCP_STATE_BOUND,
- NM_IP_CONFIG_CAST (ip4_config),
+ l3cd,
options);
}
@@ -1100,9 +1099,8 @@ dhcp4_event_cb (int fd,
return G_SOURCE_REMOVE;
}
- while (!n_dhcp4_client_pop_event (priv->client, &event) && event) {
+ while (!n_dhcp4_client_pop_event (priv->client, &event) && event)
dhcp4_event_handle (self, event);
- }
return G_SOURCE_CONTINUE;
}
diff --git a/src/dhcp/nm-dhcp-systemd.c b/src/dhcp/nm-dhcp-systemd.c
index a30a5e5883..ee403b3600 100644
--- a/src/dhcp/nm-dhcp-systemd.c
+++ b/src/dhcp/nm-dhcp-systemd.c
@@ -17,6 +17,7 @@
#include "nm-std-aux/unaligned.h"
#include "nm-utils.h"
+#include "nm-l3-config-data.h"
#include "nm-dhcp-utils.h"
#include "nm-dhcp-options.h"
#include "nm-core-utils.h"
@@ -67,7 +68,7 @@ G_DEFINE_TYPE (NMDhcpSystemd, nm_dhcp_systemd, NM_TYPE_DHCP_CLIENT)
/*****************************************************************************/
-static NMIP4Config *
+static NML3ConfigData *
lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
@@ -77,7 +78,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
GHashTable **out_options,
GError **error)
{
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
gs_unref_hashtable GHashTable *options = NULL;
const struct in_addr *addr_list;
char addr_str[NM_UTILS_INET_ADDRSTRLEN];
@@ -89,7 +90,6 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
int i, num;
const void *data;
gsize data_len;
- gboolean metered = FALSE;
gboolean has_router_from_classless = FALSE;
gboolean has_classless_route = FALSE;
gboolean has_static_route = FALSE;
@@ -124,7 +124,9 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
return NULL;
}
- ip4_config = nm_ip4_config_new (multi_idx, ifindex);
+ l3cd = nm_l3_config_data_new (multi_idx, ifindex);
+
+ nm_l3_config_data_set_source (l3cd, NM_IP_CONFIG_SOURCE_DHCP);
options = out_options ? nm_dhcp_option_create_options_dict () : NULL;
@@ -157,16 +159,16 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
addr_str);
}
- nm_ip4_config_add_address (ip4_config,
- &((const NMPlatformIP4Address) {
- .address = a_address.s_addr,
- .peer_address = a_address.s_addr,
- .plen = a_plen,
- .addr_source = NM_IP_CONFIG_SOURCE_DHCP,
- .timestamp = ts,
- .lifetime = a_lifetime,
- .preferred = a_lifetime,
- }));
+ nm_l3_config_data_add_address_4 (l3cd,
+ &((const NMPlatformIP4Address) {
+ .address = a_address.s_addr,
+ .peer_address = a_address.s_addr,
+ .plen = a_plen,
+ .addr_source = NM_IP_CONFIG_SOURCE_DHCP,
+ .timestamp = ts,
+ .lifetime = a_lifetime,
+ .preferred = a_lifetime,
+ }));
if (sd_dhcp_lease_get_server_identifier (lease, &server_id) >= 0) {
_nm_utils_inet4_ntop (server_id.s_addr, addr_str);
@@ -197,7 +199,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
* See https://github.com/systemd/systemd/issues/4524. */
continue;
}
- nm_ip4_config_add_nameserver (ip4_config, addr_list[i].s_addr);
+ nm_l3_config_data_add_nameserver (l3cd, AF_INET, &addr_list[i].s_addr);
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,
@@ -210,7 +212,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
nm_gstring_prepare (&str);
for (i = 0; i < num; i++) {
g_string_append (nm_gstring_add_space_delimiter (str), search_domains[i]);
- nm_ip4_config_add_search (ip4_config, search_domains[i]);
+ nm_l3_config_data_add_search (l3cd, AF_INET, search_domains[i]);
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,
@@ -231,7 +233,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
* As systemd escapes such characters, split them at \\032. */
domains = g_strsplit (s, "\\032", 0);
for (d = domains; *d; d++)
- nm_ip4_config_add_domain (ip4_config, *d);
+ nm_l3_config_data_add_domain (l3cd, AF_INET, *d);
}
if (sd_dhcp_lease_get_hostname (lease, &s) >= 0) {
@@ -327,16 +329,15 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
} else
m = route_metric;
- nm_ip4_config_add_route (ip4_config,
- &((const NMPlatformIP4Route) {
- .network = network_net,
- .plen = r_plen,
- .gateway = r_gateway.s_addr,
- .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
- .metric = m,
- .table_coerced = nm_platform_route_table_coerce (route_table),
- }),
- NULL);
+ nm_l3_config_data_add_route_4 (l3cd,
+ &((const NMPlatformIP4Route) {
+ .network = network_net,
+ .plen = r_plen,
+ .gateway = r_gateway.s_addr,
+ .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
+ .metric = m,
+ .table_coerced = nm_platform_route_table_coerce (route_table),
+ }));
}
if (str_classless && str_classless->len > 0)
@@ -383,14 +384,13 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
if (default_route_metric < G_MAXUINT32)
default_route_metric++;
- nm_ip4_config_add_route (ip4_config,
- &((const NMPlatformIP4Route) {
- .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
- .gateway = a_router[i].s_addr,
- .table_coerced = nm_platform_route_table_coerce (route_table),
- .metric = m,
- }),
- NULL);
+ nm_l3_config_data_add_route_4 (l3cd,
+ &((const NMPlatformIP4Route) {
+ .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
+ .gateway = a_router[i].s_addr,
+ .table_coerced = nm_platform_route_table_coerce (route_table),
+ .metric = m,
+ }));
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp4_options,
@@ -404,7 +404,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
_nm_dhcp_option_dhcp4_options,
NM_DHCP_OPTION_DHCP4_INTERFACE_MTU,
mtu);
- nm_ip4_config_set_mtu (ip4_config, mtu, NM_IP_CONFIG_SOURCE_DHCP);
+ nm_l3_config_data_set_mtu (l3cd, mtu);
}
num = sd_dhcp_lease_get_ntp (lease, &addr_list);
@@ -448,9 +448,10 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
s);
}
- if (sd_dhcp_lease_get_vendor_specific (lease, &data, &data_len) >= 0)
- metered = !!memmem (data, data_len, "ANDROID_METERED", NM_STRLEN ("ANDROID_METERED"));
- nm_ip4_config_set_metered (ip4_config, metered);
+ if (sd_dhcp_lease_get_vendor_specific (lease, &data, &data_len) >= 0) {
+ if (!!memmem (data, data_len, "ANDROID_METERED", NM_STRLEN ("ANDROID_METERED")))
+ nm_l3_config_data_set_metered (l3cd, TRUE);
+ }
num = nm_sd_dhcp_lease_get_private_options (lease, &private_options);
if (num > 0) {
@@ -471,7 +472,7 @@ lease_to_ip4_config (NMDedupMultiIndex *multi_idx,
}
}
NM_SET_OUT (out_options, g_steal_pointer (&options));
- return g_steal_pointer (&ip4_config);
+ return g_steal_pointer (&l3cd);
}
/*****************************************************************************/
@@ -482,7 +483,7 @@ bound4_handle (NMDhcpSystemd *self, gboolean extended)
NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self);
const char *iface = nm_dhcp_client_get_iface (NM_DHCP_CLIENT (self));
sd_dhcp_lease *lease;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
gs_unref_hashtable GHashTable *options = NULL;
GError *error = NULL;
@@ -495,15 +496,15 @@ bound4_handle (NMDhcpSystemd *self, gboolean extended)
_LOGD ("lease available");
- ip4_config = lease_to_ip4_config (nm_dhcp_client_get_multi_idx (NM_DHCP_CLIENT (self)),
- iface,
- nm_dhcp_client_get_ifindex (NM_DHCP_CLIENT (self)),
- lease,
- nm_dhcp_client_get_route_table (NM_DHCP_CLIENT (self)),
- nm_dhcp_client_get_route_metric (NM_DHCP_CLIENT (self)),
- &options,
- &error);
- if (!ip4_config) {
+ l3cd = lease_to_ip4_config (nm_dhcp_client_get_multi_idx (NM_DHCP_CLIENT (self)),
+ iface,
+ nm_dhcp_client_get_ifindex (NM_DHCP_CLIENT (self)),
+ lease,
+ nm_dhcp_client_get_route_table (NM_DHCP_CLIENT (self)),
+ nm_dhcp_client_get_route_metric (NM_DHCP_CLIENT (self)),
+ &options,
+ &error);
+ if (!l3cd) {
_LOGW ("%s", error->message);
g_clear_error (&error);
nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_FAIL, NULL, NULL);
@@ -515,7 +516,7 @@ bound4_handle (NMDhcpSystemd *self, gboolean extended)
nm_dhcp_client_set_state (NM_DHCP_CLIENT (self),
extended ? NM_DHCP_STATE_EXTENDED : NM_DHCP_STATE_BOUND,
- NM_IP_CONFIG_CAST (ip4_config),
+ l3cd,
options);
}
@@ -723,7 +724,7 @@ ip4_start (NMDhcpClient *client,
return TRUE;
}
-static NMIP6Config *
+static NML3ConfigData *
lease_to_ip6_config (NMDedupMultiIndex *multi_idx,
const char *iface,
int ifindex,
@@ -733,7 +734,7 @@ lease_to_ip6_config (NMDedupMultiIndex *multi_idx,
gint32 ts,
GError **error)
{
- gs_unref_object NMIP6Config *ip6_config = NULL;
+ nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
gs_unref_hashtable GHashTable *options = NULL;
struct in6_addr tmp_addr;
const struct in6_addr *dns;
@@ -741,11 +742,14 @@ lease_to_ip6_config (NMDedupMultiIndex *multi_idx,
char addr_str[NM_UTILS_INET_ADDRSTRLEN];
char **domains;
nm_auto_free_gstring GString *str = NULL;
+ gboolean has_any_addresses = FALSE;
int num, i;
g_return_val_if_fail (lease, NULL);
- ip6_config = nm_ip6_config_new (multi_idx, ifindex);
+ l3cd = nm_l3_config_data_new (multi_idx, ifindex);
+
+ nm_l3_config_data_set_source (l3cd, NM_IP_CONFIG_SOURCE_DHCP);
options = out_options ? nm_dhcp_option_create_options_dict () : NULL;
@@ -761,19 +765,23 @@ lease_to_ip6_config (NMDedupMultiIndex *multi_idx,
.addr_source = NM_IP_CONFIG_SOURCE_DHCP,
};
- nm_ip6_config_add_address (ip6_config, &address);
+ nm_l3_config_data_add_address_6 (l3cd, &address);
_nm_utils_inet6_ntop (&tmp_addr, addr_str);
g_string_append (nm_gstring_add_space_delimiter (str), addr_str);
- };
- if (str->len)
+
+ has_any_addresses = TRUE;
+ }
+
+ if (str->len) {
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp6_options,
NM_DHCP_OPTION_DHCP6_NM_IP_ADDRESS,
str->str);
+ }
if ( !info_only
- && nm_ip6_config_get_num_addresses (ip6_config) == 0) {
+ && !has_any_addresses) {
g_set_error_literal (error,
NM_MANAGER_ERROR,
NM_MANAGER_ERROR_FAILED,
@@ -787,7 +795,7 @@ lease_to_ip6_config (NMDedupMultiIndex *multi_idx,
for (i = 0; i < num; i++) {
_nm_utils_inet6_ntop (&dns[i], addr_str);
g_string_append (nm_gstring_add_space_delimiter (str), addr_str);
- nm_ip6_config_add_nameserver (ip6_config, &dns[i]);
+ nm_l3_config_data_add_nameserver (l3cd, AF_INET6, &dns[i]);
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp6_options,
@@ -800,7 +808,7 @@ lease_to_ip6_config (NMDedupMultiIndex *multi_idx,
nm_gstring_prepare (&str);
for (i = 0; i < num; i++) {
g_string_append (nm_gstring_add_space_delimiter (str), domains[i]);
- nm_ip6_config_add_search (ip6_config, domains[i]);
+ nm_l3_config_data_add_search (l3cd, AF_INET6, domains[i]);
}
nm_dhcp_option_add_option (options,
_nm_dhcp_option_dhcp6_options,
@@ -809,7 +817,7 @@ lease_to_ip6_config (NMDedupMultiIndex *multi_idx,
}
NM_SET_OUT (out_options, g_steal_pointer (&options));
- return g_steal_pointer (&ip6_config);
+ return g_steal_pointer (&l3cd);
}
static void
@@ -818,7 +826,7 @@ bound6_handle (NMDhcpSystemd *self)
NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self);
const gint32 ts = nm_utils_get_monotonic_timestamp_sec ();
const char *iface = nm_dhcp_client_get_iface (NM_DHCP_CLIENT (self));
- gs_unref_object NMIP6Config *ip6_config = NULL;
+ nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
gs_unref_hashtable GHashTable *options = NULL;
gs_free_error GError *error = NULL;
NMPlatformIP6Address prefix = { 0 };
@@ -833,16 +841,16 @@ bound6_handle (NMDhcpSystemd *self)
_LOGD ("lease available");
- ip6_config = lease_to_ip6_config (nm_dhcp_client_get_multi_idx (NM_DHCP_CLIENT (self)),
- iface,
- nm_dhcp_client_get_ifindex (NM_DHCP_CLIENT (self)),
- lease,
- nm_dhcp_client_get_info_only (NM_DHCP_CLIENT (self)),
- &options,
- ts,
- &error);
+ l3cd = lease_to_ip6_config (nm_dhcp_client_get_multi_idx (NM_DHCP_CLIENT (self)),
+ iface,
+ nm_dhcp_client_get_ifindex (NM_DHCP_CLIENT (self)),
+ lease,
+ nm_dhcp_client_get_info_only (NM_DHCP_CLIENT (self)),
+ &options,
+ ts,
+ &error);
- if (!ip6_config) {
+ if (!l3cd) {
_LOGW ("%s", error->message);
nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_FAIL, NULL, NULL);
return;
@@ -850,7 +858,7 @@ bound6_handle (NMDhcpSystemd *self)
nm_dhcp_client_set_state (NM_DHCP_CLIENT (self),
NM_DHCP_STATE_BOUND,
- NM_IP_CONFIG_CAST (ip6_config),
+ l3cd,
options);
sd_dhcp6_lease_reset_pd_prefix_iter (lease);
diff --git a/src/dhcp/nm-dhcp-utils.c b/src/dhcp/nm-dhcp-utils.c
index 88ced0548e..554b7f4e73 100644
--- a/src/dhcp/nm-dhcp-utils.c
+++ b/src/dhcp/nm-dhcp-utils.c
@@ -25,18 +25,18 @@ ip4_process_dhcpcd_rfc3442_routes (const char *iface,
const char *str,
guint32 route_table,
guint32 route_metric,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
guint32 *gwaddr)
{
- gs_free const char **routes = NULL;
- const char **r;
+ gs_strfreev char **routes = NULL;
gboolean have_routes = FALSE;
+ char **r;
- routes = nm_utils_strsplit_set (str, " ");
- if (!routes)
+ routes = g_strsplit (str, " ", 0);
+ if (g_strv_length (routes) == 0)
return FALSE;
- if ((NM_PTRARRAY_LEN (routes) % 2) != 0) {
+ if ((g_strv_length (routes) % 2) != 0) {
_LOG2W (LOGD_DHCP4, iface, " classless static routes provided, but invalid");
return FALSE;
}
@@ -72,14 +72,17 @@ ip4_process_dhcpcd_rfc3442_routes (const char *iface,
*gwaddr = rt_route;
} else {
_LOG2I (LOGD_DHCP4, iface, " classless static route %s/%d gw %s", *r, rt_cidr, *(r + 1));
- memset (&route, 0, sizeof (route));
- route.network = nm_utils_ip4_address_clear_host_address (rt_addr, rt_cidr);
- route.plen = rt_cidr;
- route.gateway = rt_route;
- route.rt_source = NM_IP_CONFIG_SOURCE_DHCP;
- route.metric = route_metric;
- route.table_coerced = nm_platform_route_table_coerce (route_table);
- nm_ip4_config_add_route (ip4_config, &route, NULL);
+
+ route = (NMPlatformIP4Route) {
+ .network = nm_utils_ip4_address_clear_host_address (rt_addr, rt_cidr),
+ .plen = rt_cidr,
+ .gateway = rt_route,
+ .rt_source = NM_IP_CONFIG_SOURCE_DHCP,
+ .metric = route_metric,
+ .table_coerced = nm_platform_route_table_coerce (route_table),
+ };
+
+ nm_l3_config_data_add_route_4 (l3cd, &route);
}
}
@@ -143,7 +146,7 @@ ip4_process_dhclient_rfc3442_routes (const char *iface,
const char *str,
guint32 route_table,
guint32 route_metric,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
guint32 *gwaddr)
{
gs_free const char **octets = NULL;
@@ -177,7 +180,8 @@ ip4_process_dhclient_rfc3442_routes (const char *iface,
route.rt_source = NM_IP_CONFIG_SOURCE_DHCP;
route.metric = route_metric;
route.table_coerced = nm_platform_route_table_coerce (route_table);
- nm_ip4_config_add_route (ip4_config, &route, NULL);
+
+ nm_l3_config_data_add_route_4 (l3cd, &route);
_LOG2I (LOGD_DHCP4, iface, " classless static route %s/%d gw %s",
_nm_utils_inet4_ntop (route.network, b1),
@@ -194,13 +198,13 @@ ip4_process_classless_routes (const char *iface,
GHashTable *options,
guint32 route_table,
guint32 route_metric,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cd,
guint32 *gwaddr)
{
const char *str, *p;
g_return_val_if_fail (options != NULL, FALSE);
- g_return_val_if_fail (ip4_config != NULL, FALSE);
+ g_return_val_if_fail (l3cd != NULL, FALSE);
*gwaddr = 0;
@@ -249,10 +253,10 @@ ip4_process_classless_routes (const char *iface,
if (strchr (str, '/')) {
/* dhcpcd format */
- return ip4_process_dhcpcd_rfc3442_routes (iface, str, route_table, route_metric, ip4_config, gwaddr);
+ return ip4_process_dhcpcd_rfc3442_routes (iface, str, route_table, route_metric, l3cd, gwaddr);
}
- return ip4_process_dhclient_rfc3442_routes (iface, str, route_table, route_metric, ip4_config, gwaddr);
+ return ip4_process_dhclient_rfc3442_routes (iface, str, route_table, route_metric, l3cd, gwaddr);
}
static void
@@ -260,21 +264,18 @@ process_classful_routes (const char *iface,
GHashTable *options,
guint32 route_table,
guint32 route_metric,
- NMIP4Config *ip4_config)
+ NML3ConfigData *l3cd)
{
- gs_free const char **searches = NULL;
- const char **s;
+ gs_strfreev char **searches = NULL;
const char *str;
+ char **s;
str = g_hash_table_lookup (options, "static_routes");
if (!str)
return;
- searches = nm_utils_strsplit_set (str, " ");
- if (!searches)
- return;
-
- if ((NM_PTRARRAY_LEN (searches) % 2) != 0) {
+ searches = g_strsplit (str, " ", 0);
+ if ((g_strv_length (searches) % 2)) {
_LOG2I (LOGD_DHCP, iface, " static routes provided, but invalid");
return;
}
@@ -294,8 +295,10 @@ process_classful_routes (const char *iface,
// FIXME: ensure the IP address and route are sane
- memset (&route, 0, sizeof (route));
- route.network = rt_addr;
+ route = (NMPlatformIP4Route) {
+ .network = rt_addr,
+ };
+
/* RFC 2132, updated by RFC 3442:
The Static Routes option (option 33) does not provide a subnet mask
for each route - it is assumed that the subnet mask is implicit in
@@ -312,17 +315,18 @@ process_classful_routes (const char *iface,
route.network = nm_utils_ip4_address_clear_host_address (route.network, route.plen);
- nm_ip4_config_add_route (ip4_config, &route, NULL);
+ nm_l3_config_data_add_route_4 (l3cd, &route);
+
_LOG2I (LOGD_DHCP, iface, " static route %s",
nm_platform_ip4_route_to_string (&route, NULL, 0));
}
}
static void
-process_domain_search (const char *iface,
+process_domain_search (int addr_family,
+ const char *iface,
const char *str,
- GFunc add_func,
- gpointer user_data)
+ NML3ConfigData *l3cd)
{
gs_free const char **searches = NULL;
gs_free char *unescaped = NULL;
@@ -331,7 +335,7 @@ process_domain_search (const char *iface,
int i;
g_return_if_fail (str != NULL);
- g_return_if_fail (add_func != NULL);
+ nm_assert (l3cd);
unescaped = g_strdup (str);
@@ -354,17 +358,11 @@ process_domain_search (const char *iface,
searches = nm_utils_strsplit_set (unescaped, " ");
for (s = searches; searches && *s; s++) {
_LOG2I (LOGD_DHCP, iface, " domain search '%s'", *s);
- add_func ((gpointer) *s, user_data);
+ nm_l3_config_data_add_search (l3cd, addr_family, *s);
}
}
-static void
-ip4_add_domain_search (gpointer data, gpointer user_data)
-{
- nm_ip4_config_add_search (NM_IP4_CONFIG (user_data), (const char *) data);
-}
-
-NMIP4Config *
+NML3ConfigData *
nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
int ifindex,
const char *iface,
@@ -372,7 +370,7 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
guint32 route_table,
guint32 route_metric)
{
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
guint32 tmp_addr;
in_addr_t addr;
NMPlatformIP4Address address;
@@ -381,19 +379,26 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
guint32 gateway = 0;
guint8 plen = 0;
char sbuf[NM_UTILS_INET_ADDRSTRLEN];
+ guint32 now;
g_return_val_if_fail (options != NULL, NULL);
- ip4_config = nm_ip4_config_new (multi_idx, ifindex);
- memset (&address, 0, sizeof (address));
- address.timestamp = nm_utils_get_monotonic_timestamp_sec ();
+ l3cd = nm_l3_config_data_new (multi_idx, ifindex);
+ nm_l3_config_data_set_source (l3cd, NM_IP_CONFIG_SOURCE_DHCP);
+
+ now = nm_utils_get_monotonic_timestamp_sec ();
+
+ address = (NMPlatformIP4Address) {
+ .timestamp = now,
+ };
str = g_hash_table_lookup (options, "ip_address");
- if (str && (inet_pton (AF_INET, str, &addr) > 0))
- _LOG2I (LOGD_DHCP4, iface, " address %s", str);
- else
+ if ( !str
+ || !nm_utils_parse_inaddr_bin (AF_INET, str, NULL, &addr))
return NULL;
+ _LOG2I (LOGD_DHCP4, iface, " address %s", str);
+
str = g_hash_table_lookup (options, "subnet_mask");
if (str && (inet_pton (AF_INET, str, &tmp_addr) > 0)) {
plen = nm_utils_ip4_netmask_to_prefix (tmp_addr);
@@ -408,8 +413,8 @@ 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, &gateway))
- process_classful_routes (iface, options, route_table, route_metric, ip4_config);
+ if (!ip4_process_classless_routes (iface, options, route_table, route_metric, l3cd, &gateway))
+ process_classful_routes (iface, options, route_table, route_metric, l3cd);
if (gateway) {
_LOG2I (LOGD_DHCP4, iface, " gateway %s", _nm_utils_inet4_ntop (gateway, sbuf));
@@ -420,10 +425,10 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
*/
str = g_hash_table_lookup (options, "routers");
if (str) {
- gs_free const char **routers = nm_utils_strsplit_set (str, " ");
- const char **s;
+ char **routers = g_strsplit (str, " ", 0);
+ char **s;
- for (s = routers; routers && *s; s++) {
+ for (s = routers; *s; s++) {
/* FIXME: how to handle multiple routers? */
if (inet_pton (AF_INET, *s, &gateway) > 0) {
_LOG2I (LOGD_DHCP4, iface, " gateway %s", *s);
@@ -432,6 +437,7 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
} else
_LOG2W (LOGD_DHCP4, iface, "ignoring invalid gateway '%s'", *s);
}
+ g_strfreev (routers);
}
}
@@ -443,7 +449,7 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
.metric = route_metric,
};
- nm_ip4_config_add_route (ip4_config, &r, NULL);
+ nm_l3_config_data_add_route_4 (l3cd, &r);
}
str = g_hash_table_lookup (options, "dhcp_lease_time");
@@ -453,7 +459,8 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
}
address.addr_source = NM_IP_CONFIG_SOURCE_DHCP;
- nm_ip4_config_add_address (ip4_config, &address);
+
+ nm_l3_config_data_add_address_4 (l3cd, &address);
str = g_hash_table_lookup (options, "host_name");
if (str)
@@ -467,7 +474,7 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
for (s = dns; dns && *s; s++) {
if (inet_pton (AF_INET, *s, &tmp_addr) > 0) {
if (tmp_addr) {
- nm_ip4_config_add_nameserver (ip4_config, tmp_addr);
+ nm_l3_config_data_add_nameserver (l3cd, AF_INET, &tmp_addr);
_LOG2I (LOGD_DHCP4, iface, " nameserver '%s'", *s);
}
} else
@@ -482,13 +489,13 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
for (s = domains; domains && *s; s++) {
_LOG2I (LOGD_DHCP4, iface, " domain name '%s'", *s);
- nm_ip4_config_add_domain (ip4_config, *s);
+ nm_l3_config_data_add_domain (l3cd, AF_INET, *s);
}
}
str = g_hash_table_lookup (options, "domain_search");
if (str)
- process_domain_search (iface, str, ip4_add_domain_search, ip4_config);
+ process_domain_search (AF_INET, iface, str, l3cd);
str = g_hash_table_lookup (options, "netbios_name_servers");
if (str) {
@@ -498,7 +505,7 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
for (s = nbns; nbns && *s; s++) {
if (inet_pton (AF_INET, *s, &tmp_addr) > 0) {
if (tmp_addr) {
- nm_ip4_config_add_wins (ip4_config, tmp_addr);
+ nm_l3_config_data_add_wins (l3cd, tmp_addr);
_LOG2I (LOGD_DHCP4, iface, " wins '%s'", *s);
}
} else
@@ -516,13 +523,13 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
return NULL;
if (int_mtu > 576)
- nm_ip4_config_set_mtu (ip4_config, int_mtu, NM_IP_CONFIG_SOURCE_DHCP);
+ nm_l3_config_data_set_mtu (l3cd, int_mtu);
}
str = g_hash_table_lookup (options, "nis_domain");
if (str) {
_LOG2I (LOGD_DHCP4, iface, " NIS domain '%s'", str);
- nm_ip4_config_set_nis_domain (ip4_config, str);
+ nm_l3_config_data_add_domain (l3cd, AF_INET, str);
}
str = g_hash_table_lookup (options, "nis_servers");
@@ -533,7 +540,7 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
for (s = nis; nis && *s; s++) {
if (inet_pton (AF_INET, *s, &tmp_addr) > 0) {
if (tmp_addr) {
- nm_ip4_config_add_nis_server (ip4_config, tmp_addr);
+ nm_l3_config_data_add_nis_server (l3cd, tmp_addr);
_LOG2I (LOGD_DHCP4, iface, " nis '%s'", *s);
}
} else
@@ -542,19 +549,14 @@ nm_dhcp_utils_ip4_config_from_options (NMDedupMultiIndex *multi_idx,
}
str = g_hash_table_lookup (options, "vendor_encapsulated_options");
- nm_ip4_config_set_metered (ip4_config, str && strstr (str, "ANDROID_METERED"));
+ if (str && strstr (str, "ANDROID_METERED"))
+ nm_l3_config_data_set_metered (l3cd, TRUE);
- return g_steal_pointer (&ip4_config);
+ return g_steal_pointer (&l3cd);
}
/*****************************************************************************/
-static void
-ip6_add_domain_search (gpointer data, gpointer user_data)
-{
- nm_ip6_config_add_search (NM_IP6_CONFIG (user_data), (const char *) data);
-}
-
NMPlatformIP6Address
nm_dhcp_utils_ip6_prefix_from_options (GHashTable *options)
{
@@ -603,25 +605,30 @@ nm_dhcp_utils_ip6_prefix_from_options (GHashTable *options)
return address;
}
-NMIP6Config *
+NML3ConfigData *
nm_dhcp_utils_ip6_config_from_options (NMDedupMultiIndex *multi_idx,
int ifindex,
const char *iface,
GHashTable *options,
gboolean info_only)
{
- gs_unref_object NMIP6Config *ip6_config = NULL;
+ nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
struct in6_addr tmp_addr;
NMPlatformIP6Address address;
char *str = NULL;
+ guint32 now;
g_return_val_if_fail (options != NULL, NULL);
- memset (&address, 0, sizeof (address));
- address.plen = 128;
- address.timestamp = nm_utils_get_monotonic_timestamp_sec ();
+ now = nm_utils_get_monotonic_timestamp_sec ();
+
+ address = (NMPlatformIP6Address) {
+ .plen = 128,
+ .timestamp = now,
+ };
- ip6_config = nm_ip6_config_new (multi_idx, ifindex);
+ l3cd = nm_l3_config_data_new (multi_idx, ifindex);
+ nm_l3_config_data_set_source (l3cd, NM_IP_CONFIG_SOURCE_DHCP);
str = g_hash_table_lookup (options, "max_life");
if (str) {
@@ -645,7 +652,7 @@ nm_dhcp_utils_ip6_config_from_options (NMDedupMultiIndex *multi_idx,
address.address = tmp_addr;
address.addr_source = NM_IP_CONFIG_SOURCE_DHCP;
- nm_ip6_config_add_address (ip6_config, &address);
+ nm_l3_config_data_add_address_6 (l3cd, &address);
_LOG2I (LOGD_DHCP6, iface, " address %s", str);
} else if (info_only == FALSE) {
/* No address in Managed mode is a hard error */
@@ -664,7 +671,7 @@ nm_dhcp_utils_ip6_config_from_options (NMDedupMultiIndex *multi_idx,
for (s = dns; dns && *s; s++) {
if (inet_pton (AF_INET6, *s, &tmp_addr) > 0) {
if (!IN6_IS_ADDR_UNSPECIFIED (&tmp_addr)) {
- nm_ip6_config_add_nameserver (ip6_config, &tmp_addr);
+ nm_l3_config_data_add_nameserver (l3cd, AF_INET6, &tmp_addr);
_LOG2I (LOGD_DHCP6, iface, " nameserver '%s'", *s);
}
} else
@@ -674,9 +681,9 @@ nm_dhcp_utils_ip6_config_from_options (NMDedupMultiIndex *multi_idx,
str = g_hash_table_lookup (options, "dhcp6_domain_search");
if (str)
- process_domain_search (iface, str, ip6_add_domain_search, ip6_config);
+ process_domain_search (AF_INET6, iface, str, l3cd);
- return g_steal_pointer (&ip6_config);
+ return g_steal_pointer (&l3cd);
}
char *
diff --git a/src/dhcp/nm-dhcp-utils.h b/src/dhcp/nm-dhcp-utils.h
index ecb91809be..24e465c814 100644
--- a/src/dhcp/nm-dhcp-utils.h
+++ b/src/dhcp/nm-dhcp-utils.h
@@ -8,21 +8,20 @@
#include <stdlib.h>
-#include "nm-ip4-config.h"
-#include "nm-ip6-config.h"
-
-NMIP4Config *nm_dhcp_utils_ip4_config_from_options (struct _NMDedupMultiIndex *multi_idx,
- int ifindex,
- const char *iface,
- GHashTable *options,
- guint32 route_table,
- guint32 route_metric);
-
-NMIP6Config *nm_dhcp_utils_ip6_config_from_options (struct _NMDedupMultiIndex *multi_idx,
- int ifindex,
- const char *iface,
- GHashTable *options,
- gboolean info_only);
+#include "nm-l3-config-data.h"
+
+NML3ConfigData *nm_dhcp_utils_ip4_config_from_options (struct _NMDedupMultiIndex *multi_idx,
+ int ifindex,
+ const char *iface,
+ GHashTable *options,
+ guint32 route_table,
+ guint32 route_metric);
+
+NML3ConfigData *nm_dhcp_utils_ip6_config_from_options (struct _NMDedupMultiIndex *multi_idx,
+ int ifindex,
+ const char *iface,
+ GHashTable *options,
+ gboolean info_only);
NMPlatformIP6Address nm_dhcp_utils_ip6_prefix_from_options (GHashTable *options);
diff --git a/src/dhcp/tests/test-dhcp-utils.c b/src/dhcp/tests/test-dhcp-utils.c
index e601534eb2..ad8c2cf6a3 100644
--- a/src/dhcp/tests/test-dhcp-utils.c
+++ b/src/dhcp/tests/test-dhcp-utils.c
@@ -17,18 +17,21 @@
#include "nm-test-utils-core.h"
-static NMIP4Config *
+static const NML3ConfigData *
_ip4_config_from_options (int ifindex,
const char *iface,
GHashTable *options,
guint32 route_metric)
{
nm_auto_unref_dedup_multi_index NMDedupMultiIndex *multi_idx = nm_dedup_multi_index_new ();
- NMIP4Config *config;
-
- config = nm_dhcp_utils_ip4_config_from_options (multi_idx, ifindex, iface, options, RT_TABLE_MAIN, route_metric);
- g_assert (config);
- return config;
+ NML3ConfigData *l3cd;
+
+ l3cd = nm_dhcp_utils_ip4_config_from_options (multi_idx, ifindex, iface, options, RT_TABLE_MAIN, route_metric);
+ g_assert (NM_IS_L3_CONFIG_DATA (l3cd));
+ g_assert (!nm_l3_config_data_is_sealed (l3cd));
+ if (nmtst_get_rand_bool ())
+ nm_l3_config_data_seal (l3cd);
+ return l3cd;
}
typedef struct {
@@ -70,8 +73,8 @@ static const Option generic_options[] = {
static void
test_generic_options (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const NMPlatformIP4Address *address;
const NMPlatformIP4Route *route;
guint32 tmp;
@@ -85,43 +88,42 @@ test_generic_options (void)
const char *expected_route1_gw = "10.1.1.1";
const char *expected_route2_dest = "100.99.88.56";
const char *expected_route2_gw = "10.1.1.1";
+ const char *const*strarr;
+ const in_addr_t *ia_arr;
+ guint u;
options = fill_table (generic_options, NULL);
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
- /* IP4 address */
- g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1);
- address = _nmtst_ip4_config_get_address (ip4_config, 0);
+ g_assert_cmpint (nm_l3_config_data_get_num_addresses (l3cd, AF_INET), ==, 1);
+ address = nmtst_l3_config_data_get_address_at_4 (l3cd, 0);
g_assert (inet_pton (AF_INET, expected_addr, &tmp) > 0);
g_assert (address->address == tmp);
g_assert (address->peer_address == tmp);
g_assert_cmpint (address->plen, ==, 24);
- /* Gateway */
- g_assert (inet_pton (AF_INET, expected_gw, &tmp) > 0);
- g_assert (nmtst_ip4_config_get_gateway (ip4_config) == tmp);
+ nmtst_assert_ip_address (AF_INET,
+ nmtst_l3_config_data_get_best_gateway (l3cd, AF_INET),
+ expected_gw);
- g_assert_cmpint (nm_ip4_config_get_num_wins (ip4_config), ==, 0);
+ g_assert (!nm_l3_config_data_get_wins (l3cd, &u));
+ g_assert_cmpint (u, ==, 0);
- g_assert_cmpint (nm_ip4_config_get_mtu (ip4_config), ==, 987);
+ g_assert_cmpint (nm_l3_config_data_get_mtu (l3cd), ==, 987);
- /* Domain searches */
- g_assert_cmpint (nm_ip4_config_get_num_searches (ip4_config), ==, 2);
- g_assert_cmpstr (nm_ip4_config_get_search (ip4_config, 0), ==, expected_search1);
- g_assert_cmpstr (nm_ip4_config_get_search (ip4_config, 1), ==, expected_search2);
+ strarr = nm_l3_config_data_get_searches (l3cd, AF_INET, &u);
+ g_assert_cmpint (u, ==, 2);
+ g_assert_cmpstr (strarr[0], ==, expected_search1);
+ g_assert_cmpstr (strarr[1], ==, expected_search2);
- /* DNS servers */
- g_assert_cmpint (nm_ip4_config_get_num_nameservers (ip4_config), ==, 2);
- g_assert (inet_pton (AF_INET, expected_dns1, &tmp) > 0);
- g_assert (nm_ip4_config_get_nameserver (ip4_config, 0) == tmp);
- g_assert (inet_pton (AF_INET, expected_dns2, &tmp) > 0);
- g_assert (nm_ip4_config_get_nameserver (ip4_config, 1) == tmp);
+ ia_arr = nm_l3_config_data_get_nameservers (l3cd, AF_INET, &u);
+ g_assert_cmpint (u, ==, 2);
+ nmtst_assert_ip4_address (ia_arr[0], expected_dns1);
+ nmtst_assert_ip4_address (ia_arr[1], expected_dns2);
- /* Routes */
- g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 3);
+ g_assert_cmpint (nm_l3_config_data_get_num_routes (l3cd, AF_INET), ==, 3);
- /* Route #1 */
- route = _nmtst_ip4_config_get_route (ip4_config, 0);
+ route = nmtst_l3_config_data_get_route_at_4 (l3cd, 0);
g_assert (inet_pton (AF_INET, expected_route1_dest, &tmp) > 0);
g_assert (route->network == tmp);
g_assert (inet_pton (AF_INET, expected_route1_gw, &tmp) > 0);
@@ -129,74 +131,68 @@ test_generic_options (void)
g_assert_cmpint (route->plen, ==, 32);
g_assert_cmpint (route->metric, ==, 0);
- /* Route #2 */
- route = _nmtst_ip4_config_get_route (ip4_config, 1);
+ route = nmtst_l3_config_data_get_route_at_4 (l3cd, 1);
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);
+ route = nmtst_l3_config_data_get_route_at_4 (l3cd, 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);
}
static void
test_wins_options (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const NMPlatformIP4Address *address;
- guint32 tmp;
const char *expected_wins1 = "63.12.199.5";
const char *expected_wins2 = "150.4.88.120";
static const Option data[] = {
{ "netbios_name_servers", "63.12.199.5 150.4.88.120" },
{ NULL, NULL }
};
+ const in_addr_t *ia_arr;
+ guint u;
options = fill_table (generic_options, NULL);
options = fill_table (data, options);
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
- /* IP4 address */
- g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1);
- address = _nmtst_ip4_config_get_address (ip4_config, 0);
+ g_assert_cmpint (nm_l3_config_data_get_num_addresses (l3cd, AF_INET), ==, 1);
+ address = nmtst_l3_config_data_get_address_at_4 (l3cd, 0);
g_assert (address);
- g_assert_cmpint (nm_ip4_config_get_num_wins (ip4_config), ==, 2);
- g_assert (inet_pton (AF_INET, expected_wins1, &tmp) > 0);
- g_assert (nm_ip4_config_get_wins (ip4_config, 0) == tmp);
- g_assert (inet_pton (AF_INET, expected_wins2, &tmp) > 0);
- g_assert (nm_ip4_config_get_wins (ip4_config, 1) == tmp);
- g_hash_table_destroy (options);
+ ia_arr = nm_l3_config_data_get_wins (l3cd, &u);
+ g_assert_cmpint (u, ==, 2);
+ nmtst_assert_ip4_address (ia_arr[0], expected_wins1);
+ nmtst_assert_ip4_address (ia_arr[1], expected_wins2);
}
static void
test_vendor_option_metered (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
static const Option data[] = {
{ "vendor_encapsulated_options", "ANDROID_METERED" },
{ NULL, NULL }
};
options = fill_table (generic_options, NULL);
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
- g_assert (nm_ip4_config_get_metered (ip4_config) == FALSE);
- g_hash_table_destroy (options);
- g_clear_object (&ip4_config);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
+ g_assert (nm_l3_config_data_get_metered (l3cd) == NM_TERNARY_DEFAULT);
+ nm_clear_pointer (&options, g_hash_table_destroy);
+ nm_clear_pointer (&l3cd, nm_l3_config_data_unref);
options = fill_table (generic_options, NULL);
options = fill_table (data, options);
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
- g_assert (nm_ip4_config_get_metered (ip4_config) == TRUE);
- g_hash_table_destroy (options);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
+ g_assert (nm_l3_config_data_get_metered (l3cd) == TRUE);
}
static void
@@ -254,7 +250,7 @@ test_parse_search_list (void)
}
static void
-ip4_test_route (NMIP4Config *ip4_config,
+ip4_test_route (const NML3ConfigData *l3cd,
guint route_num,
const char *expected_dest,
const char *expected_gw,
@@ -265,7 +261,7 @@ ip4_test_route (NMIP4Config *ip4_config,
g_assert (expected_prefix <= 32);
- route = _nmtst_ip4_config_get_route (ip4_config, route_num);
+ route = nmtst_l3_config_data_get_route_at_4 (l3cd, route_num);
g_assert (inet_pton (AF_INET, expected_dest, &tmp) > 0);
g_assert (route->network == tmp);
g_assert (inet_pton (AF_INET, expected_gw, &tmp) > 0);
@@ -274,21 +270,21 @@ ip4_test_route (NMIP4Config *ip4_config,
g_assert_cmpint (route->metric, ==, 0);
}
-static void
-ip4_test_gateway (NMIP4Config *ip4_config, const char *expected_gw)
-{
- guint32 tmp;
-
- g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1);
- g_assert (inet_pton (AF_INET, expected_gw, &tmp) > 0);
- g_assert (nmtst_ip4_config_get_gateway (ip4_config) == tmp);
-}
+#define ip4_test_gateway(l3cd, expected_gw) \
+ G_STMT_START { \
+ const NML3ConfigData *_l3cd = (l3cd); \
+ \
+ g_assert_cmpint (nm_l3_config_data_get_num_addresses (_l3cd, AF_INET), ==, 1); \
+ nmtst_assert_ip_address (AF_INET, \
+ nmtst_l3_config_data_get_best_gateway (_l3cd, AF_INET), \
+ expected_gw); \
+ } G_STMT_END
static void
test_classless_static_routes_1 (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const char *expected_route1_dest = "192.168.10.0";
const char *expected_route1_gw = "192.168.1.1";
const char *expected_route2_dest = "10.0.0.0";
@@ -301,22 +297,20 @@ test_classless_static_routes_1 (void)
options = fill_table (generic_options, NULL);
options = fill_table (data, options);
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
/* IP4 routes */
- 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);
+ g_assert_cmpint (nm_l3_config_data_get_num_routes (l3cd, AF_INET), ==, 3);
+ ip4_test_route (l3cd, 0, expected_route1_dest, expected_route1_gw, 24);
+ ip4_test_route (l3cd, 1, expected_route2_dest, expected_route2_gw, 8);
+ ip4_test_route (l3cd, 2, "0.0.0.0", "192.168.1.1", 0);
}
static void
test_classless_static_routes_2 (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const char *expected_route1_dest = "192.168.10.0";
const char *expected_route1_gw = "192.168.1.1";
const char *expected_route2_dest = "10.0.0.0";
@@ -329,22 +323,20 @@ test_classless_static_routes_2 (void)
options = fill_table (generic_options, NULL);
options = fill_table (data, options);
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
/* IP4 routes */
- 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);
+ g_assert_cmpint (nm_l3_config_data_get_num_routes (l3cd, AF_INET), ==, 3);
+ ip4_test_route (l3cd, 0, expected_route1_dest, expected_route1_gw, 24);
+ ip4_test_route (l3cd, 1, expected_route2_dest, expected_route2_gw, 8);
+ ip4_test_route (l3cd, 2, "0.0.0.0", expected_route1_gw, 0);
}
static void
test_fedora_dhclient_classless_static_routes (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const char *expected_route1_dest = "129.210.177.128";
const char *expected_route1_gw = "192.168.0.113";
const char *expected_route2_dest = "2.0.0.0";
@@ -358,25 +350,22 @@ test_fedora_dhclient_classless_static_routes (void)
options = fill_table (generic_options, NULL);
options = fill_table (data, options);
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
/* IP4 routes */
- 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);
+ g_assert_cmpint (nm_l3_config_data_get_num_routes (l3cd, AF_INET), ==, 3);
+ ip4_test_route (l3cd, 0, expected_route1_dest, expected_route1_gw, 25);
+ ip4_test_route (l3cd, 1, expected_route2_dest, expected_route2_gw, 7);
+ ip4_test_route (l3cd, 2, "0.0.0.0", expected_route1_gw, 0);
- /* Gateway */
- ip4_test_gateway (ip4_config, expected_gateway);
-
- g_hash_table_destroy (options);
+ ip4_test_gateway (l3cd, expected_gateway);
}
static void
test_dhclient_invalid_classless_routes_1 (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const char *expected_route1_dest = "192.168.10.0";
const char *expected_route1_gw = "192.168.1.1";
static const Option data[] = {
@@ -389,22 +378,20 @@ test_dhclient_invalid_classless_routes_1 (void)
options = fill_table (data, options);
NMTST_EXPECT_NM_WARN ("*ignoring invalid classless static routes*");
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
g_test_assert_expected_messages ();
/* IP4 routes */
- 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);
-
- g_hash_table_destroy (options);
+ g_assert_cmpint (nm_l3_config_data_get_num_routes (l3cd, AF_INET), ==, 2);
+ ip4_test_route (l3cd, 0, expected_route1_dest, expected_route1_gw, 24);
+ ip4_test_route (l3cd, 1, "0.0.0.0", expected_route1_gw, 0);
}
static void
test_dhcpcd_invalid_classless_routes_1 (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const char *expected_route1_dest = "10.1.1.5";
const char *expected_route1_gw = "10.1.1.1";
const char *expected_route2_dest = "100.99.88.56";
@@ -419,25 +406,23 @@ test_dhcpcd_invalid_classless_routes_1 (void)
options = fill_table (data, options);
NMTST_EXPECT_NM_WARN ("*ignoring invalid classless static routes*");
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
g_test_assert_expected_messages ();
/* Test falling back to old-style static routes if the classless static
* routes are invalid.
*/
- g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 3);
- ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 32);
- ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 32);
- ip4_test_route (ip4_config, 2, "0.0.0.0", "192.168.1.1", 0);
-
- g_hash_table_destroy (options);
+ g_assert_cmpint (nm_l3_config_data_get_num_routes (l3cd, AF_INET), ==, 3);
+ ip4_test_route (l3cd, 0, expected_route1_dest, expected_route1_gw, 32);
+ ip4_test_route (l3cd, 1, expected_route2_dest, expected_route2_gw, 32);
+ ip4_test_route (l3cd, 2, "0.0.0.0", "192.168.1.1", 0);
}
static void
test_dhclient_invalid_classless_routes_2 (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const char *expected_route1_dest = "10.1.1.5";
const char *expected_route1_gw = "10.1.1.1";
const char *expected_route2_dest = "100.99.88.56";
@@ -451,25 +436,23 @@ test_dhclient_invalid_classless_routes_2 (void)
options = fill_table (data, options);
NMTST_EXPECT_NM_WARN ("*ignoring invalid classless static routes*");
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
g_test_assert_expected_messages ();
/* Test falling back to old-style static routes if the classless static
* routes are invalid.
*/
- g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 3);
- ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 32);
- ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 32);
- ip4_test_route (ip4_config, 2, "0.0.0.0", "192.168.1.1", 0);
-
- g_hash_table_destroy (options);
+ g_assert_cmpint (nm_l3_config_data_get_num_routes (l3cd, AF_INET), ==, 3);
+ ip4_test_route (l3cd, 0, expected_route1_dest, expected_route1_gw, 32);
+ ip4_test_route (l3cd, 1, expected_route2_dest, expected_route2_gw, 32);
+ ip4_test_route (l3cd, 2, "0.0.0.0", "192.168.1.1", 0);
}
static void
test_dhcpcd_invalid_classless_routes_2 (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const char *expected_route1_dest = "10.1.1.5";
const char *expected_route1_gw = "10.1.1.1";
const char *expected_route2_dest = "100.99.88.56";
@@ -483,7 +466,7 @@ test_dhcpcd_invalid_classless_routes_2 (void)
options = fill_table (data, options);
NMTST_EXPECT_NM_WARN ("*ignoring invalid classless static routes*");
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
g_test_assert_expected_messages ();
/* Test falling back to old-style static routes if the classless static
@@ -491,19 +474,17 @@ test_dhcpcd_invalid_classless_routes_2 (void)
*/
/* Routes */
- g_assert_cmpint (nm_ip4_config_get_num_routes (ip4_config), ==, 3);
- ip4_test_route (ip4_config, 0, expected_route1_dest, expected_route1_gw, 32);
- ip4_test_route (ip4_config, 1, expected_route2_dest, expected_route2_gw, 32);
- ip4_test_route (ip4_config, 2, "0.0.0.0", "192.168.1.1", 0);
-
- g_hash_table_destroy (options);
+ g_assert_cmpint (nm_l3_config_data_get_num_routes (l3cd, AF_INET), ==, 3);
+ ip4_test_route (l3cd, 0, expected_route1_dest, expected_route1_gw, 32);
+ ip4_test_route (l3cd, 1, expected_route2_dest, expected_route2_gw, 32);
+ ip4_test_route (l3cd, 2, "0.0.0.0", "192.168.1.1", 0);
}
static void
test_dhclient_invalid_classless_routes_3 (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const char *expected_route1_dest = "192.168.10.0";
const char *expected_route1_gw = "192.168.1.1";
static const Option data[] = {
@@ -515,22 +496,20 @@ test_dhclient_invalid_classless_routes_3 (void)
options = fill_table (data, options);
NMTST_EXPECT_NM_WARN ("*ignoring invalid classless static routes*");
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
g_test_assert_expected_messages ();
/* IP4 routes */
- 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);
-
- g_hash_table_destroy (options);
+ g_assert_cmpint (nm_l3_config_data_get_num_routes (l3cd, AF_INET), ==, 2);
+ ip4_test_route (l3cd, 0, expected_route1_dest, expected_route1_gw, 24);
+ ip4_test_route (l3cd, 1, "0.0.0.0", expected_route1_gw, 0);
}
static void
test_dhcpcd_invalid_classless_routes_3 (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const char *expected_route1_dest = "192.168.10.0";
const char *expected_route1_gw = "192.168.1.1";
static Option data[] = {
@@ -542,22 +521,20 @@ test_dhcpcd_invalid_classless_routes_3 (void)
options = fill_table (data, options);
NMTST_EXPECT_NM_WARN ("*DHCP provided invalid classless static route*");
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
g_test_assert_expected_messages ();
/* IP4 routes */
- 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);
-
- g_hash_table_destroy (options);
+ g_assert_cmpint (nm_l3_config_data_get_num_routes (l3cd, AF_INET), ==, 2);
+ ip4_test_route (l3cd, 0, expected_route1_dest, expected_route1_gw, 24);
+ ip4_test_route (l3cd, 1, "0.0.0.0", expected_route1_gw, 0);
}
static void
test_dhclient_gw_in_classless_routes (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const char *expected_route1_dest = "192.168.10.0";
const char *expected_route1_gw = "192.168.1.1";
const char *expected_gateway = "192.2.3.4";
@@ -568,24 +545,21 @@ test_dhclient_gw_in_classless_routes (void)
options = fill_table (generic_options, NULL);
options = fill_table (data, options);
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
/* IP4 routes */
- 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", "192.2.3.4", 0);
+ g_assert_cmpint (nm_l3_config_data_get_num_routes (l3cd, AF_INET), ==, 2);
+ ip4_test_route (l3cd, 0, expected_route1_dest, expected_route1_gw, 24);
+ ip4_test_route (l3cd, 1, "0.0.0.0", "192.2.3.4", 0);
- /* Gateway */
- ip4_test_gateway (ip4_config, expected_gateway);
-
- g_hash_table_destroy (options);
+ ip4_test_gateway (l3cd, expected_gateway);
}
static void
test_dhcpcd_gw_in_classless_routes (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const char *expected_route1_dest = "192.168.10.0";
const char *expected_route1_gw = "192.168.1.1";
const char *expected_gateway = "192.2.3.4";
@@ -596,24 +570,21 @@ test_dhcpcd_gw_in_classless_routes (void)
options = fill_table (generic_options, NULL);
options = fill_table (data, options);
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
/* IP4 routes */
- 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", "192.2.3.4", 0);
-
- /* Gateway */
- ip4_test_gateway (ip4_config, expected_gateway);
+ g_assert_cmpint (nm_l3_config_data_get_num_routes (l3cd, AF_INET), ==, 2);
+ ip4_test_route (l3cd, 0, expected_route1_dest, expected_route1_gw, 24);
+ ip4_test_route (l3cd, 1, "0.0.0.0", "192.2.3.4", 0);
- g_hash_table_destroy (options);
+ ip4_test_gateway (l3cd, expected_gateway);
}
static void
test_escaped_domain_searches (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const char *expected_search0 = "host1";
const char *expected_search1 = "host2";
const char *expected_search2 = "host3";
@@ -621,62 +592,61 @@ test_escaped_domain_searches (void)
{ "domain_search", "host1\\032host2\\032host3" },
{ NULL, NULL }
};
+ const char *const*strarr;
+ guint u;
options = fill_table (generic_options, NULL);
options = fill_table (data, options);
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
-
- /* domain searches */
- g_assert_cmpint (nm_ip4_config_get_num_searches (ip4_config), ==, 3);
- g_assert_cmpstr (nm_ip4_config_get_search (ip4_config, 0), ==, expected_search0);
- g_assert_cmpstr (nm_ip4_config_get_search (ip4_config, 1), ==, expected_search1);
- g_assert_cmpstr (nm_ip4_config_get_search (ip4_config, 2), ==, expected_search2);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
- g_hash_table_destroy (options);
+ strarr = nm_l3_config_data_get_searches (l3cd, AF_INET, &u);
+ g_assert_cmpint (u, ==, 3);
+ g_assert_cmpstr (strarr[0], ==, expected_search0);
+ g_assert_cmpstr (strarr[1], ==, expected_search1);
+ g_assert_cmpstr (strarr[2], ==, expected_search2);
}
static void
test_invalid_escaped_domain_searches (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
static const Option data[] = {
{ "domain_search", "host1\\aahost2\\032host3" },
{ NULL, NULL }
};
+ const char *const*strarr;
+ guint u;
options = fill_table (generic_options, NULL);
options = fill_table (data, options);
NMTST_EXPECT_NM_WARN ("*invalid domain search*");
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
g_test_assert_expected_messages ();
- /* domain searches */
- g_assert_cmpint (nm_ip4_config_get_num_searches (ip4_config), ==, 0);
-
- g_hash_table_destroy (options);
+ strarr = nm_l3_config_data_get_searches (l3cd, AF_INET, &u);
+ g_assert_cmpint (u, ==, 0);
+ g_assert (!strarr);
}
static void
test_ip4_missing_prefix (const char *ip, guint32 expected_prefix)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const NMPlatformIP4Address *address;
options = fill_table (generic_options, NULL);
g_hash_table_insert (options, "ip_address", (gpointer) ip);
g_hash_table_remove (options, "subnet_mask");
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
- g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1);
- address = _nmtst_ip4_config_get_address (ip4_config, 0);
+ g_assert_cmpint (nm_l3_config_data_get_num_addresses (l3cd, AF_INET), ==, 1);
+ address = nmtst_l3_config_data_get_address_at_4 (l3cd, 0);
g_assert (address);
g_assert_cmpint (address->plen, ==, expected_prefix);
-
- g_hash_table_destroy (options);
}
static void
@@ -700,8 +670,8 @@ test_ip4_missing_prefix_8 (void)
static void
test_ip4_prefix_classless (void)
{
- GHashTable *options;
- gs_unref_object NMIP4Config *ip4_config = NULL;
+ gs_unref_hashtable GHashTable *options = NULL;
+ nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL;
const NMPlatformIP4Address *address;
/* Ensure that the missing-subnet-mask handler doesn't mangle classless
@@ -713,14 +683,12 @@ test_ip4_prefix_classless (void)
g_hash_table_insert (options, "ip_address", "172.16.54.22");
g_hash_table_insert (options, "subnet_mask", "255.255.252.0");
- ip4_config = _ip4_config_from_options (1, "eth0", options, 0);
+ l3cd = _ip4_config_from_options (1, "eth0", options, 0);
- g_assert_cmpint (nm_ip4_config_get_num_addresses (ip4_config), ==, 1);
- address = _nmtst_ip4_config_get_address (ip4_config, 0);
+ g_assert_cmpint (nm_l3_config_data_get_num_addresses (l3cd, AF_INET), ==, 1);
+ address = nmtst_l3_config_data_get_address_at_4 (l3cd, 0);
g_assert (address);
g_assert_cmpint (address->plen, ==, 22);
-
- g_hash_table_destroy (options);
}
#define COMPARE_ID(src, is_str, expected, expected_len) \
diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c
index c7d65d2a66..320f774193 100644
--- a/src/nm-iface-helper.c
+++ b/src/nm-iface-helper.c
@@ -93,7 +93,7 @@ static struct {
static void
dhcp4_state_changed (NMDhcpClient *client,
NMDhcpState state,
- NMIP4Config *ip4_config,
+ NML3ConfigData *l3cfg,
GHashTable *options,
const char *event_id,
gpointer user_data)
@@ -102,6 +102,7 @@ dhcp4_state_changed (NMDhcpClient *client,
NMIP4Config *existing;
gs_unref_ptrarray GPtrArray *ip4_dev_route_blacklist = NULL;
gs_free_error GError *error = NULL;
+ NMIP4Config *ip4_config = NULL; //XXX
g_return_if_fail (!ip4_config || NM_IS_IP4_CONFIG (ip4_config));
diff --git a/src/nm-ip-config.c b/src/nm-ip-config.c
index a7207a5f57..ce6bcf645a 100644
--- a/src/nm-ip-config.c
+++ b/src/nm-ip-config.c
@@ -57,8 +57,8 @@ set_property (GObject *object,
switch (prop_id) {
case PROP_L3CFG:
/* construct-only */
- priv->l3cfg = nm_g_object_ref (g_value_get_pointer (value));
- nm_assert (!priv->l3cfg || NM_IS_L3CFG (priv->l3cfg));
+ priv->l3cfg = g_object_ref (g_value_get_pointer (value));
+ nm_assert (NM_IS_L3CFG (priv->l3cfg));
break;
case PROP_IS_VPN:
/* construct-only */
@@ -104,7 +104,7 @@ finalize (GObject *object)
NMIPConfig *self = NM_IP_CONFIG (object);
NMIPConfigPrivate *priv = NM_IP_CONFIG_GET_PRIVATE (self);
- nm_g_object_unref (priv->l3cfg);
+ g_object_unref (priv->l3cfg);
G_OBJECT_CLASS (nm_ip_config_parent_class)->finalize (object);
}
diff --git a/src/nm-ip4-config.h b/src/nm-ip4-config.h
index d876f69ce0..31143c5fba 100644
--- a/src/nm-ip4-config.h
+++ b/src/nm-ip4-config.h
@@ -102,6 +102,8 @@ typedef struct _NMIP4ConfigClass NMIP4ConfigClass;
GType nm_ip4_config_get_type (void);
+NMIP4Config *nm_ip4_config_new_l3cfg (NML3Cfg *l3cfg);
+
NMIP4Config * nm_ip4_config_new (NMDedupMultiIndex *multi_idx,
int ifindex);
diff --git a/src/nm-ip6-config.h b/src/nm-ip6-config.h
index 187da967a9..6f7e2c9d43 100644
--- a/src/nm-ip6-config.h
+++ b/src/nm-ip6-config.h
@@ -60,6 +60,8 @@ typedef struct _NMIP6ConfigClass NMIP6ConfigClass;
GType nm_ip6_config_get_type (void);
+NMIP6Config *nm_ip6_config_new_l3cfg (NML3Cfg *l3cfg);
+
NMIP6Config * nm_ip6_config_new (struct _NMDedupMultiIndex *multi_idx, int ifindex);
NMIP6Config * nm_ip6_config_new_cloned (const NMIP6Config *src);
diff --git a/src/vpn/nm-vpn-connection.c b/src/vpn/nm-vpn-connection.c
index e2cad32b99..79e434b25d 100644
--- a/src/vpn/nm-vpn-connection.c
+++ b/src/vpn/nm-vpn-connection.c
@@ -33,6 +33,7 @@
#include "nm-vpn-plugin-info.h"
#include "nm-vpn-manager.h"
#include "dns/nm-dns-manager.h"
+#include "nm-l3-config-data.h"
typedef enum {
/* Only system secrets */
@@ -1465,6 +1466,7 @@ static void
nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict)
{
NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self);
+ nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
NMPlatformIP4Address address;
guint32 u32, route_metric;
NMSettingIPConfig *s_ip;
@@ -1514,8 +1516,12 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict)
if (ip_ifindex <= 0)
g_return_if_reached ();
+ l3cd = nm_l3_config_data_new (nm_netns_get_multi_idx (priv->netns),
+ ip_ifindex);
+ nm_l3_config_data_set_source (l3cd, NM_IP_CONFIG_SOURCE_VPN);
config = nm_ip4_config_new (nm_netns_get_multi_idx (priv->netns),
ip_ifindex);
+ nm_l3_config_data_set_dns_priority (l3cd, AF_INET, NM_DNS_PRIORITY_DEFAULT_VPN);
nm_ip4_config_set_dns_priority (config, NM_DNS_PRIORITY_DEFAULT_VPN);
memset (&address, 0, sizeof (address));
@@ -1538,6 +1544,7 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict)
if (address.address && address.plen && address.plen <= 32) {
address.addr_source = NM_IP_CONFIG_SOURCE_VPN;
+ nm_l3_config_data_add_address_4 (l3cd, &address);
nm_ip4_config_add_address (config, &address);
} else {
_LOGW ("invalid IP4 config received!");
@@ -1547,26 +1554,34 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict)
}
if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_DNS, "au", &iter)) {
- while (g_variant_iter_next (iter, "u", &u32))
+ while (g_variant_iter_next (iter, "u", &u32)) {
+ nm_l3_config_data_add_nameserver (l3cd, AF_INET, &u32);
nm_ip4_config_add_nameserver (config, u32);
+ }
g_variant_iter_free (iter);
}
if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_NBNS, "au", &iter)) {
- while (g_variant_iter_next (iter, "u", &u32))
+ while (g_variant_iter_next (iter, "u", &u32)) {
+ nm_l3_config_data_add_wins (l3cd, u32);
nm_ip4_config_add_wins (config, u32);
+ }
g_variant_iter_free (iter);
}
if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_MSS, "u", &u32))
mss = u32;
- if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_DOMAIN, "&s", &str))
+ if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_DOMAIN, "&s", &str)) {
+ nm_l3_config_data_add_domain (l3cd, AF_INET, str);
nm_ip4_config_add_domain (config, str);
+ }
if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_DOMAINS, "as", &iter)) {
- while (g_variant_iter_next (iter, "&s", &str))
+ while (g_variant_iter_next (iter, "&s", &str)) {
+ nm_l3_config_data_add_domain (l3cd, AF_INET, str);
nm_ip4_config_add_domain (config, str);
+ }
g_variant_iter_free (iter);
}
@@ -1583,8 +1598,10 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict)
NMDedupMultiIter ipconf_iter;
const NMPlatformIP4Route *route;
- nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, priv->ip4_config, &route)
+ nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, priv->ip4_config, &route) {
+ nm_l3_config_data_add_route_4 (l3cd, route);
nm_ip4_config_add_route (config, route, NULL);
+ }
}
} else if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_ROUTES, "aau", &iter)) {
while (g_variant_iter_next (iter, "@au", &v)) {
@@ -1620,6 +1637,7 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict)
break;
}
+ nm_l3_config_data_add_route_4 (l3cd, &route);
nm_ip4_config_add_route (config, &route, NULL);
break;
default:
@@ -1652,6 +1670,7 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict)
.mss = mss,
};
+ nm_l3_config_data_add_route_4 (l3cd, &r);
nm_ip4_config_add_route (config, &r, NULL);
}
@@ -1679,6 +1698,7 @@ static void
nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict)
{
NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self);
+ nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
NMPlatformIP6Address address;
guint32 u32, route_metric;
NMSettingIPConfig *s_ip;
@@ -1714,8 +1734,12 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict)
if (ip_ifindex <= 0)
g_return_if_reached ();
+ l3cd = nm_l3_config_data_new (nm_netns_get_multi_idx (priv->netns),
+ ip_ifindex);
+ nm_l3_config_data_set_source (l3cd, NM_IP_CONFIG_SOURCE_VPN);
config = nm_ip6_config_new (nm_netns_get_multi_idx (priv->netns),
ip_ifindex);
+ nm_l3_config_data_set_dns_priority (l3cd, AF_INET6, NM_DNS_PRIORITY_DEFAULT_VPN);
nm_ip6_config_set_dns_priority (config, NM_DNS_PRIORITY_DEFAULT_VPN);
memset (&address, 0, sizeof (address));
@@ -1743,6 +1767,7 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict)
if (!IN6_IS_ADDR_UNSPECIFIED (&address.address) && address.plen && address.plen <= 128) {
address.addr_source = NM_IP_CONFIG_SOURCE_VPN;
+ nm_l3_config_data_add_address_6 (l3cd, &address);
nm_ip6_config_add_address (config, &address);
} else {
_LOGW ("invalid IP6 config received!");
@@ -1755,8 +1780,10 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict)
while (g_variant_iter_next (iter, "@ay", &v)) {
struct in6_addr dns;
- if (ip6_addr_from_variant (v, &dns))
+ if (ip6_addr_from_variant (v, &dns)) {
+ nm_l3_config_data_add_nameserver (l3cd, AF_INET6, &dns);
nm_ip6_config_add_nameserver (config, &dns);
+ }
g_variant_unref (v);
}
g_variant_iter_free (iter);
@@ -1765,12 +1792,16 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict)
if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP6_CONFIG_MSS, "u", &u32))
mss = u32;
- if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP6_CONFIG_DOMAIN, "&s", &str))
+ if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP6_CONFIG_DOMAIN, "&s", &str)) {
+ nm_l3_config_data_add_domain (l3cd, AF_INET6, str);
nm_ip6_config_add_domain (config, str);
+ }
if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP6_CONFIG_DOMAINS, "as", &iter)) {
- while (g_variant_iter_next (iter, "&s", &str))
+ while (g_variant_iter_next (iter, "&s", &str)) {
+ nm_l3_config_data_add_domain (l3cd, AF_INET6, str);
nm_ip6_config_add_domain (config, str);
+ }
g_variant_iter_free (iter);
}
@@ -1786,8 +1817,10 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict)
NMDedupMultiIter ipconf_iter;
const NMPlatformIP6Route *route;
- nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, priv->ip6_config, &route)
+ nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, priv->ip6_config, &route) {
+ nm_l3_config_data_add_route_6 (l3cd, route);
nm_ip6_config_add_route (config, route, NULL);
+ }
}
} else if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP6_CONFIG_ROUTES, "a(ayuayu)", &iter)) {
GVariant *dest, *next_hop;
@@ -1823,6 +1856,7 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict)
goto next;
}
+ nm_l3_config_data_add_route_6 (l3cd, &route);
nm_ip6_config_add_route (config, &route, NULL);
next:
@@ -1852,6 +1886,7 @@ next:
.mss = mss,
};
+ nm_l3_config_data_add_route_6 (l3cd, &r);
nm_ip6_config_add_route (config, &r, NULL);
}