1
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
2
/* NetworkManager -- Network link manager
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License along
15
* with this program; if not, write to the Free Software Foundation, Inc.,
16
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
* Copyright (C) 2007 - 2009 Novell, Inc.
19
* Copyright (C) 2007 - 2012 Red Hat, Inc.
24
#include <netinet/ether.h>
29
#include <sys/types.h>
31
#include <dbus/dbus-glib-lowlevel.h>
32
#include <dbus/dbus-glib.h>
34
#include <glib/gi18n.h>
36
#include "nm-glib-compat.h"
37
#include "nm-manager.h"
38
#include "nm-logging.h"
39
#include "nm-dbus-manager.h"
40
#include "nm-vpn-manager.h"
41
#include "nm-modem-manager.h"
42
#include "nm-device-bt.h"
43
#include "nm-device.h"
44
#include "nm-device-ethernet.h"
45
#include "nm-device-wifi.h"
46
#include "nm-device-olpc-mesh.h"
47
#include "nm-device-modem.h"
48
#include "nm-device-infiniband.h"
49
#include "nm-device-bond.h"
50
#include "nm-device-bridge.h"
51
#include "nm-device-vlan.h"
52
#include "nm-device-adsl.h"
53
#include "nm-system.h"
54
#include "nm-properties-changed-signal.h"
55
#include "nm-setting-bluetooth.h"
56
#include "nm-setting-connection.h"
57
#include "nm-setting-wireless.h"
58
#include "nm-setting-vpn.h"
59
#include "nm-marshal.h"
60
#include "nm-dbus-glib-types.h"
61
#include "nm-udev-manager.h"
62
#include "nm-hostname-provider.h"
63
#include "nm-bluez-manager.h"
64
#include "nm-bluez-common.h"
65
#include "nm-settings.h"
66
#include "nm-settings-connection.h"
67
#include "nm-manager-auth.h"
68
#include "NetworkManagerUtils.h"
70
#include "nm-device-factory.h"
71
#include "wifi-utils.h"
72
#include "nm-enum-types.h"
73
#include "nm-sleep-monitor.h"
76
#include "nm-connectivity.h"
80
#define NM_AUTOIP_DBUS_SERVICE "org.freedesktop.nm_avahi_autoipd"
81
#define NM_AUTOIP_DBUS_IFACE "org.freedesktop.nm_avahi_autoipd"
83
static gboolean impl_manager_get_devices (NMManager *manager,
87
static gboolean impl_manager_get_device_by_ip_iface (NMManager *self,
89
char **out_object_path,
92
static void impl_manager_activate_connection (NMManager *manager,
93
const char *connection_path,
94
const char *device_path,
95
const char *specific_object_path,
96
DBusGMethodInvocation *context);
98
static void impl_manager_add_and_activate_connection (NMManager *manager,
100
const char *device_path,
101
const char *specific_object_path,
102
DBusGMethodInvocation *context);
104
static void impl_manager_deactivate_connection (NMManager *manager,
105
const char *connection_path,
106
DBusGMethodInvocation *context);
108
static void impl_manager_sleep (NMManager *manager,
110
DBusGMethodInvocation *context);
112
static void impl_manager_enable (NMManager *manager,
114
DBusGMethodInvocation *context);
116
static void impl_manager_get_permissions (NMManager *manager,
117
DBusGMethodInvocation *context);
119
static gboolean impl_manager_get_state (NMManager *manager,
123
static gboolean impl_manager_set_logging (NMManager *manager,
128
static void impl_manager_get_logging (NMManager *manager,
132
#include "nm-manager-glue.h"
134
static void bluez_manager_bdaddr_added_cb (NMBluezManager *bluez_mgr,
137
const char *object_path,
141
static void bluez_manager_bdaddr_removed_cb (NMBluezManager *bluez_mgr,
143
const char *object_path,
146
static void add_device (NMManager *self, NMDevice *device);
148
static void hostname_provider_init (NMHostnameProvider *provider_class);
150
static NMActiveConnection *internal_activate_device (NMManager *manager,
152
NMConnection *connection,
153
const char *specific_object,
154
gboolean user_requested,
156
const char *dbus_sender,
158
NMActiveConnection *master,
161
static NMDevice *find_device_by_ip_iface (NMManager *self, const gchar *iface);
163
static GSList * remove_one_device (NMManager *manager,
168
static void rfkill_change_wifi (const char *desc, gboolean enabled);
170
#define SSD_POKE_INTERVAL 120
171
#define ORIGDEV_TAG "originating-device"
173
typedef struct PendingActivation PendingActivation;
174
typedef void (*PendingActivationFunc) (PendingActivation *pending,
177
struct PendingActivation {
180
DBusGMethodInvocation *context;
181
PendingActivationFunc callback;
183
const char *wifi_shared_permission;
185
char *connection_path;
186
NMConnection *connection;
187
char *specific_object_path;
192
gboolean user_enabled;
193
gboolean daemon_enabled;
201
RfKillState (*other_enabled_func) (NMManager *);
202
RfKillState (*daemon_enabled_func) (NMManager *);
208
GSList *active_connections;
214
NMConnectivity *connectivity;
217
NMDBusManager *dbus_mgr;
218
NMUdevManager *udev_mgr;
219
NMBluezManager *bluez_mgr;
221
/* List of NMDeviceFactoryFunc pointers sorted in priority order */
224
NMSettings *settings;
227
RadioState radio_states[RFKILL_TYPE_MAX];
229
gboolean net_enabled;
231
NMVPNManager *vpn_manager;
233
NMModemManager *modem_manager;
234
guint modem_added_id;
235
guint modem_removed_id;
237
DBusGProxy *aipd_proxy;
238
NMSleepMonitor *sleep_monitor;
242
/* Firmware dir monitor */
243
GFileMonitor *fw_monitor;
247
guint timestamp_update_id;
249
GHashTable *nm_bridges;
254
#define NM_MANAGER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), NM_TYPE_MANAGER, NMManagerPrivate))
256
G_DEFINE_TYPE_EXTENDED (NMManager, nm_manager, G_TYPE_OBJECT, 0,
257
G_IMPLEMENT_INTERFACE (NM_TYPE_HOSTNAME_PROVIDER,
258
hostname_provider_init))
266
USER_PERMISSIONS_CHANGED,
267
ACTIVE_CONNECTION_ADDED,
268
ACTIVE_CONNECTION_REMOVED,
273
static guint signals[LAST_SIGNAL] = { 0 };
279
PROP_NETWORKING_ENABLED,
280
PROP_WIRELESS_ENABLED,
281
PROP_WIRELESS_HARDWARE_ENABLED,
283
PROP_WWAN_HARDWARE_ENABLED,
285
PROP_WIMAX_HARDWARE_ENABLED,
286
PROP_ACTIVE_CONNECTIONS,
296
/************************************************************************/
298
#define NM_MANAGER_ERROR (nm_manager_error_quark ())
301
nm_manager_error_quark (void)
303
static GQuark quark = 0;
305
quark = g_quark_from_static_string ("nm-manager-error");
309
/************************************************************************/
311
static void active_connection_state_changed (NMActiveConnection *active,
316
_active_connection_cleanup (gpointer user_data)
318
NMManager *self = NM_MANAGER (user_data);
319
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
321
gboolean changed = FALSE;
323
priv->ac_cleanup_id = 0;
325
iter = priv->active_connections;
327
NMActiveConnection *ac = iter->data;
330
if (nm_active_connection_get_state (ac) == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) {
331
priv->active_connections = g_slist_remove (priv->active_connections, ac);
332
g_signal_emit (self, signals[ACTIVE_CONNECTION_REMOVED], 0, ac);
333
g_signal_handlers_disconnect_by_func (ac, active_connection_state_changed, self);
340
g_object_notify (G_OBJECT (self), NM_MANAGER_ACTIVE_CONNECTIONS);
346
active_connection_state_changed (NMActiveConnection *active,
350
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
351
NMActiveConnectionState state;
353
state = nm_active_connection_get_state (active);
354
if (state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED) {
355
/* Destroy active connections from an idle handler to ensure that
356
* their last property change notifications go out, which wouldn't
357
* happen if we destroyed them immediately when their state was set
360
if (!priv->ac_cleanup_id)
361
priv->ac_cleanup_id = g_idle_add (_active_connection_cleanup, self);
366
active_connection_add (NMManager *self, NMActiveConnection *active)
368
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
370
g_return_if_fail (g_slist_find (priv->active_connections, active) == FALSE);
372
priv->active_connections = g_slist_prepend (priv->active_connections, active);
373
g_signal_connect (active, "notify::" NM_ACTIVE_CONNECTION_STATE,
374
G_CALLBACK (active_connection_state_changed),
377
g_signal_emit (self, signals[ACTIVE_CONNECTION_ADDED], 0, active);
378
g_object_notify (G_OBJECT (self), NM_MANAGER_ACTIVE_CONNECTIONS);
382
nm_manager_get_active_connections (NMManager *manager)
384
return NM_MANAGER_GET_PRIVATE (manager)->active_connections;
387
static NMActiveConnection *
388
active_connection_get_by_path (NMManager *manager, const char *path)
390
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
393
g_return_val_if_fail (manager != NULL, NULL);
394
g_return_val_if_fail (path != NULL, NULL);
396
for (iter = priv->active_connections; iter; iter = g_slist_next (iter)) {
397
NMActiveConnection *candidate = iter->data;
399
if (strcmp (path, nm_active_connection_get_path (candidate)) == 0)
405
/************************************************************************/
408
nm_manager_get_device_by_udi (NMManager *manager, const char *udi)
412
g_return_val_if_fail (udi != NULL, NULL);
414
for (iter = NM_MANAGER_GET_PRIVATE (manager)->devices; iter; iter = iter->next) {
415
if (!strcmp (nm_device_get_udi (NM_DEVICE (iter->data)), udi))
416
return NM_DEVICE (iter->data);
422
nm_manager_get_device_by_path (NMManager *manager, const char *path)
426
g_return_val_if_fail (path != NULL, NULL);
428
for (iter = NM_MANAGER_GET_PRIVATE (manager)->devices; iter; iter = iter->next) {
429
if (!strcmp (nm_device_get_path (NM_DEVICE (iter->data)), path))
430
return NM_DEVICE (iter->data);
436
nm_manager_get_device_by_master (NMManager *manager, const char *master, const char *driver)
440
g_return_val_if_fail (master != NULL, NULL);
442
for (iter = NM_MANAGER_GET_PRIVATE (manager)->devices; iter; iter = iter->next) {
443
NMDevice *device = NM_DEVICE (iter->data);
445
if (!strcmp (nm_device_get_iface (device), master) &&
446
(!driver || !strcmp (nm_device_get_driver (device), driver)))
454
manager_sleeping (NMManager *self)
456
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
458
if (priv->sleeping || !priv->net_enabled)
464
modem_added (NMModemManager *modem_manager,
469
NMManager *self = NM_MANAGER (user_data);
470
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
471
NMDevice *replace_device, *device = NULL;
472
const char *modem_iface;
475
/* Don't rely only on the data port; use the control port if available */
476
modem_iface = nm_modem_get_data_port (modem);
478
modem_iface = nm_modem_get_control_port (modem);
479
g_return_if_fail (modem_iface);
481
replace_device = find_device_by_ip_iface (NM_MANAGER (user_data), modem_iface);
482
if (replace_device) {
483
priv->devices = remove_one_device (NM_MANAGER (user_data),
489
/* Give Bluetooth DUN devices first chance to claim the modem */
490
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
491
if (nm_device_get_device_type (iter->data) == NM_DEVICE_TYPE_BT) {
492
if (nm_device_bt_modem_added (NM_DEVICE_BT (iter->data), modem, driver))
497
/* If it was a Bluetooth modem and no bluetooth device claimed it, ignore
498
* it. The rfcomm port (and thus the modem) gets created automatically
499
* by the Bluetooth code during the connection process.
501
if (driver && !strcmp (driver, "bluetooth")) {
502
nm_log_info (LOGD_MB, "ignoring modem '%s' (no associated Bluetooth device)", modem_iface);
506
/* Make the new modem device */
507
device = nm_device_modem_new (modem, driver);
509
add_device (self, device);
513
nm_manager_update_state (NMManager *manager)
515
NMManagerPrivate *priv;
516
NMState new_state = NM_STATE_DISCONNECTED;
519
g_return_if_fail (NM_IS_MANAGER (manager));
521
priv = NM_MANAGER_GET_PRIVATE (manager);
523
if (manager_sleeping (manager))
524
new_state = NM_STATE_ASLEEP;
526
for (iter = priv->devices; iter; iter = iter->next) {
527
NMDevice *dev = NM_DEVICE (iter->data);
528
NMDeviceState state = nm_device_get_state (dev);
530
if (state == NM_DEVICE_STATE_ACTIVATED) {
531
new_state = NM_STATE_CONNECTED_GLOBAL;
533
/* Connectivity check might have a better idea */
534
if (nm_connectivity_get_connected (priv->connectivity) == FALSE)
535
new_state = NM_STATE_CONNECTED_SITE;
540
if (nm_device_is_activating (dev))
541
new_state = NM_STATE_CONNECTING;
542
else if (new_state != NM_STATE_CONNECTING) {
543
if (state == NM_DEVICE_STATE_DEACTIVATING)
544
new_state = NM_STATE_DISCONNECTING;
549
if (priv->state != new_state) {
550
priv->state = new_state;
551
g_object_notify (G_OBJECT (manager), NM_MANAGER_STATE);
553
g_signal_emit (manager, signals[STATE_CHANGED], 0, priv->state);
558
manager_device_state_changed (NMDevice *device,
559
NMDeviceState new_state,
560
NMDeviceState old_state,
561
NMDeviceStateReason reason,
564
NMManager *self = NM_MANAGER (user_data);
566
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
570
case NM_DEVICE_STATE_UNMANAGED:
571
case NM_DEVICE_STATE_UNAVAILABLE:
572
case NM_DEVICE_STATE_DISCONNECTED:
573
case NM_DEVICE_STATE_PREPARE:
574
case NM_DEVICE_STATE_FAILED:
575
g_object_notify (G_OBJECT (self), NM_MANAGER_ACTIVE_CONNECTIONS);
581
nm_manager_update_state (self);
584
if (priv->state >= NM_STATE_CONNECTED_LOCAL) {
585
if (old_state == NM_DEVICE_STATE_ACTIVATED || new_state == NM_DEVICE_STATE_ACTIVATED) {
586
/* Still connected, but a device activated or deactivated; make sure
587
* we still have connectivity on the other activated devices.
589
nm_log_dbg (LOGD_CORE, "(%s): triggered connectivity check due to state change",
590
nm_device_get_iface (device));
591
nm_connectivity_start_check (priv->connectivity);
594
/* Cannot be connected if no devices are activated */
595
nm_log_dbg (LOGD_CORE, "stopping connectivity checks");
596
nm_connectivity_stop_check (priv->connectivity);
601
/* Removes a device from a device list; returns the start of the new device list */
603
remove_one_device (NMManager *manager,
608
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
610
if (nm_device_get_managed (device)) {
611
/* When quitting, we want to leave up interfaces & connections
612
* that can be taken over again (ie, "assumed") when NM restarts
613
* so that '/etc/init.d/NetworkManager restart' will not distrupt
614
* networking for interfaces that support connection assumption.
615
* All other devices get unmanaged when NM quits so that their
616
* connections get torn down and the interface is deactivated.
619
if ( !nm_device_can_assume_connections (device)
620
|| (nm_device_get_state (device) != NM_DEVICE_STATE_ACTIVATED)
622
nm_device_set_managed (device, FALSE, NM_DEVICE_STATE_REASON_REMOVED);
625
g_signal_handlers_disconnect_by_func (device, manager_device_state_changed, manager);
627
nm_settings_device_removed (priv->settings, device);
628
g_signal_emit (manager, signals[DEVICE_REMOVED], 0, device);
629
g_object_unref (device);
631
return g_slist_remove (list, device);
635
modem_removed (NMModemManager *modem_manager,
639
NMManager *self = NM_MANAGER (user_data);
640
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
644
/* Give Bluetooth DUN devices first chance to handle the modem removal */
645
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
646
if (nm_device_get_device_type (iter->data) == NM_DEVICE_TYPE_BT) {
647
if (nm_device_bt_modem_removed (NM_DEVICE_BT (iter->data), modem))
652
/* Otherwise remove the standalone modem */
653
found = nm_manager_get_device_by_udi (self, nm_modem_get_path (modem));
655
priv->devices = remove_one_device (self, priv->devices, found, FALSE);
659
aipd_handle_event (DBusGProxy *proxy,
665
NMManager *manager = NM_MANAGER (user_data);
666
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
668
gboolean handled = FALSE;
670
if (!event || !iface) {
671
nm_log_warn (LOGD_AUTOIP4, "incomplete message received from avahi-autoipd");
675
if ( (strcmp (event, "BIND") != 0)
676
&& (strcmp (event, "CONFLICT") != 0)
677
&& (strcmp (event, "UNBIND") != 0)
678
&& (strcmp (event, "STOP") != 0)) {
679
nm_log_warn (LOGD_AUTOIP4, "unknown event '%s' received from avahi-autoipd", event);
683
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
684
NMDevice *candidate = NM_DEVICE (iter->data);
686
if (!strcmp (nm_device_get_iface (candidate), iface)) {
687
nm_device_handle_autoip4_event (candidate, event, address);
694
nm_log_warn (LOGD_AUTOIP4, "(%s): unhandled avahi-autoipd event", iface);
698
hostname_provider_get_hostname (NMHostnameProvider *provider)
700
return NM_MANAGER_GET_PRIVATE (provider)->hostname;
704
hostname_provider_init (NMHostnameProvider *provider_class)
706
provider_class->get_hostname = hostname_provider_get_hostname;
710
nm_manager_get_state (NMManager *manager)
712
g_return_val_if_fail (NM_IS_MANAGER (manager), NM_STATE_UNKNOWN);
714
return NM_MANAGER_GET_PRIVATE (manager)->state;
718
might_be_vpn (NMConnection *connection)
720
NMSettingConnection *s_con;
721
const char *ctype = NULL;
723
if (nm_connection_get_setting_vpn (connection))
726
/* Make sure it's not a VPN, which we can't autocomplete yet */
727
s_con = nm_connection_get_setting_connection (connection);
729
ctype = nm_setting_connection_get_connection_type (s_con);
731
return (g_strcmp0 (ctype, NM_SETTING_VPN_SETTING_NAME) == 0);
735
try_complete_vpn (NMConnection *connection, GSList *existing, GError **error)
737
g_assert (might_be_vpn (connection) == TRUE);
739
if (!nm_connection_get_setting_vpn (connection)) {
740
g_set_error_literal (error,
742
NM_MANAGER_ERROR_UNSUPPORTED_CONNECTION_TYPE,
743
"VPN connections require a 'vpn' setting");
747
nm_utils_complete_generic (connection,
748
NM_SETTING_VPN_SETTING_NAME,
750
_("VPN connection %d"),
752
FALSE); /* No IPv6 by default for now */
757
static PendingActivation *
758
pending_activation_new (NMManager *manager,
759
DBusGMethodInvocation *context,
760
const char *device_path,
761
const char *connection_path,
762
GHashTable *settings,
763
const char *specific_object_path,
764
PendingActivationFunc callback,
767
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
768
PendingActivation *pending;
769
NMDevice *device = NULL;
770
NMConnection *connection = NULL;
771
GSList *all_connections = NULL;
774
g_return_val_if_fail (manager != NULL, NULL);
775
g_return_val_if_fail (context != NULL, NULL);
776
g_return_val_if_fail (device_path != NULL, NULL);
778
/* A object path of "/" means NULL */
779
if (g_strcmp0 (specific_object_path, "/") == 0)
780
specific_object_path = NULL;
781
if (g_strcmp0 (device_path, "/") == 0)
784
/* Create the partial connection from the given settings */
787
device = nm_manager_get_device_by_path (manager, device_path);
789
g_set_error_literal (error,
791
NM_MANAGER_ERROR_UNKNOWN_DEVICE,
796
connection = nm_connection_new ();
797
nm_connection_replace_settings (connection, settings, NULL);
799
all_connections = nm_settings_get_connections (priv->settings);
801
if (might_be_vpn (connection)) {
802
/* Try to fill the VPN's connection setting and name at least */
803
success = try_complete_vpn (connection, all_connections, error);
805
/* Let each device subclass complete the connection */
806
success = nm_device_complete_connection (device,
808
specific_object_path,
812
g_slist_free (all_connections);
814
if (success == FALSE) {
815
g_object_unref (connection);
820
pending = g_slice_new0 (PendingActivation);
821
pending->manager = manager;
822
pending->context = context;
823
pending->callback = callback;
825
pending->connection_path = g_strdup (connection_path);
826
pending->connection = connection;
828
/* "/" is special-cased to NULL to get through D-Bus */
829
if (specific_object_path && strcmp (specific_object_path, "/"))
830
pending->specific_object_path = g_strdup (specific_object_path);
831
if (device_path && strcmp (device_path, "/"))
832
pending->device_path = g_strdup (device_path);
838
pending_auth_done (NMAuthChain *chain,
840
DBusGMethodInvocation *context,
843
PendingActivation *pending = user_data;
844
NMAuthCallResult result;
845
GError *tmp_error = NULL;
847
/* Caller has had a chance to obtain authorization, so we only need to
848
* check for 'yes' here.
850
result = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, NM_AUTH_PERMISSION_NETWORK_CONTROL));
851
if (result != NM_AUTH_CALL_RESULT_YES) {
852
tmp_error = g_error_new_literal (NM_MANAGER_ERROR,
853
NM_MANAGER_ERROR_PERMISSION_DENIED,
854
"Not authorized to control networking.");
858
if (pending->wifi_shared_permission) {
859
result = nm_auth_chain_get_result (chain, pending->wifi_shared_permission);
860
if (result != NM_AUTH_CALL_RESULT_YES) {
861
tmp_error = g_error_new_literal (NM_MANAGER_ERROR,
862
NM_MANAGER_ERROR_PERMISSION_DENIED,
863
"Not authorized to share connections via wifi.");
868
/* Otherwise authorized and available to activate */
871
pending->callback (pending, tmp_error);
872
g_clear_error (&tmp_error);
876
pending_activation_check_authorized (PendingActivation *pending,
877
NMDBusManager *dbus_mgr)
879
char *error_desc = NULL;
880
gulong sender_uid = G_MAXULONG;
882
const char *wifi_permission = NULL;
883
NMConnection *connection;
884
NMSettings *settings;
886
g_return_if_fail (pending != NULL);
887
g_return_if_fail (dbus_mgr != NULL);
889
if (!nm_auth_get_caller_uid (pending->context,
893
error = g_error_new_literal (NM_MANAGER_ERROR,
894
NM_MANAGER_ERROR_PERMISSION_DENIED,
896
pending->callback (pending, error);
897
g_error_free (error);
903
if (0 == sender_uid) {
904
pending->callback (pending, NULL);
908
/* By this point we have an auto-completed connection (for AddAndActivate)
909
* or an existing connection (for Activate).
911
connection = pending->connection;
913
settings = NM_MANAGER_GET_PRIVATE (pending->manager)->settings;
914
connection = (NMConnection *) nm_settings_get_connection_by_path (settings, pending->connection_path);
918
error = g_error_new_literal (NM_MANAGER_ERROR,
919
NM_MANAGER_ERROR_UNKNOWN_CONNECTION,
920
"Connection could not be found.");
921
pending->callback (pending, error);
922
g_error_free (error);
926
/* First check if the user is allowed to use networking at all, giving
927
* the user a chance to authenticate to gain the permission.
929
pending->chain = nm_auth_chain_new (pending->context,
933
g_assert (pending->chain);
934
nm_auth_chain_add_call (pending->chain, NM_AUTH_PERMISSION_NETWORK_CONTROL, TRUE);
936
/* Shared wifi connections require special permissions too */
937
wifi_permission = nm_utils_get_shared_wifi_permission (connection);
938
if (wifi_permission) {
939
pending->wifi_shared_permission = wifi_permission;
940
nm_auth_chain_add_call (pending->chain, wifi_permission, TRUE);
945
pending_activation_destroy (PendingActivation *pending,
947
NMActiveConnection *ac)
949
g_return_if_fail (pending != NULL);
952
dbus_g_method_return_error (pending->context, error);
954
if (pending->connection) {
955
dbus_g_method_return (pending->context,
956
pending->connection_path,
957
nm_active_connection_get_path (ac));
959
dbus_g_method_return (pending->context,
960
nm_active_connection_get_path (ac));
964
g_free (pending->connection_path);
965
g_free (pending->specific_object_path);
966
g_free (pending->device_path);
967
if (pending->connection)
968
g_object_unref (pending->connection);
971
nm_auth_chain_unref (pending->chain);
973
memset (pending, 0, sizeof (PendingActivation));
974
g_slice_free (PendingActivation, pending);
977
/*******************************************************************/
978
/* Settings stuff via NMSettings */
979
/*******************************************************************/
982
get_device_from_hwaddr (NMManager *self, NMConnection *connection)
984
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
987
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
988
if (nm_device_hwaddr_matches (NM_DEVICE (iter->data), connection, NULL, 0, TRUE))
995
find_vlan_parent (NMManager *self,
996
NMConnection *connection,
997
gboolean check_hwaddr)
999
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1000
NMSettingVlan *s_vlan;
1001
NMConnection *parent_connection;
1002
const char *parent_iface;
1003
NMDevice *parent = NULL;
1006
/* The 'parent' property could be either an interface name, a connection
1007
* UUID, or even given by the MAC address of the connection's ethernet
1010
s_vlan = nm_connection_get_setting_vlan (connection);
1011
g_return_val_if_fail (s_vlan != NULL, NULL);
1013
parent_iface = nm_setting_vlan_get_parent (s_vlan);
1015
parent = find_device_by_ip_iface (self, parent_iface);
1019
if (nm_utils_is_uuid (parent_iface)) {
1020
/* Try as a connection UUID */
1021
parent_connection = (NMConnection *) nm_settings_get_connection_by_uuid (priv->settings, parent_iface);
1022
if (parent_connection) {
1023
/* Check if the parent connection is activated on some device already */
1024
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
1026
NMConnection *candidate;
1028
req = nm_device_get_act_request (NM_DEVICE (iter->data));
1030
candidate = nm_active_connection_get_connection (NM_ACTIVE_CONNECTION (req));
1031
if (candidate == parent_connection)
1036
/* Check the hardware address of the parent connection */
1038
return get_device_from_hwaddr (self, parent_connection);
1044
/* Try the hardware address from the VLAN connection's hardware setting */
1046
return get_device_from_hwaddr (self, connection);
1052
* get_virtual_iface_name:
1053
* @self: the #NMManager
1054
* @connection: the #NMConnection representing a virtual interface
1055
* @out_parent: on success, the parent device if any
1057
* Given @connection, returns the interface name that the connection
1058
* would represent. If the interface name is not given by the connection,
1059
* this may require constructing it based on information in the connection
1060
* and existing network interfaces.
1062
* Returns: the expected interface name (caller takes ownership), or %NULL
1065
get_virtual_iface_name (NMManager *self,
1066
NMConnection *connection,
1067
NMDevice **out_parent)
1070
NMDevice *parent = NULL;
1075
if (nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME))
1076
return g_strdup (nm_connection_get_virtual_iface_name (connection));
1078
if (nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME))
1079
return g_strdup (nm_connection_get_virtual_iface_name (connection));
1081
if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
1082
NMSettingVlan *s_vlan;
1085
s_vlan = nm_connection_get_setting_vlan (connection);
1086
g_return_val_if_fail (s_vlan != NULL, NULL);
1088
parent = find_vlan_parent (self, connection, TRUE);
1090
ifname = nm_connection_get_virtual_iface_name (connection);
1092
if (!nm_device_supports_vlans (parent)) {
1093
nm_log_warn (LOGD_DEVICE, "(%s): No support for VLANs on interface %s of type %s",
1094
ifname ? ifname : nm_connection_get_id (connection),
1095
nm_device_get_ip_iface (parent),
1096
nm_device_get_type_desc (parent));
1100
/* If the connection doesn't specify the interface name for the VLAN
1101
* device, we create one for it using the VLAN ID and the parent
1105
vname = g_strdup (ifname);
1107
vname = nm_utils_new_vlan_name (nm_device_get_ip_iface (parent),
1108
nm_setting_vlan_get_id (s_vlan));
1111
*out_parent = parent;
1119
connection_needs_virtual_device (NMConnection *connection)
1121
if ( nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME)
1122
|| nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)
1123
|| nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME))
1130
get_virtual_iface_placeholder_udi (void)
1132
static guint32 id = 0;
1134
return g_strdup_printf ("/virtual/device/placeholder/%d", id++);
1137
/***************************/
1139
/* FIXME: remove when we handle bridges non-destructively */
1141
#define NM_BRIDGE_FILE NMRUNDIR "/nm-bridges"
1144
read_nm_created_bridges (NMManager *self)
1146
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1148
char **lines, **iter;
1152
if (!g_file_get_contents (NM_BRIDGE_FILE, &contents, NULL, NULL))
1155
g_get_current_time (&tv);
1157
lines = g_strsplit_set (contents, "\n", 0);
1160
for (iter = lines; iter && *iter; iter++) {
1161
if (g_str_has_prefix (*iter, "ts=")) {
1163
ts = strtol (*iter + 3, NULL, 10);
1164
/* allow 30 minutes time difference before we ignore the file */
1165
if (errno || ABS (tv.tv_sec - ts) > 1800)
1167
} else if (g_str_has_prefix (*iter, "iface="))
1168
g_hash_table_insert (priv->nm_bridges, g_strdup (*iter + 6), GUINT_TO_POINTER (1));
1173
unlink (NM_BRIDGE_FILE);
1177
write_nm_created_bridges (NMManager *self)
1179
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1182
GError *error = NULL;
1184
gboolean found = FALSE;
1186
/* write out nm-created bridges list */
1187
br_list = g_string_sized_new (50);
1189
/* Timestamp is first line */
1190
g_get_current_time (&tv);
1191
g_string_append_printf (br_list, "ts=%ld\n", tv.tv_sec);
1193
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
1194
NMDevice *device = iter->data;
1196
if (nm_device_get_device_type (device) == NM_DEVICE_TYPE_BRIDGE) {
1197
g_string_append_printf (br_list, "iface=%s\n", nm_device_get_iface (device));
1203
if (!g_file_set_contents (NM_BRIDGE_FILE, br_list->str, -1, &error)) {
1204
nm_log_warn (LOGD_BRIDGE, "Failed to write NetworkManager-created bridge list; "
1205
"on restart bridges may not be recognized. (%s)",
1206
error ? error->message : "unknown");
1207
g_clear_error (&error);
1210
g_string_free (br_list, TRUE);
1214
bridge_created_by_nm (NMManager *self, const char *iface)
1216
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1218
return (priv->nm_bridges && g_hash_table_lookup (priv->nm_bridges, iface));
1221
/***************************/
1224
* system_create_virtual_device:
1225
* @self: the #NMManager
1226
* @connection: the connection which might require a virtual device
1228
* If @connection requires a virtual device and one does not yet exist for it,
1229
* creates that device.
1231
* Returns: the #NMDevice if successfully created, NULL if not
1234
system_create_virtual_device (NMManager *self, NMConnection *connection)
1236
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1238
char *iface = NULL, *udi;
1239
NMDevice *device = NULL, *parent = NULL;
1241
iface = get_virtual_iface_name (self, connection, &parent);
1243
nm_log_warn (LOGD_DEVICE, "(%s) failed to determine virtual interface name",
1244
nm_connection_get_id (connection));
1248
/* Make sure we didn't create a device for this connection already */
1249
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
1250
NMDevice *candidate = iter->data;
1251
GError *error = NULL;
1253
if ( g_strcmp0 (nm_device_get_iface (candidate), iface) == 0
1254
|| nm_device_check_connection_compatible (candidate, connection, &error)) {
1255
g_clear_error (&error);
1258
g_clear_error (&error);
1261
if (nm_connection_is_type (connection, NM_SETTING_BOND_SETTING_NAME)) {
1262
if (!nm_system_add_bonding_master (iface)) {
1263
nm_log_warn (LOGD_DEVICE, "(%s): failed to add bonding master interface for '%s'",
1264
iface, nm_connection_get_id (connection));
1268
udi = get_virtual_iface_placeholder_udi ();
1269
device = nm_device_bond_new (udi, iface);
1271
} else if (nm_connection_is_type (connection, NM_SETTING_BRIDGE_SETTING_NAME)) {
1272
gboolean exists = FALSE;
1274
if (!nm_system_create_bridge (iface, &exists)) {
1275
nm_log_warn (LOGD_DEVICE, "(%s): failed to add bridging interface for '%s'",
1276
iface, nm_connection_get_id (connection));
1280
/* FIXME: remove when we handle bridges non-destructively */
1281
if (exists && !bridge_created_by_nm (self, iface)) {
1282
nm_log_warn (LOGD_DEVICE, "(%s): cannot use existing bridge for '%s'",
1283
iface, nm_connection_get_id (connection));
1287
udi = get_virtual_iface_placeholder_udi ();
1288
device = nm_device_bridge_new (udi, iface);
1290
} else if (nm_connection_is_type (connection, NM_SETTING_VLAN_SETTING_NAME)) {
1291
g_return_val_if_fail (parent != NULL, FALSE);
1293
if (!nm_system_add_vlan_iface (connection, iface, nm_device_get_ip_ifindex (parent))) {
1294
nm_log_warn (LOGD_DEVICE, "(%s): failed to add VLAN interface for '%s'",
1295
iface, nm_connection_get_id (connection));
1298
udi = get_virtual_iface_placeholder_udi ();
1299
device = nm_device_vlan_new (udi, iface, parent);
1304
add_device (self, device);
1312
system_create_virtual_devices (NMManager *self)
1314
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1315
GSList *iter, *connections;
1317
nm_log_dbg (LOGD_CORE, "creating virtual devices...");
1319
connections = nm_settings_get_connections (priv->settings);
1320
for (iter = connections; iter; iter = g_slist_next (iter)) {
1321
NMConnection *connection = iter->data;
1322
NMSettingConnection *s_con = nm_connection_get_setting_connection (connection);
1325
if (connection_needs_virtual_device (connection)) {
1326
/* We only create a virtual interface if the connection can autoconnect */
1327
if (nm_setting_connection_get_autoconnect (s_con))
1328
system_create_virtual_device (self, connection);
1331
g_slist_free (connections);
1335
connection_added (NMSettings *settings,
1336
NMSettingsConnection *settings_connection,
1339
NMConnection *connection = NM_CONNECTION (settings_connection);
1341
if (connection_needs_virtual_device (connection)) {
1342
NMSettingConnection *s_con = nm_connection_get_setting_connection (connection);
1345
if (nm_setting_connection_get_autoconnect (s_con))
1346
system_create_virtual_device (manager, connection);
1351
connection_changed (NMSettings *settings,
1352
NMSettingsConnection *connection,
1355
/* FIXME: Some virtual devices may need to be updated in the future. */
1359
connection_removed (NMSettings *settings,
1360
NMSettingsConnection *connection,
1364
* Do not delete existing virtual devices to keep connectivity up.
1365
* Virtual devices are reused when NetworkManager is restarted.
1370
system_unmanaged_devices_changed_cb (NMSettings *settings,
1374
NMManager *self = NM_MANAGER (user_data);
1375
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1376
const GSList *unmanaged_specs, *iter;
1378
unmanaged_specs = nm_settings_get_unmanaged_specs (priv->settings);
1379
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
1380
NMDevice *device = NM_DEVICE (iter->data);
1383
managed = !nm_device_spec_match_list (device, unmanaged_specs);
1384
nm_device_set_managed (device,
1386
managed ? NM_DEVICE_STATE_REASON_NOW_MANAGED :
1387
NM_DEVICE_STATE_REASON_NOW_UNMANAGED);
1392
system_hostname_changed_cb (NMSettings *settings,
1396
NMManager *self = NM_MANAGER (user_data);
1397
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1400
hostname = nm_settings_get_hostname (priv->settings);
1401
if (!hostname && !priv->hostname)
1403
if (hostname && priv->hostname && !strcmp (hostname, priv->hostname))
1406
g_free (priv->hostname);
1407
priv->hostname = (hostname && strlen (hostname)) ? g_strdup (hostname) : NULL;
1408
g_object_notify (G_OBJECT (self), NM_MANAGER_HOSTNAME);
1413
/*******************************************************************/
1414
/* General NMManager stuff */
1415
/*******************************************************************/
1417
/* Store value into key-file; supported types: boolean, int, string */
1419
write_value_to_state_file (const char *filename,
1429
gboolean ret = FALSE;
1431
g_return_val_if_fail (filename != NULL, FALSE);
1432
g_return_val_if_fail (group != NULL, FALSE);
1433
g_return_val_if_fail (key != NULL, FALSE);
1434
g_return_val_if_fail (value_type == G_TYPE_BOOLEAN ||
1435
value_type == G_TYPE_INT ||
1436
value_type == G_TYPE_STRING,
1439
key_file = g_key_file_new ();
1443
g_key_file_set_list_separator (key_file, ',');
1444
g_key_file_load_from_file (key_file, filename, G_KEY_FILE_KEEP_COMMENTS, NULL);
1445
switch (value_type) {
1446
case G_TYPE_BOOLEAN:
1447
g_key_file_set_boolean (key_file, group, key, *((gboolean *) value));
1450
g_key_file_set_integer (key_file, group, key, *((gint *) value));
1453
g_key_file_set_string (key_file, group, key, *((const gchar **) value));
1457
data = g_key_file_to_data (key_file, &len, NULL);
1459
ret = g_file_set_contents (filename, data, len, error);
1462
g_key_file_free (key_file);
1468
radio_enabled_for_rstate (RadioState *rstate, gboolean check_changeable)
1472
enabled = rstate->user_enabled && rstate->hw_enabled;
1473
if (check_changeable) {
1474
enabled &= rstate->sw_enabled;
1475
if (rstate->daemon_enabled_func)
1476
enabled &= rstate->daemon_enabled;
1482
radio_enabled_for_type (NMManager *self, RfKillType rtype, gboolean check_changeable)
1484
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1486
return radio_enabled_for_rstate (&priv->radio_states[rtype], check_changeable);
1490
manager_update_radio_enabled (NMManager *self,
1494
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1497
/* Do nothing for radio types not yet implemented */
1501
g_object_notify (G_OBJECT (self), rstate->prop);
1503
/* Don't touch devices if asleep/networking disabled */
1504
if (manager_sleeping (self))
1507
/* enable/disable wireless devices as required */
1508
for (iter = priv->devices; iter; iter = iter->next) {
1509
NMDevice *device = NM_DEVICE (iter->data);
1511
if (nm_device_get_rfkill_type (device) == rstate->rtype) {
1512
nm_log_dbg (LOGD_RFKILL, "(%s): setting radio %s",
1513
nm_device_get_iface (device),
1514
enabled ? "enabled" : "disabled");
1515
nm_device_set_enabled (device, enabled);
1521
manager_hidden_ap_found (NMDevice *device,
1525
NMManager *manager = NM_MANAGER (user_data);
1526
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
1527
const struct ether_addr *bssid;
1529
GSList *connections;
1530
gboolean done = FALSE;
1532
g_return_if_fail (nm_ap_get_ssid (ap) == NULL);
1534
bssid = nm_ap_get_address (ap);
1537
/* Look for this AP's BSSID in the seen-bssids list of a connection,
1538
* and if a match is found, copy over the SSID */
1539
connections = nm_settings_get_connections (priv->settings);
1540
for (iter = connections; iter && !done; iter = g_slist_next (iter)) {
1541
NMConnection *connection = NM_CONNECTION (iter->data);
1542
NMSettingWireless *s_wifi;
1544
s_wifi = nm_connection_get_setting_wireless (connection);
1546
if (nm_settings_connection_has_seen_bssid (NM_SETTINGS_CONNECTION (connection), bssid))
1547
nm_ap_set_ssid (ap, nm_setting_wireless_get_ssid (s_wifi));
1550
g_slist_free (connections);
1554
nm_manager_get_ipw_rfkill_state (NMManager *self)
1556
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1558
RfKillState ipw_state = RFKILL_UNBLOCKED;
1560
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
1561
NMDevice *candidate = NM_DEVICE (iter->data);
1562
RfKillState candidate_state;
1564
if (nm_device_get_device_type (candidate) == NM_DEVICE_TYPE_WIFI) {
1565
candidate_state = nm_device_wifi_get_ipw_rfkill_state (NM_DEVICE_WIFI (candidate));
1567
if (candidate_state > ipw_state)
1568
ipw_state = candidate_state;
1576
nm_manager_get_modem_enabled_state (NMManager *self)
1578
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1580
RfKillState wwan_state = RFKILL_UNBLOCKED;
1582
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
1583
NMDevice *candidate = NM_DEVICE (iter->data);
1584
RfKillState candidate_state = RFKILL_UNBLOCKED;
1586
if (nm_device_get_rfkill_type (candidate) == RFKILL_TYPE_WWAN) {
1587
if (!nm_device_get_enabled (candidate))
1588
candidate_state = RFKILL_SOFT_BLOCKED;
1590
if (candidate_state > wwan_state)
1591
wwan_state = candidate_state;
1599
update_rstate_from_rfkill (RadioState *rstate, RfKillState rfkill)
1601
if (rfkill == RFKILL_UNBLOCKED) {
1602
rstate->sw_enabled = TRUE;
1603
rstate->hw_enabled = TRUE;
1604
} else if (rfkill == RFKILL_SOFT_BLOCKED) {
1605
rstate->sw_enabled = FALSE;
1606
rstate->hw_enabled = TRUE;
1607
} else if (rfkill == RFKILL_HARD_BLOCKED) {
1608
rstate->sw_enabled = FALSE;
1609
rstate->hw_enabled = FALSE;
1614
manager_rfkill_update_one_type (NMManager *self,
1618
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1619
RfKillState udev_state = RFKILL_UNBLOCKED;
1620
RfKillState other_state = RFKILL_UNBLOCKED;
1621
RfKillState composite;
1622
gboolean old_enabled, new_enabled, old_rfkilled, new_rfkilled;
1623
gboolean old_hwe, old_daemon_enabled = FALSE;
1625
old_enabled = radio_enabled_for_rstate (rstate, TRUE);
1626
old_rfkilled = rstate->hw_enabled && rstate->sw_enabled;
1627
old_hwe = rstate->hw_enabled;
1629
udev_state = nm_udev_manager_get_rfkill_state (priv->udev_mgr, rtype);
1631
if (rstate->other_enabled_func)
1632
other_state = rstate->other_enabled_func (self);
1634
/* The composite state is the "worst" of either udev or other states */
1635
if (udev_state == RFKILL_HARD_BLOCKED || other_state == RFKILL_HARD_BLOCKED)
1636
composite = RFKILL_HARD_BLOCKED;
1637
else if (udev_state == RFKILL_SOFT_BLOCKED || other_state == RFKILL_SOFT_BLOCKED)
1638
composite = RFKILL_SOFT_BLOCKED;
1640
composite = RFKILL_UNBLOCKED;
1642
update_rstate_from_rfkill (rstate, composite);
1644
/* If the device has a management daemon that can affect enabled state, check that now */
1645
if (rstate->daemon_enabled_func) {
1646
old_daemon_enabled = rstate->daemon_enabled;
1647
rstate->daemon_enabled = (rstate->daemon_enabled_func (self) == RFKILL_UNBLOCKED);
1648
if (old_daemon_enabled != rstate->daemon_enabled) {
1649
nm_log_info (LOGD_RFKILL, "%s now %s by management service",
1651
rstate->daemon_enabled ? "enabled" : "disabled");
1655
/* Print out all states affecting device enablement */
1657
if (rstate->daemon_enabled_func) {
1658
nm_log_dbg (LOGD_RFKILL, "%s hw-enabled %d sw-enabled %d daemon-enabled %d",
1659
rstate->desc, rstate->hw_enabled, rstate->sw_enabled, rstate->daemon_enabled);
1661
nm_log_dbg (LOGD_RFKILL, "%s hw-enabled %d sw-enabled %d",
1662
rstate->desc, rstate->hw_enabled, rstate->sw_enabled);
1666
/* Log new killswitch state */
1667
new_rfkilled = rstate->hw_enabled && rstate->sw_enabled;
1668
if (old_rfkilled != new_rfkilled) {
1669
nm_log_info (LOGD_RFKILL, "%s now %s by radio killswitch",
1671
new_rfkilled ? "enabled" : "disabled");
1674
/* Send out property changed signal for HW enabled */
1675
if (rstate->hw_enabled != old_hwe) {
1676
if (rstate->hw_prop)
1677
g_object_notify (G_OBJECT (self), rstate->hw_prop);
1680
/* And finally update the actual device radio state itself; respect the
1681
* daemon state here because this is never called from user-triggered
1682
* radio changes and we only want to ignore the daemon enabled state when
1683
* handling user radio change requests.
1685
new_enabled = radio_enabled_for_rstate (rstate, TRUE);
1686
if (new_enabled != old_enabled)
1687
manager_update_radio_enabled (self, rstate, new_enabled);
1691
nm_manager_rfkill_update (NMManager *self, RfKillType rtype)
1693
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1696
if (rtype != RFKILL_TYPE_UNKNOWN)
1697
manager_rfkill_update_one_type (self, &priv->radio_states[rtype], rtype);
1699
/* Otherwise sync all radio types */
1700
for (i = 0; i < RFKILL_TYPE_MAX; i++)
1701
manager_rfkill_update_one_type (self, &priv->radio_states[i], i);
1706
manager_ipw_rfkill_state_changed (NMDeviceWifi *device,
1710
nm_manager_rfkill_update (NM_MANAGER (user_data), RFKILL_TYPE_WLAN);
1714
manager_modem_enabled_changed (NMDevice *device, gpointer user_data)
1716
nm_manager_rfkill_update (NM_MANAGER (user_data), RFKILL_TYPE_WWAN);
1720
device_auth_done_cb (NMAuthChain *chain,
1722
DBusGMethodInvocation *context,
1725
NMManager *self = NM_MANAGER (user_data);
1726
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1727
GError *error = NULL;
1728
NMAuthCallResult result;
1730
const char *permission;
1731
NMDeviceAuthRequestFunc callback;
1733
priv->auth_chains = g_slist_remove (priv->auth_chains, chain);
1735
permission = nm_auth_chain_get_data (chain, "requested-permission");
1736
g_assert (permission);
1737
callback = nm_auth_chain_get_data (chain, "callback");
1738
g_assert (callback);
1739
device = nm_auth_chain_get_data (chain, "device");
1742
result = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, permission));
1744
/* translate the auth error into a manager permission denied error */
1745
nm_log_dbg (LOGD_CORE, "%s request failed: %s", permission, auth_error->message);
1746
error = g_error_new (NM_MANAGER_ERROR,
1747
NM_MANAGER_ERROR_PERMISSION_DENIED,
1748
"%s request failed: %s",
1749
permission, auth_error->message);
1750
} else if (result != NM_AUTH_CALL_RESULT_YES) {
1751
nm_log_dbg (LOGD_CORE, "%s request failed: not authorized", permission);
1752
error = g_error_new (NM_MANAGER_ERROR,
1753
NM_MANAGER_ERROR_PERMISSION_DENIED,
1754
"%s request failed: not authorized",
1758
g_assert (error || (result == NM_AUTH_CALL_RESULT_YES));
1763
nm_auth_chain_get_data (chain, "user-data"));
1765
g_clear_error (&error);
1766
nm_auth_chain_unref (chain);
1770
device_auth_request_cb (NMDevice *device,
1771
DBusGMethodInvocation *context,
1772
const char *permission,
1773
gboolean allow_interaction,
1774
NMDeviceAuthRequestFunc callback,
1778
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1779
GError *error = NULL;
1780
gulong sender_uid = G_MAXULONG;
1781
char *error_desc = NULL;
1784
/* Get the caller's UID for the root check */
1785
if (!nm_auth_get_caller_uid (context, priv->dbus_mgr, &sender_uid, &error_desc)) {
1786
error = g_error_new_literal (NM_MANAGER_ERROR,
1787
NM_MANAGER_ERROR_PERMISSION_DENIED,
1789
callback (device, context, error, user_data);
1790
g_error_free (error);
1791
g_free (error_desc);
1796
if (0 == sender_uid)
1797
callback (device, context, NULL, user_data);
1799
/* Otherwise validate the non-root request */
1800
chain = nm_auth_chain_new (context, NULL, device_auth_done_cb, self);
1802
priv->auth_chains = g_slist_append (priv->auth_chains, chain);
1804
nm_auth_chain_set_data (chain, "device", g_object_ref (device), g_object_unref);
1805
nm_auth_chain_set_data (chain, "requested-permission", g_strdup (permission), g_free);
1806
nm_auth_chain_set_data (chain, "callback", callback, NULL);
1807
nm_auth_chain_set_data (chain, "user-data", user_data, NULL);
1808
nm_auth_chain_add_call (chain, permission, allow_interaction);
1813
add_device (NMManager *self, NMDevice *device)
1815
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
1816
const char *iface, *driver, *type_desc;
1818
static guint32 devcount = 0;
1819
const GSList *unmanaged_specs;
1820
NMConnection *existing = NULL;
1821
gboolean managed = FALSE, enabled = FALSE;
1823
NMDeviceType devtype;
1825
iface = nm_device_get_ip_iface (device);
1828
devtype = nm_device_get_device_type (device);
1830
/* Ignore the device if we already know about it. But some modems will
1831
* provide pseudo-ethernet devices that NM has already claimed while
1832
* ModemManager is still detecting the modem's serial ports, so when the
1833
* MM modem object finally shows up it may have the same IP interface as the
1834
* ethernet interface we've already detected. In this case we skip the
1835
* check for an existing device with the same IP interface name and kill
1836
* the ethernet device later in favor of the modem device.
1838
if ((devtype != NM_DEVICE_TYPE_MODEM) && find_device_by_ip_iface (self, iface)) {
1839
g_object_unref (device);
1843
nm_device_set_connection_provider (device, NM_CONNECTION_PROVIDER (priv->settings));
1845
priv->devices = g_slist_append (priv->devices, device);
1847
g_signal_connect (device, "state-changed",
1848
G_CALLBACK (manager_device_state_changed),
1851
g_signal_connect (device, NM_DEVICE_AUTH_REQUEST,
1852
G_CALLBACK (device_auth_request_cb),
1855
if (devtype == NM_DEVICE_TYPE_WIFI) {
1856
/* Attach to the access-point-added signal so that the manager can fill
1857
* non-SSID-broadcasting APs with an SSID.
1859
g_signal_connect (device, "hidden-ap-found",
1860
G_CALLBACK (manager_hidden_ap_found),
1863
/* Hook up rfkill handling for ipw-based cards until they get converted
1864
* to use the kernel's rfkill subsystem in 2.6.33.
1866
g_signal_connect (device, "notify::" NM_DEVICE_WIFI_IPW_RFKILL_STATE,
1867
G_CALLBACK (manager_ipw_rfkill_state_changed),
1869
} else if (devtype == NM_DEVICE_TYPE_MODEM) {
1870
g_signal_connect (device, NM_DEVICE_MODEM_ENABLE_CHANGED,
1871
G_CALLBACK (manager_modem_enabled_changed),
1875
/* Update global rfkill state for this device type with the device's
1876
* rfkill state, and then set this device's rfkill state based on the
1879
rtype = nm_device_get_rfkill_type (device);
1880
if (rtype != RFKILL_TYPE_UNKNOWN) {
1881
nm_manager_rfkill_update (self, rtype);
1882
enabled = radio_enabled_for_type (self, rtype, TRUE);
1883
nm_device_set_enabled (device, enabled);
1886
type_desc = nm_device_get_type_desc (device);
1887
g_assert (type_desc);
1888
driver = nm_device_get_driver (device);
1891
nm_log_info (LOGD_HW, "(%s): new %s device (driver: '%s' ifindex: %d)",
1892
iface, type_desc, driver, nm_device_get_ifindex (device));
1894
path = g_strdup_printf ("/org/freedesktop/NetworkManager/Devices/%d", devcount++);
1895
nm_device_set_path (device, path);
1896
dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (priv->dbus_mgr),
1899
nm_log_info (LOGD_CORE, "(%s): exported as %s", iface, path);
1902
/* Check if we should assume the device's active connection by matching its
1903
* config with an existing system connection.
1905
if (nm_device_can_assume_connections (device)) {
1906
GSList *connections = NULL;
1908
connections = nm_settings_get_connections (priv->settings);
1909
existing = nm_device_connection_match_config (device, (const GSList *) connections);
1910
g_slist_free (connections);
1913
nm_log_dbg (LOGD_DEVICE, "(%s): found existing device connection '%s'",
1914
nm_device_get_iface (device),
1915
nm_connection_get_id (existing));
1918
/* Start the device if it's supposed to be managed */
1919
unmanaged_specs = nm_settings_get_unmanaged_specs (priv->settings);
1920
if ( !manager_sleeping (self)
1921
&& !nm_device_spec_match_list (device, unmanaged_specs)) {
1922
nm_device_set_managed (device,
1924
existing ? NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED :
1925
NM_DEVICE_STATE_REASON_NOW_MANAGED);
1929
nm_settings_device_added (priv->settings, device);
1930
g_signal_emit (self, signals[DEVICE_ADDED], 0, device);
1932
/* New devices might be master interfaces for virtual interfaces; so we may
1933
* need to create new virtual interfaces now.
1935
system_create_virtual_devices (self);
1937
/* If the device has a connection it can assume, do that now */
1938
if (existing && managed && nm_device_is_available (device)) {
1939
NMActiveConnection *ac;
1940
GError *error = NULL;
1942
nm_log_dbg (LOGD_DEVICE, "(%s): will attempt to assume existing connection",
1943
nm_device_get_iface (device));
1945
ac = internal_activate_device (self, device, existing, NULL, FALSE, 0, NULL, TRUE, NULL, &error);
1947
active_connection_add (self, ac);
1949
nm_log_warn (LOGD_DEVICE, "assumed connection %s failed to activate: (%d) %s",
1950
nm_connection_get_path (existing),
1951
error ? error->code : -1,
1952
error && error->message ? error->message : "(unknown)");
1953
g_error_free (error);
1959
bluez_manager_bdaddr_added_cb (NMBluezManager *bluez_mgr,
1962
const char *object_path,
1963
guint32 capabilities,
1967
gboolean has_dun = (capabilities & NM_BT_CAPABILITY_DUN);
1968
gboolean has_nap = (capabilities & NM_BT_CAPABILITY_NAP);
1970
g_return_if_fail (bdaddr != NULL);
1971
g_return_if_fail (name != NULL);
1972
g_return_if_fail (object_path != NULL);
1973
g_return_if_fail (capabilities != NM_BT_CAPABILITY_NONE);
1975
/* Make sure the device is not already in the device list */
1976
if (nm_manager_get_device_by_udi (manager, object_path))
1979
device = nm_device_bt_new (object_path, bdaddr, name, capabilities, FALSE);
1981
nm_log_info (LOGD_HW, "BT device %s (%s) added (%s%s%s)",
1984
has_dun ? "DUN" : "",
1985
has_dun && has_nap ? " " : "",
1986
has_nap ? "NAP" : "");
1988
add_device (manager, device);
1993
bluez_manager_bdaddr_removed_cb (NMBluezManager *bluez_mgr,
1995
const char *object_path,
1998
NMManager *self = NM_MANAGER (user_data);
1999
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
2002
g_return_if_fail (bdaddr != NULL);
2003
g_return_if_fail (object_path != NULL);
2005
device = nm_manager_get_device_by_udi (self, object_path);
2007
nm_log_info (LOGD_HW, "BT device %s removed", bdaddr);
2008
priv->devices = remove_one_device (self, priv->devices, device, FALSE);
2013
find_device_by_ip_iface (NMManager *self, const gchar *iface)
2015
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
2018
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
2019
NMDevice *candidate = iter->data;
2021
if (g_strcmp0 (nm_device_get_ip_iface (candidate), iface) == 0)
2028
find_device_by_ifindex (NMManager *self, guint32 ifindex)
2030
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
2033
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
2034
NMDevice *candidate = NM_DEVICE (iter->data);
2036
if (ifindex == nm_device_get_ifindex (candidate))
2042
#define PLUGIN_PREFIX "libnm-device-plugin-"
2047
NMDeviceFactoryCreateFunc create_func;
2051
plugin_sort (PluginInfo *a, PluginInfo *b)
2053
/* Higher priority means sort earlier in the list (ie, return -1) */
2054
if (a->priority > b->priority)
2056
else if (a->priority < b->priority)
2062
load_device_factories (NMManager *self)
2064
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
2066
GError *error = NULL;
2069
GSList *list = NULL, *iter;
2071
dir = g_dir_open (NMPLUGINDIR, 0, &error);
2073
nm_log_warn (LOGD_HW, "Failed to open plugin directory %s: %s",
2075
(error && error->message) ? error->message : "(unknown)");
2076
g_clear_error (&error);
2080
while ((item = g_dir_read_name (dir))) {
2082
NMDeviceFactoryCreateFunc create_func;
2083
NMDeviceFactoryPriorityFunc priority_func;
2084
NMDeviceFactoryTypeFunc type_func;
2085
PluginInfo *info = NULL;
2086
NMDeviceType plugin_type;
2088
if (!g_str_has_prefix (item, PLUGIN_PREFIX))
2091
path = g_module_build_path (NMPLUGINDIR, item);
2093
plugin = g_module_open (path, G_MODULE_BIND_LOCAL);
2097
nm_log_warn (LOGD_HW, "(%s): failed to load plugin: %s", item, g_module_error ());
2101
if (!g_module_symbol (plugin, "nm_device_factory_get_type", (gpointer) (&type_func))) {
2102
nm_log_warn (LOGD_HW, "(%s): failed to find device factory: %s", item, g_module_error ());
2103
g_module_close (plugin);
2107
/* Make sure we don't double-load plugins */
2108
plugin_type = type_func ();
2109
for (iter = list; iter; iter = g_slist_next (iter)) {
2110
PluginInfo *candidate = iter->data;
2112
if (plugin_type == candidate->t) {
2118
g_module_close (plugin);
2122
if (!g_module_symbol (plugin, "nm_device_factory_create_device", (gpointer) (&create_func))) {
2123
nm_log_warn (LOGD_HW, "(%s): failed to find device creator: %s", item, g_module_error ());
2124
g_module_close (plugin);
2128
info = g_malloc0 (sizeof (*info));
2129
info->create_func = create_func;
2130
info->t = plugin_type;
2132
/* Grab priority; higher number equals higher priority */
2133
if (g_module_symbol (plugin, "nm_device_factory_get_priority", (gpointer) (&priority_func)))
2134
info->priority = priority_func ();
2136
nm_log_dbg (LOGD_HW, "(%s): failed to find device factory priority func: %s",
2137
item, g_module_error ());
2140
g_module_make_resident (plugin);
2141
list = g_slist_insert_sorted (list, info, (GCompareFunc) plugin_sort);
2143
nm_log_info (LOGD_HW, "Loaded device factory: %s", g_module_name (plugin));
2147
/* Ditch the priority info and copy the factory functions to our private data */
2148
for (iter = list; iter; iter = g_slist_next (iter)) {
2149
PluginInfo *info = iter->data;
2151
priv->factories = g_slist_append (priv->factories, info->create_func);
2154
g_slist_free (list);
2158
is_wireless (GUdevDevice *device)
2162
/* Check devtype, newer kernels (2.6.32+) have this */
2163
tmp = g_udev_device_get_property (device, "DEVTYPE");
2164
if (g_strcmp0 (tmp, "wlan") == 0)
2167
/* Otherwise hit up WEXT directly */
2168
return wifi_utils_is_wifi (g_udev_device_get_name (device),
2169
g_udev_device_get_sysfs_path (device));
2173
is_olpc_mesh (GUdevDevice *device)
2175
const gchar *prop = g_udev_device_get_property (device, "ID_NM_OLPC_MESH");
2176
return (prop != NULL);
2180
is_infiniband (GUdevDevice *device)
2182
gint etype = g_udev_device_get_sysfs_attr_as_int (device, "type");
2183
return etype == ARPHRD_INFINIBAND;
2187
is_bond (int ifindex)
2189
return (nm_system_get_iface_type (ifindex, NULL) == NM_IFACE_TYPE_BOND);
2193
is_bridge (int ifindex)
2195
return (nm_system_get_iface_type (ifindex, NULL) == NM_IFACE_TYPE_BRIDGE);
2199
is_vlan (int ifindex)
2201
return (nm_system_get_iface_type (ifindex, NULL) == NM_IFACE_TYPE_VLAN);
2205
is_adsl (GUdevDevice *device)
2207
return (g_strcmp0 (g_udev_device_get_subsystem (device), "atm") == 0);
2211
udev_device_added_cb (NMUdevManager *udev_mgr,
2212
GUdevDevice *udev_device,
2214
const char *sysfs_path,
2219
NMManager *self = NM_MANAGER (user_data);
2220
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
2221
NMDevice *device = NULL;
2223
GError *error = NULL;
2225
g_return_if_fail (udev_device != NULL);
2226
g_return_if_fail (iface != NULL);
2227
g_return_if_fail (sysfs_path != NULL);
2228
g_return_if_fail (driver != NULL);
2230
/* Most devices will have an ifindex here */
2232
device = find_device_by_ifindex (self, ifindex);
2234
/* If it's a virtual device we may need to update its UDI */
2235
if (nm_system_get_iface_type (ifindex, iface) != NM_IFACE_TYPE_UNSPEC)
2236
g_object_set (G_OBJECT (device), NM_DEVICE_UDI, sysfs_path, NULL);
2240
/* But ATM/ADSL devices don't */
2241
g_return_if_fail (is_adsl (udev_device));
2242
device = find_device_by_ip_iface (self, iface);
2247
/* Try registered device factories */
2248
for (iter = priv->factories; iter; iter = g_slist_next (iter)) {
2249
NMDeviceFactoryCreateFunc create_func = iter->data;
2251
g_clear_error (&error);
2252
device = (NMDevice *) create_func (udev_device, sysfs_path, iface, driver, &error);
2253
if (device && NM_IS_DEVICE (device)) {
2254
g_assert_no_error (error);
2255
break; /* success! */
2259
nm_log_warn (LOGD_HW, "%s: factory failed to create device: (%d) %s",
2261
error ? error->code : -1,
2262
error ? error->message : "(unknown)");
2263
g_clear_error (&error);
2268
if (device == NULL) {
2269
if (is_olpc_mesh (udev_device)) /* must be before is_wireless */
2270
device = nm_device_olpc_mesh_new (sysfs_path, iface, driver);
2271
else if (is_wireless (udev_device))
2272
device = nm_device_wifi_new (sysfs_path, iface, driver);
2273
else if (is_infiniband (udev_device))
2274
device = nm_device_infiniband_new (sysfs_path, iface, driver);
2275
else if (is_bond (ifindex))
2276
device = nm_device_bond_new (sysfs_path, iface);
2277
else if (is_bridge (ifindex)) {
2279
/* FIXME: always create device when we handle bridges non-destructively */
2280
if (bridge_created_by_nm (self, iface))
2281
device = nm_device_bridge_new (sysfs_path, iface);
2283
nm_log_info (LOGD_BRIDGE, "(%s): ignoring bridge not created by NetworkManager", iface);
2284
} else if (is_vlan (ifindex)) {
2285
int parent_ifindex = -1;
2288
/* Have to find the parent device */
2289
if (nm_system_get_iface_vlan_info (ifindex, &parent_ifindex, NULL)) {
2290
parent = find_device_by_ifindex (self, parent_ifindex);
2292
device = nm_device_vlan_new (sysfs_path, iface, parent);
2294
/* If udev signaled the VLAN interface before it signaled
2295
* the VLAN's parent at startup we may not know about the
2296
* parent device yet. But we'll find it on the second pass
2297
* from nm_manager_start().
2299
nm_log_dbg (LOGD_HW, "(%s): VLAN parent interface unknown", iface);
2302
nm_log_err (LOGD_HW, "(%s): failed to get VLAN parent ifindex", iface);
2303
} else if (is_adsl (udev_device))
2304
device = nm_device_adsl_new (sysfs_path, iface, driver);
2306
device = nm_device_ethernet_new (sysfs_path, iface, driver);
2310
add_device (self, device);
2314
udev_device_removed_cb (NMUdevManager *manager,
2315
GUdevDevice *udev_device,
2318
NMManager *self = NM_MANAGER (user_data);
2319
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
2323
ifindex = g_udev_device_get_property_as_int (udev_device, "IFINDEX");
2324
device = find_device_by_ifindex (self, ifindex);
2327
const char *iface = g_udev_device_get_name (udev_device);
2329
/* On removal we aren't always be able to read properties like IFINDEX
2330
* anymore, as they may have already been removed from sysfs. So we
2331
* have to fall back on device name (eg, interface name).
2333
* Also, some devices (namely PPPoE (pppX), ADSL (nasX, pppX), and
2334
* mobile broadband (pppX, bnepX)) create a kernel netdevice for IP
2335
* communication (called the "IP interface" in NM) as part of the
2336
* connection process and thus the IP interface lifetime does not
2337
* correspond to the NMDevice lifetime. For these devices we must
2338
* ignore removal events for the IP interface name otherwise the
2339
* NMDevice would be removed. Hence the usage here of
2340
* nm_device_get_iface() rather than nm_device_get_ip_iface().
2342
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
2343
if (g_strcmp0 (nm_device_get_iface (NM_DEVICE (iter->data)), iface) == 0) {
2344
device = iter->data;
2351
priv->devices = remove_one_device (self, priv->devices, device, FALSE);
2355
udev_manager_rfkill_changed_cb (NMUdevManager *udev_mgr,
2357
RfKillState udev_state,
2360
nm_manager_rfkill_update (NM_MANAGER (user_data), rtype);
2364
nm_manager_get_devices (NMManager *manager)
2366
g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
2368
return NM_MANAGER_GET_PRIVATE (manager)->devices;
2372
impl_manager_get_devices (NMManager *manager, GPtrArray **devices, GError **err)
2374
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
2377
*devices = g_ptr_array_sized_new (g_slist_length (priv->devices));
2379
for (iter = priv->devices; iter; iter = iter->next)
2380
g_ptr_array_add (*devices, g_strdup (nm_device_get_path (NM_DEVICE (iter->data))));
2386
impl_manager_get_device_by_ip_iface (NMManager *self,
2388
char **out_object_path,
2392
const char *path = NULL;
2394
device = find_device_by_ip_iface (self, iface);
2396
path = nm_device_get_path (device);
2398
*out_object_path = g_strdup (path);
2402
g_set_error_literal (error,
2404
NM_MANAGER_ERROR_UNKNOWN_DEVICE,
2405
"No device found for the requested iface.");
2408
return path ? TRUE : FALSE;
2411
static NMActiveConnection *
2412
internal_activate_device (NMManager *manager,
2414
NMConnection *connection,
2415
const char *specific_object,
2416
gboolean user_requested,
2418
const char *dbus_sender,
2420
NMActiveConnection *master,
2424
NMDevice *master_device = NULL;
2426
g_return_val_if_fail (NM_IS_MANAGER (manager), NULL);
2427
g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
2428
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
2430
/* Ensure the requested connection is compatible with the device */
2431
if (!nm_device_check_connection_compatible (device, connection, error))
2434
/* Tear down any existing connection */
2435
if (nm_device_get_act_request (device)) {
2436
nm_log_info (LOGD_DEVICE, "(%s): disconnecting for new activation request.",
2437
nm_device_get_iface (device));
2438
nm_device_state_changed (device,
2439
NM_DEVICE_STATE_DISCONNECTED,
2440
NM_DEVICE_STATE_REASON_NONE);
2444
master_device = nm_active_connection_get_device (master);
2446
req = nm_act_request_new (connection,
2455
nm_device_activate (device, req);
2457
return NM_ACTIVE_CONNECTION (req);
2462
* @self: #NMManager object
2463
* @connection: the #NMConnection to find the master connection and device for
2464
* @device: the #NMDevice, if any, which will activate @connection
2465
* @out_master_connection: on success, the master connection of @connection if
2466
* that master connection was found
2467
* @out_master_device: on success, the master device of @connection if that
2468
* master device was found
2470
* Given an #NMConnection, attempts to find its master connection and/or its
2471
* master device. This function may return a master connection, a master device,
2472
* or both. If only a connection is returned, that master connection is not
2473
* currently active on any device. If only a device is returned, that device
2474
* is not currently activated with any connection. If both are returned, then
2475
* the device is currently activated or activating with the returned master
2478
* Returns: %TRUE if the master device and/or connection could be found or if
2479
* the connection did not require a master, %FALSE otherwise
2482
find_master (NMManager *self,
2483
NMConnection *connection,
2485
NMConnection **out_master_connection,
2486
NMDevice **out_master_device)
2488
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
2489
NMSettingConnection *s_con;
2491
NMDevice *master_device = NULL;
2492
NMConnection *master_connection = NULL;
2493
GSList *iter, *connections = NULL;
2495
s_con = nm_connection_get_setting_connection (connection);
2497
master = nm_setting_connection_get_master (s_con);
2500
return TRUE; /* success, but no master */
2502
/* Try as an interface name first */
2503
master_device = find_device_by_ip_iface (self, master);
2504
if (master_device) {
2505
/* A device obviously can't be its own master */
2506
if (master_device == device)
2509
/* Try master as a connection UUID */
2510
master_connection = (NMConnection *) nm_settings_get_connection_by_uuid (priv->settings, master);
2511
if (master_connection) {
2512
/* Check if the master connection is activated on some device already */
2513
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
2514
NMDevice *candidate = NM_DEVICE (iter->data);
2516
if (candidate == device)
2519
if (nm_device_get_connection (candidate) == master_connection) {
2520
master_device = candidate;
2525
/* Might be a virtual interface that hasn't been created yet, so
2526
* look through the interface names of connections that require
2527
* virtual interfaces and see if one of their virtual interface
2528
* names matches the master.
2530
connections = nm_settings_get_connections (priv->settings);
2531
for (iter = connections; iter && !master_connection; iter = g_slist_next (iter)) {
2532
NMConnection *candidate = iter->data;
2535
if (connection_needs_virtual_device (candidate)) {
2536
vname = get_virtual_iface_name (self, candidate, NULL);
2537
if (g_strcmp0 (master, vname) == 0)
2538
master_connection = candidate;
2542
g_slist_free (connections);
2546
if (out_master_connection)
2547
*out_master_connection = master_connection;
2548
if (out_master_device)
2549
*out_master_device = master_device;
2551
return master_device || master_connection;
2555
is_compatible_with_slave (NMConnection *master, NMConnection *slave)
2557
NMSettingConnection *s_con;
2559
g_return_val_if_fail (master, FALSE);
2560
g_return_val_if_fail (slave, FALSE);
2562
s_con = nm_connection_get_setting_connection (slave);
2565
return nm_connection_is_type (master, nm_setting_connection_get_slave_type (s_con));
2569
* ensure_master_active_connection:
2571
* @self: the #NMManager
2572
* @dbus_sender: if the request was initiated by a user via D-Bus, the
2573
* dbus sender name of the client that requested the activation; for auto
2574
* activated connections use %NULL
2575
* @connection: the connection that should depend on @master_connection
2576
* @device: the #NMDevice, if any, which will activate @connection
2577
* @master_connection: the master connection
2578
* @master_device: the master device
2579
* @error: the error, if an error occurred
2581
* Determines whether a given #NMConnection depends on another connection to
2582
* be activated, and if so, finds that master connection or creates it.
2584
* Returns: the master #NMActiveConnection that the caller should depend on, or
2585
* %NULL if an error occurred
2587
static NMActiveConnection *
2588
ensure_master_active_connection (NMManager *self,
2589
const char *dbus_sender,
2590
NMConnection *connection,
2592
NMConnection *master_connection,
2593
NMDevice *master_device,
2596
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
2597
NMActiveConnection *master_ac = NULL;
2598
NMDeviceState master_state;
2601
g_assert (connection);
2602
g_assert (master_connection || master_device);
2604
/* If the master device isn't activated then we need to activate it using
2605
* compatible connection. If it's already activating we can just proceed.
2607
if (master_device) {
2608
/* If we're passed a connection and a device, we require that connection
2609
* be already activated on the device, eg returned from find_master().
2611
if (master_connection)
2612
g_assert (nm_device_get_connection (master_device) == master_connection);
2614
master_state = nm_device_get_state (master_device);
2615
if ( (master_state == NM_DEVICE_STATE_ACTIVATED)
2616
|| nm_device_is_activating (master_device)) {
2617
/* Device already using master_connection */
2618
return NM_ACTIVE_CONNECTION (nm_device_get_act_request (master_device));
2621
/* If the device is disconnected, find a compabile connection and
2622
* activate it on the device.
2624
if (master_state == NM_DEVICE_STATE_DISCONNECTED) {
2625
GSList *connections;
2627
g_assert (master_connection == NULL);
2629
/* Find a compatible connection and activate this device using it */
2630
connections = nm_settings_get_connections (priv->settings);
2631
for (iter = connections; iter; iter = g_slist_next (iter)) {
2632
NMConnection *candidate = NM_CONNECTION (iter->data);
2634
/* Ensure eg bond slave and the candidate master is a bond master */
2635
if (!is_compatible_with_slave (candidate, connection))
2638
if (nm_device_check_connection_compatible (master_device, candidate, NULL)) {
2639
master_ac = nm_manager_activate_connection (self,
2642
nm_device_get_path (master_device),
2646
g_prefix_error (error, "%s", "Master device activation failed: ");
2647
g_slist_free (connections);
2651
g_slist_free (connections);
2655
NM_MANAGER_ERROR_UNKNOWN_CONNECTION,
2656
"No compatible connection found for master device %s.",
2657
nm_device_get_iface (master_device));
2661
/* Otherwise, the device is unmanaged, unavailable, or disconnecting */
2664
NM_MANAGER_ERROR_UNMANAGED_DEVICE,
2665
"Master device %s unmanaged or not available for activation",
2666
nm_device_get_iface (master_device));
2667
} else if (master_connection) {
2668
gboolean found_device = FALSE;
2670
/* Find a compatible device and activate it using this connection */
2671
for (iter = priv->devices; iter; iter = g_slist_next (iter)) {
2672
NMDevice *candidate = NM_DEVICE (iter->data);
2674
if (candidate == device) {
2675
/* A device obviously can't be its own master */
2679
if (!nm_device_check_connection_compatible (candidate, master_connection, NULL))
2682
found_device = TRUE;
2683
master_state = nm_device_get_state (candidate);
2684
if (master_state != NM_DEVICE_STATE_DISCONNECTED)
2687
master_ac = nm_manager_activate_connection (self,
2690
nm_device_get_path (candidate),
2694
g_prefix_error (error, "%s", "Master device activation failed: ");
2698
/* Device described by master_connection may be a virtual one that's
2701
if (!found_device && connection_needs_virtual_device (master_connection)) {
2702
master_ac = nm_manager_activate_connection (self,
2709
g_prefix_error (error, "%s", "Master device activation failed: ");
2715
NM_MANAGER_ERROR_UNKNOWN_DEVICE,
2716
"No compatible disconnected device found for master connection %s.",
2717
nm_connection_get_uuid (master_connection));
2719
g_assert_not_reached ();
2724
static NMActiveConnection *
2725
activate_vpn_connection (NMManager *self,
2726
NMConnection *connection,
2727
const char *specific_object,
2731
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
2732
NMActiveConnection *parent = NULL;
2733
NMDevice *device = NULL;
2736
if (specific_object) {
2737
/* Find the specifc connection the client requested we use */
2738
parent = active_connection_get_by_path (self, specific_object);
2740
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_CONNECTION_NOT_ACTIVE,
2741
"Base connection for VPN connection not active.");
2745
for (iter = priv->active_connections; iter; iter = g_slist_next (iter)) {
2746
NMActiveConnection *candidate = iter->data;
2748
if (nm_active_connection_get_default (candidate)) {
2756
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_CONNECTION,
2757
"Could not find source connection.");
2761
device = nm_active_connection_get_device (parent);
2763
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
2764
"Source connection had no active device.");
2768
return nm_vpn_manager_activate_connection (priv->vpn_manager,
2771
nm_active_connection_get_path (parent),
2777
NMActiveConnection *
2778
nm_manager_activate_connection (NMManager *manager,
2779
NMConnection *connection,
2780
const char *specific_object,
2781
const char *device_path,
2782
const char *dbus_sender,
2785
NMManagerPrivate *priv;
2786
NMDevice *device = NULL;
2787
gulong sender_uid = 0;
2788
DBusError dbus_error;
2789
NMDeviceState state;
2791
NMDevice *master_device = NULL;
2792
NMConnection *master_connection = NULL;
2793
NMActiveConnection *master_ac = NULL, *ac = NULL;
2795
g_return_val_if_fail (manager != NULL, NULL);
2796
g_return_val_if_fail (connection != NULL, NULL);
2797
g_return_val_if_fail (error != NULL, NULL);
2798
g_return_val_if_fail (*error == NULL, NULL);
2800
priv = NM_MANAGER_GET_PRIVATE (manager);
2802
/* Get the UID of the user that originated the request, if any */
2804
dbus_error_init (&dbus_error);
2805
sender_uid = dbus_bus_get_unix_user (nm_dbus_manager_get_dbus_connection (priv->dbus_mgr),
2808
if (dbus_error_is_set (&dbus_error)) {
2809
g_set_error_literal (error,
2810
NM_MANAGER_ERROR, NM_MANAGER_ERROR_PERMISSION_DENIED,
2811
"Failed to get unix user for dbus sender");
2812
dbus_error_free (&dbus_error);
2818
if (nm_connection_is_type (connection, NM_SETTING_VPN_SETTING_NAME)) {
2819
ac = activate_vpn_connection (manager, connection, specific_object, sender_uid, error);
2823
/* Device-based connection */
2825
device = nm_manager_get_device_by_path (manager, device_path);
2827
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
2828
"Device not found");
2832
/* If it's a virtual interface make sure the device given by the
2833
* path matches the connection's interface details.
2835
if (connection_needs_virtual_device (connection)) {
2836
iface = get_virtual_iface_name (manager, connection, NULL);
2838
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
2839
"Failed to determine connection's virtual interface name");
2841
} else if (g_strcmp0 (iface, nm_device_get_ip_iface (device)) != 0) {
2842
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
2843
"Device given by path did not match connection's virtual interface name");
2850
/* Virtual connections (VLAN, bond, etc) may not specify a device
2851
* path because the device may not be created yet, or it be given
2852
* by the connection's properties instead. Find the device the
2853
* connection refers to, or create it if needed.
2855
if (!connection_needs_virtual_device (connection)) {
2856
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
2857
"This connection requires an existing device.");
2861
iface = get_virtual_iface_name (manager, connection, NULL);
2863
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
2864
"Failed to determine connection's virtual interface name");
2868
device = find_device_by_ip_iface (manager, iface);
2871
device = system_create_virtual_device (manager, connection);
2873
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
2874
"Failed to create virtual interface");
2878
/* A newly created device, if allowed to be managed by NM, will be
2879
* in the UNAVAILABLE state here. Since we want to use it right
2880
* away, we transition it immediately to DISCONNECTED.
2882
if ( nm_device_is_available (device)
2883
&& (nm_device_get_state (device) == NM_DEVICE_STATE_UNAVAILABLE)) {
2884
nm_device_state_changed (device,
2885
NM_DEVICE_STATE_DISCONNECTED,
2886
NM_DEVICE_STATE_REASON_NONE);
2891
state = nm_device_get_state (device);
2892
if (state < NM_DEVICE_STATE_DISCONNECTED) {
2893
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNMANAGED_DEVICE,
2894
"Device not managed by NetworkManager or unavailable");
2898
/* If this is an autoconnect request, but the device isn't allowing autoconnect
2899
* right now, we reject it.
2901
if (!dbus_sender && !nm_device_autoconnect_allowed (device)) {
2902
g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_AUTOCONNECT_NOT_ALLOWED,
2903
"%s does not allow automatic connections at this time",
2904
nm_device_get_iface (device));
2908
/* Try to find the master connection/device if the connection has a dependency */
2909
if (!find_master (manager, connection, device, &master_connection, &master_device)) {
2910
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_DEVICE,
2911
"Master connection not found or invalid");
2915
/* Ensure there's a master active connection the new connection we're
2916
* activating can depend on.
2918
if (master_connection || master_device) {
2919
if (master_connection) {
2920
nm_log_dbg (LOGD_CORE, "Activation of '%s' requires master connection '%s'",
2921
nm_connection_get_id (connection),
2922
nm_connection_get_id (master_connection));
2924
if (master_device) {
2925
nm_log_dbg (LOGD_CORE, "Activation of '%s' requires master device '%s'",
2926
nm_connection_get_id (connection),
2927
nm_device_get_ip_iface (master_device));
2930
/* Ensure eg bond slave and the candidate master is a bond master */
2931
if (master_connection && !is_compatible_with_slave (master_connection, connection)) {
2932
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_DEPENDENCY_FAILED,
2933
"The master connection was not compatible");
2937
master_ac = ensure_master_active_connection (manager,
2950
nm_log_dbg (LOGD_CORE, "Activation of '%s' depends on active connection %s",
2951
nm_connection_get_id (connection),
2952
nm_active_connection_get_path (master_ac));
2955
ac = internal_activate_device (manager,
2959
dbus_sender ? TRUE : FALSE,
2960
dbus_sender ? sender_uid : 0,
2968
active_connection_add (manager, ac);
2974
* TODO this function was created and named in the era of user settings, where
2975
* we could get activation requests for a connection before we got the settings
2976
* data of that connection. Now that user settings are gone, flatten or rename
2980
pending_activate (NMManager *self, PendingActivation *pending)
2982
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
2983
NMSettingsConnection *connection;
2984
NMActiveConnection *ac = NULL;
2985
GError *error = NULL;
2988
/* Ok, we're authorized */
2990
connection = nm_settings_get_connection_by_path (priv->settings, pending->connection_path);
2992
error = g_error_new_literal (NM_MANAGER_ERROR,
2993
NM_MANAGER_ERROR_UNKNOWN_CONNECTION,
2994
"Connection could not be found.");
2998
sender = dbus_g_method_get_sender (pending->context);
3000
ac = nm_manager_activate_connection (self,
3001
NM_CONNECTION (connection),
3002
pending->specific_object_path,
3003
pending->device_path,
3009
nm_log_warn (LOGD_CORE, "connection %s failed to activate: (%d) %s",
3010
pending->connection_path,
3011
error ? error->code : -1,
3012
error && error->message ? error->message : "(unknown)");
3016
pending_activation_destroy (pending, error, ac);
3017
g_clear_error (&error);
3021
activation_auth_done (PendingActivation *pending, GError *error)
3024
pending_activation_destroy (pending, error, NULL);
3026
pending_activate (pending->manager, pending);
3030
impl_manager_activate_connection (NMManager *self,
3031
const char *connection_path,
3032
const char *device_path,
3033
const char *specific_object_path,
3034
DBusGMethodInvocation *context)
3036
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3037
PendingActivation *pending;
3038
GError *error = NULL;
3040
/* Need to check the caller's permissions and stuff before we can
3041
* activate the connection.
3043
pending = pending_activation_new (self,
3048
specific_object_path,
3049
activation_auth_done,
3052
pending_activation_check_authorized (pending, priv->dbus_mgr);
3055
dbus_g_method_return_error (context, error);
3056
g_error_free (error);
3061
activation_add_done (NMSettings *self,
3062
NMSettingsConnection *connection,
3064
DBusGMethodInvocation *context,
3067
PendingActivation *pending = user_data;
3070
pending_activation_destroy (pending, error, NULL);
3072
/* Save the new connection's D-Bus path */
3073
pending->connection_path = g_strdup (nm_connection_get_path (NM_CONNECTION (connection)));
3075
/* And activate it */
3076
pending_activate (pending->manager, pending);
3081
add_and_activate_auth_done (PendingActivation *pending, GError *error)
3084
pending_activation_destroy (pending, error, NULL);
3086
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (pending->manager);
3088
/* Basic sender auth checks performed; try to add the connection */
3089
nm_settings_add_connection (priv->settings,
3090
pending->connection,
3092
activation_add_done,
3098
impl_manager_add_and_activate_connection (NMManager *self,
3099
GHashTable *settings,
3100
const char *device_path,
3101
const char *specific_object_path,
3102
DBusGMethodInvocation *context)
3104
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3105
PendingActivation *pending;
3106
GError *error = NULL;
3108
/* Need to check the caller's permissions and stuff before we can
3109
* activate the connection.
3111
pending = pending_activation_new (self,
3116
specific_object_path,
3117
add_and_activate_auth_done,
3120
pending_activation_check_authorized (pending, priv->dbus_mgr);
3123
dbus_g_method_return_error (context, error);
3124
g_error_free (error);
3129
nm_manager_deactivate_connection (NMManager *manager,
3130
const char *connection_path,
3131
NMDeviceStateReason reason,
3134
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
3135
NMActiveConnection *active;
3136
gboolean success = FALSE;
3138
active = active_connection_get_by_path (manager, connection_path);
3140
g_set_error_literal (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_CONNECTION_NOT_ACTIVE,
3141
"The connection was not active.");
3145
if (NM_IS_VPN_CONNECTION (active)) {
3146
NMVPNConnectionStateReason vpn_reason = NM_VPN_CONNECTION_STATE_REASON_USER_DISCONNECTED;
3148
if (reason == NM_DEVICE_STATE_REASON_CONNECTION_REMOVED)
3149
vpn_reason = NM_VPN_CONNECTION_STATE_REASON_CONNECTION_REMOVED;
3150
if (nm_vpn_manager_deactivate_connection (priv->vpn_manager, NM_VPN_CONNECTION (active), vpn_reason))
3153
g_assert (NM_IS_ACT_REQUEST (active));
3154
/* FIXME: use DEACTIVATING state */
3155
nm_device_state_changed (nm_active_connection_get_device (active),
3156
NM_DEVICE_STATE_DISCONNECTED,
3162
g_object_notify (G_OBJECT (manager), NM_MANAGER_ACTIVE_CONNECTIONS);
3168
deactivate_net_auth_done_cb (NMAuthChain *chain,
3170
DBusGMethodInvocation *context,
3173
NMManager *self = NM_MANAGER (user_data);
3174
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3175
GError *error = NULL;
3176
NMAuthCallResult result;
3177
const char *active_path;
3179
priv->auth_chains = g_slist_remove (priv->auth_chains, chain);
3181
result = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, NM_AUTH_PERMISSION_NETWORK_CONTROL));
3183
nm_log_dbg (LOGD_CORE, "Disconnect request failed: %s", auth_error->message);
3184
error = g_error_new (NM_MANAGER_ERROR,
3185
NM_MANAGER_ERROR_PERMISSION_DENIED,
3186
"Deactivate request failed: %s",
3187
auth_error->message);
3188
} else if (result != NM_AUTH_CALL_RESULT_YES) {
3189
error = g_error_new_literal (NM_MANAGER_ERROR,
3190
NM_MANAGER_ERROR_PERMISSION_DENIED,
3191
"Not authorized to deactivate connections");
3193
/* success; deactivation allowed */
3194
active_path = nm_auth_chain_get_data (chain, "path");
3195
if (!nm_manager_deactivate_connection (self,
3197
NM_DEVICE_STATE_REASON_USER_REQUESTED,
3203
dbus_g_method_return_error (context, error);
3205
dbus_g_method_return (context);
3207
g_clear_error (&error);
3208
nm_auth_chain_unref (chain);
3212
impl_manager_deactivate_connection (NMManager *self,
3213
const char *active_path,
3214
DBusGMethodInvocation *context)
3216
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3217
NMConnection *connection = NULL;
3218
GError *error = NULL;
3221
gulong sender_uid = G_MAXULONG;
3222
char *error_desc = NULL;
3224
/* Find the connection by its object path */
3225
for (iter = priv->active_connections; iter; iter = g_slist_next (iter)) {
3226
NMActiveConnection *ac = iter->data;
3228
if (g_strcmp0 (nm_active_connection_get_path (ac), active_path) == 0) {
3229
connection = nm_active_connection_get_connection (ac);
3235
error = g_error_new_literal (NM_MANAGER_ERROR,
3236
NM_MANAGER_ERROR_CONNECTION_NOT_ACTIVE,
3237
"The connection was not active.");
3238
dbus_g_method_return_error (context, error);
3239
g_error_free (error);
3243
/* Need to check the caller's permissions and stuff before we can
3244
* deactivate the connection.
3246
if (!nm_auth_get_caller_uid (context,
3250
error = g_error_new_literal (NM_MANAGER_ERROR,
3251
NM_MANAGER_ERROR_PERMISSION_DENIED,
3253
dbus_g_method_return_error (context, error);
3254
g_error_free (error);
3255
g_free (error_desc);
3260
if (0 == sender_uid) {
3261
if (!nm_manager_deactivate_connection (self,
3263
NM_DEVICE_STATE_REASON_USER_REQUESTED,
3265
dbus_g_method_return_error (context, error);
3266
g_clear_error (&error);
3268
dbus_g_method_return (context);
3273
/* Otherwise validate the user request */
3274
chain = nm_auth_chain_new (context, NULL, deactivate_net_auth_done_cb, self);
3276
priv->auth_chains = g_slist_append (priv->auth_chains, chain);
3278
nm_auth_chain_set_data (chain, "path", g_strdup (active_path), g_free);
3279
nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_NETWORK_CONTROL, TRUE);
3283
do_sleep_wake (NMManager *self)
3285
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3286
const GSList *unmanaged_specs;
3289
if (manager_sleeping (self)) {
3290
nm_log_info (LOGD_SUSPEND, "sleeping or disabling...");
3292
/* Just deactivate and down all devices from the device list,
3293
* to keep things fast the device list will get resynced when
3294
* the manager wakes up.
3296
for (iter = priv->devices; iter; iter = iter->next)
3297
nm_device_set_managed (NM_DEVICE (iter->data), FALSE, NM_DEVICE_STATE_REASON_SLEEPING);
3300
nm_log_info (LOGD_SUSPEND, "waking up and re-enabling...");
3302
unmanaged_specs = nm_settings_get_unmanaged_specs (priv->settings);
3304
/* Ensure rfkill state is up-to-date since we don't respond to state
3305
* changes during sleep.
3307
nm_manager_rfkill_update (self, RFKILL_TYPE_UNKNOWN);
3309
/* Re-manage managed devices */
3310
for (iter = priv->devices; iter; iter = iter->next) {
3311
NMDevice *device = NM_DEVICE (iter->data);
3314
/* enable/disable wireless devices since that we don't respond
3315
* to killswitch changes during sleep.
3317
for (i = 0; i < RFKILL_TYPE_MAX; i++) {
3318
RadioState *rstate = &priv->radio_states[i];
3319
gboolean enabled = radio_enabled_for_rstate (rstate, TRUE);
3322
nm_log_dbg (LOGD_RFKILL, "%s %s devices (hw_enabled %d, sw_enabled %d, user_enabled %d)",
3323
enabled ? "enabling" : "disabling",
3324
rstate->desc, rstate->hw_enabled, rstate->sw_enabled, rstate->user_enabled);
3327
if (nm_device_get_rfkill_type (device) == rstate->rtype)
3328
nm_device_set_enabled (device, enabled);
3331
g_object_set (G_OBJECT (device), NM_DEVICE_AUTOCONNECT, TRUE, NULL);
3333
if (nm_device_spec_match_list (device, unmanaged_specs))
3334
nm_device_set_managed (device, FALSE, NM_DEVICE_STATE_REASON_NOW_UNMANAGED);
3336
nm_device_set_managed (device, TRUE, NM_DEVICE_STATE_REASON_NOW_MANAGED);
3340
nm_manager_update_state (self);
3344
_internal_sleep (NMManager *self, gboolean do_sleep)
3346
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3348
if (priv->sleeping == do_sleep)
3351
nm_log_info (LOGD_SUSPEND, "%s requested (sleeping: %s enabled: %s)",
3352
do_sleep ? "sleep" : "wake",
3353
priv->sleeping ? "yes" : "no",
3354
priv->net_enabled ? "yes" : "no");
3356
priv->sleeping = do_sleep;
3358
do_sleep_wake (self);
3360
g_object_notify (G_OBJECT (self), NM_MANAGER_SLEEPING);
3365
sleep_auth_done_cb (NMAuthChain *chain,
3367
DBusGMethodInvocation *context,
3370
NMManager *self = NM_MANAGER (user_data);
3371
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3373
NMAuthCallResult result;
3376
priv->auth_chains = g_slist_remove (priv->auth_chains, chain);
3378
result = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, NM_AUTH_PERMISSION_SLEEP_WAKE));
3380
nm_log_dbg (LOGD_SUSPEND, "Sleep/wake request failed: %s", error->message);
3381
ret_error = g_error_new (NM_MANAGER_ERROR,
3382
NM_MANAGER_ERROR_PERMISSION_DENIED,
3383
"Sleep/wake request failed: %s",
3385
dbus_g_method_return_error (context, ret_error);
3386
g_error_free (ret_error);
3387
} else if (result != NM_AUTH_CALL_RESULT_YES) {
3388
ret_error = g_error_new_literal (NM_MANAGER_ERROR,
3389
NM_MANAGER_ERROR_PERMISSION_DENIED,
3390
"Not authorized to sleep/wake");
3391
dbus_g_method_return_error (context, ret_error);
3392
g_error_free (ret_error);
3395
do_sleep = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, "sleep"));
3396
_internal_sleep (self, do_sleep);
3397
dbus_g_method_return (context);
3400
nm_auth_chain_unref (chain);
3405
impl_manager_sleep (NMManager *self,
3407
DBusGMethodInvocation *context)
3409
NMManagerPrivate *priv;
3410
GError *error = NULL;
3413
gulong sender_uid = G_MAXULONG;
3414
const char *error_desc = NULL;
3417
g_return_if_fail (NM_IS_MANAGER (self));
3419
priv = NM_MANAGER_GET_PRIVATE (self);
3421
if (priv->sleeping == do_sleep) {
3422
error = g_error_new (NM_MANAGER_ERROR,
3423
NM_MANAGER_ERROR_ALREADY_ASLEEP_OR_AWAKE,
3424
"Already %s", do_sleep ? "asleep" : "awake");
3425
dbus_g_method_return_error (context, error);
3426
g_error_free (error);
3430
/* Unconditionally allow the request. Previously it was polkit protected
3431
* but unfortunately that doesn't work for short-lived processes like
3432
* pm-utils. It uses dbus-send without --print-reply, which quits
3433
* immediately after sending the request, and NM is unable to obtain the
3434
* sender's UID as dbus-send has already dropped off the bus. Thus NM
3435
* fails the request. Instead, don't validate the request, but rely on
3436
* D-Bus permissions to restrict the call to root.
3438
_internal_sleep (self, do_sleep);
3439
dbus_g_method_return (context);
3443
if (!nm_auth_get_caller_uid (context, priv->dbus_mgr, &sender_uid, &error_desc)) {
3444
error = g_error_new_literal (NM_MANAGER_ERROR,
3445
NM_MANAGER_ERROR_PERMISSION_DENIED,
3447
dbus_g_method_return_error (context, error);
3448
g_error_free (error);
3452
/* Root doesn't need PK authentication */
3453
if (0 == sender_uid) {
3454
_internal_sleep (self, do_sleep);
3455
dbus_g_method_return (context);
3459
chain = nm_auth_chain_new (context, NULL, sleep_auth_done_cb, self);
3461
priv->auth_chains = g_slist_append (priv->auth_chains, chain);
3463
nm_auth_chain_set_data (chain, "sleep", GUINT_TO_POINTER (do_sleep), NULL);
3464
nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_SLEEP_WAKE, TRUE);
3469
sleeping_cb (DBusGProxy *proxy, gpointer user_data)
3471
nm_log_dbg (LOGD_SUSPEND, "Received sleeping signal");
3472
_internal_sleep (NM_MANAGER (user_data), TRUE);
3476
resuming_cb (DBusGProxy *proxy, gpointer user_data)
3478
nm_log_dbg (LOGD_SUSPEND, "Received resuming signal");
3479
_internal_sleep (NM_MANAGER (user_data), FALSE);
3483
_internal_enable (NMManager *self, gboolean enable)
3485
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3488
/* Update "NetworkingEnabled" key in state file */
3489
if (priv->state_file) {
3490
if (!write_value_to_state_file (priv->state_file,
3491
"main", "NetworkingEnabled",
3492
G_TYPE_BOOLEAN, (gpointer) &enable,
3494
/* Not a hard error */
3495
nm_log_warn (LOGD_SUSPEND, "writing to state file %s failed: (%d) %s.",
3497
err ? err->code : -1,
3498
(err && err->message) ? err->message : "unknown");
3502
nm_log_info (LOGD_SUSPEND, "%s requested (sleeping: %s enabled: %s)",
3503
enable ? "enable" : "disable",
3504
priv->sleeping ? "yes" : "no",
3505
priv->net_enabled ? "yes" : "no");
3507
priv->net_enabled = enable;
3509
do_sleep_wake (self);
3511
g_object_notify (G_OBJECT (self), NM_MANAGER_NETWORKING_ENABLED);
3515
enable_net_done_cb (NMAuthChain *chain,
3517
DBusGMethodInvocation *context,
3520
NMManager *self = NM_MANAGER (user_data);
3521
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3523
NMAuthCallResult result;
3526
priv->auth_chains = g_slist_remove (priv->auth_chains, chain);
3528
result = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK));
3530
nm_log_dbg (LOGD_CORE, "Enable request failed: %s", error->message);
3531
ret_error = g_error_new (NM_MANAGER_ERROR,
3532
NM_MANAGER_ERROR_PERMISSION_DENIED,
3533
"Enable request failed: %s",
3535
dbus_g_method_return_error (context, ret_error);
3536
g_error_free (ret_error);
3537
} else if (result != NM_AUTH_CALL_RESULT_YES) {
3538
ret_error = g_error_new_literal (NM_MANAGER_ERROR,
3539
NM_MANAGER_ERROR_PERMISSION_DENIED,
3540
"Not authorized to enable/disable networking");
3541
dbus_g_method_return_error (context, ret_error);
3542
g_error_free (ret_error);
3545
enable = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, "enable"));
3546
_internal_enable (self, enable);
3547
dbus_g_method_return (context);
3550
nm_auth_chain_unref (chain);
3554
impl_manager_enable (NMManager *self,
3556
DBusGMethodInvocation *context)
3558
NMManagerPrivate *priv;
3560
GError *error = NULL;
3561
gulong sender_uid = G_MAXULONG;
3562
char *error_desc = NULL;
3564
g_return_if_fail (NM_IS_MANAGER (self));
3566
priv = NM_MANAGER_GET_PRIVATE (self);
3568
if (priv->net_enabled == enable) {
3569
error = g_error_new (NM_MANAGER_ERROR,
3570
NM_MANAGER_ERROR_ALREADY_ENABLED_OR_DISABLED,
3571
"Already %s", enable ? "enabled" : "disabled");
3572
dbus_g_method_return_error (context, error);
3573
g_error_free (error);
3577
if (!nm_auth_get_caller_uid (context, priv->dbus_mgr, &sender_uid, &error_desc)) {
3578
error = g_error_new_literal (NM_MANAGER_ERROR,
3579
NM_MANAGER_ERROR_PERMISSION_DENIED,
3581
dbus_g_method_return_error (context, error);
3582
g_error_free (error);
3583
g_free (error_desc);
3587
/* Root doesn't need PK authentication */
3588
if (0 == sender_uid) {
3589
_internal_enable (self, enable);
3590
dbus_g_method_return (context);
3594
chain = nm_auth_chain_new (context, NULL, enable_net_done_cb, self);
3596
priv->auth_chains = g_slist_append (priv->auth_chains, chain);
3598
nm_auth_chain_set_data (chain, "enable", GUINT_TO_POINTER (enable), NULL);
3599
nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK, TRUE);
3605
get_perm_add_result (NMAuthChain *chain, GHashTable *results, const char *permission)
3607
NMAuthCallResult result;
3609
result = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, permission));
3610
if (result == NM_AUTH_CALL_RESULT_YES)
3611
g_hash_table_insert (results, (char *) permission, "yes");
3612
else if (result == NM_AUTH_CALL_RESULT_NO)
3613
g_hash_table_insert (results, (char *) permission, "no");
3614
else if (result == NM_AUTH_CALL_RESULT_AUTH)
3615
g_hash_table_insert (results, (char *) permission, "auth");
3617
nm_log_dbg (LOGD_CORE, "unknown auth chain result %d", result);
3622
get_permissions_done_cb (NMAuthChain *chain,
3624
DBusGMethodInvocation *context,
3627
NMManager *self = NM_MANAGER (user_data);
3628
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3630
GHashTable *results;
3632
priv->auth_chains = g_slist_remove (priv->auth_chains, chain);
3634
nm_log_dbg (LOGD_CORE, "Permissions request failed: %s", error->message);
3635
ret_error = g_error_new (NM_MANAGER_ERROR,
3636
NM_MANAGER_ERROR_PERMISSION_DENIED,
3637
"Permissions request failed: %s",
3639
dbus_g_method_return_error (context, ret_error);
3640
g_error_free (ret_error);
3642
results = g_hash_table_new (g_str_hash, g_str_equal);
3643
get_perm_add_result (chain, results, NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK);
3644
get_perm_add_result (chain, results, NM_AUTH_PERMISSION_SLEEP_WAKE);
3645
get_perm_add_result (chain, results, NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI);
3646
get_perm_add_result (chain, results, NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN);
3647
get_perm_add_result (chain, results, NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX);
3648
get_perm_add_result (chain, results, NM_AUTH_PERMISSION_NETWORK_CONTROL);
3649
get_perm_add_result (chain, results, NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED);
3650
get_perm_add_result (chain, results, NM_AUTH_PERMISSION_WIFI_SHARE_OPEN);
3651
get_perm_add_result (chain, results, NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM);
3652
get_perm_add_result (chain, results, NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN);
3653
get_perm_add_result (chain, results, NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME);
3654
dbus_g_method_return (context, results);
3655
g_hash_table_destroy (results);
3658
nm_auth_chain_unref (chain);
3662
impl_manager_get_permissions (NMManager *self,
3663
DBusGMethodInvocation *context)
3665
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3668
chain = nm_auth_chain_new (context, NULL, get_permissions_done_cb, self);
3670
priv->auth_chains = g_slist_append (priv->auth_chains, chain);
3672
nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_ENABLE_DISABLE_NETWORK, FALSE);
3673
nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_SLEEP_WAKE, FALSE);
3674
nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI, FALSE);
3675
nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN, FALSE);
3676
nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX, FALSE);
3677
nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_NETWORK_CONTROL, FALSE);
3678
nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_WIFI_SHARE_PROTECTED, FALSE);
3679
nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_WIFI_SHARE_OPEN, FALSE);
3680
nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_SETTINGS_MODIFY_SYSTEM, FALSE);
3681
nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_SETTINGS_MODIFY_OWN, FALSE);
3682
nm_auth_chain_add_call (chain, NM_AUTH_PERMISSION_SETTINGS_MODIFY_HOSTNAME, FALSE);
3686
impl_manager_get_state (NMManager *manager, guint32 *state, GError **error)
3688
nm_manager_update_state (manager);
3689
*state = NM_MANAGER_GET_PRIVATE (manager)->state;
3694
impl_manager_set_logging (NMManager *manager,
3696
const char *domains,
3699
if (nm_logging_setup (level, domains, error)) {
3700
char *new_domains = nm_logging_domains_to_string ();
3702
nm_log_info (LOGD_CORE, "logging: level '%s' domains '%s'",
3703
nm_logging_level_to_string (),
3705
g_free (new_domains);
3712
impl_manager_get_logging (NMManager *manager,
3716
*level = g_strdup (nm_logging_level_to_string ());
3717
*domains = g_strdup (nm_logging_domains_to_string ());
3721
nm_manager_start (NMManager *self)
3723
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3726
/* Set initial radio enabled/disabled state */
3727
for (i = 0; i < RFKILL_TYPE_MAX; i++) {
3728
RadioState *rstate = &priv->radio_states[i];
3729
RfKillState udev_state;
3735
udev_state = nm_udev_manager_get_rfkill_state (priv->udev_mgr, i);
3736
update_rstate_from_rfkill (rstate, udev_state);
3739
nm_log_info (LOGD_RFKILL, "%s %s by radio killswitch; %s by state file",
3741
(rstate->hw_enabled && rstate->sw_enabled) ? "enabled" : "disabled",
3742
rstate->user_enabled ? "enabled" : "disabled");
3744
enabled = radio_enabled_for_rstate (rstate, TRUE);
3745
manager_update_radio_enabled (self, rstate, enabled);
3748
/* Log overall networking status - enabled/disabled */
3749
nm_log_info (LOGD_CORE, "Networking is %s by state file",
3750
priv->net_enabled ? "enabled" : "disabled");
3752
system_unmanaged_devices_changed_cb (priv->settings, NULL, self);
3753
system_hostname_changed_cb (priv->settings, NULL, self);
3755
/* FIXME: remove when we handle bridges non-destructively */
3756
/* Read a list of bridges NM managed when it last quit, and only
3757
* manage those bridges to avoid conflicts with external tools.
3759
priv->nm_bridges = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
3760
read_nm_created_bridges (self);
3762
nm_udev_manager_query_devices (priv->udev_mgr);
3763
nm_bluez_manager_query_devices (priv->bluez_mgr);
3765
/* Query devices again to ensure that we catch all virtual interfaces (like
3766
* VLANs) that require a parent. If during the first pass the VLAN
3767
* interface was detected first, the parent wouldn't exist yet and creating
3768
* the VLAN would fail. The second query ensures that we'll have a valid
3769
* parent for the VLAN during the second pass.
3771
nm_udev_manager_query_devices (priv->udev_mgr);
3774
* Connections added before the manager is started do not emit
3775
* connection-added signals thus devices have to be created manually.
3777
system_create_virtual_devices (self);
3779
/* FIXME: remove when we handle bridges non-destructively */
3780
g_hash_table_unref (priv->nm_bridges);
3781
priv->nm_bridges = NULL;
3785
handle_firmware_changed (gpointer user_data)
3787
NMManager *self = NM_MANAGER (user_data);
3788
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3791
priv->fw_changed_id = 0;
3793
if (manager_sleeping (self))
3796
/* Try to re-enable devices with missing firmware */
3797
for (iter = priv->devices; iter; iter = iter->next) {
3798
NMDevice *candidate = NM_DEVICE (iter->data);
3799
NMDeviceState state = nm_device_get_state (candidate);
3801
if ( nm_device_get_firmware_missing (candidate)
3802
&& (state == NM_DEVICE_STATE_UNAVAILABLE)) {
3803
nm_log_info (LOGD_CORE, "(%s): firmware may now be available",
3804
nm_device_get_iface (candidate));
3806
/* Re-set unavailable state to try bringing the device up again */
3807
nm_device_state_changed (candidate,
3808
NM_DEVICE_STATE_UNAVAILABLE,
3809
NM_DEVICE_STATE_REASON_NONE);
3818
connectivity_changed (NMConnectivity *connectivity,
3822
NMManager *self = NM_MANAGER (user_data);
3825
connected = nm_connectivity_get_connected (connectivity);
3826
nm_log_dbg (LOGD_CORE, "connectivity checking indicates %s",
3827
connected ? "CONNECTED" : "NOT CONNECTED");
3829
nm_manager_update_state (self);
3831
#endif /* WITH_CONCHECK */
3834
firmware_dir_changed (GFileMonitor *monitor,
3837
GFileMonitorEvent event_type,
3840
NMManager *self = NM_MANAGER (user_data);
3841
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3843
switch (event_type) {
3844
case G_FILE_MONITOR_EVENT_CREATED:
3845
case G_FILE_MONITOR_EVENT_CHANGED:
3846
#if GLIB_CHECK_VERSION(2,23,4)
3847
case G_FILE_MONITOR_EVENT_MOVED:
3849
case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
3850
case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
3851
if (!priv->fw_changed_id) {
3852
priv->fw_changed_id = g_timeout_add_seconds (4, handle_firmware_changed, self);
3853
nm_log_info (LOGD_CORE, "kernel firmware directory '%s' changed",
3854
KERNEL_FIRMWARE_DIR);
3862
#define NM_PERM_DENIED_ERROR "org.freedesktop.NetworkManager.PermissionDenied"
3863
#define DEV_PERM_DENIED_ERROR "org.freedesktop.NetworkManager.Device.PermissionDenied"
3866
prop_set_auth_done_cb (NMAuthChain *chain,
3868
DBusGMethodInvocation *context,
3871
NMManager *self = NM_MANAGER (user_data);
3872
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3873
DBusGConnection *bus;
3874
DBusConnection *dbus_connection;
3875
NMAuthCallResult result;
3876
DBusMessage *reply = NULL, *request;
3878
const char *permission, *prop, *objpath;
3879
gboolean set_enabled = TRUE;
3880
gboolean is_device = FALSE;
3884
priv->auth_chains = g_slist_remove (priv->auth_chains, chain);
3886
request = nm_auth_chain_get_data (chain, "message");
3887
permission = nm_auth_chain_get_data (chain, "permission");
3888
prop = nm_auth_chain_get_data (chain, "prop");
3889
set_enabled = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, "enabled"));
3890
objpath = nm_auth_chain_get_data (chain, "objectpath");
3892
objpath_len = strlen (objpath);
3893
devpath_len = strlen (NM_DBUS_PATH "/Devices");
3894
if ( strncmp (objpath, NM_DBUS_PATH "/Devices", devpath_len) == 0
3895
&& objpath_len > devpath_len)
3899
reply = dbus_message_new_error (request, is_device ? DEV_PERM_DENIED_ERROR : NM_PERM_DENIED_ERROR,
3900
"Not authorized to perform this operation");
3902
/* Caller has had a chance to obtain authorization, so we only need to
3903
* check for 'yes' here.
3905
result = GPOINTER_TO_UINT (nm_auth_chain_get_data (chain, permission));
3906
if (result != NM_AUTH_CALL_RESULT_YES) {
3907
reply = dbus_message_new_error (request, is_device ? DEV_PERM_DENIED_ERROR : NM_PERM_DENIED_ERROR,
3908
"Not authorized to perform this operation");
3911
/* Find the device */
3912
NMDevice *device = nm_manager_get_device_by_path (self, objpath);
3914
g_object_set (device, prop, set_enabled, NULL);
3915
reply = dbus_message_new_method_return (request);
3918
ret_error = g_error_new_literal (NM_MANAGER_ERROR,
3919
NM_MANAGER_ERROR_UNKNOWN_DEVICE,
3920
"Can't find device for this operation");
3921
dbus_g_method_return_error (context, ret_error);
3922
g_error_free (ret_error);
3925
g_object_set (self, prop, set_enabled, NULL);
3926
reply = dbus_message_new_method_return (request);
3932
bus = nm_dbus_manager_get_connection (priv->dbus_mgr);
3934
dbus_connection = dbus_g_connection_get_connection (bus);
3935
g_assert (dbus_connection);
3937
dbus_connection_send (dbus_connection, reply, NULL);
3938
dbus_message_unref (reply);
3940
nm_auth_chain_unref (chain);
3943
static DBusHandlerResult
3944
prop_filter (DBusConnection *connection,
3945
DBusMessage *message,
3948
NMManager *self = NM_MANAGER (user_data);
3949
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
3950
DBusMessageIter iter;
3951
DBusMessageIter sub;
3952
const char *propiface = NULL;
3953
const char *propname = NULL;
3954
const char *sender = NULL;
3955
const char *objpath = NULL;
3956
const char *glib_propname = NULL, *permission = NULL;
3957
DBusError dbus_error;
3958
gulong uid = G_MAXULONG;
3959
DBusMessage *reply = NULL;
3960
gboolean set_enabled = FALSE;
3963
/* The sole purpose of this function is to validate property accesses
3964
* on the NMManager object since dbus-glib doesn't yet give us this
3968
if (!dbus_message_is_method_call (message, DBUS_INTERFACE_PROPERTIES, "Set"))
3969
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
3971
dbus_message_iter_init (message, &iter);
3973
/* Get the D-Bus interface of the property to set */
3974
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING)
3975
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
3976
dbus_message_iter_get_basic (&iter, &propiface);
3977
if (!propiface || (strcmp (propiface, NM_DBUS_INTERFACE) && strcmp (propiface, NM_DBUS_INTERFACE_DEVICE)))
3978
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
3979
dbus_message_iter_next (&iter);
3981
/* Get the property name that's going to be set */
3982
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_STRING)
3983
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
3984
dbus_message_iter_get_basic (&iter, &propname);
3985
dbus_message_iter_next (&iter);
3987
if (!strcmp (propname, "WirelessEnabled")) {
3988
glib_propname = NM_MANAGER_WIRELESS_ENABLED;
3989
permission = NM_AUTH_PERMISSION_ENABLE_DISABLE_WIFI;
3990
} else if (!strcmp (propname, "WwanEnabled")) {
3991
glib_propname = NM_MANAGER_WWAN_ENABLED;
3992
permission = NM_AUTH_PERMISSION_ENABLE_DISABLE_WWAN;
3993
} else if (!strcmp (propname, "WimaxEnabled")) {
3994
glib_propname = NM_MANAGER_WIMAX_ENABLED;
3995
permission = NM_AUTH_PERMISSION_ENABLE_DISABLE_WIMAX;
3996
} else if (!strcmp (propname, "Autoconnect")) {
3997
glib_propname = NM_DEVICE_AUTOCONNECT;
3998
permission = NM_AUTH_PERMISSION_NETWORK_CONTROL;
4000
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
4002
/* Get the new value for the property */
4003
if (dbus_message_iter_get_arg_type (&iter) != DBUS_TYPE_VARIANT)
4004
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
4005
dbus_message_iter_recurse (&iter, &sub);
4006
if (dbus_message_iter_get_arg_type (&sub) != DBUS_TYPE_BOOLEAN)
4007
return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
4008
dbus_message_iter_get_basic (&sub, &set_enabled);
4010
sender = dbus_message_get_sender (message);
4012
reply = dbus_message_new_error (message, NM_PERM_DENIED_ERROR,
4013
"Could not determine D-Bus requestor");
4017
objpath = dbus_message_get_path (message);
4019
reply = dbus_message_new_error (message, NM_PERM_DENIED_ERROR,
4020
"Could not determine D-Bus object path");
4024
dbus_error_init (&dbus_error);
4025
uid = dbus_bus_get_unix_user (connection, sender, &dbus_error);
4026
if (dbus_error_is_set (&dbus_error)) {
4027
reply = dbus_message_new_error (message, NM_PERM_DENIED_ERROR,
4028
"Could not determine the user ID of the requestor");
4029
dbus_error_free (&dbus_error);
4034
/* Otherwise validate the user request */
4035
chain = nm_auth_chain_new_raw_message (message, prop_set_auth_done_cb, self);
4037
priv->auth_chains = g_slist_append (priv->auth_chains, chain);
4038
nm_auth_chain_set_data (chain, "prop", g_strdup (glib_propname), g_free);
4039
nm_auth_chain_set_data (chain, "permission", g_strdup (permission), g_free);
4040
nm_auth_chain_set_data (chain, "enabled", GUINT_TO_POINTER (set_enabled), NULL);
4041
nm_auth_chain_set_data (chain, "message", dbus_message_ref (message), (GDestroyNotify) dbus_message_unref);
4042
nm_auth_chain_set_data (chain, "objectpath", g_strdup (objpath), g_free);
4043
nm_auth_chain_add_call (chain, permission, TRUE);
4046
g_object_set (self, glib_propname, set_enabled, NULL);
4047
reply = dbus_message_new_method_return (message);
4052
dbus_connection_send (connection, reply, NULL);
4053
dbus_message_unref (reply);
4055
return DBUS_HANDLER_RESULT_HANDLED;
4058
static NMManager *singleton = NULL;
4061
nm_manager_get (void)
4063
g_assert (singleton);
4064
return g_object_ref (singleton);
4068
nm_manager_new (NMSettings *settings,
4069
const char *state_file,
4070
gboolean initial_net_enabled,
4071
gboolean initial_wifi_enabled,
4072
gboolean initial_wwan_enabled,
4073
gboolean initial_wimax_enabled,
4074
const gchar *connectivity_uri,
4075
gint connectivity_interval,
4076
const gchar *connectivity_response,
4079
NMManagerPrivate *priv;
4080
DBusGConnection *bus;
4081
DBusConnection *dbus_connection;
4083
g_assert (settings);
4085
/* Can only be called once */
4086
g_assert (singleton == NULL);
4087
singleton = (NMManager *) g_object_new (NM_TYPE_MANAGER, NULL);
4088
g_assert (singleton);
4090
priv = NM_MANAGER_GET_PRIVATE (singleton);
4093
priv->connectivity = nm_connectivity_new (connectivity_uri, connectivity_interval, connectivity_response);
4095
g_signal_connect (priv->connectivity, "notify::" NM_CONNECTIVITY_CONNECTED,
4096
G_CALLBACK (connectivity_changed), singleton);
4099
bus = nm_dbus_manager_get_connection (priv->dbus_mgr);
4101
dbus_connection = dbus_g_connection_get_connection (bus);
4102
g_assert (dbus_connection);
4104
if (!dbus_connection_add_filter (dbus_connection, prop_filter, singleton, NULL)) {
4105
nm_log_err (LOGD_CORE, "failed to register DBus connection filter");
4106
g_object_unref (singleton);
4110
priv->settings = g_object_ref (settings);
4112
priv->state_file = g_strdup (state_file);
4114
priv->net_enabled = initial_net_enabled;
4116
priv->radio_states[RFKILL_TYPE_WLAN].user_enabled = initial_wifi_enabled;
4117
priv->radio_states[RFKILL_TYPE_WWAN].user_enabled = initial_wwan_enabled;
4118
priv->radio_states[RFKILL_TYPE_WIMAX].user_enabled = initial_wimax_enabled;
4120
g_signal_connect (priv->settings, "notify::" NM_SETTINGS_UNMANAGED_SPECS,
4121
G_CALLBACK (system_unmanaged_devices_changed_cb), singleton);
4122
g_signal_connect (priv->settings, "notify::" NM_SETTINGS_HOSTNAME,
4123
G_CALLBACK (system_hostname_changed_cb), singleton);
4124
g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_ADDED,
4125
G_CALLBACK (connection_added), singleton);
4126
g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_UPDATED,
4127
G_CALLBACK (connection_changed), singleton);
4128
g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_REMOVED,
4129
G_CALLBACK (connection_removed), singleton);
4130
g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_VISIBILITY_CHANGED,
4131
G_CALLBACK (connection_changed), singleton);
4133
dbus_g_connection_register_g_object (bus, NM_DBUS_PATH, G_OBJECT (singleton));
4135
priv->udev_mgr = nm_udev_manager_new ();
4136
g_signal_connect (priv->udev_mgr,
4138
G_CALLBACK (udev_device_added_cb),
4140
g_signal_connect (priv->udev_mgr,
4142
G_CALLBACK (udev_device_removed_cb),
4144
g_signal_connect (priv->udev_mgr,
4146
G_CALLBACK (udev_manager_rfkill_changed_cb),
4149
priv->bluez_mgr = nm_bluez_manager_get (NM_CONNECTION_PROVIDER (priv->settings));
4151
g_signal_connect (priv->bluez_mgr,
4152
NM_BLUEZ_MANAGER_BDADDR_ADDED,
4153
G_CALLBACK (bluez_manager_bdaddr_added_cb),
4156
g_signal_connect (priv->bluez_mgr,
4157
NM_BLUEZ_MANAGER_BDADDR_REMOVED,
4158
G_CALLBACK (bluez_manager_bdaddr_removed_cb),
4161
/* Force kernel WiFi rfkill state to follow NM saved wifi state in case
4162
* the BIOS doesn't save rfkill state, and to be consistent with user
4163
* changes to the WirelessEnabled property which toggles kernel rfkill.
4165
rfkill_change_wifi (priv->radio_states[RFKILL_TYPE_WLAN].desc, initial_wifi_enabled);
4171
authority_changed_cb (gpointer user_data)
4173
/* Let clients know they should re-check their authorization */
4174
g_signal_emit (NM_MANAGER (user_data), signals[CHECK_PERMISSIONS], 0);
4178
dispose (GObject *object)
4180
NMManager *manager = NM_MANAGER (object);
4181
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
4182
DBusGConnection *bus;
4183
DBusConnection *dbus_connection;
4186
if (priv->disposed) {
4187
G_OBJECT_CLASS (nm_manager_parent_class)->dispose (object);
4190
priv->disposed = TRUE;
4192
g_slist_foreach (priv->auth_chains, (GFunc) nm_auth_chain_unref, NULL);
4193
g_slist_free (priv->auth_chains);
4195
nm_auth_changed_func_unregister (authority_changed_cb, manager);
4197
/* FIXME: remove when we handle bridges non-destructively */
4198
write_nm_created_bridges (manager);
4200
/* Remove all devices */
4201
while (g_slist_length (priv->devices)) {
4202
priv->devices = remove_one_device (manager,
4204
NM_DEVICE (priv->devices->data),
4208
if (priv->ac_cleanup_id) {
4209
g_source_remove (priv->ac_cleanup_id);
4210
priv->ac_cleanup_id = 0;
4213
for (iter = priv->active_connections; iter; iter = g_slist_next (iter)) {
4214
g_signal_handlers_disconnect_by_func (iter->data, active_connection_state_changed, object);
4215
g_object_unref (iter->data);
4217
g_slist_free (priv->active_connections);
4220
if (priv->connectivity) {
4221
g_object_unref (priv->connectivity);
4222
priv->connectivity = NULL;
4226
g_free (priv->hostname);
4228
g_object_unref (priv->settings);
4229
g_object_unref (priv->vpn_manager);
4231
if (priv->modem_added_id) {
4232
g_source_remove (priv->modem_added_id);
4233
priv->modem_added_id = 0;
4235
if (priv->modem_removed_id) {
4236
g_source_remove (priv->modem_removed_id);
4237
priv->modem_removed_id = 0;
4239
g_object_unref (priv->modem_manager);
4241
/* Unregister property filter */
4242
bus = nm_dbus_manager_get_connection (priv->dbus_mgr);
4244
dbus_connection = dbus_g_connection_get_connection (bus);
4245
g_assert (dbus_connection);
4246
dbus_connection_remove_filter (dbus_connection, prop_filter, manager);
4248
g_object_unref (priv->dbus_mgr);
4250
if (priv->bluez_mgr)
4251
g_object_unref (priv->bluez_mgr);
4253
if (priv->aipd_proxy)
4254
g_object_unref (priv->aipd_proxy);
4256
if (priv->sleep_monitor)
4257
g_object_unref (priv->sleep_monitor);
4259
if (priv->fw_monitor) {
4260
if (priv->fw_monitor_id)
4261
g_signal_handler_disconnect (priv->fw_monitor, priv->fw_monitor_id);
4263
if (priv->fw_changed_id)
4264
g_source_remove (priv->fw_changed_id);
4266
g_file_monitor_cancel (priv->fw_monitor);
4267
g_object_unref (priv->fw_monitor);
4270
g_slist_free (priv->factories);
4272
if (priv->timestamp_update_id) {
4273
g_source_remove (priv->timestamp_update_id);
4274
priv->timestamp_update_id = 0;
4277
G_OBJECT_CLASS (nm_manager_parent_class)->dispose (object);
4280
#define KERN_RFKILL_OP_CHANGE_ALL 3
4281
#define KERN_RFKILL_TYPE_WLAN 1
4282
struct rfkill_event {
4287
} __attribute__((packed));
4290
rfkill_change_wifi (const char *desc, gboolean enabled)
4293
struct rfkill_event event;
4297
fd = open ("/dev/rfkill", O_RDWR);
4299
if (errno == EACCES)
4300
nm_log_warn (LOGD_RFKILL, "(%s): failed to open killswitch device "
4301
"for WiFi radio control", desc);
4305
if (fcntl (fd, F_SETFL, O_NONBLOCK) < 0) {
4306
nm_log_warn (LOGD_RFKILL, "(%s): failed to set killswitch device for "
4307
"non-blocking operation", desc);
4312
memset (&event, 0, sizeof (event));
4313
event.op = KERN_RFKILL_OP_CHANGE_ALL;
4314
event.type = KERN_RFKILL_TYPE_WLAN;
4315
event.soft = enabled ? 0 : 1;
4317
len = write (fd, &event, sizeof (event));
4319
nm_log_warn (LOGD_RFKILL, "(%s): failed to change WiFi killswitch state: (%d) %s",
4320
desc, errno, g_strerror (errno));
4321
} else if (len == sizeof (event)) {
4322
nm_log_info (LOGD_RFKILL, "%s hardware radio set %s",
4323
desc, enabled ? "enabled" : "disabled");
4325
/* Failed to write full structure */
4326
nm_log_warn (LOGD_RFKILL, "(%s): failed to change WiFi killswitch state", desc);
4333
manager_radio_user_toggled (NMManager *self,
4337
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
4338
GError *error = NULL;
4339
gboolean old_enabled, new_enabled;
4342
nm_log_dbg (LOGD_RFKILL, "(%s): setting radio %s by user",
4344
enabled ? "enabled" : "disabled");
4347
/* Update enabled key in state file */
4348
if (priv->state_file) {
4349
if (!write_value_to_state_file (priv->state_file,
4350
"main", rstate->key,
4351
G_TYPE_BOOLEAN, (gpointer) &enabled,
4353
nm_log_warn (LOGD_CORE, "writing to state file %s failed: (%d) %s.",
4355
error ? error->code : -1,
4356
(error && error->message) ? error->message : "unknown");
4357
g_clear_error (&error);
4361
/* When the user toggles the radio, their request should override any
4362
* daemon (like ModemManager) enabled state that can be changed. For WWAN
4363
* for example, we want the WwanEnabled property to reflect the daemon state
4364
* too so that users can toggle the modem powered, but we don't want that
4365
* daemon state to affect whether or not the user *can* turn it on, which is
4366
* what the kernel rfkill state does. So we ignore daemon enabled state
4367
* when determining what the new state should be since it shouldn't block
4368
* the user's request.
4370
old_enabled = radio_enabled_for_rstate (rstate, TRUE);
4371
rstate->user_enabled = enabled;
4372
new_enabled = radio_enabled_for_rstate (rstate, FALSE);
4373
if (new_enabled != old_enabled) {
4374
manager_update_radio_enabled (self, rstate, new_enabled);
4376
/* For WiFi only (for now) set the actual kernel rfkill state */
4377
if (rstate->rtype == RFKILL_TYPE_WLAN)
4378
rfkill_change_wifi (rstate->desc, new_enabled);
4383
set_property (GObject *object, guint prop_id,
4384
const GValue *value, GParamSpec *pspec)
4386
NMManager *self = NM_MANAGER (object);
4387
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
4390
case PROP_NETWORKING_ENABLED:
4391
/* Construct only for now */
4392
priv->net_enabled = g_value_get_boolean (value);
4394
case PROP_WIRELESS_ENABLED:
4395
manager_radio_user_toggled (NM_MANAGER (object),
4396
&priv->radio_states[RFKILL_TYPE_WLAN],
4397
g_value_get_boolean (value));
4399
case PROP_WWAN_ENABLED:
4400
manager_radio_user_toggled (NM_MANAGER (object),
4401
&priv->radio_states[RFKILL_TYPE_WWAN],
4402
g_value_get_boolean (value));
4404
case PROP_WIMAX_ENABLED:
4405
manager_radio_user_toggled (NM_MANAGER (object),
4406
&priv->radio_states[RFKILL_TYPE_WIMAX],
4407
g_value_get_boolean (value));
4410
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
4416
get_property (GObject *object, guint prop_id,
4417
GValue *value, GParamSpec *pspec)
4419
NMManager *self = NM_MANAGER (object);
4420
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (self);
4427
g_value_set_string (value, VERSION);
4430
nm_manager_update_state (self);
4431
g_value_set_uint (value, priv->state);
4433
case PROP_NETWORKING_ENABLED:
4434
g_value_set_boolean (value, priv->net_enabled);
4436
case PROP_WIRELESS_ENABLED:
4437
g_value_set_boolean (value, radio_enabled_for_type (self, RFKILL_TYPE_WLAN, TRUE));
4439
case PROP_WIRELESS_HARDWARE_ENABLED:
4440
g_value_set_boolean (value, priv->radio_states[RFKILL_TYPE_WLAN].hw_enabled);
4442
case PROP_WWAN_ENABLED:
4443
g_value_set_boolean (value, radio_enabled_for_type (self, RFKILL_TYPE_WWAN, TRUE));
4445
case PROP_WWAN_HARDWARE_ENABLED:
4446
g_value_set_boolean (value, priv->radio_states[RFKILL_TYPE_WWAN].hw_enabled);
4448
case PROP_WIMAX_ENABLED:
4449
g_value_set_boolean (value, radio_enabled_for_type (self, RFKILL_TYPE_WIMAX, TRUE));
4451
case PROP_WIMAX_HARDWARE_ENABLED:
4452
g_value_set_boolean (value, priv->radio_states[RFKILL_TYPE_WIMAX].hw_enabled);
4454
case PROP_ACTIVE_CONNECTIONS:
4455
active = g_ptr_array_sized_new (3);
4456
for (iter = priv->active_connections; iter; iter = g_slist_next (iter)) {
4457
path = nm_active_connection_get_path (NM_ACTIVE_CONNECTION (iter->data));
4458
g_ptr_array_add (active, g_strdup (path));
4460
g_value_take_boxed (value, active);
4463
g_value_set_string (value, priv->hostname);
4466
g_value_set_boolean (value, priv->sleeping);
4469
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
4475
periodic_update_active_connection_timestamps (gpointer user_data)
4477
NMManager *manager = NM_MANAGER (user_data);
4478
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
4481
for (iter = priv->active_connections; iter; iter = g_slist_next (iter)) {
4482
NMActiveConnection *ac = iter->data;
4483
NMSettingsConnection *connection;
4485
if (nm_active_connection_get_state (ac) == NM_ACTIVE_CONNECTION_STATE_ACTIVATED) {
4486
connection = NM_SETTINGS_CONNECTION (nm_active_connection_get_connection (ac));
4487
nm_settings_connection_update_timestamp (connection, (guint64) time (NULL), FALSE);
4495
nm_manager_init (NMManager *manager)
4497
NMManagerPrivate *priv = NM_MANAGER_GET_PRIVATE (manager);
4498
DBusGConnection *g_connection;
4502
/* Initialize rfkill structures and states */
4503
memset (priv->radio_states, 0, sizeof (priv->radio_states));
4505
priv->radio_states[RFKILL_TYPE_WLAN].user_enabled = TRUE;
4506
priv->radio_states[RFKILL_TYPE_WLAN].key = "WirelessEnabled";
4507
priv->radio_states[RFKILL_TYPE_WLAN].prop = NM_MANAGER_WIRELESS_ENABLED;
4508
priv->radio_states[RFKILL_TYPE_WLAN].hw_prop = NM_MANAGER_WIRELESS_HARDWARE_ENABLED;
4509
priv->radio_states[RFKILL_TYPE_WLAN].desc = "WiFi";
4510
priv->radio_states[RFKILL_TYPE_WLAN].other_enabled_func = nm_manager_get_ipw_rfkill_state;
4511
priv->radio_states[RFKILL_TYPE_WLAN].rtype = RFKILL_TYPE_WLAN;
4513
priv->radio_states[RFKILL_TYPE_WWAN].user_enabled = TRUE;
4514
priv->radio_states[RFKILL_TYPE_WWAN].key = "WWANEnabled";
4515
priv->radio_states[RFKILL_TYPE_WWAN].prop = NM_MANAGER_WWAN_ENABLED;
4516
priv->radio_states[RFKILL_TYPE_WWAN].hw_prop = NM_MANAGER_WWAN_HARDWARE_ENABLED;
4517
priv->radio_states[RFKILL_TYPE_WWAN].desc = "WWAN";
4518
priv->radio_states[RFKILL_TYPE_WWAN].daemon_enabled_func = nm_manager_get_modem_enabled_state;
4519
priv->radio_states[RFKILL_TYPE_WWAN].rtype = RFKILL_TYPE_WWAN;
4521
priv->radio_states[RFKILL_TYPE_WIMAX].user_enabled = TRUE;
4522
priv->radio_states[RFKILL_TYPE_WIMAX].key = "WiMAXEnabled";
4523
priv->radio_states[RFKILL_TYPE_WIMAX].prop = NM_MANAGER_WIMAX_ENABLED;
4524
priv->radio_states[RFKILL_TYPE_WIMAX].hw_prop = NM_MANAGER_WIMAX_HARDWARE_ENABLED;
4525
priv->radio_states[RFKILL_TYPE_WIMAX].desc = "WiMAX";
4526
priv->radio_states[RFKILL_TYPE_WIMAX].other_enabled_func = NULL;
4527
priv->radio_states[RFKILL_TYPE_WIMAX].rtype = RFKILL_TYPE_WIMAX;
4529
for (i = 0; i < RFKILL_TYPE_MAX; i++)
4530
priv->radio_states[i].hw_enabled = TRUE;
4532
priv->sleeping = FALSE;
4533
priv->state = NM_STATE_DISCONNECTED;
4535
priv->dbus_mgr = nm_dbus_manager_get ();
4537
priv->modem_manager = nm_modem_manager_get ();
4538
priv->modem_added_id = g_signal_connect (priv->modem_manager, "modem-added",
4539
G_CALLBACK (modem_added), manager);
4540
priv->modem_removed_id = g_signal_connect (priv->modem_manager, "modem-removed",
4541
G_CALLBACK (modem_removed), manager);
4543
priv->vpn_manager = nm_vpn_manager_get ();
4545
g_connection = nm_dbus_manager_get_connection (priv->dbus_mgr);
4547
/* avahi-autoipd stuff */
4548
priv->aipd_proxy = dbus_g_proxy_new_for_name (g_connection,
4549
NM_AUTOIP_DBUS_SERVICE,
4551
NM_AUTOIP_DBUS_IFACE);
4552
if (priv->aipd_proxy) {
4553
dbus_g_object_register_marshaller (_nm_marshal_VOID__STRING_STRING_STRING,
4555
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
4558
dbus_g_proxy_add_signal (priv->aipd_proxy,
4560
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
4563
dbus_g_proxy_connect_signal (priv->aipd_proxy, "Event",
4564
G_CALLBACK (aipd_handle_event),
4568
nm_log_warn (LOGD_AUTOIP4, "could not initialize avahi-autoipd D-Bus proxy");
4570
/* sleep/wake handling */
4571
priv->sleep_monitor = nm_sleep_monitor_get ();
4572
g_signal_connect (priv->sleep_monitor, "sleeping",
4573
G_CALLBACK (sleeping_cb), manager);
4574
g_signal_connect (priv->sleep_monitor, "resuming",
4575
G_CALLBACK (resuming_cb), manager);
4577
/* Listen for authorization changes */
4578
nm_auth_changed_func_register (authority_changed_cb, manager);
4580
/* Monitor the firmware directory */
4581
if (strlen (KERNEL_FIRMWARE_DIR)) {
4582
file = g_file_new_for_path (KERNEL_FIRMWARE_DIR "/");
4583
priv->fw_monitor = g_file_monitor_directory (file, G_FILE_MONITOR_NONE, NULL, NULL);
4584
g_object_unref (file);
4587
if (priv->fw_monitor) {
4588
priv->fw_monitor_id = g_signal_connect (priv->fw_monitor, "changed",
4589
G_CALLBACK (firmware_dir_changed),
4591
nm_log_info (LOGD_CORE, "monitoring kernel firmware directory '%s'.",
4592
KERNEL_FIRMWARE_DIR);
4594
nm_log_warn (LOGD_CORE, "failed to monitor kernel firmware directory '%s'.",
4595
KERNEL_FIRMWARE_DIR);
4598
load_device_factories (manager);
4600
/* Update timestamps in active connections */
4601
priv->timestamp_update_id = g_timeout_add_seconds (300, (GSourceFunc) periodic_update_active_connection_timestamps, manager);
4605
nm_manager_class_init (NMManagerClass *manager_class)
4607
GObjectClass *object_class = G_OBJECT_CLASS (manager_class);
4609
g_type_class_add_private (manager_class, sizeof (NMManagerPrivate));
4611
/* virtual methods */
4612
object_class->set_property = set_property;
4613
object_class->get_property = get_property;
4614
object_class->dispose = dispose;
4617
g_object_class_install_property
4618
(object_class, PROP_VERSION,
4619
g_param_spec_string (NM_MANAGER_VERSION,
4621
"NetworkManager version",
4625
g_object_class_install_property
4626
(object_class, PROP_STATE,
4627
g_param_spec_uint (NM_MANAGER_STATE,
4630
0, NM_STATE_DISCONNECTED, 0,
4633
g_object_class_install_property
4634
(object_class, PROP_NETWORKING_ENABLED,
4635
g_param_spec_boolean (NM_MANAGER_NETWORKING_ENABLED,
4636
"NetworkingEnabled",
4637
"Is networking enabled",
4639
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
4641
g_object_class_install_property
4642
(object_class, PROP_WIRELESS_ENABLED,
4643
g_param_spec_boolean (NM_MANAGER_WIRELESS_ENABLED,
4645
"Is wireless enabled",
4647
G_PARAM_READWRITE));
4649
g_object_class_install_property
4650
(object_class, PROP_WIRELESS_HARDWARE_ENABLED,
4651
g_param_spec_boolean (NM_MANAGER_WIRELESS_HARDWARE_ENABLED,
4652
"WirelessHardwareEnabled",
4657
g_object_class_install_property
4658
(object_class, PROP_WWAN_ENABLED,
4659
g_param_spec_boolean (NM_MANAGER_WWAN_ENABLED,
4661
"Is mobile broadband enabled",
4663
G_PARAM_READWRITE));
4665
g_object_class_install_property
4666
(object_class, PROP_WWAN_HARDWARE_ENABLED,
4667
g_param_spec_boolean (NM_MANAGER_WWAN_HARDWARE_ENABLED,
4668
"WwanHardwareEnabled",
4669
"Whether WWAN is disabled by a hardware switch or not",
4673
g_object_class_install_property
4674
(object_class, PROP_WIMAX_ENABLED,
4675
g_param_spec_boolean (NM_MANAGER_WIMAX_ENABLED,
4679
G_PARAM_READWRITE));
4681
g_object_class_install_property
4682
(object_class, PROP_WIMAX_HARDWARE_ENABLED,
4683
g_param_spec_boolean (NM_MANAGER_WIMAX_HARDWARE_ENABLED,
4684
"WimaxHardwareEnabled",
4685
"Whether WiMAX is disabled by a hardware switch or not",
4689
g_object_class_install_property
4690
(object_class, PROP_ACTIVE_CONNECTIONS,
4691
g_param_spec_boxed (NM_MANAGER_ACTIVE_CONNECTIONS,
4692
"Active connections",
4693
"Active connections",
4694
DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH,
4697
/* Hostname is not exported over D-Bus */
4698
g_object_class_install_property
4699
(object_class, PROP_HOSTNAME,
4700
g_param_spec_string (NM_MANAGER_HOSTNAME,
4704
G_PARAM_READABLE | NM_PROPERTY_PARAM_NO_EXPORT));
4706
/* Sleeping is not exported over D-Bus */
4707
g_object_class_install_property
4708
(object_class, PROP_SLEEPING,
4709
g_param_spec_boolean (NM_MANAGER_SLEEPING,
4713
G_PARAM_READABLE | NM_PROPERTY_PARAM_NO_EXPORT));
4716
signals[DEVICE_ADDED] =
4717
g_signal_new ("device-added",
4718
G_OBJECT_CLASS_TYPE (object_class),
4720
G_STRUCT_OFFSET (NMManagerClass, device_added),
4722
g_cclosure_marshal_VOID__OBJECT,
4723
G_TYPE_NONE, 1, G_TYPE_OBJECT);
4725
signals[DEVICE_REMOVED] =
4726
g_signal_new ("device-removed",
4727
G_OBJECT_CLASS_TYPE (object_class),
4729
G_STRUCT_OFFSET (NMManagerClass, device_removed),
4731
g_cclosure_marshal_VOID__OBJECT,
4732
G_TYPE_NONE, 1, G_TYPE_OBJECT);
4734
signals[STATE_CHANGED] =
4735
g_signal_new ("state-changed",
4736
G_OBJECT_CLASS_TYPE (object_class),
4738
G_STRUCT_OFFSET (NMManagerClass, state_changed),
4740
g_cclosure_marshal_VOID__UINT,
4741
G_TYPE_NONE, 1, G_TYPE_UINT);
4743
signals[PROPERTIES_CHANGED] =
4744
nm_properties_changed_signal_new (object_class,
4745
G_STRUCT_OFFSET (NMManagerClass, properties_changed));
4747
signals[CHECK_PERMISSIONS] =
4748
g_signal_new ("check-permissions",
4749
G_OBJECT_CLASS_TYPE (object_class),
4752
g_cclosure_marshal_VOID__VOID,
4755
signals[USER_PERMISSIONS_CHANGED] =
4756
g_signal_new ("user-permissions-changed",
4757
G_OBJECT_CLASS_TYPE (object_class),
4760
g_cclosure_marshal_VOID__VOID,
4763
signals[ACTIVE_CONNECTION_ADDED] =
4764
g_signal_new (NM_MANAGER_ACTIVE_CONNECTION_ADDED,
4765
G_OBJECT_CLASS_TYPE (object_class),
4768
g_cclosure_marshal_VOID__OBJECT,
4769
G_TYPE_NONE, 1, G_TYPE_OBJECT);
4771
signals[ACTIVE_CONNECTION_REMOVED] =
4772
g_signal_new (NM_MANAGER_ACTIVE_CONNECTION_REMOVED,
4773
G_OBJECT_CLASS_TYPE (object_class),
4776
g_cclosure_marshal_VOID__OBJECT,
4777
G_TYPE_NONE, 1, G_TYPE_OBJECT);
4779
dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (manager_class),
4780
&dbus_glib_nm_manager_object_info);
4782
dbus_g_error_domain_register (NM_MANAGER_ERROR, NULL, NM_TYPE_MANAGER_ERROR);
4783
dbus_g_error_domain_register (NM_LOGGING_ERROR, "org.freedesktop.NetworkManager.Logging", NM_TYPE_LOGGING_ERROR);