From 40ca9fff30829ed2179fe5e5795d68651c71fad4 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Sat, 2 Mar 2019 18:34:09 +0100 Subject: device: merge IPv4 and IPv6 variant of nm_device_set_wwan_ip_config() --- src/devices/nm-device-private.h | 5 +++-- src/devices/nm-device.c | 32 +++++++++++++++++--------------- src/devices/wwan/nm-device-modem.c | 5 +++-- 3 files changed, 23 insertions(+), 19 deletions(-) diff --git a/src/devices/nm-device-private.h b/src/devices/nm-device-private.h index 54cc151983..9a9929692d 100644 --- a/src/devices/nm-device-private.h +++ b/src/devices/nm-device-private.h @@ -146,8 +146,9 @@ void nm_device_queue_recheck_available (NMDevice *device, NMDeviceStateReason available_reason, NMDeviceStateReason unavailable_reason); -void nm_device_set_wwan_ip4_config (NMDevice *device, NMIP4Config *config); -void nm_device_set_wwan_ip6_config (NMDevice *device, NMIP6Config *config); +void nm_device_set_wwan_ip_config (NMDevice *device, + int addr_family, + NMIPConfig *config); gboolean nm_device_hw_addr_is_explict (NMDevice *device); diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index cda047faec..f5bce0410b 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -12190,13 +12190,25 @@ nm_device_replace_vpn4_config (NMDevice *self, NMIP4Config *old, NMIP4Config *co } void -nm_device_set_wwan_ip4_config (NMDevice *self, NMIP4Config *config) +nm_device_set_wwan_ip_config (NMDevice *self, + int addr_family, + NMIPConfig *config) { - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); + NMDevicePrivate *priv; + const gboolean IS_IPv4 = (addr_family == AF_INET); - applied_config_init (&priv->wwan_ip_config_4, config); - if (!ip_config_merge_and_apply (self, AF_INET, TRUE)) - _LOGW (LOGD_IP4, "failed to set WWAN IPv4 configuration"); + 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->wwan_ip_config_x[IS_IPv4], config); + if (!ip_config_merge_and_apply (self, addr_family, TRUE)) { + _LOGW (LOGD_IP, "failed to set WWAN IPv%c configuration", + nm_utils_addr_family_to_char (addr_family)); + } } void @@ -12217,16 +12229,6 @@ nm_device_replace_vpn6_config (NMDevice *self, NMIP6Config *old, NMIP6Config *co _LOGW (LOGD_IP6, "failed to set VPN routes for device"); } -void -nm_device_set_wwan_ip6_config (NMDevice *self, NMIP6Config *config) -{ - NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); - - applied_config_init (&priv->wwan_ip_config_6, config); - if (!ip_config_merge_and_apply (self, AF_INET6, TRUE)) - _LOGW (LOGD_IP6, "failed to set WWAN IPv6 configuration"); -} - NMDhcp6Config * nm_device_get_dhcp6_config (NMDevice *self) { diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index 0fd2fab81d..36fb2e8b5c 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -23,6 +23,7 @@ #include "nm-device-modem.h" #include "nm-modem.h" +#include "nm-ip4-config.h" #include "devices/nm-device-private.h" #include "nm-rfkill-manager.h" #include "settings/nm-settings-connection.h" @@ -211,7 +212,7 @@ modem_ip4_config_result (NMModem *modem, AF_INET, NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); } else { - nm_device_set_wwan_ip4_config (device, config); + nm_device_set_wwan_ip_config (device, AF_INET, NM_IP_CONFIG_CAST (config)); nm_device_activate_schedule_ip_config_result (device, AF_INET, NULL); } } @@ -245,7 +246,7 @@ modem_ip6_config_result (NMModem *modem, nm_device_sysctl_ip_conf_set (device, AF_INET6, "disable_ipv6", "0"); if (config) - nm_device_set_wwan_ip6_config (device, config); + nm_device_set_wwan_ip_config (device, AF_INET6, NM_IP_CONFIG_CAST (config)); if (do_slaac == FALSE) { if (got_config) -- cgit v1.2.1