diff options
| author | Michael Biebl <biebl@debian.org> | 2016-01-20 16:26:51 +0100 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2016-01-20 16:26:51 +0100 |
| commit | 494f296a3baab08522617b24b1f126d8f9a17502 (patch) | |
| tree | c8ef32fb0dd1c4ff35a0b38e787abb58692de0cd /src/ppp-manager | |
| parent | 54f6333410ffd570e62717d9e77c5c987175e397 (diff) | |
Imported Upstream version 1.1.90 upstream/1.1.90
Diffstat (limited to 'src/ppp-manager')
| -rw-r--r-- | src/ppp-manager/Makefile.am | 7 | ||||
| -rw-r--r-- | src/ppp-manager/Makefile.in | 25 | ||||
| -rw-r--r-- | src/ppp-manager/nm-ppp-manager.c | 420 | ||||
| -rw-r--r-- | src/ppp-manager/nm-ppp-manager.h | 11 | ||||
| -rw-r--r-- | src/ppp-manager/nm-pppd-plugin.c | 6 | ||||
| -rw-r--r-- | src/ppp-manager/nm-pppd-plugin.h | 2 |
6 files changed, 204 insertions, 267 deletions
diff --git a/src/ppp-manager/Makefile.am b/src/ppp-manager/Makefile.am index 5b1edc29..5cf908df 100644 --- a/src/ppp-manager/Makefile.am +++ b/src/ppp-manager/Makefile.am @@ -1,12 +1,13 @@ if WITH_PPP AM_CPPFLAGS = \ - -I${top_srcdir}/include \ - -I${top_builddir}/include \ + -I${top_srcdir}/shared \ + -I${top_builddir}/shared \ -I${top_srcdir}/libnm-core \ + -I${top_srcdir}/src \ -I${top_builddir}/libnm-core \ -DG_LOG_DOMAIN=\""nm-pppd-plugin"\" \ - -DNETWORKMANAGER_COMPILATION \ + -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ $(GLIB_CFLAGS) diff --git a/src/ppp-manager/Makefile.in b/src/ppp-manager/Makefile.in index 338dcff7..50e84429 100644 --- a/src/ppp-manager/Makefile.in +++ b/src/ppp-manager/Makefile.in @@ -232,7 +232,6 @@ BLUEZ5_LIBS = @BLUEZ5_LIBS@ CC = @CC@ CCDEPMODE = @CCDEPMODE@ CFLAGS = @CFLAGS@ -CKDB_PATH = @CKDB_PATH@ CODE_COVERAGE_CFLAGS = @CODE_COVERAGE_CFLAGS@ CODE_COVERAGE_ENABLED = @CODE_COVERAGE_ENABLED@ CODE_COVERAGE_LDFLAGS = @CODE_COVERAGE_LDFLAGS@ @@ -244,8 +243,6 @@ CXXDEPMODE = @CXXDEPMODE@ CXXFLAGS = @CXXFLAGS@ CYGPATH_W = @CYGPATH_W@ DBUS_CFLAGS = @DBUS_CFLAGS@ -DBUS_GLIB_100_CFLAGS = @DBUS_GLIB_100_CFLAGS@ -DBUS_GLIB_100_LIBS = @DBUS_GLIB_100_LIBS@ DBUS_LIBS = @DBUS_LIBS@ DBUS_SYS_DIR = @DBUS_SYS_DIR@ DEFS = @DEFS@ @@ -255,6 +252,7 @@ DHCPCD_PATH = @DHCPCD_PATH@ DISTRO_NETWORK_SERVICE = @DISTRO_NETWORK_SERVICE@ DLLTOOL = @DLLTOOL@ DNSMASQ_PATH = @DNSMASQ_PATH@ +DNSSEC_TRIGGER_SCRIPT = @DNSSEC_TRIGGER_SCRIPT@ DSYMUTIL = @DSYMUTIL@ DUMPBIN = @DUMPBIN@ ECHO_C = @ECHO_C@ @@ -309,16 +307,13 @@ INTROSPECTION_MAKEFILE = @INTROSPECTION_MAKEFILE@ INTROSPECTION_SCANNER = @INTROSPECTION_SCANNER@ INTROSPECTION_TYPELIBDIR = @INTROSPECTION_TYPELIBDIR@ IPTABLES_PATH = @IPTABLES_PATH@ -IWMX_SDK_CFLAGS = @IWMX_SDK_CFLAGS@ -IWMX_SDK_LIBS = @IWMX_SDK_LIBS@ KERNEL_FIRMWARE_DIR = @KERNEL_FIRMWARE_DIR@ LCOV = @LCOV@ LD = @LD@ LDFLAGS = @LDFLAGS@ +LIBAUDIT_CFLAGS = @LIBAUDIT_CFLAGS@ +LIBAUDIT_LIBS = @LIBAUDIT_LIBS@ LIBDL = @LIBDL@ -LIBGCRYPT_CFLAGS = @LIBGCRYPT_CFLAGS@ -LIBGCRYPT_CONFIG = @LIBGCRYPT_CONFIG@ -LIBGCRYPT_LIBS = @LIBGCRYPT_LIBS@ LIBICONV = @LIBICONV@ LIBINTL = @LIBINTL@ LIBM = @LIBM@ @@ -355,6 +350,8 @@ NEWT_LIBS = @NEWT_LIBS@ NM = @NM@ NMEDIT = @NMEDIT@ NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT = @NM_CONFIG_DEFAULT_AUTH_POLKIT_TEXT@ +NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT = @NM_CONFIG_DEFAULT_LOGGING_AUDIT_TEXT@ +NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT = @NM_CONFIG_LOGGING_BACKEND_DEFAULT_TEXT@ NM_MAJOR_VERSION = @NM_MAJOR_VERSION@ NM_MICRO_VERSION = @NM_MICRO_VERSION@ NM_MINOR_VERSION = @NM_MINOR_VERSION@ @@ -383,7 +380,6 @@ POLKIT_LIBS = @POLKIT_LIBS@ POSUB = @POSUB@ PPPD_PATH = @PPPD_PATH@ PPPD_PLUGIN_DIR = @PPPD_PLUGIN_DIR@ -PPPOE_PATH = @PPPOE_PATH@ QT_CFLAGS = @QT_CFLAGS@ QT_LIBS = @QT_LIBS@ RANLIB = @RANLIB@ @@ -398,6 +394,8 @@ SYSTEMD_200_CFLAGS = @SYSTEMD_200_CFLAGS@ SYSTEMD_200_LIBS = @SYSTEMD_200_LIBS@ SYSTEMD_INHIBIT_CFLAGS = @SYSTEMD_INHIBIT_CFLAGS@ SYSTEMD_INHIBIT_LIBS = @SYSTEMD_INHIBIT_LIBS@ +SYSTEMD_JOURNAL_CFLAGS = @SYSTEMD_JOURNAL_CFLAGS@ +SYSTEMD_JOURNAL_LIBS = @SYSTEMD_JOURNAL_LIBS@ SYSTEMD_LOGIN_CFLAGS = @SYSTEMD_LOGIN_CFLAGS@ SYSTEMD_LOGIN_LIBS = @SYSTEMD_LOGIN_LIBS@ SYSTEM_CA_PATH = @SYSTEM_CA_PATH@ @@ -458,6 +456,7 @@ mkdir_p = @mkdir_p@ nmbinary = @nmbinary@ nmconfdir = @nmconfdir@ nmdatadir = @nmdatadir@ +nmlibdir = @nmlibdir@ nmrundir = @nmrundir@ nmstatedir = @nmstatedir@ oldincludedir = @oldincludedir@ @@ -465,6 +464,7 @@ pdfdir = @pdfdir@ prefix = @prefix@ program_transform_name = @program_transform_name@ psdir = @psdir@ +runstatedir = @runstatedir@ sbindir = @sbindir@ sharedstatedir = @sharedstatedir@ srcdir = @srcdir@ @@ -481,12 +481,13 @@ with_netconfig = @with_netconfig@ with_resolvconf = @with_resolvconf@ with_valgrind = @with_valgrind@ @WITH_PPP_TRUE@AM_CPPFLAGS = \ -@WITH_PPP_TRUE@ -I${top_srcdir}/include \ -@WITH_PPP_TRUE@ -I${top_builddir}/include \ +@WITH_PPP_TRUE@ -I${top_srcdir}/shared \ +@WITH_PPP_TRUE@ -I${top_builddir}/shared \ @WITH_PPP_TRUE@ -I${top_srcdir}/libnm-core \ +@WITH_PPP_TRUE@ -I${top_srcdir}/src \ @WITH_PPP_TRUE@ -I${top_builddir}/libnm-core \ @WITH_PPP_TRUE@ -DG_LOG_DOMAIN=\""nm-pppd-plugin"\" \ -@WITH_PPP_TRUE@ -DNETWORKMANAGER_COMPILATION \ +@WITH_PPP_TRUE@ -DNETWORKMANAGER_COMPILATION=NM_NETWORKMANAGER_COMPILATION_INSIDE_DAEMON \ @WITH_PPP_TRUE@ -DNM_VERSION_MAX_ALLOWED=NM_VERSION_NEXT_STABLE \ @WITH_PPP_TRUE@ $(GLIB_CFLAGS) diff --git a/src/ppp-manager/nm-ppp-manager.c b/src/ppp-manager/nm-ppp-manager.c index d27b262e..10bc0fec 100644 --- a/src/ppp-manager/nm-ppp-manager.c +++ b/src/ppp-manager/nm-ppp-manager.c @@ -42,30 +42,13 @@ #include <linux/if.h> #include <linux/if_ppp.h> +#include "nm-default.h" #include "NetworkManagerUtils.h" -#include "nm-glib-compat.h" #include "nm-ppp-manager.h" -#include "nm-dbus-manager.h" -#include "nm-logging.h" #include "nm-platform.h" #include "nm-core-internal.h" -static void impl_ppp_manager_need_secrets (NMPPPManager *manager, - DBusGMethodInvocation *context); - -static gboolean impl_ppp_manager_set_state (NMPPPManager *manager, - guint32 state, - GError **err); - -static gboolean impl_ppp_manager_set_ip4_config (NMPPPManager *manager, - GHashTable *config, - GError **err); - -static gboolean impl_ppp_manager_set_ip6_config (NMPPPManager *manager, - GHashTable *config, - GError **err); - -#include "nm-ppp-manager-glue.h" +#include "nmdbus-ppp-manager.h" static void _ppp_cleanup (NMPPPManager *manager); static void _ppp_kill (NMPPPManager *manager); @@ -75,13 +58,12 @@ static void _ppp_kill (NMPPPManager *manager); typedef struct { GPid pid; - char *dbus_path; char *parent_iface; NMActRequest *act_req; - DBusGMethodInvocation *pending_secrets_context; - guint32 secrets_id; + GDBusMethodInvocation *pending_secrets_context; + NMActRequestGetSecretsCallId secrets_id; const char *secrets_setting_name; guint32 ppp_watch_id; @@ -95,7 +77,7 @@ typedef struct { #define NM_PPP_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_PPP_MANAGER, NMPPPManagerPrivate)) -G_DEFINE_TYPE (NMPPPManager, nm_ppp_manager, G_TYPE_OBJECT) +G_DEFINE_TYPE (NMPPPManager, nm_ppp_manager, NM_TYPE_EXPORTED_OBJECT) enum { STATE_CHANGED, @@ -121,20 +103,6 @@ nm_ppp_manager_init (NMPPPManager *manager) } static void -constructed (GObject *object) -{ - NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (object); - DBusGConnection *connection; - static guint32 counter = 0; - - priv->dbus_path = g_strdup_printf (NM_DBUS_PATH "/PPP/%d", counter++); - connection = nm_dbus_manager_get_connection (nm_dbus_manager_get ()); - dbus_g_connection_register_g_object (connection, priv->dbus_path, object); - - G_OBJECT_CLASS (nm_ppp_manager_parent_class)->constructed (object); -} - -static void dispose (GObject *object) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (object); @@ -191,68 +159,6 @@ get_property (GObject *object, guint prop_id, } } -static void -nm_ppp_manager_class_init (NMPPPManagerClass *manager_class) -{ - GObjectClass *object_class = G_OBJECT_CLASS (manager_class); - - g_type_class_add_private (manager_class, sizeof (NMPPPManagerPrivate)); - - object_class->constructed = constructed; - object_class->dispose = dispose; - object_class->finalize = finalize; - object_class->get_property = get_property; - object_class->set_property = set_property; - - /* Properties */ - g_object_class_install_property - (object_class, PROP_PARENT_IFACE, - g_param_spec_string (NM_PPP_MANAGER_PARENT_IFACE, "", "", - NULL, - G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | - G_PARAM_STATIC_STRINGS)); - - /* signals */ - signals[STATE_CHANGED] = - g_signal_new ("state-changed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMPPPManagerClass, state_changed), - NULL, NULL, NULL, - G_TYPE_NONE, 1, - G_TYPE_UINT); - - signals[IP4_CONFIG] = - g_signal_new ("ip4-config", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMPPPManagerClass, ip4_config), - NULL, NULL, NULL, - G_TYPE_NONE, 2, - G_TYPE_STRING, - G_TYPE_OBJECT); - - signals[IP6_CONFIG] = - g_signal_new ("ip6-config", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMPPPManagerClass, ip6_config), - NULL, NULL, NULL, - G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_OBJECT); - - signals[STATS] = - g_signal_new ("stats", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_FIRST, - G_STRUCT_OFFSET (NMPPPManagerClass, stats), - NULL, NULL, NULL, - G_TYPE_NONE, 2, - G_TYPE_UINT, G_TYPE_UINT); - - dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (manager_class), - &dbus_glib_nm_ppp_manager_object_info); -} - NMPPPManager * nm_ppp_manager_new (const char *iface) { @@ -315,11 +221,8 @@ static void remove_timeout_handler (NMPPPManager *manager) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); - - if (priv->ppp_timeout_handler) { - g_source_remove (priv->ppp_timeout_handler); - priv->ppp_timeout_handler = 0; - } + + nm_clear_g_source (&priv->ppp_timeout_handler); } static void @@ -327,11 +230,10 @@ cancel_get_secrets (NMPPPManager *self) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); - if (priv->secrets_id) { + if (priv->secrets_id) nm_act_request_cancel_secrets (priv->act_req, priv->secrets_id); - priv->secrets_id = 0; - } - priv->secrets_setting_name = NULL; + + g_return_if_fail (!priv->secrets_id && !priv->secrets_setting_name); } static gboolean @@ -395,8 +297,8 @@ extract_details_from_connection (NMConnection *connection, static void ppp_secrets_cb (NMActRequest *req, - guint32 call_id, - NMConnection *connection, + NMActRequestGetSecretsCallId call_id, + NMSettingsConnection *settings_connection, /* unused (we pass NULL here) */ GError *error, gpointer user_data) { @@ -405,21 +307,26 @@ ppp_secrets_cb (NMActRequest *req, const char *username = NULL; const char *password = NULL; GError *local = NULL; + NMConnection *applied_connection; g_return_if_fail (priv->pending_secrets_context != NULL); g_return_if_fail (req == priv->act_req); g_return_if_fail (call_id == priv->secrets_id); + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) + goto out; + if (error) { nm_log_warn (LOGD_PPP, "%s", error->message); - dbus_g_method_return_error (priv->pending_secrets_context, error); + g_dbus_method_invocation_return_gerror (priv->pending_secrets_context, error); goto out; } - if (!extract_details_from_connection (connection, priv->secrets_setting_name, &username, &password, &local)) { + applied_connection = nm_act_request_get_applied_connection (req); + + if (!extract_details_from_connection (applied_connection, priv->secrets_setting_name, &username, &password, &local)) { nm_log_warn (LOGD_PPP, "%s", local->message); - dbus_g_method_return_error (priv->pending_secrets_context, local); - g_clear_error (&local); + g_dbus_method_invocation_take_error (priv->pending_secrets_context, local); goto out; } @@ -429,20 +336,22 @@ ppp_secrets_cb (NMActRequest *req, * against libnm just to parse this. So instead, let's just send what * it needs. */ - dbus_g_method_return (priv->pending_secrets_context, username, password); + g_dbus_method_invocation_return_value ( + priv->pending_secrets_context, + g_variant_new ("(ss)", username ? username : "", password ? password : "")); out: priv->pending_secrets_context = NULL; - priv->secrets_id = 0; + priv->secrets_id = NULL; priv->secrets_setting_name = NULL; } static void impl_ppp_manager_need_secrets (NMPPPManager *manager, - DBusGMethodInvocation *context) + GDBusMethodInvocation *context) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); - NMConnection *connection; + NMConnection *applied_connection; const char *username = NULL; const char *password = NULL; guint32 tries; @@ -450,20 +359,20 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager, GError *error = NULL; NMSecretAgentGetSecretsFlags flags = NM_SECRET_AGENT_GET_SECRETS_FLAG_ALLOW_INTERACTION; - connection = nm_act_request_get_connection (priv->act_req); + nm_active_connection_clear_secrets (NM_ACTIVE_CONNECTION (priv->act_req)); - nm_connection_clear_secrets (connection); - priv->secrets_setting_name = nm_connection_need_secrets (connection, &hints); + applied_connection = nm_act_request_get_applied_connection (priv->act_req); + + priv->secrets_setting_name = nm_connection_need_secrets (applied_connection, &hints); if (!priv->secrets_setting_name) { /* Use existing secrets from the connection */ - if (extract_details_from_connection (connection, NULL, &username, &password, &error)) { + if (extract_details_from_connection (applied_connection, NULL, &username, &password, &error)) { /* Send existing secrets to the PPP plugin */ priv->pending_secrets_context = context; - ppp_secrets_cb (priv->act_req, priv->secrets_id, connection, NULL, manager); + ppp_secrets_cb (priv->act_req, priv->secrets_id, NULL, NULL, manager); } else { nm_log_warn (LOGD_PPP, "%s", error->message); - dbus_g_method_return_error (priv->pending_secrets_context, error); - g_clear_error (&error); + g_dbus_method_invocation_take_error (priv->pending_secrets_context, error); } return; } @@ -472,7 +381,7 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager, * appear to ask a few times when they actually don't even care what you * pass back. */ - tries = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (connection), PPP_MANAGER_SECRET_TRIES)); + tries = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (applied_connection), PPP_MANAGER_SECRET_TRIES)); if (tries > 1) flags |= NM_SECRET_AGENT_GET_SECRETS_FLAG_REQUEST_NEW; @@ -482,88 +391,86 @@ impl_ppp_manager_need_secrets (NMPPPManager *manager, hints ? g_ptr_array_index (hints, 0) : NULL, ppp_secrets_cb, manager); - g_object_set_data (G_OBJECT (connection), PPP_MANAGER_SECRET_TRIES, GUINT_TO_POINTER (++tries)); + g_object_set_data (G_OBJECT (applied_connection), PPP_MANAGER_SECRET_TRIES, GUINT_TO_POINTER (++tries)); priv->pending_secrets_context = context; if (hints) g_ptr_array_free (hints, TRUE); } -static gboolean impl_ppp_manager_set_state (NMPPPManager *manager, - guint32 state, - GError **err) +static void +impl_ppp_manager_set_state (NMPPPManager *manager, + GDBusMethodInvocation *context, + guint32 state) { g_signal_emit (manager, signals[STATE_CHANGED], 0, state); - return TRUE; + g_dbus_method_invocation_return_value (context, NULL); } static gboolean set_ip_config_common (NMPPPManager *self, - GHashTable *hash, + GVariant *config_dict, const char *iface_prop, guint32 *out_mtu) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); - NMConnection *connection; + NMConnection *applied_connection; NMSettingPpp *s_ppp; - GValue *val; + const char *iface; - val = g_hash_table_lookup (hash, iface_prop); - if (!val || !G_VALUE_HOLDS_STRING (val)) { + if (!g_variant_lookup (config_dict, iface_prop, "&s", &iface)) { nm_log_err (LOGD_PPP, "no interface received!"); return FALSE; } if (priv->ip_iface == NULL) - priv->ip_iface = g_value_dup_string (val); + priv->ip_iface = g_strdup (iface); /* Got successful IP config; obviously the secrets worked */ - connection = nm_act_request_get_connection (priv->act_req); - g_assert (connection); - g_object_set_data (G_OBJECT (connection), PPP_MANAGER_SECRET_TRIES, NULL); + applied_connection = nm_act_request_get_applied_connection (priv->act_req); + g_object_set_data (G_OBJECT (applied_connection), PPP_MANAGER_SECRET_TRIES, NULL); - /* Get any custom MTU */ - s_ppp = nm_connection_get_setting_ppp (connection); - if (s_ppp && out_mtu) - *out_mtu = nm_setting_ppp_get_mtu (s_ppp); + if (out_mtu) { + /* Get any custom MTU */ + s_ppp = nm_connection_get_setting_ppp (applied_connection); + *out_mtu = s_ppp ? nm_setting_ppp_get_mtu (s_ppp) : 0; + } monitor_stats (self); return TRUE; } -static gboolean +static void impl_ppp_manager_set_ip4_config (NMPPPManager *manager, - GHashTable *config_hash, - GError **err) + GDBusMethodInvocation *context, + GVariant *config_dict) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMIP4Config *config; NMPlatformIP4Address address; - GValue *val; - int i; - guint32 mtu = 0; + guint32 u32; + GVariantIter *iter; nm_log_info (LOGD_PPP, "PPP manager (IPv4 Config Get) reply received."); remove_timeout_handler (manager); - config = nm_ip4_config_new (); + config = nm_ip4_config_new (nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->ip_iface)); + memset (&address, 0, sizeof (address)); address.plen = 32; - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_GATEWAY); - if (val) { - nm_ip4_config_set_gateway (config, g_value_get_uint (val)); - address.peer_address = g_value_get_uint (val); - } + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_ADDRESS, "u", &u32)) + address.address = u32; - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_ADDRESS); - if (val) - address.address = g_value_get_uint (val); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_GATEWAY, "u", &u32)) { + nm_ip4_config_set_gateway (config, u32); + address.peer_address = u32; + } else + address.peer_address = address.address; - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_PREFIX); - if (val) - address.plen = g_value_get_uint (val); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_PREFIX, "u", &u32)) + address.plen = u32; if (address.address && address.plen) { address.source = NM_IP_CONFIG_SOURCE_PPP; @@ -573,55 +480,47 @@ impl_ppp_manager_set_ip4_config (NMPPPManager *manager, goto out; } - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_DNS); - if (val) { - GArray *dns = (GArray *) g_value_get_boxed (val); - - for (i = 0; i < dns->len; i++) - nm_ip4_config_add_nameserver (config, g_array_index (dns, guint, i)); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_DNS, "au", &iter)) { + while (g_variant_iter_next (iter, "u", &u32)) + nm_ip4_config_add_nameserver (config, u32); + g_variant_iter_free (iter); } - val = (GValue *) g_hash_table_lookup (config_hash, NM_PPP_IP4_CONFIG_WINS); - if (val) { - GArray *wins = (GArray *) g_value_get_boxed (val); - - for (i = 0; i < wins->len; i++) - nm_ip4_config_add_wins (config, g_array_index (wins, guint, i)); + if (g_variant_lookup (config_dict, NM_PPP_IP4_CONFIG_WINS, "au", &iter)) { + while (g_variant_iter_next (iter, "u", &u32)) + nm_ip4_config_add_wins (config, u32); + g_variant_iter_free (iter); } - if (!set_ip_config_common (manager, config_hash, NM_PPP_IP4_CONFIG_INTERFACE, &mtu)) + if (!set_ip_config_common (manager, config_dict, NM_PPP_IP4_CONFIG_INTERFACE, &u32)) goto out; - if (mtu) - nm_ip4_config_set_mtu (config, mtu, NM_IP_CONFIG_SOURCE_PPP); + if (u32) + nm_ip4_config_set_mtu (config, u32, NM_IP_CONFIG_SOURCE_PPP); /* Push the IP4 config up to the device */ g_signal_emit (manager, signals[IP4_CONFIG], 0, priv->ip_iface, config); out: g_object_unref (config); - return TRUE; + g_dbus_method_invocation_return_value (context, NULL); } /* Converts the named Interface Identifier item to an IPv6 LL address and * returns the IID. */ static gboolean -iid_value_to_ll6_addr (GHashTable *hash, +iid_value_to_ll6_addr (GVariant *dict, const char *prop, struct in6_addr *out_addr, NMUtilsIPv6IfaceId *out_iid) { - GValue *val; guint64 iid; - val = g_hash_table_lookup (hash, prop); - if (!val || !G_VALUE_HOLDS (val, G_TYPE_UINT64)) { + if (!g_variant_lookup (dict, prop, "t", &iid)) { nm_log_dbg (LOGD_PPP, "pppd plugin property '%s' missing or not a uint64", prop); return FALSE; } - - iid = g_value_get_uint64 (val); g_return_val_if_fail (iid != 0, FALSE); /* Construct an IPv6 LL address from the interface identifier. See @@ -636,10 +535,10 @@ iid_value_to_ll6_addr (GHashTable *hash, return TRUE; } -static gboolean +static void impl_ppp_manager_set_ip6_config (NMPPPManager *manager, - GHashTable *hash, - GError **err) + GDBusMethodInvocation *context, + GVariant *config_dict) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (manager); NMIP6Config *config; @@ -651,20 +550,20 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager, remove_timeout_handler (manager); - config = nm_ip6_config_new (); + config = nm_ip6_config_new (nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->ip_iface)); memset (&addr, 0, sizeof (addr)); addr.plen = 64; - if (iid_value_to_ll6_addr (hash, NM_PPP_IP6_CONFIG_PEER_IID, &a, NULL)) { + if (iid_value_to_ll6_addr (config_dict, NM_PPP_IP6_CONFIG_PEER_IID, &a, NULL)) { nm_ip6_config_set_gateway (config, &a); addr.peer_address = a; } - if (iid_value_to_ll6_addr (hash, NM_PPP_IP6_CONFIG_OUR_IID, &addr.address, &iid)) { + if (iid_value_to_ll6_addr (config_dict, NM_PPP_IP6_CONFIG_OUR_IID, &addr.address, &iid)) { nm_ip6_config_add_address (config, &addr); - if (set_ip_config_common (manager, hash, NM_PPP_IP6_CONFIG_INTERFACE, NULL)) { + if (set_ip_config_common (manager, config_dict, NM_PPP_IP6_CONFIG_INTERFACE, NULL)) { /* Push the IPv6 config and interface identifier up to the device */ g_signal_emit (manager, signals[IP6_CONFIG], 0, priv->ip_iface, &iid, config); } @@ -672,7 +571,77 @@ impl_ppp_manager_set_ip6_config (NMPPPManager *manager, nm_log_err (LOGD_PPP, "invalid IPv6 address received!"); g_object_unref (config); - return TRUE; + g_dbus_method_invocation_return_value (context, NULL); +} + +static void +nm_ppp_manager_class_init (NMPPPManagerClass *manager_class) +{ + GObjectClass *object_class = G_OBJECT_CLASS (manager_class); + NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (manager_class); + + g_type_class_add_private (manager_class, sizeof (NMPPPManagerPrivate)); + + exported_object_class->export_path = NM_DBUS_PATH "/PPP"; + exported_object_class->export_on_construction = TRUE; + + object_class->dispose = dispose; + object_class->finalize = finalize; + object_class->get_property = get_property; + object_class->set_property = set_property; + + /* Properties */ + g_object_class_install_property + (object_class, PROP_PARENT_IFACE, + g_param_spec_string (NM_PPP_MANAGER_PARENT_IFACE, "", "", + NULL, + G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | + G_PARAM_STATIC_STRINGS)); + + /* signals */ + signals[STATE_CHANGED] = + g_signal_new (NM_PPP_MANAGER_STATE_CHANGED, + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMPPPManagerClass, state_changed), + NULL, NULL, NULL, + G_TYPE_NONE, 1, + G_TYPE_UINT); + + signals[IP4_CONFIG] = + g_signal_new ("ip4-config", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMPPPManagerClass, ip4_config), + NULL, NULL, NULL, + G_TYPE_NONE, 2, + G_TYPE_STRING, + G_TYPE_OBJECT); + + signals[IP6_CONFIG] = + g_signal_new ("ip6-config", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMPPPManagerClass, ip6_config), + NULL, NULL, NULL, + G_TYPE_NONE, 3, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_OBJECT); + + signals[STATS] = + g_signal_new ("stats", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (NMPPPManagerClass, stats), + NULL, NULL, NULL, + G_TYPE_NONE, 2, + G_TYPE_UINT, G_TYPE_UINT); + + nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (manager_class), + NMDBUS_TYPE_PPP_MANAGER_SKELETON, + "NeedSecrets", impl_ppp_manager_need_secrets, + "SetIp4Config", impl_ppp_manager_set_ip4_config, + "SetIp6Config", impl_ppp_manager_set_ip6_config, + "SetState", impl_ppp_manager_set_state, + NULL); } /*******************************************/ @@ -828,6 +797,7 @@ ppp_watch_cb (GPid pid, gint status, gpointer user_data) nm_log_dbg (LOGD_PPP, "pppd pid %d cleaned up", priv->pid); priv->pid = 0; + priv->ppp_watch_id = 0; g_signal_emit (manager, signals[STATE_CHANGED], 0, NM_PPP_STATUS_DEAD); } @@ -854,7 +824,7 @@ create_pppd_cmd_line (NMPPPManager *self, GError **err) { NMPPPManagerPrivate *priv = NM_PPP_MANAGER_GET_PRIVATE (self); - const char *pppd_binary = NULL, *pppoe_binary = NULL; + const char *pppd_binary = NULL; NMCmdLine *cmd; gboolean ppp_debug; @@ -864,14 +834,6 @@ create_pppd_cmd_line (NMPPPManager *self, if (!pppd_binary) return NULL; - if ( pppoe - || ( adsl - && !strcmp (nm_setting_adsl_get_protocol (adsl), NM_SETTING_ADSL_PROTOCOL_PPPOE))) { - pppoe_binary = nm_utils_find_helper ("pppoe", NULL, err); - if (!pppoe_binary) - return NULL; - } - /* Create pppd command line */ cmd = nm_cmd_line_new (); nm_cmd_line_add_string (cmd, pppd_binary); @@ -899,30 +861,21 @@ create_pppd_cmd_line (NMPPPManager *self, } if (pppoe) { - GString *pppoe_arg; + char *dev_str; const char *pppoe_service; - char *quoted; - g_assert (pppoe_binary != NULL); - pppoe_arg = g_string_new (pppoe_binary); + nm_cmd_line_add_string (cmd, "plugin"); + nm_cmd_line_add_string (cmd, "rp-pppoe.so"); - g_string_append (pppoe_arg, " -I "); - quoted = g_shell_quote (priv->parent_iface); - g_string_append (pppoe_arg, quoted); - g_free (quoted); + dev_str = g_strdup_printf ("nic-%s", priv->parent_iface); + nm_cmd_line_add_string (cmd, dev_str); + g_free (dev_str); pppoe_service = nm_setting_pppoe_get_service (pppoe); if (pppoe_service) { - g_string_append (pppoe_arg, " -S "); - quoted = g_shell_quote (pppoe_service); - g_string_append (pppoe_arg, quoted); - g_free (quoted); + nm_cmd_line_add_string (cmd, "rp_pppoe_service"); + nm_cmd_line_add_string (cmd, pppoe_service); } - - nm_cmd_line_add_string (cmd, "pty"); - nm_cmd_line_add_string (cmd, pppoe_arg->str); - - g_string_free (pppoe_arg, TRUE); } else if (adsl) { const gchar *protocol = nm_setting_adsl_get_protocol (adsl); @@ -945,14 +898,9 @@ create_pppd_cmd_line (NMPPPManager *self, nm_cmd_line_add_string (cmd, "vc-encaps"); } else if (!strcmp (protocol, NM_SETTING_ADSL_PROTOCOL_PPPOE)) { - char *pppoe_arg; - - g_assert (pppoe_binary != NULL); - - pppoe_arg = g_strdup_printf ("%s -I %s", pppoe_binary, priv->parent_iface); - nm_cmd_line_add_string (cmd, "pty"); - nm_cmd_line_add_string (cmd, pppoe_arg); - g_free (pppoe_arg); + nm_cmd_line_add_string (cmd, "plugin"); + nm_cmd_line_add_string (cmd, "rp-pppoe.so"); + nm_cmd_line_add_string (cmd, priv->parent_iface); } nm_cmd_line_add_string (cmd, "noipdefault"); @@ -1022,7 +970,7 @@ create_pppd_cmd_line (NMPPPManager *self, nm_cmd_line_add_int (cmd, 0); nm_cmd_line_add_string (cmd, "ipparam"); - nm_cmd_line_add_string (cmd, priv->dbus_path); + nm_cmd_line_add_string (cmd, nm_exported_object_get_path (NM_EXPORTED_OBJECT (self))); nm_cmd_line_add_string (cmd, "plugin"); nm_cmd_line_add_string (cmd, NM_PPPD_PLUGIN); @@ -1094,7 +1042,7 @@ nm_ppp_manager_start (NMPPPManager *manager, if (stat ("/dev/ppp", &st) || !S_ISCHR (st.st_mode)) nm_utils_modprobe (NULL, FALSE, "ppp_generic", NULL); - connection = nm_act_request_get_connection (req); + connection = nm_act_request_get_applied_connection (req); g_assert (connection); s_ppp = nm_connection_get_setting_ppp (connection); @@ -1174,10 +1122,7 @@ _ppp_cleanup (NMPPPManager *manager) cancel_get_secrets (manager); - if (priv->monitor_id) { - g_source_remove (priv->monitor_id); - priv->monitor_id = 0; - } + nm_clear_g_source (&priv->monitor_id); if (priv->monitor_fd >= 0) { /* Get the stats one last time */ @@ -1186,15 +1131,8 @@ _ppp_cleanup (NMPPPManager *manager) priv->monitor_fd = -1; } - if (priv->ppp_timeout_handler) { - g_source_remove (priv->ppp_timeout_handler); - priv->ppp_timeout_handler = 0; - } - - if (priv->ppp_watch_id) { - g_source_remove (priv->ppp_watch_id); - priv->ppp_watch_id = 0; - } + nm_clear_g_source (&priv->ppp_timeout_handler); + nm_clear_g_source (&priv->ppp_watch_id); } /***********************************************************/ diff --git a/src/ppp-manager/nm-ppp-manager.h b/src/ppp-manager/nm-ppp-manager.h index f8cbda13..188be84e 100644 --- a/src/ppp-manager/nm-ppp-manager.h +++ b/src/ppp-manager/nm-ppp-manager.h @@ -22,10 +22,8 @@ #ifndef __NETWORKMANAGER_PPP_MANAGER_H__ #define __NETWORKMANAGER_PPP_MANAGER_H__ -#include <glib.h> -#include <glib-object.h> -#include <gio/gio.h> +#include "nm-exported-object.h" #include "nm-ppp-status.h" #include "nm-activation-request.h" #include "nm-connection.h" @@ -43,12 +41,15 @@ #define NM_PPP_MANAGER_PARENT_IFACE "parent-iface" +/* signals */ +#define NM_PPP_MANAGER_STATE_CHANGED "state-changed" + typedef struct { - GObject parent; + NMExportedObject parent; } NMPPPManager; typedef struct { - GObjectClass parent; + NMExportedObjectClass parent; /* Signals */ void (*state_changed) (NMPPPManager *manager, NMPPPStatus status); diff --git a/src/ppp-manager/nm-pppd-plugin.c b/src/ppp-manager/nm-pppd-plugin.c index d5e8d707..1f1016ae 100644 --- a/src/ppp-manager/nm-pppd-plugin.c +++ b/src/ppp-manager/nm-pppd-plugin.c @@ -29,12 +29,12 @@ #include <netinet/in.h> #include <arpa/inet.h> #include <dlfcn.h> -#include <gio/gio.h> #define INET6 #include <pppd/eui64.h> #include <pppd/ipv6cp.h> +#include "nm-default.h" #include "nm-dbus-interface.h" #include "nm-pppd-plugin.h" #include "nm-ppp-status.h" @@ -372,9 +372,7 @@ plugin_init (void) GDBusConnection *bus; GError *err = NULL; -#if !GLIB_CHECK_VERSION (2, 35, 0) - g_type_init (); -#endif + nm_g_type_init (); g_message ("nm-ppp-plugin: (%s): initializing", __func__); diff --git a/src/ppp-manager/nm-pppd-plugin.h b/src/ppp-manager/nm-pppd-plugin.h index 2c3073e4..1a2ea09e 100644 --- a/src/ppp-manager/nm-pppd-plugin.h +++ b/src/ppp-manager/nm-pppd-plugin.h @@ -32,5 +32,3 @@ #define NM_PPP_IP6_CONFIG_OUR_IID "our-iid" #define NM_PPP_IP6_CONFIG_PEER_IID "peer-iid" -#define DBUS_TYPE_EUI64 (dbus_g_type_get_collection ("GByteArray", G_TYPE_UINT8)) - |