Commit 025235e0 authored by Beniamino Galvani's avatar Beniamino Galvani

ppp: split ppp manager into a plugin

Moving the PPP manager to a separate plugin that is loaded when needed
has the advantage of slightly reducing memory footprint and makes it
possible to install the PPP support only where needed.

https://bugzilla.gnome.org/show_bug.cgi?id=773482
parent 2e21d784
......@@ -989,7 +989,6 @@ src_cppflags = \
\
-DDHCLIENT_PATH=\"$(DHCLIENT_PATH)\" \
-DDHCPCD_PATH=\"$(DHCPCD_PATH)\" \
-DPPPD_PLUGIN_DIR=\"$(PPPD_PLUGIN_DIR)\" \
\
$(GUDEV_CFLAGS) \
$(LIBNL_CFLAGS) \
......@@ -1318,7 +1317,8 @@ src_libNetworkManager_la_SOURCES = \
src/dnsmasq/nm-dnsmasq-utils.c \
src/dnsmasq/nm-dnsmasq-utils.h \
\
src/ppp/nm-ppp-manager.c \
src/ppp/nm-ppp-manager-call.c \
src/ppp/nm-ppp-manager-call.h \
src/ppp/nm-ppp-manager.h \
src/ppp/nm-ppp-status.h \
\
......@@ -1566,6 +1566,7 @@ EXTRA_DIST += \
if WITH_PPP
pppd_plugin_LTLIBRARIES += src/ppp/nm-pppd-plugin.la
pkglib_LTLIBRARIES += src/ppp/libnm-ppp-plugin.la
src_ppp_nm_pppd_plugin_la_CPPFLAGS = \
-I$(srcdir)/shared \
......@@ -1589,6 +1590,36 @@ src_ppp_nm_pppd_plugin_la_LIBADD = \
$(GLIB_LIBS) \
$(DL_LIBS)
src_ppp_libnm_ppp_plugin_la_SOURCES = \
src/ppp/nm-pppd-plugin.h \
src/ppp/nm-ppp-manager.c \
src/ppp/nm-ppp-manager.h \
src/ppp/nm-ppp-plugin-api.h \
src/ppp/nm-ppp-status.h
EXTRA_src_ppp_libnm_ppp_plugin_la_DEPENDENCIES = \
src/ppp/nm-ppp-plugin.ver
src_ppp_libnm_ppp_plugin_la_CPPFLAGS = \
-I${top_srcdir}/src \
-I${top_builddir}/src \
-I${top_srcdir}/shared \
-I$(top_builddir)/shared \
-I${top_builddir}/libnm-core \
-I${top_srcdir}/libnm-core \
-DPPPD_PLUGIN_DIR=\"$(PPPD_PLUGIN_DIR)\" \
-DG_LOG_DOMAIN=\""NetworkManager"\" \
-DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \
$(GLIB_CFLAGS)
src_ppp_libnm_ppp_plugin_la_LDFLAGS = \
-module -avoid-version \
-Wl,--version-script="$(top_srcdir)/src/ppp/nm-ppp-plugin.ver"
src_ppp_libnm_ppp_plugin_la_LIBADD = \
introspection/libnmdbus.la \
$(GLIB_LIBS)
endif
###############################################################################
......@@ -4067,6 +4098,7 @@ EXTRA_DIST += \
linker-script-binary.ver \
linker-script-devices.ver \
linker-script-settings.ver \
src/ppp/nm-ppp-plugin.ver \
Makefile.glib \
autogen.sh \
valgrind.suppressions \
......
......@@ -186,6 +186,8 @@ GQuark nm_device_error_quark (void);
* @NM_MANAGER_ERROR_UNKNOWN_LOG_LEVEL: Unknown log level in SetLogging
* @NM_MANAGER_ERROR_UNKNOWN_LOG_DOMAIN: Unknown log domain in SetLogging
* @NM_MANAGER_ERROR_INVALID_ARGUMENTS: Invalid arguments for D-Bus request
* @NM_MANAGER_ERROR_MISSING_PLUGIN: A plug-in was needed to complete the
* activation but is not available.
*
* Errors related to the main "network management" interface of NetworkManager.
* These may be returned from #NMClient methods that invoke D-Bus operations on
......@@ -206,6 +208,7 @@ typedef enum {
NM_MANAGER_ERROR_UNKNOWN_LOG_LEVEL, /*< nick=UnknownLogLevel >*/
NM_MANAGER_ERROR_UNKNOWN_LOG_DOMAIN, /*< nick=UnknownLogDomain >*/
NM_MANAGER_ERROR_INVALID_ARGUMENTS, /*< nick=InvalidArguments >*/
NM_MANAGER_ERROR_MISSING_PLUGIN, /*< nick=MissingPlugin >*/
} NMManagerError;
GQuark nm_manager_error_quark (void);
......
......@@ -5,7 +5,6 @@ global:
_nm_dbus_error_has_name;
_nm_dbus_proxy_call_finish;
_nm_dbus_signal_connect_data;
_nm_exported_object_clear_and_unexport;
_nm_log_impl;
_nm_logging_enabled_state;
_nm_platform_error_to_string;
......@@ -21,6 +20,7 @@ global:
nm_act_request_get_secrets;
nm_act_request_get_settings_connection;
nm_act_request_get_type;
nm_active_connection_clear_secrets;
nm_active_connection_get_specific_object;
nm_active_connection_get_type;
nm_active_connection_set_specific_object;
......@@ -39,12 +39,14 @@ global:
nm_connection_get_id;
nm_connection_get_interface_name;
nm_connection_get_path;
nm_connection_get_setting;
nm_connection_get_setting_802_1x;
nm_connection_get_setting_adsl;
nm_connection_get_setting_bluetooth;
nm_connection_get_setting_bond;
nm_connection_get_setting_bridge;
nm_connection_get_setting_bridge_port;
nm_connection_get_setting_by_name;
nm_connection_get_setting_cdma;
nm_connection_get_setting_connection;
nm_connection_get_setting_dcb;
......@@ -144,6 +146,7 @@ global:
nm_ip4_config_add_address;
nm_ip4_config_add_nameserver;
nm_ip4_config_add_route;
nm_ip4_config_add_wins;
nm_ip4_config_get_address;
nm_ip4_config_get_nameserver;
nm_ip4_config_get_num_nameservers;
......@@ -169,8 +172,14 @@ global:
nm_ip_route_get_prefix;
nm_ip_route_new;
nm_ip_route_unref;
nm_manager_error_quark;
nm_manager_get;
nm_manager_get_devices;
nm_manager_ppp_create;
nm_manager_ppp_start;
nm_manager_ppp_stop_async;
nm_manager_ppp_stop_finish;
nm_manager_ppp_stop_sync;
nm_manager_set_capability;
nm_platform_address_flush;
nm_platform_get;
......@@ -198,10 +207,6 @@ global:
nm_platform_wifi_indicate_addressing_running;
nm_platform_wifi_set_mode;
nm_platform_wifi_set_powersave;
nm_ppp_manager_new;
nm_ppp_manager_start;
nm_ppp_manager_stop;
nm_ppp_manager_stop_finish;
nm_route_manager_get;
nm_route_manager_route_flush;
nm_setting_802_1x_add_eap_method;
......@@ -257,6 +262,7 @@ global:
nm_setting_802_1x_set_phase2_private_key;
nm_setting_802_1x_set_private_key;
nm_setting_adsl_get_encapsulation;
nm_setting_adsl_get_password;
nm_setting_adsl_get_protocol;
nm_setting_adsl_get_type;
nm_setting_adsl_get_username;
......@@ -286,6 +292,7 @@ global:
nm_setting_bridge_port_new;
nm_setting_cdma_get_number;
nm_setting_cdma_get_password;
nm_setting_cdma_get_type;
nm_setting_cdma_get_username;
nm_setting_cdma_new;
nm_setting_connection_add_permission;
......@@ -333,6 +340,7 @@ global:
nm_setting_dcb_set_priority_group_id;
nm_setting_dcb_set_priority_strict_bandwidth;
nm_setting_dcb_set_priority_traffic_class;
nm_setting_duplicate;
nm_setting_generic_new;
nm_setting_get_secret_flags;
nm_setting_get_type;
......@@ -345,6 +353,7 @@ global:
nm_setting_gsm_get_pin;
nm_setting_gsm_get_sim_id;
nm_setting_gsm_get_sim_operator_id;
nm_setting_gsm_get_type;
nm_setting_gsm_get_username;
nm_setting_infiniband_get_mac_address;
nm_setting_infiniband_get_mtu;
......@@ -397,14 +406,28 @@ global:
nm_setting_olpc_mesh_get_dhcp_anycast_address;
nm_setting_olpc_mesh_get_ssid;
nm_setting_olpc_mesh_new;
nm_setting_ppp_get_baud;
nm_setting_ppp_get_crtscts;
nm_setting_ppp_get_lcp_echo_failure;
nm_setting_ppp_get_lcp_echo_interval;
nm_setting_ppp_get_mppe_stateful;
nm_setting_ppp_get_mru;
nm_setting_ppp_get_mtu;
nm_setting_ppp_get_no_vj_comp;
nm_setting_ppp_get_noauth;
nm_setting_ppp_get_nobsdcomp;
nm_setting_ppp_get_nodeflate;
nm_setting_ppp_get_refuse_chap;
nm_setting_ppp_get_refuse_eap;
nm_setting_ppp_get_refuse_mschap;
nm_setting_ppp_get_refuse_mschapv2;
nm_setting_ppp_get_refuse_pap;
nm_setting_ppp_get_require_mppe;
nm_setting_ppp_get_require_mppe_128;
nm_setting_ppp_get_type;
nm_setting_ppp_new;
nm_setting_pppoe_get_password;
nm_setting_pppoe_get_service;
nm_setting_pppoe_get_type;
nm_setting_pppoe_get_username;
nm_setting_pppoe_new;
......@@ -542,9 +565,11 @@ global:
nm_utils_ip4_netmask_to_prefix;
nm_utils_ip4_prefix_to_netmask;
nm_utils_ipaddr_valid;
nm_utils_ipv6_interface_identifier_get_from_addr;
nm_utils_is_empty_ssid;
nm_utils_is_json_object;
nm_utils_kill_child_async;
nm_utils_modprobe;
nm_utils_monotonic_timestamp_as_boottime;
nm_utils_rsa_key_encrypt;
nm_utils_same_ssid;
......
......@@ -34,7 +34,7 @@
#include "devices/nm-device-private.h"
#include "platform/nm-platform.h"
#include "ppp/nm-ppp-manager.h"
#include "ppp/nm-ppp-manager-call.h"
#include "ppp/nm-ppp-status.h"
#include "nm-setting-adsl.h"
#include "nm-utils.h"
......@@ -477,8 +477,11 @@ act_stage3_ip4_config_start (NMDevice *device,
_LOGD (LOGD_ADSL, "starting PPPoA");
}
priv->ppp_manager = nm_ppp_manager_new (ppp_iface);
if (nm_ppp_manager_start (priv->ppp_manager, req, nm_setting_adsl_get_username (s_adsl), 30, 0, &err)) {
priv->ppp_manager = nm_ppp_manager_create (ppp_iface, &err);
if ( priv->ppp_manager
&& nm_ppp_manager_start (priv->ppp_manager, req,
nm_setting_adsl_get_username (s_adsl),
30, 0, &err)) {
g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_STATE_CHANGED,
G_CALLBACK (ppp_state_changed),
self);
......@@ -490,7 +493,7 @@ act_stage3_ip4_config_start (NMDevice *device,
_LOGW (LOGD_ADSL, "PPP failed to start: %s", err->message);
g_error_free (err);
nm_exported_object_clear_and_unexport (&priv->ppp_manager);
g_clear_object (&priv->ppp_manager);
*reason = NM_DEVICE_STATE_REASON_PPP_START_FAILED;
}
......@@ -506,7 +509,8 @@ 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);
nm_exported_object_clear_and_unexport (&priv->ppp_manager);
nm_ppp_manager_stop_sync (priv->ppp_manager);
g_clear_object (&priv->ppp_manager);
}
g_signal_handlers_disconnect_by_func (NM_PLATFORM_GET, G_CALLBACK (link_changed_cb), self);
......
......@@ -39,6 +39,7 @@
#include "supplicant/nm-supplicant-interface.h"
#include "supplicant/nm-supplicant-config.h"
#include "ppp/nm-ppp-manager.h"
#include "ppp/nm-ppp-manager-call.h"
#include "ppp/nm-ppp-status.h"
#include "platform/nm-platform.h"
#include "platform/nm-platform-utils.h"
......@@ -1011,8 +1012,12 @@ pppoe_stage3_ip4_config_start (NMDeviceEthernet *self, NMDeviceStateReason *reas
s_pppoe = (NMSettingPppoe *) nm_device_get_applied_setting ((NMDevice *) self, NM_TYPE_SETTING_PPPOE);
g_assert (s_pppoe);
priv->ppp_manager = nm_ppp_manager_new (nm_device_get_iface (NM_DEVICE (self)));
if (nm_ppp_manager_start (priv->ppp_manager, req, nm_setting_pppoe_get_username (s_pppoe), 30, 0, &err)) {
priv->ppp_manager = nm_ppp_manager_create (nm_device_get_iface (NM_DEVICE (self)),
&err);
if ( priv->ppp_manager
&& nm_ppp_manager_start (priv->ppp_manager, req,
nm_setting_pppoe_get_username (s_pppoe),
30, 0, &err)) {
g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_STATE_CHANGED,
G_CALLBACK (ppp_state_changed),
self);
......@@ -1024,7 +1029,7 @@ pppoe_stage3_ip4_config_start (NMDeviceEthernet *self, NMDeviceStateReason *reas
_LOGW (LOGD_DEVICE, "PPPoE failed to start: %s", err->message);
g_error_free (err);
nm_exported_object_clear_and_unexport (&priv->ppp_manager);
g_clear_object (&priv->ppp_manager);
*reason = NM_DEVICE_STATE_REASON_PPP_START_FAILED;
}
......@@ -1389,7 +1394,10 @@ deactivate (NMDevice *device)
priv->pending_ip4_config = NULL;
}
nm_exported_object_clear_and_unexport (&priv->ppp_manager);
if (priv->ppp_manager) {
nm_ppp_manager_stop_sync (priv->ppp_manager);
g_clear_object (&priv->ppp_manager);
}
supplicant_interface_release (self);
......
......@@ -36,6 +36,7 @@
#include "nm-act-request.h"
#include "nm-ip4-config.h"
#include "nm-ip6-config.h"
#include "ppp/nm-ppp-manager-call.h"
#include "ppp/nm-ppp-status.h"
/*****************************************************************************/
......@@ -558,8 +559,10 @@ ppp_stage3_ip_config_start (NMModem *self,
if (port_speed_is_zero (priv->data_port))
baud_override = 57600;
priv->ppp_manager = nm_ppp_manager_new (priv->data_port);
if (nm_ppp_manager_start (priv->ppp_manager, req, ppp_name, ip_timeout, baud_override, &error)) {
priv->ppp_manager = nm_ppp_manager_create (priv->data_port, &error);
if ( priv->ppp_manager
&& nm_ppp_manager_start (priv->ppp_manager, req, ppp_name,
ip_timeout, baud_override, &error)) {
g_signal_connect (priv->ppp_manager, NM_PPP_MANAGER_STATE_CHANGED,
G_CALLBACK (ppp_state_changed),
self);
......@@ -580,7 +583,7 @@ ppp_stage3_ip_config_start (NMModem *self,
error->message);
g_error_free (error);
nm_exported_object_clear_and_unexport (&priv->ppp_manager);
g_clear_object (&priv->ppp_manager);
*reason = NM_DEVICE_STATE_REASON_PPP_START_FAILED;
ret = NM_ACT_STAGE_RETURN_FAILURE;
......@@ -1000,7 +1003,7 @@ deactivate_cleanup (NMModem *self, NMDevice *device)
priv->in_bytes = priv->out_bytes = 0;
nm_exported_object_clear_and_unexport (&priv->ppp_manager);
g_clear_object (&priv->ppp_manager);
if (device) {
g_return_if_fail (NM_IS_DEVICE (device));
......@@ -1136,10 +1139,10 @@ deactivate_step (DeactivateContext *ctx)
case DEACTIVATE_CONTEXT_STEP_PPP_MANAGER_STOP:
/* If we have a PPP manager, stop it */
if (ctx->ppp_manager) {
nm_ppp_manager_stop (ctx->ppp_manager,
ctx->cancellable,
(GAsyncReadyCallback) ppp_manager_stop_ready,
ctx);
nm_ppp_manager_stop_async (ctx->ppp_manager,
ctx->cancellable,
(GAsyncReadyCallback) ppp_manager_stop_ready,
ctx);
return;
}
ctx->step++;
......
......@@ -3904,3 +3904,4 @@ skip:
g_array_free (paths, TRUE);
return result;
}
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2016 Red Hat, Inc.
*/
#include "nm-default.h"
#include "nm-ppp-manager-call.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <errno.h>
#include "nm-manager.h"
#include "nm-core-utils.h"
#include "nm-ppp-plugin-api.h"
#define PPP_PLUGIN_PATH NMPLUGINDIR "/libnm-ppp-plugin.so"
/*****************************************************************************/
static NMPPPOps *ppp_ops = NULL;
NMPPPManager *
nm_ppp_manager_create (const char *iface, GError **error)
{
NMPPPManager *ret;
GModule *plugin;
GError *error_local = NULL;
NMPPPOps *ops;
struct stat st;
int errsv;
if (G_UNLIKELY (!ppp_ops)) {
if (stat (PPP_PLUGIN_PATH, &st) != 0) {
errsv = errno;
g_set_error_literal (error,
NM_MANAGER_ERROR, NM_MANAGER_ERROR_MISSING_PLUGIN,
"the PPP plugin " PPP_PLUGIN_PATH " is not installed");
return NULL;
}
if (!nm_utils_validate_plugin (PPP_PLUGIN_PATH, &st, &error_local)) {
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_MISSING_PLUGIN,
"could not load the PPP plugin " PPP_PLUGIN_PATH ": %s",
error_local->message);
g_clear_error (&error_local);
return NULL;
}
plugin = g_module_open (PPP_PLUGIN_PATH, G_MODULE_BIND_LOCAL);
if (!plugin) {
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_MISSING_PLUGIN,
"could not load the PPP plugin " PPP_PLUGIN_PATH ": %s",
g_module_error ());
return NULL;
}
if (!g_module_symbol (plugin, "ppp_ops", (gpointer) &ops)) {
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_MISSING_PLUGIN,
"error loading the PPP plugin: %s", g_module_error ());
return NULL;
}
/* after loading glib types from the plugin, we cannot unload the library anymore.
* Make it resident. */
g_module_make_resident (plugin);
nm_assert (ops);
nm_assert (ops->create);
nm_assert (ops->start);
nm_assert (ops->stop_async);
nm_assert (ops->stop_finish);
nm_assert (ops->stop_sync);
ppp_ops = ops;
nm_log_info (LOGD_CORE | LOGD_PPP, "loaded PPP plugin " PPP_PLUGIN_PATH);
}
ret = ppp_ops->create (iface);
g_return_val_if_fail (ret, NULL);
return ret;
}
gboolean
nm_ppp_manager_start (NMPPPManager *self,
NMActRequest *req,
const char *ppp_name,
guint32 timeout_secs,
guint baud_override,
GError **err)
{
g_return_val_if_fail (ppp_ops, FALSE);
return ppp_ops->start (self, req, ppp_name, timeout_secs, baud_override, err);
}
void
nm_ppp_manager_stop_async (NMPPPManager *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
g_return_if_fail (ppp_ops);
ppp_ops->stop_async (self, cancellable, callback, user_data);
}
gboolean
nm_ppp_manager_stop_finish (NMPPPManager *self,
GAsyncResult *res,
GError **error)
{
g_return_val_if_fail (ppp_ops, FALSE);
return ppp_ops->stop_finish (self, res, error);
}
void
nm_ppp_manager_stop_sync (NMPPPManager *self)
{
g_return_if_fail (ppp_ops);
ppp_ops->stop_sync (self);
}
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
/* NetworkManager -- Network link manager
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2016 Red Hat, Inc.
*/
#ifndef __NM_PPP_MANAGER_CALL_H__
#define __NM_PPP_MANAGER_CALL_H__
#include "nm-ppp-manager.h"
NMPPPManager * nm_ppp_manager_create (const char *iface,
GError **error);
gboolean nm_ppp_manager_start (NMPPPManager *self,
NMActRequest *req,
const char *ppp_name,
guint32 timeout_secs,
guint baud_override,
GError **error);
void nm_ppp_manager_stop_async (NMPPPManager *self,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
gboolean nm_ppp_manager_stop_finish (NMPPPManager *self,
GAsyncResult *res,
GError **error);
void nm_ppp_manager_stop_sync (NMPPPManager *self);
#endif /* __NM_PPP_MANAGER_CALL_H__ */
......@@ -49,7 +49,9 @@
#include "nm-act-request.h"
#include "nm-ip4-config.h"
#include "nm-ip6-config.h"
#include "nm-pppd-plugin.h"
#include "nm-ppp-plugin-api.h"
#include "nm-ppp-status.h"
#include "introspection/org.freedesktop.NetworkManager.PPP.h"
......@@ -59,6 +61,17 @@
/*****************************************************************************/
#define NM_TYPE_PPP_MANAGER (nm_ppp_manager_get_type ())
#define NM_PPP_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_PPP_MANAGER, NMPPPManager))
#define NM_PPP_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_PPP_MANAGER, NMPPPManagerClass))
#define NM_IS_PPP_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_PPP_MANAGER))
#define NM_IS_PPP_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_PPP_MANAGER))
#define NM_PPP_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_PPP_MANAGER, NMPPPManagerClass))
GType nm_ppp_manager_get_type (void);
/*****************************************************************************/
enum {
STATE_CHANGED,
IP4_CONFIG,
......@@ -98,9 +111,9 @@ struct _NMPPPManager {
NMPPPManagerPrivate _priv;
};
struct _NMPPPManagerClass {
typedef struct {
NMExportedObjectClass parent;
};
} NMPPPManagerClass;
G_DEFINE_TYPE (NMPPPManager, nm_ppp_manager, NM_TYPE_EXPORTED_OBJECT)
......@@ -887,13 +900,13 @@ pppoe_fill_defaults (NMSettingPpp *setting)
#endif
}
gboolean
nm_ppp_manager_start (NMPPPManager *manager,
NMActRequest *req,
const char *ppp_name,
guint32 timeout_secs,
guint baud_override,
GError **err)
static gboolean
_ppp_manager_start (NMPPPManager *manager,
NMActRequest *req,
const char *ppp_name,
guint32 timeout_secs,
guint baud_override,
GError **err)
{
NMPPPManagerPrivate *priv;
NMConnection *connection;
......@@ -919,6 +932,8 @@ nm_ppp_manager_start (NMPPPManager *manager,
return FALSE;
#endif
nm_exported_object_export (NM_EXPORTED_OBJECT (manager));
priv->pid = 0;
/* Make sure /dev/ppp exists (bgo #533064) */
......@@ -976,6 +991,9 @@ out:
if (ppp_cmd)
nm_cmd_line_destroy (ppp_cmd);
if (priv->pid <= 0)
nm_exported_object_unexport (NM_EXPORTED_OBJECT (manager));
return priv->pid > 0;
}
......@@ -1050,10 +1068,10 @@ stop_context_complete_if_cancelled (StopContext *ctx)
return FALSE;
}
gboolean
nm_ppp_manager_stop_finish (NMPPPManager *manager,
GAsyncResult *res,
GError **error)
static gboolean
_ppp_manager_stop_finish (NMPPPManager *manager,
GAsyncResult *res,
GError **error)
{
return !g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (res), error);
}
......@@ -1069,21 +1087,23 @@ kill_child_ready (pid_t pid,
stop_context_complete (ctx);
}
void
nm_ppp_manager_stop (NMPPPManager *manager,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
static void
_ppp_manager_stop_async (NMPPPManager *manager,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager);
StopContext *ctx;
nm_exported_object_unexport (NM_EXPORTED_OBJECT (manager));
ctx = g_slice_new0 (StopContext);
ctx->manager = g_object_ref (manager);
ctx->result = g_simple_async_result_new (G_OBJECT (manager),
callback,
user_data,
nm_ppp_manager_stop);
_ppp_manager_stop_async);
/* Setup cancellable */
ctx->cancellable = cancellable ? g_object_ref (cancellable) : NULL;
......@@ -1110,6 +1130,18 @@ nm_ppp_manager_stop (NMPPPManager *manager,
priv->pid = 0;
}
static void
_ppp_manager_stop_sync (NMPPPManager *manager)
{
NMExportedObject *exported = NM_EXPORTED_OBJECT (manager);
if (nm_exported_object_is_exported (exported))
nm_exported_object_unexport (exported);
_ppp_cleanup (manager);
_ppp_kill (manager);
}
/*****************************************************************************/
static void
......@@ -1153,8 +1185,8 @@ nm_ppp_manager_init (NMPPPManager *manager)
NM_PPP_MANAGER_GET_PRIVATE (manager)->monitor_fd = -1;
}
NMPPPManager *
nm_ppp_manager_new (const char *iface)
static NMPPPManager *
_ppp_manager_new (const char *iface)
{
g_return_val_if_fail (iface != NULL, NULL);
......@@ -1200,7 +1232,6 @@ nm_ppp_manager_class_init (NMPPPManagerClass *manager_class)
object_class->set_property = set_property;
exported_object_class->export_path = NM_DBUS_PATH "/PPP/%u";
exported_object_class->export_on_construction = TRUE;
obj_properties[PROP_PARENT_IFACE] =
g_param_spec_string (NM_PPP_MANAGER_PARENT_IFACE, "", "",
......@@ -1255,3 +1286,10 @@ nm_ppp_manager_class_init (NMPPPManagerClass *manager_class)
NULL);
}
NMPPPOps ppp_ops = {
.create = _ppp_manager_new,
.start = _ppp_manager_start,
.stop_async = _ppp_manager_stop_async,
.stop_finish = _ppp_manager_stop_finish,
.stop_sync = _ppp_manager_stop_sync,
};
......@@ -16,43 +16,15 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Copyright (C) 2008 Novell, Inc.
* Copyright (C) 2008 - 2010 Red Hat, Inc.
* Copyright (C) 2008 - 2016 Red Hat, Inc.
*/
#ifndef __NETWORKMANAGER_PPP_MANAGER_H__
#define __NETWORKMANAGER_PPP_MANAGER_H__
#define NM_TYPE_PPP_MANAGER (nm_ppp_manager_get_type ())
#define NM_PPP_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), NM_TYPE_PPP_MANAGER, NMPPPManager))
#define NM_PPP_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), NM_TYPE_PPP_MANAGER, NMPPPManagerClass))
#define NM_IS_PPP_MANAGER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), NM_TYPE_PPP_MANAGER))
#define NM_IS_PPP_MANAGER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), NM_TYPE_PPP_MANAGER))
#define NM_PPP_MANAGER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), NM_TYPE_PPP_MANAGER, NMPPPManagerClass))
#ifndef __NM_PPP_MANAGER_H__
#define __NM_PPP_MANAGER_H__
#define NM_PPP_MANAGER_PARENT_IFACE "parent-iface"
#define NM_PPP_MANAGER_STATE_CHANGED "state-changed"
typedef struct _NMPPPManager NMPPPManager;
typedef struct _NMPPPManagerClass NMPPPManagerClass;
GType nm_ppp_manager_get_type (void);
NMPPPManager *nm_ppp_manager_new (const char *iface);
gboolean nm_ppp_manager_start (NMPPPManager *manager,
NMActRequest *req,
const char *ppp_name,
guint32 timeout_secs,
guint baud_override,
GError **err);
void nm_ppp_manager_stop (NMPPPManager *manager,
GCancellable *cancellable,