summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-01-09 14:08:35 +0100
committerThomas Haller <thaller@redhat.com>2018-01-09 14:22:27 +0100
commit5188361a7cb08a26515ef7d7c92734b314198c88 (patch)
treeabe0aa76093fdf7a2d2c8c34d58acc16b3141eb7
parent485ba2944cc47102fe5fd237cffdd8398d45d16a (diff)
downloadNetworkManager-bg/ppp-set-ifindex-bgo1515829.tar.gz
fixup! ppp: introduce SetIfindex pppd plugin D-Bus methodbg/ppp-set-ifindex-bgo1515829
(1) in impl_ppp_manager_set_ifindex(), always emit the signal. Even if we fail to resolve ifindex, emit the signal with ifindex=0, ifname=NULL. (2) in nm_ppp_manager_init(), initialize priv->ifindex = -1; That way, impl_ppp_manager_set_ifindex() can only accept a call exactly once (even if the once call yields an unknown ifindex, we will cache that indefinitely). (3) drop NMPppManagerPrivate.ip_iface. It's almost unused, except in monitor_cb(), and there it's better to look it up new every time. (4) when nm_device_set_ip_ifindex() fails, abort activation. See (1).
-rw-r--r--src/devices/adsl/nm-device-adsl.c6
-rw-r--r--src/devices/nm-device-ethernet.c6
-rw-r--r--src/devices/wwan/nm-modem.c23
-rw-r--r--src/ppp/nm-ppp-manager.c59
4 files changed, 53 insertions, 41 deletions
diff --git a/src/devices/adsl/nm-device-adsl.c b/src/devices/adsl/nm-device-adsl.c
index 6a6e646a61..2512c3187e 100644
--- a/src/devices/adsl/nm-device-adsl.c
+++ b/src/devices/adsl/nm-device-adsl.c
@@ -438,7 +438,11 @@ ppp_ifindex_set (NMPPPManager *ppp_manager,
{
NMDevice *device = NM_DEVICE (user_data);
- nm_device_set_ip_ifindex (device, ifindex);
+ if (!nm_device_set_ip_ifindex (device, ifindex)) {
+ nm_device_state_changed (device,
+ NM_DEVICE_STATE_FAILED,
+ NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE);
+ }
}
static void
diff --git a/src/devices/nm-device-ethernet.c b/src/devices/nm-device-ethernet.c
index 2967b413e4..54c8176f67 100644
--- a/src/devices/nm-device-ethernet.c
+++ b/src/devices/nm-device-ethernet.c
@@ -960,7 +960,11 @@ ppp_ifindex_set (NMPPPManager *ppp_manager,
{
NMDevice *device = NM_DEVICE (user_data);
- nm_device_set_ip_ifindex (device, ifindex);
+ if (!nm_device_set_ip_ifindex (device, ifindex)) {
+ nm_device_state_changed (device,
+ NM_DEVICE_STATE_FAILED,
+ NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE);
+ }
}
static void
diff --git a/src/devices/wwan/nm-modem.c b/src/devices/wwan/nm-modem.c
index d04d10001f..10baa424af 100644
--- a/src/devices/wwan/nm-modem.c
+++ b/src/devices/wwan/nm-modem.c
@@ -450,27 +450,22 @@ ppp_state_changed (NMPPPManager *ppp_manager, NMPPPStatus status, gpointer user_
}
static void
-set_data_port (NMModem *self, const char *new_data_port)
-{
- NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self);
-
- if (g_strcmp0 (priv->data_port, new_data_port) != 0) {
- g_free (priv->data_port);
- priv->data_port = g_strdup (new_data_port);
- _notify (self, PROP_DATA_PORT);
- }
-}
-
-static void
ppp_ifindex_set (NMPPPManager *ppp_manager,
int ifindex,
const char *iface,
gpointer user_data)
{
NMModem *self = NM_MODEM (user_data);
+ NMModemPrivate *priv = NM_MODEM_GET_PRIVATE (self);
- /* Notify about the new data port to use */
- set_data_port (self, iface);
+ /* 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);
+ }
}
static void
diff --git a/src/ppp/nm-ppp-manager.c b/src/ppp/nm-ppp-manager.c
index 06c3541970..d1e12643ef 100644
--- a/src/ppp/nm-ppp-manager.c
+++ b/src/ppp/nm-ppp-manager.c
@@ -176,24 +176,28 @@ monitor_cb (gpointer user_data)
{
NMPPPManager *manager = NM_PPP_MANAGER (user_data);
NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
- struct ifreq req;
- struct ppp_stats stats;
+ const char *ifname;
- memset (&req, 0, sizeof (req));
- memset (&stats, 0, sizeof (stats));
- req.ifr_data = (caddr_t) &stats;
+ ifname = nm_platform_link_get_name (NM_PLATFORM_GET, priv->ifindex);
- strncpy (req.ifr_name, priv->ip_iface, sizeof (req.ifr_name));
- if (ioctl (priv->monitor_fd, SIOCGPPPSTATS, &req) < 0) {
- if (errno != ENODEV)
- _LOGW ("could not read ppp stats: %s", strerror (errno));
- } else {
- g_signal_emit (manager, signals[STATS], 0,
- (guint) stats.p.ppp_ibytes,
- (guint) stats.p.ppp_obytes);
+ if (ifname) {
+ struct ppp_stats stats = { };
+ struct ifreq req = {
+ .ifr_data = (caddr_t) &stats,
+ };
+
+ nm_utils_ifname_cpy (req.ifr_name, ifname);
+ if (ioctl (priv->monitor_fd, SIOCGPPPSTATS, &req) < 0) {
+ if (errno != ENODEV)
+ _LOGW ("could not read ppp stats: %s", strerror (errno));
+ } else {
+ g_signal_emit (manager, signals[STATS], 0,
+ (guint) stats.p.ppp_ibytes,
+ (guint) stats.p.ppp_obytes);
+ }
}
- return TRUE;
+ return G_SOURCE_CONTINUE;
}
static void
@@ -407,29 +411,34 @@ impl_ppp_manager_set_ifindex (NMPPPManager *manager,
gint32 ifindex)
{
NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
- const NMPlatformLink *plink;
+ const NMPlatformLink *plink = NULL;
+ nm_auto_nmpobj const NMPObject *obj_keep_alive = NULL;
_LOGD ("set-ifindex %d", (int) ifindex);
- if (priv->ifindex > 0) {
+ if (priv->ifindex >= 0) {
_LOGW ("can't change the ifindex from %d to %d", priv->ifindex, (int) ifindex);
return;
}
- plink = nm_platform_link_get (NM_PLATFORM_GET, ifindex);
- if (!plink) {
- nm_platform_process_events (NM_PLATFORM_GET);
+ if (ifindex > 0) {
plink = nm_platform_link_get (NM_PLATFORM_GET, ifindex);
if (!plink) {
- _LOGW ("unknown interface with ifindex %d", ifindex);
- return;
+ nm_platform_process_events (NM_PLATFORM_GET);
+ plink = nm_platform_link_get (NM_PLATFORM_GET, ifindex);
}
}
+ if (!plink) {
+ _LOGW ("unknown interface with ifindex %d", ifindex);
+ ifindex = 0;
+ }
+
priv->ifindex = ifindex;
- priv->ip_iface = g_strdup (plink->name);
- g_signal_emit (manager, signals[IFINDEX_SET], 0, ifindex, priv->ip_iface);
+ obj_keep_alive = nmp_object_ref (NMP_OBJECT_UP_CAST (plink));
+
+ g_signal_emit (manager, signals[IFINDEX_SET], 0, ifindex, plink->name);
g_dbus_method_invocation_return_value (context, NULL);
}
@@ -442,7 +451,7 @@ set_ip_config_common (NMPPPManager *self,
NMConnection *applied_connection;
NMSettingPpp *s_ppp;
- if (!priv->ip_iface || priv->ifindex <= 0)
+ if (priv->ifindex <= 0)
return FALSE;
/* Got successful IP config; obviously the secrets worked */
@@ -1262,6 +1271,7 @@ nm_ppp_manager_init (NMPPPManager *manager)
{
NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
+ priv->ifindex = -1;
priv->monitor_fd = -1;
priv->ip4_route_table = RT_TABLE_MAIN;
priv->ip4_route_metric = 460;
@@ -1302,7 +1312,6 @@ finalize (GObject *object)
{
NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE ((NMPPPManager *) object);
- g_free (priv->ip_iface);
g_free (priv->parent_iface);
G_OBJECT_CLASS (nm_ppp_manager_parent_class)->finalize (object);