diff options
author | Thomas Haller <thaller@redhat.com> | 2020-07-23 10:36:04 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-09-03 11:52:43 +0200 |
commit | 90597bef818575f09de9e20c362bcd0974ee2cf6 (patch) | |
tree | 587d44d288d838562ed523ad7e1b96849e8904d9 | |
parent | aff1a7dfa1b4327863b11a0449136972f00c259c (diff) | |
download | NetworkManager-th/l3cfg-6.tar.gz |
core: use NML3ConfigData (WIP)th/l3cfg-6
45 files changed, 1301 insertions, 2331 deletions
diff --git a/.gitignore b/.gitignore index 8c08337548..12d35c9fde 100644 --- a/.gitignore +++ b/.gitignore @@ -220,7 +220,6 @@ test-*.trs /src/NetworkManager-all-sym /src/NetworkManager.ver /src/devices/bluetooth/tests/nm-bt-test -/src/devices/tests/test-acd /src/devices/tests/test-lldp /src/devices/wifi/tests/test-devices-wifi /src/devices/wwan/tests/test-service-providers @@ -365,3 +364,4 @@ test-*.trs /src/tests/test-general /src/tests/test-general-with-expect /src/tests/test-resolvconf-capture +/src/devices/tests/test-acd diff --git a/Makefile.am b/Makefile.am index bfb448c29f..96f494448f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -2178,8 +2178,6 @@ src_libNetworkManager_la_SOURCES = \ src/nm-checkpoint-manager.c \ src/nm-checkpoint-manager.h \ \ - src/devices/nm-acd-manager.c \ - src/devices/nm-acd-manager.h \ src/devices/nm-lldp-listener.c \ src/devices/nm-lldp-listener.h \ src/devices/nm-device.c \ @@ -4002,20 +4000,14 @@ src_devices_tests_ldflags = \ check_programs += \ src/devices/tests/test-lldp \ - src/devices/tests/test-acd + $(NULL) src_devices_tests_test_lldp_CPPFLAGS = $(src_cppflags_test) src_devices_tests_test_lldp_LDFLAGS = $(src_devices_tests_ldflags) src_devices_tests_test_lldp_LDADD = \ src/libNetworkManagerTest.la -src_devices_tests_test_acd_CPPFLAGS = $(src_cppflags_test) -src_devices_tests_test_acd_LDFLAGS = $(src_devices_tests_ldflags) -src_devices_tests_test_acd_LDADD = \ - src/libNetworkManagerTest.la - $(src_devices_tests_test_lldp_OBJECTS): $(libnm_core_lib_h_pub_mkenums) -$(src_devices_tests_test_acd_OBJECTS): $(libnm_core_lib_h_pub_mkenums) EXTRA_DIST += \ src/devices/tests/meson.build diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c index 8f7cba221a..919c5d14ce 100644 --- a/src/devices/adsl/nm-device-adsl.c +++ b/src/devices/adsl/nm-device-adsl.c @@ -15,7 +15,6 @@ #include <unistd.h> #include <stdlib.h> -#include "nm-ip4-config.h" #include "devices/nm-device-private.h" #include "platform/nm-platform.h" #include "ppp/nm-ppp-manager-call.h" @@ -429,20 +428,29 @@ ppp_ifindex_set (NMPPPManager *ppp_manager, } static void -ppp_ip4_config (NMPPPManager *ppp_manager, - NMIP4Config *config, +ppp_new_config (NMPPPManager *ppp_manager, + int addr_family, + const NML3ConfigData *l3cd, + const NMUtilsIPv6IfaceId *iid, gpointer user_data) { NMDevice *device = NM_DEVICE (user_data); - /* Ignore PPP IP4 events that come in after initial configuration */ - if (nm_device_activate_ip4_state_in_conf (device)) - nm_device_activate_schedule_ip_config_result (device, AF_INET, NM_IP_CONFIG_CAST (config)); + if (addr_family != AF_INET) + return; + + if (!nm_device_activate_ip4_state_in_conf (device)) { + /* Ignore PPP events that come in after initial configuration */ + return; + } + + nm_device_set_dev2_ip_config (device, AF_INET, l3cd); + nm_device_activate_schedule_ip_config_result (device, AF_INET); } static NMActStageReturn act_stage3_ip4_config_start (NMDevice *device, - NMIP4Config **out_config, + const NML3ConfigData **out_l3cd, NMDeviceStateReason *out_failure_reason) { NMDeviceAdsl *self = NM_DEVICE_ADSL (device); @@ -494,14 +502,17 @@ act_stage3_ip4_config_start (NMDevice *device, return NM_ACT_STAGE_RETURN_FAILURE; } - g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_STATE_CHANGED, + g_signal_connect (priv->ppp_manager, + NM_PPP_MANAGER_SIGNAL_STATE_CHANGED, G_CALLBACK (ppp_state_changed), self); - g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IFINDEX_SET, + g_signal_connect (priv->ppp_manager, + NM_PPP_MANAGER_SIGNAL_IFINDEX_SET, G_CALLBACK (ppp_ifindex_set), self); - g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, - G_CALLBACK (ppp_ip4_config), + g_signal_connect (priv->ppp_manager, + NM_PPP_MANAGER_SIGNAL_NEW_CONFIG, + G_CALLBACK (ppp_new_config), self); return NM_ACT_STAGE_RETURN_POSTPONE; } @@ -509,13 +520,13 @@ act_stage3_ip4_config_start (NMDevice *device, static NMActStageReturn act_stage3_ip_config_start (NMDevice *device, int addr_family, - gpointer *out_config, + const NML3ConfigData **out_l3cd, NMDeviceStateReason *out_failure_reason) { if (addr_family == AF_INET) - return act_stage3_ip4_config_start (device, (NMIP4Config **) out_config, out_failure_reason); + return act_stage3_ip4_config_start (device, out_l3cd, out_failure_reason); - return NM_DEVICE_CLASS (nm_device_adsl_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason); + return NM_DEVICE_CLASS (nm_device_adsl_parent_class)->act_stage3_ip_config_start (device, addr_family, out_l3cd, out_failure_reason); } static void @@ -525,7 +536,7 @@ adsl_cleanup (NMDeviceAdsl *self) if (priv->ppp_manager) { g_signal_handlers_disconnect_by_func (priv->ppp_manager, G_CALLBACK (ppp_state_changed), self); - g_signal_handlers_disconnect_by_func (priv->ppp_manager, G_CALLBACK (ppp_ip4_config), self); + g_signal_handlers_disconnect_by_func (priv->ppp_manager, G_CALLBACK (ppp_new_config), self); nm_ppp_manager_stop (priv->ppp_manager, NULL, NULL, NULL); g_clear_object (&priv->ppp_manager); } diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c index 9ab3810f68..b95f38b308 100644 --- a/src/devices/bluetooth/nm-device-bt.c +++ b/src/devices/bluetooth/nm-device-bt.c @@ -24,7 +24,6 @@ #include "settings/nm-settings-connection.h" #include "nm-utils.h" #include "nm-bt-error.h" -#include "nm-ip4-config.h" #include "platform/nm-platform.h" #include "devices/wwan/nm-modem-manager.h" @@ -543,14 +542,20 @@ device_state_changed (NMDevice *device, } static void -modem_ip4_config_result (NMModem *modem, - NMIP4Config *config, - GError *error, - gpointer user_data) +modem_new_config (NMModem *modem, + int addr_family, + const NML3ConfigData *l3cd, + gboolean do_slaac, + const NMUtilsIPv6IfaceId *iid, + GError *error, + gpointer user_data) { NMDeviceBt *self = NM_DEVICE_BT (user_data); NMDevice *device = NM_DEVICE (self); + if (addr_family != AF_INET) + return; + g_return_if_fail (nm_device_activate_ip4_state_in_conf (device) == TRUE); if (error) { @@ -563,7 +568,8 @@ modem_ip4_config_result (NMModem *modem, return; } - nm_device_activate_schedule_ip_config_result (device, AF_INET, NM_IP_CONFIG_CAST (config)); + nm_device_set_dev2_ip_config (device, AF_INET, l3cd); + nm_device_activate_schedule_ip_config_result (device, AF_INET); } static void @@ -692,7 +698,7 @@ modem_try_claim (NMDeviceBt *self, g_signal_connect (modem, NM_MODEM_PPP_STATS, G_CALLBACK (ppp_stats), self); g_signal_connect (modem, NM_MODEM_PPP_FAILED, G_CALLBACK (ppp_failed), self); g_signal_connect (modem, NM_MODEM_PREPARE_RESULT, G_CALLBACK (modem_prepare_result), self); - g_signal_connect (modem, NM_MODEM_IP4_CONFIG_RESULT, G_CALLBACK (modem_ip4_config_result), self); + g_signal_connect (modem, NM_MODEM_NEW_CONFIG, G_CALLBACK (modem_new_config), self); g_signal_connect (modem, NM_MODEM_AUTH_REQUESTED, G_CALLBACK (modem_auth_requested), self); g_signal_connect (modem, NM_MODEM_AUTH_RESULT, G_CALLBACK (modem_auth_result), self); g_signal_connect (modem, NM_MODEM_STATE_CHANGED, G_CALLBACK (modem_state_cb), self); @@ -1005,7 +1011,7 @@ act_stage2_config (NMDevice *device, static NMActStageReturn act_stage3_ip_config_start (NMDevice *device, int addr_family, - gpointer *out_config, + const NML3ConfigData **out_l3cd, NMDeviceStateReason *out_failure_reason) { NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (device); @@ -1025,7 +1031,7 @@ act_stage3_ip_config_start (NMDevice *device, } } - return NM_DEVICE_CLASS (nm_device_bt_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason); + return NM_DEVICE_CLASS (nm_device_bt_parent_class)->act_stage3_ip_config_start (device, addr_family, out_l3cd, out_failure_reason); } static void diff --git a/src/devices/nm-acd-manager.c b/src/devices/nm-acd-manager.c deleted file mode 100644 index 1c6c42a0ea..0000000000 --- a/src/devices/nm-acd-manager.c +++ /dev/null @@ -1,509 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (C) 2015 - 2018 Red Hat, Inc. - */ - -#include "nm-default.h" - -#include "nm-acd-manager.h" - -#include <netinet/in.h> -#include <sys/types.h> -#include <sys/wait.h> - -#include "platform/nm-platform.h" -#include "nm-utils.h" -#include "NetworkManagerUtils.h" -#include "n-acd/src/n-acd.h" - -/*****************************************************************************/ - -typedef enum { - STATE_INIT, - STATE_PROBING, - STATE_PROBE_DONE, - STATE_ANNOUNCING, -} State; - -typedef struct { - in_addr_t address; - gboolean duplicate; - NAcdProbe *probe; -} AddressInfo; - -struct _NMAcdManager { - int ifindex; - guint8 hwaddr[ETH_ALEN]; - State state; - GHashTable *addresses; - guint completed; - NAcd *acd; - GSource *event_source; - - NMAcdCallbacks callbacks; - gpointer user_data; -}; - -/*****************************************************************************/ - -#define _NMLOG_DOMAIN LOGD_IP4 -#define _NMLOG_PREFIX_NAME "acd" -#define _NMLOG(level, ...) \ - G_STMT_START { \ - char _sbuf[64]; \ - \ - nm_log ((level), _NMLOG_DOMAIN, \ - self && self->ifindex > 0 ? nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex) : NULL, \ - NULL, \ - "%s%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \ - _NMLOG_PREFIX_NAME, \ - self ? nm_sprintf_buf (_sbuf, "[%p,%d]", self, self->ifindex) : "" \ - _NM_UTILS_MACRO_REST (__VA_ARGS__)); \ - } G_STMT_END - -/*****************************************************************************/ - -static const char * -_acd_event_to_string (unsigned int event) -{ - switch (event) { - case N_ACD_EVENT_READY: - return "ready"; - case N_ACD_EVENT_USED: - return "used"; - case N_ACD_EVENT_DEFENDED: - return "defended"; - case N_ACD_EVENT_CONFLICT: - return "conflict"; - case N_ACD_EVENT_DOWN: - return "down"; - } - return NULL; -} - -#define ACD_EVENT_TO_STRING_BUF_SIZE 50 - -static const char * -_acd_event_to_string_buf (unsigned event, char buffer[static ACD_EVENT_TO_STRING_BUF_SIZE]) -{ - const char *s; - - s = _acd_event_to_string (event); - if (s) - return s; - - g_snprintf (buffer, ACD_EVENT_TO_STRING_BUF_SIZE, "(%u)", event); - return buffer; -} - -static const char * -acd_error_to_string (int error) -{ - if (error < 0) - return nm_strerror_native (-error); - - switch (error) { - case _N_ACD_E_SUCCESS: - return "success"; - case N_ACD_E_PREEMPTED: - return "preempted"; - case N_ACD_E_INVALID_ARGUMENT: - return "invalid argument"; - } - - g_return_val_if_reached (NULL); -} - -static int -acd_error_to_nmerr (int error, gboolean always_fail) -{ - if (error < 0) - return -nm_errno_native (error); - - if (always_fail) { - if (NM_IN_SET (error, N_ACD_E_PREEMPTED, - N_ACD_E_INVALID_ARGUMENT)) - return -NME_UNSPEC; - g_return_val_if_reached (-NME_UNSPEC); - } - - /* so, @error is either zero (indicating success) or one - * of the special status codes like N_ACD_E_*. In both cases, - * return the positive value here. */ - if (NM_IN_SET (error, _N_ACD_E_SUCCESS, - N_ACD_E_PREEMPTED, - N_ACD_E_INVALID_ARGUMENT)) - return error; - - g_return_val_if_reached (error); -} - -/*****************************************************************************/ - -/** - * nm_acd_manager_add_address: - * @self: a #NMAcdManager - * @address: an IP address - * - * Add @address to the list of IP addresses to probe. - - * Returns: %TRUE on success, %FALSE if the address was already in the list - */ -gboolean -nm_acd_manager_add_address (NMAcdManager *self, in_addr_t address) -{ - AddressInfo *info; - - g_return_val_if_fail (self, FALSE); - g_return_val_if_fail (self->state == STATE_INIT, FALSE); - - if (g_hash_table_lookup (self->addresses, GUINT_TO_POINTER (address))) - return FALSE; - - info = g_slice_new0 (AddressInfo); - info->address = address; - - g_hash_table_insert (self->addresses, GUINT_TO_POINTER (address), info); - - return TRUE; -} - -static gboolean -acd_event (int fd, - GIOCondition condition, - gpointer data) -{ - NMAcdManager *self = data; - NAcdEvent *event; - AddressInfo *info; - gboolean emit_probe_terminated = FALSE; - char address_str[INET_ADDRSTRLEN]; - int r; - - if (n_acd_dispatch (self->acd)) - return G_SOURCE_CONTINUE; - - while ( !n_acd_pop_event (self->acd, &event) - && event) { - char to_string_buffer[ACD_EVENT_TO_STRING_BUF_SIZE]; - gs_free char *hwaddr_str = NULL; - gboolean check_probing_done = FALSE; - - switch (event->event) { - case N_ACD_EVENT_READY: - n_acd_probe_get_userdata (event->ready.probe, (void **) &info); - info->duplicate = FALSE; - if (self->state == STATE_ANNOUNCING) { - /* fake probe ended, start announcing */ - r = n_acd_probe_announce (info->probe, N_ACD_DEFEND_ONCE); - if (r) { - _LOGW ("couldn't announce address %s on interface '%s': %s", - _nm_utils_inet4_ntop (info->address, address_str), - nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex), - acd_error_to_string (r)); - } else { - _LOGD ("announcing address %s", - _nm_utils_inet4_ntop (info->address, address_str)); - } - } - check_probing_done = TRUE; - break; - case N_ACD_EVENT_USED: - n_acd_probe_get_userdata (event->used.probe, (void **) &info); - info->duplicate = TRUE; - check_probing_done = TRUE; - break; - case N_ACD_EVENT_DEFENDED: - n_acd_probe_get_userdata (event->defended.probe, (void **) &info); - _LOGD ("defended address %s from host %s", - _nm_utils_inet4_ntop (info->address, address_str), - (hwaddr_str = nm_utils_hwaddr_ntoa (event->defended.sender, - event->defended.n_sender))); - break; - case N_ACD_EVENT_CONFLICT: - n_acd_probe_get_userdata (event->conflict.probe, (void **) &info); - _LOGW ("conflict for address %s detected with host %s on interface '%s'", - _nm_utils_inet4_ntop (info->address, address_str), - (hwaddr_str = nm_utils_hwaddr_ntoa (event->defended.sender, - event->defended.n_sender)), - nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex)); - break; - default: - _LOGD ("unhandled event '%s'", _acd_event_to_string_buf (event->event, to_string_buffer)); - break; - } - - if ( check_probing_done - && self->state == STATE_PROBING - && ++self->completed == g_hash_table_size (self->addresses)) { - self->state = STATE_PROBE_DONE; - emit_probe_terminated = TRUE; - } - } - - if (emit_probe_terminated) { - if (self->callbacks.probe_terminated_callback) { - self->callbacks.probe_terminated_callback (self, - self->user_data); - } - } - - return G_SOURCE_CONTINUE; -} - -static gboolean -acd_probe_add (NMAcdManager *self, - AddressInfo *info, - guint64 timeout) -{ - NAcdProbeConfig *probe_config; - int r; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; - - r = n_acd_probe_config_new (&probe_config); - if (r) { - _LOGW ("could not create probe config for %s on interface '%s': %s", - _nm_utils_inet4_ntop (info->address, sbuf), - nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex), - acd_error_to_string (r)); - return FALSE; - } - - n_acd_probe_config_set_ip (probe_config, (struct in_addr) { info->address }); - n_acd_probe_config_set_timeout (probe_config, timeout); - - r = n_acd_probe (self->acd, &info->probe, probe_config); - if (r) { - _LOGW ("could not start probe for %s on interface '%s': %s", - _nm_utils_inet4_ntop (info->address, sbuf), - nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex), - acd_error_to_string (r)); - n_acd_probe_config_free (probe_config); - return FALSE; - } - - n_acd_probe_set_userdata (info->probe, info); - n_acd_probe_config_free (probe_config); - - return TRUE; -} - -static int -acd_init (NMAcdManager *self) -{ - NAcdConfig *config; - int r; - - if (self->acd) - return 0; - - r = n_acd_config_new (&config); - if (r) - return r; - - n_acd_config_set_ifindex (config, self->ifindex); - n_acd_config_set_transport (config, N_ACD_TRANSPORT_ETHERNET); - n_acd_config_set_mac (config, self->hwaddr, ETH_ALEN); - - r = n_acd_new (&self->acd, config); - n_acd_config_free (config); - return r; -} - -/** - * nm_acd_manager_start_probe: - * @self: a #NMAcdManager - * @timeout: maximum probe duration in milliseconds - * @error: location to store error, or %NULL - * - * Start probing IP addresses for duplicates; when the probe terminates a - * PROBE_TERMINATED signal is emitted. - * - * Returns: 0 on success or a negative NetworkManager error code (NME_*). - */ -int -nm_acd_manager_start_probe (NMAcdManager *self, guint timeout) -{ - GHashTableIter iter; - AddressInfo *info; - gboolean success = FALSE; - int fd, r; - - g_return_val_if_fail (self, FALSE); - g_return_val_if_fail (self->state == STATE_INIT, FALSE); - - r = acd_init (self); - if (r) { - _LOGW ("couldn't init ACD for probing on interface '%s': %s", - nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex), - acd_error_to_string (r)); - return acd_error_to_nmerr (r, TRUE); - } - - self->completed = 0; - - g_hash_table_iter_init (&iter, self->addresses); - while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &info)) - success |= acd_probe_add (self, info, timeout); - - if (success) - self->state = STATE_PROBING; - - nm_assert (!self->event_source); - n_acd_get_fd (self->acd, &fd); - self->event_source = nm_g_unix_fd_source_new (fd, - G_IO_IN, - G_PRIORITY_DEFAULT, - acd_event, - self, - NULL); - g_source_attach (self->event_source, NULL); - - return success ? 0 : -NME_UNSPEC; -} - -/** - * nm_acd_manager_check_address: - * @self: a #NMAcdManager - * @address: an IP address - * - * Check if an IP address is duplicate. @address must have been added with - * nm_acd_manager_add_address(). - * - * Returns: %TRUE if the address is not duplicate, %FALSE otherwise - */ -gboolean -nm_acd_manager_check_address (NMAcdManager *self, in_addr_t address) -{ - AddressInfo *info; - - g_return_val_if_fail (self, FALSE); - g_return_val_if_fail (NM_IN_SET (self->state, STATE_INIT, STATE_PROBE_DONE), FALSE); - - info = g_hash_table_lookup (self->addresses, GUINT_TO_POINTER (address)); - g_return_val_if_fail (info, FALSE); - - return !info->duplicate; -} - -/** - * nm_acd_manager_announce_addresses: - * @self: a #NMAcdManager - * - * Start announcing addresses. - * - * Returns: a negative NetworkManager error number or zero on success. - */ -int -nm_acd_manager_announce_addresses (NMAcdManager *self) -{ - GHashTableIter iter; - AddressInfo *info; - int r; - int fd; - gboolean success = TRUE; - - r = acd_init (self); - if (r) { - _LOGW ("couldn't init ACD for announcing addresses on interface '%s': %s", - nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex), - acd_error_to_string (r)); - return acd_error_to_nmerr (r, TRUE); - } - - if (self->state == STATE_INIT) { - /* n-acd can't announce without probing, therefore let's - * start a fake probe with zero timeout and then perform - * the announcement. */ - g_hash_table_iter_init (&iter, self->addresses); - while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &info)) { - if (!acd_probe_add (self, info, 0)) - success = FALSE; - } - self->state = STATE_ANNOUNCING; - } else if (self->state == STATE_ANNOUNCING) { - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; - - g_hash_table_iter_init (&iter, self->addresses); - while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &info)) { - if (info->duplicate) - continue; - r = n_acd_probe_announce (info->probe, N_ACD_DEFEND_ONCE); - if (r) { - _LOGW ("couldn't announce address %s on interface '%s': %s", - _nm_utils_inet4_ntop (info->address, sbuf), - nm_platform_link_get_name (NM_PLATFORM_GET, self->ifindex), - acd_error_to_string (r)); - success = FALSE; - } else - _LOGD ("announcing address %s", _nm_utils_inet4_ntop (info->address, sbuf)); - } - } - - if (!self->event_source) { - n_acd_get_fd (self->acd, &fd); - self->event_source = nm_g_unix_fd_source_new (fd, - G_IO_IN, - G_PRIORITY_DEFAULT, - acd_event, - self, - NULL); - g_source_attach (self->event_source, NULL); - } - - return success ? 0 : -NME_UNSPEC; -} - -static void -destroy_address_info (gpointer data) -{ - AddressInfo *info = (AddressInfo *) data; - - n_acd_probe_free (info->probe); - - g_slice_free (AddressInfo, info); -} - -/*****************************************************************************/ - -NMAcdManager * -nm_acd_manager_new (int ifindex, - const guint8 *hwaddr, - guint hwaddr_len, - const NMAcdCallbacks *callbacks, - gpointer user_data) -{ - NMAcdManager *self; - - g_return_val_if_fail (ifindex > 0, NULL); - g_return_val_if_fail (hwaddr, NULL); - g_return_val_if_fail (hwaddr_len == ETH_ALEN, NULL); - - self = g_slice_new0 (NMAcdManager); - - if (callbacks) - self->callbacks = *callbacks; - self->user_data = user_data; - - self->addresses = g_hash_table_new_full (nm_direct_hash, NULL, - NULL, destroy_address_info); - self->state = STATE_INIT; - self->ifindex = ifindex; - memcpy (self->hwaddr, hwaddr, ETH_ALEN); - return self; -} - -void -nm_acd_manager_free (NMAcdManager *self) -{ - g_return_if_fail (self); - - if (self->callbacks.user_data_destroy) - self->callbacks.user_data_destroy (self->user_data); - - nm_clear_pointer (&self->addresses, g_hash_table_destroy); - nm_clear_g_source_inst (&self->event_source); - nm_clear_pointer (&self->acd, n_acd_unref); - - g_slice_free (NMAcdManager, self); -} diff --git a/src/devices/nm-acd-manager.h b/src/devices/nm-acd-manager.h deleted file mode 100644 index 4afe509db9..0000000000 --- a/src/devices/nm-acd-manager.h +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (C) 2015 - 2018 Red Hat, Inc. - */ - -#ifndef __NM_ACD_MANAGER__ -#define __NM_ACD_MANAGER__ - -#include <netinet/in.h> - -typedef struct _NMAcdManager NMAcdManager; - -typedef struct { - void (*probe_terminated_callback) (NMAcdManager *self, - gpointer user_data); - GDestroyNotify user_data_destroy; -} NMAcdCallbacks; - -NMAcdManager *nm_acd_manager_new (int ifindex, - const guint8 *hwaddr, - guint hwaddr_len, - const NMAcdCallbacks *callbacks, - gpointer user_data); - -void nm_acd_manager_free (NMAcdManager *self); - -gboolean nm_acd_manager_add_address (NMAcdManager *self, in_addr_t address); -int nm_acd_manager_start_probe (NMAcdManager *self, guint timeout); -gboolean nm_acd_manager_check_address (NMAcdManager *self, in_addr_t address); -int nm_acd_manager_announce_addresses (NMAcdManager *self); - -NM_AUTO_DEFINE_FCN0 (NMAcdManager *, _nm_auto_free_acdmgr, nm_acd_manager_free); -#define nm_auto_free_acdmgr nm_auto (_nm_auto_free_acdmgr) - -#endif /* __NM_ACD_MANAGER__ */ diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c index 9d8207f73d..494ae62632 100644 --- a/src/devices/nm-device-ethernet.c +++ b/src/devices/nm-device-ethernet.c @@ -1144,15 +1144,24 @@ ppp_ifindex_set (NMPPPManager *ppp_manager, } static void -ppp_ip4_config (NMPPPManager *ppp_manager, - NMIP4Config *config, +ppp_new_config (NMPPPManager *ppp_manager, + int addr_family, + const NML3ConfigData *l3cd, + const NMUtilsIPv6IfaceId *iid, gpointer user_data) { NMDevice *device = NM_DEVICE (user_data); - /* Ignore PPP IP4 events that come in after initial configuration */ - if (nm_device_activate_ip4_state_in_conf (device)) - nm_device_activate_schedule_ip_config_result (device, AF_INET, NM_IP_CONFIG_CAST (config)); + if (addr_family != AF_INET) + return; + + if (!nm_device_activate_ip4_state_in_conf (device)) { + /* Ignore PPP IP4 events that come in after initial configuration */ + return; + } + + nm_device_set_dev2_ip_config (device, AF_INET, l3cd); + nm_device_activate_schedule_ip_config_result (device, AF_INET); } static NMActStageReturn @@ -1202,8 +1211,8 @@ pppoe_stage3_ip4_config_start (NMDeviceEthernet *self, NMDeviceStateReason *out_ g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IFINDEX_SET, G_CALLBACK (ppp_ifindex_set), self); - g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, - G_CALLBACK (ppp_ip4_config), + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_NEW_CONFIG, + G_CALLBACK (ppp_new_config), self); return NM_ACT_STAGE_RETURN_POSTPONE; } @@ -1498,7 +1507,7 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) static NMActStageReturn act_stage3_ip_config_start (NMDevice *device, int addr_family, - gpointer *out_config, + const NML3ConfigData **out_config, NMDeviceStateReason *out_failure_reason) { NMSettingConnection *s_con; diff --git a/src/devices/nm-device-ppp.c b/src/devices/nm-device-ppp.c index cbc871419a..01040fa552 100644 --- a/src/devices/nm-device-ppp.c +++ b/src/devices/nm-device-ppp.c @@ -7,7 +7,7 @@ #include "nm-device-ppp.h" -#include "nm-ip4-config.h" +#include "nm-l3-config-data.h" #include "nm-act-request.h" #include "nm-device-factory.h" #include "nm-device-private.h" @@ -25,7 +25,7 @@ _LOG_DECLARE_SELF(NMDevicePpp); typedef struct _NMDevicePppPrivate { NMPPPManager *ppp_manager; - NMIP4Config *ip4_config; + const NML3ConfigData *l3cd_4; } NMDevicePppPrivate; struct _NMDevicePpp { @@ -90,26 +90,33 @@ ppp_ifindex_set (NMPPPManager *ppp_manager, } static void -ppp_ip4_config (NMPPPManager *ppp_manager, - NMIP4Config *config, +ppp_new_config (NMPPPManager *ppp_manager, + int addr_family, + const NML3ConfigData *l3cd, + const NMUtilsIPv6IfaceId *iid, gpointer user_data) { NMDevice *device = NM_DEVICE (user_data); NMDevicePpp *self = NM_DEVICE_PPP (device); NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE (self); + if (addr_family != AF_INET) + return; + _LOGT (LOGD_DEVICE | LOGD_PPP, "received IPv4 config from pppd"); - if (nm_device_get_state (device) == NM_DEVICE_STATE_IP_CONFIG) { - if (nm_device_activate_ip4_state_in_conf (device)) { - nm_device_activate_schedule_ip_config_result (device, AF_INET, NM_IP_CONFIG_CAST (config)); - return; - } - } else { - if (priv->ip4_config) - g_object_unref (priv->ip4_config); - priv->ip4_config = g_object_ref (config); + if (nm_device_get_state (device) != NM_DEVICE_STATE_IP_CONFIG) { + nm_clear_l3cd (&priv->l3cd_4); + if (l3cd) + priv->l3cd_4 = nm_l3_config_data_ref_and_seal (l3cd); + return; } + + if (!nm_device_activate_ip4_state_in_conf (device)) + return; + + nm_device_set_dev2_ip_config (device, AF_INET, l3cd); + nm_device_activate_schedule_ip_config_result (device, AF_INET); } static gboolean @@ -146,7 +153,7 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) s_pppoe = nm_device_get_applied_setting (device, NM_TYPE_SETTING_PPPOE); g_return_val_if_fail (s_pppoe, NM_ACT_STAGE_RETURN_FAILURE); - g_clear_object (&priv->ip4_config); + nm_clear_l3cd (&priv->l3cd_4); priv->ppp_manager = nm_ppp_manager_create (nm_setting_pppoe_get_parent (s_pppoe), &error); @@ -183,8 +190,8 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) G_CALLBACK (ppp_ifindex_set), self); g_signal_connect (priv->ppp_manager, - NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, - G_CALLBACK (ppp_ip4_config), + NM_PPP_MANAGER_SIGNAL_NEW_CONFIG, + G_CALLBACK (ppp_new_config), self); return NM_ACT_STAGE_RETURN_POSTPONE; } @@ -192,18 +199,18 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) static NMActStageReturn act_stage3_ip_config_start (NMDevice *device, int addr_family, - gpointer *out_config, + const NML3ConfigData **out_l3cd, NMDeviceStateReason *out_failure_reason) { if (addr_family == AF_INET) { NMDevicePpp *self = NM_DEVICE_PPP (device); NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE (self); - if (priv->ip4_config) { - if (out_config) - *out_config = g_steal_pointer (&priv->ip4_config); + if (priv->l3cd_4) { + if (out_l3cd) + *out_l3cd = g_steal_pointer (&priv->l3cd_4); else - g_clear_object (&priv->ip4_config); + nm_clear_l3cd (&priv->l3cd_4); return NM_ACT_STAGE_RETURN_SUCCESS; } @@ -213,7 +220,7 @@ act_stage3_ip_config_start (NMDevice *device, return NM_DEVICE_CLASS (nm_device_ppp_parent_class)->act_stage3_ip_config_start (device, addr_family, - out_config, + out_l3cd, out_failure_reason); } @@ -265,7 +272,7 @@ dispose (GObject *object) NMDevicePpp *self = NM_DEVICE_PPP (object); NMDevicePppPrivate *priv = NM_DEVICE_PPP_GET_PRIVATE (self); - g_clear_object (&priv->ip4_config); + nm_clear_l3cd (&priv->l3cd_4); G_OBJECT_CLASS (nm_device_ppp_parent_class)->dispose (object); } diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index 1cda2e1950..399582327f 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -42,8 +42,6 @@ enum NMActStageReturn { #define NM_DEVICE_CAP_INTERNAL_MASK 0xc0000000 -void nm_device_arp_announce (NMDevice *self); - NMSettings *nm_device_get_settings (NMDevice *self); NMManager *nm_device_get_manager (NMDevice *self); @@ -79,8 +77,7 @@ void nm_device_activate_schedule_stage2_device_config (NMDevice *device, gboolean do_sync); void nm_device_activate_schedule_ip_config_result (NMDevice *device, - int addr_family, - NMIPConfig *config); + int addr_family); void nm_device_activate_schedule_ip_config_timeout (NMDevice *device, int addr_family); @@ -143,7 +140,7 @@ void nm_device_queue_recheck_available (NMDevice *device, void nm_device_set_dev2_ip_config (NMDevice *device, int addr_family, - NMIPConfig *config); + const NML3ConfigData *l3cd); gboolean nm_device_hw_addr_is_explict (NMDevice *device); @@ -159,6 +156,7 @@ NMIP4Config *nm_device_ip4_config_new (NMDevice *self); NMIP6Config *nm_device_ip6_config_new (NMDevice *self); NMIPConfig *nm_device_ip_config_new (NMDevice *self, int addr_family); +NML3ConfigData *nm_device_create_l3_config_data (NMDevice *self); NML3ConfigData *nm_device_create_l3_config_data (NMDevice *self); diff --git a/src/devices/nm-device-vlan.c b/src/devices/nm-device-vlan.c index 183e9eff06..060cfeb5cd 100644 --- a/src/devices/nm-device-vlan.c +++ b/src/devices/nm-device-vlan.c @@ -112,7 +112,6 @@ parent_hwaddr_maybe_changed (NMDevice *parent, NM_PRINT_FMT_QUOTE_STRING (new_mac)); if (new_mac) { nm_device_hw_addr_set (device, new_mac, "vlan-parent", TRUE); - nm_device_arp_announce (device); /* When changing the hw address the interface is taken down, * removing the IPv6 configuration; reapply it. */ diff --git a/src/devices/nm-device-wireguard.c b/src/devices/nm-device-wireguard.c index d6c6cb78e0..288021f986 100644 --- a/src/devices/nm-device-wireguard.c +++ b/src/devices/nm-device-wireguard.c @@ -12,6 +12,7 @@ #include "nm-setting-wireguard.h" #include "nm-core-internal.h" +#include "nm-l3-config-data.h" #include "nm-glib-aux/nm-secret-utils.h" #include "nm-device-private.h" #include "platform/nm-platform.h" @@ -1544,12 +1545,12 @@ act_stage2_config (NMDevice *device, return ret; } -static NMIPConfig * +static const NML3ConfigData * _get_dev2_ip_config (NMDeviceWireGuard *self, int addr_family) { NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE (self); - gs_unref_object NMIPConfig *ip_config = NULL; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; NMConnection *connection; NMSettingWireGuard *s_wg; guint n_peers; @@ -1639,11 +1640,9 @@ _get_dev2_ip_config (NMDeviceWireGuard *self, continue; } - if (!ip_config) { - ip_config = nm_device_ip_config_new (NM_DEVICE (self), addr_family); - nm_ip_config_set_config_flags (ip_config, - NM_IP_CONFIG_FLAGS_IGNORE_MERGE_NO_DEFAULT_ROUTES, - 0); + if (!l3cd) { + l3cd = nm_device_create_l3_config_data (NM_DEVICE (self)); + nm_l3_config_data_set_flags (l3cd, NM_L3_CONFIG_DAT_FLAGS_IGNORE_MERGE_NO_DEFAULT_ROUTES); } nm_utils_ipx_address_clear_host_address (addr_family, &addrbin, NULL, prefix); @@ -1679,26 +1678,29 @@ _get_dev2_ip_config (NMDeviceWireGuard *self, }; } - nm_ip_config_add_route (ip_config, &rt.rx, NULL); + nm_l3_config_data_add_route (l3cd, addr_family, NULL, &rt.rx); } } - return g_steal_pointer (&ip_config); + if (!l3cd) + return NULL; + + return nm_l3_config_data_seal (g_steal_pointer (&l3cd)); } static NMActStageReturn act_stage3_ip_config_start (NMDevice *device, int addr_family, - gpointer *out_config, + const NML3ConfigData **out_l3cd, NMDeviceStateReason *out_failure_reason) { - gs_unref_object NMIPConfig *ip_config = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; - ip_config = _get_dev2_ip_config (NM_DEVICE_WIREGUARD (device), addr_family); + l3cd = _get_dev2_ip_config (NM_DEVICE_WIREGUARD (device), addr_family); - nm_device_set_dev2_ip_config (device, addr_family, ip_config); + nm_device_set_dev2_ip_config (device, addr_family, l3cd); - return NM_DEVICE_CLASS (nm_device_wireguard_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason); + return NM_DEVICE_CLASS (nm_device_wireguard_parent_class)->act_stage3_ip_config_start (device, addr_family, out_l3cd, out_failure_reason); } static guint32 @@ -1796,8 +1798,6 @@ reapply_connection (NMDevice *device, { NMDeviceWireGuard *self = NM_DEVICE_WIREGUARD (device); NMDeviceWireGuardPrivate *priv = NM_DEVICE_WIREGUARD_GET_PRIVATE (self); - gs_unref_object NMIPConfig *ip4_config = NULL; - gs_unref_object NMIPConfig *ip6_config = NULL; NMDeviceState state = nm_device_get_state (device); NM_DEVICE_CLASS (nm_device_wireguard_parent_class)->reapply_connection (device, @@ -1813,11 +1813,14 @@ reapply_connection (NMDevice *device, } if (state >= NM_DEVICE_STATE_IP_CONFIG) { - ip4_config = _get_dev2_ip_config (self, AF_INET); - ip6_config = _get_dev2_ip_config (self, AF_INET6); + nm_auto_unref_l3cd const NML3ConfigData *l3cd_4 = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd_6 = NULL; + + l3cd_4 = _get_dev2_ip_config (self, AF_INET); + l3cd_6 = _get_dev2_ip_config (self, AF_INET6); - nm_device_set_dev2_ip_config (device, AF_INET, ip4_config); - nm_device_set_dev2_ip_config (device, AF_INET6, ip6_config); + nm_device_set_dev2_ip_config (device, AF_INET, l3cd_4); + nm_device_set_dev2_ip_config (device, AF_INET6, l3cd_6); } } diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 53a3085bea..18a9a743c5 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -60,7 +60,6 @@ #include "nm-config.h" #include "c-list/src/c-list.h" #include "dns/nm-dns-manager.h" -#include "nm-acd-manager.h" #include "nm-core-internal.h" #include "systemd/nm-sd.h" #include "nm-lldp-listener.h" @@ -582,12 +581,6 @@ typedef struct _NMDevicePrivate { guint ipv4ll_timeout; guint rt6_temporary_not_available_id; - /* IPv4 DAD stuff */ - struct { - GSList * dad_list; - NMAcdManager * announcing; - } acd; - union { struct { const NMDeviceIPState ip_state_6; @@ -1994,6 +1987,7 @@ static void _dev_l3_cfg_acd_maybe_comlete (NMDevice *self) { /* FIXME(l3cfg) */ + nm_device_activate_schedule_ip_config_result (self, AF_INET); } static void @@ -4065,11 +4059,6 @@ nm_device_master_enslave_slave (NMDevice *self, NMDevice *slave, NMConnection *c */ nm_device_update_hw_address (self); - /* Send ARP announcements if did not yet and have addresses. */ - if ( priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE - && !priv->acd.announcing) - nm_device_arp_announce (self); - /* Restart IP configuration if we're waiting for slaves. Do this * after updating the hardware address as IP config may need the * new address. @@ -7850,173 +7839,7 @@ get_ipv4_dad_timeout (NMDevice *self) 0); } -static void -acd_data_destroy (gpointer ptr) -{ - AcdData *data = ptr; - int i; - - for (i = 0; data->configs && data->configs[i]; i++) - g_object_unref (data->configs[i]); - g_free (data->configs); - g_slice_free (AcdData, data); -} - -static void -ipv4_manual_method_apply (NMDevice *self, NMIP4Config **configs, gboolean success) -{ - NMConnection *connection; - const char *method; - - connection = nm_device_get_applied_connection (self); - nm_assert (connection); - method = nm_utils_get_ip_config_method (connection, AF_INET); - nm_assert (NM_IN_STRSET (method, - NM_SETTING_IP4_CONFIG_METHOD_MANUAL, - NM_SETTING_IP4_CONFIG_METHOD_AUTO)); - - if (!success) { - nm_device_ip_method_failed (self, AF_INET, - NM_DEVICE_STATE_REASON_IP_ADDRESS_DUPLICATE); - return; - } - - if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) - nm_device_activate_schedule_ip_config_result (self, AF_INET, NULL); - else { - if (NM_DEVICE_GET_PRIVATE (self)->ip_state_4 != NM_DEVICE_IP_STATE_DONE) - ip_config_merge_and_apply (self, AF_INET, TRUE); - } -} - -static void -acd_manager_probe_terminated (NMAcdManager *acd_manager, gpointer user_data) -{ - AcdData *data = user_data; - NMDevice *self; - NMDevicePrivate *priv; - NMDedupMultiIter ipconf_iter; - const NMPlatformIP4Address *address; - gboolean result, success = TRUE; - int i; - - g_assert (data); - self = data->device; - priv = NM_DEVICE_GET_PRIVATE (self); - - for (i = 0; data->configs && data->configs[i]; i++) { - nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, data->configs[i], &address) { - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; - - result = nm_acd_manager_check_address (acd_manager, address->address); - success &= result; - - _NMLOG (result ? LOGL_DEBUG : LOGL_WARN, - LOGD_DEVICE, - "IPv4 DAD result: address %s is %s", - _nm_utils_inet4_ntop (address->address, sbuf), - result ? "unique" : "duplicate"); - } - } - - data->callback (self, data->configs, success); - - priv->acd.dad_list = g_slist_remove (priv->acd.dad_list, acd_manager); - nm_acd_manager_free (acd_manager); -} - -/** - * ipv4_dad_start: - * @self: device instance - * @configs: NULL-terminated array of IPv4 configurations - * @cb: callback function - * - * Start IPv4 DAD on device @self, check addresses in @configs and call @cb - * when the procedure ends. @cb will be called in any case, even if DAD can't - * be started. @configs will be unreferenced after @cb has been called. - */ -static void -ipv4_dad_start (NMDevice *self, NMIP4Config **configs, AcdCallback cb) -{ - static const NMAcdCallbacks acd_callbacks = { - .probe_terminated_callback = acd_manager_probe_terminated, - .user_data_destroy = acd_data_destroy, - }; - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMAcdManager *acd_manager; - const NMPlatformIP4Address *address; - NMDedupMultiIter ipconf_iter; - AcdData *data; - guint timeout; - gboolean addr_found; - int r; - const guint8 *hwaddr_arr; - size_t length; - guint i; - - g_return_if_fail (NM_IS_DEVICE (self)); - g_return_if_fail (configs); - g_return_if_fail (cb); - - for (i = 0, addr_found = FALSE; configs[i]; i++) { - if (nm_ip4_config_get_num_addresses (configs[i]) > 0) { - addr_found = TRUE; - break; - } - } - - timeout = get_ipv4_dad_timeout (self); - hwaddr_arr = nm_platform_link_get_address (nm_device_get_platform (self), - nm_device_get_ip_ifindex (self), - &length); - - if ( !timeout - || !hwaddr_arr - || !addr_found - || length != ETH_ALEN - || nm_device_sys_iface_state_is_external_or_assume (self)) { - - /* DAD not needed, signal success */ - cb (self, configs, TRUE); - - for (i = 0; configs[i]; i++) - g_object_unref (configs[i]); - g_free (configs); - - return; - } - - data = g_slice_new0 (AcdData); - data->configs = configs; - data->callback = cb; - data->device = self; - - acd_manager = nm_acd_manager_new (nm_device_get_ip_ifindex (self), - hwaddr_arr, - length, - &acd_callbacks, - data); - priv->acd.dad_list = g_slist_append (priv->acd.dad_list, acd_manager); - - for (i = 0; configs[i]; i++) { - nm_ip_config_iter_ip4_address_for_each (&ipconf_iter, configs[i], &address) - nm_acd_manager_add_address (acd_manager, address->address); - } - - r = nm_acd_manager_start_probe (acd_manager, timeout); - if (r < 0) { - _LOGW (LOGD_DEVICE, "acd probe failed"); - - /* DAD could not be started, signal success */ - cb (self, configs, TRUE); - - priv->acd.dad_list = g_slist_remove (priv->acd.dad_list, acd_manager); - nm_acd_manager_free (acd_manager); - } -} - /*****************************************************************************/ -/* IPv4LL stuff */ static void ipv4ll_cleanup (NMDevice *self) @@ -8032,31 +7855,34 @@ ipv4ll_cleanup (NMDevice *self) nm_clear_g_source (&priv->ipv4ll_timeout); } -static NMIP4Config * -ipv4ll_get_ip4_config (NMDevice *self, guint32 lla) +static const NML3ConfigData * +ipv4ll_get_ip4_config (NMDevice *self, in_addr_t lla) { - NMIP4Config *config = NULL; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; NMPlatformIP4Address address; NMPlatformIP4Route route; - config = nm_device_ip4_config_new (self); - g_assert (config); + l3cd = nm_device_create_l3_config_data (self); + g_return_val_if_fail (l3cd, NULL); - memset (&address, 0, sizeof (address)); + address = (NMPlatformIP4Address) { + .addr_source = NM_IP_CONFIG_SOURCE_IP4LL, + }; nm_platform_ip4_address_set_addr (&address, lla, 16); - address.addr_source = NM_IP_CONFIG_SOURCE_IP4LL; - nm_ip4_config_add_address (config, &address); + + nm_l3_config_data_add_address_4 (l3cd, &address); /* Add a multicast route for link-local connections: destination= 224.0.0.0, netmask=240.0.0.0 */ - memset (&route, 0, sizeof (route)); - route.network = htonl (0xE0000000L); - route.plen = 4; - route.rt_source = NM_IP_CONFIG_SOURCE_IP4LL; - route.table_coerced = nm_platform_route_table_coerce (nm_device_get_route_table (self, AF_INET)); - route.metric = nm_device_get_route_metric (self, AF_INET); - nm_ip4_config_add_route (config, &route, NULL); + route = (NMPlatformIP4Route) { + .network = htonl (0xE0000000L), + .plen = 4, + .rt_source = NM_IP_CONFIG_SOURCE_IP4LL, + .table_coerced = nm_platform_route_table_coerce (nm_device_get_route_table (self, AF_INET)), + .metric = nm_device_get_route_metric (self, AF_INET), + }; + nm_l3_config_data_add_route_4 (l3cd, &route); - return config; + return nm_l3_config_data_seal (g_steal_pointer (&l3cd));; } static void @@ -8065,7 +7891,6 @@ nm_device_handle_ipv4ll_event (sd_ipv4ll *ll, int event, void *data) NMDevice *self = data; NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); struct in_addr address; - NMIP4Config *config; int r; if (priv->act_request.obj == NULL) @@ -8075,7 +7900,9 @@ nm_device_handle_ipv4ll_event (sd_ipv4ll *ll, int event, void *data) NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)); switch (event) { - case SD_IPV4LL_EVENT_BIND: + case SD_IPV4LL_EVENT_BIND: { + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; + r = sd_ipv4ll_get_address (ll, &address); if (r < 0) { _LOGE (LOGD_AUTOIP4, "invalid IPv4 link-local address received, error %d.", r); @@ -8089,27 +7916,28 @@ nm_device_handle_ipv4ll_event (sd_ipv4ll *ll, int event, void *data) return; } - config = ipv4ll_get_ip4_config (self, address.s_addr); - if (config == NULL) { + l3cd = ipv4ll_get_ip4_config (self, address.s_addr); + if (!l3cd) { _LOGE (LOGD_AUTOIP4, "failed to get IPv4LL config"); nm_device_ip_method_failed (self, AF_INET, NM_DEVICE_STATE_REASON_AUTOIP_FAILED); return; } + _dev_l3_register_l3cds_set_one (self, L3_CONFIG_DATA_TYPE_LL_4, l3cd); if (priv->ip_state_4 == NM_DEVICE_IP_STATE_CONF) { nm_clear_g_source (&priv->ipv4ll_timeout); - nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (config)); - } else if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE) { - applied_config_init (&priv->dev_ip_config_4, config); - if (!ip_config_merge_and_apply (self, AF_INET, TRUE)) { + nm_device_activate_schedule_ip_config_result (self, AF_INET); + return; + } + if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE) { + if (!_dev_l3_platform_commit (self)) { _LOGE (LOGD_AUTOIP4, "failed to update IP4 config for autoip change."); nm_device_ip_method_failed (self, AF_INET, NM_DEVICE_STATE_REASON_AUTOIP_FAILED); } - } else - g_assert_not_reached (); - - g_object_unref (config); - break; + return; + } + g_return_if_reached (); + } default: _LOGW (LOGD_AUTOIP4, "IPv4LL address no longer valid after event %d.", event); nm_device_ip_method_failed (self, AF_INET, NM_DEVICE_STATE_REASON_AUTOIP_FAILED); @@ -8529,6 +8357,7 @@ ip_config_merge_and_apply (NMDevice *self, return success; } +_nm_unused /* FIXME(l3cfg) */ static gboolean dhcp4_lease_change (NMDevice *self, NMIP4Config *config, gboolean bound) { @@ -8684,42 +8513,24 @@ clear_config: } static void -dhcp4_dad_cb (NMDevice *self, NMIP4Config **configs, gboolean success) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - - if (success) { - nm_device_activate_schedule_ip_config_result (self, AF_INET, - NM_IP_CONFIG_CAST (configs[1])); - } else { - nm_dhcp_client_decline (priv->dhcp_data_4.client, "Address conflict detected", NULL); - nm_device_ip_method_failed (self, AF_INET, - NM_DEVICE_STATE_REASON_IP_ADDRESS_DUPLICATE); - } -} - -static void dhcp4_state_changed (NMDhcpClient *client, NMDhcpState state, - NMIP4Config *ip4_config, + const NML3ConfigData *l3cd, GHashTable *options, const char *event_id, gpointer user_data) { NMDevice *self = NM_DEVICE (user_data); NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - 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); _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; @@ -8744,30 +8555,8 @@ dhcp4_state_changed (NMDhcpClient *client, nm_dhcp_config_set_options (priv->dhcp_data_4.config, options); _notify (self, PROP_DHCP4_CONFIG); - if (priv->ip_state_4 == NM_DEVICE_IP_STATE_CONF) { - connection = nm_device_get_applied_connection (self); - g_assert (connection); - - manual = nm_device_ip4_config_new (self); - nm_ip4_config_merge_setting (manual, - nm_connection_get_setting_ip4_config (connection), - NM_SETTING_CONNECTION_MDNS_DEFAULT, - NM_SETTING_CONNECTION_LLMNR_DEFAULT, - nm_device_get_route_table (self, AF_INET), - nm_device_get_route_metric (self, AF_INET)); - - configs = g_new0 (NMIP4Config *, 3); - configs[0] = manual; - configs[1] = g_object_ref (ip4_config); - - ipv4_dad_start (self, configs, dhcp4_dad_cb); - } else if (priv->ip_state_4 == NM_DEVICE_IP_STATE_DONE) { - if (dhcp4_lease_change (self, ip4_config, - state == NM_DHCP_STATE_BOUND)) - nm_device_update_metered (self); - else - dhcp4_fail (self, state); - } + if (_dev_l3_register_l3cds_set_one (self, L3_CONFIG_DATA_TYPE_DHCP_4, l3cd)) + _dev_l3_cfg_acd_maybe_comlete (self); break; case NM_DHCP_STATE_TIMEOUT: dhcp4_fail (self, state); @@ -9268,21 +9057,10 @@ nm_device_dhcp4_renew (NMDevice *self, gboolean release) /*****************************************************************************/ -static GHashTable *shared_ips = NULL; - -static void -shared_ip_release (gpointer data) -{ - g_hash_table_remove (shared_ips, data); - if (!g_hash_table_size (shared_ips)) - nm_clear_pointer (&shared_ips, g_hash_table_unref); -} - -static NMIP4Config * +static const NML3ConfigData * shared4_new_config (NMDevice *self, NMConnection *connection) { - NMIP4Config *config = NULL; - gboolean is_generated = FALSE; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; NMSettingIPConfig *s_ip4; NMPlatformIP4Address address = { .addr_source = NM_IP_CONFIG_SOURCE_SHARED, @@ -9304,6 +9082,9 @@ shared4_new_config (NMDevice *self, NMConnection *connection) guint32 start = (guint32) ntohl (0x0a2a0001); /* 10.42.0.1 */ guint32 count = 0; + /* FIXME(l3cfg): need to keep track of the shared-ip addresses in use. + * Let NMManager or NMNetns provide a mechanism for that. */ +#if 0 if (G_UNLIKELY (!shared_ips)) shared_ips = g_hash_table_new (nm_direct_hash, NULL); else { @@ -9315,20 +9096,16 @@ shared4_new_config (NMDevice *self, NMConnection *connection) } } } - nm_platform_ip4_address_set_addr (&address, start + count, 24); g_hash_table_add (shared_ips, GUINT_TO_POINTER (address.address)); is_generated = TRUE; +#endif + nm_platform_ip4_address_set_addr (&address, start + count, 24); } - config = nm_device_ip4_config_new (self); - nm_ip4_config_add_address (config, &address); - if (is_generated) { - /* Remove the address lock when the object gets disposed */ - g_object_set_qdata_full (G_OBJECT (config), NM_CACHED_QUARK ("shared-ip"), - GUINT_TO_POINTER (address.address), - shared_ip_release); - } - return config; + l3cd = nm_device_create_l3_config_data (self); + nm_l3_config_data_add_address_4 (l3cd, &address); + + return nm_l3_config_data_seal (g_steal_pointer (&l3cd)); } /*****************************************************************************/ @@ -9454,6 +9231,7 @@ dhcp6_cleanup (NMDevice *self, CleanupType cleanup_type, gboolean release) } } +_nm_unused /* FIXME(l3cfg) */ static gboolean dhcp6_lease_change (NMDevice *self) { @@ -9529,7 +9307,7 @@ dhcp6_fail (NMDevice *self, NMDhcpState dhcp_state) /* not a hard failure; just live with the RA info */ dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE); if (priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF) - nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); + nm_device_activate_schedule_ip_config_result (self, AF_INET6); } return; @@ -9598,7 +9376,7 @@ dhcp6_state_changed (NMDhcpClient *client, nm_device_ip_method_failed (self, AF_INET6, NM_DEVICE_STATE_REASON_DHCP_FAILED); break; } - nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); + nm_device_activate_schedule_ip_config_result (self, AF_INET6); } else if (priv->ip_state_6 == NM_DEVICE_IP_STATE_DONE) if (!dhcp6_lease_change (self)) dhcp6_fail (self, state); @@ -9610,7 +9388,7 @@ dhcp6_state_changed (NMDhcpClient *client, /* not a hard failure; just live with the RA info */ dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE); if (priv->ip_state_6 == NM_DEVICE_IP_STATE_CONF) - nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); + nm_device_activate_schedule_ip_config_result (self, AF_INET6); } break; case NM_DHCP_STATE_EXPIRE: @@ -10248,7 +10026,7 @@ linklocal6_check_complete (NMDevice *self) nm_device_activate_schedule_ip_config_timeout (self, AF_INET6); } } else if (nm_streq (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL)) - nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); + nm_device_activate_schedule_ip_config_result (self, AF_INET6); else g_return_if_fail (FALSE); } @@ -10861,7 +10639,7 @@ ndisc_config_changed (NMNDisc *ndisc, const NMNDiscData *rdata, guint changed_in } } - nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); + nm_device_activate_schedule_ip_config_result (self, AF_INET6); } static void @@ -10888,7 +10666,7 @@ ndisc_ra_timeout (NMNDisc *ndisc, NMDevice *self) && nm_ip6_config_find_first_address (priv->ip_config_6, NM_PLATFORM_MATCH_WITH_ADDRTYPE_NORMAL | NM_PLATFORM_MATCH_WITH_ADDRSTATE__ANY)) - nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); + nm_device_activate_schedule_ip_config_result (self, AF_INET6); else nm_device_activate_schedule_ip_config_timeout (self, AF_INET6); } @@ -10917,7 +10695,7 @@ addrconf6_start_with_link_ready (NMDevice *self) if (nm_ndisc_get_node_type (priv->ndisc) == NM_NDISC_NODE_TYPE_ROUTER) { nm_device_sysctl_ip_conf_set (self, AF_INET6, "forwarding", "1"); - nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); + nm_device_activate_schedule_ip_config_result (self, AF_INET6); priv->needs_ip6_subnet = TRUE; g_signal_emit (self, signals[IP6_SUBNET_NEEDED], 0); } @@ -11229,7 +11007,7 @@ ip_requires_slaves (NMDevice *self, int addr_family) static NMActStageReturn act_stage3_ip_config_start (NMDevice *self, int addr_family, - gpointer *out_config, + const NML3ConfigData **out_l3cd, NMDeviceStateReason *out_failure_reason) { const gboolean IS_IPv4 = (addr_family == AF_INET); @@ -11279,9 +11057,9 @@ act_stage3_ip_config_start (NMDevice *self, NM_SETTING_IP4_CONFIG_METHOD_AUTO, NM_SETTING_IP4_CONFIG_METHOD_MANUAL)) { NMSettingIPConfig *s_ip4; - NMIP4Config **configs, *config; guint num_addresses; + /* FIXME(l3cfg) */ s_ip4 = nm_connection_get_setting_ip4_config (connection); g_return_val_if_fail (s_ip4, NM_ACT_STAGE_RETURN_FAILURE); num_addresses = nm_setting_ip_config_get_num_addresses (s_ip4); @@ -11296,27 +11074,14 @@ act_stage3_ip_config_start (NMDevice *self, g_return_val_if_fail (num_addresses != 0, NM_ACT_STAGE_RETURN_FAILURE); ret = NM_ACT_STAGE_RETURN_POSTPONE; } - - if (num_addresses) { - config = nm_device_ip4_config_new (self); - nm_ip4_config_merge_setting (config, - nm_connection_get_setting_ip4_config (connection), - NM_SETTING_CONNECTION_MDNS_DEFAULT, - NM_SETTING_CONNECTION_LLMNR_DEFAULT, - nm_device_get_route_table (self, AF_INET), - nm_device_get_route_metric (self, AF_INET)); - configs = g_new0 (NMIP4Config *, 2); - configs[0] = config; - ipv4_dad_start (self, configs, ipv4_manual_method_apply); - } } else if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL)) { ret = ipv4ll_start (self); if (ret == NM_ACT_STAGE_RETURN_FAILURE) NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED); } else if (nm_streq (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED)) { - if (out_config) { - *out_config = shared4_new_config (self, connection); - if (*out_config) { + if (out_l3cd) { + *out_l3cd = shared4_new_config (self, connection); + if (*out_l3cd) { priv->dnsmasq_manager = nm_dnsmasq_manager_new (nm_device_get_ip_iface (self)); ret = NM_ACT_STAGE_RETURN_SUCCESS; } else { @@ -11465,7 +11230,7 @@ nm_device_activate_stage3_ip4_start (NMDevice *self) NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMActStageReturn ret; NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; - gs_unref_object NMIP4Config *ip4_config = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; g_assert (priv->ip_state_4 == NM_DEVICE_IP_STATE_WAIT); @@ -11476,10 +11241,11 @@ nm_device_activate_stage3_ip4_start (NMDevice *self) } _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_CONF); - ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip_config_start (self, AF_INET, (gpointer *) &ip4_config, &failure_reason); - if (ret == NM_ACT_STAGE_RETURN_SUCCESS) - nm_device_activate_schedule_ip_config_result (self, AF_INET, NM_IP_CONFIG_CAST (ip4_config)); - else if (ret == NM_ACT_STAGE_RETURN_IP_DONE) { + ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip_config_start (self, AF_INET, &l3cd, &failure_reason); + if (ret == NM_ACT_STAGE_RETURN_SUCCESS) { + _dev_l3_register_l3cds_set_one (self, L3_CONFIG_DATA_TYPE_DEV_4, l3cd); + nm_device_activate_schedule_ip_config_result (self, AF_INET); + } else if (ret == NM_ACT_STAGE_RETURN_IP_DONE) { _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_DONE); check_ip_state (self, FALSE, TRUE); } else if (ret == NM_ACT_STAGE_RETURN_FAILURE) { @@ -11509,9 +11275,9 @@ nm_device_activate_stage3_ip6_start (NMDevice *self) NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMActStageReturn ret; NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; - gs_unref_object NMIP6Config *ip6_config = NULL; + nm_auto_unref_l3cd const NML3ConfigData *l3cd = NULL; - g_assert (priv->ip_state_6 == NM_DEVICE_IP_STATE_WAIT); + g_return_val_if_fail (priv->ip_state_6 == NM_DEVICE_IP_STATE_WAIT, FALSE); if (nm_device_sys_iface_state_is_external (self)) { _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_DONE); @@ -11520,16 +11286,10 @@ nm_device_activate_stage3_ip6_start (NMDevice *self) } _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_CONF); - ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip_config_start (self, AF_INET6, (gpointer *) &ip6_config, &failure_reason); + ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip_config_start (self, AF_INET6, &l3cd, &failure_reason); if (ret == NM_ACT_STAGE_RETURN_SUCCESS) { - if (!ip6_config) - ip6_config = nm_device_ip6_config_new (self); - /* Here we get a static IPv6 config, like for Shared where it's - * autogenerated or from modems where it comes from ModemManager. - */ - nm_assert (!applied_config_get_current (&priv->ac_ip6_config)); - applied_config_init (&priv->ac_ip6_config, ip6_config); - nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); + _dev_l3_register_l3cds_set_one (self, L3_CONFIG_DATA_TYPE_DEV_6, l3cd); + nm_device_activate_schedule_ip_config_result (self, AF_INET6); } else if (ret == NM_ACT_STAGE_RETURN_IP_DONE) { _set_ip_state (self, AF_INET6, NM_DEVICE_IP_STATE_DONE); check_ip_state (self, FALSE, TRUE); @@ -11922,72 +11682,12 @@ start_sharing (NMDevice *self, NMIP4Config *config, GError **error) } static void -arp_cleanup (NMDevice *self) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - - nm_clear_pointer (&priv->acd.announcing, nm_acd_manager_free); -} - -void -nm_device_arp_announce (NMDevice *self) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - NMConnection *connection; - NMSettingIPConfig *s_ip4; - guint num, i; - const guint8 *hw_addr; - size_t hw_addr_len = 0; - - arp_cleanup (self); - - hw_addr = nm_platform_link_get_address (nm_device_get_platform (self), - nm_device_get_ip_ifindex (self), - &hw_addr_len); - - if (!hw_addr || hw_addr_len != ETH_ALEN) - return; - - /* We only care about manually-configured addresses; DHCP- and autoip-configured - * ones should already have been seen on the network at this point. - */ - connection = nm_device_get_applied_connection (self); - if (!connection) - return; - s_ip4 = nm_connection_get_setting_ip4_config (connection); - if (!s_ip4) - return; - num = nm_setting_ip_config_get_num_addresses (s_ip4); - if (num == 0) - return; - - priv->acd.announcing = nm_acd_manager_new (nm_device_get_ip_ifindex (self), - hw_addr, - hw_addr_len, - NULL, - NULL); - - for (i = 0; i < num; i++) { - NMIPAddress *ip = nm_setting_ip_config_get_address (s_ip4, i); - in_addr_t addr; - - if (inet_pton (AF_INET, nm_ip_address_get_address (ip), &addr) == 1) - nm_acd_manager_add_address (priv->acd.announcing, addr); - else - g_warn_if_reached (); - } - - nm_acd_manager_announce_addresses (priv->acd.announcing); -} - -static void activate_stage5_ip_config_result_4 (NMDevice *self) { NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMActRequest *req; const char *method; int ip_ifindex; - gboolean do_announce = FALSE; req = nm_device_get_act_request (self); g_assert (req); @@ -12042,31 +11742,6 @@ activate_stage5_ip_config_result_4 (NMDevice *self) NULL, NULL, NULL); } - /* Send ARP announcements */ - - if (nm_device_is_master (self)) { - CList *iter; - SlaveInfo *info; - - /* Skip announcement if there are no device enslaved, for two reasons: - * 1) the master has a temporary MAC address until the first slave comes - * 2) announcements are going to be dropped anyway without slaves - */ - do_announce = FALSE; - - c_list_for_each (iter, &priv->slaves) { - info = c_list_entry (iter, SlaveInfo, lst_slave); - if (info->slave_is_enslaved) { - do_announce = TRUE; - break; - } - } - } else - do_announce = TRUE; - - if (do_announce) - nm_device_arp_announce (self); - /* Enter the IP_CHECK state if this is the first method to complete */ _set_ip_state (self, AF_INET, NM_DEVICE_IP_STATE_DONE); check_ip_state (self, FALSE, TRUE); @@ -12074,22 +11749,18 @@ activate_stage5_ip_config_result_4 (NMDevice *self) void nm_device_activate_schedule_ip_config_result (NMDevice *self, - int addr_family, - NMIPConfig *config) + int addr_family) { NMDevicePrivate *priv; const gboolean IS_IPv4 = (addr_family == AF_INET); g_return_if_fail (NM_IS_DEVICE (self)); g_return_if_fail (NM_IN_SET (addr_family, AF_INET, AF_INET6)); - g_return_if_fail ( !config - || ( addr_family == AF_INET - && nm_ip_config_get_addr_family (config) == AF_INET)); priv = NM_DEVICE_GET_PRIVATE (self); if (IS_IPv4) { - applied_config_init (&priv->dev_ip_config_4, config); + /* FIXME(l3cfg): surely there is something to do here? */ } else { /* If IP had previously failed, move it back to NM_DEVICE_IP_STATE_CONF since we * clearly now have configuration. @@ -12435,11 +12106,8 @@ _cleanup_ip_pre (NMDevice *self, int addr_family, CleanupType cleanup_type) if (IS_IPv4) { dhcp4_cleanup (self, cleanup_type, FALSE); - arp_cleanup (self); dnsmasq_cleanup (self); ipv4ll_cleanup (self); - g_slist_free_full (priv->acd.dad_list, (GDestroyNotify) nm_acd_manager_free); - priv->acd.dad_list = NULL; } else { g_slist_free_full (priv->dad6_failed_addrs, (GDestroyNotify) nmp_object_unref); priv->dad6_failed_addrs = NULL; @@ -13169,7 +12837,7 @@ _rt6_temporary_not_available_timeout (gpointer user_data) NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); priv->rt6_temporary_not_available_id = 0; - nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); + nm_device_activate_schedule_ip_config_result (self, AF_INET6); return G_SOURCE_REMOVE; } @@ -13871,19 +13539,15 @@ nm_device_replace_vpn4_config (NMDevice *self, NMIP4Config *old, NMIP4Config *co void nm_device_set_dev2_ip_config (NMDevice *self, int addr_family, - NMIPConfig *config) + const NML3ConfigData *l3cd) { - NMDevicePrivate *priv; - const gboolean IS_IPv4 = (addr_family == AF_INET); + const gboolean IS_IPv4 = NM_IS_IPv4 (addr_family); - g_return_if_fail (NM_IS_DEVICE (self)); - g_return_if_fail (NM_IN_SET (addr_family, AF_INET, AF_INET6)); - g_return_if_fail ( !config - || nm_ip_config_get_addr_family (config) == addr_family); - - priv = NM_DEVICE_GET_PRIVATE (self); - - applied_config_init (&priv->dev2_ip_config_x[IS_IPv4], config); + _dev_l3_register_l3cds_set_one (self, + IS_IPv4 + ? L3_CONFIG_DATA_TYPE_DEV_4 + : L3_CONFIG_DATA_TYPE_DEV_6, + l3cd); if (!ip_config_merge_and_apply (self, addr_family, TRUE)) { _LOGW (LOGD_IP, "failed to set extra device IPv%c configuration", nm_utils_addr_family_to_char (addr_family)); @@ -14663,7 +14327,7 @@ queued_ip_config_change (NMDevice *self, int addr_family) _set_ip_state (self, addr_family, NM_DEVICE_IP_STATE_DONE); check_ip_state (self, FALSE, TRUE); if (priv->rt6_temporary_not_available) - nm_device_activate_schedule_ip_config_result (self, AF_INET6, NULL); + nm_device_activate_schedule_ip_config_result (self, AF_INET6); } } @@ -18304,8 +17968,6 @@ dispose (GObject *object) g_signal_handlers_disconnect_by_func (platform, G_CALLBACK (device_ipx_changed), self); g_signal_handlers_disconnect_by_func (platform, G_CALLBACK (link_changed_cb), self); - arp_cleanup (self); - nm_clear_g_signal_handler (nm_config_get (), &priv->config_changed_id); dispatcher_cleanup (self); diff --git a/src/devices/nm-device.h b/src/devices/nm-device.h index 36cae7a3aa..db02fb4b61 100644 --- a/src/devices/nm-device.h +++ b/src/devices/nm-device.h @@ -374,12 +374,13 @@ typedef struct _NMDeviceClass { NMDeviceStateReason *out_failure_reason); NMActStageReturn (* act_stage3_ip_config_start) (NMDevice *self, int addr_family, - gpointer *out_config, + const NML3ConfigData **out_l3cd, NMDeviceStateReason *out_failure_reason); NMActStageReturn (* act_stage4_ip_config_timeout) (NMDevice *self, int addr_family, NMDeviceStateReason *out_failure_reason); + //XXX: needs rework to not use NMIP4Config. void (* ip4_config_pre_commit) (NMDevice *self, NMIP4Config *config); /* Async deactivating (in the DEACTIVATING phase) */ diff --git a/src/devices/ovs/nm-device-ovs-bridge.c b/src/devices/ovs/nm-device-ovs-bridge.c index 5909680354..0e68726435 100644 --- a/src/devices/ovs/nm-device-ovs-bridge.c +++ b/src/devices/ovs/nm-device-ovs-bridge.c @@ -65,7 +65,7 @@ get_generic_capabilities (NMDevice *device) static NMActStageReturn act_stage3_ip_config_start (NMDevice *device, int addr_family, - gpointer *out_config, + const NML3ConfigData **out_l3cd, NMDeviceStateReason *out_failure_reason) { return NM_ACT_STAGE_RETURN_IP_FAIL; diff --git a/src/devices/ovs/nm-device-ovs-interface.c b/src/devices/ovs/nm-device-ovs-interface.c index 83954cf075..e31b0d9c91 100644 --- a/src/devices/ovs/nm-device-ovs-interface.c +++ b/src/devices/ovs/nm-device-ovs-interface.c @@ -169,7 +169,7 @@ set_platform_mtu (NMDevice *device, guint32 mtu) static NMActStageReturn act_stage3_ip_config_start (NMDevice *device, int addr_family, - gpointer *out_config, + const NML3ConfigData **out_l3cd, NMDeviceStateReason *out_failure_reason) { NMDeviceOvsInterface *self = NM_DEVICE_OVS_INTERFACE (device); @@ -191,7 +191,7 @@ act_stage3_ip_config_start (NMDevice *device, return NM_ACT_STAGE_RETURN_FAILURE; } - return NM_DEVICE_CLASS (nm_device_ovs_interface_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason); + return NM_DEVICE_CLASS (nm_device_ovs_interface_parent_class)->act_stage3_ip_config_start (device, addr_family, out_l3cd, out_failure_reason); } static gboolean diff --git a/src/devices/ovs/nm-device-ovs-port.c b/src/devices/ovs/nm-device-ovs-port.c index e021637779..15e2494587 100644 --- a/src/devices/ovs/nm-device-ovs-port.c +++ b/src/devices/ovs/nm-device-ovs-port.c @@ -60,7 +60,7 @@ get_generic_capabilities (NMDevice *device) static NMActStageReturn act_stage3_ip_config_start (NMDevice *device, int addr_family, - gpointer *out_config, + const NML3ConfigData **out_l3cd, NMDeviceStateReason *out_failure_reason) { return NM_ACT_STAGE_RETURN_IP_FAIL; diff --git a/src/devices/tests/meson.build b/src/devices/tests/meson.build index 1ddd4f8553..4e420ff3db 100644 --- a/src/devices/tests/meson.build +++ b/src/devices/tests/meson.build @@ -1,7 +1,6 @@ # SPDX-License-Identifier: LGPL-2.1+ test_units = [ - 'test-acd', 'test-lldp', ] diff --git a/src/devices/tests/test-acd.c b/src/devices/tests/test-acd.c deleted file mode 100644 index 32d6f6695a..0000000000 --- a/src/devices/tests/test-acd.c +++ /dev/null @@ -1,232 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ -/* - * Copyright (C) 2015 Red Hat, Inc. - */ - -#include "nm-default.h" - -#include "n-acd/src/n-acd.h" - -#include "devices/nm-acd-manager.h" -#include "platform/tests/test-common.h" - -#define IFACE_VETH0 "nm-test-veth0" -#define IFACE_VETH1 "nm-test-veth1" - -#define ADDR1 0x01010101 -#define ADDR2 0x02020202 -#define ADDR3 0x03030303 -#define ADDR4 0x04040404 - -/*****************************************************************************/ - -static gboolean -_skip_acd_test_check (void) -{ - NAcd *acd; - NAcdConfig *config; - const guint8 hwaddr[ETH_ALEN] = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06 }; - int r; - static int skip = -1; - - if (skip == -1) { - r = n_acd_config_new (&config); - g_assert (r == 0); - - n_acd_config_set_ifindex (config, 1); - n_acd_config_set_transport (config, N_ACD_TRANSPORT_ETHERNET); - n_acd_config_set_mac (config, hwaddr, sizeof (hwaddr)); - - r = n_acd_new (&acd, config); - n_acd_config_free (config); - if (r == 0) - n_acd_unref (acd); - - skip = (r != 0); - } - return skip; -} - -#define _skip_acd_test() \ - ({ \ - gboolean _skip = _skip_acd_test_check (); \ - \ - if (_skip) \ - g_test_skip ("Cannot create NAcd. Running under valgind?"); \ - _skip; \ - }) - -/*****************************************************************************/ - -typedef struct { - int ifindex0; - int ifindex1; - const guint8 *hwaddr0; - const guint8 *hwaddr1; - size_t hwaddr0_len; - size_t hwaddr1_len; -} test_fixture; - -static void -fixture_setup (test_fixture *fixture, gconstpointer user_data) -{ - /* create veth pair. */ - fixture->ifindex0 = nmtstp_link_veth_add (NM_PLATFORM_GET, -1, IFACE_VETH0, IFACE_VETH1)->ifindex; - fixture->ifindex1 = nmtstp_link_get_typed (NM_PLATFORM_GET, -1, IFACE_VETH1, NM_LINK_TYPE_VETH)->ifindex; - - g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, fixture->ifindex0, NULL)); - g_assert (nm_platform_link_set_up (NM_PLATFORM_GET, fixture->ifindex1, NULL)); - - fixture->hwaddr0 = nm_platform_link_get_address (NM_PLATFORM_GET, fixture->ifindex0, &fixture->hwaddr0_len); - fixture->hwaddr1 = nm_platform_link_get_address (NM_PLATFORM_GET, fixture->ifindex1, &fixture->hwaddr1_len); -} - -typedef struct { - in_addr_t addresses[8]; - in_addr_t peer_addresses[8]; - gboolean expected_result[8]; -} TestInfo; - -static void -acd_manager_probe_terminated (NMAcdManager *acd_manager, gpointer user_data) -{ - g_main_loop_quit (user_data); -} - -static void -test_acd_common (test_fixture *fixture, TestInfo *info) -{ - nm_auto_free_acdmgr NMAcdManager *manager = NULL; - nm_auto_unref_gmainloop GMainLoop *loop = NULL; - int i; - const guint WAIT_TIME_OPTIMISTIC = 50; - guint wait_time; - static const NMAcdCallbacks callbacks = { - .probe_terminated_callback = acd_manager_probe_terminated, - .user_data_destroy = (GDestroyNotify) g_main_loop_unref, - }; - int r; - - if (_skip_acd_test ()) - return; - - /* first, try with a short waittime. We hope that this is long enough - * to successfully complete the test. Only if that's not the case, we - * assume the computer is currently busy (high load) and we retry with - * a longer timeout. */ - wait_time = WAIT_TIME_OPTIMISTIC; -again: - - nm_clear_pointer (&loop, g_main_loop_unref); - loop = g_main_loop_new (NULL, FALSE); - - nm_clear_pointer (&manager, nm_acd_manager_free); - manager = nm_acd_manager_new (fixture->ifindex0, - fixture->hwaddr0, - fixture->hwaddr0_len, - &callbacks, - g_main_loop_ref (loop)); - g_assert (manager != NULL); - - for (i = 0; info->addresses[i]; i++) - g_assert (nm_acd_manager_add_address (manager, info->addresses[i])); - - for (i = 0; info->peer_addresses[i]; i++) { - nmtstp_ip4_address_add (NULL, FALSE, fixture->ifindex1, info->peer_addresses[i], - 24, 0, 3600, 1800, 0, NULL); - } - - r = nm_acd_manager_start_probe (manager, wait_time); - g_assert_cmpint (r, ==, 0); - - g_assert (nmtst_main_loop_run (loop, 2000)); - - for (i = 0; info->addresses[i]; i++) { - gboolean val; - char sbuf[NM_UTILS_INET_ADDRSTRLEN]; - - val = nm_acd_manager_check_address (manager, info->addresses[i]); - if (val == info->expected_result[i]) - continue; - - if (wait_time == WAIT_TIME_OPTIMISTIC) { - /* probably we just had a glitch and the system took longer than - * expected. Re-verify with a large timeout this time. */ - wait_time = 1000; - goto again; - } - - g_error ("expected check for address #%d (%s) to %s, but it didn't", - i, _nm_utils_inet4_ntop (info->addresses[i], sbuf), - info->expected_result[i] ? "detect no duplicated" : "detect a duplicate"); - } -} - -static void -test_acd_probe_1 (test_fixture *fixture, gconstpointer user_data) -{ - TestInfo info = { .addresses = { ADDR1, ADDR2, ADDR3 }, - .peer_addresses = { ADDR4 }, - .expected_result = { TRUE, TRUE, TRUE } }; - - test_acd_common (fixture, &info); -} - -static void -test_acd_probe_2 (test_fixture *fixture, gconstpointer user_data) -{ - TestInfo info = { .addresses = { ADDR1, ADDR2, ADDR3, ADDR4 }, - .peer_addresses = { ADDR3, ADDR2 }, - .expected_result = { TRUE, FALSE, FALSE, TRUE } }; - - test_acd_common (fixture, &info); -} - -static void -test_acd_announce (test_fixture *fixture, gconstpointer user_data) -{ - nm_auto_free_acdmgr NMAcdManager *manager = NULL; - nm_auto_unref_gmainloop GMainLoop *loop = NULL; - int r; - - if (_skip_acd_test ()) - return; - - manager = nm_acd_manager_new (fixture->ifindex0, - fixture->hwaddr0, - fixture->hwaddr0_len, - NULL, - NULL); - g_assert (manager != NULL); - - g_assert (nm_acd_manager_add_address (manager, ADDR1)); - g_assert (nm_acd_manager_add_address (manager, ADDR2)); - - loop = g_main_loop_new (NULL, FALSE); - r = nm_acd_manager_announce_addresses (manager); - g_assert_cmpint (r, ==, 0); - g_assert (!nmtst_main_loop_run (loop, 200)); -} - -static void -fixture_teardown (test_fixture *fixture, gconstpointer user_data) -{ - nm_platform_link_delete (NM_PLATFORM_GET, fixture->ifindex0); - nm_platform_link_delete (NM_PLATFORM_GET, fixture->ifindex1); -} - -NMTstpSetupFunc const _nmtstp_setup_platform_func = nm_linux_platform_setup; - -void -_nmtstp_init_tests (int *argc, char ***argv) -{ - nmtst_init_with_logging (argc, argv, NULL, "ALL"); -} - -void -_nmtstp_setup_tests (void) -{ - g_test_add ("/acd/probe/1", test_fixture, NULL, fixture_setup, test_acd_probe_1, fixture_teardown); - g_test_add ("/acd/probe/2", test_fixture, NULL, fixture_setup, test_acd_probe_2, fixture_teardown); - g_test_add ("/acd/announce", test_fixture, NULL, fixture_setup, test_acd_announce, fixture_teardown); -} diff --git a/src/devices/wifi/nm-device-wifi-p2p.c b/src/devices/wifi/nm-device-wifi-p2p.c index 497bc43603..89d856bd4a 100644 --- a/src/devices/wifi/nm-device-wifi-p2p.c +++ b/src/devices/wifi/nm-device-wifi-p2p.c @@ -554,7 +554,7 @@ remove_all_peers (NMDeviceWifiP2P *self) static NMActStageReturn act_stage3_ip_config_start (NMDevice *device, int addr_family, - gpointer *out_config, + const NML3ConfigData **out_l3cd, NMDeviceStateReason *out_failure_reason) { gboolean indicate_addressing_running; @@ -575,7 +575,7 @@ act_stage3_ip_config_start (NMDevice *device, if (indicate_addressing_running) nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), TRUE); - return NM_DEVICE_CLASS (nm_device_wifi_p2p_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason); + return NM_DEVICE_CLASS (nm_device_wifi_p2p_parent_class)->act_stage3_ip_config_start (device, addr_family, out_l3cd, out_failure_reason); } static void diff --git a/src/devices/wifi/nm-device-wifi.c b/src/devices/wifi/nm-device-wifi.c index 4a2f1f855e..1cceda2215 100644 --- a/src/devices/wifi/nm-device-wifi.c +++ b/src/devices/wifi/nm-device-wifi.c @@ -3223,7 +3223,7 @@ out_fail: static NMActStageReturn act_stage3_ip_config_start (NMDevice *device, int addr_family, - gpointer *out_config, + const NML3ConfigData **out_l3cd, NMDeviceStateReason *out_failure_reason) { gboolean indicate_addressing_running; @@ -3243,7 +3243,7 @@ act_stage3_ip_config_start (NMDevice *device, if (indicate_addressing_running) nm_platform_wifi_indicate_addressing_running (nm_device_get_platform (device), nm_device_get_ip_ifindex (device), TRUE); - return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage3_ip_config_start (device, addr_family, out_config, out_failure_reason); + return NM_DEVICE_CLASS (nm_device_wifi_parent_class)->act_stage3_ip_config_start (device, addr_family, out_l3cd, out_failure_reason); } static guint32 diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index a2f2e7a6f8..640d343737 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -8,7 +8,7 @@ #include "nm-device-modem.h" #include "nm-modem.h" -#include "nm-ip4-config.h" +#include "nm-l3-config-data.h" #include "devices/nm-device-private.h" #include "nm-rfkill-manager.h" #include "settings/nm-settings-connection.h" @@ -34,6 +34,7 @@ typedef struct { NMModem *modem; NMDeviceModemCapabilities caps; NMDeviceModemCapabilities current_caps; + NMUtilsIPv6IfaceId iid; char *device_id; char *operator_code; char *apn; @@ -195,41 +196,38 @@ modem_auth_result (NMModem *modem, GError *error, gpointer user_data) } static void -modem_ip4_config_result (NMModem *modem, - NMIP4Config *config, - GError *error, - gpointer user_data) +modem_new_config (NMModem *modem, + int addr_family, + const NML3ConfigData *l3cd, + gboolean do_slaac, + const NMUtilsIPv6IfaceId *iid, + GError *error, + gpointer user_data) { NMDeviceModem *self = NM_DEVICE_MODEM (user_data); + NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (self); NMDevice *device = NM_DEVICE (self); + NMActStageReturn ret; + NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; + nm_auto_unref_l3cd const NML3ConfigData *l3cd_ignored = NULL; - g_return_if_fail (nm_device_activate_ip4_state_in_conf (device) == TRUE); + if (addr_family == AF_INET) { - if (error) { - _LOGW (LOGD_MB | LOGD_IP4, "retrieving IPv4 configuration failed: %s", - error->message); - nm_device_ip_method_failed (device, - AF_INET, - NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); - } else { - nm_device_set_dev2_ip_config (device, AF_INET, NM_IP_CONFIG_CAST (config)); - nm_device_activate_schedule_ip_config_result (device, AF_INET, NULL); - } -} + g_return_if_fail (nm_device_activate_ip4_state_in_conf (device) == TRUE); -static void -modem_ip6_config_result (NMModem *modem, - NMIP6Config *config, - gboolean do_slaac, - GError *error, - gpointer user_data) -{ - NMDeviceModem *self = NM_DEVICE_MODEM (user_data); - NMDevice *device = NM_DEVICE (self); - NMActStageReturn ret; - NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; - gs_unref_object NMIP6Config *ignored = NULL; - gboolean got_config = !!config; + if (error) { + _LOGW (LOGD_MB | LOGD_IP4, "retrieving IPv4 configuration failed: %s", + error->message); + nm_device_ip_method_failed (device, + AF_INET, + NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); + return; + } + + nm_device_set_dev2_ip_config (device, AF_INET, l3cd); + nm_device_activate_schedule_ip_config_result (device, AF_INET); + return; + } g_return_if_fail (nm_device_activate_ip6_state_in_conf (device) == TRUE); @@ -242,15 +240,19 @@ modem_ip6_config_result (NMModem *modem, return; } + if (iid) + priv->iid = *iid; + else + priv->iid.id = 0; + /* Re-enable IPv6 on the interface */ nm_device_sysctl_ip_conf_set (device, AF_INET6, "disable_ipv6", "0"); - if (config) - nm_device_set_dev2_ip_config (device, AF_INET6, NM_IP_CONFIG_CAST (config)); + nm_device_set_dev2_ip_config (device, AF_INET6, l3cd); if (do_slaac == FALSE) { - if (got_config) - nm_device_activate_schedule_ip_config_result (device, AF_INET6, NULL); + if (l3cd) + nm_device_activate_schedule_ip_config_result (device, AF_INET6); else { _LOGW (LOGD_MB | LOGD_IP6, "retrieving IPv6 configuration failed: SLAAC not requested and no addresses"); nm_device_ip_method_failed (device, @@ -261,9 +263,9 @@ modem_ip6_config_result (NMModem *modem, } /* Start SLAAC now that we have a link-local address from the modem */ - ret = NM_DEVICE_CLASS (nm_device_modem_parent_class)->act_stage3_ip_config_start (device, AF_INET6, (gpointer *) &ignored, &failure_reason); + ret = NM_DEVICE_CLASS (nm_device_modem_parent_class)->act_stage3_ip_config_start (device, AF_INET6, &l3cd_ignored, &failure_reason); - nm_assert (ignored == NULL); + nm_assert (!l3cd_ignored); switch (ret) { case NM_ACT_STAGE_RETURN_FAILURE: @@ -271,7 +273,7 @@ modem_ip6_config_result (NMModem *modem, break; case NM_ACT_STAGE_RETURN_IP_FAIL: /* all done */ - nm_device_activate_schedule_ip_config_result (device, AF_INET6, NULL); + nm_device_activate_schedule_ip_config_result (device, AF_INET6); break; case NM_ACT_STAGE_RETURN_POSTPONE: /* let SLAAC run */ @@ -620,7 +622,7 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason) static NMActStageReturn act_stage3_ip_config_start (NMDevice *device, int addr_family, - gpointer *out_config, + const NML3ConfigData **out_l3cd, NMDeviceStateReason *out_failure_reason) { NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (device); @@ -650,13 +652,15 @@ get_ip_iface_identifier (NMDevice *device, NMUtilsIPv6IfaceId *out_iid) { NMDeviceModem *self = NM_DEVICE_MODEM (device); NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE (self); - gboolean success; g_return_val_if_fail (priv->modem, FALSE); - success = nm_modem_get_iid (priv->modem, out_iid); - if (!success) - success = NM_DEVICE_CLASS (nm_device_modem_parent_class)->get_ip_iface_identifier (device, out_iid); - return success; + + if (priv->iid.id != 0) { + *out_iid = priv->iid; + return TRUE; + } + + return NM_DEVICE_CLASS (nm_device_modem_parent_class)->get_ip_iface_identifier (device, out_iid); } /*****************************************************************************/ @@ -724,8 +728,7 @@ set_modem (NMDeviceModem *self, NMModem *modem) g_signal_connect (modem, NM_MODEM_PPP_FAILED, G_CALLBACK (ppp_failed), self); g_signal_connect (modem, NM_MODEM_PREPARE_RESULT, G_CALLBACK (modem_prepare_result), self); - g_signal_connect (modem, NM_MODEM_IP4_CONFIG_RESULT, G_CALLBACK (modem_ip4_config_result), self); - g_signal_connect (modem, NM_MODEM_IP6_CONFIG_RESULT, G_CALLBACK (modem_ip6_config_result), self); + g_signal_connect (modem, NM_MODEM_NEW_CONFIG, G_CALLBACK (modem_new_config), self); g_signal_connect (modem, NM_MODEM_AUTH_REQUESTED, G_CALLBACK (modem_auth_requested), self); g_signal_connect (modem, NM_MODEM_AUTH_RESULT, G_CALLBACK (modem_auth_result), self); g_signal_connect (modem, NM_MODEM_STATE_CHANGED, G_CALLBACK (modem_state_cb), self); diff --git a/src/devices/wwan/nm-modem-broadband.c b/src/devices/wwan/nm-modem-broadband.c index 0929adafc4..dd3a7325df 100644 --- a/src/devices/wwan/nm-modem-broadband.c +++ b/src/devices/wwan/nm-modem-broadband.c @@ -15,8 +15,7 @@ #include "NetworkManagerUtils.h" #include "devices/nm-device-private.h" #include "platform/nm-platform.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" +#include "nm-l3-config-data.h" #define NM_MODEM_BROADBAND_MODEM "modem" @@ -953,10 +952,12 @@ set_mm_enabled (NMModem *_self, /* IPv4 method static */ static gboolean -static_stage3_ip4_done (NMModemBroadband *self) +static_stage3_ip4_done (gpointer user_data) { - GError *error = NULL; - gs_unref_object NMIP4Config *config = NULL; + NMModemBroadband *self = user_data; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + char sbuf[sizeof (_nm_utils_to_string_buffer)]; + gs_free_error GError *error = NULL; const char *data_port; const char *address_string; const char *gw_string; @@ -964,9 +965,11 @@ static_stage3_ip4_done (NMModemBroadband *self) guint32 gw = 0; NMPlatformIP4Address address; const char **dns; + int ifindex; guint i; - guint32 ip4_route_table, ip4_route_metric; - NMPlatformIP4Route *r; + guint32 ip4_route_metric; + guint32 ip4_route_table; + NMPlatformIP4Route route; guint32 mtu_n; g_return_val_if_fail (self->_priv.ipv4_config, FALSE); @@ -980,11 +983,12 @@ static_stage3_ip4_done (NMModemBroadband *self) address_string = mm_bearer_ip_config_get_address (self->_priv.ipv4_config); if ( !address_string || !nm_utils_parse_inaddr_bin (AF_INET, address_string, NULL, &address_network)) { - error = g_error_new (NM_DEVICE_ERROR, - NM_DEVICE_ERROR_INVALID_CONNECTION, - "(%s) retrieving IP4 configuration failed: invalid address given %s%s%s", - nm_modem_get_uid (NM_MODEM (self)), - NM_PRINT_FMT_QUOTE_STRING (address_string)); + g_set_error (&error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + "(%s) retrieving IP4 configuration failed: invalid address given %s%s%s", + nm_modem_get_uid (NM_MODEM (self)), + NM_PRINT_FMT_QUOTE_STRING (address_string)); goto out; } @@ -992,49 +996,65 @@ static_stage3_ip4_done (NMModemBroadband *self) gw_string = mm_bearer_ip_config_get_gateway (self->_priv.ipv4_config); if ( gw_string && !nm_utils_parse_inaddr_bin (AF_INET, gw_string, NULL, &gw)) { - error = g_error_new (NM_DEVICE_ERROR, - NM_DEVICE_ERROR_INVALID_CONNECTION, - "(%s) retrieving IP4 configuration failed: invalid gateway address \"%s\"", - nm_modem_get_uid (NM_MODEM (self)), - gw_string); + g_set_error (&error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + "(%s) retrieving IP4 configuration failed: invalid gateway address \"%s\"", + nm_modem_get_uid (NM_MODEM (self)), + gw_string); goto out; } data_port = mm_bearer_get_interface (self->_priv.bearer); g_return_val_if_fail (data_port, FALSE); - config = nm_ip4_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET), - nm_platform_link_get_ifindex (NM_PLATFORM_GET, data_port)); - - memset (&address, 0, sizeof (address)); - address.address = address_network; - address.peer_address = address_network; - address.plen = mm_bearer_ip_config_get_prefix (self->_priv.ipv4_config); - address.addr_source = NM_IP_CONFIG_SOURCE_WWAN; + + ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, data_port); + if (ifindex <= 0) { + g_set_error (&error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + "(%s) data port %s not found", + nm_modem_get_uid (NM_MODEM (self)), + data_port); + goto out; + } + + l3cd = nm_l3_config_data_new (nm_platform_get_multi_idx (NM_PLATFORM_GET), + ifindex); + + nm_l3_config_data_set_source (l3cd, NM_IP_CONFIG_SOURCE_WWAN); + + address = (NMPlatformIP4Address) { + .address = address_network, + .peer_address = address_network, + .plen = mm_bearer_ip_config_get_prefix (self->_priv.ipv4_config), + .addr_source = NM_IP_CONFIG_SOURCE_WWAN, + }; if (address.plen <= 32) - nm_ip4_config_add_address (config, &address); + nm_l3_config_data_add_address_4 (l3cd, &address); - _LOGI (" address %s/%d", address_string, address.plen); + _LOGI (" address %s", nm_platform_ip4_address_to_string (&address, sbuf, sizeof (sbuf))); nm_modem_get_route_parameters (NM_MODEM (self), &ip4_route_table, &ip4_route_metric, NULL, NULL); - r = &(NMPlatformIP4Route) { + + route = (NMPlatformIP4Route) { .rt_source = NM_IP_CONFIG_SOURCE_WWAN, .gateway = gw, .table_coerced = nm_platform_route_table_coerce (ip4_route_table), .metric = ip4_route_metric, }; - nm_ip4_config_add_route (config, r, NULL); + nm_l3_config_data_add_route_4 (l3cd, &route); _LOGI (" gateway %s", gw_string); - /* DNS servers */ dns = mm_bearer_ip_config_get_dns (self->_priv.ipv4_config); for (i = 0; dns && dns[i]; i++) { if ( nm_utils_parse_inaddr_bin (AF_INET, dns[i], NULL, &address_network) && address_network > 0) { - nm_ip4_config_add_nameserver (config, address_network); + nm_l3_config_data_add_nameserver (l3cd, AF_INET, &address_network); _LOGI (" DNS %s", dns[i]); } } @@ -1042,15 +1062,17 @@ static_stage3_ip4_done (NMModemBroadband *self) #if MM_CHECK_VERSION(1, 4, 0) mtu_n = mm_bearer_ip_config_get_mtu (self->_priv.ipv4_config); if (mtu_n) { - nm_ip4_config_set_mtu (config, mtu_n, NM_IP_CONFIG_SOURCE_WWAN); + nm_l3_config_data_set_mtu (l3cd, mtu_n); _LOGI (" MTU %u", mtu_n); } #endif out: - g_signal_emit_by_name (self, NM_MODEM_IP4_CONFIG_RESULT, config, error); - g_clear_error (&error); - return FALSE; + if (error) + nm_clear_l3cd (&l3cd); + + nm_modem_emit_signal_new_config (NM_MODEM (self), AF_INET, l3cd, FALSE, NULL, error); + return G_SOURCE_REMOVE; } static NMActStageReturn @@ -1064,8 +1086,7 @@ static_stage3_ip4_config_start (NMModem *modem, /* We schedule it in an idle just to follow the same logic as in the * generic modem implementation. */ nm_clear_g_source (&priv->idle_id_ip4); - priv->idle_id_ip4 = g_idle_add ((GSourceFunc) static_stage3_ip4_done, self); - + priv->idle_id_ip4 = g_idle_add (static_stage3_ip4_done, self); return NM_ACT_STAGE_RETURN_POSTPONE; } @@ -1073,21 +1094,26 @@ static_stage3_ip4_config_start (NMModem *modem, /* IPv6 method static */ static gboolean -stage3_ip6_done (NMModemBroadband *self) +stage3_ip6_done (gpointer user_data) { - GError *error = NULL; - NMIP6Config *config = NULL; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + char sbuf[sizeof (_nm_utils_to_string_buffer)]; + NMModemBroadband *self = user_data; + gs_free_error GError *error = NULL; const char *data_port; const char *address_string; NMPlatformIP6Address address; NMModemIPMethod ip_method; const char **dns; guint i; + gboolean do_slaac = TRUE; + int ifindex; + NMUtilsIPv6IfaceId iid_data; + const NMUtilsIPv6IfaceId *iid = NULL; - g_return_val_if_fail (self->_priv.ipv6_config, FALSE); + g_return_val_if_fail (self->_priv.ipv6_config, G_SOURCE_REMOVE); self->_priv.idle_id_ip6 = 0; - memset (&address, 0, sizeof (address)); ip_method = get_bearer_ip_method (self->_priv.ipv6_config); @@ -1095,48 +1121,73 @@ stage3_ip6_done (NMModemBroadband *self) if (!address_string) { /* DHCP/SLAAC is allowed to skip addresses; other methods require it */ if (ip_method != NM_MODEM_IP_METHOD_AUTO) { - error = g_error_new (NM_DEVICE_ERROR, - NM_DEVICE_ERROR_INVALID_CONNECTION, - "(%s) retrieving IPv6 configuration failed: no address given", - nm_modem_get_uid (NM_MODEM (self))); + g_set_error (&error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + "(%s) retrieving IPv6 configuration failed: no address given", + nm_modem_get_uid (NM_MODEM (self))); } goto out; } - /* Fail if invalid IP address retrieved */ - if (!inet_pton (AF_INET6, address_string, (void *) &(address.address))) { - error = g_error_new (NM_DEVICE_ERROR, - NM_DEVICE_ERROR_INVALID_CONNECTION, - "(%s) retrieving IPv6 configuration failed: invalid address given '%s'", - nm_modem_get_uid (NM_MODEM (self)), - address_string); + address = (NMPlatformIP6Address) { + }; + + if (!inet_pton (AF_INET6, address_string, &address.address)) { + g_set_error (&error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + "(%s) retrieving IPv6 configuration failed: invalid address given '%s'", + nm_modem_get_uid (NM_MODEM (self)), + address_string); goto out; } - _LOGI ("IPv6 base configuration:"); - data_port = mm_bearer_get_interface (self->_priv.bearer); - g_return_val_if_fail (data_port, FALSE); + g_return_val_if_fail (data_port, G_SOURCE_REMOVE); + + ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, data_port); + if (ifindex <= 0) { + g_set_error (&error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + "(%s) data port %s not found", + nm_modem_get_uid (NM_MODEM (self)), + data_port); + goto out; + } - config = nm_ip6_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET), - nm_platform_link_get_ifindex (NM_PLATFORM_GET, data_port)); + _LOGI ("IPv6 base configuration:"); + + l3cd = nm_l3_config_data_new (nm_platform_get_multi_idx (NM_PLATFORM_GET), + ifindex); address.plen = mm_bearer_ip_config_get_prefix (self->_priv.ipv6_config); - if (address.plen <= 128) - nm_ip6_config_add_address (config, &address); + if (address.plen <= 128) { + if (IN6_IS_ADDR_LINKLOCAL (&address.address)) { + iid_data.id = ((guint64 *) (&address.address.s6_addr))[1]; + iid = &iid_data; + } else + do_slaac = FALSE; + nm_l3_config_data_add_address_6 (l3cd, &address); + } - _LOGI (" address %s/%d", address_string, address.plen); + _LOGI (" address %s (slaac %s)", + nm_platform_ip6_address_to_string (&address, sbuf, sizeof (sbuf)), + do_slaac ? "enabled" : "disabled"); address_string = mm_bearer_ip_config_get_gateway (self->_priv.ipv6_config); if (address_string) { - guint32 ip6_route_table, ip6_route_metric; + guint32 ip6_route_table; + guint32 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'", - nm_modem_get_uid (NM_MODEM (self)), - address_string); + g_set_error (&error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + "(%s) retrieving IPv6 configuration failed: invalid gateway given '%s'", + nm_modem_get_uid (NM_MODEM (self)), + address_string); goto out; } @@ -1154,33 +1205,36 @@ stage3_ip6_done (NMModemBroadband *self) }; _LOGI (" gateway %s", address_string); - nm_ip6_config_add_route (config, &r, NULL); + nm_l3_config_data_add_route_6 (l3cd, &r); } } else if (ip_method == NM_MODEM_IP_METHOD_STATIC) { /* Gateway required for the 'static' method */ - error = g_error_new (NM_DEVICE_ERROR, - NM_DEVICE_ERROR_INVALID_CONNECTION, - "(%s) retrieving IPv6 configuration failed: missing gateway", - nm_modem_get_uid (NM_MODEM (self))); + g_set_error (&error, + NM_DEVICE_ERROR, + NM_DEVICE_ERROR_INVALID_CONNECTION, + "(%s) retrieving IPv6 configuration failed: missing gateway", + nm_modem_get_uid (NM_MODEM (self))); goto out; } - /* DNS servers */ dns = mm_bearer_ip_config_get_dns (self->_priv.ipv6_config); for (i = 0; dns && dns[i]; i++) { struct in6_addr addr; if (inet_pton (AF_INET6, dns[i], &addr)) { - nm_ip6_config_add_nameserver (config, &addr); + nm_l3_config_data_add_nameserver (l3cd, AF_INET6, &addr); _LOGI (" DNS %s", dns[i]); } } out: - nm_modem_emit_ip6_config_result (NM_MODEM (self), config, error); - g_clear_object (&config); - g_clear_error (&error); - return FALSE; + if (error) { + nm_clear_l3cd (&l3cd); + do_slaac = FALSE; + iid = NULL; + } + nm_modem_emit_signal_new_config (NM_MODEM (self), AF_INET6, l3cd, do_slaac, iid, error); + return G_SOURCE_REMOVE; } static NMActStageReturn @@ -1192,7 +1246,7 @@ stage3_ip6_config_request (NMModem *modem, NMDeviceStateReason *out_failure_reas /* We schedule it in an idle just to follow the same logic as in the * generic modem implementation. */ nm_clear_g_source (&priv->idle_id_ip6); - priv->idle_id_ip6 = g_idle_add ((GSourceFunc) stage3_ip6_done, self); + priv->idle_id_ip6 = g_idle_add (stage3_ip6_done, self); return NM_ACT_STAGE_RETURN_POSTPONE; } diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 96b08e7cff..c2acba5891 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -11,7 +11,7 @@ #include "devices/nm-device-private.h" #include "nm-modem.h" #include "platform/nm-platform.h" -#include "nm-ip4-config.h" +#include "nm-l3-config-data.h" #define VARIANT_IS_OF_TYPE_BOOLEAN(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_BOOLEAN) )) #define VARIANT_IS_OF_TYPE_STRING(v) ((v) != NULL && ( g_variant_is_of_type ((v), G_VARIANT_TYPE_STRING) )) @@ -42,7 +42,7 @@ typedef struct { gboolean modem_online; gboolean gprs_attached; - NMIP4Config *ip4_config; + NML3ConfigData *l3cd_4; } NMModemOfonoPrivate; struct _NMModemOfono { @@ -243,7 +243,7 @@ deactivate_cleanup (NMModem *modem, /* TODO: cancel SimpleConnect() if any */ - g_clear_object (&priv->ip4_config); + nm_clear_l3cd (&priv->l3cd_4); NM_MODEM_CLASS (nm_modem_ofono_parent_class)->deactivate_cleanup (modem, device, @@ -793,12 +793,13 @@ context_property_changed (GDBusProxy *proxy, { NMModemOfono *self = NM_MODEM_OFONO (user_data); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); - NMPlatformIP4Address addr; + char sbuf[sizeof (_nm_utils_to_string_buffer)]; + NMPlatformIP4Address address; gboolean ret = FALSE; gs_unref_variant GVariant *v_dict = NULL; const char *interface; const char *s; - const char **array, **iter; + const char **array; guint32 address_network, gateway_network; guint32 ip4_route_table, ip4_route_metric; int ifindex; @@ -842,13 +843,14 @@ context_property_changed (GDBusProxy *proxy, } ifindex = nm_modem_get_ip_ifindex (NM_MODEM (self)); - nm_assert (ifindex > 0); + g_return_if_fail (ifindex > 0); - /* TODO: verify handling of ip4_config; check other places it's used... */ - g_clear_object (&priv->ip4_config); + /* TODO: verify handling of l3cd_4; check other places it's used... */ + nm_clear_l3cd (&priv->l3cd_4); - priv->ip4_config = nm_ip4_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET), + priv->l3cd_4 = nm_l3_config_data_new (nm_platform_get_multi_idx (NM_PLATFORM_GET), ifindex); + nm_l3_config_data_set_source (priv->l3cd_4, NM_IP_CONFIG_SOURCE_WWAN); if (!g_variant_lookup (v_dict, "Address", "&s", &s)) { _LOGW ("Settings 'Address' missing"); @@ -859,10 +861,12 @@ context_property_changed (GDBusProxy *proxy, _LOGW ("can't convert 'Address' %s to addr", s ?: ""); goto out; } - memset (&addr, 0, sizeof (addr)); - addr.ifindex = ifindex; - addr.address = address_network; - addr.addr_source = NM_IP_CONFIG_SOURCE_WWAN; + + address = (NMPlatformIP4Address) { + .ifindex = ifindex, + .address = address_network, + .addr_source = NM_IP_CONFIG_SOURCE_WWAN, + }; if (!g_variant_lookup (v_dict, "Netmask", "&s", &s)) { _LOGW ("Settings 'Netmask' missing"); @@ -873,10 +877,10 @@ context_property_changed (GDBusProxy *proxy, _LOGW ("invalid 'Netmask': %s", s ?: ""); goto out; } - addr.plen = nm_utils_ip4_netmask_to_prefix (address_network); + address.plen = nm_utils_ip4_netmask_to_prefix (address_network); - _LOGI ("Address: %s", nm_platform_ip4_address_to_string (&addr, NULL, 0)); - nm_ip4_config_add_address (priv->ip4_config, &addr); + _LOGI ("Address: %s", nm_platform_ip4_address_to_string (&address, sbuf, sizeof (sbuf))); + nm_l3_config_data_add_address_4 (priv->l3cd_4, &address); if ( !g_variant_lookup (v_dict, "Gateway", "&s", &s) || !s) { @@ -894,14 +898,14 @@ context_property_changed (GDBusProxy *proxy, NULL); { const NMPlatformIP4Route r = { - .rt_source = NM_IP_CONFIG_SOURCE_WWAN, - .gateway = gateway_network, + .rt_source = NM_IP_CONFIG_SOURCE_WWAN, + .gateway = gateway_network, .table_coerced = nm_platform_route_table_coerce (ip4_route_table), - .metric = ip4_route_metric, + .metric = ip4_route_metric, }; _LOGI ("Gateway: %s", s); - nm_ip4_config_add_route (priv->ip4_config, &r, NULL); + nm_l3_config_data_add_route_4 (priv->l3cd_4, &r); } if (!g_variant_lookup (v_dict, "DomainNameServers", "^a&s", &array)) { @@ -909,22 +913,23 @@ context_property_changed (GDBusProxy *proxy, goto out; } if (array) { - for (iter = array; *iter; iter++) { - if ( nm_utils_parse_inaddr_bin (AF_INET, *iter, NULL, &address_network) - && address_network) { - _LOGI ("DNS: %s", *iter); - nm_ip4_config_add_nameserver (priv->ip4_config, address_network); - } else { - _LOGW ("invalid NameServer: %s", *iter); + gs_free const char **array_free = array; + gboolean any_good = FALSE; + + for (; array[0]; array++) { + if ( !nm_utils_parse_inaddr_bin (AF_INET, *array, NULL, &address_network) + || !address_network) { + _LOGW ("invalid NameServer: %s", *array); + continue; } + any_good = TRUE; + _LOGI ("DNS: %s", *array); + nm_l3_config_data_add_nameserver (priv->l3cd_4, AF_INET, &address_network); } - - if (iter == array) { + if (!any_good) { _LOGW ("Settings: 'DomainNameServers': none specified"); - g_free (array); goto out; } - g_free (array); } if (g_variant_lookup (v_dict, "MessageProxy", "&s", &s)) { @@ -939,23 +944,25 @@ context_property_changed (GDBusProxy *proxy, { const NMPlatformIP4Route mms_route = { - .network = address_network, - .plen = 32, - .gateway = gateway_network, + .network = address_network, + .plen = 32, + .gateway = gateway_network, .table_coerced = nm_platform_route_table_coerce (ip4_route_table), - .metric = ip4_route_metric, + .metric = ip4_route_metric, }; - nm_ip4_config_add_route (priv->ip4_config, &mms_route, NULL); + nm_l3_config_data_add_route_4 (priv->l3cd_4, &mms_route); } - } else { + } else _LOGW ("invalid MessageProxy: %s", s); - } } ret = TRUE; out: + if (priv->l3cd_4) + nm_l3_config_data_seal (priv->l3cd_4); + if (nm_modem_get_state (NM_MODEM (self)) != NM_MODEM_STATE_CONNECTED) { _LOGI ("emitting PREPARE_RESULT: %s", ret ? "TRUE" : "FALSE"); nm_modem_emit_prepare_result (NM_MODEM (self), ret, @@ -975,18 +982,17 @@ static_stage3_ip4_config_start (NMModem *modem, { NMModemOfono *self = NM_MODEM_OFONO (modem); NMModemOfonoPrivate *priv = NM_MODEM_OFONO_GET_PRIVATE (self); - GError *error = NULL; - if (!priv->ip4_config) { + if (!priv->l3cd_4) { _LOGD ("IP4 config not ready(?)"); return NM_ACT_STAGE_RETURN_FAILURE; } _LOGD ("IP4 config is done; setting modem_state -> CONNECTED"); - g_signal_emit_by_name (self, NM_MODEM_IP4_CONFIG_RESULT, priv->ip4_config, error); - /* Signal listener takes ownership of the IP4Config */ - priv->ip4_config = NULL; + nm_modem_emit_signal_new_config (NM_MODEM (self), AF_INET, priv->l3cd_4, FALSE, NULL, NULL); + + nm_clear_l3cd (&priv->l3cd_4); nm_modem_set_state (NM_MODEM (self), NM_MODEM_STATE_CONNECTED, @@ -1031,7 +1037,7 @@ context_proxy_new_cb (GObject *source, GAsyncResult *result, gpointer user_data) * clear it so that we can gate getting the IP config from oFono * on whether or not we have already received them */ - g_clear_object (&priv->ip4_config); + nm_clear_l3cd (&priv->l3cd_4); _nm_dbus_signal_connect (priv->context_proxy, "PropertyChanged", @@ -1252,7 +1258,7 @@ dispose (GObject *object) priv->connect_properties = NULL; } - g_clear_object (&priv->ip4_config); + nm_clear_l3cd (&priv->l3cd_4); if (priv->modem_proxy) { g_signal_handlers_disconnect_by_data (priv->modem_proxy, self); diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index bedc38448a..e6ef5cf2f2 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -19,8 +19,7 @@ #include "devices/nm-device-private.h" #include "nm-netns.h" #include "nm-act-request.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" +#include "nm-l3-config-data.h" #include "ppp/nm-ppp-manager-call.h" #include "ppp/nm-ppp-status.h" @@ -45,8 +44,7 @@ enum { PPP_STATS, PPP_FAILED, PREPARE_RESULT, - IP4_CONFIG_RESULT, - IP6_CONFIG_RESULT, + NEW_CONFIG, AUTH_REQUESTED, AUTH_RESULT, REMOVED, @@ -70,7 +68,6 @@ typedef struct _NMModemPrivate { int ip_ifindex; NMModemIPMethod ip4_method; NMModemIPMethod ip6_method; - NMUtilsIPv6IfaceId iid; NMModemState state; NMModemState prev_state; /* revert to this state if enable/disable fails */ char *device_id; @@ -177,6 +174,41 @@ nm_modem_state_to_string (NMModemState state) /*****************************************************************************/ +void +nm_modem_emit_signal_new_config (NMModem *self, + int addr_family, + const NML3ConfigData *l3cd, + gboolean do_slaac, + const NMUtilsIPv6IfaceId *iid, + GError *error) +{ + nm_assert (NM_IS_MODEM (self)); + nm_assert_addr_family (addr_family); + nm_assert (!l3cd || NM_IS_L3_CONFIG_DATA (l3cd)); + nm_assert (!do_slaac || addr_family == AF_INET6); + nm_assert (!iid || addr_family == AF_INET6); + nm_assert (!error || (!l3cd && !do_slaac && !iid)); + + if (error) { + do_slaac = FALSE; + l3cd = NULL; + iid = NULL; + goto out_emit; + } + + if (addr_family == AF_INET6) { + do_slaac = !!do_slaac; + } else { + iid = NULL; + do_slaac = FALSE; + } + if (l3cd) + nm_l3_config_data_seal (l3cd); + +out_emit: + g_signal_emit (self, signals[NEW_CONFIG], 0, addr_family, l3cd, do_slaac, iid, error); +} + gboolean nm_modem_is_claimed (NMModem *self) { @@ -527,68 +559,74 @@ ppp_ifindex_set (NMPPPManager *ppp_manager, } static void -ppp_ip4_config (NMPPPManager *ppp_manager, - NMIP4Config *config, +ppp_new_config (NMPPPManager *ppp_manager, + int addr_family, + const NML3ConfigData *l3cd, + const NMUtilsIPv6IfaceId *iid, gpointer user_data) { + nm_auto_unref_l3cd_init NML3ConfigData *l3cd_modified = NULL; NMModem *self = NM_MODEM (user_data); - guint32 i, num; - guint32 bad_dns1 = htonl (0x0A0B0C0D); - guint32 good_dns1 = htonl (0x04020201); /* GTE nameserver */ - guint32 bad_dns2 = htonl (0x0A0B0C0E); - guint32 good_dns2 = htonl (0x04020202); /* GTE nameserver */ - gboolean dns_workaround = FALSE; - - /* Work around a PPP bug (#1732) which causes many mobile broadband - * providers to return 10.11.12.13 and 10.11.12.14 for the DNS servers. - * Apparently fixed in ppp-2.4.5 but we've had some reports that this is - * not the case. - * - * http://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=2e09ef6886bbf00bc5a9a641110f801e372ffde6 - * http://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=f8191bf07df374f119a07910a79217c7618f113e - */ + gboolean do_slaac = FALSE; - num = nm_ip4_config_get_num_nameservers (config); - if (num == 2) { - gboolean found1 = FALSE, found2 = FALSE; + nm_assert_addr_family (addr_family); - for (i = 0; i < num; i++) { - guint32 ns = nm_ip4_config_get_nameserver (config, i); - - if (ns == bad_dns1) - found1 = TRUE; - else if (ns == bad_dns2) - found2 = TRUE; + if (addr_family == AF_INET6) { + if (!l3cd) + do_slaac = TRUE; + else { + do_slaac = !!nm_l3_config_data_get_first_obj (l3cd, + NMP_OBJECT_TYPE_IP6_ADDRESS, + nmp_object_ip6_address_is_not_link_local); } + } else { - /* Be somewhat conservative about substitutions; the "bad" nameservers - * could actually be valid in some cases, so only substitute if ppp - * returns *only* the two bad nameservers. - */ - dns_workaround = (found1 && found2); - } - - if (!num || dns_workaround) { - _LOGW ("compensating for invalid PPP-provided nameservers"); - nm_ip4_config_reset_nameservers (config); - nm_ip4_config_add_nameserver (config, good_dns1); - nm_ip4_config_add_nameserver (config, good_dns2); + nm_assert (!iid); + iid = NULL; + + if (l3cd) { + const in_addr_t bad_dns1 = htonl (0x0A0B0C0D); + const in_addr_t good_dns1 = htonl (0x04020201); /* GTE nameserver */ + const in_addr_t bad_dns2 = htonl (0x0A0B0C0E); + const in_addr_t good_dns2 = htonl (0x04020202); /* GTE nameserver */ + gboolean dns_workaround = FALSE; + const in_addr_t *addrs; + guint num; + + /* Work around a PPP bug (#1732) which causes many mobile broadband + * providers to return 10.11.12.13 and 10.11.12.14 for the DNS servers. + * Apparently fixed in ppp-2.4.5 but we've had some reports that this is + * not the case. + * + * http://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=2e09ef6886bbf00bc5a9a641110f801e372ffde6 + * http://git.ozlabs.org/?p=ppp.git;a=commitdiff_plain;h=f8191bf07df374f119a07910a79217c7618f113e + */ + + addrs = nm_l3_config_data_get_nameservers (l3cd, AF_INET, &num); + if (num == 0) + dns_workaround = TRUE; + else if (num == 2) { + /* Be somewhat conservative about substitutions; the "bad" nameservers + * could actually be valid in some cases, so only substitute if ppp + * returns *only* the two bad nameservers. + */ + dns_workaround = (addrs[0] == bad_dns1 && addrs[1] == bad_dns2) + || (addrs[1] == bad_dns1 && addrs[0] == bad_dns2); + } else + dns_workaround = FALSE; + + if (dns_workaround) { + _LOGW ("compensating for invalid PPP-provided nameservers"); + l3cd_modified = nm_l3_config_data_new_clone (l3cd, -1); + nm_l3_config_data_clear_nameserver (l3cd_modified, AF_INET); + nm_l3_config_data_add_nameserver (l3cd_modified, AF_INET, &good_dns1); + nm_l3_config_data_add_nameserver (l3cd_modified, AF_INET, &good_dns2); + l3cd = nm_l3_config_data_seal (l3cd_modified); + } + } } - g_signal_emit (self, signals[IP4_CONFIG_RESULT], 0, config, NULL); -} - -static void -ppp_ip6_config (NMPPPManager *ppp_manager, - const NMUtilsIPv6IfaceId *iid, - NMIP6Config *config, - gpointer user_data) -{ - NMModem *self = NM_MODEM (user_data); - - NM_MODEM_GET_PRIVATE (self)->iid = *iid; - - nm_modem_emit_ip6_config_result (self, config, NULL); + nm_modem_emit_signal_new_config (self, addr_family, l3cd, do_slaac, iid, NULL); } static void @@ -715,11 +753,8 @@ ppp_stage3_ip_config_start (NMModem *self, g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IFINDEX_SET, G_CALLBACK (ppp_ifindex_set), self); - g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, - G_CALLBACK (ppp_ip4_config), - self); - g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_IP6_CONFIG, - G_CALLBACK (ppp_ip6_config), + g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_NEW_CONFIG, + G_CALLBACK (ppp_new_config), self); g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_SIGNAL_STATS, G_CALLBACK (ppp_stats), @@ -795,6 +830,8 @@ nm_modem_ip4_pre_commit (NMModem *modem, NMDevice *device, NMIP4Config *config) { + //XXX +#if 0 NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (modem); /* If the modem has an ethernet-type data interface (ie, not PPP and thus @@ -809,42 +846,11 @@ nm_modem_ip4_pre_commit (NMModem *modem, if (address->plen == 32) nm_platform_link_set_noarp (nm_device_get_platform (device), nm_device_get_ip_ifindex (device)); } +#endif } /*****************************************************************************/ -void -nm_modem_emit_ip6_config_result (NMModem *self, - NMIP6Config *config, - GError *error) -{ - NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self); - NMDedupMultiIter ipconf_iter; - const NMPlatformIP6Address *addr; - gboolean do_slaac = TRUE; - - if (error) { - g_signal_emit (self, signals[IP6_CONFIG_RESULT], 0, NULL, FALSE, error); - return; - } - - if (config) { - /* If the IPv6 configuration only included a Link-Local address, then - * we have to run SLAAC to get the full IPv6 configuration. - */ - nm_ip_config_iter_ip6_address_for_each (&ipconf_iter, config, &addr) { - if (IN6_IS_ADDR_LINKLOCAL (&addr->address)) { - if (!priv->iid.id) - priv->iid.id = ((guint64 *)(&addr->address.s6_addr))[1]; - } else - do_slaac = FALSE; - } - } - g_assert (config || do_slaac); - - g_signal_emit (self, signals[IP6_CONFIG_RESULT], 0, config, do_slaac, NULL); -} - static NMActStageReturn stage3_ip6_config_request (NMModem *self, NMDeviceStateReason *out_failure_reason) { @@ -1540,15 +1546,6 @@ nm_modem_owns_port (NMModem *self, const char *iface) priv->control_port); } -gboolean -nm_modem_get_iid (NMModem *self, NMUtilsIPv6IfaceId *out_iid) -{ - g_return_val_if_fail (NM_IS_MODEM (self), FALSE); - - *out_iid = NM_MODEM_GET_PRIVATE (self)->iid; - return TRUE; -} - /*****************************************************************************/ void @@ -1933,32 +1930,25 @@ nm_modem_class_init (NMModemClass *klass) 0, NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_UINT); - signals[IP4_CONFIG_RESULT] = - g_signal_new (NM_MODEM_IP4_CONFIG_RESULT, - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, NULL, NULL, NULL, - G_TYPE_NONE, 2, G_TYPE_OBJECT, G_TYPE_POINTER); - - /** - * NMModem::ip6-config-result: - * @modem: the #NMModem on which the signal is emitted - * @config: the #NMIP6Config to apply to the modem's data port - * @do_slaac: %TRUE if IPv6 SLAAC should be started - * @error: a #GError if any error occurred during IP configuration - * - * This signal is emitted when IPv6 configuration has completed or failed. - * If @error is set the configuration failed. If @config is set, then + /* + * This signal is emitted when IP configuration has completed or failed. + * If @error is set the configuration failed. If @l3cd is set, then * the details should be applied to the data port before any further - * configuration (like SLAAC) is done. @do_slaac indicates whether SLAAC - * should be started after applying @config to the data port. + * configuration (like SLAAC) is done. @do_slaac indicates whether SLAAC + * should be started after applying @l3cd to the data port. */ - signals[IP6_CONFIG_RESULT] = - g_signal_new (NM_MODEM_IP6_CONFIG_RESULT, + signals[NEW_CONFIG] = + g_signal_new (NM_MODEM_NEW_CONFIG, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, - G_TYPE_NONE, 3, G_TYPE_OBJECT, G_TYPE_BOOLEAN, G_TYPE_POINTER); + G_TYPE_NONE, + 3, + G_TYPE_INT, /* int addr_family */ + G_TYPE_POINTER, /* const NML3ConfigData *l3cd */ + G_TYPE_BOOLEAN, /* gboolean do_slaac */ + G_TYPE_POINTER, /* const NMUtilsIPv6IfaceId *iid */ + G_TYPE_POINTER); /* GError *error */ signals[PREPARE_RESULT] = g_signal_new (NM_MODEM_PREPARE_RESULT, diff --git a/src/devices/wwan/nm-modem.h b/src/devices/wwan/nm-modem.h index f2de990b80..828f4ce704 100644 --- a/src/devices/wwan/nm-modem.h +++ b/src/devices/wwan/nm-modem.h @@ -35,8 +35,7 @@ #define NM_MODEM_PPP_STATS "ppp-stats" #define NM_MODEM_PPP_FAILED "ppp-failed" #define NM_MODEM_PREPARE_RESULT "prepare-result" -#define NM_MODEM_IP4_CONFIG_RESULT "ip4-config-result" -#define NM_MODEM_IP6_CONFIG_RESULT "ip6-config-result" +#define NM_MODEM_NEW_CONFIG "new-config" #define NM_MODEM_AUTH_REQUESTED "auth-requested" #define NM_MODEM_AUTH_RESULT "auth-result" #define NM_MODEM_REMOVED "removed" @@ -165,7 +164,6 @@ const char *nm_modem_get_driver (NMModem *modem); const char *nm_modem_get_device_id (NMModem *modem); const char *nm_modem_get_sim_id (NMModem *modem); const char *nm_modem_get_sim_operator_id (NMModem *modem); -gboolean nm_modem_get_iid (NMModem *modem, NMUtilsIPv6IfaceId *out_iid); const char *nm_modem_get_operator_code (NMModem *modem); const char *nm_modem_get_apn (NMModem *modem); @@ -269,8 +267,12 @@ GArray *nm_modem_get_connection_ip_type (NMModem *self, GError **error); /* For subclasses */ -void nm_modem_emit_ip6_config_result (NMModem *self, - NMIP6Config *config, + +void nm_modem_emit_signal_new_config (NMModem *self, + int addr_family, + const NML3ConfigData *l3cd, + gboolean do_slaac, + const NMUtilsIPv6IfaceId *iid, GError *error); const char *nm_modem_ip_type_to_string (NMModemIPType ip_type); diff --git a/src/dhcp/nm-dhcp-client.c b/src/dhcp/nm-dhcp-client.c index b02ff93426..6639edea5c 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" @@ -441,20 +442,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) @@ -499,7 +503,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); } @@ -889,7 +893,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); @@ -926,19 +930,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 (); @@ -952,13 +956,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; @@ -1319,7 +1323,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 b6512d5a7d..0d62d5962f 100644 --- a/src/dhcp/nm-dhcp-client.h +++ b/src/dhcp/nm-dhcp-client.h @@ -8,8 +8,6 @@ #include "nm-setting-ip4-config.h" #include "nm-setting-ip6-config.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" #include "nm-dhcp-utils.h" #define NM_DHCP_TIMEOUT_DEFAULT ((guint32) 45) /* default DHCP timeout, in seconds */ @@ -191,7 +189,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-dhclient-utils.c b/src/dhcp/nm-dhcp-dhclient-utils.c index 6f208e96e1..feb5cc9600 100644 --- a/src/dhcp/nm-dhcp-dhclient-utils.c +++ b/src/dhcp/nm-dhcp-dhclient-utils.c @@ -14,7 +14,6 @@ #include "nm-glib-aux/nm-dedup-multi.h" #include "nm-dhcp-utils.h" -#include "nm-ip4-config.h" #include "nm-utils.h" #include "platform/nm-platform.h" #include "NetworkManagerUtils.h" diff --git a/src/dhcp/nm-dhcp-manager.c b/src/dhcp/nm-dhcp-manager.c index 5148d641f1..5c9a7ffaff 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-manager.h b/src/dhcp/nm-dhcp-manager.h index 1bb48ca060..6f8e04d740 100644 --- a/src/dhcp/nm-dhcp-manager.h +++ b/src/dhcp/nm-dhcp-manager.h @@ -8,7 +8,6 @@ #define __NETWORKMANAGER_DHCP_MANAGER_H__ #include "nm-dhcp-client.h" -#include "nm-ip4-config.h" #include "nm-dhcp-config.h" #define NM_TYPE_DHCP_MANAGER (nm_dhcp_manager_get_type ()) diff --git a/src/dhcp/nm-dhcp-nettools.c b/src/dhcp/nm-dhcp-nettools.c index e7ae502d87..412b9d83c0 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_address_list (NDhcp4ClientLease *lease, - NMIP4Config *ip4_config, + NML3ConfigData *l3cd, NMDhcpOptionDhcp4Options option, GHashTable *options) { @@ -499,13 +500,13 @@ lease_parse_address_list (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); break; case NM_DHCP_OPTION_DHCP4_NIS_SERVERS: - nm_ip4_config_add_nis_server (ip4_config, addr.s_addr); + nm_l3_config_data_add_nis_server (l3cd, addr.s_addr); break; case NM_DHCP_OPTION_DHCP4_NETBIOS_NAMESERVER: - nm_ip4_config_add_wins (ip4_config, addr.s_addr); + nm_l3_config_data_add_wins (l3cd, addr.s_addr); break; default: nm_assert_not_reached (); @@ -520,7 +521,7 @@ lease_parse_address_list (NDhcp4ClientLease *lease, static void lease_parse_routes (NDhcp4ClientLease *lease, - NMIP4Config *ip4_config, + NML3ConfigData *l3cd, GHashTable *options, guint32 route_table, guint32 route_metric) @@ -563,20 +564,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, @@ -614,16 +613,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, @@ -660,14 +658,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, @@ -678,7 +675,7 @@ lease_parse_routes (NDhcp4ClientLease *lease, static void lease_parse_mtu (NDhcp4ClientLease *lease, - NMIP4Config *ip4_config, + NML3ConfigData *l3cd, GHashTable *options) { uint16_t mtu; @@ -693,27 +690,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 @@ -770,7 +765,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; @@ -794,7 +789,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, @@ -833,7 +828,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; @@ -852,7 +847,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, @@ -905,7 +900,7 @@ lease_parse_wpad (NDhcp4ClientLease *lease, static void lease_parse_nis_domain (NDhcp4ClientLease *lease, - NMIP4Config *ip4_config, + NML3ConfigData *l3cd, GHashTable *options) { gs_free char *str_free = NULL; @@ -929,7 +924,7 @@ lease_parse_nis_domain (NDhcp4ClientLease *lease, _nm_dhcp_option_dhcp4_options, NM_DHCP_OPTION_DHCP4_NIS_DOMAIN, str); - nm_ip4_config_set_nis_domain (ip4_config, str); + nm_l3_config_data_set_nis_domain (l3cd, str); } static void @@ -962,7 +957,7 @@ lease_parse_private_options (NDhcp4ClientLease *lease, } } -static NMIP4Config * +static NML3ConfigData * lease_to_ip4_config (NMDedupMultiIndex *multi_idx, const char *iface, int ifindex, @@ -972,35 +967,38 @@ 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_address_list (lease, ip4_config, NM_DHCP_OPTION_DHCP4_DOMAIN_NAME_SERVER, 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_address_list (lease, l3cd, NM_DHCP_OPTION_DHCP4_DOMAIN_NAME_SERVER, 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); lease_parse_root_path (lease, options); lease_parse_wpad (lease, options); - lease_parse_nis_domain (lease, ip4_config, options); - lease_parse_address_list (lease, ip4_config, NM_DHCP_OPTION_DHCP4_NIS_SERVERS, options); - lease_parse_address_list (lease, ip4_config, NM_DHCP_OPTION_DHCP4_NETBIOS_NAMESERVER, options); + lease_parse_nis_domain (lease, l3cd, options); + lease_parse_address_list (lease, l3cd, NM_DHCP_OPTION_DHCP4_NIS_SERVERS, options); + lease_parse_address_list (lease, l3cd, NM_DHCP_OPTION_DHCP4_NETBIOS_NAMESERVER, options); 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); } /*****************************************************************************/ @@ -1037,22 +1035,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; @@ -1063,7 +1061,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); } @@ -1158,9 +1156,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 cd2a00c713..2bc123f972 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); } /*****************************************************************************/ @@ -481,7 +482,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)); - gs_unref_object NMIP4Config *ip4_config = NULL; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; gs_unref_hashtable GHashTable *options = NULL; sd_dhcp_lease *lease = 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); } @@ -757,7 +758,7 @@ ip4_start (NMDhcpClient *client, return TRUE; } -static NMIP6Config * +static NML3ConfigData * lease_to_ip6_config (NMDedupMultiIndex *multi_idx, const char *iface, int ifindex, @@ -767,7 +768,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; @@ -776,11 +777,14 @@ lease_to_ip6_config (NMDedupMultiIndex *multi_idx, char **domains; const char *s; nm_auto_free_gstring GString *str = NULL; + gboolean has_any_addresses = FALSE; int num, i; nm_assert (lease); - 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; @@ -796,19 +800,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, @@ -822,7 +830,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, @@ -835,7 +843,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, @@ -851,7 +859,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 @@ -860,7 +868,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 }; @@ -875,16 +883,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; @@ -892,7 +900,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-dhclient.c b/src/dhcp/tests/test-dhcp-dhclient.c index 29cfefc976..e8552eda65 100644 --- a/src/dhcp/tests/test-dhcp-dhclient.c +++ b/src/dhcp/tests/test-dhcp-dhclient.c @@ -15,7 +15,6 @@ #include "dhcp/nm-dhcp-dhclient-utils.h" #include "dhcp/nm-dhcp-utils.h" #include "nm-utils.h" -#include "nm-ip4-config.h" #include "platform/nm-platform.h" #include "nm-test-utils-core.h" diff --git a/src/dhcp/tests/test-dhcp-utils.c b/src/dhcp/tests/test-dhcp-utils.c index e601534eb2..63d1490a87 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_l3cd (&l3cd); 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/meson.build b/src/meson.build index 667a6a2ce2..1d0860bf04 100644 --- a/src/meson.build +++ b/src/meson.build @@ -75,7 +75,6 @@ libnetwork_manager_base = static_library( ) sources = files( - 'devices/nm-acd-manager.c', 'devices/nm-device-6lowpan.c', 'devices/nm-device-bond.c', 'devices/nm-device-bridge.c', diff --git a/src/nm-iface-helper.c b/src/nm-iface-helper.c index 5904e8fc0b..8a90cf5050 100644 --- a/src/nm-iface-helper.c +++ b/src/nm-iface-helper.c @@ -19,6 +19,8 @@ #include "nm-glib-aux/nm-c-list.h" #include "main-utils.h" +#include "nm-ip4-config.h" +#include "nm-ip6-config.h" #include "NetworkManagerUtils.h" #include "platform/nm-linux-platform.h" #include "platform/nm-platform-utils.h" @@ -93,7 +95,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 +104,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/ppp/nm-ppp-manager.c b/src/ppp/nm-ppp-manager.c index 751ec28b94..48bd01db0a 100644 --- a/src/ppp/nm-ppp-manager.c +++ b/src/ppp/nm-ppp-manager.c @@ -31,8 +31,7 @@ #include "platform/nm-platform.h" #include "nm-core-internal.h" #include "nm-act-request.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" +#include "nm-l3-config-data.h" #include "nm-dbus-object.h" #include "nm-pppd-plugin.h" @@ -60,8 +59,7 @@ GType nm_ppp_manager_get_type (void); enum { STATE_CHANGED, IFINDEX_SET, - IP4_CONFIG, - IP6_CONFIG, + NEW_CONFIG, STATS, LAST_SIGNAL @@ -130,6 +128,22 @@ static void _ppp_manager_stop_cancel (NMPPPManagerStopHandle *handle); /*****************************************************************************/ static void +_emit_signal_new_config (NMPPPManager *self, + int addr_family, + const NML3ConfigData *l3cd, + const NMUtilsIPv6IfaceId *iid) +{ + nm_assert (NM_IS_PPP_MANAGER (self)); + nm_assert_addr_family (addr_family); + nm_assert (NM_IS_L3_CONFIG_DATA (l3cd)); + nm_assert ((!!iid) == (addr_family == AF_INET)); + + nm_l3_config_data_seal (l3cd); + + g_signal_emit (self, signals[NEW_CONFIG], 0, addr_family, l3cd, iid); +} + +static void _ppp_manager_set_route_parameters (NMPPPManager *self, guint32 ip4_route_table, guint32 ip4_route_metric, @@ -504,7 +518,7 @@ impl_ppp_manager_set_ip4_config (NMDBusObject *obj, { NMPPPManager *self = NM_PPP_MANAGER (obj); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); - gs_unref_object NMIP4Config *config = NULL; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; NMPlatformIP4Address address; guint32 u32, mtu; GVariantIter *iter; @@ -519,17 +533,21 @@ impl_ppp_manager_set_ip4_config (NMDBusObject *obj, if (!set_ip_config_common (self, config_dict, &mtu)) goto out; - config = nm_ip4_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET), priv->ifindex); + l3cd = nm_l3_config_data_new (nm_platform_get_multi_idx (NM_PLATFORM_GET), priv->ifindex); - if (mtu) - nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_PPP); + nm_l3_config_data_set_source (l3cd, NM_IP_CONFIG_SOURCE_PPP); + nm_l3_config_data_set_mtu (l3cd, mtu); - memset (&address, 0, sizeof (address)); - address.plen = 32; + address = (NMPlatformIP4Address) { + .plen = 32, + }; if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_ADDRESS, "u", &u32)) address.address = u32; + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_PREFIX, "u", &u32)) + address.plen = u32; + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_GATEWAY, "u", &u32)) { const NMPlatformIP4Route r = { .ifindex = priv->ifindex, @@ -539,17 +557,16 @@ impl_ppp_manager_set_ip4_config (NMDBusObject *obj, .metric = priv->ip4_route_metric, }; - nm_ip4_config_add_route (config, &r, NULL); + nm_l3_config_data_add_route_4 (l3cd, &r); address.peer_address = u32; } else address.peer_address = address.address; - if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_PREFIX, "u", &u32)) - address.plen = u32; - - if (address.address && address.plen && address.plen <= 32) { + if ( address.address + && address.plen > 0 + && address.plen <= 32) { address.addr_source = NM_IP_CONFIG_SOURCE_PPP; - nm_ip4_config_add_address (config, &address); + nm_l3_config_data_add_address_4 (l3cd, &address); } else { _LOGE ("invalid IPv4 address received!"); goto out; @@ -557,18 +574,17 @@ impl_ppp_manager_set_ip4_config (NMDBusObject *obj, if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_DNS, "au", &iter)) { while (g_variant_iter_next (iter, "u", &u32)) - nm_ip4_config_add_nameserver (config, u32); + nm_l3_config_data_add_nameserver (l3cd, AF_INET, &u32); g_variant_iter_free (iter); } if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_WINS, "au", &iter)) { while (g_variant_iter_next (iter, "u", &u32)) - nm_ip4_config_add_wins (config, u32); + nm_l3_config_data_add_wins (l3cd, u32); g_variant_iter_free (iter); } - /* Push the IP4 config up to the device */ - g_signal_emit (self, signals[IP4_CONFIG], 0, config); + _emit_signal_new_config (self, AF_INET, l3cd, NULL); out: g_dbus_method_invocation_return_value (invocation, NULL); @@ -614,8 +630,8 @@ impl_ppp_manager_set_ip6_config (NMDBusObject *obj, { NMPPPManager *self = NM_PPP_MANAGER (obj); NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); - gs_unref_object NMIP6Config *config = NULL; - NMPlatformIP6Address addr; + nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL; + NMPlatformIP6Address address; struct in6_addr a; NMUtilsIPv6IfaceId iid = NM_UTILS_IPV6_IFACE_ID_INIT; gboolean has_peer = FALSE; @@ -630,10 +646,11 @@ impl_ppp_manager_set_ip6_config (NMDBusObject *obj, if (!set_ip_config_common (self, config_dict, NULL)) goto out; - config = nm_ip6_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET), priv->ifindex); + l3cd = nm_l3_config_data_new (nm_platform_get_multi_idx (NM_PLATFORM_GET), priv->ifindex); - memset (&addr, 0, sizeof (addr)); - addr.plen = 64; + address = (NMPlatformIP6Address) { + .plen = 64, + }; if (iid_value_to_ll6_addr (config_dict, NM_PPP_IP6_CONFIG_PEER_IID, &a, NULL)) { const NMPlatformIP6Route r = { @@ -644,18 +661,17 @@ impl_ppp_manager_set_ip6_config (NMDBusObject *obj, .metric = priv->ip6_route_metric, }; - nm_ip6_config_add_route (config, &r, NULL); - addr.peer_address = a; + nm_l3_config_data_add_route_6 (l3cd, &r); + address.peer_address = a; has_peer = TRUE; } - if (iid_value_to_ll6_addr (config_dict, NM_PPP_IP6_CONFIG_OUR_IID, &addr.address, &iid)) { + if (iid_value_to_ll6_addr (config_dict, NM_PPP_IP6_CONFIG_OUR_IID, &address.address, &iid)) { if (!has_peer) - addr.peer_address = addr.address; - nm_ip6_config_add_address (config, &addr); + address.peer_address = address.address; + nm_l3_config_data_add_address_6 (l3cd, &address); - /* Push the IPv6 config and interface identifier up to the device */ - g_signal_emit (self, signals[IP6_CONFIG], 0, &iid, config); + _emit_signal_new_config (self, AF_INET6, l3cd, &iid); } else _LOGE ("invalid IPv6 address received!"); @@ -1437,24 +1453,17 @@ nm_ppp_manager_class_init (NMPPPManagerClass *manager_class) G_TYPE_INT, G_TYPE_STRING); - signals[IP4_CONFIG] = - g_signal_new (NM_PPP_MANAGER_SIGNAL_IP4_CONFIG, - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - 0, - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_OBJECT); - - signals[IP6_CONFIG] = - g_signal_new (NM_PPP_MANAGER_SIGNAL_IP6_CONFIG, + signals[NEW_CONFIG] = + g_signal_new (NM_PPP_MANAGER_SIGNAL_NEW_CONFIG, G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, - G_TYPE_NONE, 2, - G_TYPE_POINTER, - G_TYPE_OBJECT); + G_TYPE_NONE, + 3, + G_TYPE_INT, /* addr_family */ + G_TYPE_POINTER, /* (const NML3ConfigData *) */ + G_TYPE_POINTER); /* (const NMUtilsIPv6IfaceId *) */ signals[STATS] = g_signal_new (NM_PPP_MANAGER_SIGNAL_STATS, @@ -1462,9 +1471,10 @@ nm_ppp_manager_class_init (NMPPPManagerClass *manager_class) G_SIGNAL_RUN_FIRST, 0, NULL, NULL, NULL, - G_TYPE_NONE, 2, - G_TYPE_UINT /*guint32 in_bytes*/, - G_TYPE_UINT /*guint32 out_bytes*/); + G_TYPE_NONE, + 2, + G_TYPE_UINT, /* guint32 in_bytes */ + G_TYPE_UINT); /* guint32 out_bytes */ } NMPPPOps ppp_ops = { diff --git a/src/ppp/nm-ppp-manager.h b/src/ppp/nm-ppp-manager.h index 8657367fa5..ac1affb480 100644 --- a/src/ppp/nm-ppp-manager.h +++ b/src/ppp/nm-ppp-manager.h @@ -11,8 +11,7 @@ #define NM_PPP_MANAGER_SIGNAL_STATE_CHANGED "state-changed" #define NM_PPP_MANAGER_SIGNAL_IFINDEX_SET "ifindex-set" -#define NM_PPP_MANAGER_SIGNAL_IP4_CONFIG "ip4-config" -#define NM_PPP_MANAGER_SIGNAL_IP6_CONFIG "ip6-config" +#define NM_PPP_MANAGER_SIGNAL_NEW_CONFIG "new-config" #define NM_PPP_MANAGER_SIGNAL_STATS "stats" typedef struct _NMPPPManager NMPPPManager; diff --git a/src/vpn/nm-vpn-connection.c b/src/vpn/nm-vpn-connection.c index e2cad32b99..23d86232e3 100644 --- a/src/vpn/nm-vpn-connection.c +++ b/src/vpn/nm-vpn-connection.c @@ -6,6 +6,10 @@ #include "nm-default.h" +//XXX +#define __NETWORKMANAGER_IP4_CONFIG_H__ +#define __NETWORKMANAGER_IP6_CONFIG_H__ + #include "nm-vpn-connection.h" #include <sys/socket.h> @@ -17,8 +21,6 @@ #include <linux/rtnetlink.h> #include "nm-proxy-config.h" -#include "nm-ip4-config.h" -#include "nm-ip6-config.h" #include "platform/nm-platform.h" #include "nm-active-connection.h" #include "NetworkManagerUtils.h" @@ -33,6 +35,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 */ @@ -101,7 +104,7 @@ typedef struct { NMNetns *netns; - GPtrArray *ip4_dev_route_blacklist; + NML3Cfg *l3cfg; GDBusProxy *proxy; GCancellable *cancellable; @@ -111,6 +114,14 @@ typedef struct { NMPacrunnerConfId *pacrunner_conf_id; gboolean has_ip4; NMIP4Config *ip4_config; + + union { + struct { + const NML3ConfigData *l3cd_6; + const NML3ConfigData *l3cd_4; + }; + const NML3ConfigData *l3cd_x[2]; + }; guint32 ip4_internal_gw; guint32 ip4_external_gw; gboolean has_ip6; @@ -675,8 +686,10 @@ device_state_changed (NMActiveConnection *active, */ } +//XXX +_nm_unused static void -add_ip4_vpn_gateway_route (NMIP4Config *config, +add_ip4_vpn_gateway_route (NML3ConfigData *l3cd, NMDevice *parent_device, in_addr_t vpn_gw, NMPlatform *platform) @@ -688,11 +701,11 @@ add_ip4_vpn_gateway_route (NMIP4Config *config, guint32 route_metric; nm_auto_nmpobj const NMPObject *route_resolved = NULL; - g_return_if_fail (NM_IS_IP4_CONFIG (config)); + nm_assert (NM_IS_L3_CONFIG_DATA (l3cd)); g_return_if_fail (NM_IS_DEVICE (parent_device)); g_return_if_fail (vpn_gw != 0); - ifindex = nm_ip4_config_get_ifindex (config); + ifindex = nm_l3_config_data_get_ifindex (l3cd); nm_assert (ifindex > 0); nm_assert (ifindex == nm_device_get_ip_ifindex (parent_device)); @@ -733,14 +746,15 @@ add_ip4_vpn_gateway_route (NMIP4Config *config, route_metric = nm_device_get_route_metric (parent_device, AF_INET); - memset (&route, 0, sizeof (route)); - route.ifindex = ifindex; - route.network = vpn_gw; - route.plen = 32; - route.gateway = parent_gw; - route.rt_source = NM_IP_CONFIG_SOURCE_VPN; - route.metric = route_metric; - nm_ip4_config_add_route (config, &route, NULL); + route = (NMPlatformIP4Route) { + .ifindex = ifindex, + .network = vpn_gw, + .plen = 32, + .gateway = parent_gw, + .rt_source = NM_IP_CONFIG_SOURCE_VPN, + .metric = route_metric, + }; + nm_l3_config_data_add_route_4 (l3cd, &route); if (parent_gw) { /* Ensure there's a route to the parent device's gateway through the @@ -748,17 +762,20 @@ add_ip4_vpn_gateway_route (NMIP4Config *config, * routes include a subnet that matches the parent device's subnet, * the parent device's gateway would get routed through the VPN and fail. */ - memset (&route, 0, sizeof (route)); - route.network = parent_gw; - route.plen = 32; - route.rt_source = NM_IP_CONFIG_SOURCE_VPN; - route.metric = route_metric; - nm_ip4_config_add_route (config, &route, NULL); + route = (NMPlatformIP4Route) { + .network = parent_gw, + .plen = 32, + .rt_source = NM_IP_CONFIG_SOURCE_VPN, + .metric = route_metric, + }; + nm_l3_config_data_add_route_4 (l3cd, &route); } } +//XXX +_nm_unused static void -add_ip6_vpn_gateway_route (NMIP6Config *config, +add_ip6_vpn_gateway_route (NML3ConfigData *l3cd, NMDevice *parent_device, const struct in6_addr *vpn_gw, NMPlatform *platform) @@ -770,11 +787,11 @@ add_ip6_vpn_gateway_route (NMIP6Config *config, guint32 route_metric; nm_auto_nmpobj const NMPObject *route_resolved = NULL; - g_return_if_fail (NM_IS_IP6_CONFIG (config)); + nm_assert (NM_IS_L3_CONFIG_DATA (l3cd)); g_return_if_fail (NM_IS_DEVICE (parent_device)); g_return_if_fail (vpn_gw != NULL); - ifindex = nm_ip6_config_get_ifindex (config); + ifindex = nm_l3_config_data_get_ifindex (l3cd); nm_assert (ifindex > 0); nm_assert (ifindex == nm_device_get_ip_ifindex (parent_device)); @@ -815,28 +832,30 @@ add_ip6_vpn_gateway_route (NMIP6Config *config, route_metric = nm_device_get_route_metric (parent_device, AF_INET6); - memset (&route, 0, sizeof (route)); - route.ifindex = ifindex; - route.network = *vpn_gw; - route.plen = 128; - if (parent_gw) - route.gateway = *parent_gw; - route.rt_source = NM_IP_CONFIG_SOURCE_VPN; - route.metric = route_metric; - nm_ip6_config_add_route (config, &route, NULL); + route = (NMPlatformIP6Route) { + .ifindex = ifindex, + .network = *vpn_gw, + .plen = 128, + .gateway = (parent_gw ? *parent_gw : in6addr_any), + .rt_source = NM_IP_CONFIG_SOURCE_VPN, + .metric = route_metric, + }; + nm_l3_config_data_add_route_6 (l3cd, &route); /* Ensure there's a route to the parent device's gateway through the * parent device, since if the VPN claims the default route and the VPN * routes include a subnet that matches the parent device's subnet, * the parent device's gateway would get routed through the VPN and fail. */ - if (parent_gw && !IN6_IS_ADDR_UNSPECIFIED (parent_gw)) { - memset (&route, 0, sizeof (route)); - route.network = *parent_gw; - route.plen = 128; - route.rt_source = NM_IP_CONFIG_SOURCE_VPN; - route.metric = route_metric; - nm_ip6_config_add_route (config, &route, NULL); + if ( parent_gw + && !IN6_IS_ADDR_UNSPECIFIED (parent_gw)) { + route = (NMPlatformIP6Route) { + .network = *parent_gw, + .plen = 128, + .rt_source = NM_IP_CONFIG_SOURCE_VPN, + .metric = route_metric, + }; + nm_l3_config_data_add_route_6 (l3cd, &route); } } @@ -977,12 +996,11 @@ static void print_vpn_config (NMVpnConnection *self) { NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); - const NMPlatformIP4Address *address4; - const NMPlatformIP6Address *address6; - char *dns_domain = NULL; - guint32 num, i; + const char *const*strv; + guint num; + guint i; char b1[NM_UTILS_INET_ADDRSTRLEN]; - char b2[NM_UTILS_INET_ADDRSTRLEN]; + char sbuf1[sizeof (_nm_utils_to_string_buffer)]; NMDedupMultiIter ipconf_iter; if (priv->ip4_external_gw) { @@ -995,75 +1013,50 @@ print_vpn_config (NMVpnConnection *self) _LOGI ("Data: Tunnel Device: %s%s%s", NM_PRINT_FMT_QUOTE_STRING (priv->ip_iface)); - if (priv->ip4_config) { - const NMPlatformIP4Route *route; - - _LOGI ("Data: IPv4 configuration:"); + for (i = 0; i < 2; i++) { + const gboolean IS_IPv4 = (i == 0); + const int addr_family = IS_IPv4 ? AF_INET : AF_INET6; + const NML3ConfigData *l3cd = priv->l3cd_x[IS_IPv4]; + const NMPObject *plobj; + const guint8 *p_addrs; - address4 = nm_ip4_config_get_first_address (priv->ip4_config); - nm_assert (address4); + if (!l3cd) { + _LOGI ("Data: No IPv%c configuration", nm_utils_addr_family_to_char (addr_family)); + continue; + } - if (priv->ip4_internal_gw) - _LOGI ("Data: Internal Gateway: %s", _nm_utils_inet4_ntop (priv->ip4_internal_gw, b1)); - _LOGI ("Data: Internal Address: %s", address4 ? _nm_utils_inet4_ntop (address4->address, b1) : "??"); - _LOGI ("Data: Internal Prefix: %d", address4 ? (int) address4->plen : -1); - _LOGI ("Data: Internal Point-to-Point Address: %s", _nm_utils_inet4_ntop (address4->peer_address, b1)); + _LOGI ("Data: IPv%c configuration:", nm_utils_addr_family_to_char (addr_family)); - nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, priv->ip4_config, &route) { - _LOGI ("Data: Static Route: %s/%d Next Hop: %s", - _nm_utils_inet4_ntop (route->network, b1), - route->plen, - _nm_utils_inet4_ntop (route->gateway, b2)); + nm_l3_config_data_iter_obj_for_each (&ipconf_iter, l3cd, &plobj, NMP_OBJECT_TYPE_IP_ADDRESS (IS_IPv4)) { + _LOGI ("Data: Internal Address: %s", + nmp_object_to_string (plobj, NMP_OBJECT_TO_STRING_PUBLIC, sbuf1, sizeof (sbuf1))); } - num = nm_ip4_config_get_num_nameservers (priv->ip4_config); - for (i = 0; i < num; i++) { - _LOGI ("Data: Internal DNS: %s", - _nm_utils_inet4_ntop (nm_ip4_config_get_nameserver (priv->ip4_config, i), b1)); + if (IS_IPv4) { + if (priv->ip4_internal_gw) + _LOGI ("Data: Internal Gateway: %s", _nm_utils_inet4_ntop (priv->ip4_internal_gw, b1)); + } else { + if (priv->ip6_internal_gw) + _LOGI ("Data: Internal Gateway: %s", _nm_utils_inet6_ntop (priv->ip6_internal_gw, b1)); } - if (nm_ip4_config_get_num_domains (priv->ip4_config) > 0) - dns_domain = (char *) nm_ip4_config_get_domain (priv->ip4_config, 0); - - _LOGI ("Data: DNS Domain: '%s'", dns_domain ?: "(none)"); - } else - _LOGI ("Data: No IPv4 configuration"); - - if (priv->ip6_config) { - const NMPlatformIP6Route *route; - - _LOGI ("Data: IPv6 configuration:"); - - address6 = nm_ip6_config_get_first_address (priv->ip6_config); - nm_assert (address6); - - if (priv->ip6_internal_gw) - _LOGI ("Data: Internal Gateway: %s", _nm_utils_inet6_ntop (priv->ip6_internal_gw, b1)); - _LOGI ("Data: Internal Address: %s", _nm_utils_inet6_ntop (&address6->address, b1)); - _LOGI ("Data: Internal Prefix: %d", address6->plen); - _LOGI ("Data: Internal Point-to-Point Address: %s", _nm_utils_inet6_ntop (&address6->peer_address, b1)); - - nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, priv->ip6_config, &route) { - _LOGI ("Data: Static Route: %s/%d Next Hop: %s", - _nm_utils_inet6_ntop (&route->network, b1), - route->plen, - _nm_utils_inet6_ntop (&route->gateway, b2)); + nm_l3_config_data_iter_obj_for_each (&ipconf_iter, l3cd, &plobj, NMP_OBJECT_TYPE_IP_ROUTE (IS_IPv4)) { + _LOGI ("Data: Static Route: %s", + nmp_object_to_string (plobj, NMP_OBJECT_TO_STRING_PUBLIC, sbuf1, sizeof (sbuf1))); } - num = nm_ip6_config_get_num_nameservers (priv->ip6_config); - for (i = 0; i < num; i++) { + p_addrs = nm_l3_config_data_get_nameservers (l3cd, addr_family, &num); + for (i = 0; i < num; i++, p_addrs += nm_utils_addr_family_to_size (addr_family)) { _LOGI ("Data: Internal DNS: %s", - _nm_utils_inet6_ntop (nm_ip6_config_get_nameserver (priv->ip6_config, i), b1)); + nm_utils_inet_ntop (addr_family, p_addrs, b1)); } - if (nm_ip6_config_get_num_domains (priv->ip6_config) > 0) - dns_domain = (char *) nm_ip6_config_get_domain (priv->ip6_config, 0); - - _LOGI ("Data: DNS Domain: '%s'", dns_domain ?: "(none)"); - } else - _LOGI ("Data: No IPv6 configuration"); + strv = nm_l3_config_data_get_domains (l3cd, addr_family, &num); + for (i = 0; i < num; i++) + _LOGI ("Data: DNS Domain: '%s'", strv[i]); + } - if (priv->banner && strlen (priv->banner)) { + if (!nm_str_is_empty (priv->banner)) { _LOGI ("Data: Login Banner:"); _LOGI ("Data: -----------------------------------------"); _LOGI ("Data: %s", priv->banner); @@ -1074,6 +1067,7 @@ print_vpn_config (NMVpnConnection *self) static void apply_parent_device_config (NMVpnConnection *self) { +#if 0 NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); NMDevice *parent_dev = nm_active_connection_get_device (NM_ACTIVE_CONNECTION (self)); int ifindex; @@ -1123,11 +1117,13 @@ apply_parent_device_config (NMVpnConnection *self) nm_device_replace_vpn6_config (parent_dev, priv->last_device_ip6_config, vpn6_parent_config); g_clear_object (&priv->last_device_ip6_config); priv->last_device_ip6_config = vpn6_parent_config; +#endif } static gboolean nm_vpn_connection_apply_config (NMVpnConnection *self) { +#if 0 NMVpnConnectionPrivate *priv = NM_VPN_CONNECTION_GET_PRIVATE (self); apply_parent_device_config (self); @@ -1166,6 +1162,7 @@ nm_vpn_connection_apply_config (NMVpnConnection *self) _LOGI ("VPN connection: (IP Config Get) complete"); if (priv->vpn_state < STATE_PRE_UP) _set_vpn_state (self, STATE_PRE_UP, NM_ACTIVE_CONNECTION_STATE_REASON_NONE, FALSE); +#endif return TRUE; } @@ -1266,26 +1263,24 @@ ip6_addr_from_variant (GVariant *v, struct in6_addr *addr) g_return_val_if_fail (v, FALSE); g_return_val_if_fail (addr, FALSE); + nm_assert (g_variant_is_of_type (v, G_VARIANT_TYPE ("ay"))); - if (g_variant_is_of_type (v, G_VARIANT_TYPE ("ay"))) { - bytes = g_variant_get_fixed_array (v, &len, sizeof (guint8)); - if (len == sizeof (struct in6_addr) && !IN6_IS_ADDR_UNSPECIFIED (bytes)) { - memcpy (addr, bytes, len); - return TRUE; - } + bytes = g_variant_get_fixed_array (v, &len, sizeof (guint8)); + if ( len == sizeof (struct in6_addr) + && !IN6_IS_ADDR_UNSPECIFIED (bytes)) { + memcpy (addr, bytes, len); + return TRUE; } return FALSE; } static struct in6_addr * -ip6_addr_dup_from_variant (GVariant *v) +ip6_addr_from_variant_dup (GVariant *v) { - struct in6_addr *addr; + struct in6_addr addr; - addr = g_malloc0 (sizeof (*addr)); - if (ip6_addr_from_variant (v, addr)) - return addr; - g_free (addr); + if (ip6_addr_from_variant (v, &addr)) + return nm_memdup (&addr, sizeof (addr)); return NULL; } @@ -1355,7 +1350,7 @@ process_generic_config (NMVpnConnection *self, GVariant *dict) if (g_variant_lookup (dict, NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY, "u", &u32)) { priv->ip4_external_gw = u32; } else if (g_variant_lookup (dict, NM_VPN_PLUGIN_CONFIG_EXT_GATEWAY, "@ay", &v)) { - priv->ip6_external_gw = ip6_addr_dup_from_variant (v); + priv->ip6_external_gw = ip6_addr_from_variant_dup (v); g_variant_unref (v); if (!priv->ip6_external_gw) { @@ -1465,12 +1460,12 @@ 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; NMSettingConnection *s_con; guint32 route_table; - NMIP4Config *config; GVariantIter *iter; const char *str; GVariant *v; @@ -1514,12 +1509,14 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict) if (ip_ifindex <= 0) g_return_if_reached (); - config = nm_ip4_config_new (nm_netns_get_multi_idx (priv->netns), - ip_ifindex); - nm_ip4_config_set_dns_priority (config, NM_DNS_PRIORITY_DEFAULT_VPN); + 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); + nm_l3_config_data_set_dns_priority (l3cd, AF_INET, NM_DNS_PRIORITY_DEFAULT_VPN); - memset (&address, 0, sizeof (address)); - address.plen = 24; + address = (NMPlatformIP4Address) { + .plen = 24, + }; /* Internal address of the VPN subnet's gateway */ if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_INT_GATEWAY, "u", &u32)) @@ -1536,25 +1533,26 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict) if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_PREFIX, "u", &u32)) address.plen = u32; - if (address.address && address.plen && address.plen <= 32) { + if ( address.address + && address.plen + && address.plen <= 32) { address.addr_source = NM_IP_CONFIG_SOURCE_VPN; - nm_ip4_config_add_address (config, &address); + nm_l3_config_data_add_address_4 (l3cd, &address); } else { _LOGW ("invalid IP4 config received!"); - g_object_unref (config); nm_vpn_connection_config_maybe_complete (self, FALSE); return; } if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_DNS, "au", &iter)) { while (g_variant_iter_next (iter, "u", &u32)) - nm_ip4_config_add_nameserver (config, u32); + nm_l3_config_data_add_nameserver (l3cd, AF_INET, &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)) - nm_ip4_config_add_wins (config, u32); + nm_l3_config_data_add_wins (l3cd, u32); g_variant_iter_free (iter); } @@ -1562,11 +1560,11 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict) mss = u32; if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_DOMAIN, "&s", &str)) - nm_ip4_config_add_domain (config, str); + nm_l3_config_data_add_domain (l3cd, AF_INET, str); if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_DOMAINS, "as", &iter)) { while (g_variant_iter_next (iter, "&s", &str)) - nm_ip4_config_add_domain (config, str); + nm_l3_config_data_add_domain (l3cd, AF_INET, str); g_variant_iter_free (iter); } @@ -1579,12 +1577,12 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict) /* ignore VPN routes */ } else if ( g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_PRESERVE_ROUTES, "b", &b) && b) { - if (priv->ip4_config) { - NMDedupMultiIter ipconf_iter; + if (priv->l3cd_4) { const NMPlatformIP4Route *route; + NMDedupMultiIter ipconf_iter; - nm_ip_config_iter_ip4_route_for_each (&ipconf_iter, priv->ip4_config, &route) - nm_ip4_config_add_route (config, route, NULL); + nm_l3_config_data_iter_ip4_route_for_each (&ipconf_iter, priv->l3cd_4, &route) + nm_l3_config_data_add_route_4 (l3cd, route); } } else if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP4_CONFIG_ROUTES, "aau", &iter)) { while (g_variant_iter_next (iter, "@au", &v)) { @@ -1620,7 +1618,7 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict) break; } - nm_ip4_config_add_route (config, &route, NULL); + nm_l3_config_data_add_route_4 (l3cd, &route); break; default: break; @@ -1634,12 +1632,14 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict) never_default = b; /* Merge in user overrides from the NMConnection's IPv4 setting */ - nm_ip4_config_merge_setting (config, - s_ip, - nm_setting_connection_get_mdns (s_con), - nm_setting_connection_get_llmnr (s_con), - route_table, - route_metric); + (void) s_con; + //XXX + //nm_ip4_config_merge_setting (config, + // s_ip, + // nm_setting_connection_get_mdns (s_con), + // nm_setting_connection_get_llmnr (s_con), + // route_table, + // route_metric); if ( !never_default && !nm_setting_ip_config_get_never_default (s_ip)) { @@ -1652,17 +1652,17 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict) .mss = mss, }; - nm_ip4_config_add_route (config, &r, NULL); + nm_l3_config_data_add_route_4 (l3cd, &r); } - nm_clear_pointer (&priv->ip4_dev_route_blacklist, g_ptr_array_unref); - - nm_ip4_config_add_dependent_routes (config, - route_table, - nm_vpn_connection_get_ip4_route_metric (self), - _is_device_vrf (self), - &priv->ip4_dev_route_blacklist); + nm_l3_config_data_add_dependent_routes (l3cd, + AF_INET, + route_table, + nm_vpn_connection_get_ip4_route_metric (self), + _is_device_vrf (self)); + //XXX +#if 0 if (priv->ip4_config) { nm_ip4_config_replace (priv->ip4_config, config, NULL); g_object_unref (config); @@ -1673,17 +1673,19 @@ nm_vpn_connection_ip4_config_get (NMVpnConnection *self, GVariant *dict) } nm_vpn_connection_config_maybe_complete (self, TRUE); +#endif } 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; + guint32 u32; + guint32 route_metric; NMSettingIPConfig *s_ip; guint32 route_table; - NMIP6Config *config; GVariantIter *iter; const char *str; GVariant *v; @@ -1714,17 +1716,19 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict) if (ip_ifindex <= 0) g_return_if_reached (); - config = nm_ip6_config_new (nm_netns_get_multi_idx (priv->netns), - ip_ifindex); - nm_ip6_config_set_dns_priority (config, NM_DNS_PRIORITY_DEFAULT_VPN); + 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); + nm_l3_config_data_set_dns_priority (l3cd, AF_INET6, NM_DNS_PRIORITY_DEFAULT_VPN); - memset (&address, 0, sizeof (address)); - address.plen = 128; + address = (NMPlatformIP6Address) { + .plen = 128, + }; /* Internal address of the VPN subnet's gateway */ nm_clear_g_free (&priv->ip6_internal_gw); if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP6_CONFIG_INT_GATEWAY, "@ay", &v)) { - priv->ip6_internal_gw = ip6_addr_dup_from_variant (v); + priv->ip6_internal_gw = ip6_addr_from_variant_dup (v); g_variant_unref (v); } @@ -1743,10 +1747,9 @@ 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_ip6_config_add_address (config, &address); + nm_l3_config_data_add_address_6 (l3cd, &address); } else { _LOGW ("invalid IP6 config received!"); - g_object_unref (config); nm_vpn_connection_config_maybe_complete (self, FALSE); return; } @@ -1756,7 +1759,7 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict) struct in6_addr dns; if (ip6_addr_from_variant (v, &dns)) - nm_ip6_config_add_nameserver (config, &dns); + nm_l3_config_data_add_nameserver (l3cd, AF_INET6, &dns); g_variant_unref (v); } g_variant_iter_free (iter); @@ -1766,11 +1769,11 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict) mss = u32; if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP6_CONFIG_DOMAIN, "&s", &str)) - nm_ip6_config_add_domain (config, str); + nm_l3_config_data_add_domain (l3cd, AF_INET6, str); if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP6_CONFIG_DOMAINS, "as", &iter)) { while (g_variant_iter_next (iter, "&s", &str)) - nm_ip6_config_add_domain (config, str); + nm_l3_config_data_add_domain (l3cd, AF_INET6, str); g_variant_iter_free (iter); } @@ -1782,33 +1785,38 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict) /* Ignore VPN routes */ } else if ( g_variant_lookup (dict, NM_VPN_PLUGIN_IP6_CONFIG_PRESERVE_ROUTES, "b", &b) && b) { - if (priv->ip6_config) { + if (priv->l3cd_6) { NMDedupMultiIter ipconf_iter; - const NMPlatformIP6Route *route; + const NMPObject *route; - nm_ip_config_iter_ip6_route_for_each (&ipconf_iter, priv->ip6_config, &route) - nm_ip6_config_add_route (config, route, NULL); + nm_l3_config_data_iter_obj_for_each (&ipconf_iter, priv->l3cd_6, &route, NMP_OBJECT_TYPE_IP6_ROUTE) + nm_l3_config_data_add_route (l3cd, AF_INET6, route, NULL); } } else if (g_variant_lookup (dict, NM_VPN_PLUGIN_IP6_CONFIG_ROUTES, "a(ayuayu)", &iter)) { - GVariant *dest, *next_hop; - guint32 prefix, metric; + GVariant *next_hop; + GVariant *dest; + guint32 prefix; + guint32 metric; while (g_variant_iter_next (iter, "(@ayu@ayu)", &dest, &prefix, &next_hop, &metric)) { + _nm_unused gs_unref_variant GVariant *nexT_hop_keep_alive = next_hop; + _nm_unused gs_unref_variant GVariant *dest_keep_alive = dest; NMPlatformIP6Route route; - memset (&route, 0, sizeof (route)); + if (prefix > 128 || prefix == 0) + continue; + + route = (NMPlatformIP6Route) { + .plen = prefix, + .table_coerced = nm_platform_route_table_coerce (route_table), + .metric = route_metric, + .rt_source = NM_IP_CONFIG_SOURCE_VPN, + }; if (!ip6_addr_from_variant (dest, &route.network)) - goto next; - - if (prefix > 128 || prefix == 0) - goto next; + continue; - route.plen = prefix; ip6_addr_from_variant (next_hop, &route.gateway); - route.table_coerced = nm_platform_route_table_coerce (route_table); - route.metric = route_metric; - route.rt_source = NM_IP_CONFIG_SOURCE_VPN; nm_utils_ip6_address_clear_host_address (&route.network, &route.network, route.plen); @@ -1820,14 +1828,10 @@ nm_vpn_connection_ip6_config_get (NMVpnConnection *self, GVariant *dict) * server, we want to use the NM created route instead of whatever * the server provides. */ - goto next; + continue; } - nm_ip6_config_add_route (config, &route, NULL); - -next: - g_variant_unref (dest); - g_variant_unref (next_hop); + nm_l3_config_data_add_route_6 (l3cd, &route); } g_variant_iter_free (iter); } @@ -1836,10 +1840,12 @@ next: never_default = b; /* Merge in user overrides from the NMConnection's IPv6 setting */ - nm_ip6_config_merge_setting (config, - s_ip, - route_table, - route_metric); + //XXX + (void) s_ip; + //nm_ip6_config_merge_setting (config, + // s_ip, + // route_table, + // route_metric); if ( !never_default && !nm_setting_ip_config_get_never_default (s_ip)) { @@ -1852,11 +1858,13 @@ next: .mss = mss, }; - nm_ip6_config_add_route (config, &r, NULL); + nm_l3_config_data_add_route_6 (l3cd, &r); } - nm_ip6_config_add_dependent_routes (config, route_table, route_metric, _is_device_vrf (self)); + nm_l3_config_data_add_dependent_routes (l3cd, AF_INET6, route_table, route_metric, _is_device_vrf (self)); + //XXX +#if 0 if (priv->ip6_config) { nm_ip6_config_replace (priv->ip6_config, config, NULL); g_object_unref (config); @@ -1865,6 +1873,7 @@ next: nm_dbus_object_export (NM_DBUS_OBJECT (config)); g_object_notify ((GObject *) self, NM_ACTIVE_CONNECTION_IP6_CONFIG); } +#endif nm_vpn_connection_config_maybe_complete (self, TRUE); } @@ -2791,8 +2800,6 @@ dispose (GObject *object) nm_clear_pointer (&priv->connect_hash, g_variant_unref); - nm_clear_pointer (&priv->ip4_dev_route_blacklist, g_ptr_array_unref); - nm_clear_g_source (&priv->connect_timeout); dispatcher_cleanup (self); diff --git a/tools/run-nm-test.sh b/tools/run-nm-test.sh index 4df3ab962f..58bd083f56 100755 --- a/tools/run-nm-test.sh +++ b/tools/run-nm-test.sh @@ -312,7 +312,6 @@ if [ $HAS_ERRORS -eq 0 ]; then case "$TEST_NAME" in 'test-config' | \ 'test-link-linux' | \ - 'test-acd' | \ 'test-service-providers' | \ 'test-remote-settings-client' | \ 'test-secret-agent' | \ |