core: split dispatcher into its own file
This commit is contained in:
@@ -193,7 +193,9 @@ NetworkManager_SOURCES = \
|
|||||||
nm-session-utils.c \
|
nm-session-utils.c \
|
||||||
nm-session-utils.h \
|
nm-session-utils.h \
|
||||||
nm-connection-provider.h \
|
nm-connection-provider.h \
|
||||||
nm-connection-provider.c
|
nm-connection-provider.c \
|
||||||
|
nm-dispatcher.c \
|
||||||
|
nm-dispatcher.h
|
||||||
|
|
||||||
if WITH_CONCHECK
|
if WITH_CONCHECK
|
||||||
NetworkManager_SOURCES += nm-connectivity.c nm-connectivity.h
|
NetworkManager_SOURCES += nm-connectivity.c nm-connectivity.h
|
||||||
|
@@ -22,7 +22,6 @@
|
|||||||
#include <glib.h>
|
#include <glib.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -32,9 +31,6 @@
|
|||||||
#include "nm-utils.h"
|
#include "nm-utils.h"
|
||||||
#include "nm-logging.h"
|
#include "nm-logging.h"
|
||||||
#include "nm-device.h"
|
#include "nm-device.h"
|
||||||
#include "nm-dbus-manager.h"
|
|
||||||
#include "nm-dispatcher-action.h"
|
|
||||||
#include "nm-dbus-glib-types.h"
|
|
||||||
#include "nm-setting-connection.h"
|
#include "nm-setting-connection.h"
|
||||||
#include "nm-setting-ip4-config.h"
|
#include "nm-setting-ip4-config.h"
|
||||||
#include "nm-setting-ip6-config.h"
|
#include "nm-setting-ip6-config.h"
|
||||||
@@ -368,221 +364,6 @@ nm_utils_merge_ip6_config (NMIP6Config *ip6_config, NMSettingIP6Config *setting)
|
|||||||
nm_ip6_config_set_never_default (ip6_config, TRUE);
|
nm_ip6_config_set_never_default (ip6_config, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
dump_object_to_props (GObject *object, GHashTable *hash)
|
|
||||||
{
|
|
||||||
GParamSpec **pspecs;
|
|
||||||
guint len = 0, i;
|
|
||||||
|
|
||||||
pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (object), &len);
|
|
||||||
for (i = 0; i < len; i++) {
|
|
||||||
value_hash_add_object_property (hash,
|
|
||||||
pspecs[i]->name,
|
|
||||||
object,
|
|
||||||
pspecs[i]->name,
|
|
||||||
pspecs[i]->value_type);
|
|
||||||
}
|
|
||||||
g_free (pspecs);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
dump_dhcp4_to_props (NMDHCP4Config *config, GHashTable *hash)
|
|
||||||
{
|
|
||||||
GSList *options, *iter;
|
|
||||||
|
|
||||||
options = nm_dhcp4_config_list_options (config);
|
|
||||||
for (iter = options; iter; iter = g_slist_next (iter)) {
|
|
||||||
const char *option = (const char *) iter->data;
|
|
||||||
const char *val;
|
|
||||||
|
|
||||||
val = nm_dhcp4_config_get_option (config, option);
|
|
||||||
value_hash_add_str (hash, option, val);
|
|
||||||
}
|
|
||||||
g_slist_free (options);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
dump_dhcp6_to_props (NMDHCP6Config *config, GHashTable *hash)
|
|
||||||
{
|
|
||||||
GSList *options, *iter;
|
|
||||||
|
|
||||||
options = nm_dhcp6_config_list_options (config);
|
|
||||||
for (iter = options; iter; iter = g_slist_next (iter)) {
|
|
||||||
const char *option = (const char *) iter->data;
|
|
||||||
const char *val;
|
|
||||||
|
|
||||||
val = nm_dhcp6_config_get_option (config, option);
|
|
||||||
value_hash_add_str (hash, option, val);
|
|
||||||
}
|
|
||||||
g_slist_free (options);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
fill_device_props (NMDevice *device,
|
|
||||||
GHashTable *dev_hash,
|
|
||||||
GHashTable *ip4_hash,
|
|
||||||
GHashTable *ip6_hash,
|
|
||||||
GHashTable *dhcp4_hash,
|
|
||||||
GHashTable *dhcp6_hash)
|
|
||||||
{
|
|
||||||
NMIP4Config *ip4_config;
|
|
||||||
NMIP6Config *ip6_config;
|
|
||||||
NMDHCP4Config *dhcp4_config;
|
|
||||||
NMDHCP6Config *dhcp6_config;
|
|
||||||
|
|
||||||
/* If the action is for a VPN, send the VPN's IP interface instead of the device's */
|
|
||||||
value_hash_add_str (dev_hash, NMD_DEVICE_PROPS_IP_INTERFACE, nm_device_get_ip_iface (device));
|
|
||||||
value_hash_add_str (dev_hash, NMD_DEVICE_PROPS_INTERFACE, nm_device_get_iface (device));
|
|
||||||
value_hash_add_uint (dev_hash, NMD_DEVICE_PROPS_TYPE, nm_device_get_device_type (device));
|
|
||||||
value_hash_add_uint (dev_hash, NMD_DEVICE_PROPS_STATE, nm_device_get_state (device));
|
|
||||||
value_hash_add_object_path (dev_hash, NMD_DEVICE_PROPS_PATH, nm_device_get_path (device));
|
|
||||||
|
|
||||||
ip4_config = nm_device_get_ip4_config (device);
|
|
||||||
if (ip4_config)
|
|
||||||
dump_object_to_props (G_OBJECT (ip4_config), ip4_hash);
|
|
||||||
|
|
||||||
ip6_config = nm_device_get_ip6_config (device);
|
|
||||||
if (ip6_config)
|
|
||||||
dump_object_to_props (G_OBJECT (ip6_config), ip6_hash);
|
|
||||||
|
|
||||||
dhcp4_config = nm_device_get_dhcp4_config (device);
|
|
||||||
if (dhcp4_config)
|
|
||||||
dump_dhcp4_to_props (dhcp4_config, dhcp4_hash);
|
|
||||||
|
|
||||||
dhcp6_config = nm_device_get_dhcp6_config (device);
|
|
||||||
if (dhcp6_config)
|
|
||||||
dump_dhcp6_to_props (dhcp6_config, dhcp6_hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
fill_vpn_props (NMIP4Config *ip4_config,
|
|
||||||
NMIP6Config *ip6_config,
|
|
||||||
GHashTable *ip4_hash,
|
|
||||||
GHashTable *ip6_hash)
|
|
||||||
{
|
|
||||||
if (ip4_config)
|
|
||||||
dump_object_to_props (G_OBJECT (ip4_config), ip4_hash);
|
|
||||||
if (ip6_config)
|
|
||||||
dump_object_to_props (G_OBJECT (ip6_config), ip6_hash);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
dispatcher_done_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
|
|
||||||
{
|
|
||||||
dbus_g_proxy_end_call (proxy, call, NULL, G_TYPE_INVALID);
|
|
||||||
g_object_unref (proxy);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
nm_utils_call_dispatcher (const char *action,
|
|
||||||
NMConnection *connection,
|
|
||||||
NMDevice *device,
|
|
||||||
const char *vpn_iface,
|
|
||||||
NMIP4Config *vpn_ip4_config,
|
|
||||||
NMIP6Config *vpn_ip6_config)
|
|
||||||
{
|
|
||||||
NMDBusManager *dbus_mgr;
|
|
||||||
DBusGProxy *proxy;
|
|
||||||
DBusGConnection *g_connection;
|
|
||||||
GHashTable *connection_hash;
|
|
||||||
GHashTable *connection_props;
|
|
||||||
GHashTable *device_props;
|
|
||||||
GHashTable *device_ip4_props;
|
|
||||||
GHashTable *device_ip6_props;
|
|
||||||
GHashTable *device_dhcp4_props;
|
|
||||||
GHashTable *device_dhcp6_props;
|
|
||||||
GHashTable *vpn_ip4_props;
|
|
||||||
GHashTable *vpn_ip6_props;
|
|
||||||
|
|
||||||
g_return_if_fail (action != NULL);
|
|
||||||
|
|
||||||
/* All actions except 'hostname' require a device */
|
|
||||||
if (strcmp (action, "hostname") != 0)
|
|
||||||
g_return_if_fail (NM_IS_DEVICE (device));
|
|
||||||
/* VPN actions require at least an IPv4 config (for now) */
|
|
||||||
if (strcmp (action, "vpn-up") == 0)
|
|
||||||
g_return_if_fail (vpn_ip4_config != NULL);
|
|
||||||
|
|
||||||
dbus_mgr = nm_dbus_manager_get ();
|
|
||||||
g_connection = nm_dbus_manager_get_connection (dbus_mgr);
|
|
||||||
proxy = dbus_g_proxy_new_for_name (g_connection,
|
|
||||||
NM_DISPATCHER_DBUS_SERVICE,
|
|
||||||
NM_DISPATCHER_DBUS_PATH,
|
|
||||||
NM_DISPATCHER_DBUS_IFACE);
|
|
||||||
if (!proxy) {
|
|
||||||
nm_log_err (LOGD_CORE, "could not get dispatcher proxy!");
|
|
||||||
g_object_unref (dbus_mgr);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (connection) {
|
|
||||||
connection_hash = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_NO_SECRETS);
|
|
||||||
|
|
||||||
connection_props = value_hash_create ();
|
|
||||||
|
|
||||||
/* path */
|
|
||||||
value_hash_add_object_path (connection_props,
|
|
||||||
NMD_CONNECTION_PROPS_PATH,
|
|
||||||
nm_connection_get_path (connection));
|
|
||||||
} else {
|
|
||||||
connection_hash = value_hash_create ();
|
|
||||||
connection_props = value_hash_create ();
|
|
||||||
}
|
|
||||||
|
|
||||||
device_props = value_hash_create ();
|
|
||||||
device_ip4_props = value_hash_create ();
|
|
||||||
device_ip6_props = value_hash_create ();
|
|
||||||
device_dhcp4_props = value_hash_create ();
|
|
||||||
device_dhcp6_props = value_hash_create ();
|
|
||||||
vpn_ip4_props = value_hash_create ();
|
|
||||||
vpn_ip6_props = value_hash_create ();
|
|
||||||
|
|
||||||
/* hostname actions only send the hostname */
|
|
||||||
if (strcmp (action, "hostname") != 0) {
|
|
||||||
fill_device_props (device,
|
|
||||||
device_props,
|
|
||||||
device_ip4_props,
|
|
||||||
device_ip6_props,
|
|
||||||
device_dhcp4_props,
|
|
||||||
device_dhcp6_props);
|
|
||||||
if (vpn_iface)
|
|
||||||
fill_vpn_props (vpn_ip4_config, NULL, vpn_ip4_props, vpn_ip6_props);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Do a non-blocking call, but wait for the reply, because dbus-glib
|
|
||||||
* sometimes needs time to complete internal housekeeping. If we use
|
|
||||||
* dbus_g_proxy_call_no_reply(), that housekeeping (specifically the
|
|
||||||
* GetNameOwner response) doesn't complete and we run into an assert
|
|
||||||
* on unreffing the proxy.
|
|
||||||
*/
|
|
||||||
dbus_g_proxy_begin_call_with_timeout (proxy, "Action",
|
|
||||||
dispatcher_done_cb,
|
|
||||||
dbus_mgr, /* automatically unref the dbus mgr when call is done */
|
|
||||||
g_object_unref,
|
|
||||||
5000,
|
|
||||||
G_TYPE_STRING, action,
|
|
||||||
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, connection_hash,
|
|
||||||
DBUS_TYPE_G_MAP_OF_VARIANT, connection_props,
|
|
||||||
DBUS_TYPE_G_MAP_OF_VARIANT, device_props,
|
|
||||||
DBUS_TYPE_G_MAP_OF_VARIANT, device_ip4_props,
|
|
||||||
DBUS_TYPE_G_MAP_OF_VARIANT, device_ip6_props,
|
|
||||||
DBUS_TYPE_G_MAP_OF_VARIANT, device_dhcp4_props,
|
|
||||||
DBUS_TYPE_G_MAP_OF_VARIANT, device_dhcp6_props,
|
|
||||||
G_TYPE_STRING, vpn_iface ? vpn_iface : "",
|
|
||||||
DBUS_TYPE_G_MAP_OF_VARIANT, vpn_ip4_props,
|
|
||||||
DBUS_TYPE_G_MAP_OF_VARIANT, vpn_ip6_props,
|
|
||||||
G_TYPE_INVALID);
|
|
||||||
g_hash_table_destroy (connection_hash);
|
|
||||||
g_hash_table_destroy (connection_props);
|
|
||||||
g_hash_table_destroy (device_props);
|
|
||||||
g_hash_table_destroy (device_ip4_props);
|
|
||||||
g_hash_table_destroy (device_ip6_props);
|
|
||||||
g_hash_table_destroy (device_dhcp4_props);
|
|
||||||
g_hash_table_destroy (device_dhcp6_props);
|
|
||||||
g_hash_table_destroy (vpn_ip4_props);
|
|
||||||
g_hash_table_destroy (vpn_ip6_props);
|
|
||||||
}
|
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
nm_match_spec_hwaddr (const GSList *specs, const char *hwaddr)
|
nm_match_spec_hwaddr (const GSList *specs, const char *hwaddr)
|
||||||
{
|
{
|
||||||
|
@@ -26,7 +26,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <net/ethernet.h>
|
#include <net/ethernet.h>
|
||||||
|
|
||||||
#include "nm-device.h"
|
|
||||||
#include "nm-ip4-config.h"
|
#include "nm-ip4-config.h"
|
||||||
#include "nm-setting-ip4-config.h"
|
#include "nm-setting-ip4-config.h"
|
||||||
#include "nm-ip6-config.h"
|
#include "nm-ip6-config.h"
|
||||||
@@ -40,13 +39,6 @@ int nm_spawn_process (const char *args);
|
|||||||
void nm_utils_merge_ip4_config (NMIP4Config *ip4_config, NMSettingIP4Config *setting);
|
void nm_utils_merge_ip4_config (NMIP4Config *ip4_config, NMSettingIP4Config *setting);
|
||||||
void nm_utils_merge_ip6_config (NMIP6Config *ip6_config, NMSettingIP6Config *setting);
|
void nm_utils_merge_ip6_config (NMIP6Config *ip6_config, NMSettingIP6Config *setting);
|
||||||
|
|
||||||
void nm_utils_call_dispatcher (const char *action,
|
|
||||||
NMConnection *connection,
|
|
||||||
NMDevice *device,
|
|
||||||
const char *vpn_iface,
|
|
||||||
NMIP4Config *vpn_ip4_config,
|
|
||||||
NMIP6Config *vpn_ip6_config);
|
|
||||||
|
|
||||||
gboolean nm_match_spec_hwaddr (const GSList *specs, const char *hwaddr);
|
gboolean nm_match_spec_hwaddr (const GSList *specs, const char *hwaddr);
|
||||||
gboolean nm_match_spec_s390_subchannels (const GSList *specs, const char *subchannels);
|
gboolean nm_match_spec_s390_subchannels (const GSList *specs, const char *subchannels);
|
||||||
|
|
||||||
|
@@ -66,6 +66,7 @@
|
|||||||
#include "nm-posix-signals.h"
|
#include "nm-posix-signals.h"
|
||||||
#include "nm-manager-auth.h"
|
#include "nm-manager-auth.h"
|
||||||
#include "nm-dbus-glib-types.h"
|
#include "nm-dbus-glib-types.h"
|
||||||
|
#include "nm-dispatcher.h"
|
||||||
|
|
||||||
static void impl_device_disconnect (NMDevice *device, DBusGMethodInvocation *context);
|
static void impl_device_disconnect (NMDevice *device, DBusGMethodInvocation *context);
|
||||||
|
|
||||||
|
246
src/nm-dispatcher.c
Normal file
246
src/nm-dispatcher.c
Normal file
@@ -0,0 +1,246 @@
|
|||||||
|
/* -*- 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) 2004 - 2012 Red Hat, Inc.
|
||||||
|
* Copyright (C) 2005 - 2008 Novell, Inc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "nm-dispatcher.h"
|
||||||
|
#include "nm-dispatcher-action.h"
|
||||||
|
#include "NetworkManagerUtils.h"
|
||||||
|
#include "nm-utils.h"
|
||||||
|
#include "nm-logging.h"
|
||||||
|
#include "nm-dbus-manager.h"
|
||||||
|
#include "nm-dbus-glib-types.h"
|
||||||
|
|
||||||
|
static void
|
||||||
|
dump_object_to_props (GObject *object, GHashTable *hash)
|
||||||
|
{
|
||||||
|
GParamSpec **pspecs;
|
||||||
|
guint len = 0, i;
|
||||||
|
|
||||||
|
pspecs = g_object_class_list_properties (G_OBJECT_GET_CLASS (object), &len);
|
||||||
|
for (i = 0; i < len; i++) {
|
||||||
|
value_hash_add_object_property (hash,
|
||||||
|
pspecs[i]->name,
|
||||||
|
object,
|
||||||
|
pspecs[i]->name,
|
||||||
|
pspecs[i]->value_type);
|
||||||
|
}
|
||||||
|
g_free (pspecs);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dump_dhcp4_to_props (NMDHCP4Config *config, GHashTable *hash)
|
||||||
|
{
|
||||||
|
GSList *options, *iter;
|
||||||
|
|
||||||
|
options = nm_dhcp4_config_list_options (config);
|
||||||
|
for (iter = options; iter; iter = g_slist_next (iter)) {
|
||||||
|
const char *option = (const char *) iter->data;
|
||||||
|
const char *val;
|
||||||
|
|
||||||
|
val = nm_dhcp4_config_get_option (config, option);
|
||||||
|
value_hash_add_str (hash, option, val);
|
||||||
|
}
|
||||||
|
g_slist_free (options);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dump_dhcp6_to_props (NMDHCP6Config *config, GHashTable *hash)
|
||||||
|
{
|
||||||
|
GSList *options, *iter;
|
||||||
|
|
||||||
|
options = nm_dhcp6_config_list_options (config);
|
||||||
|
for (iter = options; iter; iter = g_slist_next (iter)) {
|
||||||
|
const char *option = (const char *) iter->data;
|
||||||
|
const char *val;
|
||||||
|
|
||||||
|
val = nm_dhcp6_config_get_option (config, option);
|
||||||
|
value_hash_add_str (hash, option, val);
|
||||||
|
}
|
||||||
|
g_slist_free (options);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
fill_device_props (NMDevice *device,
|
||||||
|
GHashTable *dev_hash,
|
||||||
|
GHashTable *ip4_hash,
|
||||||
|
GHashTable *ip6_hash,
|
||||||
|
GHashTable *dhcp4_hash,
|
||||||
|
GHashTable *dhcp6_hash)
|
||||||
|
{
|
||||||
|
NMIP4Config *ip4_config;
|
||||||
|
NMIP6Config *ip6_config;
|
||||||
|
NMDHCP4Config *dhcp4_config;
|
||||||
|
NMDHCP6Config *dhcp6_config;
|
||||||
|
|
||||||
|
/* If the action is for a VPN, send the VPN's IP interface instead of the device's */
|
||||||
|
value_hash_add_str (dev_hash, NMD_DEVICE_PROPS_IP_INTERFACE, nm_device_get_ip_iface (device));
|
||||||
|
value_hash_add_str (dev_hash, NMD_DEVICE_PROPS_INTERFACE, nm_device_get_iface (device));
|
||||||
|
value_hash_add_uint (dev_hash, NMD_DEVICE_PROPS_TYPE, nm_device_get_device_type (device));
|
||||||
|
value_hash_add_uint (dev_hash, NMD_DEVICE_PROPS_STATE, nm_device_get_state (device));
|
||||||
|
value_hash_add_object_path (dev_hash, NMD_DEVICE_PROPS_PATH, nm_device_get_path (device));
|
||||||
|
|
||||||
|
ip4_config = nm_device_get_ip4_config (device);
|
||||||
|
if (ip4_config)
|
||||||
|
dump_object_to_props (G_OBJECT (ip4_config), ip4_hash);
|
||||||
|
|
||||||
|
ip6_config = nm_device_get_ip6_config (device);
|
||||||
|
if (ip6_config)
|
||||||
|
dump_object_to_props (G_OBJECT (ip6_config), ip6_hash);
|
||||||
|
|
||||||
|
dhcp4_config = nm_device_get_dhcp4_config (device);
|
||||||
|
if (dhcp4_config)
|
||||||
|
dump_dhcp4_to_props (dhcp4_config, dhcp4_hash);
|
||||||
|
|
||||||
|
dhcp6_config = nm_device_get_dhcp6_config (device);
|
||||||
|
if (dhcp6_config)
|
||||||
|
dump_dhcp6_to_props (dhcp6_config, dhcp6_hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
fill_vpn_props (NMIP4Config *ip4_config,
|
||||||
|
NMIP6Config *ip6_config,
|
||||||
|
GHashTable *ip4_hash,
|
||||||
|
GHashTable *ip6_hash)
|
||||||
|
{
|
||||||
|
if (ip4_config)
|
||||||
|
dump_object_to_props (G_OBJECT (ip4_config), ip4_hash);
|
||||||
|
if (ip6_config)
|
||||||
|
dump_object_to_props (G_OBJECT (ip6_config), ip6_hash);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dispatcher_done_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
|
||||||
|
{
|
||||||
|
dbus_g_proxy_end_call (proxy, call, NULL, G_TYPE_INVALID);
|
||||||
|
g_object_unref (proxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
nm_utils_call_dispatcher (const char *action,
|
||||||
|
NMConnection *connection,
|
||||||
|
NMDevice *device,
|
||||||
|
const char *vpn_iface,
|
||||||
|
NMIP4Config *vpn_ip4_config,
|
||||||
|
NMIP6Config *vpn_ip6_config)
|
||||||
|
{
|
||||||
|
NMDBusManager *dbus_mgr;
|
||||||
|
DBusGProxy *proxy;
|
||||||
|
DBusGConnection *g_connection;
|
||||||
|
GHashTable *connection_hash;
|
||||||
|
GHashTable *connection_props;
|
||||||
|
GHashTable *device_props;
|
||||||
|
GHashTable *device_ip4_props;
|
||||||
|
GHashTable *device_ip6_props;
|
||||||
|
GHashTable *device_dhcp4_props;
|
||||||
|
GHashTable *device_dhcp6_props;
|
||||||
|
GHashTable *vpn_ip4_props;
|
||||||
|
GHashTable *vpn_ip6_props;
|
||||||
|
|
||||||
|
g_return_if_fail (action != NULL);
|
||||||
|
|
||||||
|
/* All actions except 'hostname' require a device */
|
||||||
|
if (strcmp (action, "hostname") != 0)
|
||||||
|
g_return_if_fail (NM_IS_DEVICE (device));
|
||||||
|
/* VPN actions require at least an IPv4 config (for now) */
|
||||||
|
if (strcmp (action, "vpn-up") == 0)
|
||||||
|
g_return_if_fail (vpn_ip4_config != NULL);
|
||||||
|
|
||||||
|
dbus_mgr = nm_dbus_manager_get ();
|
||||||
|
g_connection = nm_dbus_manager_get_connection (dbus_mgr);
|
||||||
|
proxy = dbus_g_proxy_new_for_name (g_connection,
|
||||||
|
NM_DISPATCHER_DBUS_SERVICE,
|
||||||
|
NM_DISPATCHER_DBUS_PATH,
|
||||||
|
NM_DISPATCHER_DBUS_IFACE);
|
||||||
|
if (!proxy) {
|
||||||
|
nm_log_err (LOGD_CORE, "could not get dispatcher proxy!");
|
||||||
|
g_object_unref (dbus_mgr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (connection) {
|
||||||
|
connection_hash = nm_connection_to_hash (connection, NM_SETTING_HASH_FLAG_NO_SECRETS);
|
||||||
|
|
||||||
|
connection_props = value_hash_create ();
|
||||||
|
value_hash_add_object_path (connection_props,
|
||||||
|
NMD_CONNECTION_PROPS_PATH,
|
||||||
|
nm_connection_get_path (connection));
|
||||||
|
} else {
|
||||||
|
connection_hash = value_hash_create ();
|
||||||
|
connection_props = value_hash_create ();
|
||||||
|
}
|
||||||
|
|
||||||
|
device_props = value_hash_create ();
|
||||||
|
device_ip4_props = value_hash_create ();
|
||||||
|
device_ip6_props = value_hash_create ();
|
||||||
|
device_dhcp4_props = value_hash_create ();
|
||||||
|
device_dhcp6_props = value_hash_create ();
|
||||||
|
vpn_ip4_props = value_hash_create ();
|
||||||
|
vpn_ip6_props = value_hash_create ();
|
||||||
|
|
||||||
|
/* hostname actions only send the hostname */
|
||||||
|
if (strcmp (action, "hostname") != 0) {
|
||||||
|
fill_device_props (device,
|
||||||
|
device_props,
|
||||||
|
device_ip4_props,
|
||||||
|
device_ip6_props,
|
||||||
|
device_dhcp4_props,
|
||||||
|
device_dhcp6_props);
|
||||||
|
if (vpn_iface)
|
||||||
|
fill_vpn_props (vpn_ip4_config, NULL, vpn_ip4_props, vpn_ip6_props);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Do a non-blocking call, but wait for the reply, because dbus-glib
|
||||||
|
* sometimes needs time to complete internal housekeeping. If we use
|
||||||
|
* dbus_g_proxy_call_no_reply(), that housekeeping (specifically the
|
||||||
|
* GetNameOwner response) doesn't complete and we run into an assert
|
||||||
|
* on unreffing the proxy.
|
||||||
|
*/
|
||||||
|
dbus_g_proxy_begin_call_with_timeout (proxy, "Action",
|
||||||
|
dispatcher_done_cb,
|
||||||
|
dbus_mgr, /* automatically unref the dbus mgr when call is done */
|
||||||
|
g_object_unref,
|
||||||
|
5000,
|
||||||
|
G_TYPE_STRING, action,
|
||||||
|
DBUS_TYPE_G_MAP_OF_MAP_OF_VARIANT, connection_hash,
|
||||||
|
DBUS_TYPE_G_MAP_OF_VARIANT, connection_props,
|
||||||
|
DBUS_TYPE_G_MAP_OF_VARIANT, device_props,
|
||||||
|
DBUS_TYPE_G_MAP_OF_VARIANT, device_ip4_props,
|
||||||
|
DBUS_TYPE_G_MAP_OF_VARIANT, device_ip6_props,
|
||||||
|
DBUS_TYPE_G_MAP_OF_VARIANT, device_dhcp4_props,
|
||||||
|
DBUS_TYPE_G_MAP_OF_VARIANT, device_dhcp6_props,
|
||||||
|
G_TYPE_STRING, vpn_iface ? vpn_iface : "",
|
||||||
|
DBUS_TYPE_G_MAP_OF_VARIANT, vpn_ip4_props,
|
||||||
|
DBUS_TYPE_G_MAP_OF_VARIANT, vpn_ip6_props,
|
||||||
|
G_TYPE_INVALID);
|
||||||
|
g_hash_table_destroy (connection_hash);
|
||||||
|
g_hash_table_destroy (connection_props);
|
||||||
|
g_hash_table_destroy (device_props);
|
||||||
|
g_hash_table_destroy (device_ip4_props);
|
||||||
|
g_hash_table_destroy (device_ip6_props);
|
||||||
|
g_hash_table_destroy (device_dhcp4_props);
|
||||||
|
g_hash_table_destroy (device_dhcp6_props);
|
||||||
|
g_hash_table_destroy (vpn_ip4_props);
|
||||||
|
g_hash_table_destroy (vpn_ip6_props);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
40
src/nm-dispatcher.h
Normal file
40
src/nm-dispatcher.h
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
/* -*- 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) 2004 - 2012 Red Hat, Inc.
|
||||||
|
* Copyright (C) 2005 - 2008 Novell, Inc.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef NM_DISPATCHER_H
|
||||||
|
#define NM_DISPATCHER_H
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "nm-device.h"
|
||||||
|
#include "nm-ip4-config.h"
|
||||||
|
#include "nm-ip6-config.h"
|
||||||
|
#include "nm-connection.h"
|
||||||
|
|
||||||
|
void nm_utils_call_dispatcher (const char *action,
|
||||||
|
NMConnection *connection,
|
||||||
|
NMDevice *device,
|
||||||
|
const char *vpn_iface,
|
||||||
|
NMIP4Config *vpn_ip4_config,
|
||||||
|
NMIP6Config *vpn_ip6_config);
|
||||||
|
|
||||||
|
#endif /* NM_DISPATCHER_H */
|
@@ -41,6 +41,7 @@
|
|||||||
#include "nm-policy-hostname.h"
|
#include "nm-policy-hostname.h"
|
||||||
#include "nm-manager-auth.h"
|
#include "nm-manager-auth.h"
|
||||||
#include "nm-firewall-manager.h"
|
#include "nm-firewall-manager.h"
|
||||||
|
#include "nm-dispatcher.h"
|
||||||
|
|
||||||
struct NMPolicy {
|
struct NMPolicy {
|
||||||
NMManager *manager;
|
NMManager *manager;
|
||||||
|
@@ -47,6 +47,7 @@
|
|||||||
#include "nm-netlink-utils.h"
|
#include "nm-netlink-utils.h"
|
||||||
#include "nm-glib-compat.h"
|
#include "nm-glib-compat.h"
|
||||||
#include "settings/nm-settings-connection.h"
|
#include "settings/nm-settings-connection.h"
|
||||||
|
#include "nm-dispatcher.h"
|
||||||
|
|
||||||
#include "nm-vpn-connection-glue.h"
|
#include "nm-vpn-connection-glue.h"
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user