From 66585dc1afa8de340cd1b00578bb4ba852125ccf Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Jan 2018 15:55:58 +0100 Subject: [PATCH 01/16] wwan: free ppp_iface in NMModem's finalize() --- src/devices/wwan/nm-modem.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 10baa424af..a1089e3b83 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -1665,6 +1665,7 @@ finalize (GObject *object) g_free (priv->driver); g_free (priv->control_port); g_free (priv->data_port); + g_free (priv->ppp_iface); g_free (priv->device_id); g_free (priv->sim_id); g_free (priv->sim_operator_id); From 19f24574dc253cf287ec1aea632ac1a1d919dbbb Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Jan 2018 15:58:40 +0100 Subject: [PATCH 02/16] wwan: cleanup handling ppp_iface in NMModem --- src/devices/wwan/nm-modem.c | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index a1089e3b83..d87cf6c1d2 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -1119,8 +1119,7 @@ deactivate_cleanup (NMModem *self, NMDevice *device) priv->ip4_method = NM_MODEM_IP_METHOD_UNKNOWN; priv->ip6_method = NM_MODEM_IP_METHOD_UNKNOWN; - g_free (priv->ppp_iface); - priv->ppp_iface = NULL; + nm_clear_g_free (&priv->ppp_iface); } /*****************************************************************************/ @@ -1374,14 +1373,17 @@ nm_modem_get_control_port (NMModem *self) const char * nm_modem_get_data_port (NMModem *self) { + NMModemPrivate *priv; + g_return_val_if_fail (NM_IS_MODEM (self), NULL); + priv = NM_MODEM_GET_PRIVATE (self); + /* The ppp_iface takes precedence over the data interface when PPP is used, * since data_iface is the TTY over which PPP is run, and that TTY can't * do IP. The caller really wants the thing that's doing IP. */ - return NM_MODEM_GET_PRIVATE (self)->ppp_iface ? - NM_MODEM_GET_PRIVATE (self)->ppp_iface : NM_MODEM_GET_PRIVATE (self)->data_port; + return priv->ppp_iface ?: priv->data_port; } gboolean @@ -1394,15 +1396,10 @@ nm_modem_owns_port (NMModem *self, const char *iface) if (NM_MODEM_GET_CLASS (self)->owns_port) return NM_MODEM_GET_CLASS (self)->owns_port (self, iface); - /* Fall back to data/control ports */ - if (priv->ppp_iface && (strcmp (priv->ppp_iface, iface) == 0)) - return TRUE; - if (priv->data_port && (strcmp (priv->data_port, iface) == 0)) - return TRUE; - if (priv->control_port && (strcmp (priv->control_port, iface) == 0)) - return TRUE; - - return FALSE; + return NM_IN_STRSET (iface, + priv->ppp_iface, + priv->data_port, + priv->control_port); } gboolean From bc3aebbab8e857827e732d156d6684aef4179945 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Jan 2018 17:26:58 +0100 Subject: [PATCH 03/16] wwan: disconnect signals from ppp-manager before clearing instance --- src/devices/wwan/nm-device-modem.c | 5 +++-- src/devices/wwan/nm-modem.c | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index b79d145d1f..ccf6e17da2 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -743,9 +743,10 @@ dispose (GObject *object) { NMDeviceModemPrivate *priv = NM_DEVICE_MODEM_GET_PRIVATE ((NMDeviceModem *) object); - if (priv->modem) + if (priv->modem) { g_signal_handlers_disconnect_by_data (priv->modem, NM_DEVICE_MODEM (object)); - g_clear_object (&priv->modem); + g_clear_object (&priv->modem); + } G_OBJECT_CLASS (nm_device_modem_parent_class)->dispose (object); } diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index d87cf6c1d2..5de461e5d8 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -1097,7 +1097,10 @@ deactivate_cleanup (NMModem *self, NMDevice *device) priv->in_bytes = priv->out_bytes = 0; - g_clear_object (&priv->ppp_manager); + if (priv->ppp_manager) { + g_signal_handlers_disconnect_by_data (priv->ppp_manager, self); + g_clear_object (&priv->ppp_manager); + } if (device) { g_return_if_fail (NM_IS_DEVICE (device)); From 41e80a02b25391eb1c11047ef2755ddad014bc47 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Jan 2018 16:00:24 +0100 Subject: [PATCH 04/16] wwan: handle missing data_port in ppp_stage3_ip_config_start() of NMModem It's not at all clear, that the data_port is set at this point. Guard against it, and avoid the assertion later. --- src/devices/wwan/nm-modem.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 5de461e5d8..7adaca798b 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -557,6 +557,8 @@ port_speed_is_zero (const char *port) struct termios options; nm_auto_close int fd = -1; + nm_assert (port); + fd = open (port, O_RDWR | O_NONBLOCK | O_NOCTTY | O_CLOEXEC); if (fd < 0) return FALSE; @@ -597,6 +599,12 @@ ppp_stage3_ip_config_start (NMModem *self, return NM_ACT_STAGE_RETURN_FAILURE; } + if (!priv->data_port) { + _LOGE ("error starting PPP (no data port)"); + NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_PPP_START_FAILED); + return NM_ACT_STAGE_RETURN_FAILURE; + } + /* Check if ModemManager requested a specific IP timeout to be used. If 0 reported, * use the default one (30s) */ if (priv->mm_ip_timeout > 0) { @@ -628,9 +636,7 @@ ppp_stage3_ip_config_start (NMModem *self, ip_timeout, baud_override, &error)) { _LOGE ("error starting PPP: %s", error->message); g_error_free (error); - g_clear_object (&priv->ppp_manager); - NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_PPP_START_FAILED); return NM_ACT_STAGE_RETURN_FAILURE; } From 352d063009cdf4bfbff0064c66c63fc48e876340 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Jan 2018 17:32:35 +0100 Subject: [PATCH 05/16] wwan/trivial: rename internal variable ppp_iface to ip_iface This is really the name of the networking device. Whether it is created by ppp is not that important here. Rename. --- src/devices/wwan/nm-modem.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 7adaca798b..98208fe449 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -79,7 +79,7 @@ typedef struct _NMModemPrivate { char *driver; char *control_port; char *data_port; - char *ppp_iface; + char *ip_iface; NMModemIPMethod ip4_method; NMModemIPMethod ip6_method; NMUtilsIPv6IfaceId iid; @@ -1128,7 +1128,7 @@ deactivate_cleanup (NMModem *self, NMDevice *device) priv->ip4_method = NM_MODEM_IP_METHOD_UNKNOWN; priv->ip6_method = NM_MODEM_IP_METHOD_UNKNOWN; - nm_clear_g_free (&priv->ppp_iface); + nm_clear_g_free (&priv->ip_iface); } /*****************************************************************************/ @@ -1388,11 +1388,11 @@ nm_modem_get_data_port (NMModem *self) priv = NM_MODEM_GET_PRIVATE (self); - /* The ppp_iface takes precedence over the data interface when PPP is used, + /* The ip_iface takes precedence over the data interface when PPP is used, * since data_iface is the TTY over which PPP is run, and that TTY can't * do IP. The caller really wants the thing that's doing IP. */ - return priv->ppp_iface ?: priv->data_port; + return priv->ip_iface ?: priv->data_port; } gboolean @@ -1406,7 +1406,7 @@ nm_modem_owns_port (NMModem *self, const char *iface) return NM_MODEM_GET_CLASS (self)->owns_port (self, iface); return NM_IN_STRSET (iface, - priv->ppp_iface, + priv->ip_iface, priv->data_port, priv->control_port); } @@ -1671,7 +1671,7 @@ finalize (GObject *object) g_free (priv->driver); g_free (priv->control_port); g_free (priv->data_port); - g_free (priv->ppp_iface); + g_free (priv->ip_iface); g_free (priv->device_id); g_free (priv->sim_id); g_free (priv->sim_operator_id); From 79980536b98b6319f0c3bd9598aada51768c1a3e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 11 Jan 2018 11:15:35 +0100 Subject: [PATCH 06/16] platform: add nm_platform_process_events_ensure_link() function --- src/platform/nm-platform.c | 39 ++++++++++++++++++++++++++++++++++++++ src/platform/nm-platform.h | 4 ++++ 2 files changed, 43 insertions(+) diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index 2c12359cfc..6f483fa654 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -353,6 +353,45 @@ nm_platform_process_events (NMPlatform *self) klass->process_events (self); } +const NMPlatformLink * +nm_platform_process_events_ensure_link (NMPlatform *self, + int ifindex, + const char *ifname) +{ + const NMPObject *obj; + gboolean refreshed = FALSE; + + g_return_val_if_fail (NM_IS_PLATFORM (self), NULL); + + if (ifindex <= 0 && !ifname) + return NULL; + + /* we look into the cache, whether a link for given ifindex/ifname + * exits. If not, we poll the netlink socket, maybe the event + * with the link is waiting. + * + * Then we try again to find the object. + * + * If the link is already cached the first time, we avoid polling + * the netlink socket. */ +again: + obj = nmp_cache_lookup_link_full (nm_platform_get_cache (self), + ifindex, + ifname, + FALSE, /* also invisible. We don't care here whether udev is ready */ + NM_LINK_TYPE_NONE, + NULL, NULL); + if (obj) + return NMP_OBJECT_CAST_LINK (obj); + if (!refreshed) { + refreshed = TRUE; + nm_platform_process_events (self); + goto again; + } + + return NULL; +} + /*****************************************************************************/ /** diff --git a/src/platform/nm-platform.h b/src/platform/nm-platform.h index a545485183..53b2975bf5 100644 --- a/src/platform/nm-platform.h +++ b/src/platform/nm-platform.h @@ -1106,6 +1106,10 @@ const char *nm_platform_link_get_type_name (NMPlatform *self, int ifindex); gboolean nm_platform_link_refresh (NMPlatform *self, int ifindex); void nm_platform_process_events (NMPlatform *self); +const NMPlatformLink *nm_platform_process_events_ensure_link (NMPlatform *self, + int ifindex, + const char *ifname); + gboolean nm_platform_link_set_up (NMPlatform *self, int ifindex, gboolean *out_no_firmware); gboolean nm_platform_link_set_down (NMPlatform *self, int ifindex); gboolean nm_platform_link_set_arp (NMPlatform *self, int ifindex); From ab4578302d6968fe420db0951c5291c65c631e51 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Jan 2018 16:33:13 +0100 Subject: [PATCH 07/16] device: refactor nm_device_set_ip_ifindex() and set_ip_iface() - don't even bother to look into the platform cache, but use if_indextoname() / if_nametoindex(). In most cases, we obtained the ifindex/ifname not from the platform cache in the first place. Hence, there is a race, where the interface might not exist. However, try to process events of the platform cache, hoping that the cache contains an interface for the given ifindex/ifname. - let set_ip_ifindex() and set_ip_iface() both return a boolean value to indicate whether a ip-interface is set or not. That is, whether we have a positive ip_ifindex. That seems more interesting information, then to return whether anything changed. - as before, set_ip_ifindex() can only clear an ifindex/ifname, or error out without doing anything. That is different from set_ip_iface(), which will also set an ifname if no ifindex can be resolved. That is curreently ugly, because then ip-ifindex and ip-iface don't agree. That shall be improved in the future by: - trying to set an interface that cannot be resolved shall lead to a disconnect in any case. - we shall make less use of the ip-iface and rely more on the ifindex. --- src/devices/nm-device.c | 150 ++++++++++++----------------- src/devices/wwan/nm-device-modem.c | 6 +- 2 files changed, 66 insertions(+), 90 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index ecdf7c2008..084c3f7ae4 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1282,126 +1282,102 @@ nm_device_get_ip_ifindex (const NMDevice *self) return priv->ip_iface ? priv->ip_ifindex : priv->ifindex; } -gboolean -nm_device_set_ip_ifindex (NMDevice *self, int ifindex) +static void +_set_ip_ifindex (NMDevice *self, + int ifindex, + const char *ifname) { - NMDevicePrivate *priv; + NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self); NMPlatform *platform; - const char *name = NULL; + gboolean eq_name; - g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); + /* we can set only the ifname without ifindex (to indicate that this + * is an ip-interface, but lookup for the ifindex failed. + * But we cannot just set ifindex > 0 without an ifname. */ + nm_assert (ifindex <= 0 || ifname); - priv = NM_DEVICE_GET_PRIVATE (self); - platform = nm_device_get_platform (self); + /* normalize ifindex */ + if (ifindex < 0) + ifindex = 0; - if (ifindex > 0) { - const NMPlatformLink *plink; + eq_name = nm_streq0 (priv->ip_iface, ifname); - plink = nm_platform_link_get (platform, ifindex); - if (!plink) { - nm_platform_process_events (platform); - plink = nm_platform_link_get (NM_PLATFORM_GET, ifindex); - } - if (!plink) { - _LOGW (LOGD_DEVICE, "ip-ifindex: ifindex %d not found", ifindex); - return FALSE; - } - name = plink->name; - } else - g_return_val_if_fail (ifindex == 0, FALSE); + if ( eq_name + && priv->ip_ifindex == ifindex) + return; - if (priv->ip_ifindex == ifindex) - return TRUE; + _LOGD (LOGD_DEVICE, "ip-ifindex: update ip-interface to %s%s%s, ifindex %d", + NM_PRINT_FMT_QUOTE_STRING (ifname), + ifindex); - _LOGD (LOGD_DEVICE, "ip-ifindex: update ifindex to %d", ifindex); priv->ip_ifindex = ifindex; - if (!nm_streq0 (priv->ip_iface, name)) { - _LOGD (LOGD_DEVICE, "ip-ifindex: update ip-iface to %s%s%s", - NM_PRINT_FMT_QUOTED (name, "\"", name, "\"", "NULL")); - priv->ip_iface = g_strdup (name); + if (!eq_name) { + g_free (priv->ip_iface); + priv->ip_iface = g_strdup (ifname); _notify (self, PROP_IP_IFACE); } if (priv->ip_ifindex > 0) { - if (nm_platform_check_kernel_support (nm_device_get_platform (self), - NM_PLATFORM_KERNEL_SUPPORT_USER_IPV6LL)) - nm_platform_link_set_user_ipv6ll_enabled (nm_device_get_platform (self), priv->ip_ifindex, TRUE); + platform = nm_device_get_platform (self); - if (!nm_platform_link_is_up (nm_device_get_platform (self), priv->ip_ifindex)) - nm_platform_link_set_up (nm_device_get_platform (self), priv->ip_ifindex, NULL); + nm_platform_process_events_ensure_link (platform, + priv->ip_ifindex, + priv->ip_iface); + + if (nm_platform_check_kernel_support (platform, + NM_PLATFORM_KERNEL_SUPPORT_USER_IPV6LL)) + nm_platform_link_set_user_ipv6ll_enabled (platform, priv->ip_ifindex, TRUE); + + if (!nm_platform_link_is_up (platform, priv->ip_ifindex)) + nm_platform_link_set_up (platform, priv->ip_ifindex, NULL); } /* We don't care about any saved values from the old iface */ g_hash_table_remove_all (priv->ip6_saved_properties); +} - return TRUE; +gboolean +nm_device_set_ip_ifindex (NMDevice *self, int ifindex) +{ + char ifname_buf[IFNAMSIZ]; + const char *ifname = NULL; + + g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); + + if (ifindex > 0) { + ifname = nm_platform_if_indextoname (nm_device_get_platform (self), ifindex, ifname_buf); + if (!ifname) { + _LOGW (LOGD_DEVICE, "ip-ifindex: ifindex %d not found", ifindex); + return FALSE; + } + } + + _set_ip_ifindex (self, ifindex, ifname); + return ifindex > 0; } /** * nm_device_set_ip_iface: * @self: the #NMDevice - * @iface: the new IP interface name + * @ifname: the new IP interface name * * Updates the IP interface name and possibly the ifindex. * - * Returns: %TRUE if the anything (name or ifindex) changed, %FALSE if nothing - * changed. + * Returns: %TRUE if an interface with name @ifname exists, + * and %FALSE, if @ifname is %NULL or no such interface exists. */ gboolean -nm_device_set_ip_iface (NMDevice *self, const char *iface) +nm_device_set_ip_iface (NMDevice *self, const char *ifname) { - NMDevicePrivate *priv; - int ifindex; + int ifindex = 0; g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); - priv = NM_DEVICE_GET_PRIVATE (self); - if (nm_streq0 (iface, priv->ip_iface)) { - if (!iface) - return FALSE; - ifindex = nm_platform_if_nametoindex (nm_device_get_platform (self), iface); - if ( ifindex <= 0 - || priv->ip_ifindex == ifindex) - return FALSE; + if (ifname) + ifindex = nm_platform_if_nametoindex (nm_device_get_platform (self), ifname); - priv->ip_ifindex = ifindex; - _LOGD (LOGD_DEVICE, "ip-ifname: update ifindex for ifname '%s': %d", iface, priv->ip_ifindex); - } else { - g_free (priv->ip_iface); - priv->ip_iface = g_strdup (iface); - - if (iface) { - /* The @iface name is not in sync with the platform cache. - * So, there is no point asking the platform cache to resolve - * the ifindex. Instead, we can only hope that the interface - * with this name still exists and we resolve the ifindex - * anew. - */ - priv->ip_ifindex = nm_platform_if_nametoindex (nm_device_get_platform (self), iface); - if (priv->ip_ifindex > 0) - _LOGD (LOGD_DEVICE, "ip-ifname: set ifname '%s', ifindex %d", iface, priv->ip_ifindex); - else - _LOGW (LOGD_DEVICE, "ip-ifname: set ifname '%s', unknown ifindex", iface); - } else { - priv->ip_ifindex = 0; - _LOGD (LOGD_DEVICE, "ip-ifname: clear ifname"); - } - } - - if (priv->ip_ifindex > 0) { - if (nm_platform_check_kernel_support (nm_device_get_platform (self), - NM_PLATFORM_KERNEL_SUPPORT_USER_IPV6LL)) - nm_platform_link_set_user_ipv6ll_enabled (nm_device_get_platform (self), priv->ip_ifindex, TRUE); - - if (!nm_platform_link_is_up (nm_device_get_platform (self), priv->ip_ifindex)) - nm_platform_link_set_up (nm_device_get_platform (self), priv->ip_ifindex, NULL); - } - - /* We don't care about any saved values from the old iface */ - g_hash_table_remove_all (priv->ip6_saved_properties); - - _notify (self, PROP_IP_IFACE); - return TRUE; + _set_ip_ifindex (self, ifindex, ifname); + return ifindex > 0; } static gboolean @@ -12941,7 +12917,7 @@ _cleanup_generic_post (NMDevice *self, CleanupType cleanup_type) * those are identified by ip_iface, not by iface (which might be a tty * or ATM device). */ - nm_device_set_ip_iface (self, NULL); + _set_ip_ifindex (self, 0, NULL); } /* diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index ccf6e17da2..cec9e5327b 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -263,17 +263,17 @@ static void data_port_changed_cb (NMModem *modem, GParamSpec *pspec, gpointer user_data) { NMDevice *self = NM_DEVICE (user_data); - gboolean changed; + gboolean has_ifindex; /* We set the IP iface in the device as soon as we know it, so that we * properly ifup it if needed */ - changed = nm_device_set_ip_iface (self, nm_modem_get_data_port (modem)); + has_ifindex = nm_device_set_ip_iface (self, nm_modem_get_data_port (modem)); /* Disable IPv6 immediately on the interface since NM handles IPv6 * internally, and leaving it enabled could allow the kernel's IPv6 * RA handling code to run before NM is ready. */ - if (changed) + if (has_ifindex) nm_device_ipv6_sysctl_set (self, "disable_ipv6", "1"); } From 4fbea56b54be94e6adc776bd4daf4b2ac574890e Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Jan 2018 16:29:26 +0100 Subject: [PATCH 08/16] wwan: add modem:ip-ifindex property Will be used later to replace ip-iface. --- src/devices/wwan/nm-modem.c | 53 +++++++++++++++++++++++++++++++++++-- src/devices/wwan/nm-modem.h | 2 ++ 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 98208fe449..d55936c38d 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -45,6 +45,7 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMModem, PROP_CONTROL_PORT, PROP_DATA_PORT, + PROP_IP_IFINDEX, PROP_PATH, PROP_UID, PROP_DRIVER, @@ -80,6 +81,7 @@ typedef struct _NMModemPrivate { char *control_port; char *data_port; char *ip_iface; + int ip_ifindex; NMModemIPMethod ip4_method; NMModemIPMethod ip6_method; NMUtilsIPv6IfaceId iid; @@ -152,6 +154,10 @@ _nmlog_prefix (char *prefix, NMModem *self) _NM_UTILS_MACRO_REST (__VA_ARGS__)); \ } G_STMT_END +/*****************************************************************************/ + +static void _set_ip_ifindex (NMModem *self, int ifindex); + /*****************************************************************************/ /* State/enabled/connected */ @@ -458,6 +464,8 @@ ppp_ifindex_set (NMPPPManager *ppp_manager, NMModem *self = NM_MODEM (user_data); NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self); + nm_assert (ifindex >= 0); + /* Notify about the new data port to use. * * @iface might be %NULL. */ @@ -466,6 +474,7 @@ ppp_ifindex_set (NMPPPManager *ppp_manager, priv->data_port = g_strdup (iface); _notify (self, PROP_DATA_PORT); } + _set_ip_ifindex (self, ifindex); } static void @@ -1128,6 +1137,7 @@ deactivate_cleanup (NMModem *self, NMDevice *device) priv->ip4_method = NM_MODEM_IP_METHOD_UNKNOWN; priv->ip6_method = NM_MODEM_IP_METHOD_UNKNOWN; + _set_ip_ifindex (self, -1); nm_clear_g_free (&priv->ip_iface); } @@ -1395,6 +1405,34 @@ nm_modem_get_data_port (NMModem *self) return priv->ip_iface ?: priv->data_port; } +int +nm_modem_get_ip_ifindex (NMModem *self) +{ + NMModemPrivate *priv; + + g_return_val_if_fail (NM_IS_MODEM (self), 0); + + priv = NM_MODEM_GET_PRIVATE (self); + + /* internally we track an unset ip_ifindex as -1. + * For the caller of nm_modem_get_ip_ifindex(), this + * shall be zero too. */ + return priv->ip_ifindex != -1 ? priv->ip_ifindex : 0; +} + +static void +_set_ip_ifindex (NMModem *self, int ifindex) +{ + NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self); + + nm_assert (ifindex >= -1); + + if (priv->ip_ifindex != ifindex) { + priv->ip_ifindex = ifindex; + _notify (self, PROP_IP_IFINDEX); + } +} + gboolean nm_modem_owns_port (NMModem *self, const char *iface) { @@ -1508,7 +1546,8 @@ static void get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { - NMModemPrivate *priv = NM_MODEM_GET_PRIVATE ((NMModem *) object); + NMModem *self = NM_MODEM (object); + NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self); switch (prop_id) { case PROP_PATH: @@ -1521,7 +1560,10 @@ get_property (GObject *object, guint prop_id, g_value_set_string (value, priv->control_port); break; case PROP_DATA_PORT: - g_value_set_string (value, nm_modem_get_data_port (NM_MODEM (object))); + g_value_set_string (value, nm_modem_get_data_port (self)); + break; + case PROP_IP_IFINDEX: + g_value_set_int (value, nm_modem_get_ip_ifindex (self)); break; case PROP_UID: g_value_set_string (value, priv->uid); @@ -1631,6 +1673,7 @@ nm_modem_init (NMModem *self) self->_priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_MODEM, NMModemPrivate); priv = self->_priv; + priv->ip_ifindex = -1; priv->ip4_route_table = RT_TABLE_MAIN; priv->ip4_route_metric = 700; priv->ip6_route_table = RT_TABLE_MAIN; @@ -1726,6 +1769,12 @@ nm_modem_class_init (NMModemClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS); + obj_properties[PROP_IP_IFINDEX] = + g_param_spec_int (NM_MODEM_IP_IFINDEX, "", "", + 0, G_MAXINT, 0, + G_PARAM_READABLE | + G_PARAM_STATIC_STRINGS); + obj_properties[PROP_IP4_METHOD] = g_param_spec_uint (NM_MODEM_IP4_METHOD, "", "", NM_MODEM_IP_METHOD_UNKNOWN, diff --git a/src/devices/wwan/nm-modem.h b/src/devices/wwan/nm-modem.h index 9546e4a12e..39b85d0a42 100644 --- a/src/devices/wwan/nm-modem.h +++ b/src/devices/wwan/nm-modem.h @@ -38,6 +38,7 @@ #define NM_MODEM_DRIVER "driver" #define NM_MODEM_CONTROL_PORT "control-port" #define NM_MODEM_DATA_PORT "data-port" +#define NM_MODEM_IP_IFINDEX "ip-ifindex" #define NM_MODEM_IP4_METHOD "ip4-method" #define NM_MODEM_IP6_METHOD "ip6-method" #define NM_MODEM_IP_TIMEOUT "ip-timeout" @@ -168,6 +169,7 @@ const char *nm_modem_get_path (NMModem *modem); const char *nm_modem_get_uid (NMModem *modem); const char *nm_modem_get_control_port (NMModem *modem); const char *nm_modem_get_data_port (NMModem *modem); +int nm_modem_get_ip_ifindex (NMModem *modem); 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); From 8209e42106c48e30e8dea0e7e1ea367493cac6cc Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 10 Jan 2018 17:36:15 +0100 Subject: [PATCH 09/16] wwan: notify change of modem:data-port when clearing ip-iface data-port returns ip-iface, if set. Clearing it, most likely causes the property to change. Emit a notification. --- src/devices/wwan/nm-modem.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index d55936c38d..0237c3a751 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -1138,7 +1138,8 @@ deactivate_cleanup (NMModem *self, NMDevice *device) priv->ip6_method = NM_MODEM_IP_METHOD_UNKNOWN; _set_ip_ifindex (self, -1); - nm_clear_g_free (&priv->ip_iface); + if (nm_clear_g_free (&priv->ip_iface)) + _notify (self, PROP_DATA_PORT); } /*****************************************************************************/ From bfe38c1bf348ea459e5efac9af1c80c052c58ccd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 11 Jan 2018 09:22:03 +0100 Subject: [PATCH 10/16] wwan: make NM_MODEM_DATA_PORT not a construct property The property was never set at construct time. Don't make it a construct property. --- src/devices/wwan/nm-device-modem.c | 34 ++++++++++++-------------- src/devices/wwan/nm-modem-broadband.c | 35 +++++++++++++-------------- src/devices/wwan/nm-modem.c | 4 +-- 3 files changed, 34 insertions(+), 39 deletions(-) diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index cec9e5327b..1ef385d49e 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -629,11 +629,7 @@ set_modem (NMDeviceModem *self, NMModem *modem) g_signal_connect (modem, NM_MODEM_STATE_CHANGED, G_CALLBACK (modem_state_cb), self); g_signal_connect (modem, NM_MODEM_REMOVED, G_CALLBACK (modem_removed_cb), self); - /* In the old ModemManager the data port is known from the very beginning; - * while in the new ModemManager the data port is set afterwards when the bearer gets - * created */ g_signal_connect (modem, "notify::" NM_MODEM_DATA_PORT, G_CALLBACK (data_port_changed_cb), self); - g_signal_connect (modem, "notify::" NM_MODEM_DEVICE_ID, G_CALLBACK (ids_changed_cb), self); g_signal_connect (modem, "notify::" NM_MODEM_SIM_ID, G_CALLBACK (ids_changed_cb), self); g_signal_connect (modem, "notify::" NM_MODEM_SIM_OPERATOR_ID, G_CALLBACK (ids_changed_cb), self); @@ -706,9 +702,9 @@ nm_device_modem_init (NMDeviceModem *self) NMDevice * nm_device_modem_new (NMModem *modem) { + NMDevice *self; NMDeviceModemCapabilities caps = NM_DEVICE_MODEM_CAPABILITY_NONE; NMDeviceModemCapabilities current_caps = NM_DEVICE_MODEM_CAPABILITY_NONE; - NMDevice *device; const char *data_port; g_return_val_if_fail (NM_IS_MODEM (modem), NULL); @@ -716,26 +712,26 @@ nm_device_modem_new (NMModem *modem) /* Load capabilities */ nm_modem_get_capabilities (modem, &caps, ¤t_caps); - device = (NMDevice *) g_object_new (NM_TYPE_DEVICE_MODEM, - NM_DEVICE_UDI, nm_modem_get_path (modem), - NM_DEVICE_IFACE, nm_modem_get_uid (modem), - NM_DEVICE_DRIVER, nm_modem_get_driver (modem), - NM_DEVICE_TYPE_DESC, "Broadband", - NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_MODEM, - NM_DEVICE_RFKILL_TYPE, RFKILL_TYPE_WWAN, - NM_DEVICE_MODEM_MODEM, modem, - NM_DEVICE_MODEM_CAPABILITIES, caps, - NM_DEVICE_MODEM_CURRENT_CAPABILITIES, current_caps, - NULL); + self = g_object_new (NM_TYPE_DEVICE_MODEM, + NM_DEVICE_UDI, nm_modem_get_path (modem), + NM_DEVICE_IFACE, nm_modem_get_uid (modem), + NM_DEVICE_DRIVER, nm_modem_get_driver (modem), + NM_DEVICE_TYPE_DESC, "Broadband", + NM_DEVICE_DEVICE_TYPE, NM_DEVICE_TYPE_MODEM, + NM_DEVICE_RFKILL_TYPE, RFKILL_TYPE_WWAN, + NM_DEVICE_MODEM_MODEM, modem, + NM_DEVICE_MODEM_CAPABILITIES, caps, + NM_DEVICE_MODEM_CURRENT_CAPABILITIES, current_caps, + NULL); /* If the data port is known, set it as the IP interface immediately */ data_port = nm_modem_get_data_port (modem); if (data_port) { - nm_device_set_ip_iface (device, data_port); - nm_device_ipv6_sysctl_set (device, "disable_ipv6", "1"); + nm_device_set_ip_iface (self, data_port); + nm_device_ipv6_sysctl_set (self, "disable_ipv6", "1"); } - return device; + return self; } static void diff --git a/src/devices/wwan/nm-modem-broadband.c b/src/devices/wwan/nm-modem-broadband.c index dc0ce303ca..fcff57b399 100644 --- a/src/devices/wwan/nm-modem-broadband.c +++ b/src/devices/wwan/nm-modem-broadband.c @@ -1409,35 +1409,34 @@ nm_modem_broadband_init (NMModemBroadband *self) NMModem * nm_modem_broadband_new (GObject *object, GError **error) { - NMModem *modem; MMObject *modem_object; MMModem *modem_iface; - gchar *drivers; + const char *const*drivers; + gs_free char *driver = NULL; g_return_val_if_fail (MM_IS_OBJECT (object), NULL); modem_object = MM_OBJECT (object); /* Ensure we have the 'Modem' interface and the primary port at least */ modem_iface = mm_object_peek_modem (modem_object); - g_return_val_if_fail (!!modem_iface, NULL); - g_return_val_if_fail (!!mm_modem_get_primary_port (modem_iface), NULL); + g_return_val_if_fail (modem_iface, NULL); + g_return_val_if_fail (mm_modem_get_primary_port (modem_iface), NULL); /* Build a single string with all drivers listed */ - drivers = g_strjoinv (", ", (gchar **)mm_modem_get_drivers (modem_iface)); + drivers = mm_modem_get_drivers (modem_iface); + if (drivers) + driver = g_strjoinv (", ", (char **) drivers); - modem = g_object_new (NM_TYPE_MODEM_BROADBAND, - NM_MODEM_PATH, mm_object_get_path (modem_object), - NM_MODEM_UID, mm_modem_get_primary_port (modem_iface), - NM_MODEM_CONTROL_PORT, mm_modem_get_primary_port (modem_iface), - NM_MODEM_DATA_PORT, NULL, /* We don't know it until bearer created */ - NM_MODEM_IP_TYPES, mm_ip_family_to_nm (mm_modem_get_supported_ip_families (modem_iface)), - NM_MODEM_STATE, (int) mm_state_to_nm (mm_modem_get_state (modem_iface)), - NM_MODEM_DEVICE_ID, mm_modem_get_device_identifier (modem_iface), - NM_MODEM_BROADBAND_MODEM, modem_object, - NM_MODEM_DRIVER, drivers, - NULL); - g_free (drivers); - return modem; + return g_object_new (NM_TYPE_MODEM_BROADBAND, + NM_MODEM_PATH, mm_object_get_path (modem_object), + NM_MODEM_UID, mm_modem_get_primary_port (modem_iface), + NM_MODEM_CONTROL_PORT, mm_modem_get_primary_port (modem_iface), + NM_MODEM_IP_TYPES, mm_ip_family_to_nm (mm_modem_get_supported_ip_families (modem_iface)), + NM_MODEM_STATE, (int) mm_state_to_nm (mm_modem_get_state (modem_iface)), + NM_MODEM_DEVICE_ID, mm_modem_get_device_identifier (modem_iface), + NM_MODEM_BROADBAND_MODEM, modem_object, + NM_MODEM_DRIVER, driver, + NULL); } static void diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 0237c3a751..491334d202 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -1690,7 +1690,7 @@ constructed (GObject *object) priv = NM_MODEM_GET_PRIVATE (NM_MODEM (object)); - g_return_if_fail (priv->data_port || priv->control_port); + g_return_if_fail (priv->control_port); } /*****************************************************************************/ @@ -1767,7 +1767,7 @@ nm_modem_class_init (NMModemClass *klass) obj_properties[PROP_DATA_PORT] = g_param_spec_string (NM_MODEM_DATA_PORT, "", "", NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS); obj_properties[PROP_IP_IFINDEX] = From 0ef23b139d95d455343ad1ca19c984c98dd7dc39 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 12 Jan 2018 10:09:52 +0100 Subject: [PATCH 11/16] device: don't set NMDeviceModem's ip-iface right after constuction nm_device_modem_new() is only called with a newly created NMModemBroadband or NMModemOfono instance. See the callers - NMModemManager:handle_new_modem() - NMWwanFactory:modem_added_cb() - NMDeviceModem:nm_device_modem_new() Hence, at that point, the modem cannot yet have a data-port or ip-iface set, because that is only obtained later. --- src/devices/wwan/nm-device-modem.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index 1ef385d49e..86f1864946 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -702,17 +702,15 @@ nm_device_modem_init (NMDeviceModem *self) NMDevice * nm_device_modem_new (NMModem *modem) { - NMDevice *self; NMDeviceModemCapabilities caps = NM_DEVICE_MODEM_CAPABILITY_NONE; NMDeviceModemCapabilities current_caps = NM_DEVICE_MODEM_CAPABILITY_NONE; - const char *data_port; g_return_val_if_fail (NM_IS_MODEM (modem), NULL); /* Load capabilities */ nm_modem_get_capabilities (modem, &caps, ¤t_caps); - self = g_object_new (NM_TYPE_DEVICE_MODEM, + return g_object_new (NM_TYPE_DEVICE_MODEM, NM_DEVICE_UDI, nm_modem_get_path (modem), NM_DEVICE_IFACE, nm_modem_get_uid (modem), NM_DEVICE_DRIVER, nm_modem_get_driver (modem), @@ -723,15 +721,6 @@ nm_device_modem_new (NMModem *modem) NM_DEVICE_MODEM_CAPABILITIES, caps, NM_DEVICE_MODEM_CURRENT_CAPABILITIES, current_caps, NULL); - - /* If the data port is known, set it as the IP interface immediately */ - data_port = nm_modem_get_data_port (modem); - if (data_port) { - nm_device_set_ip_iface (self, data_port); - nm_device_ipv6_sysctl_set (self, "disable_ipv6", "1"); - } - - return self; } static void From a169d689babd350b1c48e7397ffbf23447849b22 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 11 Jan 2018 09:44:28 +0100 Subject: [PATCH 12/16] wwan: avoid dangling pointer for error variable in connect_ready() --- src/devices/wwan/nm-modem-broadband.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/devices/wwan/nm-modem-broadband.c b/src/devices/wwan/nm-modem-broadband.c index fcff57b399..dd3328f867 100644 --- a/src/devices/wwan/nm-modem-broadband.c +++ b/src/devices/wwan/nm-modem-broadband.c @@ -385,9 +385,10 @@ connect_ready (MMModemSimple *simple_iface, g_dbus_error_strip_remote_error (error); ctx->first_error = error; } else - g_error_free (error); + g_clear_error (&error); - if (ctx->ip_type_tries == 0 && g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_RETRY)) { + if ( ctx->ip_type_tries == 0 + && g_error_matches (error, MM_CORE_ERROR, MM_CORE_ERROR_RETRY)) { /* Try one more time */ ctx->ip_type_tries++; } else { From 2ea8e1029fc3a4f51e240ea4b90a74f5031a608b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 11 Jan 2018 11:15:40 +0100 Subject: [PATCH 13/16] bluetooth: fail activation when setting unknown ip-iface --- src/devices/bluetooth/nm-device-bt.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c index 977c1e1ae6..c61736d3c7 100644 --- a/src/devices/bluetooth/nm-device-bt.c +++ b/src/devices/bluetooth/nm-device-bt.c @@ -753,7 +753,7 @@ bluez_connect_cb (GObject *object, GAsyncResult *res, void *user_data) { - NMDeviceBt *self = NM_DEVICE_BT (user_data); + gs_unref_object NMDeviceBt *self = NM_DEVICE_BT (user_data); NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (self); GError *error = NULL; const char *device; @@ -761,6 +761,9 @@ bluez_connect_cb (GObject *object, device = nm_bluez_device_connect_finish (NM_BLUEZ_DEVICE (object), res, &error); + if (!nm_device_is_activating (NM_DEVICE (self))) + return; + if (!device) { _LOGW (LOGD_BT, "Error connecting with bluez: %s", error->message); g_clear_error (&error); @@ -768,7 +771,6 @@ bluez_connect_cb (GObject *object, nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_BT_FAILED); - g_object_unref (self); return; } @@ -776,7 +778,13 @@ bluez_connect_cb (GObject *object, g_free (priv->rfcomm_iface); priv->rfcomm_iface = g_strdup (device); } else if (priv->bt_type == NM_BT_CAPABILITY_NAP) { - nm_device_set_ip_iface (NM_DEVICE (self), device); + if (!nm_device_set_ip_iface (NM_DEVICE (self), device)) { + _LOGW (LOGD_BT, "Error connecting with bluez: cannot find device %s", device); + nm_device_state_changed (NM_DEVICE (self), + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_BT_FAILED); + return; + } } _LOGD (LOGD_BT, "connect request successful"); @@ -784,7 +792,6 @@ bluez_connect_cb (GObject *object, /* Stage 3 gets scheduled when Bluez says we're connected */ priv->have_iface = TRUE; check_connect_continue (self); - g_object_unref (self); } static void From c7b3586b9db49fed8926d746ec24e3d21b542f42 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 11 Jan 2018 09:47:30 +0100 Subject: [PATCH 14/16] wwan: rework setting modem's data-port Depending on the bearer's configuration method, the data-port is either a networking interface, or an tty for ppp. Let's treat them strictily separate. Also, rework how NM_MODEM_DATA_PORT was used in both contexts. Instead, use the that we actually care about. Also, when nm_device_set_ip_ifindex() fails, fail activation right away. Also, we early try to resolve the network interface's name to an ifindex. If that fails, the device is already gone and we fail early. --- src/devices/bluetooth/nm-device-bt.c | 38 ++--- src/devices/wwan/libnm-wwan.ver | 1 + src/devices/wwan/nm-device-modem.c | 23 +-- src/devices/wwan/nm-modem-broadband.c | 19 ++- src/devices/wwan/nm-modem-ofono.c | 30 ++-- src/devices/wwan/nm-modem.c | 197 +++++++++++++++----------- src/devices/wwan/nm-modem.h | 12 +- src/devices/wwan/nm-wwan-factory.c | 9 +- 8 files changed, 186 insertions(+), 143 deletions(-) diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c index c61736d3c7..c039a158b8 100644 --- a/src/devices/bluetooth/nm-device-bt.c +++ b/src/devices/bluetooth/nm-device-bt.c @@ -540,11 +540,16 @@ modem_ip4_config_result (NMModem *modem, } static void -data_port_changed_cb (NMModem *modem, GParamSpec *pspec, gpointer user_data) +ip_ifindex_changed_cb (NMModem *modem, GParamSpec *pspec, gpointer user_data) { - NMDevice *self = NM_DEVICE (user_data); + NMDevice *device = NM_DEVICE (user_data); - nm_device_set_ip_iface (self, nm_modem_get_data_port (modem)); + if (!nm_device_set_ip_ifindex (device, + nm_modem_get_ip_ifindex (modem))) { + nm_device_state_changed (device, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); + } } static gboolean @@ -640,29 +645,26 @@ component_added (NMDevice *device, GObject *component) NMDeviceBt *self = NM_DEVICE_BT (device); NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (self); NMModem *modem; - const gchar *modem_data_port; - const gchar *modem_control_port; - char *base; NMDeviceState state; NMDeviceStateReason failure_reason = NM_DEVICE_STATE_REASON_NONE; - if (!component || !NM_IS_MODEM (component)) + if ( !component + || !NM_IS_MODEM (component)) return FALSE; + modem = NM_MODEM (component); - - modem_data_port = nm_modem_get_data_port (modem); - modem_control_port = nm_modem_get_control_port (modem); - g_return_val_if_fail (modem_data_port != NULL || modem_control_port != NULL, FALSE); - if (!priv->rfcomm_iface) return FALSE; - base = g_path_get_basename (priv->rfcomm_iface); - if (g_strcmp0 (base, modem_data_port) && g_strcmp0 (base, modem_control_port)) { - g_free (base); - return FALSE; + { + gs_free char *base = NULL; + + base = g_path_get_basename (priv->rfcomm_iface); + if (!NM_IN_STRSET (base, + nm_modem_get_control_port (modem), + nm_modem_get_data_port (modem))) + return FALSE; } - g_free (base); /* Got the modem */ nm_clear_g_source (&priv->timeout_id); @@ -696,7 +698,7 @@ component_added (NMDevice *device, GObject *component) g_signal_connect (modem, NM_MODEM_STATE_CHANGED, G_CALLBACK (modem_state_cb), self); g_signal_connect (modem, NM_MODEM_REMOVED, G_CALLBACK (modem_removed_cb), self); - g_signal_connect (modem, "notify::" NM_MODEM_DATA_PORT, G_CALLBACK (data_port_changed_cb), self); + g_signal_connect (modem, "notify::" NM_MODEM_IP_IFINDEX, G_CALLBACK (ip_ifindex_changed_cb), self); /* Kick off the modem connection */ if (!modem_stage1 (self, modem, &failure_reason)) diff --git a/src/devices/wwan/libnm-wwan.ver b/src/devices/wwan/libnm-wwan.ver index 6efcb03fa7..d30a175ce7 100644 --- a/src/devices/wwan/libnm-wwan.ver +++ b/src/devices/wwan/libnm-wwan.ver @@ -15,6 +15,7 @@ global: nm_modem_get_driver; nm_modem_get_iid; nm_modem_get_path; + nm_modem_get_ip_ifindex; nm_modem_get_secrets; nm_modem_get_state; nm_modem_get_type; diff --git a/src/devices/wwan/nm-device-modem.c b/src/devices/wwan/nm-device-modem.c index 86f1864946..7aa2fd9315 100644 --- a/src/devices/wwan/nm-device-modem.c +++ b/src/devices/wwan/nm-device-modem.c @@ -260,21 +260,26 @@ modem_ip6_config_result (NMModem *modem, } static void -data_port_changed_cb (NMModem *modem, GParamSpec *pspec, gpointer user_data) +ip_ifindex_changed_cb (NMModem *modem, GParamSpec *pspec, gpointer user_data) { - NMDevice *self = NM_DEVICE (user_data); - gboolean has_ifindex; + NMDevice *device = NM_DEVICE (user_data); - /* We set the IP iface in the device as soon as we know it, so that we - * properly ifup it if needed */ - has_ifindex = nm_device_set_ip_iface (self, nm_modem_get_data_port (modem)); + if (!nm_device_is_activating (device)) + return; + + if (!nm_device_set_ip_ifindex (device, + nm_modem_get_ip_ifindex (modem))) { + nm_device_state_changed (device, + NM_DEVICE_STATE_FAILED, + NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE); + return; + } /* Disable IPv6 immediately on the interface since NM handles IPv6 * internally, and leaving it enabled could allow the kernel's IPv6 * RA handling code to run before NM is ready. */ - if (has_ifindex) - nm_device_ipv6_sysctl_set (self, "disable_ipv6", "1"); + nm_device_ipv6_sysctl_set (device, "disable_ipv6", "1"); } static void @@ -629,7 +634,7 @@ set_modem (NMDeviceModem *self, NMModem *modem) g_signal_connect (modem, NM_MODEM_STATE_CHANGED, G_CALLBACK (modem_state_cb), self); g_signal_connect (modem, NM_MODEM_REMOVED, G_CALLBACK (modem_removed_cb), self); - g_signal_connect (modem, "notify::" NM_MODEM_DATA_PORT, G_CALLBACK (data_port_changed_cb), self); + g_signal_connect (modem, "notify::" NM_MODEM_IP_IFINDEX, G_CALLBACK (ip_ifindex_changed_cb), self); g_signal_connect (modem, "notify::" NM_MODEM_DEVICE_ID, G_CALLBACK (ids_changed_cb), self); g_signal_connect (modem, "notify::" NM_MODEM_SIM_ID, G_CALLBACK (ids_changed_cb), self); g_signal_connect (modem, "notify::" NM_MODEM_SIM_OPERATOR_ID, G_CALLBACK (ids_changed_cb), self); diff --git a/src/devices/wwan/nm-modem-broadband.c b/src/devices/wwan/nm-modem-broadband.c index dd3328f867..683d6ed84f 100644 --- a/src/devices/wwan/nm-modem-broadband.c +++ b/src/devices/wwan/nm-modem-broadband.c @@ -411,21 +411,20 @@ connect_ready (MMModemSimple *simple_iface, if (self->_priv.ipv6_config) ip6_method = get_bearer_ip_method (self->_priv.ipv6_config); - if (ip4_method == NM_MODEM_IP_METHOD_UNKNOWN && - ip6_method == NM_MODEM_IP_METHOD_UNKNOWN) { - _LOGW ("failed to connect modem: invalid bearer IP configuration"); + if (!nm_modem_set_data_port (NM_MODEM (self), + NM_PLATFORM_GET, + mm_bearer_get_interface (self->_priv.bearer), + ip4_method, + ip6_method, + mm_bearer_get_ip_timeout (self->_priv.bearer), + &error)) { + _LOGW ("failed to connect modem: %s", error->message); + g_error_free (error); nm_modem_emit_prepare_result (NM_MODEM (self), FALSE, NM_DEVICE_STATE_REASON_CONFIG_FAILED); connect_context_clear (self); return; } - g_object_set (self, - NM_MODEM_DATA_PORT, mm_bearer_get_interface (self->_priv.bearer), - NM_MODEM_IP4_METHOD, ip4_method, - NM_MODEM_IP6_METHOD, ip6_method, - NM_MODEM_IP_TIMEOUT, mm_bearer_get_ip_timeout (self->_priv.bearer), - NULL); - ctx->step++; connect_context_step (self); } diff --git a/src/devices/wwan/nm-modem-ofono.c b/src/devices/wwan/nm-modem-ofono.c index 811c3afb27..a1c6aef256 100644 --- a/src/devices/wwan/nm-modem-ofono.c +++ b/src/devices/wwan/nm-modem-ofono.c @@ -836,6 +836,7 @@ context_property_changed (GDBusProxy *proxy, guint32 address_network, gateway_network; guint32 ip4_route_table, ip4_route_metric; int ifindex; + GError *error = NULL; _LOGD ("PropertyChanged: %s", property); @@ -860,27 +861,26 @@ context_property_changed (GDBusProxy *proxy, _LOGW ("Settings 'Interface' missing"); goto out; } - if (!interface || !interface[0]) { - _LOGW ("Settings 'Interface'; empty"); - goto out; - } - - ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, interface); - if (ifindex <= 0) { - _LOGW ("Interface \"%s\" not found", interface); - goto out; - } _LOGD ("Interface: %s", interface); - g_object_set (self, - NM_MODEM_DATA_PORT, interface, - NM_MODEM_IP4_METHOD, NM_MODEM_IP_METHOD_STATIC, - NULL); + if (!nm_modem_set_data_port (NM_MODEM (self), + NM_PLATFORM_GET, + interface, + NM_MODEM_IP_METHOD_STATIC, + NM_MODEM_IP_METHOD_UNKNOWN, + 0, + &error)) { + _LOGW ("failed to connect to modem: %s", error->message); + g_clear_error (&error); + goto out; + } + + ifindex = nm_modem_get_ip_ifindex (NM_MODEM (self)); + nm_assert (ifindex > 0); /* TODO: verify handling of ip4_config; check other places it's used... */ g_clear_object (&priv->ip4_config); - priv->ip4_config = nm_ip4_config_new (nm_platform_get_multi_idx (NM_PLATFORM_GET), ifindex); diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 491334d202..873d871875 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -44,14 +44,10 @@ NM_GOBJECT_PROPERTIES_DEFINE (NMModem, PROP_CONTROL_PORT, - PROP_DATA_PORT, PROP_IP_IFINDEX, PROP_PATH, PROP_UID, PROP_DRIVER, - PROP_IP4_METHOD, - PROP_IP6_METHOD, - PROP_IP_TIMEOUT, PROP_STATE, PROP_DEVICE_ID, PROP_SIM_ID, @@ -80,7 +76,11 @@ typedef struct _NMModemPrivate { char *driver; char *control_port; char *data_port; + + /* TODO: ip_iface is solely used for nm_modem_owns_port(). + * We should rework the code that it's not necessary */ char *ip_iface; + int ip_ifindex; NMModemIPMethod ip4_method; NMModemIPMethod ip6_method; @@ -98,7 +98,7 @@ typedef struct _NMModemPrivate { guint32 secrets_tries; NMActRequestGetSecretsCallId *secrets_id; - guint32 mm_ip_timeout; + guint mm_ip_timeout; guint32 ip4_route_table; guint32 ip4_route_metric; @@ -156,7 +156,7 @@ _nmlog_prefix (char *prefix, NMModem *self) /*****************************************************************************/ -static void _set_ip_ifindex (NMModem *self, int ifindex); +static void _set_ip_ifindex (NMModem *self, int ifindex, const char *ifname); /*****************************************************************************/ /* State/enabled/connected */ @@ -462,19 +462,18 @@ ppp_ifindex_set (NMPPPManager *ppp_manager, gpointer user_data) { NMModem *self = NM_MODEM (user_data); - NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self); nm_assert (ifindex >= 0); + nm_assert (NM_MODEM_GET_PRIVATE (self)->ppp_manager == ppp_manager); - /* Notify about the new data port to use. - * - * @iface might be %NULL. */ - if (g_strcmp0 (priv->data_port, iface) != 0) { - g_free (priv->data_port); - priv->data_port = g_strdup (iface); - _notify (self, PROP_DATA_PORT); + if (ifindex <= 0 && iface) { + /* this might happen, if the ifname was already deleted + * and we failed to resolve ifindex. + * + * Forget about the name. */ + iface = NULL; } - _set_ip_ifindex (self, ifindex); + _set_ip_ifindex (self, ifindex, iface); } static void @@ -565,9 +564,19 @@ port_speed_is_zero (const char *port) { struct termios options; nm_auto_close int fd = -1; + gs_free char *path = NULL; nm_assert (port); + if (port[0] != '/') { + if ( !port[0] + || strchr (port, '/') + || NM_IN_STRSET (port, ".", "..")) + return FALSE; + path = g_build_path ("/sys/class/tty", port, NULL); + port = path; + } + fd = open (port, O_RDWR | O_NONBLOCK | O_NOCTTY | O_CLOEXEC); if (fd < 0) return FALSE; @@ -1134,12 +1143,12 @@ deactivate_cleanup (NMModem *self, NMDevice *device) } } } + + nm_clear_g_free (&priv->data_port); + priv->mm_ip_timeout = 0; priv->ip4_method = NM_MODEM_IP_METHOD_UNKNOWN; priv->ip6_method = NM_MODEM_IP_METHOD_UNKNOWN; - - _set_ip_ifindex (self, -1); - if (nm_clear_g_free (&priv->ip_iface)) - _notify (self, PROP_DATA_PORT); + _set_ip_ifindex (self, -1, NULL); } /*****************************************************************************/ @@ -1393,17 +1402,9 @@ nm_modem_get_control_port (NMModem *self) const char * nm_modem_get_data_port (NMModem *self) { - NMModemPrivate *priv; - g_return_val_if_fail (NM_IS_MODEM (self), NULL); - priv = NM_MODEM_GET_PRIVATE (self); - - /* The ip_iface takes precedence over the data interface when PPP is used, - * since data_iface is the TTY over which PPP is run, and that TTY can't - * do IP. The caller really wants the thing that's doing IP. - */ - return priv->ip_iface ?: priv->data_port; + return NM_MODEM_GET_PRIVATE (self)->data_port; } int @@ -1422,11 +1423,17 @@ nm_modem_get_ip_ifindex (NMModem *self) } static void -_set_ip_ifindex (NMModem *self, int ifindex) +_set_ip_ifindex (NMModem *self, int ifindex, const char *ifname) { NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self); nm_assert (ifindex >= -1); + nm_assert ((ifindex > 0) == !!ifname); + + if (!nm_streq0 (priv->ip_iface, ifname)) { + g_free (priv->ip_iface); + priv->ip_iface = g_strdup (ifname); + } if (priv->ip_ifindex != ifindex) { priv->ip_ifindex = ifindex; @@ -1434,6 +1441,85 @@ _set_ip_ifindex (NMModem *self, int ifindex) } } +gboolean +nm_modem_set_data_port (NMModem *self, + NMPlatform *platform, + const char *data_port, + NMModemIPMethod ip4_method, + NMModemIPMethod ip6_method, + guint timeout, + GError **error) +{ + NMModemPrivate *priv; + gboolean is_ppp; + int ifindex = -1; + + g_return_val_if_fail (NM_IS_MODEM (self), FALSE); + g_return_val_if_fail (NM_IS_PLATFORM (platform), FALSE); + g_return_val_if_fail (!error || !*error, FALSE); + + priv = NM_MODEM_GET_PRIVATE (self); + + if ( priv->ppp_manager + || priv->data_port + || priv->ip_ifindex != -1) { + g_set_error_literal (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN, + "cannot set data port in activated state"); + /* this really shouldn't happen. Assert. */ + g_return_val_if_reached (FALSE); + } + + if (!data_port) { + g_set_error_literal (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN, + "missing data port"); + return FALSE; + } + + is_ppp = (ip4_method == NM_MODEM_IP_METHOD_PPP) + || (ip6_method == NM_MODEM_IP_METHOD_PPP); + if (is_ppp) { + if ( !NM_IN_SET (ip4_method, NM_MODEM_IP_METHOD_UNKNOWN, NM_MODEM_IP_METHOD_PPP) + || !NM_IN_SET (ip6_method, NM_MODEM_IP_METHOD_UNKNOWN, NM_MODEM_IP_METHOD_PPP)) { + g_set_error_literal (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN, + "conflicting ip methods"); + return FALSE; + } + } else if ( !NM_IN_SET (ip4_method, NM_MODEM_IP_METHOD_UNKNOWN, NM_MODEM_IP_METHOD_STATIC, NM_MODEM_IP_METHOD_AUTO) + || !NM_IN_SET (ip6_method, NM_MODEM_IP_METHOD_UNKNOWN, NM_MODEM_IP_METHOD_STATIC, NM_MODEM_IP_METHOD_AUTO) + || ( ip4_method == NM_MODEM_IP_METHOD_UNKNOWN + && ip6_method == NM_MODEM_IP_METHOD_UNKNOWN)) { + g_set_error_literal (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN, + "invalid ip methods"); + return FALSE; + } + + if (!is_ppp) { + ifindex = nm_platform_if_nametoindex (platform, data_port); + if (ifindex <= 0) { + g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN, + "cannot find network interface %s", data_port); + return FALSE; + } + if (!nm_platform_process_events_ensure_link (platform, ifindex, data_port)) { + g_set_error (error, NM_UTILS_ERROR, NM_UTILS_ERROR_UNKNOWN, + "cannot find network interface %s in platform cache", data_port); + return FALSE; + } + } + + priv->mm_ip_timeout = timeout; + priv->ip4_method = ip4_method; + priv->ip6_method = ip6_method; + if (is_ppp) { + priv->data_port = g_strdup (data_port); + _set_ip_ifindex (self, -1, NULL); + } else { + priv->data_port = NULL; + _set_ip_ifindex (self, ifindex, data_port); + } + return TRUE; +} + gboolean nm_modem_owns_port (NMModem *self, const char *iface) { @@ -1560,24 +1646,12 @@ get_property (GObject *object, guint prop_id, case PROP_CONTROL_PORT: g_value_set_string (value, priv->control_port); break; - case PROP_DATA_PORT: - g_value_set_string (value, nm_modem_get_data_port (self)); - break; case PROP_IP_IFINDEX: g_value_set_int (value, nm_modem_get_ip_ifindex (self)); break; case PROP_UID: g_value_set_string (value, priv->uid); break; - case PROP_IP4_METHOD: - g_value_set_uint (value, priv->ip4_method); - break; - case PROP_IP6_METHOD: - g_value_set_uint (value, priv->ip6_method); - break; - case PROP_IP_TIMEOUT: - g_value_set_uint (value, priv->mm_ip_timeout); - break; case PROP_STATE: g_value_set_int (value, priv->state); break; @@ -1620,23 +1694,10 @@ set_property (GObject *object, guint prop_id, /* construct-only */ priv->control_port = g_value_dup_string (value); break; - case PROP_DATA_PORT: - g_free (priv->data_port); - priv->data_port = g_value_dup_string (value); - break; case PROP_UID: /* construct-only */ priv->uid = g_value_dup_string (value); break; - case PROP_IP4_METHOD: - priv->ip4_method = g_value_get_uint (value); - break; - case PROP_IP6_METHOD: - priv->ip6_method = g_value_get_uint (value); - break; - case PROP_IP_TIMEOUT: - priv->mm_ip_timeout = g_value_get_uint (value); - break; case PROP_STATE: /* construct-only */ priv->state = g_value_get_int (value); @@ -1764,40 +1825,12 @@ nm_modem_class_init (NMModemClass *klass) G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_DATA_PORT] = - g_param_spec_string (NM_MODEM_DATA_PORT, "", "", - NULL, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS); - obj_properties[PROP_IP_IFINDEX] = g_param_spec_int (NM_MODEM_IP_IFINDEX, "", "", 0, G_MAXINT, 0, G_PARAM_READABLE | G_PARAM_STATIC_STRINGS); - obj_properties[PROP_IP4_METHOD] = - g_param_spec_uint (NM_MODEM_IP4_METHOD, "", "", - NM_MODEM_IP_METHOD_UNKNOWN, - NM_MODEM_IP_METHOD_AUTO, - NM_MODEM_IP_METHOD_UNKNOWN, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | - G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_IP6_METHOD] = - g_param_spec_uint (NM_MODEM_IP6_METHOD, "", "", - NM_MODEM_IP_METHOD_UNKNOWN, - NM_MODEM_IP_METHOD_AUTO, - NM_MODEM_IP_METHOD_UNKNOWN, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT | - G_PARAM_STATIC_STRINGS); - - obj_properties[PROP_IP_TIMEOUT] = - g_param_spec_uint (NM_MODEM_IP_TIMEOUT, "", "", - 0, 360, 20, - G_PARAM_READWRITE | - G_PARAM_STATIC_STRINGS); - obj_properties[PROP_STATE] = g_param_spec_int (NM_MODEM_STATE, "", "", NM_MODEM_STATE_UNKNOWN, _NM_MODEM_STATE_LAST, NM_MODEM_STATE_UNKNOWN, diff --git a/src/devices/wwan/nm-modem.h b/src/devices/wwan/nm-modem.h index 39b85d0a42..047cb37af8 100644 --- a/src/devices/wwan/nm-modem.h +++ b/src/devices/wwan/nm-modem.h @@ -37,11 +37,7 @@ #define NM_MODEM_PATH "path" #define NM_MODEM_DRIVER "driver" #define NM_MODEM_CONTROL_PORT "control-port" -#define NM_MODEM_DATA_PORT "data-port" #define NM_MODEM_IP_IFINDEX "ip-ifindex" -#define NM_MODEM_IP4_METHOD "ip4-method" -#define NM_MODEM_IP6_METHOD "ip6-method" -#define NM_MODEM_IP_TIMEOUT "ip-timeout" #define NM_MODEM_STATE "state" #define NM_MODEM_DEVICE_ID "device-id" #define NM_MODEM_SIM_ID "sim-id" @@ -176,6 +172,14 @@ 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); +gboolean nm_modem_set_data_port (NMModem *self, + NMPlatform *platform, + const char *data_port, + NMModemIPMethod ip4_method, + NMModemIPMethod ip6_method, + guint timeout, + GError **error); + gboolean nm_modem_owns_port (NMModem *modem, const char *iface); void nm_modem_get_capabilities (NMModem *self, diff --git a/src/devices/wwan/nm-wwan-factory.c b/src/devices/wwan/nm-wwan-factory.c index 663102de4d..8767fe09c1 100644 --- a/src/devices/wwan/nm-wwan-factory.c +++ b/src/devices/wwan/nm-wwan-factory.c @@ -80,7 +80,7 @@ modem_added_cb (NMModemManager *manager, { NMWwanFactory *self = NM_WWAN_FACTORY (user_data); NMDevice *device; - const char *driver, *port; + const char *driver; /* Do nothing if the modem was consumed by some other plugin */ if (nm_device_factory_emit_component_added (NM_DEVICE_FACTORY (self), G_OBJECT (modem))) @@ -93,10 +93,9 @@ modem_added_cb (NMModemManager *manager, * by the Bluetooth code during the connection process. */ if (driver && strstr (driver, "bluetooth")) { - port = nm_modem_get_data_port (modem); - if (!port) - port = nm_modem_get_control_port (modem); - nm_log_info (LOGD_MB, "ignoring modem '%s' (no associated Bluetooth device)", port); + nm_log_info (LOGD_MB, "ignoring modem '%s' (no associated Bluetooth device)", + nm_modem_get_data_port (modem) + ?: nm_modem_get_control_port (modem)); return; } From 78ca2a70c719b255aa7de04cffaa264bb4d06b55 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 11 Jan 2018 11:35:13 +0100 Subject: [PATCH 15/16] device: don't set invalid ip-iface Now that every call to nm_device_set_ip_iface() and nm_device_set_ip_ifindex() is checked, and setting an interface that does not exist causes the device state to fail, we no longer need to allow setting an ip-iface if we are unable to retrieve the ip-ifindex. --- src/devices/nm-device.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 084c3f7ae4..54b0097326 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -1291,14 +1291,11 @@ _set_ip_ifindex (NMDevice *self, NMPlatform *platform; gboolean eq_name; - /* we can set only the ifname without ifindex (to indicate that this - * is an ip-interface, but lookup for the ifindex failed. - * But we cannot just set ifindex > 0 without an ifname. */ - nm_assert (ifindex <= 0 || ifname); - - /* normalize ifindex */ - if (ifindex < 0) + /* normalize arguments */ + if (ifindex <= 0) { ifindex = 0; + ifname = NULL; + } eq_name = nm_streq0 (priv->ip_iface, ifname); @@ -1343,13 +1340,12 @@ nm_device_set_ip_ifindex (NMDevice *self, int ifindex) const char *ifname = NULL; g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); + g_return_val_if_fail (nm_device_is_activating (self), FALSE); if (ifindex > 0) { ifname = nm_platform_if_indextoname (nm_device_get_platform (self), ifindex, ifname_buf); - if (!ifname) { + if (!ifname) _LOGW (LOGD_DEVICE, "ip-ifindex: ifindex %d not found", ifindex); - return FALSE; - } } _set_ip_ifindex (self, ifindex, ifname); @@ -1372,9 +1368,13 @@ nm_device_set_ip_iface (NMDevice *self, const char *ifname) int ifindex = 0; g_return_val_if_fail (NM_IS_DEVICE (self), FALSE); + g_return_val_if_fail (nm_device_is_activating (self), FALSE); - if (ifname) + if (ifname) { ifindex = nm_platform_if_nametoindex (nm_device_get_platform (self), ifname); + if (ifindex <= 0) + _LOGW (LOGD_DEVICE, "ip-ifindex: ifname %s not found", ifname); + } _set_ip_ifindex (self, ifindex, ifname); return ifindex > 0; From de16ef91cfcf11daed29a5dab842d99706a519d9 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 11 Jan 2018 11:49:48 +0100 Subject: [PATCH 16/16] wwan: drop nm_modem_get_data_port() function It was only used by bluetooth's component_added() check. It should compare rfcomm_iface only against the control-port, not the data-port. --- src/devices/bluetooth/nm-device-bt.c | 4 +--- src/devices/wwan/libnm-wwan.ver | 1 - src/devices/wwan/nm-modem.c | 8 -------- src/devices/wwan/nm-modem.h | 1 - src/devices/wwan/nm-wwan-factory.c | 3 +-- 5 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c index c039a158b8..77d258ecdd 100644 --- a/src/devices/bluetooth/nm-device-bt.c +++ b/src/devices/bluetooth/nm-device-bt.c @@ -660,9 +660,7 @@ component_added (NMDevice *device, GObject *component) gs_free char *base = NULL; base = g_path_get_basename (priv->rfcomm_iface); - if (!NM_IN_STRSET (base, - nm_modem_get_control_port (modem), - nm_modem_get_data_port (modem))) + if (!nm_streq (base, nm_modem_get_control_port (modem))) return FALSE; } diff --git a/src/devices/wwan/libnm-wwan.ver b/src/devices/wwan/libnm-wwan.ver index d30a175ce7..70b954c5d8 100644 --- a/src/devices/wwan/libnm-wwan.ver +++ b/src/devices/wwan/libnm-wwan.ver @@ -11,7 +11,6 @@ global: nm_modem_get_capabilities; nm_modem_get_configured_mtu; nm_modem_get_control_port; - nm_modem_get_data_port; nm_modem_get_driver; nm_modem_get_iid; nm_modem_get_path; diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c index 873d871875..85f6eb039e 100644 --- a/src/devices/wwan/nm-modem.c +++ b/src/devices/wwan/nm-modem.c @@ -1399,14 +1399,6 @@ nm_modem_get_control_port (NMModem *self) return NM_MODEM_GET_PRIVATE (self)->control_port; } -const char * -nm_modem_get_data_port (NMModem *self) -{ - g_return_val_if_fail (NM_IS_MODEM (self), NULL); - - return NM_MODEM_GET_PRIVATE (self)->data_port; -} - int nm_modem_get_ip_ifindex (NMModem *self) { diff --git a/src/devices/wwan/nm-modem.h b/src/devices/wwan/nm-modem.h index 047cb37af8..a95da25534 100644 --- a/src/devices/wwan/nm-modem.h +++ b/src/devices/wwan/nm-modem.h @@ -164,7 +164,6 @@ GType nm_modem_get_type (void); const char *nm_modem_get_path (NMModem *modem); const char *nm_modem_get_uid (NMModem *modem); const char *nm_modem_get_control_port (NMModem *modem); -const char *nm_modem_get_data_port (NMModem *modem); int nm_modem_get_ip_ifindex (NMModem *modem); const char *nm_modem_get_driver (NMModem *modem); const char *nm_modem_get_device_id (NMModem *modem); diff --git a/src/devices/wwan/nm-wwan-factory.c b/src/devices/wwan/nm-wwan-factory.c index 8767fe09c1..f0aae04008 100644 --- a/src/devices/wwan/nm-wwan-factory.c +++ b/src/devices/wwan/nm-wwan-factory.c @@ -94,8 +94,7 @@ modem_added_cb (NMModemManager *manager, */ if (driver && strstr (driver, "bluetooth")) { nm_log_info (LOGD_MB, "ignoring modem '%s' (no associated Bluetooth device)", - nm_modem_get_data_port (modem) - ?: nm_modem_get_control_port (modem)); + nm_modem_get_control_port (modem)); return; }