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) 2005 - 2013 Red Hat, Inc.
19 * Copyright (C) 2006 - 2008 Novell, Inc.
22 #include "nm-default.h"
24 #include <netinet/in.h>
28 #include <sys/ioctl.h>
30 #include <sys/types.h>
32 #include <arpa/inet.h>
34 #include <netlink/route/addr.h>
35 #include <linux/if_addr.h>
37 #include "nm-device.h"
38 #include "nm-device-private.h"
39 #include "NetworkManagerUtils.h"
40 #include "nm-manager.h"
41 #include "nm-platform.h"
43 #include "nm-lndp-rdisc.h"
44 #include "nm-dhcp-manager.h"
45 #include "nm-activation-request.h"
46 #include "nm-ip4-config.h"
47 #include "nm-ip6-config.h"
48 #include "nm-dnsmasq-manager.h"
49 #include "nm-dhcp4-config.h"
50 #include "nm-dhcp6-config.h"
51 #include "nm-rfkill-manager.h"
52 #include "nm-firewall-manager.h"
53 #include "nm-enum-types.h"
54 #include "nm-settings-connection.h"
55 #include "nm-connection-provider.h"
56 #include "nm-auth-utils.h"
57 #include "nm-dispatcher.h"
58 #include "nm-config.h"
59 #include "nm-dns-manager.h"
60 #include "nm-core-internal.h"
61 #include "nm-default-route-manager.h"
62 #include "nm-route-manager.h"
63 #include "nm-lldp-listener.h"
64 #include "sd-ipv4ll.h"
65 #include "nm-audit-manager.h"
66 #include "nm-arping-manager.h"
68 #include "nm-device-logging.h"
69 _LOG_DECLARE_SELF (NMDevice);
71 #include "nmdbus-device.h"
73 G_DEFINE_ABSTRACT_TYPE (NMDevice, nm_device, NM_TYPE_EXPORTED_OBJECT)
75 #define NM_DEVICE_GET_PRIVATE(o) ((o)->priv)
84 RECHECK_AUTO_ACTIVATE,
88 static guint signals[LAST_SIGNAL] = { 0 };
90 NM_GOBJECT_PROPERTIES_DEFINE (NMDevice,
96 PROP_FIRMWARE_VERSION,
107 PROP_ACTIVE_CONNECTION,
112 PROP_FIRMWARE_MISSING,
113 PROP_NM_PLUGIN_MISSING,
117 PROP_AVAILABLE_CONNECTIONS,
118 PROP_PHYSICAL_PORT_ID,
122 PROP_HAS_PENDING_ACTION,
129 #define DEFAULT_AUTOCONNECT TRUE
131 /***********************************************************/
133 #define PENDING_ACTION_DHCP4 "dhcp4"
134 #define PENDING_ACTION_DHCP6 "dhcp6"
135 #define PENDING_ACTION_AUTOCONF6 "autoconf6"
137 typedef void (*ActivationHandleFunc) (NMDevice *self);
140 ActivationHandleFunc func;
142 } ActivationHandleData;
145 CLEANUP_TYPE_DECONFIGURE,
147 CLEANUP_TYPE_REMOVED,
160 NMDeviceStateReason reason;
166 gboolean slave_is_enslaved;
172 NMLogDomain log_domain;
185 } DeleteOnDeactivateData;
187 typedef void (*ArpingCallback) (NMDevice *, NMIP4Config **, gboolean);
190 ArpingCallback callback;
192 NMIP4Config **configs;
195 typedef struct _NMDevicePrivate {
196 gboolean in_state_changed;
198 guint device_link_changed_id;
199 guint device_ip_link_changed_id;
202 NMDeviceStateReason state_reason;
203 QueuedState queued_state;
204 guint queued_ip4_config_id;
205 guint queued_ip6_config_id;
206 GSList *pending_actions;
207 GSList *dad6_failed_addrs;
210 char * iface; /* may change, could be renamed by user */
217 char * type_description;
218 NMLinkType link_type;
219 NMDeviceCapabilities capabilities;
221 char * driver_version;
222 char * firmware_version;
223 RfKillType rfkill_type;
224 gboolean firmware_missing;
225 gboolean nm_plugin_missing;
226 GHashTable * available_connections;
230 char * initial_hw_addr;
231 char * physical_port_id;
234 NMUnmanagedFlags unmanaged_mask;
235 NMUnmanagedFlags unmanaged_flags;
236 gboolean is_nm_owned; /* whether the device is a device owned and created by NM */
237 DeleteOnDeactivateData *delete_on_deactivate_data; /* data for scheduled cleanup when deleting link (g_idle_add) */
239 GCancellable *deactivating_cancellable;
243 NMActRequest * queued_act_request;
244 gboolean queued_act_request_is_waiting_for_carrier;
245 NMActRequest * act_request;
246 ActivationHandleData act_handle4; /* for layer2 and IPv4. */
247 ActivationHandleData act_handle6;
248 guint recheck_assume_id;
251 NMDeviceStateReason available_reason;
252 NMDeviceStateReason unavailable_reason;
256 NMDeviceState post_state;
257 NMDeviceStateReason post_state_reason;
261 guint link_connected_id;
262 guint link_disconnected_id;
263 guint carrier_defer_id;
265 guint carrier_wait_id;
266 gboolean ignore_carrier;
268 gboolean up; /* IFF_UP */
270 /* Generic DHCP stuff */
271 guint32 dhcp_timeout;
272 char * dhcp_anycast_address;
274 /* IP4 configuration info */
275 NMIP4Config * ip4_config; /* Combined config from VPN, settings, and device */
277 NMIP4Config * con_ip4_config; /* config from the setting */
278 NMIP4Config * dev_ip4_config; /* Config from DHCP, PPP, LLv4, etc */
279 NMIP4Config * ext_ip4_config; /* Stuff added outside NM */
280 NMIP4Config * wwan_ip4_config; /* WWAN configuration */
281 GSList * vpn4_configs; /* VPNs which use this device */
284 gboolean v4_is_assumed;
285 NMPlatformIP4Route v4;
287 gboolean v6_is_assumed;
288 NMPlatformIP6Route v6;
291 gboolean v4_commit_first_time;
292 gboolean v6_commit_first_time;
294 /* DHCPv4 tracking */
295 NMDhcpClient * dhcp4_client;
296 gulong dhcp4_state_sigid;
297 NMDhcp4Config * dhcp4_config;
298 guint dhcp4_restart_id;
302 /* dnsmasq stuff for shared connections */
303 NMDnsMasqManager *dnsmasq_manager;
304 gulong dnsmasq_state_id;
308 NMFirewallManagerCallId fw_call;
312 guint ipv4ll_timeout;
317 NMArpingManager * announcing;
320 /* IP6 configuration info */
321 NMIP6Config * ip6_config;
323 NMIP6Config * con_ip6_config; /* config from the setting */
324 NMIP6Config * wwan_ip6_config;
325 NMIP6Config * ext_ip6_config; /* Stuff added outside NM */
326 NMIP6Config * ext_ip6_config_captured; /* Configuration captured from platform. */
327 GSList * vpn6_configs; /* VPNs which use this device */
328 gboolean nm_ipv6ll; /* TRUE if NM handles the device's IPv6LL address */
332 gulong rdisc_changed_id;
333 gulong rdisc_timeout_id;
334 NMSettingIP6ConfigPrivacy rdisc_use_tempaddr;
335 /* IP6 config from autoconf */
336 NMIP6Config * ac_ip6_config;
338 guint linklocal6_timeout_id;
339 guint8 linklocal6_dad_counter;
341 GHashTable * ip6_saved_properties;
343 NMDhcpClient * dhcp6_client;
344 NMRDiscDHCPLevel dhcp6_mode;
345 gulong dhcp6_state_sigid;
346 NMDhcp6Config * dhcp6_config;
347 /* IP6 config from DHCP */
348 NMIP6Config * dhcp6_ip6_config;
349 /* Event ID of the current IP6 config from DHCP */
350 char * dhcp6_event_id;
351 guint dhcp6_restart_id;
353 /* allow autoconnect feature */
354 gboolean autoconnect;
356 /* master interface for bridge/bond/team slave */
358 gboolean is_enslaved;
359 gboolean master_ready_handled;
360 gulong master_ready_id;
362 /* slave management */
364 GSList * slaves; /* list of SlaveInfo */
368 NMConnectionProvider *con_provider;
369 NMLldpListener *lldp_listener;
371 guint check_delete_unrealized_id;
374 static gboolean nm_device_set_ip4_config (NMDevice *self,
376 guint32 default_route_metric,
378 gboolean routes_full_sync,
379 NMDeviceStateReason *reason);
380 static gboolean ip4_config_merge_and_apply (NMDevice *self,
383 NMDeviceStateReason *out_reason);
385 static gboolean nm_device_set_ip6_config (NMDevice *self,
388 gboolean routes_full_sync,
389 NMDeviceStateReason *reason);
391 static void nm_device_master_add_slave (NMDevice *self, NMDevice *slave, gboolean configure);
392 static void nm_device_slave_notify_enslave (NMDevice *self, gboolean success);
393 static void nm_device_slave_notify_release (NMDevice *self, NMDeviceStateReason reason);
395 static gboolean addrconf6_start_with_link_ready (NMDevice *self);
396 static NMActStageReturn linklocal6_start (NMDevice *self);
398 static void _carrier_wait_check_queued_act_request (NMDevice *self);
400 static const char *_activation_func_to_string (ActivationHandleFunc func);
401 static void activation_source_handle_cb (NMDevice *self, int family);
403 static void _set_state_full (NMDevice *self,
405 NMDeviceStateReason reason,
408 static gboolean queued_ip4_config_change (gpointer user_data);
409 static gboolean queued_ip6_config_change (gpointer user_data);
410 static void ip_check_ping_watch_cb (GPid pid, gint status, gpointer user_data);
411 static gboolean ip_config_valid (NMDeviceState state);
412 static NMActStageReturn dhcp4_start (NMDevice *self, NMConnection *connection, NMDeviceStateReason *reason);
413 static gboolean dhcp6_start (NMDevice *self, gboolean wait_for_ll, NMDeviceStateReason *reason);
414 static void nm_device_start_ip_check (NMDevice *self);
415 static void realize_start_setup (NMDevice *self, const NMPlatformLink *plink);
417 /***********************************************************/
419 #define QUEUED_PREFIX "queued state change to "
421 static const char *state_table[] = {
422 [NM_DEVICE_STATE_UNKNOWN] = QUEUED_PREFIX "unknown",
423 [NM_DEVICE_STATE_UNMANAGED] = QUEUED_PREFIX "unmanaged",
424 [NM_DEVICE_STATE_UNAVAILABLE] = QUEUED_PREFIX "unavailable",
425 [NM_DEVICE_STATE_DISCONNECTED] = QUEUED_PREFIX "disconnected",
426 [NM_DEVICE_STATE_PREPARE] = QUEUED_PREFIX "prepare",
427 [NM_DEVICE_STATE_CONFIG] = QUEUED_PREFIX "config",
428 [NM_DEVICE_STATE_NEED_AUTH] = QUEUED_PREFIX "need-auth",
429 [NM_DEVICE_STATE_IP_CONFIG] = QUEUED_PREFIX "ip-config",
430 [NM_DEVICE_STATE_IP_CHECK] = QUEUED_PREFIX "ip-check",
431 [NM_DEVICE_STATE_SECONDARIES] = QUEUED_PREFIX "secondaries",
432 [NM_DEVICE_STATE_ACTIVATED] = QUEUED_PREFIX "activated",
433 [NM_DEVICE_STATE_DEACTIVATING] = QUEUED_PREFIX "deactivating",
434 [NM_DEVICE_STATE_FAILED] = QUEUED_PREFIX "failed",
438 queued_state_to_string (NMDeviceState state)
440 if ((gsize) state < G_N_ELEMENTS (state_table))
441 return state_table[state];
442 return state_table[NM_DEVICE_STATE_UNKNOWN];
446 state_to_string (NMDeviceState state)
448 return queued_state_to_string (state) + strlen (QUEUED_PREFIX);
451 NM_UTILS_LOOKUP_STR_DEFINE_STATIC (_reason_to_string, NMDeviceStateReason,
452 NM_UTILS_LOOKUP_DEFAULT (NULL),
453 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_UNKNOWN, "unknown"),
454 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_NONE, "none"),
455 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_NOW_MANAGED, "managed"),
456 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_NOW_UNMANAGED, "unmanaged"),
457 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_CONFIG_FAILED, "config-failed"),
458 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE, "ip-config-unavailable"),
459 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED, "ip-config-expired"),
460 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_NO_SECRETS, "no-secrets"),
461 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_SUPPLICANT_DISCONNECT, "supplicant-disconnect"),
462 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_SUPPLICANT_CONFIG_FAILED, "supplicant-config-failed"),
463 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED, "supplicant-failed"),
464 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_SUPPLICANT_TIMEOUT, "supplicant-timeout"),
465 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_PPP_START_FAILED, "ppp-start-failed"),
466 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_PPP_DISCONNECT, "ppp-disconnect"),
467 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_PPP_FAILED, "ppp-failed"),
468 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_DHCP_START_FAILED, "dhcp-start-failed"),
469 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_DHCP_ERROR, "dhcp-error"),
470 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_DHCP_FAILED, "dhcp-failed"),
471 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_SHARED_START_FAILED, "sharing-start-failed"),
472 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_SHARED_FAILED, "sharing-failed"),
473 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED, "autoip-start-failed"),
474 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_AUTOIP_ERROR, "autoip-error"),
475 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_AUTOIP_FAILED, "autoip-failed"),
476 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_MODEM_BUSY, "modem-busy"),
477 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_MODEM_NO_DIAL_TONE, "modem-no-dialtone"),
478 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_MODEM_NO_CARRIER, "modem-no-carrier"),
479 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_MODEM_DIAL_TIMEOUT, "modem-dial-timeout"),
480 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_MODEM_DIAL_FAILED, "modem-dial-failed"),
481 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_MODEM_INIT_FAILED, "modem-init-failed"),
482 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_GSM_APN_FAILED, "gsm-apn-failed"),
483 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_GSM_REGISTRATION_NOT_SEARCHING, "gsm-registration-idle"),
484 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_GSM_REGISTRATION_DENIED, "gsm-registration-denied"),
485 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_GSM_REGISTRATION_TIMEOUT, "gsm-registration-timeout"),
486 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_GSM_REGISTRATION_FAILED, "gsm-registration-failed"),
487 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_GSM_PIN_CHECK_FAILED, "gsm-pin-check-failed"),
488 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_FIRMWARE_MISSING, "firmware-missing"),
489 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_REMOVED, "removed"),
490 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_SLEEPING, "sleeping"),
491 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_CONNECTION_REMOVED, "connection-removed"),
492 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_USER_REQUESTED, "user-requested"),
493 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_CARRIER, "carrier-changed"),
494 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED, "connection-assumed"),
495 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_SUPPLICANT_AVAILABLE, "supplicant-available"),
496 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_MODEM_NOT_FOUND, "modem-not-found"),
497 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_BT_FAILED, "bluetooth-failed"),
498 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_GSM_SIM_NOT_INSERTED, "gsm-sim-not-inserted"),
499 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_GSM_SIM_PIN_REQUIRED, "gsm-sim-pin-required"),
500 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_GSM_SIM_PUK_REQUIRED, "gsm-sim-puk-required"),
501 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_GSM_SIM_WRONG, "gsm-sim-wrong"),
502 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_INFINIBAND_MODE, "infiniband-mode"),
503 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED, "dependency-failed"),
504 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_BR2684_FAILED, "br2684-bridge-failed"),
505 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_MODEM_MANAGER_UNAVAILABLE, "modem-manager-unavailable"),
506 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_SSID_NOT_FOUND, "ssid-not-found"),
507 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_SECONDARY_CONNECTION_FAILED, "secondary-connection-failed"),
508 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_DCB_FCOE_FAILED, "dcb-fcoe-failed"),
509 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_TEAMD_CONTROL_FAILED, "teamd-control-failed"),
510 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_MODEM_FAILED, "modem-failed"),
511 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_MODEM_AVAILABLE, "modem-available"),
512 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT, "sim-pin-incorrect"),
513 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_NEW_ACTIVATION, "new-activation"),
514 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_PARENT_CHANGED, "parent-changed"),
515 NM_UTILS_LOOKUP_STR_ITEM (NM_DEVICE_STATE_REASON_PARENT_MANAGED_CHANGED, "parent-managed-changed"),
518 #define reason_to_string(reason) \
519 NM_UTILS_LOOKUP_STR (_reason_to_string, reason)
521 /***********************************************************/
524 nm_device_ipv6_sysctl_set (NMDevice *self, const char *property, const char *value)
526 return nm_platform_sysctl_set (NM_PLATFORM_GET, nm_utils_ip6_property_path (nm_device_get_ip_iface (self), property), value);
530 nm_device_ipv6_sysctl_get_int32 (NMDevice *self, const char *property, gint32 fallback)
532 return nm_platform_sysctl_get_int32 (NM_PLATFORM_GET, nm_utils_ip6_property_path (nm_device_get_ip_iface (self), property), fallback);
536 nm_device_has_capability (NMDevice *self, NMDeviceCapabilities caps)
538 return NM_FLAGS_ANY (NM_DEVICE_GET_PRIVATE (self)->capabilities, caps);
541 /***********************************************************/
544 nm_device_get_udi (NMDevice *self)
546 g_return_val_if_fail (self != NULL, NULL);
548 return NM_DEVICE_GET_PRIVATE (self)->udi;
552 nm_device_get_iface (NMDevice *self)
554 g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
556 return NM_DEVICE_GET_PRIVATE (self)->iface;
560 nm_device_get_ifindex (NMDevice *self)
562 g_return_val_if_fail (NM_IS_DEVICE (self), 0);
564 return NM_DEVICE_GET_PRIVATE (self)->ifindex;
568 * nm_device_is_software:
569 * @self: the #NMDevice
571 * Indicates if the device is a software-based virtual device without
572 * backing hardware, which can be added and removed programmatically.
574 * Returns: %TRUE if the device is a software-based device
577 nm_device_is_software (NMDevice *self)
579 return NM_FLAGS_HAS (NM_DEVICE_GET_PRIVATE (self)->capabilities, NM_DEVICE_CAP_IS_SOFTWARE);
584 * @self: the #NMDevice
586 * Returns: %TRUE if the device exists, %FALSE if the device is a placeholder
589 nm_device_is_real (NMDevice *self)
591 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
593 return NM_DEVICE_GET_PRIVATE (self)->real;
597 nm_device_get_ip_iface (NMDevice *self)
599 NMDevicePrivate *priv;
601 g_return_val_if_fail (self != NULL, NULL);
603 priv = NM_DEVICE_GET_PRIVATE (self);
604 /* If it's not set, default to iface */
605 return priv->ip_iface ? priv->ip_iface : priv->iface;
609 nm_device_get_ip_ifindex (NMDevice *self)
611 NMDevicePrivate *priv;
613 g_return_val_if_fail (self != NULL, 0);
615 priv = NM_DEVICE_GET_PRIVATE (self);
616 /* If it's not set, default to ifindex */
617 return priv->ip_iface ? priv->ip_ifindex : priv->ifindex;
621 nm_device_set_ip_iface (NMDevice *self, const char *iface)
623 NMDevicePrivate *priv;
626 g_return_if_fail (NM_IS_DEVICE (self));
628 priv = NM_DEVICE_GET_PRIVATE (self);
629 if (!g_strcmp0 (iface, priv->ip_iface))
632 old_ip_iface = priv->ip_iface;
633 priv->ip_ifindex = 0;
635 priv->ip_iface = g_strdup (iface);
636 if (priv->ip_iface) {
637 priv->ip_ifindex = nm_platform_link_get_ifindex (NM_PLATFORM_GET, priv->ip_iface);
638 if (priv->ip_ifindex > 0) {
639 if (nm_platform_check_support_user_ipv6ll (NM_PLATFORM_GET))
640 nm_platform_link_set_user_ipv6ll_enabled (NM_PLATFORM_GET, priv->ip_ifindex, TRUE);
642 if (!nm_platform_link_is_up (NM_PLATFORM_GET, priv->ip_ifindex))
643 nm_platform_link_set_up (NM_PLATFORM_GET, priv->ip_ifindex, NULL);
645 /* Device IP interface must always be a kernel network interface */
646 _LOGW (LOGD_HW, "failed to look up interface index");
650 /* We don't care about any saved values from the old iface */
651 g_hash_table_remove_all (priv->ip6_saved_properties);
653 /* Emit change notification */
654 if (g_strcmp0 (old_ip_iface, priv->ip_iface))
655 _notify (self, PROP_IP_IFACE);
656 g_free (old_ip_iface);
660 get_ip_iface_identifier (NMDevice *self, NMUtilsIPv6IfaceId *out_iid)
662 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
663 NMLinkType link_type;
664 const guint8 *hwaddr = NULL;
665 size_t hwaddr_len = 0;
669 /* If we get here, we *must* have a kernel netdev, which implies an ifindex */
670 ifindex = nm_device_get_ip_ifindex (self);
673 link_type = nm_platform_link_get_type (NM_PLATFORM_GET, ifindex);
674 g_return_val_if_fail (link_type > NM_LINK_TYPE_UNKNOWN, 0);
676 hwaddr = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, &hwaddr_len);
680 success = nm_utils_get_ipv6_interface_identifier (link_type,
686 _LOGW (LOGD_HW, "failed to generate interface identifier "
687 "for link type %u hwaddr_len %zu", link_type, hwaddr_len);
693 nm_device_get_ip_iface_identifier (NMDevice *self, NMUtilsIPv6IfaceId *iid)
695 return NM_DEVICE_GET_CLASS (self)->get_ip_iface_identifier (self, iid);
699 nm_device_get_driver (NMDevice *self)
701 g_return_val_if_fail (self != NULL, NULL);
703 return NM_DEVICE_GET_PRIVATE (self)->driver;
707 nm_device_get_driver_version (NMDevice *self)
709 g_return_val_if_fail (self != NULL, NULL);
711 return NM_DEVICE_GET_PRIVATE (self)->driver_version;
715 nm_device_get_device_type (NMDevice *self)
717 g_return_val_if_fail (NM_IS_DEVICE (self), NM_DEVICE_TYPE_UNKNOWN);
719 return NM_DEVICE_GET_PRIVATE (self)->type;
723 nm_device_get_link_type (NMDevice *self)
725 g_return_val_if_fail (NM_IS_DEVICE (self), NM_LINK_TYPE_UNKNOWN);
727 return NM_DEVICE_GET_PRIVATE (self)->link_type;
731 * nm_device_get_metered:
732 * @setting: the #NMDevice
734 * Returns: the #NMDevice:metered property of the device.
739 nm_device_get_metered (NMDevice *self)
741 g_return_val_if_fail (NM_IS_DEVICE (self), NM_METERED_UNKNOWN);
743 return NM_DEVICE_GET_PRIVATE (self)->metered;
747 * nm_device_get_priority():
748 * @self: the #NMDevice
750 * Returns: the device's routing priority. Lower numbers means a "better"
751 * device, eg higher priority.
754 nm_device_get_priority (NMDevice *self)
756 g_return_val_if_fail (NM_IS_DEVICE (self), 1000);
758 /* Device 'priority' is used for the default route-metric and is based on
759 * the device type. The settings ipv4.route-metric and ipv6.route-metric
760 * can overwrite this default.
762 * Currently for both IPv4 and IPv6 we use the same default values.
764 * The route-metric is used for the metric of the routes of device.
765 * This also applies to the default route. Therefore it affects also
766 * which device is the "best".
768 * For comparison, note that iproute2 by default adds IPv4 routes with
769 * metric 0, and IPv6 routes with metric 1024. The latter is the IPv6
770 * "user default" in the kernel (NM_PLATFORM_ROUTE_METRIC_DEFAULT_IP6).
771 * In kernel, the full uint32_t range is available for route
772 * metrics (except for IPv6, where 0 means 1024).
775 switch (nm_device_get_device_type (self)) {
776 /* 50 is reserved for VPN (NM_VPN_ROUTE_METRIC_DEFAULT) */
777 case NM_DEVICE_TYPE_ETHERNET:
778 case NM_DEVICE_TYPE_VETH:
780 case NM_DEVICE_TYPE_INFINIBAND:
782 case NM_DEVICE_TYPE_ADSL:
784 case NM_DEVICE_TYPE_WIMAX:
786 case NM_DEVICE_TYPE_BOND:
788 case NM_DEVICE_TYPE_TEAM:
790 case NM_DEVICE_TYPE_VLAN:
792 case NM_DEVICE_TYPE_MACVLAN:
794 case NM_DEVICE_TYPE_BRIDGE:
796 case NM_DEVICE_TYPE_TUN:
798 case NM_DEVICE_TYPE_VXLAN:
800 case NM_DEVICE_TYPE_WIFI:
802 case NM_DEVICE_TYPE_OLPC_MESH:
804 case NM_DEVICE_TYPE_IP_TUNNEL:
806 case NM_DEVICE_TYPE_MODEM:
808 case NM_DEVICE_TYPE_BT:
810 case NM_DEVICE_TYPE_GENERIC:
812 case NM_DEVICE_TYPE_UNKNOWN:
814 case NM_DEVICE_TYPE_UNUSED1:
815 case NM_DEVICE_TYPE_UNUSED2:
816 /* omit default: to get compiler warning about missing switch cases */
823 _get_ipx_route_metric (NMDevice *self,
828 NMSettingIPConfig *s_ip;
829 NMConnection *connection;
831 g_return_val_if_fail (NM_IS_DEVICE (self), G_MAXUINT32);
833 connection = nm_device_get_applied_connection (self);
836 ? nm_connection_get_setting_ip4_config (connection)
837 : nm_connection_get_setting_ip6_config (connection);
839 /* Slave interfaces don't have IP settings, but we may get here when
840 * external changes are made or when noticing IP changes when starting
841 * the slave connection.
844 route_metric = nm_setting_ip_config_get_route_metric (s_ip);
845 if (route_metric >= 0)
850 /* use the current NMConfigData, which makes this configuration reloadable.
851 * Note that that means that the route-metric might change between SIGHUP.
852 * You must cache the returned value if that is a problem. */
853 value = nm_config_data_get_connection_default (NM_CONFIG_GET_DATA,
854 is_v4 ? "ipv4.route-metric" : "ipv6.route-metric", self);
856 route_metric = _nm_utils_ascii_str_to_int64 (value, 10, 0, G_MAXUINT32, -1);
859 if (route_metric >= 0)
862 route_metric = nm_device_get_priority (self);
865 route_metric = nm_utils_ip6_route_metric_normalize (route_metric);
870 nm_device_get_ip4_route_metric (NMDevice *self)
872 return _get_ipx_route_metric (self, TRUE);
876 nm_device_get_ip6_route_metric (NMDevice *self)
878 return _get_ipx_route_metric (self, FALSE);
881 const NMPlatformIP4Route *
882 nm_device_get_ip4_default_route (NMDevice *self, gboolean *out_is_assumed)
884 NMDevicePrivate *priv;
886 g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
888 priv = NM_DEVICE_GET_PRIVATE (self);
891 *out_is_assumed = priv->default_route.v4_is_assumed;
893 return priv->default_route.v4_has ? &priv->default_route.v4 : NULL;
896 const NMPlatformIP6Route *
897 nm_device_get_ip6_default_route (NMDevice *self, gboolean *out_is_assumed)
899 NMDevicePrivate *priv;
901 g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
903 priv = NM_DEVICE_GET_PRIVATE (self);
906 *out_is_assumed = priv->default_route.v6_is_assumed;
908 return priv->default_route.v6_has ? &priv->default_route.v6 : NULL;
912 nm_device_get_type_desc (NMDevice *self)
914 g_return_val_if_fail (self != NULL, NULL);
916 return NM_DEVICE_GET_PRIVATE (self)->type_desc;
920 nm_device_get_type_description (NMDevice *self)
922 g_return_val_if_fail (self != NULL, NULL);
924 /* Beware: this function should return the same
925 * value as nm_device_get_type_description() in libnm. */
927 return NM_DEVICE_GET_CLASS (self)->get_type_description (self);
931 get_type_description (NMDevice *self)
933 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
935 if (!priv->type_description) {
936 const char *typename;
938 typename = G_OBJECT_TYPE_NAME (self);
939 if (g_str_has_prefix (typename, "NMDevice"))
941 priv->type_description = g_ascii_strdown (typename, -1);
944 return priv->type_description;
948 nm_device_has_carrier (NMDevice *self)
950 return NM_DEVICE_GET_PRIVATE (self)->carrier;
954 nm_device_get_act_request (NMDevice *self)
956 g_return_val_if_fail (self != NULL, NULL);
958 return NM_DEVICE_GET_PRIVATE (self)->act_request;
961 NMSettingsConnection *
962 nm_device_get_settings_connection (NMDevice *self)
964 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
966 return priv->act_request ? nm_act_request_get_settings_connection (priv->act_request) : NULL;
970 nm_device_get_applied_connection (NMDevice *self)
972 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
974 return priv->act_request ? nm_act_request_get_applied_connection (priv->act_request) : NULL;
978 nm_device_has_unmodified_applied_connection (NMDevice *self, NMSettingCompareFlags compare_flags)
980 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
982 if (!priv->act_request)
985 return nm_active_connection_has_unmodified_applied_connection ((NMActiveConnection *) priv->act_request, compare_flags);
989 nm_device_get_applied_setting (NMDevice *device, GType setting_type)
992 NMSetting *setting = NULL;
994 g_return_val_if_fail (NM_IS_DEVICE (device), NULL);
996 req = nm_device_get_act_request (device);
998 NMConnection *connection;
1000 connection = nm_act_request_get_applied_connection (req);
1002 setting = nm_connection_get_setting (connection, setting_type);
1009 nm_device_get_rfkill_type (NMDevice *self)
1011 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
1013 return NM_DEVICE_GET_PRIVATE (self)->rfkill_type;
1017 nm_device_get_physical_port_id (NMDevice *self)
1019 return NM_DEVICE_GET_PRIVATE (self)->physical_port_id;
1022 /***********************************************************/
1025 nm_device_uses_generated_assumed_connection (NMDevice *self)
1027 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
1028 NMSettingsConnection *connection;
1030 if ( priv->act_request
1031 && nm_active_connection_get_assumed (NM_ACTIVE_CONNECTION (priv->act_request))) {
1032 connection = nm_act_request_get_settings_connection (priv->act_request);
1034 && nm_settings_connection_get_nm_generated_assumed (connection))
1041 nm_device_uses_assumed_connection (NMDevice *self)
1043 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
1045 if ( priv->act_request
1046 && nm_active_connection_get_assumed (NM_ACTIVE_CONNECTION (priv->act_request)))
1052 find_slave_info (NMDevice *self, NMDevice *slave)
1054 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
1058 for (iter = priv->slaves; iter; iter = g_slist_next (iter)) {
1060 if (info->slave == slave)
1067 * nm_device_master_enslave_slave:
1068 * @self: the master device
1069 * @slave: the slave device to enslave
1070 * @connection: (allow-none): the slave device's connection
1072 * If @self is capable of enslaving other devices (ie it's a bridge, bond, team,
1073 * etc) then this function enslaves @slave.
1075 * Returns: %TRUE on success, %FALSE on failure or if this device cannot enslave
1079 nm_device_master_enslave_slave (NMDevice *self, NMDevice *slave, NMConnection *connection)
1082 gboolean success = FALSE;
1085 g_return_val_if_fail (self != NULL, FALSE);
1086 g_return_val_if_fail (slave != NULL, FALSE);
1087 g_return_val_if_fail (NM_DEVICE_GET_CLASS (self)->enslave_slave != NULL, FALSE);
1089 info = find_slave_info (self, slave);
1093 if (info->slave_is_enslaved)
1096 configure = (info->configure && connection != NULL);
1098 g_return_val_if_fail (nm_device_get_state (slave) >= NM_DEVICE_STATE_DISCONNECTED, FALSE);
1100 success = NM_DEVICE_GET_CLASS (self)->enslave_slave (self, slave, connection, configure);
1101 info->slave_is_enslaved = success;
1104 nm_device_slave_notify_enslave (info->slave, success);
1106 /* Ensure the device's hardware address is up-to-date; it often changes
1107 * when slaves change.
1109 nm_device_update_hw_address (self);
1111 /* Restart IP configuration if we're waiting for slaves. Do this
1112 * after updating the hardware address as IP config may need the
1116 if (NM_DEVICE_GET_PRIVATE (self)->ip4_state == IP_WAIT)
1117 nm_device_activate_stage3_ip4_start (self);
1119 if (NM_DEVICE_GET_PRIVATE (self)->ip6_state == IP_WAIT)
1120 nm_device_activate_stage3_ip6_start (self);
1127 * nm_device_master_release_one_slave:
1128 * @self: the master device
1129 * @slave: the slave device to release
1130 * @configure: whether @self needs to actually release @slave
1131 * @reason: the state change reason for the @slave
1133 * If @self is capable of enslaving other devices (ie it's a bridge, bond, team,
1134 * etc) then this function releases the previously enslaved @slave and/or
1135 * updates the state of @self and @slave to reflect its release.
1138 nm_device_master_release_one_slave (NMDevice *self, NMDevice *slave, gboolean configure, NMDeviceStateReason reason)
1140 NMDevicePrivate *priv;
1141 NMDevicePrivate *slave_priv;
1143 gs_unref_object NMDevice *self_free = NULL;
1145 g_return_if_fail (NM_DEVICE (self));
1146 g_return_if_fail (NM_DEVICE (slave));
1147 g_return_if_fail (NM_DEVICE_GET_CLASS (self)->release_slave != NULL);
1149 info = find_slave_info (self, slave);
1151 _LOGt (LOGD_CORE, "master: release one slave %p/%s%s", slave, nm_device_get_iface (slave),
1152 !info ? " (not registered)" : "");
1155 g_return_if_reached ();
1157 priv = NM_DEVICE_GET_PRIVATE (self);
1158 slave_priv = NM_DEVICE_GET_PRIVATE (slave);
1160 g_return_if_fail (self == slave_priv->master);
1161 nm_assert (slave == info->slave);
1163 /* first, let subclasses handle the release ... */
1164 if (info->slave_is_enslaved)
1165 NM_DEVICE_GET_CLASS (self)->release_slave (self, slave, configure);
1167 /* raise notifications about the release, including clearing is_enslaved. */
1168 nm_device_slave_notify_release (slave, reason);
1170 /* keep both alive until the end of the function.
1171 * Transfers ownership from slave_priv->master. */
1174 priv->slaves = g_slist_remove (priv->slaves, info);
1175 slave_priv->master = NULL;
1177 g_signal_handler_disconnect (slave, info->watch_id);
1178 g_object_unref (slave);
1179 g_slice_free (SlaveInfo, info);
1181 /* Ensure the device's hardware address is up-to-date; it often changes
1182 * when slaves change.
1184 nm_device_update_hw_address (self);
1185 nm_device_set_unmanaged_by_flags (slave, NM_UNMANAGED_IS_SLAVE, NM_UNMAN_FLAG_OP_FORGET, NM_DEVICE_STATE_REASON_REMOVED);
1189 * can_unmanaged_external_down:
1192 * Check whether the device should stay NM_UNMANAGED_EXTERNAL_DOWN unless
1193 * IFF_UP-ed externally.
1196 can_unmanaged_external_down (NMDevice *self)
1198 return !NM_DEVICE_GET_PRIVATE (self)->is_nm_owned
1199 && nm_device_is_software (self);
1203 update_dynamic_ip_setup (NMDevice *self)
1205 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
1210 g_hash_table_remove_all (priv->ip6_saved_properties);
1212 if (priv->dhcp4_client) {
1213 if (!nm_device_dhcp4_renew (self, FALSE)) {
1214 nm_device_state_changed (self,
1215 NM_DEVICE_STATE_FAILED,
1216 NM_DEVICE_STATE_REASON_DHCP_FAILED);
1220 if (priv->dhcp6_client) {
1221 if (!nm_device_dhcp6_renew (self, FALSE)) {
1222 nm_device_state_changed (self,
1223 NM_DEVICE_STATE_FAILED,
1224 NM_DEVICE_STATE_REASON_DHCP_FAILED);
1231 if (priv->dnsmasq_manager) {
1235 if (priv->lldp_listener && nm_lldp_listener_is_running (priv->lldp_listener)) {
1236 nm_lldp_listener_stop (priv->lldp_listener);
1237 addr = nm_platform_link_get_address (NM_PLATFORM_GET, priv->ifindex, &addr_length);
1239 if (!nm_lldp_listener_start (priv->lldp_listener, nm_device_get_ifindex (self), &error)) {
1240 _LOGD (LOGD_DEVICE, "LLDP listener %p could not be restarted: %s",
1241 priv->lldp_listener, error->message);
1242 g_clear_error (&error);
1248 carrier_changed (NMDevice *self, gboolean carrier)
1250 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
1252 if (priv->state <= NM_DEVICE_STATE_UNMANAGED)
1255 nm_device_recheck_available_connections (self);
1257 /* ignore-carrier devices ignore all carrier-down events */
1258 if (priv->ignore_carrier && !carrier)
1261 if (priv->is_master) {
1262 /* Bridge/bond/team carrier does not affect its own activation,
1263 * but when carrier comes on, if there are slaves waiting,
1264 * it will restart them.
1269 if (nm_device_activate_ip4_state_in_wait (self))
1270 nm_device_activate_stage3_ip4_start (self);
1271 if (nm_device_activate_ip6_state_in_wait (self))
1272 nm_device_activate_stage3_ip6_start (self);
1275 } else if (nm_device_get_enslaved (self) && !carrier) {
1276 /* Slaves don't deactivate when they lose carrier; for
1277 * bonds/teams in particular that would be actively
1278 * counterproductive.
1284 if (priv->state == NM_DEVICE_STATE_UNAVAILABLE) {
1285 nm_device_queue_state (self, NM_DEVICE_STATE_DISCONNECTED,
1286 NM_DEVICE_STATE_REASON_CARRIER);
1287 } else if (priv->state == NM_DEVICE_STATE_DISCONNECTED) {
1288 /* If the device is already in DISCONNECTED state without a carrier
1289 * (probably because it is tagged for carrier ignore) ensure that
1290 * when the carrier appears, auto connections are rechecked for
1293 nm_device_emit_recheck_auto_activate (self);
1294 } else if (priv->state == NM_DEVICE_STATE_ACTIVATED) {
1295 /* If the device is active without a carrier (probably because it is
1296 * tagged for carrier ignore) ensure that when the carrier appears we
1297 * renew DHCP leases and such.
1299 update_dynamic_ip_setup (self);
1302 if (priv->state == NM_DEVICE_STATE_UNAVAILABLE) {
1303 if (nm_device_queued_state_peek (self) >= NM_DEVICE_STATE_DISCONNECTED)
1304 nm_device_queued_state_clear (self);
1306 nm_device_queue_state (self, NM_DEVICE_STATE_UNAVAILABLE,
1307 NM_DEVICE_STATE_REASON_CARRIER);
1312 #define LINK_DISCONNECT_DELAY 4
1315 link_disconnect_action_cb (gpointer user_data)
1317 NMDevice *self = NM_DEVICE (user_data);
1318 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
1320 _LOGD (LOGD_DEVICE, "link disconnected (calling deferred action) (id=%u)", priv->carrier_defer_id);
1322 priv->carrier_defer_id = 0;
1324 _LOGI (LOGD_DEVICE, "link disconnected (calling deferred action)");
1326 NM_DEVICE_GET_CLASS (self)->carrier_changed (self, FALSE);
1332 link_disconnect_action_cancel (NMDevice *self)
1334 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
1336 if (priv->carrier_defer_id) {
1337 g_source_remove (priv->carrier_defer_id);
1338 _LOGD (LOGD_DEVICE, "link disconnected (canceling deferred action) (id=%u)", priv->carrier_defer_id);
1339 priv->carrier_defer_id = 0;
1344 nm_device_set_carrier (NMDevice *self, gboolean carrier)
1346 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
1347 NMDeviceClass *klass = NM_DEVICE_GET_CLASS (self);
1348 NMDeviceState state = nm_device_get_state (self);
1350 if (priv->carrier == carrier)
1353 priv->carrier = carrier;
1354 _notify (self, PROP_CARRIER);
1356 if (priv->carrier) {
1357 _LOGI (LOGD_DEVICE, "link connected");
1358 link_disconnect_action_cancel (self);
1359 klass->carrier_changed (self, TRUE);
1361 if (nm_clear_g_source (&priv->carrier_wait_id)) {
1362 nm_device_remove_pending_action (self, "carrier wait", TRUE);
1363 _carrier_wait_check_queued_act_request (self);
1365 } else if (state <= NM_DEVICE_STATE_DISCONNECTED) {
1366 _LOGI (LOGD_DEVICE, "link disconnected");
1367 klass->carrier_changed (self, FALSE);
1369 _LOGI (LOGD_DEVICE, "link disconnected (deferring action for %d seconds)", LINK_DISCONNECT_DELAY);
1370 priv->carrier_defer_id = g_timeout_add_seconds (LINK_DISCONNECT_DELAY,
1371 link_disconnect_action_cb, self);
1372 _LOGD (LOGD_DEVICE, "link disconnected (deferring action for %d seconds) (id=%u)",
1373 LINK_DISCONNECT_DELAY, priv->carrier_defer_id);
1378 device_recheck_slave_status (NMDevice *self, const NMPlatformLink *plink)
1380 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
1382 g_return_if_fail (plink);
1384 if (plink->master <= 0)
1388 if ( plink->master > 0
1389 && plink->master == nm_device_get_ifindex (priv->master)) {
1390 /* call add-slave again. We expect @self already to be added to
1391 * the master, but this also triggers a recheck-assume. */
1392 nm_device_master_add_slave (priv->master, self, FALSE);
1396 nm_device_master_release_one_slave (priv->master, self, FALSE, NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED);
1398 if (plink->master > 0) {
1401 master = nm_manager_get_device_by_ifindex (nm_manager_get (), plink->master);
1402 if (master && NM_DEVICE_GET_CLASS (master)->enslave_slave)
1403 nm_device_master_add_slave (master, self, FALSE);
1405 _LOGI (LOGD_DEVICE, "enslaved to non-master-type device %s; ignoring",
1406 nm_device_get_iface (master));
1408 _LOGW (LOGD_DEVICE, "enslaved to unknown device %d %s",
1410 nm_platform_link_get_name (NM_PLATFORM_GET, plink->master));
1416 device_link_changed (NMDevice *self)
1418 NMDeviceClass *klass = NM_DEVICE_GET_CLASS (self);
1419 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
1420 NMUtilsIPv6IfaceId token_iid;
1421 gboolean ip_ifname_changed = FALSE;
1423 NMPlatformLink info;
1424 const NMPlatformLink *pllink;
1428 priv->device_link_changed_id = 0;
1430 ifindex = nm_device_get_ifindex (self);
1431 pllink = nm_platform_link_get (NM_PLATFORM_GET, ifindex);
1433 return G_SOURCE_REMOVE;
1437 udi = nm_platform_link_get_udi (NM_PLATFORM_GET, info.ifindex);
1438 if (udi && g_strcmp0 (udi, priv->udi)) {
1439 /* Update UDI to what udev gives us */
1441 priv->udi = g_strdup (udi);
1442 _notify (self, PROP_UDI);
1445 if (g_strcmp0 (info.driver, priv->driver)) {
1446 /* Update driver to what udev gives us */
1447 g_free (priv->driver);
1448 priv->driver = g_strdup (info.driver);
1449 _notify (self, PROP_DRIVER);
1452 /* Update MTU if it has changed. */
1453 if (priv->mtu != info.mtu) {
1454 priv->mtu = info.mtu;
1455 _notify (self, PROP_MTU);
1458 if (info.driver && g_strcmp0 (priv->driver, info.driver) != 0) {
1459 g_free (priv->driver);
1460 priv->driver = g_strdup (info.driver);
1461 _notify (self, PROP_DRIVER);
1464 if (info.name[0] && strcmp (priv->iface, info.name) != 0) {
1465 _LOGI (LOGD_DEVICE, "interface index %d renamed iface from '%s' to '%s'",
1466 priv->ifindex, priv->iface, info.name);
1467 g_free (priv->iface);
1468 priv->iface = g_strdup (info.name);
1470 /* If the device has no explicit ip_iface, then changing iface changes ip_iface too. */
1471 ip_ifname_changed = !priv->ip_iface;
1473 _notify (self, PROP_IFACE);
1474 if (ip_ifname_changed)
1475 _notify (self, PROP_IP_IFACE);
1477 /* Re-match available connections against the new interface name */
1478 nm_device_recheck_available_connections (self);
1480 /* Let any connections that use the new interface name have a chance
1481 * to auto-activate on the device.
1483 nm_device_emit_recheck_auto_activate (self);
1486 if (priv->rdisc && nm_platform_link_get_ipv6_token (NM_PLATFORM_GET, priv->ifindex, &token_iid)) {
1487 _LOGD (LOGD_DEVICE, "IPv6 tokenized identifier present on device %s", priv->iface);
1488 if (nm_rdisc_set_iid (priv->rdisc, token_iid))
1489 nm_rdisc_start (priv->rdisc);
1492 if (klass->link_changed)
1493 klass->link_changed (self, &info);
1495 /* Update DHCP, etc, if needed */
1496 if (ip_ifname_changed)
1497 update_dynamic_ip_setup (self);
1500 priv->up = NM_FLAGS_HAS (info.n_ifi_flags, IFF_UP);
1502 if ( priv->ifindex > 0
1504 && nm_device_get_unmanaged_flags (self, NM_UNMANAGED_PLATFORM_INIT)) {
1505 NMDeviceStateReason reason;
1507 nm_device_set_unmanaged_by_user_udev (self);
1509 /* If the devices that need an external IFF_UP go managed below,
1510 * it means they're already up. In that case we should use an "assumed"
1511 * reason to prevent the cleanup sequence from being run on transition
1512 * from "unmanaged" to "unavailable". */
1514 && !nm_device_get_unmanaged_flags (self, NM_UNMANAGED_EXTERNAL_DOWN)
1515 && NM_DEVICE_GET_CLASS (self)->can_unmanaged_external_down (self)) {
1516 /* Ensure the assume check is queued before any queued state changes
1517 * from the transition to UNAVAILABLE.
1519 nm_device_queue_recheck_assume (self);
1520 reason = NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED;
1522 reason = NM_DEVICE_STATE_REASON_NOW_MANAGED;
1524 nm_device_set_unmanaged_by_flags (self, NM_UNMANAGED_PLATFORM_INIT, FALSE, reason);
1527 if ( priv->ifindex > 0
1528 && priv->up != was_up
1529 && NM_DEVICE_GET_CLASS (self)->can_unmanaged_external_down (self)) {
1530 /* Manage externally-created software interfaces only when they are IFF_UP */
1532 && nm_device_get_unmanaged_flags (self, NM_UNMANAGED_EXTERNAL_DOWN)) {
1533 /* Ensure the assume check is queued before any queued state changes
1534 * from the transition to UNAVAILABLE.
1536 nm_device_queue_recheck_assume (self);
1539 /* In case of @priv->up, resetting the EXTERNAL_DOWN flag may change the device's
1540 * state to UNAVAILABLE. To ensure that the state change doesn't touch
1541 * the device before assumption occurs, pass NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED
1544 * In case of !@priv->up, and the device is already unmanaged for other reasons, the
1545 * state-change-reason has no effect.
1546 * If the device is managed for an explict user-request, the state-change-reason
1547 * also has no effect, because the device stays managed.
1549 * The state-change-reason only has effect if the device was assumed
1550 * and is now to be unmanaged. */
1551 nm_device_set_unmanaged_by_flags (self,
1552 NM_UNMANAGED_EXTERNAL_DOWN,
1554 NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED);
1557 device_recheck_slave_status (self, &info);
1558 return G_SOURCE_REMOVE;
1562 device_ip_link_changed (NMDevice *self)
1564 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
1565 const NMPlatformLink *pllink;
1567 priv->device_ip_link_changed_id = 0;
1569 if (!priv->ip_ifindex)
1570 return G_SOURCE_REMOVE;
1572 pllink = nm_platform_link_get (NM_PLATFORM_GET, priv->ip_ifindex);
1574 return G_SOURCE_REMOVE;
1576 if (pllink->name[0] && g_strcmp0 (priv->ip_iface, pllink->name)) {
1577 _LOGI (LOGD_DEVICE, "interface index %d renamed ip_iface (%d) from '%s' to '%s'",
1578 priv->ifindex, nm_device_get_ip_ifindex (self),
1579 priv->ip_iface, pllink->name);
1580 g_free (priv->ip_iface);
1581 priv->ip_iface = g_strdup (pllink->name);
1583 _notify (self, PROP_IP_IFACE);
1584 update_dynamic_ip_setup (self);
1586 return G_SOURCE_REMOVE;
1590 link_changed_cb (NMPlatform *platform,
1591 NMPObjectType obj_type,
1593 NMPlatformLink *info,
1594 NMPlatformSignalChangeType change_type,
1597 NMDevicePrivate *priv;
1599 if (change_type != NM_PLATFORM_SIGNAL_CHANGED)
1602 priv = NM_DEVICE_GET_PRIVATE (self);
1604 if (ifindex == nm_device_get_ifindex (self)) {
1605 if (!priv->device_link_changed_id) {
1606 priv->device_link_changed_id = g_idle_add ((GSourceFunc) device_link_changed, self);
1607 _LOGD (LOGD_DEVICE, "queued link change for ifindex %d", ifindex);
1609 } else if (ifindex == nm_device_get_ip_ifindex (self)) {
1610 if (!priv->device_ip_link_changed_id) {
1611 priv->device_ip_link_changed_id = g_idle_add ((GSourceFunc) device_ip_link_changed, self);
1612 _LOGD (LOGD_DEVICE, "queued link change for ip-ifindex %d", ifindex);
1618 link_changed (NMDevice *self, NMPlatformLink *info)
1620 /* Update carrier from link event if applicable. */
1621 if ( nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT)
1622 && !nm_device_has_capability (self, NM_DEVICE_CAP_NONSTANDARD_CARRIER))
1623 nm_device_set_carrier (self, info->connected);
1627 link_type_compatible (NMDevice *self,
1628 NMLinkType link_type,
1629 gboolean *out_compatible,
1632 NMDeviceClass *klass;
1633 NMLinkType device_type;
1636 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
1638 klass = NM_DEVICE_GET_CLASS (self);
1640 if (!klass->link_types) {
1641 NM_SET_OUT (out_compatible, FALSE);
1642 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
1643 "Device does not support platform links");
1647 device_type = self->priv->link_type;
1648 if (device_type > NM_LINK_TYPE_UNKNOWN && device_type != link_type) {
1649 g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
1650 "Needed link type 0x%x does not match the platform link type 0x%X",
1651 device_type, link_type);
1655 for (i = 0; klass->link_types[i] > NM_LINK_TYPE_UNKNOWN; i++) {
1656 if (klass->link_types[i] == link_type)
1658 if (klass->link_types[i] == NM_LINK_TYPE_ANY)
1662 NM_SET_OUT (out_compatible, FALSE);
1663 g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
1664 "Device does not support platform link type 0x%X",
1670 * nm_device_realize_start():
1671 * @self: the #NMDevice
1672 * @plink: an existing platform link or %NULL
1673 * @out_compatible: %TRUE on return if @self is compatible with @plink
1674 * @error: location to store error, or %NULL
1676 * Initializes and sets up the device using existing backing resources. Before
1677 * the device is ready for use nm_device_realize_finish() must be called.
1678 * @out_compatible will only be set if @plink is not %NULL, and
1680 * Important: if nm_device_realize_start() returns %TRUE, the caller MUST
1681 * also call nm_device_realize_finish() to balance g_object_freeze_notify().
1683 * Returns: %TRUE on success, %FALSE on error
1686 nm_device_realize_start (NMDevice *self,
1687 const NMPlatformLink *plink,
1688 gboolean *out_compatible,
1691 NM_SET_OUT (out_compatible, TRUE);
1694 if (g_strcmp0 (nm_device_get_iface (self), plink->name) != 0) {
1695 NM_SET_OUT (out_compatible, FALSE);
1696 g_set_error_literal (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_FAILED,
1697 "Device interface name does not match platform link");
1701 if (!link_type_compatible (self, plink->type, out_compatible, error))
1705 realize_start_setup (self, plink);
1711 * nm_device_create_and_realize():
1712 * @self: the #NMDevice
1713 * @connection: the #NMConnection being activated
1714 * @parent: the parent #NMDevice if any
1715 * @error: location to store error, or %NULL
1717 * Creates any backing resources needed to realize the device to proceed
1718 * with activating @connection.
1720 * Returns: %TRUE on success, %FALSE on error
1723 nm_device_create_and_realize (NMDevice *self,
1724 NMConnection *connection,
1728 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
1729 NMPlatformLink plink_copy;
1730 const NMPlatformLink *plink = NULL;
1732 /* Must be set before device is realized */
1733 priv->is_nm_owned = !nm_platform_link_get_by_ifname (NM_PLATFORM_GET, priv->iface);
1735 _LOGD (LOGD_DEVICE, "create (is %snm-owned)", priv->is_nm_owned ? "" : "not ");
1737 /* Create any resources the device needs */
1738 if (NM_DEVICE_GET_CLASS (self)->create_and_realize) {
1739 if (!NM_DEVICE_GET_CLASS (self)->create_and_realize (self, connection, parent, &plink, error))
1741 plink_copy = *plink;
1742 plink = &plink_copy;
1745 realize_start_setup (self, plink);
1746 nm_device_realize_finish (self, plink);
1748 if (nm_device_get_managed (self, FALSE)) {
1749 nm_device_state_changed (self,
1750 NM_DEVICE_STATE_UNAVAILABLE,
1751 NM_DEVICE_STATE_REASON_NOW_MANAGED);
1757 update_device_from_platform_link (NMDevice *self, const NMPlatformLink *plink)
1759 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
1762 g_return_if_fail (plink != NULL);
1764 udi = nm_platform_link_get_udi (NM_PLATFORM_GET, plink->ifindex);
1765 if (udi && !g_strcmp0 (udi, priv->udi)) {
1767 priv->udi = g_strdup (udi);
1768 _notify (self, PROP_UDI);
1771 if (!g_strcmp0 (plink->name, priv->iface)) {
1772 g_free (priv->iface);
1773 priv->iface = g_strdup (plink->name);
1774 _notify (self, PROP_IFACE);
1777 priv->ifindex = plink->ifindex;
1778 _notify (self, PROP_IFINDEX);
1780 priv->up = NM_FLAGS_HAS (plink->n_ifi_flags, IFF_UP);
1781 if (plink->driver && g_strcmp0 (plink->driver, priv->driver) != 0) {
1782 g_free (priv->driver);
1783 priv->driver = g_strdup (plink->driver);
1784 _notify (self, PROP_DRIVER);
1789 config_changed_update_ignore_carrier (NMConfig *config,
1790 NMConfigData *config_data,
1791 NMConfigChangeFlags changes,
1792 NMConfigData *old_data,
1795 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
1797 if ( priv->state <= NM_DEVICE_STATE_DISCONNECTED
1798 || priv->state > NM_DEVICE_STATE_ACTIVATED)
1799 priv->ignore_carrier = nm_config_data_get_ignore_carrier (config_data, self);
1803 check_carrier (NMDevice *self)
1805 int ifindex = nm_device_get_ip_ifindex (self);
1807 if (!nm_device_has_capability (self, NM_DEVICE_CAP_NONSTANDARD_CARRIER))
1808 nm_device_set_carrier (self, nm_platform_link_is_connected (NM_PLATFORM_GET, ifindex));
1812 realize_start_notify (NMDevice *self, const NMPlatformLink *plink)
1814 /* Stub implementation for realize_start_notify(). It does nothing,
1815 * but allows derived classes to uniformly invoke the parent
1816 * implementation. */
1820 * realize_start_setup():
1821 * @self: the #NMDevice
1822 * @plink: the #NMPlatformLink if backed by a kernel netdevice
1824 * Update the device from backing resource properties (like hardware
1825 * addresses, carrier states, driver/firmware info, etc). This function
1826 * should only change properties for this device, and should not perform
1827 * any tasks that affect other interfaces (like master/slave or parent/child
1831 realize_start_setup (NMDevice *self, const NMPlatformLink *plink)
1833 NMDevicePrivate *priv;
1834 NMDeviceClass *klass;
1835 static guint32 id = 0;
1837 g_return_if_fail (NM_IS_DEVICE (self));
1839 priv = NM_DEVICE_GET_PRIVATE (self);
1841 /* The device should not be realized */
1842 g_return_if_fail (!priv->real);
1843 g_return_if_fail (nm_device_get_unmanaged_flags (self, NM_UNMANAGED_PLATFORM_INIT));
1844 g_return_if_fail (priv->ip_ifindex <= 0);
1845 g_return_if_fail (priv->ip_iface == NULL);
1847 _LOGD (LOGD_DEVICE, "start setup of %s, kernel ifindex %d", G_OBJECT_TYPE_NAME (self), plink ? plink->ifindex : 0);
1849 klass = NM_DEVICE_GET_CLASS (self);
1851 /* Balanced by a thaw in nm_device_realize_finish() */
1852 g_object_freeze_notify (G_OBJECT (self));
1855 g_return_if_fail (link_type_compatible (self, plink->type, NULL, NULL));
1856 update_device_from_platform_link (self, plink);
1859 if (priv->ifindex > 0) {
1860 priv->physical_port_id = nm_platform_link_get_physical_port_id (NM_PLATFORM_GET, priv->ifindex);
1861 _notify (self, PROP_PHYSICAL_PORT_ID);
1863 priv->dev_id = nm_platform_link_get_dev_id (NM_PLATFORM_GET, priv->ifindex);
1865 if (nm_platform_link_is_software (NM_PLATFORM_GET, priv->ifindex))
1866 priv->capabilities |= NM_DEVICE_CAP_IS_SOFTWARE;
1868 priv->mtu = nm_platform_link_get_mtu (NM_PLATFORM_GET, priv->ifindex);
1869 _notify (self, PROP_MTU);
1871 nm_platform_link_get_driver_info (NM_PLATFORM_GET,
1874 &priv->driver_version,
1875 &priv->firmware_version);
1876 if (priv->driver_version)
1877 _notify (self, PROP_DRIVER_VERSION);
1878 if (priv->firmware_version)
1879 _notify (self, PROP_FIRMWARE_VERSION);
1881 if (nm_platform_check_support_user_ipv6ll (NM_PLATFORM_GET))
1882 priv->nm_ipv6ll = nm_platform_link_get_user_ipv6ll_enabled (NM_PLATFORM_GET, priv->ifindex);
1885 if (klass->get_generic_capabilities)
1886 priv->capabilities |= klass->get_generic_capabilities (self);
1889 /* Use a placeholder UDI until we get a real one */
1890 priv->udi = g_strdup_printf ("/virtual/device/placeholder/%d", id++);
1891 _notify (self, PROP_UDI);
1894 /* trigger initial ip config change to initialize ip-config */
1895 priv->queued_ip4_config_id = g_idle_add (queued_ip4_config_change, self);
1896 priv->queued_ip6_config_id = g_idle_add (queued_ip6_config_change, self);
1898 nm_device_update_hw_address (self);
1899 nm_device_update_initial_hw_address (self);
1901 /* Note: initial hardware address must be read before calling get_ignore_carrier() */
1902 if (nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT)) {
1903 NMConfig *config = nm_config_get ();
1905 priv->ignore_carrier = nm_config_data_get_ignore_carrier (nm_config_get_data (config), self);
1906 g_signal_connect (G_OBJECT (config),
1907 NM_CONFIG_SIGNAL_CONFIG_CHANGED,
1908 G_CALLBACK (config_changed_update_ignore_carrier),
1911 check_carrier (self);
1914 priv->carrier ? "ON" : "OFF",
1915 priv->ignore_carrier ? " (but ignored)" : "");
1917 /* Fake online link when carrier detection is not available. */
1918 priv->carrier = TRUE;
1921 _notify (self, PROP_CAPABILITIES);
1923 klass->realize_start_notify (self, plink);
1925 /* Do not manage externally created software devices until they are IFF_UP */
1926 if ( priv->ifindex > 0
1929 && NM_DEVICE_GET_CLASS (self)->can_unmanaged_external_down (self))
1930 nm_device_set_unmanaged_flags (self, NM_UNMANAGED_EXTERNAL_DOWN, TRUE);
1932 /* Unmanaged the loopback device with an explicit NM_UNMANAGED_LOOPBACK flag.
1933 * Later we might want to manage 'lo' too. Currently that doesn't work because
1934 * NetworkManager might down the interface or remove the 127.0.0.1 address. */
1935 nm_device_set_unmanaged_flags (self, NM_UNMANAGED_LOOPBACK, priv->ifindex == 1);
1937 nm_device_set_unmanaged_by_user_udev (self);
1939 nm_device_set_unmanaged_flags (self, NM_UNMANAGED_PLATFORM_INIT,
1940 plink && !plink->initialized);
1944 * nm_device_realize_finish():
1945 * @self: the #NMDevice
1946 * @plink: the #NMPlatformLink if backed by a kernel netdevice
1948 * Update the device's master/slave or parent/child relationships from
1949 * backing resource properties. After this function finishes, the device
1950 * is ready for network connectivity.
1953 nm_device_realize_finish (NMDevice *self, const NMPlatformLink *plink)
1955 NMDevicePrivate *priv;
1957 g_return_if_fail (NM_IS_DEVICE (self));
1958 g_return_if_fail (!plink || link_type_compatible (self, plink->type, NULL, NULL));
1960 priv = NM_DEVICE_GET_PRIVATE (self);
1962 g_return_if_fail (!priv->real);
1965 device_recheck_slave_status (self, plink);
1968 _notify (self, PROP_REAL);
1970 nm_device_recheck_available_connections (self);
1972 /* Balanced by a freeze in realize_start_setup(). */
1973 g_object_thaw_notify (G_OBJECT (self));
1977 unrealize_notify (NMDevice *self)
1979 /* Stub implementation for unrealize_notify(). It does nothing,
1980 * but allows derived classes to uniformly invoke the parent
1981 * implementation. */
1985 available_connections_check_delete_unrealized_on_idle (gpointer user_data)
1987 NMDevice *self = user_data;
1988 NMDevicePrivate *priv;
1990 g_return_val_if_fail (NM_IS_DEVICE (self), G_SOURCE_REMOVE);
1992 priv = NM_DEVICE_GET_PRIVATE (self);
1994 priv->check_delete_unrealized_id = 0;
1996 if ( g_hash_table_size (priv->available_connections) == 0
1997 && !nm_device_is_real (self))
1998 g_signal_emit (self, signals[REMOVED], 0);
2000 return G_SOURCE_REMOVE;
2004 available_connections_check_delete_unrealized (NMDevice *self)
2006 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
2008 /* always rescheadule the remove signal. */
2009 nm_clear_g_source (&priv->check_delete_unrealized_id);
2011 if ( g_hash_table_size (priv->available_connections) == 0
2012 && !nm_device_is_real (self))
2013 priv->check_delete_unrealized_id = g_idle_add (available_connections_check_delete_unrealized_on_idle, self);
2017 * nm_device_unrealize():
2018 * @self: the #NMDevice
2019 * @remove_resources: if %TRUE, remove backing resources
2020 * @error: location to store error, or %NULL
2022 * Clears any properties that depend on backing resources (kernel devices,
2023 * etc) and removes those resources if @remove_resources is %TRUE.
2025 * Returns: %TRUE on success, %FALSE on error
2028 nm_device_unrealize (NMDevice *self, gboolean remove_resources, GError **error)
2030 NMDevicePrivate *priv;
2033 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
2035 if (!nm_device_is_software (self) || !nm_device_is_real (self)) {
2036 g_set_error_literal (error,
2038 NM_DEVICE_ERROR_NOT_SOFTWARE,
2039 "This device is not a software device or is not realized");
2043 priv = NM_DEVICE_GET_PRIVATE (self);
2045 g_return_val_if_fail (priv->iface != NULL, FALSE);
2046 g_return_val_if_fail (priv->real, FALSE);
2048 g_object_freeze_notify (G_OBJECT (self));
2050 ifindex = nm_device_get_ifindex (self);
2052 _LOGD (LOGD_DEVICE, "unrealize (ifindex %d)", ifindex > 0 ? ifindex : 0);
2054 if (remove_resources) {
2056 nm_platform_link_delete (NM_PLATFORM_GET, ifindex);
2059 NM_DEVICE_GET_CLASS (self)->unrealize_notify (self);
2061 if (priv->ifindex > 0) {
2063 _notify (self, PROP_IFINDEX);
2065 priv->ip_ifindex = 0;
2066 if (priv->ip_iface) {
2067 g_clear_pointer (&priv->ip_iface, g_free);
2068 _notify (self, PROP_IP_IFACE);
2070 if (priv->driver_version) {
2071 g_clear_pointer (&priv->driver_version, g_free);
2072 _notify (self, PROP_DRIVER_VERSION);
2074 if (priv->firmware_version) {
2075 g_clear_pointer (&priv->firmware_version, g_free);
2076 _notify (self, PROP_FIRMWARE_VERSION);
2079 g_clear_pointer (&priv->udi, g_free);
2080 _notify (self, PROP_UDI);
2082 if (priv->hw_addr) {
2083 g_clear_pointer (&priv->hw_addr, g_free);
2084 _notify (self, PROP_HW_ADDRESS);
2086 if (priv->physical_port_id) {
2087 g_clear_pointer (&priv->physical_port_id, g_free);
2088 _notify (self, PROP_PHYSICAL_PORT_ID);
2091 g_clear_pointer (&priv->perm_hw_addr, g_free);
2092 g_clear_pointer (&priv->initial_hw_addr, g_free);
2094 priv->capabilities = NM_DEVICE_CAP_NM_SUPPORTED;
2095 if (NM_DEVICE_GET_CLASS (self)->get_generic_capabilities)
2096 priv->capabilities |= NM_DEVICE_GET_CLASS (self)->get_generic_capabilities (self);
2097 _notify (self, PROP_CAPABILITIES);
2100 _notify (self, PROP_REAL);
2102 nm_device_set_autoconnect (self, DEFAULT_AUTOCONNECT);
2104 g_object_thaw_notify (G_OBJECT (self));
2106 nm_device_set_unmanaged_flags (self,
2107 NM_UNMANAGED_PLATFORM_INIT,
2110 nm_device_set_unmanaged_flags (self,
2111 NM_UNMANAGED_PARENT |
2112 NM_UNMANAGED_LOOPBACK |
2113 NM_UNMANAGED_USER_UDEV |
2114 NM_UNMANAGED_EXTERNAL_DOWN |
2115 NM_UNMANAGED_IS_SLAVE,
2116 NM_UNMAN_FLAG_OP_FORGET);
2118 nm_device_state_changed (self,
2119 NM_DEVICE_STATE_UNMANAGED,
2121 NM_DEVICE_STATE_REASON_USER_REQUESTED : NM_DEVICE_STATE_REASON_NOW_UNMANAGED);
2123 /* Garbage-collect unneeded unrealized devices. */
2124 nm_device_recheck_available_connections (self);
2130 * nm_device_notify_new_device_added():
2131 * @self: the #NMDevice
2132 * @device: the newly added device
2134 * Called by the manager to notify the device that a new device has
2135 * been found and added.
2138 nm_device_notify_new_device_added (NMDevice *self, NMDevice *device)
2140 NMDeviceClass *klass;
2142 g_return_if_fail (NM_IS_DEVICE (self));
2143 g_return_if_fail (NM_IS_DEVICE (device));
2145 klass = NM_DEVICE_GET_CLASS (self);
2146 if (klass->notify_new_device_added)
2147 klass->notify_new_device_added (self, device);
2151 * nm_device_notify_component_added():
2152 * @self: the #NMDevice
2153 * @component: the component being added by a plugin
2155 * Called by the manager to notify the device that a new component has
2156 * been found. The device implementation should return %TRUE if it
2157 * wishes to claim the component, or %FALSE if it cannot.
2159 * Returns: %TRUE to claim the component, %FALSE if the component cannot be
2163 nm_device_notify_component_added (NMDevice *self, GObject *component)
2165 NMDeviceClass *klass;
2167 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
2168 g_return_val_if_fail (G_IS_OBJECT (component), FALSE);
2170 klass = NM_DEVICE_GET_CLASS (self);
2171 if (klass->component_added)
2172 return klass->component_added (self, component);
2177 * nm_device_owns_iface():
2178 * @self: the #NMDevice
2179 * @iface: an interface name
2181 * Called by the manager to ask if the device or any of its components owns
2182 * @iface. For example, a WWAN implementation would return %TRUE for an
2183 * ethernet interface name that was owned by the WWAN device's modem component,
2184 * because that ethernet interface is controlled by the WWAN device and cannot
2185 * be used independently of the WWAN device.
2187 * Returns: %TRUE if @self or it's components owns the interface name,
2191 nm_device_owns_iface (NMDevice *self, const char *iface)
2193 if (NM_DEVICE_GET_CLASS (self)->owns_iface)
2194 return NM_DEVICE_GET_CLASS (self)->owns_iface (self, iface);
2199 nm_device_new_default_connection (NMDevice *self)
2201 if (NM_DEVICE_GET_CLASS (self)->new_default_connection)
2202 return NM_DEVICE_GET_CLASS (self)->new_default_connection (self);
2207 slave_state_changed (NMDevice *slave,
2208 NMDeviceState slave_new_state,
2209 NMDeviceState slave_old_state,
2210 NMDeviceStateReason reason,
2213 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
2214 gboolean release = FALSE;
2216 _LOGD (LOGD_DEVICE, "slave %s state change %d (%s) -> %d (%s)",
2217 nm_device_get_iface (slave),
2219 state_to_string (slave_old_state),
2221 state_to_string (slave_new_state));
2223 /* Don't try to enslave slaves until the master is ready */
2224 if (priv->state < NM_DEVICE_STATE_CONFIG)
2227 if (slave_new_state == NM_DEVICE_STATE_IP_CONFIG)
2228 nm_device_master_enslave_slave (self, slave, nm_device_get_applied_connection (slave));
2229 else if (slave_new_state > NM_DEVICE_STATE_ACTIVATED)
2231 else if ( slave_new_state <= NM_DEVICE_STATE_DISCONNECTED
2232 && slave_old_state > NM_DEVICE_STATE_DISCONNECTED) {
2233 /* Catch failures due to unavailable or unmanaged */
2238 nm_device_master_release_one_slave (self, slave, TRUE, reason);
2239 /* Bridge/bond/team interfaces are left up until manually deactivated */
2240 if (priv->slaves == NULL && priv->state == NM_DEVICE_STATE_ACTIVATED)
2241 _LOGD (LOGD_DEVICE, "last slave removed; remaining activated");
2246 * nm_device_master_add_slave:
2247 * @self: the master device
2248 * @slave: the slave device to enslave
2249 * @configure: pass %TRUE if the slave should be configured by the master, or
2250 * %FALSE if it is already configured outside NetworkManager
2252 * If @self is capable of enslaving other devices (ie it's a bridge, bond, team,
2253 * etc) then this function adds @slave to the slave list for later enslavement.
2256 nm_device_master_add_slave (NMDevice *self, NMDevice *slave, gboolean configure)
2258 NMDevicePrivate *priv;
2259 NMDevicePrivate *slave_priv;
2262 g_return_if_fail (NM_IS_DEVICE (self));
2263 g_return_if_fail (NM_IS_DEVICE (slave));
2264 g_return_if_fail (NM_DEVICE_GET_CLASS (self)->enslave_slave != NULL);
2266 priv = NM_DEVICE_GET_PRIVATE (self);
2267 slave_priv = NM_DEVICE_GET_PRIVATE (slave);
2269 info = find_slave_info (self, slave);
2271 _LOGt (LOGD_CORE, "master: add one slave %p/%s%s", slave, nm_device_get_iface (slave),
2272 info ? " (already registered)" : "");
2275 g_return_if_fail (nm_device_get_state (slave) >= NM_DEVICE_STATE_DISCONNECTED);
2278 g_return_if_fail (!slave_priv->master);
2279 g_return_if_fail (!slave_priv->is_enslaved);
2281 info = g_slice_new0 (SlaveInfo);
2282 info->slave = g_object_ref (slave);
2283 info->configure = configure;
2284 info->watch_id = g_signal_connect (slave,
2285 NM_DEVICE_STATE_CHANGED,
2286 G_CALLBACK (slave_state_changed), self);
2287 priv->slaves = g_slist_append (priv->slaves, info);
2288 slave_priv->master = g_object_ref (self);
2292 * _notify (slave, PROP_MASTER);
2294 * because slave_priv->is_enslaved is not true, thus the value
2295 * didn't change yet. */
2297 g_warn_if_fail (!NM_FLAGS_HAS (slave_priv->unmanaged_mask, NM_UNMANAGED_IS_SLAVE));
2298 nm_device_set_unmanaged_by_flags (slave, NM_UNMANAGED_IS_SLAVE, FALSE, NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED);
2300 g_return_if_fail (slave_priv->master == self);
2302 nm_device_queue_recheck_assume (self);
2303 nm_device_queue_recheck_assume (slave);
2308 * nm_device_master_get_slaves:
2309 * @self: the master device
2311 * Returns: any slaves of which @self is the master. Caller owns returned list.
2314 nm_device_master_get_slaves (NMDevice *self)
2316 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
2317 GSList *slaves = NULL, *iter;
2319 for (iter = priv->slaves; iter; iter = g_slist_next (iter))
2320 slaves = g_slist_prepend (slaves, ((SlaveInfo *) iter->data)->slave);
2326 * nm_device_master_get_slave_by_ifindex:
2327 * @self: the master device
2328 * @ifindex: the slave's interface index
2330 * Returns: the slave with the given @ifindex of which @self is the master,
2331 * or %NULL if no device with @ifindex is a slave of @self.
2334 nm_device_master_get_slave_by_ifindex (NMDevice *self, int ifindex)
2338 for (iter = NM_DEVICE_GET_PRIVATE (self)->slaves; iter; iter = g_slist_next (iter)) {
2339 SlaveInfo *info = iter->data;
2341 if (nm_device_get_ip_ifindex (info->slave) == ifindex)
2348 * nm_device_master_check_slave_physical_port:
2349 * @self: the master device
2350 * @slave: a slave device
2351 * @log_domain: domain to log a warning in
2353 * Checks if @self already has a slave with the same #NMDevice:physical-port-id
2354 * as @slave, and logs a warning if so.
2357 nm_device_master_check_slave_physical_port (NMDevice *self, NMDevice *slave,
2358 NMLogDomain log_domain)
2360 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
2361 const char *slave_physical_port_id, *existing_physical_port_id;
2365 slave_physical_port_id = nm_device_get_physical_port_id (slave);
2366 if (!slave_physical_port_id)
2369 for (iter = priv->slaves; iter; iter = iter->next) {
2371 if (info->slave == slave)
2374 existing_physical_port_id = nm_device_get_physical_port_id (info->slave);
2375 if (!g_strcmp0 (slave_physical_port_id, existing_physical_port_id)) {
2376 _LOGW (log_domain, "slave %s shares a physical port with existing slave %s",
2377 nm_device_get_ip_iface (slave),
2378 nm_device_get_ip_iface (info->slave));
2379 /* Since this function will get called for every slave, we only have
2380 * to warn about the first match we find; if there are other matches
2381 * later in the list, we will have already warned about them matching
2382 * @existing earlier.
2389 /* release all slaves */
2391 nm_device_master_release_slaves (NMDevice *self)
2393 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
2394 NMDeviceStateReason reason;
2395 gboolean configure = TRUE;
2397 /* Don't release the slaves if this connection doesn't belong to NM. */
2398 if (nm_device_uses_generated_assumed_connection (self))
2401 reason = priv->state_reason;
2402 if (priv->state == NM_DEVICE_STATE_FAILED)
2403 reason = NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED;
2405 if (!nm_platform_link_get (NM_PLATFORM_GET, priv->ifindex))
2408 while (priv->slaves) {
2409 SlaveInfo *info = priv->slaves->data;
2411 nm_device_master_release_one_slave (self, info->slave, configure, reason);
2416 * nm_device_is_master:
2419 * Returns: %TRUE if the device can have slaves
2422 nm_device_is_master (NMDevice *self)
2424 return NM_DEVICE_GET_PRIVATE (self)->is_master;
2428 * nm_device_get_master:
2431 * If @self has been enslaved by another device, this returns that
2432 * device. Otherwise it returns %NULL. (In particular, note that if
2433 * @self is in the process of activating as a slave, but has not yet
2434 * been enslaved by its master, this will return %NULL.)
2436 * Returns: (transfer none): @self's master, or %NULL
2439 nm_device_get_master (NMDevice *self)
2441 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
2443 if (priv->is_enslaved) {
2444 g_return_val_if_fail (priv->master, NULL);
2445 return priv->master;
2451 * nm_device_slave_notify_enslave:
2452 * @self: the slave device
2453 * @success: whether the enslaving operation succeeded
2455 * Notifies a slave that either it has been enslaved, or else its master tried
2456 * to enslave it and failed.
2459 nm_device_slave_notify_enslave (NMDevice *self, gboolean success)
2461 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
2462 NMConnection *connection = nm_device_get_applied_connection (self);
2463 gboolean activating = (priv->state == NM_DEVICE_STATE_IP_CONFIG);
2465 g_return_if_fail (priv->master);
2467 if (!priv->is_enslaved) {
2470 _LOGI (LOGD_DEVICE, "Activation: connection '%s' enslaved, continuing activation",
2471 nm_connection_get_id (connection));
2473 _LOGI (LOGD_DEVICE, "enslaved to %s", nm_device_get_iface (priv->master));
2475 priv->is_enslaved = TRUE;
2476 _notify (self, PROP_MASTER);
2477 _notify (priv->master, PROP_SLAVES);
2478 } else if (activating) {
2479 _LOGW (LOGD_DEVICE, "Activation: connection '%s' could not be enslaved",
2480 nm_connection_get_id (connection));
2485 priv->ip4_state = IP_DONE;
2486 priv->ip6_state = IP_DONE;
2488 nm_device_queue_state (self, NM_DEVICE_STATE_SECONDARIES, NM_DEVICE_STATE_REASON_NONE);
2490 nm_device_queue_state (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_UNKNOWN);
2492 nm_device_queue_recheck_assume (self);
2496 * nm_device_slave_notify_release:
2497 * @self: the slave device
2498 * @reason: the reason associated with the state change
2500 * Notifies a slave that it has been released, and why.
2503 nm_device_slave_notify_release (NMDevice *self, NMDeviceStateReason reason)
2505 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
2506 NMConnection *connection = nm_device_get_applied_connection (self);
2507 NMDeviceState new_state;
2508 const char *master_status;
2510 g_return_if_fail (priv->master);
2512 if ( priv->state > NM_DEVICE_STATE_DISCONNECTED
2513 && priv->state <= NM_DEVICE_STATE_ACTIVATED) {
2514 if (reason == NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED) {
2515 new_state = NM_DEVICE_STATE_FAILED;
2516 master_status = "failed";
2517 } else if (reason == NM_DEVICE_STATE_REASON_USER_REQUESTED) {
2518 new_state = NM_DEVICE_STATE_DEACTIVATING;
2519 master_status = "deactivated by user request";
2521 new_state = NM_DEVICE_STATE_DISCONNECTED;
2522 master_status = "deactivated";
2525 _LOGD (LOGD_DEVICE, "Activation: connection '%s' master %s",
2526 nm_connection_get_id (connection),
2529 nm_device_queue_state (self, new_state, reason);
2531 _LOGI (LOGD_DEVICE, "released from master device %s", nm_device_get_iface (priv->master));
2533 if (priv->is_enslaved) {
2534 priv->is_enslaved = FALSE;
2535 _notify (self, PROP_MASTER);
2536 _notify (priv->master, PROP_SLAVES);
2541 * nm_device_get_enslaved:
2542 * @self: the #NMDevice
2544 * Returns: %TRUE if the device is enslaved to a master device (eg bridge or
2545 * bond or team), %FALSE if not
2548 nm_device_get_enslaved (NMDevice *self)
2550 return NM_DEVICE_GET_PRIVATE (self)->is_enslaved;
2554 * nm_device_removed:
2555 * @self: the #NMDevice
2557 * Called by the manager when the device was removed. Releases the device from
2558 * the master in case it's enslaved.
2561 nm_device_removed (NMDevice *self)
2563 NMDevicePrivate *priv;
2565 g_return_if_fail (NM_IS_DEVICE (self));
2567 priv = NM_DEVICE_GET_PRIVATE (self);
2569 /* this is called when something externally messes with the slave or during shut-down.
2570 * Release the slave from master, but don't touch the device. */
2571 nm_device_master_release_one_slave (priv->master, self, FALSE, NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED);
2576 is_available (NMDevice *self, NMDeviceCheckDevAvailableFlags flags)
2578 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
2580 if (priv->carrier || priv->ignore_carrier)
2583 if (NM_FLAGS_HAS (flags, _NM_DEVICE_CHECK_DEV_AVAILABLE_IGNORE_CARRIER))
2590 * nm_device_is_available:
2591 * @self: the #NMDevice
2592 * @flags: additional flags to influence the check. Flags have the
2593 * meaning to increase the availability of a device.
2595 * Checks if @self would currently be capable of activating a
2596 * connection. In particular, it checks that the device is ready (eg,
2597 * is not missing firmware), that it has carrier (if necessary), and
2598 * that any necessary external software (eg, ModemManager,
2599 * wpa_supplicant) is available.
2601 * @self can only be in a state higher than
2602 * %NM_DEVICE_STATE_UNAVAILABLE when nm_device_is_available() returns
2603 * %TRUE. (But note that it can still be %NM_DEVICE_STATE_UNMANAGED
2604 * when it is available.)
2606 * Returns: %TRUE or %FALSE
2609 nm_device_is_available (NMDevice *self, NMDeviceCheckDevAvailableFlags flags)
2611 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
2613 if (priv->firmware_missing)
2616 return NM_DEVICE_GET_CLASS (self)->is_available (self, flags);
2620 nm_device_get_enabled (NMDevice *self)
2622 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
2624 if (NM_DEVICE_GET_CLASS (self)->get_enabled)
2625 return NM_DEVICE_GET_CLASS (self)->get_enabled (self);
2630 nm_device_set_enabled (NMDevice *self, gboolean enabled)
2632 g_return_if_fail (NM_IS_DEVICE (self));
2634 if (NM_DEVICE_GET_CLASS (self)->set_enabled)
2635 NM_DEVICE_GET_CLASS (self)->set_enabled (self, enabled);
2639 * nm_device_get_autoconnect:
2640 * @self: the #NMDevice
2642 * Returns: %TRUE if the device allows autoconnect connections, or %FALSE if the
2643 * device is explicitly blocking all autoconnect connections. Does not take
2644 * into account transient conditions like companion devices that may wish to
2648 nm_device_get_autoconnect (NMDevice *self)
2650 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
2652 return NM_DEVICE_GET_PRIVATE (self)->autoconnect;
2656 nm_device_set_autoconnect (NMDevice *self, gboolean autoconnect)
2658 NMDevicePrivate *priv;
2660 g_return_if_fail (NM_IS_DEVICE (self));
2662 autoconnect = !!autoconnect;
2664 priv = NM_DEVICE_GET_PRIVATE (self);
2665 if (priv->autoconnect != autoconnect) {
2666 priv->autoconnect = autoconnect;
2667 _notify (self, PROP_AUTOCONNECT);
2672 autoconnect_allowed_accumulator (GSignalInvocationHint *ihint,
2673 GValue *return_accu,
2674 const GValue *handler_return, gpointer data)
2676 if (!g_value_get_boolean (handler_return))
2677 g_value_set_boolean (return_accu, FALSE);
2682 * nm_device_autoconnect_allowed:
2683 * @self: the #NMDevice
2685 * Returns: %TRUE if the device can be auto-connected immediately, taking
2686 * transient conditions into account (like companion devices that may wish to
2687 * block autoconnect for a time).
2690 nm_device_autoconnect_allowed (NMDevice *self)
2692 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
2693 GValue instance = G_VALUE_INIT;
2694 GValue retval = G_VALUE_INIT;
2696 if (!priv->autoconnect)
2699 /* Unrealized devices can always autoconnect. */
2700 if (nm_device_is_real (self) && priv->state < NM_DEVICE_STATE_DISCONNECTED)
2703 /* The 'autoconnect-allowed' signal is emitted on a device to allow
2704 * other listeners to block autoconnect on the device if they wish.
2705 * This is mainly used by the OLPC Mesh devices to block autoconnect
2706 * on their companion WiFi device as they share radio resources and
2707 * cannot be connected at the same time.
2710 g_value_init (&instance, G_TYPE_OBJECT);
2711 g_value_set_object (&instance, self);
2713 g_value_init (&retval, G_TYPE_BOOLEAN);
2714 g_value_set_boolean (&retval, TRUE);
2716 /* Use g_signal_emitv() rather than g_signal_emit() to avoid the return
2717 * value being changed if no handlers are connected */
2718 g_signal_emitv (&instance, signals[AUTOCONNECT_ALLOWED], 0, &retval);
2719 g_value_unset (&instance);
2721 return g_value_get_boolean (&retval);
2725 can_auto_connect (NMDevice *self,
2726 NMConnection *connection,
2727 char **specific_object)
2729 NMSettingConnection *s_con;
2731 s_con = nm_connection_get_setting_connection (connection);
2732 if (!nm_setting_connection_get_autoconnect (s_con))
2735 return nm_device_check_connection_available (self, connection, NM_DEVICE_CHECK_CON_AVAILABLE_NONE, NULL);
2739 * nm_device_can_auto_connect:
2740 * @self: an #NMDevice
2741 * @connection: a #NMConnection
2742 * @specific_object: (out) (transfer full): on output, the path of an
2743 * object associated with the returned connection, to be passed to
2744 * nm_manager_activate_connection(), or %NULL.
2746 * Checks if @connection can be auto-activated on @self right now.
2747 * This requires, at a minimum, that the connection be compatible with
2748 * @self, and that it have the #NMSettingConnection:autoconnect property
2749 * set, and that the device allow auto connections. Some devices impose
2750 * additional requirements. (Eg, a Wi-Fi connection can only be activated
2751 * if its SSID was seen in the last scan.)
2753 * Returns: %TRUE, if the @connection can be auto-activated.
2756 nm_device_can_auto_connect (NMDevice *self,
2757 NMConnection *connection,
2758 char **specific_object)
2760 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
2761 g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
2762 g_return_val_if_fail (specific_object && !*specific_object, FALSE);
2764 if (nm_device_autoconnect_allowed (self))
2765 return NM_DEVICE_GET_CLASS (self)->can_auto_connect (self, connection, specific_object);
2770 device_has_config (NMDevice *self)
2772 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
2774 /* Check for IP configuration. */
2775 if (priv->ip4_config && nm_ip4_config_get_num_addresses (priv->ip4_config))
2777 if (priv->ip6_config && nm_ip6_config_get_num_addresses (priv->ip6_config))
2780 /* The existence of a software device is good enough. */
2781 if (nm_device_is_software (self) && nm_device_is_real (self))
2784 /* Slaves are also configured by definition */
2785 if (nm_platform_link_get_master (NM_PLATFORM_GET, priv->ifindex) > 0)
2792 * nm_device_master_update_slave_connection:
2793 * @self: the master #NMDevice
2794 * @slave: the slave #NMDevice
2795 * @connection: the #NMConnection to update with the slave settings
2796 * @GError: (out): error description
2798 * Reads the slave configuration for @slave and updates @connection with those
2799 * properties. This invokes a virtual function on the master device @self.
2801 * Returns: %TRUE if the configuration was read and @connection updated,
2802 * %FALSE on failure.
2805 nm_device_master_update_slave_connection (NMDevice *self,
2807 NMConnection *connection,
2810 NMDeviceClass *klass;
2813 g_return_val_if_fail (self, FALSE);
2814 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
2815 g_return_val_if_fail (slave, FALSE);
2816 g_return_val_if_fail (connection, FALSE);
2817 g_return_val_if_fail (!error || !*error, FALSE);
2818 g_return_val_if_fail (nm_connection_get_setting_connection (connection), FALSE);
2820 g_return_val_if_fail (nm_device_get_iface (self), FALSE);
2822 klass = NM_DEVICE_GET_CLASS (self);
2823 if (klass->master_update_slave_connection) {
2824 success = klass->master_update_slave_connection (self, slave, connection, error);
2826 g_return_val_if_fail (!error || (success && !*error) || *error, success);
2832 NM_DEVICE_ERROR_FAILED,
2833 "master device '%s' cannot update a slave connection for slave device '%s' (master type not supported?)",
2834 nm_device_get_iface (self), nm_device_get_iface (slave));
2839 nm_device_generate_connection (NMDevice *self, NMDevice *master)
2841 NMDeviceClass *klass = NM_DEVICE_GET_CLASS (self);
2842 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
2843 const char *ifname = nm_device_get_iface (self);
2844 NMConnection *connection;
2848 gs_free char *uuid = NULL;
2849 const char *ip4_method, *ip6_method;
2850 GError *error = NULL;
2852 /* If update_connection() is not implemented, just fail. */
2853 if (!klass->update_connection)
2856 /* Return NULL if device is unconfigured. */
2857 if (!device_has_config (self)) {
2858 _LOGD (LOGD_DEVICE, "device has no existing configuration");
2862 connection = nm_simple_connection_new ();
2863 s_con = nm_setting_connection_new ();
2864 uuid = nm_utils_uuid_generate ();
2866 g_object_set (s_con,
2867 NM_SETTING_CONNECTION_UUID, uuid,
2868 NM_SETTING_CONNECTION_ID, ifname,
2869 NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
2870 NM_SETTING_CONNECTION_INTERFACE_NAME, ifname,
2871 NM_SETTING_CONNECTION_TIMESTAMP, (guint64) time (NULL),
2873 if (klass->connection_type)
2874 g_object_set (s_con, NM_SETTING_CONNECTION_TYPE, klass->connection_type, NULL);
2875 nm_connection_add_setting (connection, s_con);
2877 /* If the device is a slave, update various slave settings */
2879 if (!nm_device_master_update_slave_connection (master,
2884 _LOGE (LOGD_DEVICE, "master device '%s' failed to update slave connection: %s",
2885 nm_device_get_iface (master), error->message);
2886 g_error_free (error);
2887 g_object_unref (connection);
2891 /* Only regular and master devices get IP configuration; slaves do not */
2892 s_ip4 = nm_ip4_config_create_setting (priv->ip4_config);
2893 nm_connection_add_setting (connection, s_ip4);
2895 s_ip6 = nm_ip6_config_create_setting (priv->ip6_config);
2896 nm_connection_add_setting (connection, s_ip6);
2899 klass->update_connection (self, connection);
2901 /* Check the connection in case of update_connection() bug. */
2902 if (!nm_connection_verify (connection, &error)) {
2903 _LOGE (LOGD_DEVICE, "Generated connection does not verify: %s", error->message);
2904 g_clear_error (&error);
2905 g_object_unref (connection);
2909 /* Ignore the connection if it has no IP configuration,
2910 * no slave configuration, and is not a master interface.
2912 ip4_method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
2913 ip6_method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
2914 if ( g_strcmp0 (ip4_method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0
2915 && g_strcmp0 (ip6_method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0
2916 && !nm_setting_connection_get_master (NM_SETTING_CONNECTION (s_con))
2918 _LOGD (LOGD_DEVICE, "ignoring generated connection (no IP and not in master-slave relationship)");
2919 g_object_unref (connection);
2923 /* Ignore any IPv6LL-only, not master connections without slaves,
2924 * unless they are in the assume-ipv6ll-only list.
2927 && g_strcmp0 (ip4_method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0
2928 && g_strcmp0 (ip6_method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0
2929 && !nm_setting_connection_get_master (NM_SETTING_CONNECTION (s_con))
2931 && !nm_config_data_get_assume_ipv6ll_only (NM_CONFIG_GET_DATA, self)) {
2932 _LOGD (LOGD_DEVICE, "ignoring generated connection (IPv6LL-only and not in master-slave relationship)");
2933 g_object_unref (connection);
2941 nm_device_complete_connection (NMDevice *self,
2942 NMConnection *connection,
2943 const char *specific_object,
2944 const GSList *existing_connections,
2947 gboolean success = FALSE;
2949 g_return_val_if_fail (self != NULL, FALSE);
2950 g_return_val_if_fail (connection != NULL, FALSE);
2952 if (!NM_DEVICE_GET_CLASS (self)->complete_connection) {
2953 g_set_error (error, NM_DEVICE_ERROR, NM_DEVICE_ERROR_INVALID_CONNECTION,
2954 "Device class %s had no complete_connection method",
2955 G_OBJECT_TYPE_NAME (self));
2959 success = NM_DEVICE_GET_CLASS (self)->complete_connection (self,
2962 existing_connections,
2965 success = nm_connection_verify (connection, error);
2971 check_connection_compatible (NMDevice *self, NMConnection *connection)
2973 const char *device_iface = nm_device_get_iface (self);
2974 gs_free char *conn_iface = nm_manager_get_connection_iface (nm_manager_get (),
2978 /* We always need a interface name for virtual devices, but for
2979 * physical ones a connection without interface name is fine for
2982 return !nm_connection_is_virtual (connection);
2984 if (strcmp (conn_iface, device_iface) != 0)
2991 * nm_device_check_connection_compatible:
2992 * @self: an #NMDevice
2993 * @connection: an #NMConnection
2995 * Checks if @connection could potentially be activated on @self.
2996 * This means only that @self has the proper capabilities, and that
2997 * @connection is not locked to some other device. It does not
2998 * necessarily mean that @connection could be activated on @self
2999 * right now. (Eg, it might refer to a Wi-Fi network that is not
3000 * currently available.)
3002 * Returns: #TRUE if @connection could potentially be activated on
3006 nm_device_check_connection_compatible (NMDevice *self, NMConnection *connection)
3008 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
3009 g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
3011 return NM_DEVICE_GET_CLASS (self)->check_connection_compatible (self, connection);
3015 nm_device_check_slave_connection_compatible (NMDevice *self, NMConnection *slave)
3017 NMDevicePrivate *priv;
3018 NMSettingConnection *s_con;
3019 const char *connection_type, *slave_type;
3021 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
3022 g_return_val_if_fail (NM_IS_CONNECTION (slave), FALSE);
3024 priv = NM_DEVICE_GET_PRIVATE (self);
3026 if (!priv->is_master)
3029 /* All masters should have connection type set */
3030 connection_type = NM_DEVICE_GET_CLASS (self)->connection_type;
3031 g_return_val_if_fail (connection_type, FALSE);
3033 s_con = nm_connection_get_setting_connection (slave);
3035 slave_type = nm_setting_connection_get_slave_type (s_con);
3039 return strcmp (connection_type, slave_type) == 0;
3043 * nm_device_can_assume_connections:
3044 * @self: #NMDevice instance
3046 * This is a convenience function to determine whether connection assumption
3047 * is available for this device.
3049 * Returns: %TRUE if the device is capable of assuming connections, %FALSE if not
3052 nm_device_can_assume_connections (NMDevice *self)
3054 return !!NM_DEVICE_GET_CLASS (self)->update_connection
3055 && !NM_DEVICE_GET_PRIVATE (self)->is_nm_owned;
3059 * nm_device_can_assume_active_connection:
3060 * @self: #NMDevice instance
3062 * This is a convenience function to determine whether the device's active
3063 * connection can be assumed if NetworkManager restarts. This method returns
3064 * %TRUE if and only if the device can assume connections, and the device has
3065 * an active connection, and that active connection can be assumed.
3067 * Returns: %TRUE if the device's active connection can be assumed, or %FALSE
3068 * if there is no active connection or the active connection cannot be
3072 nm_device_can_assume_active_connection (NMDevice *self)
3074 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
3075 NMConnection *connection;
3077 const char *assumable_ip6_methods[] = {
3078 NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
3079 NM_SETTING_IP6_CONFIG_METHOD_AUTO,
3080 NM_SETTING_IP6_CONFIG_METHOD_DHCP,
3081 NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL,
3082 NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
3085 const char *assumable_ip4_methods[] = {
3086 NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
3087 NM_SETTING_IP6_CONFIG_METHOD_AUTO,
3088 NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
3092 if (!nm_device_can_assume_connections (self))
3095 connection = nm_device_get_applied_connection (self);
3099 /* Can't assume connections that aren't yet configured
3100 * FIXME: what about bridges/bonds waiting for slaves?
3102 if (priv->state < NM_DEVICE_STATE_IP_CONFIG)
3104 if (priv->ip4_state != IP_DONE && priv->ip6_state != IP_DONE)
3107 method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
3108 if (!_nm_utils_string_in_list (method, assumable_ip6_methods))
3111 method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
3112 if (!_nm_utils_string_in_list (method, assumable_ip4_methods))
3119 nm_device_emit_recheck_assume (gpointer user_data)
3121 NMDevice *self = user_data;
3122 NMDevicePrivate *priv;
3124 g_return_val_if_fail (NM_IS_DEVICE (self), G_SOURCE_REMOVE);
3126 priv = NM_DEVICE_GET_PRIVATE (self);
3128 priv->recheck_assume_id = 0;
3129 if (!nm_device_get_act_request (self)) {
3130 _LOGD (LOGD_DEVICE, "emit RECHECK_ASSUME signal");
3131 g_signal_emit (self, signals[RECHECK_ASSUME], 0);
3133 return G_SOURCE_REMOVE;
3137 nm_device_queue_recheck_assume (NMDevice *self)
3139 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
3141 if ( !priv->recheck_assume_id
3142 && nm_device_can_assume_connections (self))
3143 priv->recheck_assume_id = g_idle_add (nm_device_emit_recheck_assume, self);
3147 recheck_available (gpointer user_data)
3149 NMDevice *self = NM_DEVICE (user_data);
3150 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
3151 gboolean now_available = nm_device_is_available (self, NM_DEVICE_CHECK_DEV_AVAILABLE_NONE);
3152 NMDeviceState state = nm_device_get_state (self);
3153 NMDeviceState new_state = NM_DEVICE_STATE_UNKNOWN;
3155 priv->recheck_available.call_id = 0;
3157 if (state == NM_DEVICE_STATE_UNAVAILABLE && now_available) {
3158 new_state = NM_DEVICE_STATE_DISCONNECTED;
3159 nm_device_queue_state (self, new_state, priv->recheck_available.available_reason);
3160 } else if (state >= NM_DEVICE_STATE_DISCONNECTED && !now_available) {
3161 new_state = NM_DEVICE_STATE_UNAVAILABLE;
3162 nm_device_queue_state (self, new_state, priv->recheck_available.unavailable_reason);
3165 if (new_state > NM_DEVICE_STATE_UNKNOWN) {
3166 _LOGD (LOGD_DEVICE, "is %savailable, %s %s",
3167 now_available ? "" : "not ",
3168 new_state == NM_DEVICE_STATE_UNAVAILABLE ? "no change required for" : "will transition to",
3169 state_to_string (new_state == NM_DEVICE_STATE_UNAVAILABLE ? state : new_state));
3171 priv->recheck_available.available_reason = NM_DEVICE_STATE_REASON_NONE;
3172 priv->recheck_available.unavailable_reason = NM_DEVICE_STATE_REASON_NONE;
3175 return G_SOURCE_REMOVE;
3179 nm_device_queue_recheck_available (NMDevice *self,
3180 NMDeviceStateReason available_reason,
3181 NMDeviceStateReason unavailable_reason)
3183 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
3185 priv->recheck_available.available_reason = available_reason;
3186 priv->recheck_available.unavailable_reason = unavailable_reason;
3187 if (!priv->recheck_available.call_id)
3188 priv->recheck_available.call_id = g_idle_add (recheck_available, self);
3192 nm_device_emit_recheck_auto_activate (NMDevice *self)
3194 g_signal_emit (self, signals[RECHECK_AUTO_ACTIVATE], 0);
3198 dnsmasq_state_changed_cb (NMDnsMasqManager *manager, guint32 status, gpointer user_data)
3200 NMDevice *self = NM_DEVICE (user_data);
3203 case NM_DNSMASQ_STATUS_DEAD:
3204 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_SHARED_START_FAILED);
3211 /*****************************************************************************/
3214 activation_source_handle_cb4 (gpointer user_data)
3216 activation_source_handle_cb (user_data, AF_INET);
3217 return G_SOURCE_REMOVE;
3221 activation_source_handle_cb6 (gpointer user_data)
3223 activation_source_handle_cb (user_data, AF_INET6);
3224 return G_SOURCE_REMOVE;
3227 static ActivationHandleData *
3228 activation_source_get_by_family (NMDevice *self,
3230 GSourceFunc *out_idle_func)
3232 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
3234 if (family == AF_INET6) {
3235 NM_SET_OUT (out_idle_func, activation_source_handle_cb6);
3236 return &priv->act_handle6;
3238 NM_SET_OUT (out_idle_func, activation_source_handle_cb4);
3239 g_return_val_if_fail (family == AF_INET, &priv->act_handle4);
3240 return &priv->act_handle4;
3245 activation_source_clear (NMDevice *self, int family)
3247 ActivationHandleData *act_data;
3249 act_data = activation_source_get_by_family (self, family, NULL);
3252 _LOGD (LOGD_DEVICE, "activation-stage: clear %s,%d (id %u)",
3253 _activation_func_to_string (act_data->func), family, act_data->id);
3254 nm_clear_g_source (&act_data->id);
3255 act_data->func = NULL;
3260 activation_source_handle_cb (NMDevice *self, int family)
3262 ActivationHandleData *act_data, a;
3264 g_return_if_fail (NM_IS_DEVICE (self));
3266 act_data = activation_source_get_by_family (self, family, NULL);
3268 g_return_if_fail (act_data->id);
3269 g_return_if_fail (act_data->func);
3273 act_data->func = NULL;
3276 _LOGD (LOGD_DEVICE, "activation-stage: invoke %s,%d (id %u)",
3277 _activation_func_to_string (a.func), family, a.id);
3281 _LOGD (LOGD_DEVICE, "activation-stage: complete %s,%d (id %u)",
3282 _activation_func_to_string (a.func), family, a.id);
3286 activation_source_schedule (NMDevice *self, ActivationHandleFunc func, int family)
3288 ActivationHandleData *act_data;
3289 GSourceFunc source_func;
3292 act_data = activation_source_get_by_family (self, family, &source_func);
3294 if (act_data->id && act_data->func != func) {
3295 /* Don't bother rescheduling the same function that's about to
3296 * run anyway. Fixes issues with crappy wireless drivers sending
3297 * streams of associate events before NM has had a chance to process
3300 _LOGD (LOGD_DEVICE, "activation-stage: already scheduled %s,%d (id %u)",
3301 _activation_func_to_string (func), family, act_data->id);
3305 new_id = g_idle_add (source_func, self);
3308 _LOGW (LOGD_DEVICE, "activation-stage: schedule %s,%d which replaces %s,%d (id %u -> %u)",
3309 _activation_func_to_string (func), family,
3310 _activation_func_to_string (act_data->func), family,
3311 act_data->id, new_id);
3312 nm_clear_g_source (&act_data->id);
3314 _LOGD (LOGD_DEVICE, "activation-stage: schedule %s,%d (id %u)",
3315 _activation_func_to_string (func), family, new_id);
3318 act_data->func = func;
3319 act_data->id = new_id;
3322 /*****************************************************************************/
3325 get_ip_config_may_fail (NMDevice *self, int family)
3327 NMConnection *connection;
3328 NMSettingIPConfig *s_ip = NULL;
3330 g_return_val_if_fail (self != NULL, TRUE);
3332 connection = nm_device_get_applied_connection (self);
3333 g_assert (connection);
3335 /* Fail the connection if the failed IP method is required to complete */
3338 s_ip = nm_connection_get_setting_ip4_config (connection);
3341 s_ip = nm_connection_get_setting_ip6_config (connection);
3344 g_assert_not_reached ();
3347 return nm_setting_ip_config_get_may_fail (s_ip);
3351 master_ready (NMDevice *self,
3352 NMActiveConnection *active)
3354 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
3355 NMActiveConnection *master_connection;
3358 g_return_if_fail (priv->state == NM_DEVICE_STATE_PREPARE);
3359 g_return_if_fail (!priv->master_ready_handled);
3361 /* Notify a master device that it has a new slave */
3362 g_return_if_fail (nm_active_connection_get_master_ready (active));
3363 master_connection = nm_active_connection_get_master (active);
3365 priv->master_ready_handled = TRUE;
3366 nm_clear_g_signal_handler (active, &priv->master_ready_id);
3368 master = nm_active_connection_get_device (master_connection);
3370 _LOGD (LOGD_DEVICE, "master connection ready; master device %s",
3371 nm_device_get_iface (master));
3373 if (priv->master && priv->master != master)
3374 nm_device_master_release_one_slave (priv->master, self, FALSE, NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED);
3376 /* If the master didn't change, add-slave only rechecks whether to assume a connection. */
3377 nm_device_master_add_slave (master,
3379 nm_active_connection_get_assumed (active) ? FALSE : TRUE);
3383 master_ready_cb (NMActiveConnection *active,
3387 master_ready (self, active);
3388 nm_device_activate_schedule_stage2_device_config (self);
3392 lldp_neighbors_changed (NMLldpListener *lldp_listener, GParamSpec *pspec,
3395 NMDevice *self = NM_DEVICE (user_data);
3397 _notify (self, PROP_LLDP_NEIGHBORS);
3401 lldp_rx_enabled (NMDevice *self)
3403 NMConnection *connection;
3404 NMSettingConnection *s_con;
3405 NMSettingConnectionLldp lldp = NM_SETTING_CONNECTION_LLDP_DEFAULT;
3407 connection = nm_device_get_applied_connection (self);
3408 g_return_val_if_fail (connection, FALSE);
3410 s_con = nm_connection_get_setting_connection (connection);
3411 g_return_val_if_fail (s_con, FALSE);
3413 lldp = nm_setting_connection_get_lldp (s_con);
3414 if (lldp == NM_SETTING_CONNECTION_LLDP_DEFAULT) {
3415 gs_free char *value = NULL;
3417 value = nm_config_data_get_connection_default (NM_CONFIG_GET_DATA,
3420 lldp = _nm_utils_ascii_str_to_int64 (value, 10,
3421 NM_SETTING_CONNECTION_LLDP_DEFAULT,
3422 NM_SETTING_CONNECTION_LLDP_ENABLE_RX,
3423 NM_SETTING_CONNECTION_LLDP_DEFAULT);
3424 if (lldp == NM_SETTING_CONNECTION_LLDP_DEFAULT)
3425 lldp = NM_SETTING_CONNECTION_LLDP_DISABLE;
3427 return lldp == NM_SETTING_CONNECTION_LLDP_ENABLE_RX;
3430 static NMActStageReturn
3431 act_stage1_prepare (NMDevice *self, NMDeviceStateReason *reason)
3433 return NM_ACT_STAGE_RETURN_SUCCESS;
3437 * activate_stage1_device_prepare
3439 * Prepare for device activation
3443 activate_stage1_device_prepare (NMDevice *self)
3445 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
3446 NMActStageReturn ret = NM_ACT_STAGE_RETURN_SUCCESS;
3447 NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
3448 NMActiveConnection *active = NM_ACTIVE_CONNECTION (priv->act_request);
3450 priv->ip4_state = priv->ip6_state = IP_NONE;
3452 /* Notify the new ActiveConnection along with the state change */
3453 _notify (self, PROP_ACTIVE_CONNECTION);
3455 nm_device_state_changed (self, NM_DEVICE_STATE_PREPARE, NM_DEVICE_STATE_REASON_NONE);
3457 /* Assumed connections were already set up outside NetworkManager */
3458 if (!nm_active_connection_get_assumed (active)) {
3459 ret = NM_DEVICE_GET_CLASS (self)->act_stage1_prepare (self, &reason);
3460 if (ret == NM_ACT_STAGE_RETURN_POSTPONE) {
3462 } else if (ret == NM_ACT_STAGE_RETURN_FAILURE) {
3463 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, reason);
3466 g_assert (ret == NM_ACT_STAGE_RETURN_SUCCESS);
3469 nm_device_activate_schedule_stage2_device_config (self);
3474 * nm_device_activate_schedule_stage1_device_prepare
3476 * Prepare a device for activation
3480 nm_device_activate_schedule_stage1_device_prepare (NMDevice *self)
3482 NMDevicePrivate *priv;
3484 g_return_if_fail (NM_IS_DEVICE (self));
3486 priv = NM_DEVICE_GET_PRIVATE (self);
3487 g_return_if_fail (priv->act_request);
3489 activation_source_schedule (self, activate_stage1_device_prepare, AF_INET);
3492 static NMActStageReturn
3493 act_stage2_config (NMDevice *self, NMDeviceStateReason *reason)
3496 return NM_ACT_STAGE_RETURN_SUCCESS;
3500 * activate_stage2_device_config
3502 * Determine device parameters and set those on the device, ie
3503 * for wireless devices, set SSID, keys, etc.
3507 activate_stage2_device_config (NMDevice *self)
3509 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
3510 NMActStageReturn ret;
3511 NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
3512 gboolean no_firmware = FALSE;
3513 NMActiveConnection *active = NM_ACTIVE_CONNECTION (priv->act_request);
3516 nm_device_state_changed (self, NM_DEVICE_STATE_CONFIG, NM_DEVICE_STATE_REASON_NONE);
3518 /* Assumed connections were already set up outside NetworkManager */
3519 if (!nm_active_connection_get_assumed (active)) {
3520 if (!nm_device_bring_up (self, FALSE, &no_firmware)) {
3522 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_FIRMWARE_MISSING);
3524 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_CONFIG_FAILED);
3528 ret = NM_DEVICE_GET_CLASS (self)->act_stage2_config (self, &reason);
3529 if (ret == NM_ACT_STAGE_RETURN_POSTPONE)
3531 else if (ret == NM_ACT_STAGE_RETURN_FAILURE) {
3532 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, reason);
3535 g_assert (ret == NM_ACT_STAGE_RETURN_SUCCESS);
3538 /* If we have slaves that aren't yet enslaved, do that now */
3539 for (iter = priv->slaves; iter; iter = g_slist_next (iter)) {
3540 SlaveInfo *info = iter->data;
3541 NMDeviceState slave_state = nm_device_get_state (info->slave);
3543 if (slave_state == NM_DEVICE_STATE_IP_CONFIG)
3544 nm_device_master_enslave_slave (self, info->slave, nm_device_get_applied_connection (info->slave));
3545 else if ( nm_device_uses_generated_assumed_connection (self)
3546 && slave_state <= NM_DEVICE_STATE_DISCONNECTED)
3547 nm_device_queue_recheck_assume (info->slave);
3550 if (lldp_rx_enabled (self)) {
3551 gs_free_error GError *error = NULL;
3555 if (priv->lldp_listener)
3556 nm_lldp_listener_stop (priv->lldp_listener);
3558 priv->lldp_listener = nm_lldp_listener_new ();
3559 g_signal_connect (priv->lldp_listener,
3560 "notify::" NM_LLDP_LISTENER_NEIGHBORS,
3561 G_CALLBACK (lldp_neighbors_changed),
3565 addr = nm_platform_link_get_address (NM_PLATFORM_GET, priv->ifindex, &addr_length);
3567 if (nm_lldp_listener_start (priv->lldp_listener, nm_device_get_ifindex (self), &error))
3568 _LOGD (LOGD_DEVICE, "LLDP listener %p started", priv->lldp_listener);
3570 _LOGD (LOGD_DEVICE, "LLDP listener %p could not be started: %s",
3571 priv->lldp_listener, error->message);
3575 nm_device_activate_schedule_stage3_ip_config_start (self);
3580 * nm_device_activate_schedule_stage2_device_config
3582 * Schedule setup of the hardware device
3586 nm_device_activate_schedule_stage2_device_config (NMDevice *self)
3588 NMDevicePrivate *priv;
3590 g_return_if_fail (NM_IS_DEVICE (self));
3592 priv = NM_DEVICE_GET_PRIVATE (self);
3593 g_return_if_fail (priv->act_request);
3595 if (!priv->master_ready_handled) {
3596 NMActiveConnection *active = NM_ACTIVE_CONNECTION (priv->act_request);
3598 if (!nm_active_connection_get_master (active)) {
3599 g_warn_if_fail (!priv->master_ready_id);
3600 priv->master_ready_handled = TRUE;
3602 /* If the master connection is ready for slaves, attach ourselves */
3603 if (nm_active_connection_get_master_ready (active))
3604 master_ready (self, active);
3606 _LOGD (LOGD_DEVICE, "waiting for master connection to become ready");
3608 if (priv->master_ready_id == 0) {
3609 priv->master_ready_id = g_signal_connect (active,
3610 "notify::" NM_ACTIVE_CONNECTION_INT_MASTER_READY,
3611 (GCallback) master_ready_cb,
3620 activation_source_schedule (self, activate_stage2_device_config, AF_INET);
3626 * Progress the device to appropriate state if both IPv4 and IPv6 failed
3629 check_ip_failed (NMDevice *self, gboolean may_fail)
3631 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
3632 NMDeviceState state;
3634 if ( priv->ip4_state != IP_FAIL
3635 || priv->ip6_state != IP_FAIL)
3638 if (nm_device_uses_assumed_connection (self)) {
3639 /* We have assumed configuration, but couldn't
3640 * redo it. No problem, move to check state. */
3641 priv->ip4_state = priv->ip6_state = IP_DONE;
3642 state = NM_DEVICE_STATE_IP_CHECK;
3643 } else if ( may_fail
3644 && get_ip_config_may_fail (self, AF_INET)
3645 && get_ip_config_may_fail (self, AF_INET6)) {
3646 /* Couldn't start either IPv6 and IPv4 autoconfiguration,
3647 * but both are allowed to fail. */
3648 state = NM_DEVICE_STATE_SECONDARIES;
3650 /* Autoconfiguration attempted without success. */
3651 state = NM_DEVICE_STATE_FAILED;
3654 nm_device_state_changed (self,
3656 NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE);
3662 * Progress the device to ip connectivity check state if IPv4 or IPv6 succeeded
3665 check_ip_done (NMDevice *self)
3667 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
3669 if (nm_device_get_state (self) != NM_DEVICE_STATE_IP_CONFIG)
3672 if (priv->ip4_state != IP_DONE && !get_ip_config_may_fail (self, AF_INET))
3675 if (priv->ip6_state != IP_DONE && !get_ip_config_may_fail (self, AF_INET6))
3678 nm_device_state_changed (self, NM_DEVICE_STATE_IP_CHECK, NM_DEVICE_STATE_REASON_NONE);
3681 /*********************************************/
3682 /* IPv4 DAD stuff */
3685 get_ipv4_dad_timeout (NMDevice *self)
3687 NMConnection *connection;
3688 NMSettingIPConfig *s_ip4 = NULL;
3689 gs_free char *value = NULL;
3692 connection = nm_device_get_applied_connection (self);
3694 s_ip4 = nm_connection_get_setting_ip4_config (connection);
3697 ret = nm_setting_ip_config_get_dad_timeout (s_ip4);
3700 value = nm_config_data_get_connection_default (NM_CONFIG_GET_DATA,
3701 "ipv4.dad-timeout", self);
3702 ret = _nm_utils_ascii_str_to_int64 (value, 10, -1,
3703 NM_SETTING_IP_CONFIG_DAD_TIMEOUT_MAX,
3705 ret = ret < 0 ? 0 : ret;
3713 arping_data_destroy (gpointer ptr, GClosure *closure)
3715 ArpingData *data = ptr;
3719 for (i = 0; data->configs && data->configs[i]; i++)
3720 g_object_unref (data->configs[i]);
3721 g_free (data->configs);
3722 g_slice_free (ArpingData, data);
3727 ipv4_manual_method_apply (NMDevice *self, NMIP4Config **configs, gboolean success)
3732 empty = nm_ip4_config_new (nm_device_get_ip_ifindex (self));
3733 nm_device_activate_schedule_ip4_config_result (self, empty);
3734 g_object_unref (empty);
3736 nm_device_queue_state (self, NM_DEVICE_STATE_FAILED,
3737 NM_DEVICE_STATE_REASON_CONFIG_FAILED);
3742 arping_manager_probe_terminated (NMArpingManager *arping_manager, ArpingData *data)
3745 NMDevicePrivate *priv;
3746 const NMPlatformIP4Address *address;
3747 gboolean result, success = TRUE;
3751 self = data->device;
3752 priv = NM_DEVICE_GET_PRIVATE (self);
3754 for (i = 0; data->configs && data->configs[i]; i++) {
3755 for (j = 0; j < nm_ip4_config_get_num_addresses (data->configs[i]); j++) {
3756 address = nm_ip4_config_get_address (data->configs[i], j);
3757 result = nm_arping_manager_check_address (arping_manager, address->address);
3760 _NMLOG (result ? LOGL_DEBUG : LOGL_WARN,
3762 "IPv4 DAD result: address %s is %s",
3763 nm_utils_inet4_ntop (address->address, NULL),
3764 result ? "unique" : "duplicate");
3768 data->callback (self, data->configs, success);
3770 priv->arping.dad_list = g_slist_remove (priv->arping.dad_list, arping_manager);
3771 nm_arping_manager_destroy (arping_manager);
3776 * @self: device instance
3777 * @configs: NULL-terminated array of IPv4 configurations
3778 * @cb: callback function
3780 * Start IPv4 DAD on device @self, check addresses in @configs and call @cb
3781 * when the procedure ends. @cb will be called in any case, even if DAD can't
3782 * be started. @configs will be unreferenced after @cb has been called.
3785 ipv4_dad_start (NMDevice *self, NMIP4Config **configs, ArpingCallback cb)
3787 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
3788 NMArpingManager *arping_manager;
3789 const NMPlatformIP4Address *address;
3792 gboolean ret, addr_found;
3793 const guint8 *hw_addr;
3794 size_t hw_addr_len = 0;
3795 GError *error = NULL;
3798 g_return_if_fail (NM_IS_DEVICE (self));
3799 g_return_if_fail (configs);
3800 g_return_if_fail (cb);
3802 for (i = 0, addr_found = FALSE; configs[i]; i++) {
3803 if (nm_ip4_config_get_num_addresses (configs[i]) > 0) {
3809 timeout = get_ipv4_dad_timeout (self);
3810 hw_addr = nm_platform_link_get_address (NM_PLATFORM_GET,
3811 nm_device_get_ip_ifindex (self),
3818 || nm_device_uses_assumed_connection (self)) {
3820 /* DAD not needed, signal success */
3821 cb (self, configs, TRUE);
3823 for (i = 0; configs[i]; i++)
3824 g_object_unref (configs[i]);
3830 /* don't take additional references of @arping_manager that outlive @self.
3831 * Otherwise, the callback can be invoked on a dangling pointer as we don't
3832 * disconnect the handler. */
3833 arping_manager = nm_arping_manager_new (nm_device_get_ip_ifindex (self));
3834 priv->arping.dad_list = g_slist_append (priv->arping.dad_list, arping_manager);
3836 data = g_slice_new0 (ArpingData);
3837 data->configs = configs;
3838 data->callback = cb;
3839 data->device = self;
3841 for (i = 0; configs[i]; i++) {
3842 for (j = 0; j < nm_ip4_config_get_num_addresses (configs[i]); j++) {
3843 address = nm_ip4_config_get_address (configs[i], j);
3844 nm_arping_manager_add_address (arping_manager, address->address);
3848 g_signal_connect_data (arping_manager, NM_ARPING_MANAGER_PROBE_TERMINATED,
3849 G_CALLBACK (arping_manager_probe_terminated), data,
3850 arping_data_destroy, 0);
3852 ret = nm_arping_manager_start_probe (arping_manager, timeout, &error);
3855 _LOGW (LOGD_DEVICE, "arping probe failed: %s", error->message);
3857 /* DAD could not be started, signal success */
3858 cb (self, configs, TRUE);
3860 priv->arping.dad_list = g_slist_remove (priv->arping.dad_list, arping_manager);
3861 nm_arping_manager_destroy (arping_manager);
3865 /*********************************************/
3869 ipv4ll_cleanup (NMDevice *self)
3871 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
3874 sd_ipv4ll_set_callback (priv->ipv4ll, NULL, NULL);
3875 sd_ipv4ll_stop (priv->ipv4ll);
3876 priv->ipv4ll = sd_ipv4ll_unref (priv->ipv4ll);
3879 nm_clear_g_source (&priv->ipv4ll_timeout);
3882 static NMIP4Config *
3883 ipv4ll_get_ip4_config (NMDevice *self, guint32 lla)
3885 NMIP4Config *config = NULL;
3886 NMPlatformIP4Address address;
3887 NMPlatformIP4Route route;
3889 config = nm_ip4_config_new (nm_device_get_ip_ifindex (self));
3892 memset (&address, 0, sizeof (address));
3893 nm_platform_ip4_address_set_addr (&address, lla, 16);
3894 address.source = NM_IP_CONFIG_SOURCE_IP4LL;
3895 nm_ip4_config_add_address (config, &address);
3897 /* Add a multicast route for link-local connections: destination= 224.0.0.0, netmask=240.0.0.0 */
3898 memset (&route, 0, sizeof (route));
3899 route.network = htonl (0xE0000000L);
3901 route.source = NM_IP_CONFIG_SOURCE_IP4LL;
3902 route.metric = nm_device_get_ip4_route_metric (self);
3903 nm_ip4_config_add_route (config, &route);
3908 #define IPV4LL_NETWORK (htonl (0xA9FE0000L))
3909 #define IPV4LL_NETMASK (htonl (0xFFFF0000L))
3912 nm_device_handle_ipv4ll_event (sd_ipv4ll *ll, int event, void *data)
3914 NMDevice *self = data;
3915 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
3916 NMConnection *connection = NULL;
3918 struct in_addr address;
3919 NMIP4Config *config;
3922 if (priv->act_request == NULL)
3925 connection = nm_act_request_get_applied_connection (priv->act_request);
3926 g_assert (connection);
3928 /* Ignore if the connection isn't an AutoIP connection */
3929 method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
3930 if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL) != 0)
3934 case SD_IPV4LL_EVENT_BIND:
3935 r = sd_ipv4ll_get_address (ll, &address);
3937 _LOGE (LOGD_AUTOIP4, "invalid IPv4 link-local address received, error %d.", r);
3938 priv->ip4_state = IP_FAIL;
3939 check_ip_failed (self, FALSE);
3943 if ((address.s_addr & IPV4LL_NETMASK) != IPV4LL_NETWORK) {
3944 _LOGE (LOGD_AUTOIP4, "invalid address %08x received (not link-local).", address.s_addr);
3945 priv->ip4_state = IP_FAIL;
3946 check_ip_failed (self, FALSE);
3950 config = ipv4ll_get_ip4_config (self, address.s_addr);
3951 if (config == NULL) {
3952 _LOGE (LOGD_AUTOIP4, "failed to get IPv4LL config");
3953 priv->ip4_state = IP_FAIL;
3954 check_ip_failed (self, FALSE);
3958 if (priv->ip4_state == IP_CONF) {
3959 nm_clear_g_source (&priv->ipv4ll_timeout);
3960 nm_device_activate_schedule_ip4_config_result (self, config);
3961 } else if (priv->ip4_state == IP_DONE) {
3962 if (!ip4_config_merge_and_apply (self, config, TRUE, NULL)) {
3963 _LOGE (LOGD_AUTOIP4, "failed to update IP4 config for autoip change.");
3964 priv->ip4_state = IP_FAIL;
3965 check_ip_failed (self, FALSE);
3968 g_assert_not_reached ();
3970 g_object_unref (config);
3973 _LOGW (LOGD_AUTOIP4, "IPv4LL address no longer valid after event %d.", event);
3974 priv->ip4_state = IP_FAIL;
3975 check_ip_failed (self, FALSE);
3980 ipv4ll_timeout_cb (gpointer user_data)
3982 NMDevice *self = NM_DEVICE (user_data);
3983 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
3985 if (priv->ipv4ll_timeout) {
3986 _LOGI (LOGD_AUTOIP4, "IPv4LL configuration timed out.");
3987 priv->ipv4ll_timeout = 0;
3988 ipv4ll_cleanup (self);
3990 if (priv->ip4_state == IP_CONF)
3991 nm_device_activate_schedule_ip4_config_timeout (self);
3997 static NMActStageReturn
3998 ipv4ll_start (NMDevice *self, NMDeviceStateReason *reason)
4000 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
4001 const struct ether_addr *addr;
4005 ipv4ll_cleanup (self);
4007 r = sd_ipv4ll_new (&priv->ipv4ll);
4009 _LOGE (LOGD_AUTOIP4, "IPv4LL: new() failed with error %d", r);
4013 r = sd_ipv4ll_attach_event (priv->ipv4ll, NULL, 0);
4015 _LOGE (LOGD_AUTOIP4, "IPv4LL: attach_event() failed with error %d", r);
4019 ifindex = nm_device_get_ip_ifindex (self);
4020 addr = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, &addr_len);
4021 if (!addr || addr_len != ETH_ALEN) {
4022 _LOGE (LOGD_AUTOIP4, "IPv4LL: can't retrieve hardware address");
4026 r = sd_ipv4ll_set_mac (priv->ipv4ll, addr);
4028 _LOGE (LOGD_AUTOIP4, "IPv4LL: set_mac() failed with error %d", r);
4032 r = sd_ipv4ll_set_index (priv->ipv4ll, ifindex);
4034 _LOGE (LOGD_AUTOIP4, "IPv4LL: set_index() failed with error %d", r);
4038 r = sd_ipv4ll_set_callback (priv->ipv4ll, nm_device_handle_ipv4ll_event, self);
4040 _LOGE (LOGD_AUTOIP4, "IPv4LL: set_callback() failed with error %d", r);
4044 r = sd_ipv4ll_start (priv->ipv4ll);
4046 _LOGE (LOGD_AUTOIP4, "IPv4LL: start() failed with error %d", r);
4050 _LOGI (LOGD_DEVICE | LOGD_AUTOIP4, "IPv4LL: started");
4052 /* Start a timeout to bound the address attempt */
4053 priv->ipv4ll_timeout = g_timeout_add_seconds (20, ipv4ll_timeout_cb, self);
4055 return NM_ACT_STAGE_RETURN_POSTPONE;
4057 *reason = NM_DEVICE_STATE_REASON_AUTOIP_START_FAILED;
4058 return NM_ACT_STAGE_RETURN_FAILURE;
4061 /*********************************************/
4064 _device_get_default_route_from_platform (NMDevice *self, int addr_family, NMPlatformIPRoute *out_route)
4066 gboolean success = FALSE;
4067 int ifindex = nm_device_get_ip_ifindex (self);
4070 if (addr_family == AF_INET)
4071 routes = nm_platform_ip4_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT);
4073 routes = nm_platform_ip6_route_get_all (NM_PLATFORM_GET, ifindex, NM_PLATFORM_GET_ROUTE_FLAGS_WITH_DEFAULT);
4076 guint route_metric = G_MAXUINT32, m;
4077 const NMPlatformIPRoute *route = NULL, *r;
4080 /* if there are several default routes, find the one with the best metric */
4081 for (i = 0; i < routes->len; i++) {
4082 if (addr_family == AF_INET) {
4083 r = (const NMPlatformIPRoute *) &g_array_index (routes, NMPlatformIP4Route, i);
4086 r = (const NMPlatformIPRoute *) &g_array_index (routes, NMPlatformIP6Route, i);
4087 m = nm_utils_ip6_route_metric_normalize (r->metric);
4089 if (!route || m < route_metric) {
4096 if (addr_family == AF_INET)
4097 *((NMPlatformIP4Route *) out_route) = *((NMPlatformIP4Route *) route);
4099 *((NMPlatformIP6Route *) out_route) = *((NMPlatformIP6Route *) route);
4102 g_array_free (routes, TRUE);
4107 /*********************************************/
4110 ensure_con_ip4_config (NMDevice *self)
4112 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
4113 int ip_ifindex = nm_device_get_ip_ifindex (self);
4114 NMConnection *connection;
4116 if (priv->con_ip4_config)
4119 connection = nm_device_get_applied_connection (self);
4123 priv->con_ip4_config = nm_ip4_config_new (ip_ifindex);
4124 nm_ip4_config_merge_setting (priv->con_ip4_config,
4125 nm_connection_get_setting_ip4_config (connection),
4126 nm_device_get_ip4_route_metric (self));
4128 if (nm_device_uses_assumed_connection (self)) {
4129 /* For assumed connections ignore all addresses and routes. */
4130 nm_ip4_config_reset_addresses (priv->con_ip4_config);
4131 nm_ip4_config_reset_routes (priv->con_ip4_config);
4136 ensure_con_ip6_config (NMDevice *self)
4138 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
4139 int ip_ifindex = nm_device_get_ip_ifindex (self);
4140 NMConnection *connection;
4142 if (priv->con_ip6_config)
4145 connection = nm_device_get_applied_connection (self);
4149 priv->con_ip6_config = nm_ip6_config_new (ip_ifindex);
4150 nm_ip6_config_merge_setting (priv->con_ip6_config,
4151 nm_connection_get_setting_ip6_config (connection),
4152 nm_device_get_ip6_route_metric (self));
4154 if (nm_device_uses_assumed_connection (self)) {
4155 /* For assumed connections ignore all addresses and routes. */
4156 nm_ip6_config_reset_addresses (priv->con_ip6_config);
4157 nm_ip6_config_reset_routes (priv->con_ip6_config);
4161 /*********************************************/
4165 dhcp4_cleanup (NMDevice *self, CleanupType cleanup_type, gboolean release)
4167 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
4169 nm_clear_g_source (&priv->dhcp4_restart_id);
4171 if (priv->dhcp4_client) {
4172 /* Stop any ongoing DHCP transaction on this device */
4173 nm_clear_g_signal_handler (priv->dhcp4_client, &priv->dhcp4_state_sigid);
4175 nm_device_remove_pending_action (self, PENDING_ACTION_DHCP4, FALSE);
4177 if ( cleanup_type == CLEANUP_TYPE_DECONFIGURE
4178 || cleanup_type == CLEANUP_TYPE_REMOVED)
4179 nm_dhcp_client_stop (priv->dhcp4_client, release);
4181 g_clear_object (&priv->dhcp4_client);
4184 if (priv->dhcp4_config) {
4185 nm_exported_object_clear_and_unexport (&priv->dhcp4_config);
4186 _notify (self, PROP_DHCP4_CONFIG);
4191 _ip4_config_merge_default (gpointer value, gpointer user_data)
4193 NMIP4Config *src = (NMIP4Config *) value;
4194 NMIP4Config *dst = (NMIP4Config *) user_data;
4196 nm_ip4_config_merge (dst, src, NM_IP_CONFIG_MERGE_DEFAULT);
4200 ip4_config_merge_and_apply (NMDevice *self,
4201 NMIP4Config *config,
4203 NMDeviceStateReason *out_reason)
4205 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
4206 NMConnection *connection;
4208 NMIP4Config *composite;
4209 gboolean has_direct_route;
4210 const guint32 default_route_metric = nm_device_get_ip4_route_metric (self);
4212 gboolean connection_has_default_route, connection_is_never_default;
4213 gboolean routes_full_sync;
4214 gboolean ignore_auto_routes = FALSE;
4215 gboolean ignore_auto_dns = FALSE;
4217 /* Merge all the configs into the composite config */
4219 g_clear_object (&priv->dev_ip4_config);
4220 priv->dev_ip4_config = g_object_ref (config);
4223 /* Apply ignore-auto-routes and ignore-auto-dns settings */
4224 connection = nm_device_get_applied_connection (self);
4226 NMSettingIPConfig *s_ip4 = nm_connection_get_setting_ip4_config (connection);
4229 ignore_auto_routes = nm_setting_ip_config_get_ignore_auto_routes (s_ip4);
4230 ignore_auto_dns = nm_setting_ip_config_get_ignore_auto_dns (s_ip4);
4234 composite = nm_ip4_config_new (nm_device_get_ip_ifindex (self));
4237 ensure_con_ip4_config (self);
4239 if (priv->dev_ip4_config) {
4240 nm_ip4_config_merge (composite, priv->dev_ip4_config,
4241 (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0)
4242 | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0));
4245 g_slist_foreach (priv->vpn4_configs, _ip4_config_merge_default, composite);
4247 if (priv->ext_ip4_config)
4248 nm_ip4_config_merge (composite, priv->ext_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT);
4250 /* Merge WWAN config *last* to ensure modem-given settings overwrite
4251 * any external stuff set by pppd or other scripts.
4253 if (priv->wwan_ip4_config) {
4254 nm_ip4_config_merge (composite, priv->wwan_ip4_config,
4255 (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0)
4256 | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0));
4259 /* Merge user overrides into the composite config. For assumed connections,
4260 * con_ip4_config is empty. */
4261 if (priv->con_ip4_config)
4262 nm_ip4_config_merge (composite, priv->con_ip4_config, NM_IP_CONFIG_MERGE_DEFAULT);
4264 /* Add the default route.
4266 * We keep track of the default route of a device in a private field.
4267 * NMDevice needs to know the default route at this point, because the gateway
4268 * might require a direct route (see below).
4270 * But also, we don't want to add the default route to priv->ip4_config,
4271 * because the default route from the setting might not be the same that
4272 * NMDefaultRouteManager eventually configures (because the it might
4273 * tweak the effective metric).
4276 /* unless we come to a different conclusion below, we have no default route and
4277 * the route is assumed. */
4278 priv->default_route.v4_has = FALSE;
4279 priv->default_route.v4_is_assumed = TRUE;
4282 /* during a non-commit event, we always pickup whatever is configured. */
4283 goto END_ADD_DEFAULT_ROUTE;
4286 if (nm_device_uses_generated_assumed_connection (self)) {
4287 /* a generate-assumed-connection always detects the default route from platform */
4288 goto END_ADD_DEFAULT_ROUTE;
4291 /* At this point, we treat assumed and non-assumed connections alike.
4292 * For assumed connections we do that because we still manage RA and DHCP
4293 * leases for them, so we must extend/update the default route on commits.
4296 connection_has_default_route
4297 = nm_default_route_manager_ip4_connection_has_default_route (nm_default_route_manager_get (),
4298 connection, &connection_is_never_default);
4300 if ( !priv->v4_commit_first_time
4301 && connection_is_never_default) {
4302 /* If the connection is explicitly configured as never-default, we enforce the (absence of the)
4303 * default-route only once. That allows the user to configure a connection as never-default,
4304 * but he can add default routes externally (via a dispatcher script) and NM will not interfere. */
4305 goto END_ADD_DEFAULT_ROUTE;
4308 /* we are about to commit (for a non-assumed connection). Enforce whatever we have
4310 priv->default_route.v4_is_assumed = FALSE;
4312 if (!connection_has_default_route)
4313 goto END_ADD_DEFAULT_ROUTE;
4315 if (!nm_ip4_config_get_num_addresses (composite)) {
4316 /* without addresses we can have no default route. */
4317 goto END_ADD_DEFAULT_ROUTE;
4320 gateway = nm_ip4_config_get_gateway (composite);
4321 if ( !nm_ip4_config_has_gateway (composite)
4322 && nm_device_get_device_type (self) != NM_DEVICE_TYPE_MODEM)
4323 goto END_ADD_DEFAULT_ROUTE;
4325 has_direct_route = ( gateway == 0
4326 || nm_ip4_config_destination_is_direct (composite, gateway, 32)
4327 || nm_ip4_config_get_direct_route_for_host (composite, gateway));
4329 priv->default_route.v4_has = TRUE;
4330 memset (&priv->default_route.v4, 0, sizeof (priv->default_route.v4));
4331 priv->default_route.v4.source = NM_IP_CONFIG_SOURCE_USER;
4332 priv->default_route.v4.gateway = gateway;
4333 priv->default_route.v4.metric = default_route_metric;
4334 priv->default_route.v4.mss = nm_ip4_config_get_mss (composite);
4336 if (!has_direct_route) {
4337 NMPlatformIP4Route r = priv->default_route.v4;
4339 /* add a direct route to the gateway */
4340 r.network = gateway;
4343 nm_ip4_config_add_route (composite, &r);
4346 END_ADD_DEFAULT_ROUTE:
4348 if (priv->default_route.v4_is_assumed) {
4349 /* If above does not explicitly assign a default route, we always pick up the
4350 * default route based on what is currently configured.
4351 * That means that even managed connections with never-default, can
4352 * get a default route (if configured externally).
4354 priv->default_route.v4_has = _device_get_default_route_from_platform (self, AF_INET, (NMPlatformIPRoute *) &priv->default_route.v4);
4357 nm_ip4_config_addresses_sort (composite);
4359 /* Allow setting MTU etc */
4361 if (NM_DEVICE_GET_CLASS (self)->ip4_config_pre_commit)
4362 NM_DEVICE_GET_CLASS (self)->ip4_config_pre_commit (self, composite);
4365 routes_full_sync = commit
4366 && priv->v4_commit_first_time
4367 && !nm_device_uses_assumed_connection (self);
4369 success = nm_device_set_ip4_config (self, composite, default_route_metric, commit, routes_full_sync, out_reason);
4370 g_object_unref (composite);
4373 priv->v4_commit_first_time = FALSE;
4378 dhcp4_lease_change (NMDevice *self, NMIP4Config *config)
4380 NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
4382 g_return_if_fail (config != NULL);
4384 if (!ip4_config_merge_and_apply (self, config, TRUE, &reason)) {
4385 _LOGW (LOGD_DHCP4, "failed to update IPv4 config for DHCP change.");
4386 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, reason);
4388 /* Notify dispatcher scripts of new DHCP4 config */
4389 nm_dispatcher_call (DISPATCHER_ACTION_DHCP4_CHANGE,
4390 nm_device_get_settings_connection (self),
4391 nm_device_get_applied_connection (self),
4400 dhcp4_restart_cb (gpointer user_data)
4402 NMDevice *self = user_data;
4403 NMDevicePrivate *priv;
4404 NMDeviceStateReason reason;
4405 NMConnection *connection;
4407 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
4409 priv = NM_DEVICE_GET_PRIVATE (self);
4410 priv->dhcp4_restart_id = 0;
4411 connection = nm_device_get_applied_connection (self);
4413 if (dhcp4_start (self, connection, &reason) == NM_ACT_STAGE_RETURN_FAILURE)
4414 priv->dhcp4_restart_id = g_timeout_add_seconds (120, dhcp4_restart_cb, self);
4420 dhcp4_fail (NMDevice *self, gboolean timeout)
4422 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
4424 dhcp4_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE);
4426 /* Don't fail if there are static addresses configured on
4427 * the device, instead retry after some time.
4429 if ( priv->ip4_state == IP_DONE
4430 && priv->con_ip4_config
4431 && nm_ip4_config_get_num_addresses (priv->con_ip4_config) > 0) {
4432 _LOGI (LOGD_DHCP4, "Scheduling DHCPv4 restart because device has IP addresses");
4433 priv->dhcp4_restart_id = g_timeout_add_seconds (120, dhcp4_restart_cb, self);
4437 /* Instead of letting an assumed connection fail (which means that the
4438 * device will transition to the ACTIVATED state without IP configuration),
4441 if (nm_device_uses_assumed_connection (self)) {
4442 _LOGI (LOGD_DHCP4, "Scheduling DHCPv4 restart because the connection is assumed");
4443 priv->dhcp4_restart_id = g_timeout_add_seconds (120, dhcp4_restart_cb, self);
4447 if (timeout || (priv->ip4_state == IP_CONF))
4448 nm_device_activate_schedule_ip4_config_timeout (self);
4449 else if (priv->ip4_state == IP_DONE)
4450 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED);
4452 g_warn_if_reached ();
4456 dhcp4_dad_cb (NMDevice *self, NMIP4Config **configs, gboolean success)
4459 nm_device_activate_schedule_ip4_config_result (self, configs[1]);
4461 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED,
4462 NM_DEVICE_STATE_REASON_CONFIG_FAILED);
4467 dhcp4_state_changed (NMDhcpClient *client,
4469 NMIP4Config *ip4_config,
4470 GHashTable *options,
4471 const char *event_id,
4474 NMDevice *self = NM_DEVICE (user_data);
4475 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
4476 NMIP4Config *manual, **configs;
4477 NMConnection *connection;
4479 g_return_if_fail (nm_dhcp_client_get_ipv6 (client) == FALSE);
4480 g_return_if_fail (!ip4_config || NM_IS_IP4_CONFIG (ip4_config));
4482 _LOGD (LOGD_DHCP4, "new DHCPv4 client state %d", state);
4485 case NM_DHCP_STATE_BOUND:
4487 _LOGW (LOGD_DHCP4, "failed to get IPv4 config in response to DHCP event.");
4488 nm_device_state_changed (self,
4489 NM_DEVICE_STATE_FAILED,
4490 NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE);
4494 nm_dhcp4_config_set_options (priv->dhcp4_config, options);
4495 _notify (self, PROP_DHCP4_CONFIG);
4497 if (priv->ip4_state == IP_CONF) {
4498 connection = nm_device_get_applied_connection (self);
4499 g_assert (connection);
4501 manual = nm_ip4_config_new (nm_device_get_ip_ifindex (self));
4502 nm_ip4_config_merge_setting (manual,
4503 nm_connection_get_setting_ip4_config (connection),
4504 nm_device_get_ip4_route_metric (self));
4506 configs = g_new0 (NMIP4Config *, 3);
4507 configs[0] = manual;
4508 configs[1] = g_object_ref (ip4_config);
4510 ipv4_dad_start (self, configs, dhcp4_dad_cb);
4511 } else if (priv->ip4_state == IP_DONE) {
4512 dhcp4_lease_change (self, ip4_config);
4513 nm_device_update_metered (self);
4516 case NM_DHCP_STATE_TIMEOUT:
4517 dhcp4_fail (self, TRUE);
4519 case NM_DHCP_STATE_EXPIRE:
4520 /* Ignore expiry before we even have a lease (NAK, old lease, etc) */
4521 if (priv->ip4_state == IP_CONF)
4524 case NM_DHCP_STATE_DONE:
4525 case NM_DHCP_STATE_FAIL:
4526 dhcp4_fail (self, FALSE);
4534 dhcp4_get_timeout (NMDevice *self, NMSettingIP4Config *s_ip4)
4536 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
4537 gs_free char *value = NULL;
4540 timeout = nm_setting_ip_config_get_dhcp_timeout (NM_SETTING_IP_CONFIG (s_ip4));
4544 value = nm_config_data_get_connection_default (NM_CONFIG_GET_DATA,
4545 "ipv4.dhcp-timeout",
4547 timeout = _nm_utils_ascii_str_to_int64 (value, 10,
4552 return priv->dhcp_timeout;
4555 static NMActStageReturn
4556 dhcp4_start (NMDevice *self,
4557 NMConnection *connection,
4558 NMDeviceStateReason *reason)
4560 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
4561 NMSettingIPConfig *s_ip4;
4562 const guint8 *hw_addr;
4563 size_t hw_addr_len = 0;
4564 GByteArray *tmp = NULL;
4566 s_ip4 = nm_connection_get_setting_ip4_config (connection);
4568 /* Clear old exported DHCP options */
4569 nm_exported_object_clear_and_unexport (&priv->dhcp4_config);
4570 priv->dhcp4_config = nm_dhcp4_config_new ();
4572 hw_addr = nm_platform_link_get_address (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self), &hw_addr_len);
4574 tmp = g_byte_array_sized_new (hw_addr_len);
4575 g_byte_array_append (tmp, hw_addr, hw_addr_len);
4578 /* Begin DHCP on the interface */
4579 g_warn_if_fail (priv->dhcp4_client == NULL);
4580 priv->dhcp4_client = nm_dhcp_manager_start_ip4 (nm_dhcp_manager_get (),
4581 nm_device_get_ip_iface (self),
4582 nm_device_get_ip_ifindex (self),
4584 nm_connection_get_uuid (connection),
4585 nm_device_get_ip4_route_metric (self),
4586 nm_setting_ip_config_get_dhcp_send_hostname (s_ip4),
4587 nm_setting_ip_config_get_dhcp_hostname (s_ip4),
4588 nm_setting_ip4_config_get_dhcp_fqdn (NM_SETTING_IP4_CONFIG (s_ip4)),
4589 nm_setting_ip4_config_get_dhcp_client_id (NM_SETTING_IP4_CONFIG (s_ip4)),
4590 dhcp4_get_timeout (self, NM_SETTING_IP4_CONFIG (s_ip4)),
4591 priv->dhcp_anycast_address,
4595 g_byte_array_free (tmp, TRUE);
4597 if (!priv->dhcp4_client) {
4598 *reason = NM_DEVICE_STATE_REASON_DHCP_START_FAILED;
4599 return NM_ACT_STAGE_RETURN_FAILURE;
4602 priv->dhcp4_state_sigid = g_signal_connect (priv->dhcp4_client,
4603 NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED,
4604 G_CALLBACK (dhcp4_state_changed),
4607 nm_device_add_pending_action (self, PENDING_ACTION_DHCP4, TRUE);
4609 /* DHCP devices will be notified by the DHCP manager when stuff happens */
4610 return NM_ACT_STAGE_RETURN_POSTPONE;
4614 nm_device_dhcp4_renew (NMDevice *self, gboolean release)
4616 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
4617 NMActStageReturn ret;
4618 NMDeviceStateReason reason;
4619 NMConnection *connection;
4621 g_return_val_if_fail (priv->dhcp4_client != NULL, FALSE);
4623 _LOGI (LOGD_DHCP4, "DHCPv4 lease renewal requested");
4625 /* Terminate old DHCP instance and release the old lease */
4626 dhcp4_cleanup (self, CLEANUP_TYPE_DECONFIGURE, release);
4628 connection = nm_device_get_applied_connection (self);
4629 g_assert (connection);
4631 /* Start DHCP again on the interface */
4632 ret = dhcp4_start (self, connection, &reason);
4634 return (ret != NM_ACT_STAGE_RETURN_FAILURE);
4637 /*********************************************/
4639 static GHashTable *shared_ips = NULL;
4642 release_shared_ip (gpointer data)
4644 g_hash_table_remove (shared_ips, data);
4648 reserve_shared_ip (NMDevice *self, NMSettingIPConfig *s_ip4, NMPlatformIP4Address *address)
4650 if (G_UNLIKELY (shared_ips == NULL))
4651 shared_ips = g_hash_table_new (g_direct_hash, g_direct_equal);
4653 memset (address, 0, sizeof (*address));
4655 if (s_ip4 && nm_setting_ip_config_get_num_addresses (s_ip4)) {
4656 /* Use the first user-supplied address */
4657 NMIPAddress *user = nm_setting_ip_config_get_address (s_ip4, 0);
4661 nm_ip_address_get_address_binary (user, &a);
4662 nm_platform_ip4_address_set_addr (address, a, nm_ip_address_get_prefix (user));
4664 /* Find an unused address in the 10.42.x.x range */
4665 guint32 start = (guint32) ntohl (0x0a2a0001); /* 10.42.0.1 */
4668 while (g_hash_table_lookup (shared_ips, GUINT_TO_POINTER (start + count))) {
4669 count += ntohl (0x100);
4670 if (count > ntohl (0xFE00)) {
4671 _LOGE (LOGD_SHARING, "ran out of shared IP addresses!");
4675 nm_platform_ip4_address_set_addr (address, start + count, 24);
4676 g_hash_table_add (shared_ips, GUINT_TO_POINTER (address->address));
4682 static NMIP4Config *
4683 shared4_new_config (NMDevice *self, NMConnection *connection, NMDeviceStateReason *reason)
4685 NMIP4Config *config = NULL;
4686 NMPlatformIP4Address address;
4688 g_return_val_if_fail (self != NULL, NULL);
4690 if (!reserve_shared_ip (self, nm_connection_get_setting_ip4_config (connection), &address)) {
4691 *reason = NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE;
4695 config = nm_ip4_config_new (nm_device_get_ip_ifindex (self));
4696 address.source = NM_IP_CONFIG_SOURCE_SHARED;
4697 nm_ip4_config_add_address (config, &address);
4699 /* Remove the address lock when the object gets disposed */
4700 g_object_set_data_full (G_OBJECT (config), "shared-ip",
4701 GUINT_TO_POINTER (address.address),
4707 /*********************************************/
4710 connection_ip4_method_requires_carrier (NMConnection *connection,
4711 gboolean *out_ip4_enabled)
4713 const char *method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
4714 static const char *ip4_carrier_methods[] = {
4715 NM_SETTING_IP4_CONFIG_METHOD_AUTO,
4716 NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
4720 if (out_ip4_enabled)
4721 *out_ip4_enabled = !!strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED);
4722 return _nm_utils_string_in_list (method, ip4_carrier_methods);
4726 connection_ip6_method_requires_carrier (NMConnection *connection,
4727 gboolean *out_ip6_enabled)
4729 const char *method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
4730 static const char *ip6_carrier_methods[] = {
4731 NM_SETTING_IP6_CONFIG_METHOD_AUTO,
4732 NM_SETTING_IP6_CONFIG_METHOD_DHCP,
4733 NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL,
4737 if (out_ip6_enabled)
4738 *out_ip6_enabled = !!strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE);
4739 return _nm_utils_string_in_list (method, ip6_carrier_methods);
4743 connection_requires_carrier (NMConnection *connection)
4745 NMSettingIPConfig *s_ip4, *s_ip6;
4746 gboolean ip4_carrier_wanted, ip6_carrier_wanted;
4747 gboolean ip4_used = FALSE, ip6_used = FALSE;
4749 ip4_carrier_wanted = connection_ip4_method_requires_carrier (connection, &ip4_used);
4750 if (ip4_carrier_wanted) {
4751 /* If IPv4 wants a carrier and cannot fail, the whole connection
4752 * requires a carrier regardless of the IPv6 method.
4754 s_ip4 = nm_connection_get_setting_ip4_config (connection);
4755 if (s_ip4 && !nm_setting_ip_config_get_may_fail (s_ip4))
4759 ip6_carrier_wanted = connection_ip6_method_requires_carrier (connection, &ip6_used);
4760 if (ip6_carrier_wanted) {
4761 /* If IPv6 wants a carrier and cannot fail, the whole connection
4762 * requires a carrier regardless of the IPv4 method.
4764 s_ip6 = nm_connection_get_setting_ip6_config (connection);
4765 if (s_ip6 && !nm_setting_ip_config_get_may_fail (s_ip6))
4769 /* If an IP version wants a carrier and and the other IP version isn't
4770 * used, the connection requires carrier since it will just fail without one.
4772 if (ip4_carrier_wanted && !ip6_used)
4774 if (ip6_carrier_wanted && !ip4_used)
4777 /* If both want a carrier, the whole connection wants a carrier */
4778 return ip4_carrier_wanted && ip6_carrier_wanted;
4782 have_any_ready_slaves (NMDevice *self, const GSList *slaves)
4786 /* Any enslaved slave is "ready" in the generic case as it's
4787 * at least >= NM_DEVCIE_STATE_IP_CONFIG and has had Layer 2
4788 * properties set up.
4790 for (iter = slaves; iter; iter = g_slist_next (iter)) {
4791 if (nm_device_get_enslaved (iter->data))
4798 ip4_requires_slaves (NMConnection *connection)
4802 method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
4803 return strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0;
4806 static NMActStageReturn
4807 act_stage3_ip4_config_start (NMDevice *self,
4808 NMIP4Config **out_config,
4809 NMDeviceStateReason *reason)
4811 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
4812 NMConnection *connection;
4813 NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
4816 gboolean ready_slaves;
4818 g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE);
4820 connection = nm_device_get_applied_connection (self);
4821 g_assert (connection);
4823 if ( connection_ip4_method_requires_carrier (connection, NULL)
4825 && !priv->carrier) {
4826 _LOGI (LOGD_IP4 | LOGD_DEVICE,
4827 "IPv4 config waiting until carrier is on");
4828 return NM_ACT_STAGE_RETURN_WAIT;
4831 if (priv->is_master && ip4_requires_slaves (connection)) {
4832 /* If the master has no ready slaves, and depends on slaves for
4833 * a successful IPv4 attempt, then postpone IPv4 addressing.
4835 slaves = nm_device_master_get_slaves (self);
4836 ready_slaves = NM_DEVICE_GET_CLASS (self)->have_any_ready_slaves (self, slaves);
4837 g_slist_free (slaves);
4839 if (ready_slaves == FALSE) {
4840 _LOGI (LOGD_DEVICE | LOGD_IP4,
4841 "IPv4 config waiting until slaves are ready");
4842 return NM_ACT_STAGE_RETURN_WAIT;
4846 method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
4848 /* Start IPv4 addressing based on the method requested */
4849 if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0)
4850 ret = dhcp4_start (self, connection, reason);
4851 else if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL) == 0)
4852 ret = ipv4ll_start (self, reason);
4853 else if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_MANUAL) == 0) {
4854 NMIP4Config **configs, *config;
4856 config = nm_ip4_config_new (nm_device_get_ip_ifindex (self));
4857 nm_ip4_config_merge_setting (config,
4858 nm_connection_get_setting_ip4_config (connection),
4859 nm_device_get_ip4_route_metric (self));
4861 configs = g_new0 (NMIP4Config *, 2);
4862 configs[0] = config;
4863 ipv4_dad_start (self, configs, ipv4_manual_method_apply);
4864 ret = NM_ACT_STAGE_RETURN_POSTPONE;
4865 } else if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0) {
4866 *out_config = shared4_new_config (self, connection, reason);
4868 priv->dnsmasq_manager = nm_dnsmasq_manager_new (nm_device_get_ip_iface (self));
4869 ret = NM_ACT_STAGE_RETURN_SUCCESS;
4871 ret = NM_ACT_STAGE_RETURN_FAILURE;
4872 } else if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_DISABLED) == 0) {
4873 /* Nothing to do... */
4874 ret = NM_ACT_STAGE_RETURN_STOP;
4876 _LOGW (LOGD_IP4, "unhandled IPv4 config method '%s'; will fail", method);
4881 /*********************************************/
4885 dhcp6_cleanup (NMDevice *self, CleanupType cleanup_type, gboolean release)
4887 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
4889 priv->dhcp6_mode = NM_RDISC_DHCP_LEVEL_NONE;
4890 g_clear_object (&priv->dhcp6_ip6_config);
4891 g_clear_pointer (&priv->dhcp6_event_id, g_free);
4892 nm_clear_g_source (&priv->dhcp6_restart_id);
4894 if (priv->dhcp6_client) {
4895 nm_clear_g_signal_handler (priv->dhcp6_client, &priv->dhcp6_state_sigid);
4897 if ( cleanup_type == CLEANUP_TYPE_DECONFIGURE
4898 || cleanup_type == CLEANUP_TYPE_REMOVED)
4899 nm_dhcp_client_stop (priv->dhcp6_client, release);
4901 g_clear_object (&priv->dhcp6_client);
4904 nm_device_remove_pending_action (self, PENDING_ACTION_DHCP6, FALSE);
4906 if (priv->dhcp6_config) {
4907 nm_exported_object_clear_and_unexport (&priv->dhcp6_config);
4908 _notify (self, PROP_DHCP6_CONFIG);
4913 _ip6_config_merge_default (gpointer value, gpointer user_data)
4915 NMIP6Config *src = (NMIP6Config *) value;
4916 NMIP6Config *dst = (NMIP6Config *) user_data;
4918 nm_ip6_config_merge (dst, src, NM_IP_CONFIG_MERGE_DEFAULT);
4922 ip6_config_merge_and_apply (NMDevice *self,
4924 NMDeviceStateReason *out_reason)
4926 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
4927 NMConnection *connection;
4929 NMIP6Config *composite;
4930 gboolean has_direct_route;
4931 const struct in6_addr *gateway;
4932 gboolean connection_has_default_route, connection_is_never_default;
4933 gboolean routes_full_sync;
4934 gboolean ignore_auto_routes = FALSE;
4935 gboolean ignore_auto_dns = FALSE;
4937 /* Apply ignore-auto-routes and ignore-auto-dns settings */
4938 connection = nm_device_get_applied_connection (self);
4940 NMSettingIPConfig *s_ip6 = nm_connection_get_setting_ip6_config (connection);
4943 ignore_auto_routes = nm_setting_ip_config_get_ignore_auto_routes (s_ip6);
4944 ignore_auto_dns = nm_setting_ip_config_get_ignore_auto_dns (s_ip6);
4948 /* If no config was passed in, create a new one */
4949 composite = nm_ip6_config_new (nm_device_get_ip_ifindex (self));
4952 ensure_con_ip6_config (self);
4953 g_assert (composite);
4955 /* Merge all the IP configs into the composite config */
4956 if (priv->ac_ip6_config) {
4957 nm_ip6_config_merge (composite, priv->ac_ip6_config,
4958 (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0)
4959 | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0));
4961 if (priv->dhcp6_ip6_config) {
4962 nm_ip6_config_merge (composite, priv->dhcp6_ip6_config,
4963 (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0)
4964 | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0));
4967 g_slist_foreach (priv->vpn6_configs, _ip6_config_merge_default, composite);
4969 if (priv->ext_ip6_config)
4970 nm_ip6_config_merge (composite, priv->ext_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT);
4972 /* Merge WWAN config *last* to ensure modem-given settings overwrite
4973 * any external stuff set by pppd or other scripts.
4975 if (priv->wwan_ip6_config) {
4976 nm_ip6_config_merge (composite, priv->wwan_ip6_config,
4977 (ignore_auto_routes ? NM_IP_CONFIG_MERGE_NO_ROUTES : 0)
4978 | (ignore_auto_dns ? NM_IP_CONFIG_MERGE_NO_DNS : 0));
4981 /* Merge user overrides into the composite config. For assumed connections,
4982 * con_ip6_config is empty. */
4983 if (priv->con_ip6_config)
4984 nm_ip6_config_merge (composite, priv->con_ip6_config, NM_IP_CONFIG_MERGE_DEFAULT);
4986 /* Add the default route.
4988 * We keep track of the default route of a device in a private field.
4989 * NMDevice needs to know the default route at this point, because the gateway
4990 * might require a direct route (see below).
4992 * But also, we don't want to add the default route to priv->ip6_config,
4993 * because the default route from the setting might not be the same that
4994 * NMDefaultRouteManager eventually configures (because the it might
4995 * tweak the effective metric).
4998 /* unless we come to a different conclusion below, we have no default route and
4999 * the route is assumed. */
5000 priv->default_route.v6_has = FALSE;
5001 priv->default_route.v6_is_assumed = TRUE;
5004 /* during a non-commit event, we always pickup whatever is configured. */
5005 goto END_ADD_DEFAULT_ROUTE;
5008 if (nm_device_uses_generated_assumed_connection (self)) {
5009 /* a generate-assumed-connection always detects the default route from platform */
5010 goto END_ADD_DEFAULT_ROUTE;
5013 /* At this point, we treat assumed and non-assumed connections alike.
5014 * For assumed connections we do that because we still manage RA and DHCP
5015 * leases for them, so we must extend/update the default route on commits.
5018 connection_has_default_route
5019 = nm_default_route_manager_ip6_connection_has_default_route (nm_default_route_manager_get (),
5020 connection, &connection_is_never_default);
5022 if ( !priv->v6_commit_first_time
5023 && connection_is_never_default) {
5024 /* If the connection is explicitly configured as never-default, we enforce the (absence of the)
5025 * default-route only once. That allows the user to configure a connection as never-default,
5026 * but he can add default routes externally (via a dispatcher script) and NM will not interfere. */
5027 goto END_ADD_DEFAULT_ROUTE;
5030 /* we are about to commit (for a non-assumed connection). Enforce whatever we have
5032 priv->default_route.v6_is_assumed = FALSE;
5034 if (!connection_has_default_route)
5035 goto END_ADD_DEFAULT_ROUTE;
5037 if (!nm_ip6_config_get_num_addresses (composite)) {
5038 /* without addresses we can have no default route. */
5039 goto END_ADD_DEFAULT_ROUTE;
5042 gateway = nm_ip6_config_get_gateway (composite);
5044 goto END_ADD_DEFAULT_ROUTE;
5047 has_direct_route = nm_ip6_config_get_direct_route_for_host (composite, gateway) != NULL;
5051 priv->default_route.v6_has = TRUE;
5052 memset (&priv->default_route.v6, 0, sizeof (priv->default_route.v6));
5053 priv->default_route.v6.source = NM_IP_CONFIG_SOURCE_USER;
5054 priv->default_route.v6.gateway = *gateway;
5055 priv->default_route.v6.metric = nm_device_get_ip6_route_metric (self);
5056 priv->default_route.v6.mss = nm_ip6_config_get_mss (composite);
5058 if (!has_direct_route) {
5059 NMPlatformIP6Route r = priv->default_route.v6;
5061 /* add a direct route to the gateway */
5062 r.network = *gateway;
5064 r.gateway = in6addr_any;
5065 nm_ip6_config_add_route (composite, &r);
5068 END_ADD_DEFAULT_ROUTE:
5070 if (priv->default_route.v6_is_assumed) {
5071 /* If above does not explicitly assign a default route, we always pick up the
5072 * default route based on what is currently configured.
5073 * That means that even managed connections with never-default, can
5074 * get a default route (if configured externally).
5076 priv->default_route.v6_has = _device_get_default_route_from_platform (self, AF_INET6, (NMPlatformIPRoute *) &priv->default_route.v6);
5079 nm_ip6_config_addresses_sort (composite,
5080 priv->rdisc ? priv->rdisc_use_tempaddr : NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN);
5082 /* Allow setting MTU etc */
5084 if (NM_DEVICE_GET_CLASS (self)->ip6_config_pre_commit)
5085 NM_DEVICE_GET_CLASS (self)->ip6_config_pre_commit (self, composite);
5088 routes_full_sync = commit
5089 && priv->v6_commit_first_time
5090 && !nm_device_uses_assumed_connection (self);
5092 success = nm_device_set_ip6_config (self, composite, commit, routes_full_sync, out_reason);
5093 g_object_unref (composite);
5095 priv->v6_commit_first_time = FALSE;
5100 dhcp6_lease_change (NMDevice *self)
5102 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5103 NMSettingsConnection *settings_connection;
5104 NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
5106 if (priv->dhcp6_ip6_config == NULL) {
5107 _LOGW (LOGD_DHCP6, "failed to get DHCPv6 config for rebind");
5108 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED);
5112 g_assert (priv->dhcp6_client); /* sanity check */
5114 settings_connection = nm_device_get_settings_connection (self);
5115 g_assert (settings_connection);
5117 /* Apply the updated config */
5118 if (ip6_config_merge_and_apply (self, TRUE, &reason) == FALSE) {
5119 _LOGW (LOGD_DHCP6, "failed to update IPv6 config in response to DHCP event.");
5120 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, reason);
5122 /* Notify dispatcher scripts of new DHCPv6 config */
5123 nm_dispatcher_call (DISPATCHER_ACTION_DHCP6_CHANGE,
5124 settings_connection,
5125 nm_device_get_applied_connection (self),
5126 self, NULL, NULL, NULL);
5131 dhcp6_restart_cb (gpointer user_data)
5133 NMDevice *self = user_data;
5134 NMDevicePrivate *priv;
5135 NMDeviceStateReason reason;
5137 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
5139 priv = NM_DEVICE_GET_PRIVATE (self);
5140 priv->dhcp6_restart_id = 0;
5142 if (!dhcp6_start (self, FALSE, &reason))
5143 priv->dhcp6_restart_id = g_timeout_add_seconds (120, dhcp6_restart_cb, self);
5149 dhcp6_fail (NMDevice *self, gboolean timeout)
5151 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5153 dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE);
5155 if (priv->dhcp6_mode == NM_RDISC_DHCP_LEVEL_MANAGED) {
5156 /* Don't fail if there are static addresses configured on
5157 * the device, instead retry after some time.
5159 if ( priv->ip6_state == IP_DONE
5160 && priv->con_ip6_config
5161 && nm_ip6_config_get_num_addresses (priv->con_ip6_config)) {
5162 _LOGI (LOGD_DHCP6, "Scheduling DHCPv6 restart because device has IP addresses");
5163 priv->dhcp6_restart_id = g_timeout_add_seconds (120, dhcp6_restart_cb, self);
5167 /* Instead of letting an assumed connection fail (which means that the
5168 * device will transition to the ACTIVATED state without IP configuration),
5171 if (nm_device_uses_assumed_connection (self)) {
5172 _LOGI (LOGD_DHCP6, "Scheduling DHCPv6 restart because the connection is assumed");
5173 priv->dhcp6_restart_id = g_timeout_add_seconds (120, dhcp6_restart_cb, self);
5177 if (timeout || (priv->ip6_state == IP_CONF))
5178 nm_device_activate_schedule_ip6_config_timeout (self);
5179 else if (priv->ip6_state == IP_DONE)
5180 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_IP_CONFIG_EXPIRED);
5182 g_warn_if_reached ();
5184 /* not a hard failure; just live with the RA info */
5185 if (priv->ip6_state == IP_CONF)
5186 nm_device_activate_schedule_ip6_config_result (self);
5191 dhcp6_timeout (NMDevice *self, NMDhcpClient *client)
5193 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5195 if (priv->dhcp6_mode == NM_RDISC_DHCP_LEVEL_MANAGED)
5196 dhcp6_fail (self, TRUE);
5198 /* not a hard failure; just live with the RA info */
5199 dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, FALSE);
5200 if (priv->ip6_state == IP_CONF)
5201 nm_device_activate_schedule_ip6_config_result (self);
5206 dhcp6_state_changed (NMDhcpClient *client,
5208 NMIP6Config *ip6_config,
5209 GHashTable *options,
5210 const char *event_id,
5213 NMDevice *self = NM_DEVICE (user_data);
5214 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5217 g_return_if_fail (nm_dhcp_client_get_ipv6 (client) == TRUE);
5218 g_return_if_fail (!ip6_config || NM_IS_IP6_CONFIG (ip6_config));
5220 _LOGD (LOGD_DHCP6, "new DHCPv6 client state %d", state);
5223 case NM_DHCP_STATE_BOUND:
5224 /* If the server sends multiple IPv6 addresses, we receive a state
5225 * changed event for each of them. Use the event ID to merge IPv6
5226 * addresses from the same transaction into a single configuration.
5230 && priv->dhcp6_event_id
5231 && !strcmp (event_id, priv->dhcp6_event_id)) {
5232 for (i = 0; i < nm_ip6_config_get_num_addresses (ip6_config); i++) {
5233 nm_ip6_config_add_address (priv->dhcp6_ip6_config,
5234 nm_ip6_config_get_address (ip6_config, i));
5237 g_clear_object (&priv->dhcp6_ip6_config);
5238 g_clear_pointer (&priv->dhcp6_event_id, g_free);
5240 priv->dhcp6_ip6_config = g_object_ref (ip6_config);
5241 priv->dhcp6_event_id = g_strdup (event_id);
5242 nm_dhcp6_config_set_options (priv->dhcp6_config, options);
5243 _notify (self, PROP_DHCP6_CONFIG);
5247 if (priv->ip6_state == IP_CONF) {
5248 if (priv->dhcp6_ip6_config == NULL) {
5249 /* FIXME: Initial DHCP failed; should we fail IPv6 entirely then? */
5250 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_DHCP_FAILED);
5253 nm_device_activate_schedule_ip6_config_result (self);
5254 } else if (priv->ip6_state == IP_DONE)
5255 dhcp6_lease_change (self);
5257 case NM_DHCP_STATE_TIMEOUT:
5258 dhcp6_timeout (self, client);
5260 case NM_DHCP_STATE_EXPIRE:
5261 /* Ignore expiry before we even have a lease (NAK, old lease, etc) */
5262 if (priv->ip6_state != IP_CONF)
5263 dhcp6_fail (self, FALSE);
5265 case NM_DHCP_STATE_DONE:
5266 /* In IPv6 info-only mode, the client doesn't handle leases so it
5267 * may exit right after getting a response from the server. That's
5268 * normal. In that case we just ignore the exit.
5270 if (priv->dhcp6_mode == NM_RDISC_DHCP_LEVEL_OTHERCONF)
5272 /* Otherwise, fall through */
5273 case NM_DHCP_STATE_FAIL:
5274 dhcp6_fail (self, FALSE);
5282 dhcp6_start_with_link_ready (NMDevice *self, NMConnection *connection)
5284 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5285 NMSettingIPConfig *s_ip6;
5286 GByteArray *tmp = NULL;
5287 const guint8 *hw_addr;
5288 size_t hw_addr_len = 0;
5289 const NMPlatformIP6Address *ll_addr = NULL;
5291 g_assert (connection);
5292 s_ip6 = nm_connection_get_setting_ip6_config (connection);
5295 hw_addr = nm_platform_link_get_address (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self), &hw_addr_len);
5297 tmp = g_byte_array_sized_new (hw_addr_len);
5298 g_byte_array_append (tmp, hw_addr, hw_addr_len);
5301 if (priv->ext_ip6_config_captured)
5302 ll_addr = nm_ip6_config_get_address_first_nontentative (priv->ext_ip6_config_captured, TRUE);
5304 g_return_val_if_fail (ll_addr, FALSE);
5306 priv->dhcp6_client = nm_dhcp_manager_start_ip6 (nm_dhcp_manager_get (),
5307 nm_device_get_ip_iface (self),
5308 nm_device_get_ip_ifindex (self),
5311 nm_connection_get_uuid (connection),
5312 nm_device_get_ip6_route_metric (self),
5313 nm_setting_ip_config_get_dhcp_send_hostname (s_ip6),
5314 nm_setting_ip_config_get_dhcp_hostname (s_ip6),
5316 priv->dhcp_anycast_address,
5317 (priv->dhcp6_mode == NM_RDISC_DHCP_LEVEL_OTHERCONF) ? TRUE : FALSE,
5318 nm_setting_ip6_config_get_ip6_privacy (NM_SETTING_IP6_CONFIG (s_ip6)));
5320 g_byte_array_free (tmp, TRUE);
5322 if (priv->dhcp6_client) {
5323 priv->dhcp6_state_sigid = g_signal_connect (priv->dhcp6_client,
5324 NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED,
5325 G_CALLBACK (dhcp6_state_changed),
5329 return !!priv->dhcp6_client;
5333 dhcp6_start (NMDevice *self, gboolean wait_for_ll, NMDeviceStateReason *reason)
5335 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5336 NMConnection *connection;
5337 NMSettingIPConfig *s_ip6;
5339 nm_exported_object_clear_and_unexport (&priv->dhcp6_config);
5340 priv->dhcp6_config = nm_dhcp6_config_new ();
5342 g_warn_if_fail (priv->dhcp6_ip6_config == NULL);
5343 g_clear_object (&priv->dhcp6_ip6_config);
5344 g_clear_pointer (&priv->dhcp6_event_id, g_free);
5346 connection = nm_device_get_applied_connection (self);
5347 g_assert (connection);
5348 s_ip6 = nm_connection_get_setting_ip6_config (connection);
5349 if (!nm_setting_ip_config_get_may_fail (s_ip6) ||
5350 !strcmp (nm_setting_ip_config_get_method (s_ip6), NM_SETTING_IP6_CONFIG_METHOD_DHCP))
5351 nm_device_add_pending_action (self, PENDING_ACTION_DHCP6, TRUE);
5354 NMActStageReturn ret;
5356 /* ensure link local is ready... */
5357 ret = linklocal6_start (self);
5358 if (ret == NM_ACT_STAGE_RETURN_POSTPONE) {
5359 /* success; wait for the LL address to show up */
5363 /* success; already have the LL address; kick off DHCP */
5364 g_assert (ret == NM_ACT_STAGE_RETURN_SUCCESS || ret == NM_ACT_STAGE_RETURN_FINISH);
5367 if (!dhcp6_start_with_link_ready (self, connection)) {
5368 *reason = NM_DEVICE_STATE_REASON_DHCP_START_FAILED;
5376 nm_device_dhcp6_renew (NMDevice *self, gboolean release)
5378 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5380 g_return_val_if_fail (priv->dhcp6_client != NULL, FALSE);
5382 _LOGI (LOGD_DHCP6, "DHCPv6 lease renewal requested");
5384 /* Terminate old DHCP instance and release the old lease */
5385 dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, release);
5387 /* Start DHCP again on the interface */
5388 return dhcp6_start (self, FALSE, NULL);
5391 /******************************************/
5394 linklocal6_cleanup (NMDevice *self)
5396 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5398 nm_clear_g_source (&priv->linklocal6_timeout_id);
5402 linklocal6_failed (NMDevice *self)
5404 linklocal6_cleanup (self);
5405 nm_device_activate_schedule_ip6_config_timeout (self);
5409 linklocal6_timeout_cb (gpointer user_data)
5411 NMDevice *self = user_data;
5413 _LOGD (LOGD_DEVICE, "linklocal6: waiting for link-local addresses failed due to timeout");
5414 linklocal6_failed (self);
5415 return G_SOURCE_REMOVE;
5419 linklocal6_complete (NMDevice *self)
5421 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5422 NMConnection *connection;
5425 g_assert (priv->linklocal6_timeout_id);
5426 g_assert (nm_ip6_config_get_address_first_nontentative (priv->ip6_config, TRUE));
5428 linklocal6_cleanup (self);
5430 connection = nm_device_get_applied_connection (self);
5431 g_assert (connection);
5433 method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
5435 _LOGD (LOGD_DEVICE, "linklocal6: waiting for link-local addresses successful, continue with method %s", method);
5437 if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0) {
5438 if (!addrconf6_start_with_link_ready (self)) {
5439 /* Time out IPv6 instead of failing the entire activation */
5440 nm_device_activate_schedule_ip6_config_timeout (self);
5442 } else if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0) {
5443 if (!dhcp6_start_with_link_ready (self, connection)) {
5444 /* Time out IPv6 instead of failing the entire activation */
5445 nm_device_activate_schedule_ip6_config_timeout (self);
5447 } else if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0)
5448 nm_device_activate_schedule_ip6_config_result (self);
5450 g_return_if_fail (FALSE);
5454 check_and_add_ipv6ll_addr (NMDevice *self)
5456 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5457 int ip_ifindex = nm_device_get_ip_ifindex (self);
5458 struct in6_addr lladdr;
5460 NMConnection *connection;
5461 NMSettingIP6Config *s_ip6 = NULL;
5462 GError *error = NULL;
5464 if (priv->nm_ipv6ll == FALSE)
5467 if (priv->ip6_config) {
5468 n = nm_ip6_config_get_num_addresses (priv->ip6_config);
5469 for (i = 0; i < n; i++) {
5470 const NMPlatformIP6Address *addr;
5472 addr = nm_ip6_config_get_address (priv->ip6_config, i);
5473 if ( IN6_IS_ADDR_LINKLOCAL (&addr->address)
5474 && !(addr->n_ifa_flags & IFA_F_DADFAILED)) {
5475 /* Already have an LL address, nothing to do */
5481 memset (&lladdr, 0, sizeof (lladdr));
5482 lladdr.s6_addr16[0] = htons (0xfe80);
5484 connection = nm_device_get_applied_connection (self);
5486 s_ip6 = NM_SETTING_IP6_CONFIG (nm_connection_get_setting_ip6_config (connection));
5488 if (s_ip6 && nm_setting_ip6_config_get_addr_gen_mode (s_ip6) == NM_SETTING_IP6_CONFIG_ADDR_GEN_MODE_STABLE_PRIVACY) {
5489 if (!nm_utils_ipv6_addr_set_stable_privacy (&lladdr,
5490 nm_device_get_iface (self),
5491 nm_connection_get_uuid (connection),
5492 priv->linklocal6_dad_counter++,
5494 _LOGW (LOGD_IP6, "linklocal6: failed to generate an address: %s", error->message);
5495 g_clear_error (&error);
5496 linklocal6_failed (self);
5499 _LOGD (LOGD_IP6, "linklocal6: using IPv6 stable-privacy addressing");
5501 NMUtilsIPv6IfaceId iid;
5503 if (priv->linklocal6_timeout_id) {
5504 /* We already started and attempt to add a LL address. For the EUI-64
5505 * mode we can't pick a new one, we'll just fail. */
5506 _LOGW (LOGD_IP6, "linklocal6: DAD failed for an EUI-64 address");
5507 linklocal6_failed (self);
5511 if (!nm_device_get_ip_iface_identifier (self, &iid)) {
5512 _LOGW (LOGD_IP6, "linklocal6: failed to get interface identifier; IPv6 cannot continue");
5515 _LOGD (LOGD_IP6, "linklocal6: using EUI-64 identifier to generate IPv6LL address");
5517 nm_utils_ipv6_addr_set_interface_identfier (&lladdr, iid);
5520 _LOGD (LOGD_IP6, "linklocal6: adding IPv6LL address %s", nm_utils_inet6_ntop (&lladdr, NULL));
5521 if (!nm_platform_ip6_address_add (NM_PLATFORM_GET,
5526 NM_PLATFORM_LIFETIME_PERMANENT,
5527 NM_PLATFORM_LIFETIME_PERMANENT,
5529 _LOGW (LOGD_IP6, "failed to add IPv6 link-local address %s",
5530 nm_utils_inet6_ntop (&lladdr, NULL));
5534 static NMActStageReturn
5535 linklocal6_start (NMDevice *self)
5537 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5538 NMConnection *connection;
5541 linklocal6_cleanup (self);
5543 if ( priv->ip6_config
5544 && nm_ip6_config_get_address_first_nontentative (priv->ip6_config, TRUE))
5545 return NM_ACT_STAGE_RETURN_FINISH;
5547 connection = nm_device_get_applied_connection (self);
5548 g_assert (connection);
5550 method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
5551 _LOGD (LOGD_DEVICE, "linklocal6: starting IPv6 with method '%s', but the device has no link-local addresses configured. Wait.", method);
5553 check_and_add_ipv6ll_addr (self);
5555 /* Depending on the network and what the 'dad_transmits' and 'retrans_time_ms'
5556 * sysctl values are, DAD for the IPv6LL address may take quite a while.
5557 * FIXME: use dad/retrans sysctl values if they are higher than a minimum time.
5560 priv->linklocal6_timeout_id = g_timeout_add_seconds (15, linklocal6_timeout_cb, self);
5562 return NM_ACT_STAGE_RETURN_POSTPONE;
5565 /******************************************/
5567 static void nm_device_ipv6_set_mtu (NMDevice *self, guint32 mtu);
5570 nm_device_set_mtu (NMDevice *self, guint32 mtu)
5572 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5573 int ifindex = nm_device_get_ip_ifindex (self);
5578 /* Ensure the IPv6 MTU is still alright. */
5580 nm_device_ipv6_set_mtu (self, priv->ip6_mtu);
5582 if (priv->mtu && priv->mtu != nm_platform_link_get_mtu (NM_PLATFORM_GET, ifindex))
5583 nm_platform_link_set_mtu (NM_PLATFORM_GET, ifindex, priv->mtu);
5587 nm_device_ipv6_set_mtu (NMDevice *self, guint32 mtu)
5589 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5590 guint32 plat_mtu = nm_device_ipv6_sysctl_get_int32 (self, "mtu", priv->mtu);
5593 priv->ip6_mtu = mtu ?: plat_mtu;
5595 if (priv->ip6_mtu && priv->mtu && priv->mtu < priv->ip6_mtu) {
5596 _LOGI (LOGD_DEVICE | LOGD_IP6, "Lowering IPv6 MTU (%d) to match device MTU (%d)",
5597 priv->ip6_mtu, priv->mtu);
5598 priv->ip6_mtu = priv->mtu;
5601 if (priv->ip6_mtu && priv->ip6_mtu < 1280) {
5602 _LOGI (LOGD_DEVICE | LOGD_IP6, "IPv6 MTU (%d) smaller than 1280, adjusting",
5604 priv->ip6_mtu = 1280;
5607 if (priv->ip6_mtu && priv->mtu && priv->mtu < priv->ip6_mtu) {
5608 _LOGI (LOGD_DEVICE | LOGD_IP6, "Raising device MTU (%d) to match IPv6 MTU (%d)",
5609 priv->mtu, priv->ip6_mtu);
5610 nm_device_set_mtu (self, priv->ip6_mtu);
5613 if (priv->ip6_mtu != plat_mtu) {
5614 g_snprintf (val, sizeof (val), "%d", mtu);
5615 nm_device_ipv6_sysctl_set (self, "mtu", val);
5620 rdisc_config_changed (NMRDisc *rdisc, NMRDiscConfigMap changed, NMDevice *self)
5622 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5625 guint32 ifa_flags = 0x00;
5628 * Check, whether kernel is recent enough to help user space handling RA.
5629 * If it's not supported, we have no ipv6-privacy and must add autoconf
5630 * addresses as /128. The reason for the /128 is to prevent the kernel
5631 * from adding a prefix route for this address.
5633 system_support = nm_platform_check_support_kernel_extended_ifa_flags (NM_PLATFORM_GET);
5636 ifa_flags = IFA_F_NOPREFIXROUTE;
5637 if ( priv->rdisc_use_tempaddr == NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR
5638 || priv->rdisc_use_tempaddr == NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR)
5640 /* without system_support, this flag will be ignored. Still set it, doesn't seem to do any harm. */
5641 ifa_flags |= IFA_F_MANAGETEMPADDR;
5644 g_return_if_fail (priv->act_request);
5646 if (!priv->ac_ip6_config)
5647 priv->ac_ip6_config = nm_ip6_config_new (nm_device_get_ip_ifindex (self));
5649 if (changed & NM_RDISC_CONFIG_GATEWAYS) {
5650 /* Use the first gateway as ordered in router discovery cache. */
5651 if (rdisc->gateways->len) {
5652 NMRDiscGateway *gateway = &g_array_index (rdisc->gateways, NMRDiscGateway, 0);
5654 nm_ip6_config_set_gateway (priv->ac_ip6_config, &gateway->address);
5656 nm_ip6_config_set_gateway (priv->ac_ip6_config, NULL);
5659 if (changed & NM_RDISC_CONFIG_ADDRESSES) {
5660 /* Rebuild address list from router discovery cache. */
5661 nm_ip6_config_reset_addresses (priv->ac_ip6_config);
5663 /* rdisc->addresses contains at most max_addresses entries.
5664 * This is different from what the kernel does, which
5665 * also counts static and temporary addresses when checking
5668 for (i = 0; i < rdisc->addresses->len; i++) {
5669 NMRDiscAddress *discovered_address = &g_array_index (rdisc->addresses, NMRDiscAddress, i);
5670 NMPlatformIP6Address address;
5672 memset (&address, 0, sizeof (address));
5673 address.address = discovered_address->address;
5674 address.plen = system_support ? 64 : 128;
5675 address.timestamp = discovered_address->timestamp;
5676 address.lifetime = discovered_address->lifetime;
5677 address.preferred = discovered_address->preferred;
5678 if (address.preferred > address.lifetime)
5679 address.preferred = address.lifetime;
5680 address.source = NM_IP_CONFIG_SOURCE_RDISC;
5681 address.n_ifa_flags = ifa_flags;
5683 nm_ip6_config_add_address (priv->ac_ip6_config, &address);
5687 if (changed & NM_RDISC_CONFIG_ROUTES) {
5688 /* Rebuild route list from router discovery cache. */
5689 nm_ip6_config_reset_routes (priv->ac_ip6_config);
5691 for (i = 0; i < rdisc->routes->len; i++) {
5692 NMRDiscRoute *discovered_route = &g_array_index (rdisc->routes, NMRDiscRoute, i);
5693 NMPlatformIP6Route route;
5695 /* Only accept non-default routes. The router has no idea what the
5696 * local configuration or user preferences are, so sending routes
5697 * with a prefix length of 0 is quite rude and thus ignored.
5699 if (discovered_route->plen > 0) {
5700 memset (&route, 0, sizeof (route));
5701 route.network = discovered_route->network;
5702 route.plen = discovered_route->plen;
5703 route.gateway = discovered_route->gateway;
5704 route.source = NM_IP_CONFIG_SOURCE_RDISC;
5705 route.metric = nm_device_get_ip6_route_metric (self);
5707 nm_ip6_config_add_route (priv->ac_ip6_config, &route);
5712 if (changed & NM_RDISC_CONFIG_DNS_SERVERS) {
5713 /* Rebuild DNS server list from router discovery cache. */
5714 nm_ip6_config_reset_nameservers (priv->ac_ip6_config);
5716 for (i = 0; i < rdisc->dns_servers->len; i++) {
5717 NMRDiscDNSServer *discovered_server = &g_array_index (rdisc->dns_servers, NMRDiscDNSServer, i);
5719 nm_ip6_config_add_nameserver (priv->ac_ip6_config, &discovered_server->address);
5723 if (changed & NM_RDISC_CONFIG_DNS_DOMAINS) {
5724 /* Rebuild domain list from router discovery cache. */
5725 nm_ip6_config_reset_domains (priv->ac_ip6_config);
5727 for (i = 0; i < rdisc->dns_domains->len; i++) {
5728 NMRDiscDNSDomain *discovered_domain = &g_array_index (rdisc->dns_domains, NMRDiscDNSDomain, i);
5730 nm_ip6_config_add_domain (priv->ac_ip6_config, discovered_domain->domain);
5734 if (changed & NM_RDISC_CONFIG_DHCP_LEVEL) {
5735 dhcp6_cleanup (self, CLEANUP_TYPE_DECONFIGURE, TRUE);
5737 priv->dhcp6_mode = rdisc->dhcp_level;
5738 if (priv->dhcp6_mode != NM_RDISC_DHCP_LEVEL_NONE) {
5739 NMDeviceStateReason reason;
5741 _LOGD (LOGD_DEVICE | LOGD_DHCP6,
5742 "Activation: Stage 3 of 5 (IP Configure Start) starting DHCPv6"
5743 " as requested by IPv6 router...");
5744 if (!dhcp6_start (self, FALSE, &reason)) {
5745 if (priv->dhcp6_mode == NM_RDISC_DHCP_LEVEL_MANAGED) {
5746 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, reason);
5753 if (changed & NM_RDISC_CONFIG_HOP_LIMIT)
5754 nm_platform_sysctl_set_ip6_hop_limit_safe (NM_PLATFORM_GET, nm_device_get_ip_iface (self), rdisc->hop_limit);
5756 if (changed & NM_RDISC_CONFIG_MTU)
5757 priv->ip6_mtu = rdisc->mtu;
5759 nm_device_activate_schedule_ip6_config_result (self);
5763 rdisc_ra_timeout (NMRDisc *rdisc, NMDevice *self)
5765 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5767 /* We don't want to stop listening for router advertisements completely,
5768 * but instead let device activation continue activating. If an RA
5769 * shows up later, we'll use it as long as the device is not disconnected.
5772 _LOGD (LOGD_IP6, "timed out waiting for IPv6 router advertisement");
5773 if (priv->ip6_state == IP_CONF) {
5774 /* If RA is our only source of addressing information and we don't
5775 * ever receive one, then time out IPv6. But if there is other
5776 * IPv6 configuration, like manual IPv6 addresses or external IPv6
5777 * config, consider that sufficient for IPv6 success.
5779 if ( priv->ip6_config
5780 && nm_ip6_config_get_address_first_nontentative (priv->ip6_config, FALSE))
5781 nm_device_activate_schedule_ip6_config_result (self);
5783 nm_device_activate_schedule_ip6_config_timeout (self);
5788 addrconf6_start_with_link_ready (NMDevice *self)
5790 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5791 NMUtilsIPv6IfaceId iid;
5793 g_assert (priv->rdisc);
5795 if (nm_platform_link_get_ipv6_token (NM_PLATFORM_GET, priv->ifindex, &iid)) {
5796 _LOGD (LOGD_IP6, "addrconf6: IPv6 tokenized identifier present");
5797 nm_rdisc_set_iid (priv->rdisc, iid);
5798 } else if (nm_device_get_ip_iface_identifier (self, &iid)) {
5799 _LOGD (LOGD_IP6, "addrconf6: using the device EUI-64 identifier");
5800 nm_rdisc_set_iid (priv->rdisc, iid);
5802 /* Don't abort the addrconf at this point -- if rdisc needs the iid
5803 * it will notice this itself. */
5804 _LOGI (LOGD_IP6, "addrconf6: no interface identifier; IPv6 adddress creation may fail");
5807 /* Apply any manual configuration before starting RA */
5808 if (!ip6_config_merge_and_apply (self, TRUE, NULL))
5809 _LOGW (LOGD_IP6, "failed to apply manual IPv6 configuration");
5811 nm_device_ipv6_sysctl_set (self, "accept_ra", "1");
5812 nm_device_ipv6_sysctl_set (self, "accept_ra_defrtr", "0");
5813 nm_device_ipv6_sysctl_set (self, "accept_ra_pinfo", "0");
5814 nm_device_ipv6_sysctl_set (self, "accept_ra_rtr_pref", "0");
5816 priv->rdisc_changed_id = g_signal_connect (priv->rdisc,
5817 NM_RDISC_CONFIG_CHANGED,
5818 G_CALLBACK (rdisc_config_changed),
5820 priv->rdisc_timeout_id = g_signal_connect (priv->rdisc,
5821 NM_RDISC_RA_TIMEOUT,
5822 G_CALLBACK (rdisc_ra_timeout),
5825 nm_rdisc_start (priv->rdisc);
5830 addrconf6_start (NMDevice *self, NMSettingIP6ConfigPrivacy use_tempaddr)
5832 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5833 NMConnection *connection;
5834 NMActStageReturn ret;
5835 NMSettingIP6Config *s_ip6 = NULL;
5836 GError *error = NULL;
5838 connection = nm_device_get_applied_connection (self);
5839 g_assert (connection);
5841 g_warn_if_fail (priv->ac_ip6_config == NULL);
5842 if (priv->ac_ip6_config) {
5843 g_object_unref (priv->ac_ip6_config);
5844 priv->ac_ip6_config = NULL;
5847 s_ip6 = NM_SETTING_IP6_CONFIG (nm_connection_get_setting_ip6_config (connection));
5850 priv->rdisc = nm_lndp_rdisc_new (NM_PLATFORM_GET,
5851 nm_device_get_ip_ifindex (self),
5852 nm_device_get_ip_iface (self),
5853 nm_connection_get_uuid (connection),
5854 nm_setting_ip6_config_get_addr_gen_mode (s_ip6),
5857 _LOGE (LOGD_IP6, "addrconf6: failed to start router discovery: %s", error->message);
5858 g_error_free (error);
5862 priv->rdisc_use_tempaddr = use_tempaddr;
5864 if ( NM_IN_SET (use_tempaddr, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR, NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR)
5865 && !nm_platform_check_support_kernel_extended_ifa_flags (NM_PLATFORM_GET)) {
5866 _LOGW (LOGD_IP6, "The kernel does not support extended IFA_FLAGS needed by NM for "
5867 "IPv6 private addresses. This feature is not available");
5870 if (!nm_setting_ip_config_get_may_fail (nm_connection_get_setting_ip6_config (connection)))
5871 nm_device_add_pending_action (self, PENDING_ACTION_AUTOCONF6, TRUE);
5873 /* ensure link local is ready... */
5874 ret = linklocal6_start (self);
5875 if (ret == NM_ACT_STAGE_RETURN_POSTPONE) {
5876 /* success; wait for the LL address to show up */
5880 /* success; already have the LL address; kick off router discovery */
5881 g_assert (ret == NM_ACT_STAGE_RETURN_SUCCESS || ret == NM_ACT_STAGE_RETURN_FINISH);
5882 return addrconf6_start_with_link_ready (self);
5886 addrconf6_cleanup (NMDevice *self)
5888 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5890 nm_clear_g_signal_handler (priv->rdisc, &priv->rdisc_changed_id);
5891 nm_clear_g_signal_handler (priv->rdisc, &priv->rdisc_timeout_id);
5893 nm_device_remove_pending_action (self, PENDING_ACTION_AUTOCONF6, FALSE);
5895 g_clear_object (&priv->ac_ip6_config);
5896 g_clear_object (&priv->rdisc);
5899 /******************************************/
5901 static const char *ip6_properties_to_save[] = {
5905 "accept_ra_rtr_pref",
5912 save_ip6_properties (NMDevice *self)
5914 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5915 const char *ifname = nm_device_get_ip_iface (self);
5919 g_hash_table_remove_all (priv->ip6_saved_properties);
5921 for (i = 0; i < G_N_ELEMENTS (ip6_properties_to_save); i++) {
5922 value = nm_platform_sysctl_get (NM_PLATFORM_GET, nm_utils_ip6_property_path (ifname, ip6_properties_to_save[i]));
5924 g_hash_table_insert (priv->ip6_saved_properties,
5925 (char *) ip6_properties_to_save[i],
5932 restore_ip6_properties (NMDevice *self)
5934 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5935 GHashTableIter iter;
5936 gpointer key, value;
5938 g_hash_table_iter_init (&iter, priv->ip6_saved_properties);
5939 while (g_hash_table_iter_next (&iter, &key, &value)) {
5940 /* Don't touch "disable_ipv6" if we're doing userland IPv6LL */
5941 if (priv->nm_ipv6ll && strcmp (key, "disable_ipv6") == 0)
5943 nm_device_ipv6_sysctl_set (self, key, value);
5948 set_disable_ipv6 (NMDevice *self, const char *value)
5950 /* We only touch disable_ipv6 when NM is not managing the IPv6LL address */
5951 if (NM_DEVICE_GET_PRIVATE (self)->nm_ipv6ll == FALSE)
5952 nm_device_ipv6_sysctl_set (self, "disable_ipv6", value);
5956 set_nm_ipv6ll (NMDevice *self, gboolean enable)
5958 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
5959 int ifindex = nm_device_get_ip_ifindex (self);
5962 if (!nm_platform_check_support_user_ipv6ll (NM_PLATFORM_GET))
5965 priv->nm_ipv6ll = enable;
5967 const char *detail = enable ? "enable" : "disable";
5969 _LOGD (LOGD_IP6, "will %s userland IPv6LL", detail);
5970 if (!nm_platform_link_set_user_ipv6ll_enabled (NM_PLATFORM_GET, ifindex, enable))
5971 _LOGW (LOGD_IP6, "failed to %s userspace IPv6LL address handling", detail);
5974 /* Bounce IPv6 to ensure the kernel stops IPv6LL address generation */
5975 value = nm_platform_sysctl_get (NM_PLATFORM_GET,
5976 nm_utils_ip6_property_path (nm_device_get_ip_iface (self), "disable_ipv6"));
5977 if (g_strcmp0 (value, "0") == 0)
5978 nm_device_ipv6_sysctl_set (self, "disable_ipv6", "1");
5981 /* Ensure IPv6 is enabled */
5982 nm_device_ipv6_sysctl_set (self, "disable_ipv6", "0");
5988 /************************************************************************/
5990 static NMSettingIP6ConfigPrivacy
5991 _ip6_privacy_clamp (NMSettingIP6ConfigPrivacy use_tempaddr)
5993 switch (use_tempaddr) {
5994 case NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED:
5995 case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR:
5996 case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR:
5997 return use_tempaddr;
5999 return NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN;
6003 static NMSettingIP6ConfigPrivacy
6004 _ip6_privacy_get (NMDevice *self)
6006 NMSettingIP6ConfigPrivacy ip6_privacy;
6007 gs_free char *value = NULL;
6008 NMConnection *connection;
6010 g_return_val_if_fail (self, NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN);
6012 /* 1.) First look at the per-connection setting. If it is not -1 (unknown),
6014 connection = nm_device_get_applied_connection (self);
6016 NMSettingIPConfig *s_ip6 = nm_connection_get_setting_ip6_config (connection);
6019 ip6_privacy = nm_setting_ip6_config_get_ip6_privacy (NM_SETTING_IP6_CONFIG (s_ip6));
6020 ip6_privacy = _ip6_privacy_clamp (ip6_privacy);
6021 if (ip6_privacy != NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN)
6026 value = nm_config_data_get_connection_default (NM_CONFIG_GET_DATA,
6027 "ipv6.ip6-privacy", self);
6029 /* 2.) use the default value from the configuration. */
6030 ip6_privacy = _nm_utils_ascii_str_to_int64 (value, 10,
6031 NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN,
6032 NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR,
6033 NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN);
6034 if (ip6_privacy != NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN)
6037 /* 3.) No valid default-value configured. Fallback to reading sysctl.
6039 * Instead of reading static config files in /etc, just read the current sysctl value.
6040 * This works as NM only writes to "/proc/sys/net/ipv6/conf/IFNAME/use_tempaddr", but leaves
6041 * the "default" entry untouched. */
6042 ip6_privacy = nm_platform_sysctl_get_int32 (NM_PLATFORM_GET, "/proc/sys/net/ipv6/conf/default/use_tempaddr", NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN);
6043 return _ip6_privacy_clamp (ip6_privacy);
6046 /****************************************************************/
6049 ip6_requires_slaves (NMConnection *connection)
6053 method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
6055 /* SLAAC, DHCP, and Link-Local depend on connectivity (and thus slaves)
6056 * to complete addressing. SLAAC and DHCP obviously need a peer to
6057 * provide a prefix, while Link-Local must perform DAD on the local link.
6059 return strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0
6060 || strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0
6061 || strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0;
6064 static NMActStageReturn
6065 act_stage3_ip6_config_start (NMDevice *self,
6066 NMIP6Config **out_config,
6067 NMDeviceStateReason *reason)
6069 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6070 NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
6071 NMConnection *connection;
6073 NMSettingIP6ConfigPrivacy ip6_privacy = NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN;
6074 const char *ip6_privacy_str = "0\n";
6076 gboolean ready_slaves;
6078 g_return_val_if_fail (reason != NULL, NM_ACT_STAGE_RETURN_FAILURE);
6080 connection = nm_device_get_applied_connection (self);
6081 g_assert (connection);
6083 if ( connection_ip6_method_requires_carrier (connection, NULL)
6085 && !priv->carrier) {
6086 _LOGI (LOGD_IP6 | LOGD_DEVICE,
6087 "IPv6 config waiting until carrier is on");
6088 return NM_ACT_STAGE_RETURN_WAIT;
6091 if (priv->is_master && ip6_requires_slaves (connection)) {
6092 /* If the master has no ready slaves, and depends on slaves for
6093 * a successful IPv6 attempt, then postpone IPv6 addressing.
6095 slaves = nm_device_master_get_slaves (self);
6096 ready_slaves = NM_DEVICE_GET_CLASS (self)->have_any_ready_slaves (self, slaves);
6097 g_slist_free (slaves);
6099 if (ready_slaves == FALSE) {
6100 _LOGI (LOGD_DEVICE | LOGD_IP6,
6101 "IPv6 config waiting until slaves are ready");
6102 return NM_ACT_STAGE_RETURN_WAIT;
6106 priv->dhcp6_mode = NM_RDISC_DHCP_LEVEL_NONE;
6108 method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
6110 if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_IGNORE) == 0) {
6111 if (!priv->master) {
6112 gboolean old_nm_ipv6ll = priv->nm_ipv6ll;
6114 /* When activating an IPv6 'ignore' connection we need to revert back
6115 * to kernel IPv6LL, but the kernel won't actually assign an address
6116 * to the interface until disable_ipv6 is bounced.
6118 set_nm_ipv6ll (self, FALSE);
6119 if (old_nm_ipv6ll == TRUE)
6120 nm_device_ipv6_sysctl_set (self, "disable_ipv6", "1");
6121 restore_ip6_properties (self);
6123 return NM_ACT_STAGE_RETURN_STOP;
6126 /* Ensure the MTU makes sense. If it was below 1280 the kernel would not
6127 * expose any ipv6 sysctls or allow presence of any addresses on the interface,
6128 * including LL, which * would make it impossible to autoconfigure MTU to a
6130 if (!nm_device_uses_assumed_connection (self))
6131 nm_device_ipv6_set_mtu (self, priv->ip6_mtu);
6133 /* Any method past this point requires an IPv6LL address. Use NM-controlled
6134 * IPv6LL if this is not an assumed connection, since assumed connections
6135 * will already have IPv6 set up.
6137 if (!nm_device_uses_assumed_connection (self))
6138 set_nm_ipv6ll (self, TRUE);
6140 /* Re-enable IPv6 on the interface */
6141 set_disable_ipv6 (self, "0");
6143 ip6_privacy = _ip6_privacy_get (self);
6145 if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0) {
6146 if (!addrconf6_start (self, ip6_privacy)) {
6147 /* IPv6 might be disabled; allow IPv4 to proceed */
6148 ret = NM_ACT_STAGE_RETURN_STOP;
6150 ret = NM_ACT_STAGE_RETURN_POSTPONE;
6151 } else if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL) == 0) {
6152 ret = linklocal6_start (self);
6153 } else if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_DHCP) == 0) {
6154 priv->dhcp6_mode = NM_RDISC_DHCP_LEVEL_MANAGED;
6155 if (!dhcp6_start (self, TRUE, reason)) {
6156 /* IPv6 might be disabled; allow IPv4 to proceed */
6157 ret = NM_ACT_STAGE_RETURN_STOP;
6159 ret = NM_ACT_STAGE_RETURN_POSTPONE;
6160 } else if (strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_MANUAL) == 0) {
6161 /* New blank config */
6162 *out_config = nm_ip6_config_new (nm_device_get_ip_ifindex (self));
6163 g_assert (*out_config);
6165 ret = NM_ACT_STAGE_RETURN_SUCCESS;
6167 _LOGW (LOGD_IP6, "unhandled IPv6 config method '%s'; will fail", method);
6169 /* Other methods (shared) aren't implemented yet */
6171 switch (ip6_privacy) {
6172 case NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN:
6173 case NM_SETTING_IP6_CONFIG_PRIVACY_DISABLED:
6174 ip6_privacy_str = "0";
6176 case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_PUBLIC_ADDR:
6177 ip6_privacy_str = "1";
6179 case NM_SETTING_IP6_CONFIG_PRIVACY_PREFER_TEMP_ADDR:
6180 ip6_privacy_str = "2";
6183 nm_device_ipv6_sysctl_set (self, "use_tempaddr", ip6_privacy_str);
6189 * nm_device_activate_stage3_ip4_start:
6192 * Try starting IPv4 configuration.
6195 nm_device_activate_stage3_ip4_start (NMDevice *self)
6197 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6198 NMActStageReturn ret;
6199 NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
6200 NMIP4Config *ip4_config = NULL;
6202 g_assert (priv->ip4_state == IP_WAIT);
6204 priv->ip4_state = IP_CONF;
6205 ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip4_config_start (self, &ip4_config, &reason);
6206 if (ret == NM_ACT_STAGE_RETURN_SUCCESS) {
6207 g_assert (ip4_config);
6208 nm_device_activate_schedule_ip4_config_result (self, ip4_config);
6209 g_object_unref (ip4_config);
6210 } else if (ret == NM_ACT_STAGE_RETURN_FAILURE) {
6211 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, reason);
6213 } else if (ret == NM_ACT_STAGE_RETURN_STOP) {
6215 priv->ip4_state = IP_FAIL;
6216 } else if (ret == NM_ACT_STAGE_RETURN_WAIT) {
6217 /* Wait for something to try IP config again */
6218 priv->ip4_state = IP_WAIT;
6220 g_assert (ret == NM_ACT_STAGE_RETURN_POSTPONE);
6226 * nm_device_activate_stage3_ip6_start:
6229 * Try starting IPv6 configuration.
6232 nm_device_activate_stage3_ip6_start (NMDevice *self)
6234 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6235 NMActStageReturn ret;
6236 NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
6237 NMIP6Config *ip6_config = NULL;
6239 g_assert (priv->ip6_state == IP_WAIT);
6241 priv->ip6_state = IP_CONF;
6242 ret = NM_DEVICE_GET_CLASS (self)->act_stage3_ip6_config_start (self, &ip6_config, &reason);
6243 if (ret == NM_ACT_STAGE_RETURN_SUCCESS) {
6244 g_assert (ip6_config);
6245 /* Here we get a static IPv6 config, like for Shared where it's
6246 * autogenerated or from modems where it comes from ModemManager.
6248 g_warn_if_fail (priv->ac_ip6_config == NULL);
6249 priv->ac_ip6_config = ip6_config;
6250 nm_device_activate_schedule_ip6_config_result (self);
6251 } else if (ret == NM_ACT_STAGE_RETURN_FAILURE) {
6252 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, reason);
6254 } else if (ret == NM_ACT_STAGE_RETURN_STOP) {
6255 /* Activation not wanted */
6256 priv->ip6_state = IP_FAIL;
6257 } else if (ret == NM_ACT_STAGE_RETURN_FINISH) {
6258 /* Early finish, nothing more to do */
6259 priv->ip6_state = IP_DONE;
6260 check_ip_done (self);
6261 } else if (ret == NM_ACT_STAGE_RETURN_WAIT) {
6262 /* Wait for something to try IP config again */
6263 priv->ip6_state = IP_WAIT;
6265 g_assert (ret == NM_ACT_STAGE_RETURN_POSTPONE);
6271 * activate_stage3_ip_config_start
6273 * Begin automatic/manual IP configuration
6277 activate_stage3_ip_config_start (NMDevice *self)
6279 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6280 NMActiveConnection *master;
6281 NMDevice *master_device;
6283 priv->ip4_state = priv->ip6_state = IP_WAIT;
6285 nm_device_state_changed (self, NM_DEVICE_STATE_IP_CONFIG, NM_DEVICE_STATE_REASON_NONE);
6287 /* Device should be up before we can do anything with it */
6288 if (!nm_platform_link_is_up (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self)))
6289 _LOGW (LOGD_DEVICE, "interface %s not up for IP configuration", nm_device_get_ip_iface (self));
6291 /* If the device is a slave, then we don't do any IP configuration but we
6292 * use the IP config stage to indicate to the master we're ready for
6293 * enslavement. If the master is already activating, it will have tried to
6294 * enslave us when we changed state to IP_CONFIG, causing us to queue a
6295 * transition to SECONDARIES (or FAILED if the enslavement failed), with
6296 * our IP states set to IP_DONE either way. If the master isn't yet
6297 * activating, then they'll still be in IP_WAIT. Either way, we bail out
6298 * of IP config here.
6300 master = nm_active_connection_get_master (NM_ACTIVE_CONNECTION (priv->act_request));
6302 master_device = nm_active_connection_get_device (master);
6303 if (priv->ip4_state == IP_WAIT && priv->ip6_state == IP_WAIT) {
6304 _LOGI (LOGD_DEVICE, "Activation: connection '%s' waiting on master '%s'",
6305 nm_connection_get_id (nm_device_get_applied_connection (self)),
6306 master_device ? nm_device_get_iface (master_device) : "(unknown)");
6312 if ( nm_device_activate_ip4_state_in_wait (self)
6313 && !nm_device_activate_stage3_ip4_start (self))
6317 if ( nm_device_activate_ip6_state_in_wait (self)
6318 && !nm_device_activate_stage3_ip6_start (self))
6321 check_ip_failed (self, TRUE);
6325 fw_change_zone_handle (NMDevice *self,
6326 NMFirewallManagerCallId call_id,
6329 NMDevicePrivate *priv;
6331 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
6333 priv = NM_DEVICE_GET_PRIVATE (self);
6335 g_return_val_if_fail (priv->fw_call == call_id, FALSE);
6336 priv->fw_call = NULL;
6338 return !nm_utils_error_is_cancelled (error, FALSE);
6342 fw_change_zone_cb_stage2 (NMFirewallManager *firewall_manager,
6343 NMFirewallManagerCallId call_id,
6347 NMDevice *self = user_data;
6348 NMDevicePrivate *priv;
6350 if (!fw_change_zone_handle (self, call_id, error))
6353 /* FIXME: fail the device on error? */
6355 priv = NM_DEVICE_GET_PRIVATE (self);
6356 priv->fw_ready = TRUE;
6358 nm_device_activate_schedule_stage3_ip_config_start (self);
6362 fw_change_zone_cb_ip_check (NMFirewallManager *firewall_manager,
6363 NMFirewallManagerCallId call_id,
6367 NMDevice *self = user_data;
6369 if (!fw_change_zone_handle (self, call_id, error))
6372 /* FIXME: fail the device on error? */
6373 nm_device_start_ip_check (self);
6377 * nm_device_activate_schedule_stage3_ip_config_start
6379 * Schedule IP configuration start
6382 nm_device_activate_schedule_stage3_ip_config_start (NMDevice *self)
6384 NMDevicePrivate *priv;
6385 NMConnection *connection;
6386 NMSettingConnection *s_con = NULL;
6389 g_return_if_fail (NM_IS_DEVICE (self));
6391 priv = NM_DEVICE_GET_PRIVATE (self);
6392 g_return_if_fail (priv->act_request);
6394 /* Add the interface to the specified firewall zone */
6395 connection = nm_device_get_applied_connection (self);
6396 g_assert (connection);
6397 s_con = nm_connection_get_setting_connection (connection);
6399 if (!priv->fw_ready) {
6400 if (nm_device_uses_assumed_connection (self))
6401 priv->fw_ready = TRUE;
6403 if (!priv->fw_call) {
6404 zone = nm_setting_connection_get_zone (s_con);
6406 _LOGD (LOGD_DEVICE, "Activation: setting firewall zone '%s'", zone ? zone : "default");
6407 priv->fw_call = nm_firewall_manager_add_or_change_zone (nm_firewall_manager_get (),
6408 nm_device_get_ip_iface (self),
6411 fw_change_zone_cb_stage2,
6418 activation_source_schedule (self, activate_stage3_ip_config_start, AF_INET);
6421 static NMActStageReturn
6422 act_stage4_ip4_config_timeout (NMDevice *self, NMDeviceStateReason *reason)
6424 if (!get_ip_config_may_fail (self, AF_INET)) {
6425 *reason = NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE;
6426 return NM_ACT_STAGE_RETURN_FAILURE;
6428 return NM_ACT_STAGE_RETURN_SUCCESS;
6433 * nm_device_activate_stage4_ip4_config_timeout
6435 * Time out on retrieving the IPv4 config.
6439 activate_stage4_ip4_config_timeout (NMDevice *self)
6441 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6442 NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
6443 NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
6445 ret = NM_DEVICE_GET_CLASS (self)->act_stage4_ip4_config_timeout (self, &reason);
6446 if (ret == NM_ACT_STAGE_RETURN_POSTPONE)
6448 else if (ret == NM_ACT_STAGE_RETURN_FAILURE) {
6449 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, reason);
6452 g_assert (ret == NM_ACT_STAGE_RETURN_SUCCESS);
6454 priv->ip4_state = IP_FAIL;
6456 check_ip_failed (self, FALSE);
6461 * nm_device_activate_schedule_ip4_config_timeout
6463 * Deal with a timeout of the IPv4 configuration
6467 nm_device_activate_schedule_ip4_config_timeout (NMDevice *self)
6469 NMDevicePrivate *priv;
6471 g_return_if_fail (NM_IS_DEVICE (self));
6473 priv = NM_DEVICE_GET_PRIVATE (self);
6474 g_return_if_fail (priv->act_request);
6476 activation_source_schedule (self, activate_stage4_ip4_config_timeout, AF_INET);
6480 static NMActStageReturn
6481 act_stage4_ip6_config_timeout (NMDevice *self, NMDeviceStateReason *reason)
6483 if (!get_ip_config_may_fail (self, AF_INET6)) {
6484 *reason = NM_DEVICE_STATE_REASON_IP_CONFIG_UNAVAILABLE;
6485 return NM_ACT_STAGE_RETURN_FAILURE;
6488 return NM_ACT_STAGE_RETURN_SUCCESS;
6493 * activate_stage4_ip6_config_timeout
6495 * Time out on retrieving the IPv6 config.
6499 activate_stage4_ip6_config_timeout (NMDevice *self)
6501 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6502 NMActStageReturn ret = NM_ACT_STAGE_RETURN_FAILURE;
6503 NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
6505 ret = NM_DEVICE_GET_CLASS (self)->act_stage4_ip6_config_timeout (self, &reason);
6506 if (ret == NM_ACT_STAGE_RETURN_POSTPONE)
6508 if (ret == NM_ACT_STAGE_RETURN_FAILURE) {
6509 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, reason);
6512 g_assert (ret == NM_ACT_STAGE_RETURN_SUCCESS);
6514 priv->ip6_state = IP_FAIL;
6516 check_ip_failed (self, FALSE);
6521 * nm_device_activate_schedule_ip6_config_timeout
6523 * Deal with a timeout of the IPv6 configuration
6527 nm_device_activate_schedule_ip6_config_timeout (NMDevice *self)
6529 NMDevicePrivate *priv;
6531 g_return_if_fail (NM_IS_DEVICE (self));
6533 priv = NM_DEVICE_GET_PRIVATE (self);
6534 g_return_if_fail (priv->act_request);
6536 activation_source_schedule (self, activate_stage4_ip6_config_timeout, AF_INET6);
6542 char *modules[] = { "ip_tables", "iptable_nat", "nf_nat_ftp", "nf_nat_irc",
6543 "nf_nat_sip", "nf_nat_tftp", "nf_nat_pptp", "nf_nat_h323",
6548 if (!nm_platform_sysctl_set (NM_PLATFORM_GET, "/proc/sys/net/ipv4/ip_forward", "1")) {
6550 nm_log_err (LOGD_SHARING, "share: error starting IP forwarding: (%d) %s",
6551 errsv, strerror (errsv));
6555 if (!nm_platform_sysctl_set (NM_PLATFORM_GET, "/proc/sys/net/ipv4/ip_dynaddr", "1")) {
6557 nm_log_err (LOGD_SHARING, "share: error starting IP forwarding: (%d) %s",
6558 errsv, strerror (errsv));
6561 for (iter = modules; *iter; iter++)
6562 nm_utils_modprobe (NULL, FALSE, *iter, NULL);
6568 add_share_rule (NMActRequest *req, const char *table, const char *fmt, ...)
6573 va_start (args, fmt);
6574 cmd = g_strdup_vprintf (fmt, args);
6577 nm_act_request_add_share_rule (req, table, cmd);
6582 start_sharing (NMDevice *self, NMIP4Config *config)
6584 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6586 GError *error = NULL;
6587 char str_addr[INET_ADDRSTRLEN + 1];
6588 char str_mask[INET_ADDRSTRLEN + 1];
6589 guint32 netmask, network;
6590 const NMPlatformIP4Address *ip4_addr;
6591 const char *ip_iface;
6593 g_return_val_if_fail (config != NULL, FALSE);
6595 ip_iface = nm_device_get_ip_iface (self);
6597 ip4_addr = nm_ip4_config_get_address (config, 0);
6598 if (!ip4_addr || !ip4_addr->address)
6601 netmask = nm_utils_ip4_prefix_to_netmask (ip4_addr->plen);
6602 if (!inet_ntop (AF_INET, &netmask, str_mask, sizeof (str_mask)))
6605 network = ip4_addr->address & netmask;
6606 if (!inet_ntop (AF_INET, &network, str_addr, sizeof (str_addr)))
6612 req = nm_device_get_act_request (self);
6615 add_share_rule (req, "nat", "POSTROUTING --source %s/%s ! --destination %s/%s --jump MASQUERADE", str_addr, str_mask, str_addr, str_mask);
6616 add_share_rule (req, "filter", "FORWARD --destination %s/%s --out-interface %s --match state --state ESTABLISHED,RELATED --jump ACCEPT", str_addr, str_mask, ip_iface);
6617 add_share_rule (req, "filter", "FORWARD --source %s/%s --in-interface %s --jump ACCEPT", str_addr, str_mask, ip_iface);
6618 add_share_rule (req, "filter", "FORWARD --in-interface %s --out-interface %s --jump ACCEPT", ip_iface, ip_iface);
6619 add_share_rule (req, "filter", "FORWARD --out-interface %s --jump REJECT", ip_iface);
6620 add_share_rule (req, "filter", "FORWARD --in-interface %s --jump REJECT", ip_iface);
6621 add_share_rule (req, "filter", "INPUT --in-interface %s --protocol udp --destination-port 67 --jump ACCEPT", ip_iface);
6622 add_share_rule (req, "filter", "INPUT --in-interface %s --protocol tcp --destination-port 67 --jump ACCEPT", ip_iface);
6623 add_share_rule (req, "filter", "INPUT --in-interface %s --protocol udp --destination-port 53 --jump ACCEPT", ip_iface);
6624 add_share_rule (req, "filter", "INPUT --in-interface %s --protocol tcp --destination-port 53 --jump ACCEPT", ip_iface);
6626 nm_act_request_set_shared (req, TRUE);
6628 if (!nm_dnsmasq_manager_start (priv->dnsmasq_manager, config, &error)) {
6629 _LOGE (LOGD_SHARING, "share: (%s) failed to start dnsmasq: %s",
6630 ip_iface, error->message);
6631 g_error_free (error);
6632 nm_act_request_set_shared (req, FALSE);
6636 priv->dnsmasq_state_id = g_signal_connect (priv->dnsmasq_manager, NM_DNS_MASQ_MANAGER_STATE_CHANGED,
6637 G_CALLBACK (dnsmasq_state_changed_cb),
6643 arp_cleanup (NMDevice *self)
6645 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6647 if (priv->arping.announcing) {
6648 nm_arping_manager_destroy (priv->arping.announcing);
6649 priv->arping.announcing = NULL;
6654 arp_announce (NMDevice *self)
6656 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6657 NMConnection *connection;
6658 NMSettingIPConfig *s_ip4;
6660 const guint8 *hw_addr;
6661 size_t hw_addr_len = 0;
6665 hw_addr = nm_platform_link_get_address (NM_PLATFORM_GET,
6666 nm_device_get_ip_ifindex (self),
6669 if (!hw_addr_len || !hw_addr)
6672 /* We only care about manually-configured addresses; DHCP- and autoip-configured
6673 * ones should already have been seen on the network at this point.
6675 connection = nm_device_get_applied_connection (self);
6678 s_ip4 = nm_connection_get_setting_ip4_config (connection);
6681 num = nm_setting_ip_config_get_num_addresses (s_ip4);
6685 priv->arping.announcing = nm_arping_manager_new (nm_device_get_ip_ifindex (self));
6687 for (i = 0; i < num; i++) {
6688 NMIPAddress *ip = nm_setting_ip_config_get_address (s_ip4, i);
6691 if (inet_pton (AF_INET, nm_ip_address_get_address (ip), &addr) == 1)
6692 nm_arping_manager_add_address (priv->arping.announcing, addr);
6694 g_warn_if_reached ();
6697 nm_arping_manager_announce_addresses (priv->arping.announcing);
6701 activate_stage5_ip4_config_commit (NMDevice *self)
6703 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6706 NMConnection *connection;
6707 NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
6710 req = nm_device_get_act_request (self);
6712 connection = nm_act_request_get_applied_connection (req);
6713 g_assert (connection);
6715 /* Interface must be IFF_UP before IP config can be applied */
6716 ip_ifindex = nm_device_get_ip_ifindex (self);
6717 if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex) && !nm_device_uses_assumed_connection (self)) {
6718 nm_platform_link_set_up (NM_PLATFORM_GET, ip_ifindex, NULL);
6719 if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex))
6720 _LOGW (LOGD_DEVICE, "interface %s not up for IP configuration", nm_device_get_ip_iface (self));
6723 /* NULL to use the existing priv->dev_ip4_config */
6724 if (!ip4_config_merge_and_apply (self, NULL, TRUE, &reason)) {
6725 _LOGD (LOGD_DEVICE | LOGD_IP4, "Activation: Stage 5 of 5 (IPv4 Commit) failed");
6726 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, reason);
6730 /* Start IPv4 sharing if we need it */
6731 method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
6733 if (strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0) {
6734 if (!start_sharing (self, priv->ip4_config)) {
6735 _LOGW (LOGD_SHARING, "Activation: Stage 5 of 5 (IPv4 Commit) start sharing failed.");
6736 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_SHARED_START_FAILED);
6741 /* If IPv4 wasn't the first to complete, and DHCP was used, then ensure
6742 * dispatcher scripts get the DHCP lease information.
6744 if ( priv->dhcp4_client
6745 && nm_device_activate_ip4_state_in_conf (self)
6746 && (nm_device_get_state (self) > NM_DEVICE_STATE_IP_CONFIG)) {
6747 /* Notify dispatcher scripts of new DHCP4 config */
6748 nm_dispatcher_call (DISPATCHER_ACTION_DHCP4_CHANGE,
6749 nm_device_get_settings_connection (self),
6750 nm_device_get_applied_connection (self),
6757 arp_announce (self);
6759 nm_device_remove_pending_action (self, PENDING_ACTION_DHCP4, FALSE);
6761 /* Enter the IP_CHECK state if this is the first method to complete */
6762 priv->ip4_state = IP_DONE;
6763 check_ip_done (self);
6767 queued_ip4_config_change_clear (NMDevice *self)
6769 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6771 if (priv->queued_ip4_config_id) {
6772 _LOGD (LOGD_DEVICE, "clearing queued IP4 config change");
6773 g_source_remove (priv->queued_ip4_config_id);
6774 priv->queued_ip4_config_id = 0;
6779 queued_ip6_config_change_clear (NMDevice *self)
6781 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6783 if (priv->queued_ip6_config_id) {
6784 _LOGD (LOGD_DEVICE, "clearing queued IP6 config change");
6785 g_source_remove (priv->queued_ip6_config_id);
6786 priv->queued_ip6_config_id = 0;
6791 nm_device_activate_schedule_ip4_config_result (NMDevice *self, NMIP4Config *config)
6793 NMDevicePrivate *priv;
6795 g_return_if_fail (NM_IS_DEVICE (self));
6796 priv = NM_DEVICE_GET_PRIVATE (self);
6798 g_clear_object (&priv->dev_ip4_config);
6800 priv->dev_ip4_config = g_object_ref (config);
6802 queued_ip4_config_change_clear (self);
6803 activation_source_schedule (self, activate_stage5_ip4_config_commit, AF_INET);
6807 nm_device_activate_ip4_state_in_conf (NMDevice *self)
6809 g_return_val_if_fail (self != NULL, FALSE);
6810 return NM_DEVICE_GET_PRIVATE (self)->ip4_state == IP_CONF;
6814 nm_device_activate_ip4_state_in_wait (NMDevice *self)
6816 g_return_val_if_fail (self != NULL, FALSE);
6817 return NM_DEVICE_GET_PRIVATE (self)->ip4_state == IP_WAIT;
6821 activate_stage5_ip6_config_commit (NMDevice *self)
6823 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6825 NMConnection *connection;
6826 NMDeviceStateReason reason = NM_DEVICE_STATE_REASON_NONE;
6829 req = nm_device_get_act_request (self);
6831 connection = nm_act_request_get_applied_connection (req);
6832 g_assert (connection);
6834 /* Interface must be IFF_UP before IP config can be applied */
6835 ip_ifindex = nm_device_get_ip_ifindex (self);
6836 if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex) && !nm_device_uses_assumed_connection (self)) {
6837 nm_platform_link_set_up (NM_PLATFORM_GET, ip_ifindex, NULL);
6838 if (!nm_platform_link_is_up (NM_PLATFORM_GET, ip_ifindex))
6839 _LOGW (LOGD_DEVICE, "interface %s not up for IP configuration", nm_device_get_ip_iface (self));
6842 if (ip6_config_merge_and_apply (self, TRUE, &reason)) {
6843 if ( priv->dhcp6_mode != NM_RDISC_DHCP_LEVEL_NONE
6844 && priv->ip6_state == IP_CONF) {
6845 if (priv->dhcp6_ip6_config) {
6846 /* If IPv6 wasn't the first IP to complete, and DHCP was used,
6847 * then ensure dispatcher scripts get the DHCP lease information.
6849 nm_dispatcher_call (DISPATCHER_ACTION_DHCP6_CHANGE,
6850 nm_device_get_settings_connection (self),
6851 nm_device_get_applied_connection (self),
6857 /* still waiting for first dhcp6 lease. */
6862 nm_device_remove_pending_action (self, PENDING_ACTION_DHCP6, FALSE);
6863 nm_device_remove_pending_action (self, PENDING_ACTION_AUTOCONF6, FALSE);
6865 /* Enter the IP_CHECK state if this is the first method to complete */
6866 priv->ip6_state = IP_DONE;
6867 check_ip_done (self);
6869 _LOGW (LOGD_DEVICE | LOGD_IP6, "Activation: Stage 5 of 5 (IPv6 Commit) failed");
6870 nm_device_state_changed (self, NM_DEVICE_STATE_FAILED, reason);
6875 nm_device_activate_schedule_ip6_config_result (NMDevice *self)
6877 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6879 g_return_if_fail (NM_IS_DEVICE (self));
6881 /* If IP had previously failed, move it back to IP_CONF since we
6882 * clearly now have configuration.
6884 if (priv->ip6_state == IP_FAIL)
6885 priv->ip6_state = IP_CONF;
6887 activation_source_schedule (self, activate_stage5_ip6_config_commit, AF_INET6);
6891 nm_device_activate_ip6_state_in_conf (NMDevice *self)
6893 g_return_val_if_fail (self != NULL, FALSE);
6894 return NM_DEVICE_GET_PRIVATE (self)->ip6_state == IP_CONF;
6898 nm_device_activate_ip6_state_in_wait (NMDevice *self)
6900 g_return_val_if_fail (self != NULL, FALSE);
6901 return NM_DEVICE_GET_PRIVATE (self)->ip6_state == IP_WAIT;
6905 clear_act_request (NMDevice *self)
6907 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6909 if (!priv->act_request)
6912 nm_active_connection_set_default (NM_ACTIVE_CONNECTION (priv->act_request), FALSE);
6914 priv->master_ready_handled = FALSE;
6915 nm_clear_g_signal_handler (priv->act_request, &priv->master_ready_id);
6917 g_clear_object (&priv->act_request);
6918 _notify (self, PROP_ACTIVE_CONNECTION);
6922 dnsmasq_cleanup (NMDevice *self)
6924 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6926 if (!priv->dnsmasq_manager)
6929 nm_clear_g_signal_handler (priv->dnsmasq_manager, &priv->dnsmasq_state_id);
6931 nm_dnsmasq_manager_stop (priv->dnsmasq_manager);
6932 g_object_unref (priv->dnsmasq_manager);
6933 priv->dnsmasq_manager = NULL;
6937 _update_ip4_address (NMDevice *self)
6939 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6942 g_return_if_fail (NM_IS_DEVICE (self));
6944 if ( priv->ip4_config
6945 && ip_config_valid (priv->state)
6946 && nm_ip4_config_get_num_addresses (priv->ip4_config)) {
6947 addr = nm_ip4_config_get_address (priv->ip4_config, 0)->address;
6948 if (addr != priv->ip4_address) {
6949 priv->ip4_address = addr;
6950 _notify (self, PROP_IP4_ADDRESS);
6956 nm_device_get_is_nm_owned (NMDevice *self)
6958 return NM_DEVICE_GET_PRIVATE (self)->is_nm_owned;
6962 * delete_on_deactivate_link_delete
6964 * Function will be queued with g_idle_add to call
6965 * nm_platform_link_delete for the underlying resources
6969 delete_on_deactivate_link_delete (gpointer user_data)
6971 DeleteOnDeactivateData *data = user_data;
6972 NMDevice *self = data->device;
6974 _LOGD (LOGD_DEVICE, "delete_on_deactivate: cleanup and delete virtual link #%d (id=%u)",
6975 data->ifindex, data->idle_add_id);
6978 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (data->device);
6979 gs_free_error GError *error = NULL;
6981 g_object_remove_weak_pointer (G_OBJECT (data->device), (void **) &data->device);
6982 priv->delete_on_deactivate_data = NULL;
6984 if (!nm_device_unrealize (data->device, TRUE, &error))
6985 _LOGD (LOGD_DEVICE, "delete_on_deactivate: unrealizing %d failed (%s)", data->ifindex, error->message);
6987 nm_platform_link_delete (NM_PLATFORM_GET, data->ifindex);
6994 delete_on_deactivate_unschedule (NMDevice *self)
6996 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
6998 if (priv->delete_on_deactivate_data) {
6999 DeleteOnDeactivateData *data = priv->delete_on_deactivate_data;
7001 priv->delete_on_deactivate_data = NULL;
7003 g_source_remove (data->idle_add_id);
7004 g_object_remove_weak_pointer (G_OBJECT (self), (void **) &data->device);
7005 _LOGD (LOGD_DEVICE, "delete_on_deactivate: cancel cleanup and delete virtual link #%d (id=%u)",
7006 data->ifindex, data->idle_add_id);
7012 delete_on_deactivate_check_and_schedule (NMDevice *self, int ifindex)
7014 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
7015 DeleteOnDeactivateData *data;
7019 if (!priv->is_nm_owned)
7021 if (priv->queued_act_request)
7023 if (!nm_device_is_software (self) || !nm_device_is_real (self))
7025 if (nm_device_get_state (self) == NM_DEVICE_STATE_UNMANAGED)
7027 if (nm_device_get_state (self) == NM_DEVICE_STATE_UNAVAILABLE)
7029 delete_on_deactivate_unschedule (self); /* always cancel and reschedule */
7031 data = g_new (DeleteOnDeactivateData, 1);
7032 g_object_add_weak_pointer (G_OBJECT (self), (void **) &data->device);
7033 data->device = self;
7034 data->ifindex = ifindex;
7035 data->idle_add_id = g_idle_add (delete_on_deactivate_link_delete, data);
7036 priv->delete_on_deactivate_data = data;
7038 _LOGD (LOGD_DEVICE, "delete_on_deactivate: schedule cleanup and delete virtual link #%d (id=%u)",
7039 ifindex, data->idle_add_id);
7043 _cleanup_ip4_pre (NMDevice *self, CleanupType cleanup_type)
7045 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
7047 priv->ip4_state = IP_NONE;
7048 queued_ip4_config_change_clear (self);
7050 dhcp4_cleanup (self, cleanup_type, FALSE);
7052 dnsmasq_cleanup (self);
7053 ipv4ll_cleanup (self);
7057 _cleanup_ip6_pre (NMDevice *self, CleanupType cleanup_type)
7059 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
7061 priv->ip6_state = IP_NONE;
7062 queued_ip6_config_change_clear (self);
7064 dhcp6_cleanup (self, cleanup_type, FALSE);
7065 linklocal6_cleanup (self);
7066 addrconf6_cleanup (self);
7070 _hash_check_invalid_keys_impl (GHashTable *hash, const char *setting_name, GError **error, const char **argv)
7072 guint found_keys = 0;
7075 nm_assert (argv && argv[0]);
7077 #if NM_MORE_ASSERTS > 10
7078 /* Assert that the keys are unique. */
7080 gs_unref_hashtable GHashTable *check_dups = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, NULL);
7082 for (i = 0; argv[i]; i++) {
7083 if (!g_hash_table_add (check_dups, (char *) argv[i]))
7086 nm_assert (g_hash_table_size (check_dups) > 0);
7090 if (!hash || g_hash_table_size (hash) == 0)
7093 for (i = 0; argv[i]; i++) {
7094 if (g_hash_table_contains (hash, argv[i]))
7098 if (found_keys != g_hash_table_size (hash)) {
7099 GHashTableIter iter;
7100 const char *k = NULL;
7101 const char *first_invalid_key = NULL;
7106 g_hash_table_iter_init (&iter, hash);
7107 while (g_hash_table_iter_next (&iter, (gpointer *) &k, NULL)) {
7108 for (i = 0; argv[i]; i++) {
7109 if (!strcmp (argv[i], k)) {
7110 first_invalid_key = k;
7114 if (first_invalid_key)
7119 NM_DEVICE_ERROR_INCOMPATIBLE_CONNECTION,
7120 "Can't reapply changes to '%s%s%s' setting",
7121 setting_name ? : "",
7122 setting_name ? "." : "",
7123 first_invalid_key ? : "<UNKNOWN>");
7124 g_return_val_if_fail (first_invalid_key, FALSE);
7130 #define _hash_check_invalid_keys(hash, setting_name, error, ...) _hash_check_invalid_keys_impl (hash, setting_name, error, ((const char *[]) { __VA_ARGS__, NULL }))
7133 nm_device_reactivate_ip4_config (NMDevice *self,
7134 NMSettingIPConfig *s_ip4_old,
7135 NMSettingIPConfig *s_ip4_new)
7137 NMDevicePrivate *priv;
7139 g_return_if_fail (NM_IS_DEVICE (self));
7140 priv = NM_DEVICE_GET_PRIVATE (self);
7142 if (priv->ip4_state != IP_NONE) {
7143 g_clear_object (&priv->con_ip4_config);
7144 g_clear_object (&priv->ext_ip4_config);
7145 priv->con_ip4_config = nm_ip4_config_new (nm_device_get_ip_ifindex (self));
7146 nm_ip4_config_merge_setting (priv->con_ip4_config,
7148 nm_device_get_ip4_route_metric (self));
7150 if (strcmp (nm_setting_ip_config_get_method (s_ip4_new),
7151 nm_setting_ip_config_get_method (s_ip4_old))) {
7152 _cleanup_ip4_pre (self, CLEANUP_TYPE_DECONFIGURE);
7153 priv->ip4_state = IP_WAIT;
7154 if (!nm_device_activate_stage3_ip4_start (self))
7155 _LOGW (LOGD_IP4, "Failed to apply IPv4 configuration");
7157 if (!ip4_config_merge_and_apply (self, NULL, TRUE, NULL))
7158 _LOGW (LOGD_IP4, "Failed to reapply IPv4 configuration");
7164 nm_device_reactivate_ip6_config (NMDevice *self,
7165 NMSettingIPConfig *s_ip6_old,
7166 NMSettingIPConfig *s_ip6_new)
7168 NMDevicePrivate *priv;
7170 g_return_if_fail (NM_IS_DEVICE (self));
7171 priv = NM_DEVICE_GET_PRIVATE (self);
7173 if (priv->ip6_state != IP_NONE) {
7174 g_clear_object (&priv->con_ip6_config);
7175 g_clear_object (&priv->ext_ip6_config);
7176 priv->con_ip6_config = nm_ip6_config_new (nm_device_get_ip_ifindex (self));
7177 nm_ip6_config_merge_setting (priv->con_ip6_config,
7179 nm_device_get_ip6_route_metric (self));
7181 if (strcmp (nm_setting_ip_config_get_method (s_ip6_new),
7182 nm_setting_ip_config_get_method (s_ip6_old))) {
7183 _cleanup_ip6_pre (self, CLEANUP_TYPE_DECONFIGURE);
7184 priv->ip6_state = IP_WAIT;
7185 if (!nm_device_activate_stage3_ip6_start (self))
7186 _LOGW (LOGD_IP6, "Failed to apply IPv6 configuration");
7188 if (!ip6_config_merge_and_apply (self, TRUE, NULL))
7189 _LOGW (LOGD_IP4, "Failed to reapply IPv6 configuration");
7195 /* reapply_connection:
7196 * @connection: the new connection settings to be applied or %NULL to reapply
7197 * the current settings connection
7198 * @version_id: either zero, or the current version id for the applied
7200 * @error: the error if %FALSE is returned
7202 * Change configuration of an already configured device if possible.
7203 * Updates the device's applied connection upon success.
7205 * Return: %FALSE if the new configuration can not be reapplied.
7208 reapply_connection (NMDevice *self,
7209 NMConnection *connection,
7213 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
7214 NMConnection *applied = nm_device_get_applied_connection (self);
7215 gs_unref_object NMConnection *applied_clone = NULL;
7216 gs_unref_hashtable GHashTable *diffs = NULL;
7217 NMConnection *con_old, *con_new;
7218 NMSettingIPConfig *s_ip4_old, *s_ip4_new;
7219 NMSettingIPConfig *s_ip6_old, *s_ip6_new;
7221 if (priv->state != NM_DEVICE_STATE_ACTIVATED) {
7222 g_set_error_literal (error,
7224 NM_DEVICE_ERROR_NOT_ACTIVE,
7225 "Device is not activated");
7229 nm_connection_diff (connection,
7231 NM_SETTING_COMPARE_FLAG_IGNORE_TIMESTAMP |
7232 NM_SETTING_COMPARE_FLAG_IGNORE_SECRETS,
7235 /**************************************************************************
7236 * check for unsupported changes and reject to reapply
7237 *************************************************************************/
7238 if (!_hash_check_invalid_keys (diffs, NULL, error,
7239 NM_SETTING_IP4_CONFIG_SETTING_NAME,
7240 NM_SETTING_IP6_CONFIG_SETTING_NAME,
7241 NM_SETTING_CONNECTION_SETTING_NAME))
7244 if (!_hash_check_invalid_keys (diffs ? g_hash_table_lookup (diffs, NM_SETTING_CONNECTION_SETTING_NAME) : NULL,
7245 NM_SETTING_CONNECTION_SETTING_NAME,
7247 NM_SETTING_CONNECTION_ZONE,
7248 NM_SETTING_CONNECTION_METERED))
7251 if ( version_id != 0
7252 && version_id != nm_active_connection_version_id_get ((NMActiveConnection *) priv->act_request)) {
7253 g_set_error_literal (error,
7255 NM_DEVICE_ERROR_VERSION_ID_MISMATCH,
7256 "Reapply failed because device changed in the meantime and the version-id mismatches");
7260 /**************************************************************************
7261 * Update applied connection
7262 *************************************************************************/
7265 nm_active_connection_version_id_bump ((NMActiveConnection *) priv->act_request);
7267 _LOGD (LOGD_DEVICE, "reapply (version-id %llu%s)",
7268 (long long unsigned) nm_active_connection_version_id_get (((NMActiveConnection *) priv->act_request)),
7269 diffs ? "" : " (unmodified)");
7272 con_old = applied_clone = nm_simple_connection_new_clone (applied);
7274 nm_connection_replace_settings_from_connection (applied, connection);
7276 con_old = con_new = applied;
7278 s_ip4_new = nm_connection_get_setting_ip4_config (con_new);
7279 s_ip4_old = nm_connection_get_setting_ip4_config (con_old);
7280 s_ip6_new = nm_connection_get_setting_ip6_config (con_new);
7281 s_ip6_old = nm_connection_get_setting_ip6_config (con_old);
7283 /**************************************************************************
7285 *************************************************************************/
7287 nm_device_update_firewall_zone (self);
7288 nm_device_update_metered (self);
7290 nm_device_reactivate_ip4_config (self, s_ip4_old, s_ip4_new);
7291 nm_device_reactivate_ip6_config (self, s_ip6_old, s_ip6_new);
7297 NMConnection *connection;
7302 reapply_cb (NMDevice *self,
7303 GDBusMethodInvocation *context,
7304 NMAuthSubject *subject,
7308 ReapplyData *reapply_data = user_data;
7309 guint64 version_id = 0;
7310 gs_unref_object NMConnection *connection = NULL;
7311 GError *local = NULL;
7314 connection = reapply_data->connection;
7315 version_id = reapply_data->version_id;
7316 g_slice_free (ReapplyData, reapply_data);
7320 nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_REAPPLY, self, FALSE, subject, error->message);
7321 g_dbus_method_invocation_return_gerror (context, error);
7325 if (!reapply_connection (self,
7326 connection ? : (NMConnection *) nm_device_get_settings_connection (self),
7329 nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_REAPPLY, self, FALSE, subject, local->message);
7330 g_dbus_method_invocation_take_error (context, local);
7333 nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_REAPPLY, self, TRUE, subject, NULL);
7334 g_dbus_method_invocation_return_value (context, NULL);
7339 impl_device_reapply (NMDevice *self,
7340 GDBusMethodInvocation *context,
7345 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
7346 NMSettingsConnection *settings_connection;
7347 NMConnection *connection = NULL;
7348 GError *error = NULL;
7349 ReapplyData *reapply_data;
7351 /* No flags supported as of now. */
7353 error = g_error_new_literal (NM_DEVICE_ERROR,
7354 NM_DEVICE_ERROR_FAILED,
7355 "Invalid flags specified");
7356 nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_REAPPLY, self, FALSE, context, error->message);
7357 g_dbus_method_invocation_take_error (context, error);
7361 if (priv->state != NM_DEVICE_STATE_ACTIVATED) {
7362 error = g_error_new_literal (NM_DEVICE_ERROR,
7363 NM_DEVICE_ERROR_NOT_ACTIVE,
7364 "Device is not activated");
7365 nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_REAPPLY, self, FALSE, context, error->message);
7366 g_dbus_method_invocation_take_error (context, error);
7370 settings_connection = nm_device_get_settings_connection (self);
7371 g_return_if_fail (settings_connection);
7373 if (settings && g_variant_n_children (settings)) {
7374 /* New settings specified inline. */
7375 connection = _nm_simple_connection_new_from_dbus (settings,
7376 NM_SETTING_PARSE_FLAGS_STRICT
7377 | NM_SETTING_PARSE_FLAGS_NORMALIZE,
7380 g_prefix_error (&error, "The settings specified are invalid: ");
7381 nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_REAPPLY, self, FALSE, context, error->message);
7382 g_dbus_method_invocation_take_error (context, error);
7385 nm_connection_clear_secrets (connection);
7388 if (connection || version_id) {
7389 reapply_data = g_slice_new (ReapplyData);
7390 reapply_data->connection = connection;
7391 reapply_data->version_id = version_id;
7393 reapply_data = NULL;
7395 /* Ask the manager to authenticate this request for us */
7396 g_signal_emit (self, signals[AUTH_REQUEST], 0,
7398 nm_device_get_applied_connection (self),
7399 NM_AUTH_PERMISSION_NETWORK_CONTROL,
7405 /*****************************************************************************/
7408 get_applied_connection_cb (NMDevice *self,
7409 GDBusMethodInvocation *context,
7410 NMAuthSubject *subject,
7412 gpointer user_data /* possibly dangling pointer */)
7414 NMDevicePrivate *priv;
7415 NMConnection *applied_connection;
7418 g_return_if_fail (NM_IS_DEVICE (self));
7421 g_dbus_method_invocation_return_gerror (context, error);
7425 priv = NM_DEVICE_GET_PRIVATE (self);
7427 applied_connection = nm_device_get_applied_connection (self);
7429 if (!applied_connection) {
7430 error = g_error_new_literal (NM_DEVICE_ERROR,
7431 NM_DEVICE_ERROR_NOT_ACTIVE,
7432 "Device is not activated");
7433 g_dbus_method_invocation_take_error (context, error);
7437 if (applied_connection != user_data) {
7438 /* The applied connection changed due to a race. Reauthenticate. */
7439 g_signal_emit (self, signals[AUTH_REQUEST], 0,
7442 NM_AUTH_PERMISSION_NETWORK_CONTROL,
7444 get_applied_connection_cb,
7445 applied_connection /* no need take a ref. We will not dereference this pointer. */);
7449 settings = nm_connection_to_dbus (applied_connection, NM_CONNECTION_SERIALIZE_NO_SECRETS);
7451 settings = g_variant_new_array (G_VARIANT_TYPE ("{sa{sv}}"), NULL, 0);
7453 g_dbus_method_invocation_return_value (context,
7454 g_variant_new ("(@a{sa{sv}}t)",
7456 nm_active_connection_version_id_get ((NMActiveConnection *) priv->act_request)));
7460 impl_device_get_applied_connection (NMDevice *self,
7461 GDBusMethodInvocation *context,
7464 NMConnection *applied_connection;
7465 GError *error = NULL;
7467 g_return_if_fail (NM_IS_DEVICE (self));
7469 /* No flags supported as of now. */
7471 error = g_error_new_literal (NM_DEVICE_ERROR,
7472 NM_DEVICE_ERROR_FAILED,
7473 "Invalid flags specified");
7474 g_dbus_method_invocation_take_error (context, error);
7478 applied_connection = nm_device_get_applied_connection (self);
7479 if (!applied_connection) {
7480 error = g_error_new_literal (NM_DEVICE_ERROR,
7481 NM_DEVICE_ERROR_NOT_ACTIVE,
7482 "Device is not activated");
7483 g_dbus_method_invocation_take_error (context, error);
7487 /* Ask the manager to authenticate this request for us */
7488 g_signal_emit (self, signals[AUTH_REQUEST], 0,
7491 NM_AUTH_PERMISSION_NETWORK_CONTROL,
7493 get_applied_connection_cb,
7494 applied_connection /* no need take a ref. We will not dereference this pointer. */);
7497 /*****************************************************************************/
7500 disconnect_cb (NMDevice *self,
7501 GDBusMethodInvocation *context,
7502 NMAuthSubject *subject,
7506 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
7507 GError *local = NULL;
7510 g_dbus_method_invocation_return_gerror (context, error);
7511 nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DISCONNECT, self, FALSE, subject, error->message);
7516 if (priv->state <= NM_DEVICE_STATE_DISCONNECTED) {
7517 local = g_error_new_literal (NM_DEVICE_ERROR,
7518 NM_DEVICE_ERROR_NOT_ACTIVE,
7519 "Device is not active");
7520 nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DISCONNECT, self, FALSE, subject, local->message);
7521 g_dbus_method_invocation_take_error (context, local);
7523 nm_device_set_autoconnect (self, FALSE);
7525 nm_device_state_changed (self,
7526 NM_DEVICE_STATE_DEACTIVATING,
7527 NM_DEVICE_STATE_REASON_USER_REQUESTED);
7528 g_dbus_method_invocation_return_value (context, NULL);
7529 nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DISCONNECT, self, TRUE, subject, NULL);
7534 _clear_queued_act_request (NMDevicePrivate *priv)
7536 if (priv->queued_act_request) {
7537 nm_active_connection_set_state ((NMActiveConnection *) priv->queued_act_request, NM_ACTIVE_CONNECTION_STATE_DEACTIVATED);
7538 g_clear_object (&priv->queued_act_request);
7543 impl_device_disconnect (NMDevice *self, GDBusMethodInvocation *context)
7545 NMConnection *connection;
7546 GError *error = NULL;
7548 if (NM_DEVICE_GET_PRIVATE (self)->act_request == NULL) {
7549 error = g_error_new_literal (NM_DEVICE_ERROR,
7550 NM_DEVICE_ERROR_NOT_ACTIVE,
7551 "This device is not active");
7552 g_dbus_method_invocation_take_error (context, error);
7556 connection = nm_device_get_applied_connection (self);
7557 g_assert (connection);
7559 /* Ask the manager to authenticate this request for us */
7560 g_signal_emit (self, signals[AUTH_REQUEST], 0,
7563 NM_AUTH_PERMISSION_NETWORK_CONTROL,
7570 delete_cb (NMDevice *self,
7571 GDBusMethodInvocation *context,
7572 NMAuthSubject *subject,
7576 GError *local = NULL;
7579 g_dbus_method_invocation_return_gerror (context, error);
7580 nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DELETE, self, FALSE, subject, error->message);
7585 nm_audit_log_device_op (NM_AUDIT_OP_DEVICE_DELETE, self, TRUE, subject, NULL);
7586 if (nm_device_unrealize (self, TRUE, &local))
7587 g_dbus_method_invocation_return_value (context, NULL);
7589 g_dbus_method_invocation_take_error (context, local);
7593 impl_device_delete (NMDevice *self, GDBusMethodInvocation *context)
7595 GError *error = NULL;
7597 if (!nm_device_is_software (self) || !nm_device_is_real (self)) {
7598 error = g_error_new_literal (NM_DEVICE_ERROR,
7599 NM_DEVICE_ERROR_NOT_SOFTWARE,
7600 "This device is not a software device or is not realized");
7601 g_dbus_method_invocation_take_error (context, error);
7605 /* Ask the manager to authenticate this request for us */
7606 g_signal_emit (self, signals[AUTH_REQUEST], 0,
7609 NM_AUTH_PERMISSION_NETWORK_CONTROL,
7616 _device_activate (NMDevice *self, NMActRequest *req)
7618 NMDevicePrivate *priv;
7619 NMConnection *connection;
7621 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
7622 g_return_val_if_fail (NM_IS_ACT_REQUEST (req), FALSE);
7623 g_return_val_if_fail (nm_device_get_managed (self, FALSE), FALSE);
7625 /* Ensure the activation request is still valid; the master may have
7626 * already failed in which case activation of this device should not proceed.
7628 if (nm_active_connection_get_state (NM_ACTIVE_CONNECTION (req)) >= NM_ACTIVE_CONNECTION_STATE_DEACTIVATING)
7631 priv = NM_DEVICE_GET_PRIVATE (self);
7633 connection = nm_act_request_get_applied_connection (req);
7634 g_assert (connection);
7636 _LOGI (LOGD_DEVICE, "Activation: starting connection '%s' (%s)",
7637 nm_connection_get_id (connection),
7638 nm_connection_get_uuid (connection));
7640 delete_on_deactivate_unschedule (self);
7642 /* note: don't notify D-Bus of the new AC here, but do it later when
7643 * changing state to PREPARE so that the two properties change together.
7645 priv->act_request = g_object_ref (req);
7647 nm_device_activate_schedule_stage1_device_prepare (self);
7652 _carrier_wait_check_queued_act_request (NMDevice *self)
7654 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
7655 NMActRequest *queued_req;
7657 if ( !priv->queued_act_request
7658 || !priv->queued_act_request_is_waiting_for_carrier)
7661 priv->queued_act_request_is_waiting_for_carrier = FALSE;
7662 if (!priv->carrier) {
7663 _LOGD (LOGD_DEVICE, "Cancel queued activation request as we have no carrier after timeout");
7664 _clear_queued_act_request (priv);
7666 _LOGD (LOGD_DEVICE, "Activate queued activation request as we now have carrier");
7667 queued_req = priv->queued_act_request;
7668 priv->queued_act_request = NULL;
7669 _device_activate (self, queued_req);
7670 g_object_unref (queued_req);
7675 _carrier_wait_check_act_request_must_queue (NMDevice *self, NMActRequest *req)
7677 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
7678 NMConnection *connection;
7680 /* If we have carrier or if we are not waiting for it, the activation
7681 * request is not blocked waiting for carrier. */
7684 if (priv->carrier_wait_id == 0)
7687 connection = nm_act_request_get_applied_connection (req);
7688 if (!connection_requires_carrier (connection))
7691 if (!nm_device_check_connection_available (self, connection, NM_DEVICE_CHECK_CON_AVAILABLE_ALL, NULL)) {
7692 /* We passed all @flags we have, and no @specific_object.
7693 * This equals maximal availability, if a connection is not available
7694 * in this case, it is not waiting for carrier.
7696 * Actually, why are we even trying to activate it? Strange, but whatever
7697 * the reason, don't wait for carrier.
7702 if (nm_device_check_connection_available (self, connection, NM_DEVICE_CHECK_CON_AVAILABLE_ALL & ~_NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST_WAITING_CARRIER, NULL)) {
7703 /* The connection was available with flags ALL, and it is still available
7704 * if we pretend not to wait for carrier. That means that the
7705 * connection is available now, and does not wait for carrier.
7707 * Since the flags increase the availability of a connection, when checking
7708 * ALL&~WAITING_CARRIER, it means that we certainly would wait for carrier. */
7712 /* The activation request must wait for carrier. */
7717 nm_device_steal_connection (NMDevice *self, NMSettingsConnection *connection)
7719 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
7721 _LOGW (LOGD_DEVICE, "disconnecting connection '%s' for new activation request.",
7722 nm_settings_connection_get_id (connection));
7724 if ( priv->queued_act_request
7725 && connection == nm_active_connection_get_settings_connection (NM_ACTIVE_CONNECTION (priv->queued_act_request)))
7726 _clear_queued_act_request (priv);
7728 if ( priv->act_request
7729 && connection == nm_active_connection_get_settings_connection (NM_ACTIVE_CONNECTION (priv->act_request))
7730 && priv->state < NM_DEVICE_STATE_DEACTIVATING)
7731 nm_device_state_changed (self,
7732 NM_DEVICE_STATE_DEACTIVATING,
7733 NM_DEVICE_STATE_REASON_NEW_ACTIVATION);
7737 nm_device_queue_activation (NMDevice *self, NMActRequest *req)
7739 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
7740 gboolean must_queue;
7742 must_queue = _carrier_wait_check_act_request_must_queue (self, req);
7744 if (!priv->act_request && !must_queue && nm_device_is_real (self)) {
7745 /* Just activate immediately */
7746 if (!_device_activate (self, req))
7747 g_assert_not_reached ();
7751 /* supercede any already-queued request */
7752 _clear_queued_act_request (priv);
7753 priv->queued_act_request = g_object_ref (req);
7754 priv->queued_act_request_is_waiting_for_carrier = must_queue;
7756 _LOGD (LOGD_DEVICE, "queue activation request waiting for %s", must_queue ? "carrier" : "currently active connection to disconnect");
7758 /* Deactivate existing activation request first */
7759 if (priv->act_request) {
7760 _LOGI (LOGD_DEVICE, "disconnecting for new activation request.");
7761 nm_device_state_changed (self,
7762 NM_DEVICE_STATE_DEACTIVATING,
7763 NM_DEVICE_STATE_REASON_NEW_ACTIVATION);
7768 * nm_device_is_activating
7770 * Return whether or not the device is currently activating itself.
7774 nm_device_is_activating (NMDevice *self)
7776 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
7777 NMDeviceState state;
7779 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
7781 state = nm_device_get_state (self);
7782 if (state >= NM_DEVICE_STATE_PREPARE && state <= NM_DEVICE_STATE_SECONDARIES)
7785 /* There's a small race between the time when stage 1 is scheduled
7786 * and when the device actually sets STATE_PREPARE when the activation
7787 * handler is actually run. If there's an activation handler scheduled
7788 * we're activating anyway.
7790 return priv->act_handle4.id ? TRUE : FALSE;
7793 /* IP Configuration stuff */
7796 nm_device_get_dhcp4_config (NMDevice *self)
7798 g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
7800 return NM_DEVICE_GET_PRIVATE (self)->dhcp4_config;
7804 nm_device_get_ip4_config (NMDevice *self)
7806 g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
7808 return NM_DEVICE_GET_PRIVATE (self)->ip4_config;
7813 nm_device_set_ip4_config (NMDevice *self,
7814 NMIP4Config *new_config,
7815 guint32 default_route_metric,
7817 gboolean routes_full_sync,
7818 NMDeviceStateReason *reason)
7820 NMDevicePrivate *priv;
7821 NMIP4Config *old_config = NULL;
7822 gboolean has_changes = FALSE;
7823 gboolean success = TRUE;
7824 NMDeviceStateReason reason_local = NM_DEVICE_STATE_REASON_NONE;
7825 int ip_ifindex, config_ifindex;
7827 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
7829 priv = NM_DEVICE_GET_PRIVATE (self);
7830 ip_ifindex = nm_device_get_ip_ifindex (self);
7833 config_ifindex = nm_ip4_config_get_ifindex (new_config);
7834 if (config_ifindex > 0)
7835 g_return_val_if_fail (ip_ifindex == config_ifindex, FALSE);
7838 old_config = priv->ip4_config;
7840 /* Always commit to nm-platform to update lifetimes */
7841 if (commit && new_config) {
7842 gboolean assumed = nm_device_uses_assumed_connection (self);
7844 nm_device_set_mtu (self, nm_ip4_config_get_mtu (new_config));
7846 /* For assumed devices we must not touch the kernel-routes, such as the device-route.
7847 * FIXME: this is wrong in case where "assumed" means "take-over-seamlessly". In this
7848 * case, we should manage the device route, for example on new DHCP lease. */
7849 success = nm_ip4_config_commit (new_config, ip_ifindex,
7851 assumed ? (gint64) -1 : (gint64) default_route_metric);
7853 reason_local = NM_DEVICE_STATE_REASON_CONFIG_FAILED;
7858 /* has_changes is set only on relevant changes, because when the configuration changes,
7859 * this causes a re-read and reset. This should only happen for relevant changes */
7860 nm_ip4_config_replace (old_config, new_config, &has_changes);
7862 _LOGD (LOGD_IP4, "update IP4Config instance (%s)",
7863 nm_exported_object_get_path (NM_EXPORTED_OBJECT (old_config)));
7867 priv->ip4_config = g_object_ref (new_config);
7869 if (success && !nm_exported_object_is_exported (NM_EXPORTED_OBJECT (new_config)))
7870 nm_exported_object_export (NM_EXPORTED_OBJECT (new_config));
7872 _LOGD (LOGD_IP4, "set IP4Config instance (%s)",
7873 nm_exported_object_get_path (NM_EXPORTED_OBJECT (new_config)));
7875 } else if (old_config) {
7877 priv->ip4_config = NULL;
7878 _LOGD (LOGD_IP4, "clear IP4Config instance (%s)",
7879 nm_exported_object_get_path (NM_EXPORTED_OBJECT (old_config)));
7880 /* Device config is invalid if combined config is invalid */
7881 g_clear_object (&priv->dev_ip4_config);
7884 nm_default_route_manager_ip4_update_default_route (nm_default_route_manager_get (), self);
7887 _update_ip4_address (self);
7889 if (old_config != priv->ip4_config)
7890 _notify (self, PROP_IP4_CONFIG);
7891 g_signal_emit (self, signals[IP4_CONFIG_CHANGED], 0, priv->ip4_config, old_config);
7893 if (old_config != priv->ip4_config)
7894 nm_exported_object_clear_and_unexport (&old_config);
7896 if (nm_device_uses_generated_assumed_connection (self)) {
7897 NMConnection *connection = nm_device_get_applied_connection (self);
7898 NMConnection *settings_connection = NM_CONNECTION (nm_device_get_settings_connection (self));
7901 g_object_freeze_notify (G_OBJECT (connection));
7902 g_object_freeze_notify (G_OBJECT (settings_connection));
7904 nm_connection_remove_setting (settings_connection, NM_TYPE_SETTING_IP4_CONFIG);
7905 s_ip4 = nm_ip4_config_create_setting (priv->ip4_config);
7906 nm_connection_add_setting (settings_connection, s_ip4);
7908 nm_connection_remove_setting (connection, NM_TYPE_SETTING_IP4_CONFIG);
7909 s_ip4 = nm_ip4_config_create_setting (priv->ip4_config);
7910 nm_connection_add_setting (connection, s_ip4);
7912 g_object_thaw_notify (G_OBJECT (settings_connection));
7913 g_object_thaw_notify (G_OBJECT (connection));
7916 nm_device_queue_recheck_assume (self);
7920 *reason = reason_local;
7926 _replace_vpn_config_in_list (GSList **plist, GObject *old, GObject *new)
7930 /* Below, assert that @new is not yet tracked, but still behave
7931 * correctly in any case. Don't complain for missing @old since
7932 * it could have been removed when the parent device became
7936 && (old_link = g_slist_find (*plist, old))) {
7939 old_link->data = g_object_ref (new);
7941 *plist = g_slist_delete_link (*plist, old_link);
7942 g_object_unref (old);
7948 if (!g_slist_find (*plist, new))
7949 *plist = g_slist_append (*plist, g_object_ref (new));
7951 g_return_val_if_reached (TRUE);
7959 nm_device_replace_vpn4_config (NMDevice *self, NMIP4Config *old, NMIP4Config *config)
7961 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
7963 if (!_replace_vpn_config_in_list (&priv->vpn4_configs, (GObject *) old, (GObject *) config))
7966 /* NULL to use existing configs */
7967 if (!ip4_config_merge_and_apply (self, NULL, TRUE, NULL))
7968 _LOGW (LOGD_IP4, "failed to set VPN routes for device");
7972 nm_device_set_wwan_ip4_config (NMDevice *self, NMIP4Config *config)
7974 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
7976 if (priv->wwan_ip4_config == config)
7979 g_clear_object (&priv->wwan_ip4_config);
7981 priv->wwan_ip4_config = g_object_ref (config);
7983 /* NULL to use existing configs */
7984 if (!ip4_config_merge_and_apply (self, NULL, TRUE, NULL))
7985 _LOGW (LOGD_IP4, "failed to set WWAN IPv4 configuration");
7989 nm_device_set_ip6_config (NMDevice *self,
7990 NMIP6Config *new_config,
7992 gboolean routes_full_sync,
7993 NMDeviceStateReason *reason)
7995 NMDevicePrivate *priv;
7996 NMIP6Config *old_config = NULL;
7997 gboolean has_changes = FALSE;
7998 gboolean success = TRUE;
7999 NMDeviceStateReason reason_local = NM_DEVICE_STATE_REASON_NONE;
8000 int ip_ifindex, config_ifindex;
8002 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
8004 priv = NM_DEVICE_GET_PRIVATE (self);
8005 ip_ifindex = nm_device_get_ip_ifindex (self);
8008 config_ifindex = nm_ip6_config_get_ifindex (new_config);
8009 if (config_ifindex > 0)
8010 g_return_val_if_fail (ip_ifindex == config_ifindex, FALSE);
8013 old_config = priv->ip6_config;
8015 /* Always commit to nm-platform to update lifetimes */
8016 if (commit && new_config) {
8017 nm_device_ipv6_set_mtu (self, priv->ip6_mtu);
8018 success = nm_ip6_config_commit (new_config,
8022 reason_local = NM_DEVICE_STATE_REASON_CONFIG_FAILED;
8027 /* has_changes is set only on relevant changes, because when the configuration changes,
8028 * this causes a re-read and reset. This should only happen for relevant changes */
8029 nm_ip6_config_replace (old_config, new_config, &has_changes);
8031 _LOGD (LOGD_IP6, "update IP6Config instance (%s)",
8032 nm_exported_object_get_path (NM_EXPORTED_OBJECT (old_config)));
8036 priv->ip6_config = g_object_ref (new_config);
8038 if (success && !nm_exported_object_is_exported (NM_EXPORTED_OBJECT (new_config)))
8039 nm_exported_object_export (NM_EXPORTED_OBJECT (new_config));
8041 _LOGD (LOGD_IP6, "set IP6Config instance (%s)",
8042 nm_exported_object_get_path (NM_EXPORTED_OBJECT (new_config)));
8044 } else if (old_config) {
8046 priv->ip6_config = NULL;
8047 _LOGD (LOGD_IP6, "clear IP6Config instance (%s)",
8048 nm_exported_object_get_path (NM_EXPORTED_OBJECT (old_config)));
8051 nm_default_route_manager_ip6_update_default_route (nm_default_route_manager_get (), self);
8054 if (old_config != priv->ip6_config)
8055 _notify (self, PROP_IP6_CONFIG);
8056 g_signal_emit (self, signals[IP6_CONFIG_CHANGED], 0, priv->ip6_config, old_config);
8058 if (old_config != priv->ip6_config)
8059 nm_exported_object_clear_and_unexport (&old_config);
8061 if (nm_device_uses_generated_assumed_connection (self)) {
8062 NMConnection *connection = nm_device_get_applied_connection (self);
8063 NMConnection *settings_connection = NM_CONNECTION (nm_device_get_settings_connection (self));
8066 g_object_freeze_notify (G_OBJECT (connection));
8067 g_object_freeze_notify (G_OBJECT (settings_connection));
8069 nm_connection_remove_setting (settings_connection, NM_TYPE_SETTING_IP6_CONFIG);
8070 s_ip6 = nm_ip6_config_create_setting (priv->ip6_config);
8071 nm_connection_add_setting (settings_connection, s_ip6);
8073 nm_connection_remove_setting (connection, NM_TYPE_SETTING_IP6_CONFIG);
8074 s_ip6 = nm_ip6_config_create_setting (priv->ip6_config);
8075 nm_connection_add_setting (connection, s_ip6);
8077 g_object_thaw_notify (G_OBJECT (settings_connection));
8078 g_object_thaw_notify (G_OBJECT (connection));
8081 nm_device_queue_recheck_assume (self);
8085 *reason = reason_local;
8091 nm_device_replace_vpn6_config (NMDevice *self, NMIP6Config *old, NMIP6Config *config)
8093 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8095 if (!_replace_vpn_config_in_list (&priv->vpn6_configs, (GObject *) old, (GObject *) config))
8098 /* NULL to use existing configs */
8099 if (!ip6_config_merge_and_apply (self, TRUE, NULL))
8100 _LOGW (LOGD_IP6, "failed to set VPN routes for device");
8104 nm_device_set_wwan_ip6_config (NMDevice *self, NMIP6Config *config)
8106 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8108 if (priv->wwan_ip6_config == config)
8111 g_clear_object (&priv->wwan_ip6_config);
8113 priv->wwan_ip6_config = g_object_ref (config);
8115 /* NULL to use existing configs */
8116 if (!ip6_config_merge_and_apply (self, TRUE, NULL))
8117 _LOGW (LOGD_IP6, "failed to set WWAN IPv6 configuration");
8121 nm_device_get_dhcp6_config (NMDevice *self)
8123 g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
8125 return NM_DEVICE_GET_PRIVATE (self)->dhcp6_config;
8129 nm_device_get_ip6_config (NMDevice *self)
8131 g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
8133 return NM_DEVICE_GET_PRIVATE (self)->ip6_config;
8136 /****************************************************************/
8139 dispatcher_cleanup (NMDevice *self)
8141 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8143 if (priv->dispatcher.call_id) {
8144 nm_dispatcher_call_cancel (priv->dispatcher.call_id);
8145 priv->dispatcher.call_id = 0;
8146 priv->dispatcher.post_state = NM_DEVICE_STATE_UNKNOWN;
8147 priv->dispatcher.post_state_reason = NM_DEVICE_STATE_REASON_NONE;
8152 dispatcher_complete_proceed_state (guint call_id, gpointer user_data)
8154 NMDevice *self = NM_DEVICE (user_data);
8155 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8157 g_return_if_fail (call_id == priv->dispatcher.call_id);
8159 priv->dispatcher.call_id = 0;
8160 nm_device_queue_state (self, priv->dispatcher.post_state,
8161 priv->dispatcher.post_state_reason);
8162 priv->dispatcher.post_state = NM_DEVICE_STATE_UNKNOWN;
8163 priv->dispatcher.post_state_reason = NM_DEVICE_STATE_REASON_NONE;
8166 /****************************************************************/
8169 ip_check_pre_up (NMDevice *self)
8171 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8173 if (priv->dispatcher.call_id != 0) {
8174 g_warn_if_reached ();
8175 dispatcher_cleanup (self);
8178 priv->dispatcher.post_state = NM_DEVICE_STATE_SECONDARIES;
8179 priv->dispatcher.post_state_reason = NM_DEVICE_STATE_REASON_NONE;
8180 if (!nm_dispatcher_call (DISPATCHER_ACTION_PRE_UP,
8181 nm_device_get_settings_connection (self),
8182 nm_device_get_applied_connection (self),
8184 dispatcher_complete_proceed_state,
8186 &priv->dispatcher.call_id)) {
8187 /* Just proceed on errors */
8188 dispatcher_complete_proceed_state (0, self);
8193 ip_check_gw_ping_cleanup (NMDevice *self)
8195 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8197 nm_clear_g_source (&priv->gw_ping.watch);
8198 nm_clear_g_source (&priv->gw_ping.timeout);
8200 if (priv->gw_ping.pid) {
8201 nm_utils_kill_child_async (priv->gw_ping.pid, SIGTERM, priv->gw_ping.log_domain, "ping", 1000, NULL, NULL);
8202 priv->gw_ping.pid = 0;
8205 g_clear_pointer (&priv->gw_ping.binary, g_free);
8206 g_clear_pointer (&priv->gw_ping.address, g_free);
8210 spawn_ping (NMDevice *self)
8212 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8213 gs_free char *str_timeout = NULL;
8214 gs_free char *tmp_str = NULL;
8215 const char *args[] = { priv->gw_ping.binary, "-I", nm_device_get_ip_iface (self),
8216 "-c", "1", "-w", NULL, priv->gw_ping.address, NULL };
8217 gs_free_error GError *error = NULL;
8220 args[6] = str_timeout = g_strdup_printf ("%u", priv->gw_ping.deadline);
8221 tmp_str = g_strjoinv (" ", (gchar **) args);
8222 _LOGD (priv->gw_ping.log_domain, "ping: running '%s'", tmp_str);
8224 ret = g_spawn_async ("/",
8227 G_SPAWN_DO_NOT_REAP_CHILD,
8234 _LOGW (priv->gw_ping.log_domain, "ping: could not spawn %s: %s",
8235 priv->gw_ping.binary, error->message);
8242 respawn_ping_cb (gpointer user_data)
8244 NMDevice *self = NM_DEVICE (user_data);
8245 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8247 priv->gw_ping.watch = 0;
8249 if (spawn_ping (self)) {
8250 priv->gw_ping.watch = g_child_watch_add (priv->gw_ping.pid,
8251 ip_check_ping_watch_cb, self);
8253 ip_check_gw_ping_cleanup (self);
8254 ip_check_pre_up (self);
8261 ip_check_ping_watch_cb (GPid pid, gint status, gpointer user_data)
8263 NMDevice *self = NM_DEVICE (user_data);
8264 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8265 NMLogDomain log_domain = priv->gw_ping.log_domain;
8266 gboolean success = FALSE;
8268 if (!priv->gw_ping.watch)
8270 priv->gw_ping.watch = 0;
8271 priv->gw_ping.pid = 0;
8273 if (WIFEXITED (status)) {
8274 if (WEXITSTATUS (status) == 0) {
8275 _LOGD (log_domain, "ping: gateway ping succeeded");
8278 _LOGW (log_domain, "ping: gateway ping failed with error code %d",
8279 WEXITSTATUS (status));
8282 _LOGW (log_domain, "ping: stopped unexpectedly with status %d", status);
8285 /* We've got connectivity, proceed to pre_up */
8286 ip_check_gw_ping_cleanup (self);
8287 ip_check_pre_up (self);
8289 /* If ping exited with an error it may have returned early,
8290 * wait 1 second and restart it */
8291 priv->gw_ping.watch = g_timeout_add_seconds (1, respawn_ping_cb, self);
8296 ip_check_ping_timeout_cb (gpointer user_data)
8298 NMDevice *self = NM_DEVICE (user_data);
8299 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8301 priv->gw_ping.timeout = 0;
8303 _LOGW (priv->gw_ping.log_domain, "ping: gateway ping timed out");
8305 ip_check_gw_ping_cleanup (self);
8306 ip_check_pre_up (self);
8311 start_ping (NMDevice *self,
8312 NMLogDomain log_domain,
8314 const char *address,
8317 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8319 g_return_val_if_fail (priv->gw_ping.watch == 0, FALSE);
8320 g_return_val_if_fail (priv->gw_ping.timeout == 0, FALSE);
8322 priv->gw_ping.log_domain = log_domain;
8323 priv->gw_ping.address = g_strdup (address);
8324 priv->gw_ping.binary = g_strdup (binary);
8325 priv->gw_ping.deadline = timeout + 10; /* the proper termination is enforced by a timer */
8327 if (spawn_ping (self)) {
8328 priv->gw_ping.watch = g_child_watch_add (priv->gw_ping.pid, ip_check_ping_watch_cb, self);
8329 priv->gw_ping.timeout = g_timeout_add_seconds (timeout, ip_check_ping_timeout_cb, self);
8333 ip_check_gw_ping_cleanup (self);
8338 nm_device_start_ip_check (NMDevice *self)
8340 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8341 NMConnection *connection;
8342 NMSettingConnection *s_con;
8344 const char *ping_binary = NULL;
8345 char buf[INET6_ADDRSTRLEN] = { 0 };
8346 NMLogDomain log_domain = LOGD_IP4;
8348 /* Shouldn't be any active ping here, since IP_CHECK happens after the
8349 * first IP method completes. Any subsequently completing IP method doesn't
8352 g_assert (!priv->gw_ping.watch);
8353 g_assert (!priv->gw_ping.timeout);
8354 g_assert (!priv->gw_ping.pid);
8355 g_assert (priv->ip4_state == IP_DONE || priv->ip6_state == IP_DONE);
8357 connection = nm_device_get_applied_connection (self);
8358 g_assert (connection);
8360 s_con = nm_connection_get_setting_connection (connection);
8362 timeout = nm_setting_connection_get_gateway_ping_timeout (s_con);
8365 if (priv->ip4_config && priv->ip4_state == IP_DONE) {
8368 ping_binary = nm_utils_find_helper ("ping", "/usr/bin/ping", NULL);
8369 log_domain = LOGD_IP4;
8371 gw = nm_ip4_config_get_gateway (priv->ip4_config);
8372 if (gw && !inet_ntop (AF_INET, &gw, buf, sizeof (buf)))
8374 } else if (priv->ip6_config && priv->ip6_state == IP_DONE) {
8375 const struct in6_addr *gw = NULL;
8377 ping_binary = nm_utils_find_helper ("ping6", "/usr/bin/ping6", NULL);
8378 log_domain = LOGD_IP6;
8380 gw = nm_ip6_config_get_gateway (priv->ip6_config);
8381 if (gw && !inet_ntop (AF_INET6, gw, buf, sizeof (buf)))
8387 start_ping (self, log_domain, ping_binary, buf, timeout);
8389 /* If no ping was started, just advance to pre_up */
8390 if (!priv->gw_ping.pid)
8391 ip_check_pre_up (self);
8394 /****************************************************************/
8397 carrier_wait_timeout (gpointer user_data)
8399 NMDevice *self = NM_DEVICE (user_data);
8401 NM_DEVICE_GET_PRIVATE (self)->carrier_wait_id = 0;
8402 nm_device_remove_pending_action (self, "carrier wait", TRUE);
8404 _carrier_wait_check_queued_act_request (self);
8406 return G_SOURCE_REMOVE;
8410 nm_device_is_up (NMDevice *self)
8412 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
8414 if (NM_DEVICE_GET_CLASS (self)->is_up)
8415 return NM_DEVICE_GET_CLASS (self)->is_up (self);
8421 is_up (NMDevice *self)
8423 int ifindex = nm_device_get_ip_ifindex (self);
8425 return ifindex > 0 ? nm_platform_link_is_up (NM_PLATFORM_GET, ifindex) : TRUE;
8429 nm_device_bring_up (NMDevice *self, gboolean block, gboolean *no_firmware)
8431 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8432 gboolean device_is_up = FALSE;
8434 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
8436 _LOGD (LOGD_HW, "bringing up device");
8438 if (NM_DEVICE_GET_CLASS (self)->bring_up) {
8439 if (!NM_DEVICE_GET_CLASS (self)->bring_up (self, no_firmware))
8443 device_is_up = nm_device_is_up (self);
8444 if (block && !device_is_up) {
8445 int ifindex = nm_device_get_ip_ifindex (self);
8446 gint64 wait_until = nm_utils_get_monotonic_timestamp_us () + 10000 /* microseconds */;
8450 if (!nm_platform_link_refresh (NM_PLATFORM_GET, ifindex))
8452 device_is_up = nm_device_is_up (self);
8453 } while (!device_is_up && nm_utils_get_monotonic_timestamp_us () < wait_until);
8456 if (!device_is_up) {
8458 _LOGW (LOGD_HW, "device not up after timeout!");
8460 _LOGD (LOGD_HW, "device not up immediately");
8464 /* Devices that support carrier detect must be IFF_UP to report carrier
8465 * changes; so after setting the device IFF_UP we must suppress startup
8466 * complete (via a pending action) until either the carrier turns on, or
8467 * a timeout is reached.
8469 if (nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT)) {
8470 if (!nm_clear_g_source (&priv->carrier_wait_id))
8471 nm_device_add_pending_action (self, "carrier wait", TRUE);
8472 priv->carrier_wait_id = g_timeout_add_seconds (5, carrier_wait_timeout, self);
8475 /* Can only get HW address of some devices when they are up */
8476 nm_device_update_hw_address (self);
8478 _update_ip4_address (self);
8483 bring_up (NMDevice *self, gboolean *no_firmware)
8485 int ifindex = nm_device_get_ip_ifindex (self);
8490 *no_firmware = FALSE;
8494 result = nm_platform_link_set_up (NM_PLATFORM_GET, ifindex, no_firmware);
8496 /* Store carrier immediately. */
8497 if (result && nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT))
8498 check_carrier (self);
8504 nm_device_take_down (NMDevice *self, gboolean block)
8506 gboolean device_is_up;
8508 g_return_if_fail (NM_IS_DEVICE (self));
8510 _LOGD (LOGD_HW, "taking down device");
8512 if (NM_DEVICE_GET_CLASS (self)->take_down) {
8513 if (!NM_DEVICE_GET_CLASS (self)->take_down (self))
8517 device_is_up = nm_device_is_up (self);
8518 if (block && device_is_up) {
8519 int ifindex = nm_device_get_ip_ifindex (self);
8520 gint64 wait_until = nm_utils_get_monotonic_timestamp_us () + 10000 /* microseconds */;
8524 if (!nm_platform_link_refresh (NM_PLATFORM_GET, ifindex))
8526 device_is_up = nm_device_is_up (self);
8527 } while (device_is_up && nm_utils_get_monotonic_timestamp_us () < wait_until);
8532 _LOGW (LOGD_HW, "device not down after timeout!");
8534 _LOGD (LOGD_HW, "device not down immediately");
8539 take_down (NMDevice *self)
8541 int ifindex = nm_device_get_ip_ifindex (self);
8544 return nm_platform_link_set_down (NM_PLATFORM_GET, ifindex);
8546 /* devices without ifindex are always up. */
8547 _LOGD (LOGD_HW, "cannot take down device without ifindex");
8552 nm_device_set_firmware_missing (NMDevice *self, gboolean new_missing)
8554 NMDevicePrivate *priv;
8556 g_return_if_fail (NM_IS_DEVICE (self));
8558 priv = NM_DEVICE_GET_PRIVATE (self);
8559 if (priv->firmware_missing != new_missing) {
8560 priv->firmware_missing = new_missing;
8561 _notify (self, PROP_FIRMWARE_MISSING);
8566 nm_device_get_firmware_missing (NMDevice *self)
8568 return NM_DEVICE_GET_PRIVATE (self)->firmware_missing;
8572 nm_device_set_nm_plugin_missing (NMDevice *self, gboolean new_missing)
8574 NMDevicePrivate *priv;
8576 g_return_if_fail (NM_IS_DEVICE (self));
8578 priv = NM_DEVICE_GET_PRIVATE (self);
8579 if (priv->nm_plugin_missing != new_missing) {
8580 priv->nm_plugin_missing = new_missing;
8581 _notify (self, PROP_NM_PLUGIN_MISSING);
8586 nm_device_get_nm_plugin_missing (NMDevice *self)
8588 return NM_DEVICE_GET_PRIVATE (self)->nm_plugin_missing;
8591 static NMIP4Config *
8592 find_ip4_lease_config (NMDevice *self,
8593 NMConnection *connection,
8594 NMIP4Config *ext_ip4_config)
8596 const char *ip_iface = nm_device_get_ip_iface (self);
8597 int ip_ifindex = nm_device_get_ip_ifindex (self);
8598 GSList *leases, *liter;
8599 NMIP4Config *found = NULL;
8601 g_return_val_if_fail (NM_IS_IP4_CONFIG (ext_ip4_config), NULL);
8602 g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
8604 leases = nm_dhcp_manager_get_lease_ip_configs (nm_dhcp_manager_get (),
8607 nm_connection_get_uuid (connection),
8609 nm_device_get_ip4_route_metric (self));
8610 for (liter = leases; liter && !found; liter = liter->next) {
8611 NMIP4Config *lease_config = liter->data;
8612 const NMPlatformIP4Address *address = nm_ip4_config_get_address (lease_config, 0);
8613 guint32 gateway = nm_ip4_config_get_gateway (lease_config);
8616 if (!nm_ip4_config_address_exists (ext_ip4_config, address))
8618 if (gateway != nm_ip4_config_get_gateway (ext_ip4_config))
8620 found = g_object_ref (lease_config);
8623 g_slist_free_full (leases, g_object_unref);
8628 capture_lease_config (NMDevice *self,
8629 NMIP4Config *ext_ip4_config,
8630 NMIP4Config **out_ip4_config,
8631 NMIP6Config *ext_ip6_config,
8632 NMIP6Config **out_ip6_config)
8634 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8635 const GSList *connections, *citer;
8637 gboolean dhcp_used = FALSE;
8639 /* Ensure at least one address on the device has a non-infinite lifetime,
8640 * otherwise DHCP cannot possibly be active on the device right now.
8642 if (ext_ip4_config && out_ip4_config) {
8643 for (i = 0; i < nm_ip4_config_get_num_addresses (ext_ip4_config); i++) {
8644 const NMPlatformIP4Address *addr = nm_ip4_config_get_address (ext_ip4_config, i);
8646 if (addr->lifetime != NM_PLATFORM_LIFETIME_PERMANENT) {
8651 } else if (ext_ip6_config && out_ip6_config) {
8652 for (i = 0; i < nm_ip6_config_get_num_addresses (ext_ip6_config); i++) {
8653 const NMPlatformIP6Address *addr = nm_ip6_config_get_address (ext_ip6_config, i);
8655 if (addr->lifetime != NM_PLATFORM_LIFETIME_PERMANENT) {
8661 g_return_if_fail ( (ext_ip6_config && out_ip6_config)
8662 || (ext_ip4_config && out_ip4_config));
8668 connections = nm_connection_provider_get_connections (priv->con_provider);
8669 for (citer = connections; citer; citer = citer->next) {
8670 NMConnection *candidate = citer->data;
8673 if (!nm_device_check_connection_compatible (self, candidate))
8677 method = nm_utils_get_ip_config_method (candidate, NM_TYPE_SETTING_IP4_CONFIG);
8678 if (out_ip4_config && strcmp (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0) {
8679 *out_ip4_config = find_ip4_lease_config (self, candidate, ext_ip4_config);
8680 if (*out_ip4_config)
8685 method = nm_utils_get_ip_config_method (candidate, NM_TYPE_SETTING_IP6_CONFIG);
8686 if (out_ip6_config && strcmp (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0) {
8687 /* FIXME: implement find_ip6_lease_config() */
8693 _ip4_config_intersect (gpointer value, gpointer user_data)
8695 NMIP4Config *dst = (NMIP4Config *) value;
8696 NMIP4Config *src = (NMIP4Config *) user_data;
8698 nm_ip4_config_intersect (dst, src);
8702 _ip4_config_subtract (gpointer value, gpointer user_data)
8704 NMIP4Config *dst = (NMIP4Config *) user_data;
8705 NMIP4Config *src = (NMIP4Config *) value;
8707 nm_ip4_config_subtract (dst, src);
8711 update_ip4_config (NMDevice *self, gboolean initial)
8713 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8715 gboolean capture_resolv_conf;
8716 NMDnsManagerResolvConfMode resolv_conf_mode;
8718 ifindex = nm_device_get_ip_ifindex (self);
8722 resolv_conf_mode = nm_dns_manager_get_resolv_conf_mode (nm_dns_manager_get ());
8723 capture_resolv_conf = initial && (resolv_conf_mode == NM_DNS_MANAGER_RESOLV_CONF_EXPLICIT);
8726 g_clear_object (&priv->ext_ip4_config);
8727 priv->ext_ip4_config = nm_ip4_config_capture (ifindex, capture_resolv_conf);
8728 if (priv->ext_ip4_config) {
8730 g_clear_object (&priv->dev_ip4_config);
8731 capture_lease_config (self, priv->ext_ip4_config, &priv->dev_ip4_config, NULL, NULL);
8734 /* FIXME: ext_ip4_config does not contain routes with source==RTPROT_KERNEL.
8735 * Hence, we will wrongly remove device-routes with metric=0 if they were added by
8736 * the user on purpose. This should be fixed by also tracking and exposing
8739 /* This function was called upon external changes. Remove the configuration
8740 * (addresses,routes) that is no longer present externally from the internal
8741 * config. This way, we don't re-add addresses that were manually removed
8743 if (priv->con_ip4_config)
8744 nm_ip4_config_intersect (priv->con_ip4_config, priv->ext_ip4_config);
8745 if (priv->dev_ip4_config)
8746 nm_ip4_config_intersect (priv->dev_ip4_config, priv->ext_ip4_config);
8748 g_slist_foreach (priv->vpn4_configs, _ip4_config_intersect, priv->ext_ip4_config);
8750 if (priv->wwan_ip4_config)
8751 nm_ip4_config_intersect (priv->wwan_ip4_config, priv->ext_ip4_config);
8753 /* Remove parts from ext_ip4_config to only contain the information that
8754 * was configured externally -- we already have the same configuration from
8755 * internal origins. */
8756 if (priv->con_ip4_config)
8757 nm_ip4_config_subtract (priv->ext_ip4_config, priv->con_ip4_config);
8758 if (priv->dev_ip4_config)
8759 nm_ip4_config_subtract (priv->ext_ip4_config, priv->dev_ip4_config);
8761 g_slist_foreach (priv->vpn4_configs, _ip4_config_subtract, priv->ext_ip4_config);
8763 if (priv->wwan_ip4_config)
8764 nm_ip4_config_subtract (priv->ext_ip4_config, priv->wwan_ip4_config);
8766 ip4_config_merge_and_apply (self, NULL, FALSE, NULL);
8771 _ip6_config_intersect (gpointer value, gpointer user_data)
8773 NMIP6Config *dst = (NMIP6Config *) value;
8774 NMIP6Config *src = (NMIP6Config *) user_data;
8776 nm_ip6_config_intersect (dst, src);
8780 _ip6_config_subtract (gpointer value, gpointer user_data)
8782 NMIP6Config *dst = (NMIP6Config *) user_data;
8783 NMIP6Config *src = (NMIP6Config *) value;
8785 nm_ip6_config_subtract (dst, src);
8789 update_ip6_config (NMDevice *self, gboolean initial)
8791 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8793 gboolean capture_resolv_conf;
8794 NMDnsManagerResolvConfMode resolv_conf_mode;
8796 ifindex = nm_device_get_ip_ifindex (self);
8800 resolv_conf_mode = nm_dns_manager_get_resolv_conf_mode (nm_dns_manager_get ());
8801 capture_resolv_conf = initial && (resolv_conf_mode == NM_DNS_MANAGER_RESOLV_CONF_EXPLICIT);
8804 g_clear_object (&priv->ext_ip6_config);
8805 g_clear_object (&priv->ext_ip6_config_captured);
8806 priv->ext_ip6_config_captured = nm_ip6_config_capture (ifindex, capture_resolv_conf, NM_SETTING_IP6_CONFIG_PRIVACY_UNKNOWN);
8807 if (priv->ext_ip6_config_captured) {
8809 priv->ext_ip6_config = nm_ip6_config_new_cloned (priv->ext_ip6_config_captured);
8811 /* This function was called upon external changes. Remove the configuration
8812 * (addresses,routes) that is no longer present externally from the internal
8813 * config. This way, we don't re-add addresses that were manually removed
8815 if (priv->con_ip6_config)
8816 nm_ip6_config_intersect (priv->con_ip6_config, priv->ext_ip6_config);
8817 if (priv->ac_ip6_config)
8818 nm_ip6_config_intersect (priv->ac_ip6_config, priv->ext_ip6_config);
8819 if (priv->dhcp6_ip6_config)
8820 nm_ip6_config_intersect (priv->dhcp6_ip6_config, priv->ext_ip6_config);
8821 if (priv->wwan_ip6_config)
8822 nm_ip6_config_intersect (priv->wwan_ip6_config, priv->ext_ip6_config);
8823 g_slist_foreach (priv->vpn6_configs, _ip6_config_intersect, priv->ext_ip6_config);
8825 /* Remove parts from ext_ip6_config to only contain the information that
8826 * was configured externally -- we already have the same configuration from
8827 * internal origins. */
8828 if (priv->con_ip6_config)
8829 nm_ip6_config_subtract (priv->ext_ip6_config, priv->con_ip6_config);
8830 if (priv->ac_ip6_config)
8831 nm_ip6_config_subtract (priv->ext_ip6_config, priv->ac_ip6_config);
8832 if (priv->dhcp6_ip6_config)
8833 nm_ip6_config_subtract (priv->ext_ip6_config, priv->dhcp6_ip6_config);
8834 if (priv->wwan_ip6_config)
8835 nm_ip6_config_subtract (priv->ext_ip6_config, priv->wwan_ip6_config);
8836 g_slist_foreach (priv->vpn6_configs, _ip6_config_subtract, priv->ext_ip6_config);
8838 ip6_config_merge_and_apply (self, FALSE, NULL);
8841 if ( priv->linklocal6_timeout_id
8842 && priv->ext_ip6_config_captured
8843 && nm_ip6_config_get_address_first_nontentative (priv->ext_ip6_config_captured, TRUE)) {
8844 /* linklocal6 is ready now, do the state transition... we are also
8845 * invoked as g_idle_add, so no problems with reentrance doing it now.
8847 linklocal6_complete (self);
8852 nm_device_capture_initial_config (NMDevice *self)
8854 update_ip4_config (self, TRUE);
8855 update_ip6_config (self, TRUE);
8859 queued_ip4_config_change (gpointer user_data)
8861 NMDevice *self = NM_DEVICE (user_data);
8862 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8864 /* Wait for any queued state changes */
8865 if (priv->queued_state.id)
8868 priv->queued_ip4_config_id = 0;
8869 g_object_ref (self);
8870 update_ip4_config (self, FALSE);
8871 g_object_unref (self);
8877 queued_ip6_config_change (gpointer user_data)
8879 NMDevice *self = NM_DEVICE (user_data);
8880 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
8882 gboolean need_ipv6ll = FALSE;
8884 /* Wait for any queued state changes */
8885 if (priv->queued_state.id)
8888 priv->queued_ip6_config_id = 0;
8889 g_object_ref (self);
8890 update_ip6_config (self, FALSE);
8892 if ( nm_platform_link_get (NM_PLATFORM_GET, priv->ifindex)
8893 && priv->state < NM_DEVICE_STATE_DEACTIVATING) {
8894 /* Handle DAD falures */
8895 for (iter = priv->dad6_failed_addrs; iter; iter = g_slist_next (iter)) {
8896 NMPlatformIP6Address *addr = iter->data;
8898 if (addr->source >= NM_IP_CONFIG_SOURCE_USER)
8901 _LOGI (LOGD_IP6, "ipv6: duplicate address check failed for the %s address",
8902 nm_platform_ip6_address_to_string (addr, NULL, 0));
8904 if (IN6_IS_ADDR_LINKLOCAL (&addr->address))
8906 else if (priv->rdisc)
8907 nm_rdisc_dad_failed (priv->rdisc, &addr->address);
8910 /* If no IPv6 link-local address exists but other addresses do then we
8911 * must add the LL address to remain conformant with RFC 3513 chapter 2.1
8912 * ("Addressing Model"): "All interfaces are required to have at least
8913 * one link-local unicast address".
8915 if (priv->ip6_config && nm_ip6_config_get_num_addresses (priv->ip6_config))
8919 check_and_add_ipv6ll_addr (self);
8922 g_slist_free_full (priv->dad6_failed_addrs, g_free);
8923 priv->dad6_failed_addrs = NULL;
8925 g_object_unref (self);
8931 device_ipx_changed (NMPlatform *platform,
8932 NMPObjectType obj_type,
8934 gpointer platform_object,
8935 NMPlatformSignalChangeType change_type,
8938 NMDevicePrivate *priv;
8939 NMPlatformIP6Address *addr;
8941 if (nm_device_get_ip_ifindex (self) != ifindex)
8944 priv = NM_DEVICE_GET_PRIVATE (self);
8947 case NMP_OBJECT_TYPE_IP4_ADDRESS:
8948 case NMP_OBJECT_TYPE_IP4_ROUTE:
8949 if (!priv->queued_ip4_config_id) {
8950 priv->queued_ip4_config_id = g_idle_add (queued_ip4_config_change, self);
8951 _LOGD (LOGD_DEVICE, "queued IP4 config change");
8954 case NMP_OBJECT_TYPE_IP6_ADDRESS:
8955 addr = platform_object;
8957 if ( priv->state > NM_DEVICE_STATE_DISCONNECTED
8958 && priv->state < NM_DEVICE_STATE_DEACTIVATING
8959 && ( (change_type == NM_PLATFORM_SIGNAL_CHANGED && addr->n_ifa_flags & IFA_F_DADFAILED)
8960 || (change_type == NM_PLATFORM_SIGNAL_REMOVED && addr->n_ifa_flags & IFA_F_TENTATIVE))) {
8961 priv->dad6_failed_addrs = g_slist_append (priv->dad6_failed_addrs,
8962 g_memdup (addr, sizeof (NMPlatformIP6Address)));
8965 case NMP_OBJECT_TYPE_IP6_ROUTE:
8966 if (!priv->queued_ip6_config_id) {
8967 priv->queued_ip6_config_id = g_idle_add (queued_ip6_config_change, self);
8968 _LOGD (LOGD_DEVICE, "queued IP6 config change");
8972 g_return_if_reached ();
8976 /*****************************************************************************/
8978 NM_UTILS_FLAGS2STR_DEFINE (nm_unmanaged_flags2str, NMUnmanagedFlags,
8979 NM_UTILS_FLAGS2STR (NM_UNMANAGED_SLEEPING, "sleeping"),
8980 NM_UTILS_FLAGS2STR (NM_UNMANAGED_QUITTING, "quitting"),
8981 NM_UTILS_FLAGS2STR (NM_UNMANAGED_PARENT, "parent"),
8982 NM_UTILS_FLAGS2STR (NM_UNMANAGED_LOOPBACK, "loopback"),
8983 NM_UTILS_FLAGS2STR (NM_UNMANAGED_PLATFORM_INIT, "platform-init"),
8984 NM_UTILS_FLAGS2STR (NM_UNMANAGED_USER_EXPLICIT, "user-explicit"),
8985 NM_UTILS_FLAGS2STR (NM_UNMANAGED_BY_DEFAULT, "by-default"),
8986 NM_UTILS_FLAGS2STR (NM_UNMANAGED_USER_SETTINGS, "user-settings"),
8987 NM_UTILS_FLAGS2STR (NM_UNMANAGED_USER_UDEV, "user-udev"),
8988 NM_UTILS_FLAGS2STR (NM_UNMANAGED_EXTERNAL_DOWN, "external-down"),
8989 NM_UTILS_FLAGS2STR (NM_UNMANAGED_IS_SLAVE, "is-slave"),
8993 _unmanaged_flags2str (NMUnmanagedFlags flags, NMUnmanagedFlags mask, char *buf, gsize len)
9000 nm_utils_to_string_buffer_init (&buf, &len);
9008 nm_unmanaged_flags2str (flags, b, len);
9013 nm_unmanaged_flags2str (mask & ~flags, buf2, sizeof (buf2));
9015 gboolean add_separator = l > 0;
9020 nm_utils_strbuf_append_c (&b, &len, ',');
9021 add_separator = TRUE;
9023 tmp2 = strchr (tmp, ',');
9027 nm_utils_strbuf_append_c (&b, &len, '!');
9028 nm_utils_strbuf_append_str (&b, &len, tmp);
9040 _get_managed_by_flags(NMUnmanagedFlags flags, NMUnmanagedFlags mask, gboolean for_user_request)
9042 /* Evaluate the managed state based on the unmanaged flags.
9044 * Some flags are authoritative, meaning they always cause
9045 * the device to be unmanaged (e.g. @NM_UNMANAGED_PLATFORM_INIT).
9047 * OTOH, some flags can be overwritten. For example NM_UNMANAGED_USER_SETTINGS
9048 * is ignored once NM_UNMANAGED_USER_EXPLICIT is set. The idea is that
9049 * the flag from the configuration has no effect once the user explicitly
9050 * touches the unmanaged flags. */
9052 if (for_user_request) {
9054 /* @for_user_request can make the result only ~more~ managed.
9055 * If the flags already indicate a managed state for a non-user-request,
9056 * then it is also managed for an explict user-request.
9058 * Effectively, this check is redundant, as the code below already
9059 * already ensures that. Still, express this invariant explictly here. */
9060 if (_get_managed_by_flags (flags, mask, FALSE))
9063 /* A for-user-request, is effectively the same as pretending
9064 * that user-dbus flag is cleared. */
9065 mask |= NM_UNMANAGED_USER_EXPLICIT;
9066 flags &= ~NM_UNMANAGED_USER_EXPLICIT;
9069 if ( NM_FLAGS_ANY (mask, NM_UNMANAGED_USER_SETTINGS)
9070 && !NM_FLAGS_ANY (flags, NM_UNMANAGED_USER_SETTINGS)) {
9071 /* NM_UNMANAGED_USER_SETTINGS can only explicitly unmanage a device. It cannot
9072 * *manage* it. Having NM_UNMANAGED_USER_SETTINGS explicitly not set, is the
9073 * same as having it not set at all. */
9074 mask &= ~NM_UNMANAGED_USER_SETTINGS;
9077 if (NM_FLAGS_ANY (mask, NM_UNMANAGED_USER_UDEV)) {
9078 /* configuration from udev or nm-config overwrites the by-default flag
9079 * which is based on the device type. */
9080 flags &= ~NM_UNMANAGED_BY_DEFAULT;
9083 if ( NM_FLAGS_HAS (mask, NM_UNMANAGED_IS_SLAVE)
9084 && !NM_FLAGS_HAS (flags, NM_UNMANAGED_IS_SLAVE)) {
9085 /* for an enslaved device, by-default doesn't matter */
9086 flags &= ~NM_UNMANAGED_BY_DEFAULT;
9089 if (NM_FLAGS_HAS (mask, NM_UNMANAGED_USER_EXPLICIT)) {
9090 /* if the device is managed by user-decision, certain other flags
9093 flags &= ~( NM_UNMANAGED_BY_DEFAULT
9094 | NM_UNMANAGED_USER_UDEV
9095 | NM_UNMANAGED_EXTERNAL_DOWN);
9098 return flags == NM_UNMANAGED_NONE;
9102 * nm_device_get_managed:
9103 * @self: the #NMDevice
9104 * @for_user_request: whether to check the flags for an explict user-request
9106 * Whether the device is unmanaged according to the unmanaged flags.
9108 * Returns: %TRUE if the device is unmanaged because of the flags.
9111 nm_device_get_managed (NMDevice *self, gboolean for_user_request)
9113 NMDevicePrivate *priv;
9115 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
9117 if (!nm_device_is_real (self)) {
9118 /* a unrealized device is always considered unmanaged. */
9122 priv = NM_DEVICE_GET_PRIVATE (self);
9124 return _get_managed_by_flags (priv->unmanaged_flags, priv->unmanaged_mask, for_user_request);
9128 * nm_device_get_unmanaged_flags:
9129 * @self: the #NMDevice
9130 * @flag: the unmanaged flags to check.
9132 * Return the unmanaged flags of the device.
9134 * Returns: the flags of the device ( & @flag)
9137 nm_device_get_unmanaged_flags (NMDevice *self, NMUnmanagedFlags flag)
9139 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
9140 g_return_val_if_fail (flag != NM_UNMANAGED_NONE, FALSE);
9142 return NM_DEVICE_GET_PRIVATE (self)->unmanaged_flags & flag;
9146 * _set_unmanaged_flags:
9147 * @self: the #NMDevice instance
9148 * @flags: which #NMUnmanagedFlags to set.
9149 * @set_op: whether to set/clear/forget the flags. You can also pass
9150 * boolean values %TRUE and %FALSE, which mean %NM_UNMAN_FLAG_OP_SET_UNMANAGED
9151 * and %NM_UNMAN_FLAG_OP_SET_MANAGED, respectively.
9152 * @allow_state_transition: if %FALSE, setting flags never triggers a device
9153 * state change. If %TRUE, the device can change state, if it is real and
9154 * switches from managed to unmanaged (or vice versa).
9155 * @reason: the device state reason passed to nm_device_state_changed() if
9156 * the device becomes managed/unmanaged. This is only relevant if the
9157 * device switches state and if @allow_state_transition is %TRUE.
9159 * Set the unmanaged flags of the device.
9162 _set_unmanaged_flags (NMDevice *self,
9163 NMUnmanagedFlags flags,
9164 NMUnmanFlagOp set_op,
9165 gboolean allow_state_transition,
9166 NMDeviceStateReason reason)
9168 NMDevicePrivate *priv;
9169 gboolean was_managed, transition_state;
9170 NMUnmanagedFlags old_flags, old_mask;
9171 const char *operation = NULL;
9175 g_return_if_fail (NM_IS_DEVICE (self));
9176 g_return_if_fail (flags);
9178 priv = NM_DEVICE_GET_PRIVATE (self);
9181 allow_state_transition = FALSE;
9182 was_managed = allow_state_transition && nm_device_get_managed (self, FALSE);
9184 old_flags = priv->unmanaged_flags;
9185 old_mask = priv->unmanaged_mask;
9188 case NM_UNMAN_FLAG_OP_FORGET:
9189 priv->unmanaged_mask &= ~flags;
9190 priv->unmanaged_flags &= ~flags;
9191 operation = "forget";
9193 case NM_UNMAN_FLAG_OP_SET_UNMANAGED:
9194 priv->unmanaged_mask |= flags;
9195 priv->unmanaged_flags |= flags;
9196 operation = "set-unmanaged";
9198 case NM_UNMAN_FLAG_OP_SET_MANAGED:
9199 priv->unmanaged_mask |= flags;
9200 priv->unmanaged_flags &= ~flags;
9201 operation = "set-managed";
9204 g_return_if_reached ();
9207 if ( old_flags == priv->unmanaged_flags
9208 && old_mask == priv->unmanaged_mask)
9211 transition_state = allow_state_transition
9212 && was_managed != nm_device_get_managed (self, FALSE)
9215 && nm_device_get_state (self) == NM_DEVICE_STATE_UNMANAGED));
9217 #define _FMTX "[%s%s0x%0x/0x%x/%s"
9218 #define _FMT(flags, mask, str) \
9219 _unmanaged_flags2str ((flags), (mask), str, sizeof (str)), \
9220 ((flags) | (mask)) ? "=" : "", \
9223 (_get_managed_by_flags (flags, mask, FALSE) \
9225 : (_get_managed_by_flags (flags, mask, TRUE) \
9228 _LOGD (LOGD_DEVICE, "unmanaged: flags set to "_FMTX"%s, %s [%s=0x%0x]%s%s%s)",
9229 _FMT (priv->unmanaged_flags, priv->unmanaged_mask, str1),
9230 priv->real ? "" : "/unrealized",
9232 nm_unmanaged_flags2str (flags, str2, sizeof (str2)),
9234 NM_PRINT_FMT_QUOTED (allow_state_transition,
9236 reason_to_string (reason),
9237 transition_state ? ", transition-state" : "",
9241 if (transition_state) {
9243 nm_device_state_changed (self, NM_DEVICE_STATE_UNMANAGED, reason);
9245 nm_device_state_changed (self, NM_DEVICE_STATE_UNAVAILABLE, reason);
9250 * @self: the #NMDevice instance
9251 * @flags: which #NMUnmanagedFlags to set.
9252 * @set_op: whether to set/clear/forget the flags. You can also pass
9253 * boolean values %TRUE and %FALSE, which mean %NM_UNMAN_FLAG_OP_SET_UNMANAGED
9254 * and %NM_UNMAN_FLAG_OP_SET_MANAGED, respectively.
9256 * Set the unmanaged flags of the device (does not trigger a state change).
9259 nm_device_set_unmanaged_flags (NMDevice *self,
9260 NMUnmanagedFlags flags,
9261 NMUnmanFlagOp set_op)
9263 _set_unmanaged_flags (self, flags, set_op, FALSE, NM_DEVICE_STATE_REASON_NONE);
9267 * nm_device_set_unmanaged_by_flags:
9268 * @self: the #NMDevice instance
9269 * @flags: which #NMUnmanagedFlags to set.
9270 * @set_op: whether to set/clear/forget the flags. You can also pass
9271 * boolean values %TRUE and %FALSE, which mean %NM_UNMAN_FLAG_OP_SET_UNMANAGED
9272 * and %NM_UNMAN_FLAG_OP_SET_MANAGED, respectively.
9273 * @reason: the device state reason passed to nm_device_state_changed() if
9274 * the device becomes managed/unmanaged.
9276 * Set the unmanaged flags of the device and possibly trigger a state change.
9279 nm_device_set_unmanaged_by_flags (NMDevice *self,
9280 NMUnmanagedFlags flags,
9281 NMUnmanFlagOp set_op,
9282 NMDeviceStateReason reason)
9284 _set_unmanaged_flags (self, flags, set_op, TRUE, reason);
9288 nm_device_set_unmanaged_by_user_config (NMDevice *self, const GSList *unmanaged_specs)
9290 NMDevicePrivate *priv;
9293 g_return_if_fail (NM_IS_DEVICE (self));
9295 priv = NM_DEVICE_GET_PRIVATE (self);
9297 unmanaged = nm_device_spec_match_list (self, unmanaged_specs);
9299 nm_device_set_unmanaged_by_flags (self,
9300 NM_UNMANAGED_USER_SETTINGS,
9303 ? NM_DEVICE_STATE_REASON_NOW_UNMANAGED
9304 : NM_DEVICE_STATE_REASON_NOW_MANAGED);
9308 nm_device_set_unmanaged_by_user_udev (NMDevice *self)
9311 gboolean platform_unmanaged = FALSE;
9313 ifindex = self->priv->ifindex;
9316 || !nm_platform_link_get_unmanaged (NM_PLATFORM_GET, ifindex, &platform_unmanaged))
9319 nm_device_set_unmanaged_by_flags (self,
9320 NM_UNMANAGED_USER_UDEV,
9322 NM_DEVICE_STATE_REASON_USER_REQUESTED);
9326 nm_device_set_unmanaged_by_quitting (NMDevice *self)
9328 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
9329 gboolean need_deactivate = nm_device_is_activating (self) ||
9330 priv->state == NM_DEVICE_STATE_ACTIVATED;
9332 /* It's OK to block here because we're quitting */
9333 if (need_deactivate)
9334 _set_state_full (self, NM_DEVICE_STATE_DEACTIVATING, NM_DEVICE_STATE_REASON_NOW_UNMANAGED, TRUE);
9336 nm_device_set_unmanaged_by_flags (self,
9337 NM_UNMANAGED_QUITTING,
9339 need_deactivate ? NM_DEVICE_STATE_REASON_REMOVED
9340 : NM_DEVICE_STATE_REASON_NOW_UNMANAGED);
9343 /*****************************************************************************/
9346 nm_device_set_dhcp_timeout (NMDevice *self, guint32 timeout)
9348 g_return_if_fail (NM_IS_DEVICE (self));
9350 NM_DEVICE_GET_PRIVATE (self)->dhcp_timeout = timeout;
9354 nm_device_set_dhcp_anycast_address (NMDevice *self, const char *addr)
9356 NMDevicePrivate *priv;
9358 g_return_if_fail (NM_IS_DEVICE (self));
9359 g_return_if_fail (!addr || nm_utils_hwaddr_valid (addr, ETH_ALEN));
9361 priv = NM_DEVICE_GET_PRIVATE (self);
9363 g_free (priv->dhcp_anycast_address);
9364 priv->dhcp_anycast_address = g_strdup (addr);
9368 nm_device_reapply_settings_immediately (NMDevice *self)
9370 NMConnection *applied_connection;
9371 NMSettingsConnection *settings_connection;
9372 NMDeviceState state;
9373 NMSettingConnection *s_con_settings;
9374 NMSettingConnection *s_con_applied;
9379 g_return_if_fail (NM_IS_DEVICE (self));
9381 state = nm_device_get_state (self);
9382 if ( state <= NM_DEVICE_STATE_DISCONNECTED
9383 || state > NM_DEVICE_STATE_ACTIVATED)
9386 applied_connection = nm_device_get_applied_connection (self);
9387 settings_connection = nm_device_get_settings_connection (self);
9389 if (!nm_settings_connection_has_unmodified_applied_connection (settings_connection,
9391 NM_SETTING_COMPARE_FLAG_IGNORE_REAPPLY_IMMEDIATELY))
9394 s_con_settings = nm_connection_get_setting_connection ((NMConnection *) settings_connection);
9395 s_con_applied = nm_connection_get_setting_connection (applied_connection);
9397 if (g_strcmp0 ((zone = nm_setting_connection_get_zone (s_con_settings)),
9398 nm_setting_connection_get_zone (s_con_applied)) != 0) {
9400 version_id = nm_active_connection_version_id_bump ((NMActiveConnection *) self->priv->act_request);
9401 _LOGD (LOGD_DEVICE, "reapply setting: zone = %s%s%s (version-id %llu)", NM_PRINT_FMT_QUOTE_STRING (zone), (long long unsigned) version_id);
9403 g_object_set (G_OBJECT (s_con_applied),
9404 NM_SETTING_CONNECTION_ZONE, zone,
9407 nm_device_update_firewall_zone (self);
9410 if ((metered = nm_setting_connection_get_metered (s_con_settings)) != nm_setting_connection_get_metered (s_con_applied)) {
9412 version_id = nm_active_connection_version_id_bump ((NMActiveConnection *) self->priv->act_request);
9413 _LOGD (LOGD_DEVICE, "reapply setting: metered = %d (version-id %llu)", (int) metered, (long long unsigned) version_id);
9415 g_object_set (G_OBJECT (s_con_applied),
9416 NM_SETTING_CONNECTION_METERED, metered,
9419 nm_device_update_metered (self);
9424 nm_device_update_firewall_zone (NMDevice *self)
9426 NMConnection *applied_connection;
9427 NMSettingConnection *s_con;
9429 g_return_if_fail (NM_IS_DEVICE (self));
9431 applied_connection = nm_device_get_applied_connection (self);
9432 if (!applied_connection)
9435 s_con = nm_connection_get_setting_connection (applied_connection);
9436 if ( nm_device_get_state (self) == NM_DEVICE_STATE_ACTIVATED
9437 && !nm_device_uses_assumed_connection (self)) {
9438 nm_firewall_manager_add_or_change_zone (nm_firewall_manager_get (),
9439 nm_device_get_ip_iface (self),
9440 nm_setting_connection_get_zone (s_con),
9441 FALSE, /* change zone */
9448 nm_device_update_metered (NMDevice *self)
9450 #define NM_METERED_INVALID ((NMMetered) -1)
9451 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
9452 NMSettingConnection *setting;
9453 NMMetered conn_value, value = NM_METERED_INVALID;
9454 NMConnection *connection = NULL;
9455 NMDeviceState state;
9457 g_return_if_fail (NM_IS_DEVICE (self));
9459 state = nm_device_get_state (self);
9460 if ( state <= NM_DEVICE_STATE_DISCONNECTED
9461 || state > NM_DEVICE_STATE_ACTIVATED)
9462 value = NM_METERED_UNKNOWN;
9464 if (value == NM_METERED_INVALID) {
9465 connection = nm_device_get_applied_connection (self);
9467 setting = nm_connection_get_setting_connection (connection);
9469 conn_value = nm_setting_connection_get_metered (setting);
9470 if (conn_value != NM_METERED_UNKNOWN)
9476 /* Try to guess a value using the metered flag in IP configuration */
9477 if (value == NM_METERED_INVALID) {
9478 if ( priv->ip4_config
9479 && priv->ip4_state == IP_DONE
9480 && nm_ip4_config_get_metered (priv->ip4_config))
9481 value = NM_METERED_GUESS_YES;
9484 /* Otherwise look at connection type */
9485 if (value == NM_METERED_INVALID) {
9486 if ( nm_connection_is_type (connection, NM_SETTING_GSM_SETTING_NAME)
9487 || nm_connection_is_type (connection, NM_SETTING_CDMA_SETTING_NAME))
9488 value = NM_METERED_GUESS_YES;
9490 value = NM_METERED_GUESS_NO;
9493 if (value != priv->metered) {
9494 _LOGD (LOGD_DEVICE, "set metered value %d", value);
9495 priv->metered = value;
9496 _notify (self, PROP_METERED);
9501 _nm_device_check_connection_available (NMDevice *self,
9502 NMConnection *connection,
9503 NMDeviceCheckConAvailableFlags flags,
9504 const char *specific_object)
9506 NMDeviceState state;
9508 /* an unrealized software device is always available, hardware devices never. */
9509 if (!nm_device_is_real (self)) {
9510 if (nm_device_is_software (self))
9511 return nm_device_check_connection_compatible (self, connection);
9515 state = nm_device_get_state (self);
9516 if (state < NM_DEVICE_STATE_UNMANAGED)
9518 if ( state < NM_DEVICE_STATE_UNAVAILABLE
9519 && ( ( !NM_FLAGS_ANY (flags, NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST)
9520 && !nm_device_get_managed (self, FALSE))
9521 || ( NM_FLAGS_ANY (flags, NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST)
9522 && !nm_device_get_managed (self, TRUE))))
9524 if ( state < NM_DEVICE_STATE_DISCONNECTED
9525 && !nm_device_is_software (self)
9526 && ( ( !NM_FLAGS_ANY (flags, NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST)
9527 && !nm_device_is_available (self, NM_DEVICE_CHECK_DEV_AVAILABLE_NONE))
9528 || ( NM_FLAGS_ANY (flags, NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST)
9529 && !nm_device_is_available (self, NM_DEVICE_CHECK_DEV_AVAILABLE_FOR_USER_REQUEST))))
9532 if (!nm_device_check_connection_compatible (self, connection))
9535 return NM_DEVICE_GET_CLASS (self)->check_connection_available (self, connection, flags, specific_object);
9539 * nm_device_check_connection_available():
9540 * @self: the #NMDevice
9541 * @connection: the #NMConnection to check for availability
9542 * @flags: flags to affect the decision making of whether a connection
9543 * is available. Adding a flag can only make a connection more available,
9545 * @specific_object: a device type dependent argument to further
9546 * filter the result. Passing a non %NULL specific object can only reduce
9547 * the availability of a connection.
9549 * Check if @connection is available to be activated on @self.
9551 * Returns: %TRUE if @connection can be activated on @self
9554 nm_device_check_connection_available (NMDevice *self,
9555 NMConnection *connection,
9556 NMDeviceCheckConAvailableFlags flags,
9557 const char *specific_object)
9561 available = _nm_device_check_connection_available (self, connection, flags, specific_object);
9563 #if NM_MORE_ASSERTS >= 2
9565 /* The meaning of the flags is so that *adding* a flag relaxes a condition, thus making
9566 * the device *more* available. Assert against that requirement by testing all the flags. */
9567 NMDeviceCheckConAvailableFlags i, j, k;
9568 gboolean available_all[NM_DEVICE_CHECK_CON_AVAILABLE_ALL + 1] = { FALSE };
9570 for (i = 0; i <= NM_DEVICE_CHECK_CON_AVAILABLE_ALL; i++)
9571 available_all[i] = _nm_device_check_connection_available (self, connection, i, specific_object);
9573 for (i = 0; i <= NM_DEVICE_CHECK_CON_AVAILABLE_ALL; i++) {
9574 for (j = 1; j <= NM_DEVICE_CHECK_CON_AVAILABLE_ALL; j <<= 1) {
9575 if (NM_FLAGS_HAS (i, j)) {
9577 nm_assert ( available_all[i] == available_all[k]
9578 || available_all[i]);
9589 available_connections_notify (NMDevice *self)
9591 _notify (self, PROP_AVAILABLE_CONNECTIONS);
9595 available_connections_del_all (NMDevice *self)
9597 if (g_hash_table_size (self->priv->available_connections) == 0)
9599 g_hash_table_remove_all (self->priv->available_connections);
9604 available_connections_add (NMDevice *self, NMConnection *connection)
9606 return nm_g_hash_table_add (self->priv->available_connections, g_object_ref (connection));
9610 available_connections_del (NMDevice *self, NMConnection *connection)
9612 return g_hash_table_remove (self->priv->available_connections, connection);
9616 check_connection_available (NMDevice *self,
9617 NMConnection *connection,
9618 NMDeviceCheckConAvailableFlags flags,
9619 const char *specific_object)
9621 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
9623 /* Connections which require a network connection are not available when
9624 * the device has no carrier, even with ignore-carrer=TRUE.
9627 || !connection_requires_carrier (connection))
9630 if ( NM_FLAGS_HAS (flags, _NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST_WAITING_CARRIER)
9631 && priv->carrier_wait_id != 0) {
9632 /* The device has no carrier though the connection requires it.
9634 * If we are still waiting for carrier, the connection is available
9635 * for an explicit user-request. */
9643 nm_device_recheck_available_connections (NMDevice *self)
9645 NMDevicePrivate *priv;
9646 const GSList *connections, *iter;
9647 gboolean changed = FALSE;
9648 GHashTableIter h_iter;
9649 NMConnection *connection;
9651 g_return_if_fail (NM_IS_DEVICE (self));
9653 priv = NM_DEVICE_GET_PRIVATE(self);
9655 if (priv->con_provider) {
9656 gs_unref_hashtable GHashTable *prune_list = NULL;
9658 if (g_hash_table_size (priv->available_connections) > 0) {
9659 prune_list = g_hash_table_new (g_direct_hash, g_direct_equal);
9660 g_hash_table_iter_init (&h_iter, priv->available_connections);
9661 while (g_hash_table_iter_next (&h_iter, (gpointer *) &connection, NULL))
9662 g_hash_table_add (prune_list, connection);
9665 connections = nm_connection_provider_get_connections (priv->con_provider);
9666 for (iter = connections; iter; iter = g_slist_next (iter)) {
9667 connection = NM_CONNECTION (iter->data);
9669 if (nm_device_check_connection_available (self,
9671 NM_DEVICE_CHECK_CON_AVAILABLE_NONE,
9673 if (available_connections_add (self, connection))
9676 g_hash_table_remove (prune_list, connection);
9681 g_hash_table_iter_init (&h_iter, prune_list);
9682 while (g_hash_table_iter_next (&h_iter, (gpointer *) &connection, NULL)) {
9683 if (available_connections_del (self, connection))
9688 if (available_connections_del_all (self))
9693 available_connections_notify (self);
9694 available_connections_check_delete_unrealized (self);
9698 * nm_device_get_best_connection:
9699 * @self: the #NMDevice
9700 * @specific_object: a specific object path if any
9701 * @error: reason why no connection was returned
9703 * Returns a connection that's most suitable for user-initiated activation
9704 * of a device, optionally with a given specific object.
9706 * Returns: the #NMSettingsConnection or %NULL (setting an @error)
9708 NMSettingsConnection *
9709 nm_device_get_best_connection (NMDevice *self,
9710 const char *specific_object,
9713 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
9714 NMSettingsConnection *connection = NULL;
9715 NMSettingsConnection *candidate;
9716 guint64 best_timestamp = 0;
9717 GHashTableIter iter;
9719 g_hash_table_iter_init (&iter, priv->available_connections);
9720 while (g_hash_table_iter_next (&iter, (gpointer) &candidate, NULL)) {
9721 guint64 candidate_timestamp = 0;
9723 /* If a specific object is given, only include connections that are
9724 * compatible with it.
9726 if ( specific_object /* << Optimization: we know that the connection is available without @specific_object. */
9727 && !nm_device_check_connection_available (self,
9728 NM_CONNECTION (candidate),
9729 _NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST,
9733 nm_settings_connection_get_timestamp (candidate, &candidate_timestamp);
9734 if (!connection || (candidate_timestamp > best_timestamp)) {
9735 connection = candidate;
9736 best_timestamp = candidate_timestamp;
9741 g_set_error (error, NM_MANAGER_ERROR, NM_MANAGER_ERROR_UNKNOWN_CONNECTION,
9742 "The device '%s' has no connections available for activation.",
9743 nm_device_get_iface (self));
9750 cp_connection_added_or_updated (NMConnectionProvider *cp, NMConnection *connection, gpointer user_data)
9753 NMDevice *self = user_data;
9755 g_return_if_fail (NM_IS_DEVICE (self));
9756 g_return_if_fail (NM_IS_SETTINGS_CONNECTION (connection));
9758 if (nm_device_check_connection_available (self,
9760 _NM_DEVICE_CHECK_CON_AVAILABLE_FOR_USER_REQUEST,
9762 changed = available_connections_add (self, connection);
9764 changed = available_connections_del (self, connection);
9767 available_connections_notify (self);
9768 available_connections_check_delete_unrealized (self);
9773 cp_connection_removed (NMConnectionProvider *cp, NMConnection *connection, gpointer user_data)
9775 NMDevice *self = user_data;
9777 g_return_if_fail (NM_IS_DEVICE (self));
9779 if (available_connections_del (self, connection)) {
9780 available_connections_notify (self);
9781 available_connections_check_delete_unrealized (self);
9786 nm_device_supports_vlans (NMDevice *self)
9788 return nm_platform_link_supports_vlans (NM_PLATFORM_GET, nm_device_get_ifindex (self));
9792 * nm_device_add_pending_action():
9793 * @self: the #NMDevice to add the pending action to
9794 * @action: a static string that identifies the action
9795 * @assert_not_yet_pending: if %TRUE, assert that the @action is currently not yet pending.
9796 * Otherwise, ignore duplicate scheduling of the same action silently.
9798 * Adds a pending action to the device.
9800 * Returns: %TRUE if the action was added (and not already added before). %FALSE
9801 * if the same action is already scheduled. In the latter case, the action was not scheduled
9805 nm_device_add_pending_action (NMDevice *self, const char *action, gboolean assert_not_yet_pending)
9807 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
9811 g_return_val_if_fail (action, FALSE);
9813 /* Check if the action is already pending. Cannot add duplicate actions */
9814 for (iter = priv->pending_actions; iter; iter = iter->next) {
9815 if (!strcmp (action, iter->data)) {
9816 if (assert_not_yet_pending) {
9817 _LOGW (LOGD_DEVICE, "add_pending_action (%d): '%s' already pending",
9818 count + g_slist_length (iter), action);
9819 g_return_val_if_reached (FALSE);
9821 _LOGD (LOGD_DEVICE, "add_pending_action (%d): '%s' already pending (expected)",
9822 count + g_slist_length (iter), action);
9829 priv->pending_actions = g_slist_append (priv->pending_actions, g_strdup (action));
9832 _LOGD (LOGD_DEVICE, "add_pending_action (%d): '%s'", count, action);
9835 _notify (self, PROP_HAS_PENDING_ACTION);
9841 * nm_device_remove_pending_action():
9842 * @self: the #NMDevice to remove the pending action from
9843 * @action: a static string that identifies the action
9844 * @assert_is_pending: if %TRUE, assert that the @action is pending.
9845 * If %FALSE, don't do anything if the current action is not pending and
9848 * Removes a pending action previously added by nm_device_add_pending_action().
9850 * Returns: whether the @action was pending and is now removed.
9853 nm_device_remove_pending_action (NMDevice *self, const char *action, gboolean assert_is_pending)
9855 NMDevicePrivate *priv;
9856 GSList *iter, *next;
9859 g_return_val_if_fail (self, FALSE);
9860 g_return_val_if_fail (action, FALSE);
9862 priv = NM_DEVICE_GET_PRIVATE (self);
9864 for (iter = priv->pending_actions; iter; iter = next) {
9866 if (!strcmp (action, iter->data)) {
9867 _LOGD (LOGD_DEVICE, "remove_pending_action (%d): '%s'",
9868 count + g_slist_length (iter->next), /* length excluding 'iter' */
9870 g_free (iter->data);
9871 priv->pending_actions = g_slist_delete_link (priv->pending_actions, iter);
9872 if (priv->pending_actions == NULL)
9873 _notify (self, PROP_HAS_PENDING_ACTION);
9879 if (assert_is_pending) {
9880 _LOGW (LOGD_DEVICE, "remove_pending_action (%d): '%s' not pending", count, action);
9881 g_return_val_if_reached (FALSE);
9883 _LOGD (LOGD_DEVICE, "remove_pending_action (%d): '%s' not pending (expected)", count, action);
9889 nm_device_has_pending_action (NMDevice *self)
9891 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
9893 return !!priv->pending_actions;
9896 /***********************************************************/
9899 _cancel_activation (NMDevice *self)
9901 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
9903 /* Clean up when device was deactivated during call to firewall */
9904 if (priv->fw_call) {
9905 nm_firewall_manager_cancel_call (priv->fw_call);
9906 g_warn_if_fail (!priv->fw_call);
9907 priv->fw_call = NULL;
9909 priv->fw_ready = FALSE;
9911 ip_check_gw_ping_cleanup (self);
9913 /* Break the activation chain */
9914 activation_source_clear (self, AF_INET);
9915 activation_source_clear (self, AF_INET6);
9919 _cleanup_generic_pre (NMDevice *self, CleanupType cleanup_type)
9921 NMConnection *connection;
9923 _cancel_activation (self);
9925 connection = nm_device_get_applied_connection (self);
9926 if ( cleanup_type == CLEANUP_TYPE_DECONFIGURE
9928 && !nm_device_uses_assumed_connection (self)) {
9929 nm_firewall_manager_remove_from_zone (nm_firewall_manager_get (),
9930 nm_device_get_ip_iface (self),
9936 /* Clear any queued transitions */
9937 nm_device_queued_state_clear (self);
9939 _cleanup_ip4_pre (self, cleanup_type);
9940 _cleanup_ip6_pre (self, cleanup_type);
9944 _cleanup_generic_post (NMDevice *self, CleanupType cleanup_type)
9946 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
9947 NMDeviceStateReason ignored = NM_DEVICE_STATE_REASON_NONE;
9949 priv->default_route.v4_has = FALSE;
9950 priv->default_route.v6_has = FALSE;
9952 if (cleanup_type == CLEANUP_TYPE_DECONFIGURE) {
9953 priv->default_route.v4_is_assumed = FALSE;
9954 priv->default_route.v6_is_assumed = FALSE;
9955 nm_default_route_manager_ip4_update_default_route (nm_default_route_manager_get (), self);
9956 nm_default_route_manager_ip6_update_default_route (nm_default_route_manager_get (), self);
9959 priv->default_route.v4_is_assumed = TRUE;
9960 priv->default_route.v6_is_assumed = TRUE;
9961 nm_default_route_manager_ip4_update_default_route (nm_default_route_manager_get (), self);
9962 nm_default_route_manager_ip6_update_default_route (nm_default_route_manager_get (), self);
9964 priv->v4_commit_first_time = TRUE;
9965 priv->v6_commit_first_time = TRUE;
9967 priv->linklocal6_dad_counter = 0;
9969 /* Clean up IP configs; this does not actually deconfigure the
9970 * interface; the caller must flush routes and addresses explicitly.
9972 nm_device_set_ip4_config (self, NULL, 0, TRUE, TRUE, &ignored);
9973 nm_device_set_ip6_config (self, NULL, TRUE, TRUE, &ignored);
9974 g_clear_object (&priv->con_ip4_config);
9975 g_clear_object (&priv->dev_ip4_config);
9976 g_clear_object (&priv->ext_ip4_config);
9977 g_clear_object (&priv->wwan_ip4_config);
9978 g_clear_object (&priv->ip4_config);
9979 g_clear_object (&priv->con_ip6_config);
9980 g_clear_object (&priv->ac_ip6_config);
9981 g_clear_object (&priv->ext_ip6_config);
9982 g_clear_object (&priv->ext_ip6_config_captured);
9983 g_clear_object (&priv->wwan_ip6_config);
9984 g_clear_object (&priv->ip6_config);
9986 g_slist_free_full (priv->vpn4_configs, g_object_unref);
9987 priv->vpn4_configs = NULL;
9988 g_slist_free_full (priv->vpn6_configs, g_object_unref);
9989 priv->vpn6_configs = NULL;
9991 clear_act_request (self);
9993 /* Clear legacy IPv4 address property */
9994 if (priv->ip4_address) {
9995 priv->ip4_address = 0;
9996 _notify (self, PROP_IP4_ADDRESS);
9999 if (cleanup_type == CLEANUP_TYPE_DECONFIGURE) {
10000 /* Check if the device was deactivated, and if so, delete_link.
10001 * Don't call delete_link synchronously because we are currently
10002 * handling a state change -- which is not reentrant. */
10003 delete_on_deactivate_check_and_schedule (self, nm_device_get_ip_ifindex (self));
10006 /* ip_iface should be cleared after flushing all routes and addreses, since
10007 * those are identified by ip_iface, not by iface (which might be a tty
10010 nm_device_set_ip_iface (self, NULL);
10014 * nm_device_cleanup
10016 * Remove a device's routing table entries and IP addresses.
10020 nm_device_cleanup (NMDevice *self, NMDeviceStateReason reason, CleanupType cleanup_type)
10022 NMDevicePrivate *priv;
10025 g_return_if_fail (NM_IS_DEVICE (self));
10027 if (reason == NM_DEVICE_STATE_REASON_NOW_MANAGED)
10028 _LOGD (LOGD_DEVICE, "preparing device");
10030 _LOGD (LOGD_DEVICE, "deactivating device (reason '%s') [%d]", reason_to_string (reason), reason);
10032 /* Save whether or not we tried IPv6 for later */
10033 priv = NM_DEVICE_GET_PRIVATE (self);
10035 _cleanup_generic_pre (self, cleanup_type);
10037 /* Turn off kernel IPv6 */
10038 if (cleanup_type == CLEANUP_TYPE_DECONFIGURE) {
10039 set_disable_ipv6 (self, "1");
10040 nm_device_ipv6_sysctl_set (self, "accept_ra", "0");
10041 nm_device_ipv6_sysctl_set (self, "use_tempaddr", "0");
10044 /* Call device type-specific deactivation */
10045 if (NM_DEVICE_GET_CLASS (self)->deactivate)
10046 NM_DEVICE_GET_CLASS (self)->deactivate (self);
10048 /* master: release slaves */
10049 nm_device_master_release_slaves (self);
10051 /* slave: mark no longer enslaved */
10053 && nm_platform_link_get_master (NM_PLATFORM_GET, priv->ifindex) <= 0)
10054 nm_device_master_release_one_slave (priv->master, self, FALSE, NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED);
10056 /* Take out any entries in the routing table and any IP address the device had. */
10057 ifindex = nm_device_get_ip_ifindex (self);
10059 nm_route_manager_route_flush (nm_route_manager_get (), ifindex);
10060 nm_platform_address_flush (NM_PLATFORM_GET, ifindex);
10063 if (priv->lldp_listener)
10064 nm_lldp_listener_stop (priv->lldp_listener);
10066 nm_device_update_metered (self);
10067 _cleanup_generic_post (self, cleanup_type);
10071 bin2hexstr (const char *bytes, gsize len)
10076 g_return_val_if_fail (bytes != NULL, NULL);
10077 g_return_val_if_fail (len > 0, NULL);
10079 str = g_string_sized_new (len * 2 + 1);
10080 for (i = 0; i < len; i++) {
10082 g_string_append_c (str, ':');
10083 g_string_append_printf (str, "%02x", (guint8) bytes[i]);
10085 return g_string_free (str, FALSE);
10089 find_dhcp4_address (NMDevice *self)
10091 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
10094 if (!priv->ip4_config)
10097 n = nm_ip4_config_get_num_addresses (priv->ip4_config);
10098 for (i = 0; i < n; i++) {
10099 const NMPlatformIP4Address *a = nm_ip4_config_get_address (priv->ip4_config, i);
10101 if (a->source == NM_IP_CONFIG_SOURCE_DHCP)
10102 return g_strdup (nm_utils_inet4_ntop (a->address, NULL));
10108 nm_device_spawn_iface_helper (NMDevice *self)
10110 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
10111 gboolean configured = FALSE;
10112 NMConnection *connection;
10113 GError *error = NULL;
10114 const char *method;
10116 gs_free char *dhcp4_address = NULL;
10117 char *logging_backend;
10119 if (priv->state != NM_DEVICE_STATE_ACTIVATED)
10121 if (!nm_device_can_assume_connections (self))
10124 connection = nm_device_get_applied_connection (self);
10125 g_assert (connection);
10127 argv = g_ptr_array_sized_new (10);
10128 g_ptr_array_set_free_func (argv, g_free);
10130 g_ptr_array_add (argv, g_strdup (LIBEXECDIR "/nm-iface-helper"));
10131 g_ptr_array_add (argv, g_strdup ("--ifname"));
10132 g_ptr_array_add (argv, g_strdup (nm_device_get_ip_iface (self)));
10133 g_ptr_array_add (argv, g_strdup ("--uuid"));
10134 g_ptr_array_add (argv, g_strdup (nm_connection_get_uuid (connection)));
10136 logging_backend = nm_config_get_is_debug (nm_config_get ())
10137 ? g_strdup ("debug")
10138 : nm_config_data_get_value (NM_CONFIG_GET_DATA_ORIG,
10139 NM_CONFIG_KEYFILE_GROUP_LOGGING,
10140 NM_CONFIG_KEYFILE_KEY_LOGGING_BACKEND,
10141 NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY);
10142 if (logging_backend) {
10143 g_ptr_array_add (argv, g_strdup ("--logging-backend"));
10144 g_ptr_array_add (argv, logging_backend);
10147 dhcp4_address = find_dhcp4_address (self);
10149 method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP4_CONFIG);
10150 if (g_strcmp0 (method, NM_SETTING_IP4_CONFIG_METHOD_AUTO) == 0) {
10151 NMSettingIPConfig *s_ip4;
10152 char *hex_client_id;
10154 s_ip4 = nm_connection_get_setting_ip4_config (connection);
10157 g_ptr_array_add (argv, g_strdup ("--priority4"));
10158 g_ptr_array_add (argv, g_strdup_printf ("%u", nm_device_get_ip4_route_metric (self)));
10160 g_ptr_array_add (argv, g_strdup ("--dhcp4"));
10161 g_ptr_array_add (argv, g_strdup (dhcp4_address));
10162 if (nm_setting_ip_config_get_may_fail (s_ip4) == FALSE)
10163 g_ptr_array_add (argv, g_strdup ("--dhcp4-required"));
10165 if (priv->dhcp4_client) {
10166 const char *hostname, *fqdn;
10169 client_id = nm_dhcp_client_get_client_id (priv->dhcp4_client);
10171 g_ptr_array_add (argv, g_strdup ("--dhcp4-clientid"));
10172 hex_client_id = bin2hexstr (g_bytes_get_data (client_id, NULL),
10173 g_bytes_get_size (client_id));
10174 g_ptr_array_add (argv, hex_client_id);
10177 hostname = nm_dhcp_client_get_hostname (priv->dhcp4_client);
10179 g_ptr_array_add (argv, g_strdup ("--dhcp4-hostname"));
10180 g_ptr_array_add (argv, g_strdup (hostname));
10183 fqdn = nm_dhcp_client_get_fqdn (priv->dhcp4_client);
10185 g_ptr_array_add (argv, g_strdup ("--dhcp4-fqdn"));
10186 g_ptr_array_add (argv, g_strdup (fqdn));
10193 method = nm_utils_get_ip_config_method (connection, NM_TYPE_SETTING_IP6_CONFIG);
10194 if (g_strcmp0 (method, NM_SETTING_IP6_CONFIG_METHOD_AUTO) == 0) {
10195 NMSettingIPConfig *s_ip6;
10197 NMUtilsIPv6IfaceId iid = NM_UTILS_IPV6_IFACE_ID_INIT;
10199 s_ip6 = nm_connection_get_setting_ip6_config (connection);
10202 g_ptr_array_add (argv, g_strdup ("--priority6"));
10203 g_ptr_array_add (argv, g_strdup_printf ("%u", nm_device_get_ip6_route_metric (self)));
10205 g_ptr_array_add (argv, g_strdup ("--slaac"));
10207 if (nm_setting_ip_config_get_may_fail (s_ip6) == FALSE)
10208 g_ptr_array_add (argv, g_strdup ("--slaac-required"));
10210 g_ptr_array_add (argv, g_strdup ("--slaac-tempaddr"));
10211 g_ptr_array_add (argv, g_strdup_printf ("%d", priv->rdisc_use_tempaddr));
10213 if (nm_device_get_ip_iface_identifier (self, &iid)) {
10214 g_ptr_array_add (argv, g_strdup ("--iid"));
10215 hex_iid = bin2hexstr ((const char *) iid.id_u8, sizeof (NMUtilsIPv6IfaceId));
10216 g_ptr_array_add (argv, hex_iid);
10219 g_ptr_array_add (argv, g_strdup ("--addr-gen-mode"));
10220 g_ptr_array_add (argv, g_strdup_printf ("%d", nm_setting_ip6_config_get_addr_gen_mode (NM_SETTING_IP6_CONFIG (s_ip6))));
10228 g_ptr_array_add (argv, NULL);
10230 if (nm_logging_enabled (LOGL_DEBUG, LOGD_DEVICE)) {
10233 tmp = g_strjoinv (" ", (char **) argv->pdata);
10234 _LOGD (LOGD_DEVICE, "running '%s'", tmp);
10238 if (g_spawn_async (NULL, (char **) argv->pdata, NULL,
10239 G_SPAWN_DO_NOT_REAP_CHILD, NULL, NULL, &pid, &error)) {
10240 _LOGI (LOGD_DEVICE, "spawned helper PID %u", (guint) pid);
10242 _LOGW (LOGD_DEVICE, "failed to spawn helper: %s", error->message);
10243 g_error_free (error);
10247 g_ptr_array_unref (argv);
10250 /***********************************************************/
10253 ip_config_valid (NMDeviceState state)
10255 return (state == NM_DEVICE_STATE_UNMANAGED) ||
10256 (state >= NM_DEVICE_STATE_IP_CHECK &&
10257 state <= NM_DEVICE_STATE_DEACTIVATING);
10261 notify_ip_properties (NMDevice *self)
10263 _notify (self, PROP_IP_IFACE);
10264 _notify (self, PROP_IP4_CONFIG);
10265 _notify (self, PROP_DHCP4_CONFIG);
10266 _notify (self, PROP_IP6_CONFIG);
10267 _notify (self, PROP_DHCP6_CONFIG);
10271 ip6_managed_setup (NMDevice *self)
10273 set_nm_ipv6ll (self, TRUE);
10274 set_disable_ipv6 (self, "1");
10275 nm_device_ipv6_sysctl_set (self, "accept_ra_defrtr", "0");
10276 nm_device_ipv6_sysctl_set (self, "accept_ra_pinfo", "0");
10277 nm_device_ipv6_sysctl_set (self, "accept_ra_rtr_pref", "0");
10278 nm_device_ipv6_sysctl_set (self, "use_tempaddr", "0");
10282 deactivate_async_ready (NMDevice *self,
10284 gpointer user_data)
10286 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
10287 NMDeviceStateReason reason = GPOINTER_TO_UINT (user_data);
10288 GError *error = NULL;
10290 NM_DEVICE_GET_CLASS (self)->deactivate_async_finish (self, res, &error);
10292 /* If operation cancelled, just return */
10293 if ( g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)
10294 || (priv->deactivating_cancellable && g_cancellable_is_cancelled (priv->deactivating_cancellable))) {
10295 _LOGW (LOGD_DEVICE, "Deactivation cancelled");
10297 /* In every other case, transition to the DISCONNECTED state */
10300 _LOGW (LOGD_DEVICE, "Deactivation failed: %s",
10303 nm_device_queue_state (self, NM_DEVICE_STATE_DISCONNECTED, reason);
10306 g_clear_object (&priv->deactivating_cancellable);
10307 g_clear_error (&error);
10311 deactivate_dispatcher_complete (guint call_id, gpointer user_data)
10313 NMDevice *self = NM_DEVICE (user_data);
10314 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
10315 NMDeviceStateReason reason;
10317 g_return_if_fail (call_id == priv->dispatcher.call_id);
10318 g_return_if_fail (priv->dispatcher.post_state == NM_DEVICE_STATE_DISCONNECTED);
10320 reason = priv->dispatcher.post_state_reason;
10322 priv->dispatcher.call_id = 0;
10323 priv->dispatcher.post_state = NM_DEVICE_STATE_UNKNOWN;
10324 priv->dispatcher.post_state_reason = NM_DEVICE_STATE_REASON_NONE;
10326 if (priv->deactivating_cancellable) {
10327 g_warn_if_reached ();
10328 g_cancellable_cancel (priv->deactivating_cancellable);
10329 g_clear_object (&priv->deactivating_cancellable);
10332 if ( NM_DEVICE_GET_CLASS (self)->deactivate_async
10333 && NM_DEVICE_GET_CLASS (self)->deactivate_async_finish) {
10334 priv->deactivating_cancellable = g_cancellable_new ();
10335 NM_DEVICE_GET_CLASS (self)->deactivate_async (self,
10336 priv->deactivating_cancellable,
10337 (GAsyncReadyCallback) deactivate_async_ready,
10338 GUINT_TO_POINTER (reason));
10340 nm_device_queue_state (self, NM_DEVICE_STATE_DISCONNECTED, reason);
10344 _set_state_full (NMDevice *self,
10345 NMDeviceState state,
10346 NMDeviceStateReason reason,
10349 NMDevicePrivate *priv;
10350 NMDeviceState old_state;
10352 gboolean no_firmware = FALSE;
10353 NMSettingsConnection *connection;
10354 NMConnection *applied_connection;
10356 g_return_if_fail (NM_IS_DEVICE (self));
10358 priv = NM_DEVICE_GET_PRIVATE (self);
10360 /* Track re-entry */
10361 g_warn_if_fail (priv->in_state_changed == FALSE);
10363 old_state = priv->state;
10365 /* Do nothing if state isn't changing, but as a special case allow
10366 * re-setting UNAVAILABLE if the device is missing firmware so that we
10367 * can retry device initialization.
10369 if ( (priv->state == state)
10370 && ( state != NM_DEVICE_STATE_UNAVAILABLE
10371 || !priv->firmware_missing)) {
10372 _LOGD (LOGD_DEVICE, "state change: %s -> %s (reason '%s') [%d %d %d]%s",
10373 state_to_string (old_state),
10374 state_to_string (state),
10375 reason_to_string (reason),
10379 priv->firmware_missing ? " (missing firmware)" : "");
10383 _LOGI (LOGD_DEVICE, "state change: %s -> %s (reason '%s') [%d %d %d]",
10384 state_to_string (old_state),
10385 state_to_string (state),
10386 reason_to_string (reason),
10391 priv->in_state_changed = TRUE;
10393 priv->state = state;
10394 priv->state_reason = reason;
10396 /* Clear any queued transitions */
10397 nm_device_queued_state_clear (self);
10399 dispatcher_cleanup (self);
10400 if (priv->deactivating_cancellable)
10401 g_cancellable_cancel (priv->deactivating_cancellable);
10403 /* Cache the activation request for the dispatcher */
10404 req = priv->act_request ? g_object_ref (priv->act_request) : NULL;
10406 if (state <= NM_DEVICE_STATE_UNAVAILABLE) {
10407 if (available_connections_del_all (self))
10408 available_connections_notify (self);
10409 if (old_state > NM_DEVICE_STATE_UNAVAILABLE)
10410 _clear_queued_act_request (priv);
10413 /* Update the available connections list when a device first becomes available */
10414 if (state >= NM_DEVICE_STATE_DISCONNECTED && old_state < NM_DEVICE_STATE_DISCONNECTED)
10415 nm_device_recheck_available_connections (self);
10417 /* Handle the new state here; but anything that could trigger
10418 * another state change should be done below.
10421 case NM_DEVICE_STATE_UNMANAGED:
10422 nm_device_set_firmware_missing (self, FALSE);
10423 if (old_state > NM_DEVICE_STATE_UNMANAGED) {
10424 if (reason == NM_DEVICE_STATE_REASON_REMOVED) {
10425 nm_device_cleanup (self, reason, CLEANUP_TYPE_REMOVED);
10427 /* Clean up if the device is now unmanaged but was activated */
10428 if (nm_device_get_act_request (self))
10429 nm_device_cleanup (self, reason, CLEANUP_TYPE_DECONFIGURE);
10430 nm_device_take_down (self, TRUE);
10431 set_nm_ipv6ll (self, FALSE);
10432 restore_ip6_properties (self);
10436 case NM_DEVICE_STATE_UNAVAILABLE:
10437 if (old_state == NM_DEVICE_STATE_UNMANAGED) {
10438 save_ip6_properties (self);
10439 if (reason != NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED)
10440 ip6_managed_setup (self);
10443 if (reason != NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED) {
10444 if (old_state == NM_DEVICE_STATE_UNMANAGED || priv->firmware_missing) {
10445 if (!nm_device_bring_up (self, TRUE, &no_firmware) && no_firmware)
10446 _LOGW (LOGD_HW, "firmware may be missing.");
10447 nm_device_set_firmware_missing (self, no_firmware ? TRUE : FALSE);
10450 /* Ensure the device gets deactivated in response to stuff like
10451 * carrier changes or rfkill. But don't deactivate devices that are
10452 * about to assume a connection since that defeats the purpose of
10453 * assuming the device's existing connection.
10455 * Note that we "deactivate" the device even when coming from
10456 * UNMANAGED, to ensure that it's in a clean state.
10458 nm_device_cleanup (self, reason, CLEANUP_TYPE_DECONFIGURE);
10461 case NM_DEVICE_STATE_DISCONNECTED:
10462 if (old_state > NM_DEVICE_STATE_DISCONNECTED) {
10463 /* Ensure devices that previously assumed a connection now have
10464 * userspace IPv6LL enabled.
10466 set_nm_ipv6ll (self, TRUE);
10468 nm_device_cleanup (self, reason, CLEANUP_TYPE_DECONFIGURE);
10469 } else if (old_state < NM_DEVICE_STATE_DISCONNECTED) {
10470 if (reason != NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED) {
10471 /* Ensure IPv6 is set up as it may not have been done when
10472 * entering the UNAVAILABLE state depending on the reason.
10474 ip6_managed_setup (self);
10478 case NM_DEVICE_STATE_NEED_AUTH:
10479 if (old_state > NM_DEVICE_STATE_NEED_AUTH) {
10480 /* Clean up any half-done IP operations if the device's layer2
10481 * finds out it needs authentication during IP config.
10483 _cleanup_ip4_pre (self, CLEANUP_TYPE_DECONFIGURE);
10484 _cleanup_ip6_pre (self, CLEANUP_TYPE_DECONFIGURE);
10491 /* Reset autoconnect flag when the device is activating or connected. */
10492 if ( state >= NM_DEVICE_STATE_PREPARE
10493 && state <= NM_DEVICE_STATE_ACTIVATED)
10494 nm_device_set_autoconnect (self, TRUE);
10496 _notify (self, PROP_STATE);
10497 _notify (self, PROP_STATE_REASON);
10498 g_signal_emit_by_name (self, NM_DEVICE_STATE_CHANGED, state, old_state, reason);
10500 /* Post-process the event after internal notification */
10503 case NM_DEVICE_STATE_UNAVAILABLE:
10504 /* If the device can activate now (ie, it's got a carrier, the supplicant
10505 * is active, or whatever) schedule a delayed transition to DISCONNECTED
10506 * to get things rolling. The device can't transition immediately because
10507 * we can't change states again from the state handler for a variety of
10510 if (nm_device_is_available (self, NM_DEVICE_CHECK_DEV_AVAILABLE_NONE)) {
10511 nm_device_queue_recheck_available (self,
10512 NM_DEVICE_STATE_REASON_NONE,
10513 NM_DEVICE_STATE_REASON_NONE);
10515 _LOGD (LOGD_DEVICE, "device not yet available for transition to DISCONNECTED");
10518 case NM_DEVICE_STATE_DEACTIVATING:
10519 _cancel_activation (self);
10521 if (nm_device_has_capability (self, NM_DEVICE_CAP_CARRIER_DETECT)) {
10522 /* We cache the ignore_carrier state to not react on config-reloads while the connection
10523 * is active. But on deactivating, reset the ignore-carrier flag to the current state. */
10524 priv->ignore_carrier = nm_config_data_get_ignore_carrier (NM_CONFIG_GET_DATA, self);
10528 nm_dispatcher_call_sync (DISPATCHER_ACTION_PRE_DOWN,
10529 nm_act_request_get_settings_connection (req),
10530 nm_act_request_get_applied_connection (req),
10533 priv->dispatcher.post_state = NM_DEVICE_STATE_DISCONNECTED;
10534 priv->dispatcher.post_state_reason = reason;
10535 if (!nm_dispatcher_call (DISPATCHER_ACTION_PRE_DOWN,
10536 nm_act_request_get_settings_connection (req),
10537 nm_act_request_get_applied_connection (req),
10539 deactivate_dispatcher_complete,
10541 &priv->dispatcher.call_id)) {
10542 /* Just proceed on errors */
10543 deactivate_dispatcher_complete (0, self);
10547 case NM_DEVICE_STATE_DISCONNECTED:
10548 if ( priv->queued_act_request
10549 && !priv->queued_act_request_is_waiting_for_carrier) {
10550 NMActRequest *queued_req;
10553 queued_req = priv->queued_act_request;
10554 priv->queued_act_request = NULL;
10555 success = _device_activate (self, queued_req);
10556 g_object_unref (queued_req);
10562 case NM_DEVICE_STATE_ACTIVATED:
10563 _LOGI (LOGD_DEVICE, "Activation: successful, device activated.");
10564 nm_device_update_metered (self);
10565 nm_dispatcher_call (DISPATCHER_ACTION_UP,
10566 nm_act_request_get_settings_connection (req),
10567 nm_act_request_get_applied_connection (req),
10568 self, NULL, NULL, NULL);
10570 case NM_DEVICE_STATE_FAILED:
10571 /* Usually upon failure the activation chain is interrupted in
10572 * one of the stages; but in some cases the device fails for
10573 * external events (as a failure of master connection) while
10574 * the activation sequence is running and so we need to ensure
10575 * that the chain is terminated here.
10577 _cancel_activation (self);
10579 if (nm_device_uses_assumed_connection (self)) {
10580 /* Avoid tearing down assumed connection, assume it's connected */
10581 nm_device_queue_state (self,
10582 NM_DEVICE_STATE_ACTIVATED,
10583 NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED);
10587 connection = nm_device_get_settings_connection (self);
10588 _LOGW (LOGD_DEVICE | LOGD_WIFI,
10589 "Activation: failed for connection '%s'",
10590 connection ? nm_settings_connection_get_id (connection) : "<unknown>");
10592 /* Notify any slaves of the unexpected failure */
10593 nm_device_master_release_slaves (self);
10595 /* If the connection doesn't yet have a timestamp, set it to zero so that
10596 * we can distinguish between connections we've tried to activate and have
10597 * failed (zero timestamp), connections that succeeded (non-zero timestamp),
10598 * and those we haven't tried yet (no timestamp).
10600 if (connection && !nm_settings_connection_get_timestamp (connection, NULL))
10601 nm_settings_connection_update_timestamp (connection, (guint64) 0, TRUE);
10603 /* Schedule the transition to DISCONNECTED. The device can't transition
10604 * immediately because we can't change states again from the state
10605 * handler for a variety of reasons.
10607 nm_device_queue_state (self, NM_DEVICE_STATE_DISCONNECTED, NM_DEVICE_STATE_REASON_NONE);
10609 case NM_DEVICE_STATE_IP_CHECK:
10610 /* Now that IP config has completed, check if the firewall
10611 * zone must be set again for the IP interface.
10613 applied_connection = nm_device_get_applied_connection (self);
10615 if ( applied_connection
10616 && priv->ifindex != priv->ip_ifindex
10617 && !nm_device_uses_assumed_connection (self)) {
10618 NMSettingConnection *s_con;
10621 s_con = nm_connection_get_setting_connection (applied_connection);
10622 zone = nm_setting_connection_get_zone (s_con);
10623 g_assert (!priv->fw_call);
10624 priv->fw_call = nm_firewall_manager_add_or_change_zone (nm_firewall_manager_get (),
10625 nm_device_get_ip_iface (self),
10628 fw_change_zone_cb_ip_check,
10631 nm_device_start_ip_check (self);
10633 /* IP-related properties are only valid when the device has IP configuration;
10634 * now that it does, ensure their change notifications are emitted.
10636 notify_ip_properties (self);
10638 case NM_DEVICE_STATE_SECONDARIES:
10639 ip_check_gw_ping_cleanup (self);
10640 _LOGD (LOGD_DEVICE, "device entered SECONDARIES state");
10646 if (state > NM_DEVICE_STATE_DISCONNECTED)
10647 delete_on_deactivate_unschedule (self);
10649 if ( (old_state == NM_DEVICE_STATE_ACTIVATED || old_state == NM_DEVICE_STATE_DEACTIVATING)
10650 && (state != NM_DEVICE_STATE_DEACTIVATING)) {
10652 nm_dispatcher_call_sync (DISPATCHER_ACTION_DOWN,
10653 nm_act_request_get_settings_connection (req),
10654 nm_act_request_get_applied_connection (req),
10657 nm_dispatcher_call (DISPATCHER_ACTION_DOWN,
10658 nm_act_request_get_settings_connection (req),
10659 nm_act_request_get_applied_connection (req),
10660 self, NULL, NULL, NULL);
10664 /* IP-related properties are only valid when the device has IP configuration.
10665 * If it no longer does, ensure their change notifications are emitted.
10667 if (ip_config_valid (old_state) && !ip_config_valid (state))
10668 notify_ip_properties (self);
10670 /* Dispose of the cached activation request */
10672 g_object_unref (req);
10674 priv->in_state_changed = FALSE;
10676 if ((old_state > NM_DEVICE_STATE_UNMANAGED) != (state > NM_DEVICE_STATE_UNMANAGED))
10677 _notify (self, PROP_MANAGED);
10681 nm_device_state_changed (NMDevice *self,
10682 NMDeviceState state,
10683 NMDeviceStateReason reason)
10685 _set_state_full (self, state, reason, FALSE);
10689 queued_set_state (gpointer user_data)
10691 NMDevice *self = NM_DEVICE (user_data);
10692 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
10693 NMDeviceState new_state;
10694 NMDeviceStateReason new_reason;
10696 if (priv->queued_state.id) {
10697 _LOGD (LOGD_DEVICE, "running queued state change to %s (id %d)",
10698 state_to_string (priv->queued_state.state),
10699 priv->queued_state.id);
10701 /* Clear queued state struct before triggering state change, since
10702 * the state change may queue another state.
10704 priv->queued_state.id = 0;
10705 new_state = priv->queued_state.state;
10706 new_reason = priv->queued_state.reason;
10707 nm_device_queued_state_clear (self);
10709 nm_device_state_changed (self, new_state, new_reason);
10710 nm_device_remove_pending_action (self, queued_state_to_string (new_state), TRUE);
10712 g_warn_if_fail (priv->queued_state.state == NM_DEVICE_STATE_UNKNOWN);
10713 g_warn_if_fail (priv->queued_state.reason == NM_DEVICE_STATE_REASON_NONE);
10719 nm_device_queue_state (NMDevice *self,
10720 NMDeviceState state,
10721 NMDeviceStateReason reason)
10723 NMDevicePrivate *priv;
10725 g_return_if_fail (NM_IS_DEVICE (self));
10727 priv = NM_DEVICE_GET_PRIVATE (self);
10729 if (priv->queued_state.id && priv->queued_state.state == state)
10732 /* Add pending action for the new state before clearing the queued states, so
10733 * that we don't accidently pop all pending states and reach 'startup complete' */
10734 nm_device_add_pending_action (self, queued_state_to_string (state), TRUE);
10736 /* We should only ever have one delayed state transition at a time */
10737 if (priv->queued_state.id) {
10738 _LOGW (LOGD_DEVICE, "overwriting previously queued state change to %s (%s)",
10739 state_to_string (priv->queued_state.state),
10740 reason_to_string (priv->queued_state.reason));
10741 nm_device_queued_state_clear (self);
10744 priv->queued_state.state = state;
10745 priv->queued_state.reason = reason;
10746 priv->queued_state.id = g_idle_add (queued_set_state, self);
10748 _LOGD (LOGD_DEVICE, "queued state change to %s due to %s (id %d)",
10749 state_to_string (state), reason_to_string (reason),
10750 priv->queued_state.id);
10754 nm_device_queued_state_peek (NMDevice *self)
10756 NMDevicePrivate *priv;
10758 g_return_val_if_fail (NM_IS_DEVICE (self), NM_DEVICE_STATE_UNKNOWN);
10760 priv = NM_DEVICE_GET_PRIVATE (self);
10762 return priv->queued_state.id ? priv->queued_state.state : NM_DEVICE_STATE_UNKNOWN;
10766 nm_device_queued_state_clear (NMDevice *self)
10768 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
10770 if (priv->queued_state.id) {
10771 _LOGD (LOGD_DEVICE, "clearing queued state transition (id %d)",
10772 priv->queued_state.id);
10773 nm_clear_g_source (&priv->queued_state.id);
10774 nm_device_remove_pending_action (self, queued_state_to_string (priv->queued_state.state), TRUE);
10776 memset (&priv->queued_state, 0, sizeof (priv->queued_state));
10780 nm_device_get_state (NMDevice *self)
10782 g_return_val_if_fail (NM_IS_DEVICE (self), NM_DEVICE_STATE_UNKNOWN);
10784 return NM_DEVICE_GET_PRIVATE (self)->state;
10787 /***********************************************************/
10788 /* NMConfigDevice interface related stuff */
10791 nm_device_get_hw_address (NMDevice *self)
10793 NMDevicePrivate *priv;
10795 g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
10796 priv = NM_DEVICE_GET_PRIVATE (self);
10798 return priv->hw_addr_len ? priv->hw_addr : NULL;
10802 nm_device_update_hw_address (NMDevice *self)
10804 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
10805 int ifindex = nm_device_get_ifindex (self);
10806 const guint8 *hwaddr;
10807 gsize hwaddrlen = 0;
10808 static const guint8 zero_hwaddr[ETH_ALEN];
10813 hwaddr = nm_platform_link_get_address (NM_PLATFORM_GET, ifindex, &hwaddrlen);
10815 if ( priv->type == NM_DEVICE_TYPE_ETHERNET
10816 && nm_utils_hwaddr_matches (hwaddr, hwaddrlen, zero_hwaddr, sizeof (zero_hwaddr)))
10820 priv->hw_addr_len = hwaddrlen;
10821 if (!priv->hw_addr || !nm_utils_hwaddr_matches (priv->hw_addr, -1, hwaddr, hwaddrlen)) {
10822 g_free (priv->hw_addr);
10823 priv->hw_addr = nm_utils_hwaddr_ntoa (hwaddr, hwaddrlen);
10825 _LOGD (LOGD_HW | LOGD_DEVICE, "hardware address now %s", priv->hw_addr);
10826 _notify (self, PROP_HW_ADDRESS);
10829 /* Invalid or no hardware address */
10830 if (priv->hw_addr_len != 0) {
10831 g_clear_pointer (&priv->hw_addr, g_free);
10832 priv->hw_addr_len = 0;
10833 _LOGD (LOGD_HW | LOGD_DEVICE,
10834 "previous hardware address is no longer valid");
10835 _notify (self, PROP_HW_ADDRESS);
10841 nm_device_update_initial_hw_address (NMDevice *self)
10843 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
10845 if (priv->hw_addr_len) {
10846 priv->initial_hw_addr = g_strdup (priv->hw_addr);
10847 _LOGD (LOGD_DEVICE | LOGD_HW, "read initial MAC address %s", priv->initial_hw_addr);
10849 if (priv->ifindex > 0) {
10850 guint8 buf[NM_UTILS_HWADDR_LEN_MAX];
10853 if (nm_platform_link_get_permanent_address (NM_PLATFORM_GET, priv->ifindex, buf, &len)) {
10854 g_warn_if_fail (len == priv->hw_addr_len);
10855 priv->perm_hw_addr = nm_utils_hwaddr_ntoa (buf, priv->hw_addr_len);
10856 _LOGD (LOGD_DEVICE | LOGD_HW, "read permanent MAC address %s",
10857 priv->perm_hw_addr);
10859 /* Fall back to current address */
10860 _LOGD (LOGD_HW | LOGD_ETHER, "unable to read permanent MAC address");
10861 priv->perm_hw_addr = g_strdup (priv->hw_addr);
10868 nm_device_set_hw_addr (NMDevice *self, const char *addr,
10869 const char *detail, guint64 hw_log_domain)
10871 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
10872 gboolean success = FALSE;
10873 const char *cur_addr = nm_device_get_hw_address (self);
10874 guint8 addr_bytes[NM_UTILS_HWADDR_LEN_MAX];
10876 /* Fall back to the permanent address */
10878 addr = priv->perm_hw_addr;
10882 /* Do nothing if current MAC is same */
10883 if (cur_addr && nm_utils_hwaddr_matches (cur_addr, -1, addr, -1)) {
10884 _LOGD (LOGD_DEVICE | hw_log_domain, "no MAC address change needed");
10887 if (!nm_utils_hwaddr_aton (addr, addr_bytes, priv->hw_addr_len)) {
10888 _LOGW (LOGD_DEVICE | hw_log_domain, "invalid MAC address %s", addr);
10892 /* Can't change MAC address while device is up */
10893 nm_device_take_down (self, FALSE);
10895 success = nm_platform_link_set_address (NM_PLATFORM_GET, nm_device_get_ip_ifindex (self), addr_bytes, priv->hw_addr_len);
10897 /* MAC address succesfully changed; update the current MAC to match */
10898 nm_device_update_hw_address (self);
10899 cur_addr = nm_device_get_hw_address (self);
10900 if (cur_addr && nm_utils_hwaddr_matches (cur_addr, -1, addr, -1)) {
10901 _LOGI (LOGD_DEVICE | hw_log_domain, "%s MAC address to %s",
10904 _LOGW (LOGD_DEVICE | hw_log_domain,
10905 "new MAC address %s not successfully set", addr);
10909 _LOGW (LOGD_DEVICE | hw_log_domain, "failed to %s MAC address to %s",
10912 nm_device_bring_up (self, TRUE, NULL);
10918 nm_device_get_permanent_hw_address (NMDevice *self)
10920 g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
10922 return NM_DEVICE_GET_PRIVATE (self)->perm_hw_addr;
10926 nm_device_get_initial_hw_address (NMDevice *self)
10928 g_return_val_if_fail (NM_IS_DEVICE (self), NULL);
10930 return NM_DEVICE_GET_PRIVATE (self)->initial_hw_addr;
10934 * nm_device_spec_match_list:
10935 * @self: an #NMDevice
10936 * @specs: (element-type utf8): a list of device specs
10938 * Checks if @self matches any of the specifications in @specs. The
10939 * currently-supported spec types are:
10941 * "mac:00:11:22:33:44:55" - matches a device with the given
10944 * "interface-name:foo0" - matches a device with the given
10947 * "s390-subchannels:00.11.22" - matches a device with the given
10948 * z/VM / s390 subchannels.
10950 * "*" - matches any device
10952 * Returns: #TRUE if @self matches one of the specs in @specs
10955 nm_device_spec_match_list (NMDevice *self, const GSList *specs)
10957 g_return_val_if_fail (NM_IS_DEVICE (self), FALSE);
10962 return NM_DEVICE_GET_CLASS (self)->spec_match_list (self, specs) == NM_MATCH_SPEC_MATCH;
10965 static NMMatchSpecMatchType
10966 spec_match_list (NMDevice *self, const GSList *specs)
10968 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
10969 NMMatchSpecMatchType matched = NM_MATCH_SPEC_NO_MATCH, m;
10970 const GSList *iter;
10972 for (iter = specs; iter; iter = g_slist_next (iter)) {
10973 if (!strcmp ((const char *) iter->data, "*")) {
10974 matched = NM_MATCH_SPEC_MATCH;
10978 if (priv->hw_addr_len && priv->hw_addr) {
10979 m = nm_match_spec_hwaddr (specs, priv->hw_addr);
10980 matched = MAX (matched, m);
10982 if (matched != NM_MATCH_SPEC_NEG_MATCH) {
10983 m = nm_match_spec_interface_name (specs, nm_device_get_iface (self));
10984 matched = MAX (matched, m);
10986 if (matched != NM_MATCH_SPEC_NEG_MATCH) {
10987 m = nm_match_spec_device_type (specs, nm_device_get_type_description (self));
10988 matched = MAX (matched, m);
10993 /***********************************************************/
10995 static const char *
10996 _activation_func_to_string (ActivationHandleFunc func)
10998 #define FUNC_TO_STRING_CHECK_AND_RETURN(func, f) \
11000 if ((func) == (f)) \
11003 FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage1_device_prepare);
11004 FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage2_device_config);
11005 FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage3_ip_config_start);
11006 FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage4_ip4_config_timeout);
11007 FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage4_ip6_config_timeout);
11008 FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage5_ip4_config_commit);
11009 FUNC_TO_STRING_CHECK_AND_RETURN (func, activate_stage5_ip6_config_commit);
11010 g_return_val_if_reached ("unknown");
11013 /***********************************************************/
11016 nm_device_init (NMDevice *self)
11018 NMDevicePrivate *priv;
11020 priv = G_TYPE_INSTANCE_GET_PRIVATE (self, NM_TYPE_DEVICE, NMDevicePrivate);
11024 priv->type = NM_DEVICE_TYPE_UNKNOWN;
11025 priv->capabilities = NM_DEVICE_CAP_NM_SUPPORTED;
11026 priv->state = NM_DEVICE_STATE_UNMANAGED;
11027 priv->state_reason = NM_DEVICE_STATE_REASON_NONE;
11028 priv->dhcp_timeout = 0;
11029 priv->rfkill_type = RFKILL_TYPE_UNKNOWN;
11030 priv->autoconnect = DEFAULT_AUTOCONNECT;
11031 priv->unmanaged_flags = NM_UNMANAGED_PLATFORM_INIT;
11032 priv->unmanaged_mask = priv->unmanaged_flags;
11033 priv->available_connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL);
11034 priv->ip6_saved_properties = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
11036 priv->default_route.v4_is_assumed = TRUE;
11037 priv->default_route.v6_is_assumed = TRUE;
11039 priv->v4_commit_first_time = TRUE;
11040 priv->v6_commit_first_time = TRUE;
11044 constructor (GType type,
11045 guint n_construct_params,
11046 GObjectConstructParam *construct_params)
11049 GObjectClass *klass;
11051 NMDevicePrivate *priv;
11052 const NMPlatformLink *pllink;
11054 klass = G_OBJECT_CLASS (nm_device_parent_class);
11055 object = klass->constructor (type, n_construct_params, construct_params);
11059 self = NM_DEVICE (object);
11060 priv = NM_DEVICE_GET_PRIVATE (self);
11063 pllink = nm_platform_link_get_by_ifname (NM_PLATFORM_GET, priv->iface);
11065 if (pllink && link_type_compatible (self, pllink->type, NULL, NULL)) {
11066 priv->ifindex = pllink->ifindex;
11067 priv->up = NM_FLAGS_HAS (pllink->n_ifi_flags, IFF_UP);
11075 constructed (GObject *object)
11077 NMDevice *self = NM_DEVICE (object);
11078 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
11079 NMPlatform *platform;
11081 platform = nm_platform_get ();
11083 if (NM_DEVICE_GET_CLASS (self)->get_generic_capabilities)
11084 priv->capabilities |= NM_DEVICE_GET_CLASS (self)->get_generic_capabilities (self);
11086 /* Watch for external IP config changes */
11087 g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP4_ADDRESS_CHANGED, G_CALLBACK (device_ipx_changed), self);
11088 g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP6_ADDRESS_CHANGED, G_CALLBACK (device_ipx_changed), self);
11089 g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP4_ROUTE_CHANGED, G_CALLBACK (device_ipx_changed), self);
11090 g_signal_connect (platform, NM_PLATFORM_SIGNAL_IP6_ROUTE_CHANGED, G_CALLBACK (device_ipx_changed), self);
11091 g_signal_connect (platform, NM_PLATFORM_SIGNAL_LINK_CHANGED, G_CALLBACK (link_changed_cb), self);
11093 priv->con_provider = nm_connection_provider_get ();
11094 g_assert (priv->con_provider);
11095 g_signal_connect (priv->con_provider,
11096 NM_CP_SIGNAL_CONNECTION_ADDED,
11097 G_CALLBACK (cp_connection_added_or_updated),
11100 g_signal_connect (priv->con_provider,
11101 NM_CP_SIGNAL_CONNECTION_REMOVED,
11102 G_CALLBACK (cp_connection_removed),
11105 g_signal_connect (priv->con_provider,
11106 NM_CP_SIGNAL_CONNECTION_UPDATED,
11107 G_CALLBACK (cp_connection_added_or_updated),
11110 G_OBJECT_CLASS (nm_device_parent_class)->constructed (object);
11112 _LOGD (LOGD_DEVICE, "constructed (%s)", G_OBJECT_TYPE_NAME (self));
11116 dispose (GObject *object)
11118 NMDevice *self = NM_DEVICE (object);
11119 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
11120 NMPlatform *platform;
11122 _LOGD (LOGD_DEVICE, "disposing");
11124 g_slist_free_full (priv->arping.dad_list, (GDestroyNotify) nm_arping_manager_destroy);
11125 priv->arping.dad_list = NULL;
11127 arp_cleanup (self);
11129 g_signal_handlers_disconnect_by_func (nm_config_get (), config_changed_update_ignore_carrier, self);
11131 dispatcher_cleanup (self);
11133 _cleanup_generic_pre (self, CLEANUP_TYPE_KEEP);
11135 g_warn_if_fail (priv->slaves == NULL);
11136 g_assert (priv->master_ready_id == 0);
11138 /* Let the kernel manage IPv6LL again */
11139 set_nm_ipv6ll (self, FALSE);
11141 _cleanup_generic_post (self, CLEANUP_TYPE_KEEP);
11143 g_hash_table_remove_all (priv->ip6_saved_properties);
11145 nm_clear_g_source (&priv->recheck_assume_id);
11146 nm_clear_g_source (&priv->recheck_available.call_id);
11148 nm_clear_g_source (&priv->check_delete_unrealized_id);
11150 link_disconnect_action_cancel (self);
11152 if (priv->con_provider) {
11153 g_signal_handlers_disconnect_by_func (priv->con_provider, cp_connection_added_or_updated, self);
11154 g_signal_handlers_disconnect_by_func (priv->con_provider, cp_connection_removed, self);
11155 priv->con_provider = NULL;
11158 available_connections_del_all (self);
11160 nm_clear_g_source (&priv->carrier_wait_id);
11162 _clear_queued_act_request (priv);
11164 platform = nm_platform_get ();
11165 g_signal_handlers_disconnect_by_func (platform, G_CALLBACK (device_ipx_changed), self);
11166 g_signal_handlers_disconnect_by_func (platform, G_CALLBACK (link_changed_cb), self);
11168 nm_clear_g_source (&priv->device_link_changed_id);
11169 nm_clear_g_source (&priv->device_ip_link_changed_id);
11171 if (priv->lldp_listener) {
11172 g_signal_handlers_disconnect_by_func (priv->lldp_listener,
11173 G_CALLBACK (lldp_neighbors_changed),
11175 nm_lldp_listener_stop (priv->lldp_listener);
11176 g_clear_object (&priv->lldp_listener);
11179 G_OBJECT_CLASS (nm_device_parent_class)->dispose (object);
11181 if (nm_clear_g_source (&priv->queued_state.id)) {
11182 /* FIXME: we'd expect the queud_state to be alredy cleared and this statement
11183 * not being necessary. Add this check here to hopefully investigate crash
11185 g_return_if_reached ();
11190 finalize (GObject *object)
11192 NMDevice *self = NM_DEVICE (object);
11193 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
11195 _LOGD (LOGD_DEVICE, "finalize(): %s", G_OBJECT_TYPE_NAME (self));
11197 g_free (priv->hw_addr);
11198 g_free (priv->perm_hw_addr);
11199 g_free (priv->initial_hw_addr);
11200 g_slist_free_full (priv->pending_actions, g_free);
11201 g_slist_free_full (priv->dad6_failed_addrs, g_free);
11202 g_clear_pointer (&priv->physical_port_id, g_free);
11203 g_free (priv->udi);
11204 g_free (priv->iface);
11205 g_free (priv->ip_iface);
11206 g_free (priv->driver);
11207 g_free (priv->driver_version);
11208 g_free (priv->firmware_version);
11209 g_free (priv->type_desc);
11210 g_free (priv->type_description);
11211 g_free (priv->dhcp_anycast_address);
11213 g_hash_table_unref (priv->ip6_saved_properties);
11214 g_hash_table_unref (priv->available_connections);
11216 G_OBJECT_CLASS (nm_device_parent_class)->finalize (object);
11220 set_property (GObject *object, guint prop_id,
11221 const GValue *value, GParamSpec *pspec)
11223 NMDevice *self = NM_DEVICE (object);
11224 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
11225 const char *hw_addr, *p;
11230 if (g_value_get_string (value)) {
11231 g_free (priv->udi);
11232 priv->udi = g_value_dup_string (value);
11236 /* construct only */
11237 g_return_if_fail (!priv->iface);
11238 priv->iface = g_value_dup_string (value);
11241 if (g_value_get_string (value)) {
11242 g_free (priv->driver);
11243 priv->driver = g_value_dup_string (value);
11246 case PROP_DRIVER_VERSION:
11247 g_free (priv->driver_version);
11248 priv->driver_version = g_strdup (g_value_get_string (value));
11250 case PROP_FIRMWARE_VERSION:
11251 g_free (priv->firmware_version);
11252 priv->firmware_version = g_strdup (g_value_get_string (value));
11255 priv->mtu = g_value_get_uint (value);
11257 case PROP_IP4_ADDRESS:
11258 priv->ip4_address = g_value_get_uint (value);
11260 case PROP_MANAGED: {
11262 NMDeviceStateReason reason;
11264 managed = g_value_get_boolean (value);
11266 reason = NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED;
11268 reason = NM_DEVICE_STATE_REASON_REMOVED;
11269 nm_device_set_unmanaged_by_flags (self,
11270 NM_UNMANAGED_USER_EXPLICIT,
11275 case PROP_AUTOCONNECT:
11276 nm_device_set_autoconnect (self, g_value_get_boolean (value));
11278 case PROP_FIRMWARE_MISSING:
11279 /* construct only */
11280 priv->firmware_missing = g_value_get_boolean (value);
11282 case PROP_NM_PLUGIN_MISSING:
11283 priv->nm_plugin_missing = g_value_get_boolean (value);
11285 case PROP_DEVICE_TYPE:
11286 g_return_if_fail (priv->type == NM_DEVICE_TYPE_UNKNOWN);
11287 priv->type = g_value_get_uint (value);
11289 case PROP_LINK_TYPE:
11290 /* construct only */
11291 g_return_if_fail (priv->link_type == NM_LINK_TYPE_NONE);
11292 priv->link_type = g_value_get_uint (value);
11294 case PROP_TYPE_DESC:
11295 g_free (priv->type_desc);
11296 priv->type_desc = g_value_dup_string (value);
11298 case PROP_RFKILL_TYPE:
11299 priv->rfkill_type = g_value_get_uint (value);
11301 case PROP_IS_MASTER:
11302 priv->is_master = g_value_get_boolean (value);
11304 case PROP_HW_ADDRESS:
11305 /* construct only */
11306 p = hw_addr = g_value_get_string (value);
11308 /* Hardware address length is the number of ':' plus 1 */
11314 if (count < ETH_ALEN || count > NM_UTILS_HWADDR_LEN_MAX) {
11315 if (hw_addr && *hw_addr) {
11316 _LOGW (LOGD_DEVICE, "ignoring hardware address '%s' with unexpected length %d",
11322 priv->hw_addr_len = count;
11323 g_free (priv->hw_addr);
11324 if (nm_utils_hwaddr_valid (hw_addr, priv->hw_addr_len))
11325 priv->hw_addr = g_strdup (hw_addr);
11327 _LOGW (LOGD_DEVICE, "could not parse hw-address '%s'", hw_addr);
11328 priv->hw_addr = NULL;
11332 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
11338 get_property (GObject *object, guint prop_id,
11339 GValue *value, GParamSpec *pspec)
11341 NMDevice *self = NM_DEVICE (object);
11342 NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE (self);
11344 GHashTableIter iter;
11345 NMConnection *connection;
11346 GVariantBuilder array_builder;
11350 g_value_set_string (value, priv->udi);
11353 g_value_set_string (value, priv->iface);
11355 case PROP_IP_IFACE:
11356 if (ip_config_valid (priv->state))
11357 g_value_set_string (value, nm_device_get_ip_iface (self));
11359 g_value_set_string (value, NULL);
11362 g_value_set_int (value, priv->ifindex);
11365 g_value_set_string (value, priv->driver);
11367 case PROP_DRIVER_VERSION:
11368 g_value_set_string (value, priv->driver_version);
11370 case PROP_FIRMWARE_VERSION:
11371 g_value_set_string (value, priv->firmware_version);
11373 case PROP_CAPABILITIES:
11374 g_value_set_uint (value, (priv->capabilities & ~NM_DEVICE_CAP_INTERNAL_MASK));
11376 case PROP_IP4_ADDRESS:
11377 g_value_set_uint (value, priv->ip4_address);
11380 g_value_set_boolean (value, priv->carrier);
11383 g_value_set_uint (value, priv->mtu);
11385 case PROP_IP4_CONFIG:
11386 nm_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->ip4_config : NULL);
11388 case PROP_DHCP4_CONFIG:
11389 nm_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->dhcp4_config : NULL);
11391 case PROP_IP6_CONFIG:
11392 nm_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->ip6_config : NULL);
11394 case PROP_DHCP6_CONFIG:
11395 nm_utils_g_value_set_object_path (value, ip_config_valid (priv->state) ? priv->dhcp6_config : NULL);
11398 g_value_set_uint (value, priv->state);
11400 case PROP_STATE_REASON:
11401 g_value_take_variant (value,
11402 g_variant_new ("(uu)", priv->state, priv->state_reason));
11404 case PROP_ACTIVE_CONNECTION:
11405 nm_utils_g_value_set_object_path (value, priv->act_request);
11407 case PROP_DEVICE_TYPE:
11408 g_value_set_uint (value, priv->type);
11410 case PROP_LINK_TYPE:
11411 g_value_set_uint (value, priv->link_type);
11414 /* The managed state exposed on D-Bus only depends on the current device state alone. */
11415 g_value_set_boolean (value, nm_device_get_state (self) > NM_DEVICE_STATE_UNMANAGED);
11417 case PROP_AUTOCONNECT:
11418 g_value_set_boolean (value, priv->autoconnect);
11420 case PROP_FIRMWARE_MISSING:
11421 g_value_set_boolean (value, priv->firmware_missing);
11423 case PROP_NM_PLUGIN_MISSING:
11424 g_value_set_boolean (value, priv->nm_plugin_missing);
11426 case PROP_TYPE_DESC:
11427 g_value_set_string (value, priv->type_desc);
11429 case PROP_RFKILL_TYPE:
11430 g_value_set_uint (value, priv->rfkill_type);
11432 case PROP_AVAILABLE_CONNECTIONS:
11433 array = g_ptr_array_sized_new (g_hash_table_size (priv->available_connections));
11434 g_hash_table_iter_init (&iter, priv->available_connections);
11435 while (g_hash_table_iter_next (&iter, (gpointer) &connection, NULL))
11436 g_ptr_array_add (array, g_strdup (nm_connection_get_path (connection)));
11437 g_ptr_array_add (array, NULL);
11438 g_value_take_boxed (value, (char **) g_ptr_array_free (array, FALSE));
11440 case PROP_PHYSICAL_PORT_ID:
11441 g_value_set_string (value, priv->physical_port_id);
11443 case PROP_IS_MASTER:
11444 g_value_set_boolean (value, priv->is_master);
11447 g_value_set_object (value, nm_device_get_master (self));
11449 case PROP_HW_ADDRESS:
11450 g_value_set_string (value, priv->hw_addr);
11452 case PROP_HAS_PENDING_ACTION:
11453 g_value_set_boolean (value, nm_device_has_pending_action (self));
11456 g_value_set_uint (value, priv->metered);
11458 case PROP_LLDP_NEIGHBORS:
11459 if (priv->lldp_listener)
11460 g_value_set_variant (value, nm_lldp_listener_get_neighbors (priv->lldp_listener));
11462 g_variant_builder_init (&array_builder, G_VARIANT_TYPE ("aa{sv}"));
11463 g_value_take_variant (value, g_variant_builder_end (&array_builder));
11467 g_value_set_boolean (value, nm_device_is_real (self));
11469 case PROP_SLAVES: {
11470 GSList *slave_iter;
11474 slave_list = g_new (char *, g_slist_length (priv->slaves) + 1);
11475 for (slave_iter = priv->slaves, i = 0; slave_iter; slave_iter = slave_iter->next) {
11476 SlaveInfo *info = slave_iter->data;
11479 if (!NM_DEVICE_GET_PRIVATE (info->slave)->is_enslaved)
11481 path = nm_exported_object_get_path ((NMExportedObject *) info->slave);
11483 slave_list[i++] = g_strdup (path);
11485 slave_list[i] = NULL;
11486 g_value_take_boxed (value, slave_list);
11490 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
11496 nm_device_class_init (NMDeviceClass *klass)
11498 GObjectClass *object_class = G_OBJECT_CLASS (klass);
11499 NMExportedObjectClass *exported_object_class = NM_EXPORTED_OBJECT_CLASS (klass);
11501 g_type_class_add_private (object_class, sizeof (NMDevicePrivate));
11503 exported_object_class->export_path = NM_DBUS_PATH "/Devices/%u";
11505 /* Virtual methods */
11506 object_class->dispose = dispose;
11507 object_class->finalize = finalize;
11508 object_class->set_property = set_property;
11509 object_class->get_property = get_property;
11510 object_class->constructor = constructor;
11511 object_class->constructed = constructed;
11513 klass->link_changed = link_changed;
11515 klass->is_available = is_available;
11516 klass->act_stage1_prepare = act_stage1_prepare;
11517 klass->act_stage2_config = act_stage2_config;
11518 klass->act_stage3_ip4_config_start = act_stage3_ip4_config_start;
11519 klass->act_stage3_ip6_config_start = act_stage3_ip6_config_start;
11520 klass->act_stage4_ip4_config_timeout = act_stage4_ip4_config_timeout;
11521 klass->act_stage4_ip6_config_timeout = act_stage4_ip6_config_timeout;
11522 klass->have_any_ready_slaves = have_any_ready_slaves;
11524 klass->get_type_description = get_type_description;
11525 klass->spec_match_list = spec_match_list;
11526 klass->can_auto_connect = can_auto_connect;
11527 klass->check_connection_compatible = check_connection_compatible;
11528 klass->check_connection_available = check_connection_available;
11529 klass->can_unmanaged_external_down = can_unmanaged_external_down;
11530 klass->realize_start_notify = realize_start_notify;
11531 klass->unrealize_notify = unrealize_notify;
11532 klass->is_up = is_up;
11533 klass->bring_up = bring_up;
11534 klass->take_down = take_down;
11535 klass->carrier_changed = carrier_changed;
11536 klass->get_ip_iface_identifier = get_ip_iface_identifier;
11539 obj_properties[PROP_UDI] =
11540 g_param_spec_string (NM_DEVICE_UDI, "", "",
11542 G_PARAM_READWRITE | G_PARAM_CONSTRUCT |
11543 G_PARAM_STATIC_STRINGS);
11544 obj_properties[PROP_IFACE] =
11545 g_param_spec_string (NM_DEVICE_IFACE, "", "",
11547 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
11548 G_PARAM_STATIC_STRINGS);
11549 obj_properties[PROP_IP_IFACE] =
11550 g_param_spec_string (NM_DEVICE_IP_IFACE, "", "",
11553 G_PARAM_STATIC_STRINGS);
11554 obj_properties[PROP_DRIVER] =
11555 g_param_spec_string (NM_DEVICE_DRIVER, "", "",
11557 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
11558 G_PARAM_STATIC_STRINGS);
11559 obj_properties[PROP_DRIVER_VERSION] =
11560 g_param_spec_string (NM_DEVICE_DRIVER_VERSION, "", "",
11562 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
11563 G_PARAM_STATIC_STRINGS);
11564 obj_properties[PROP_FIRMWARE_VERSION] =
11565 g_param_spec_string (NM_DEVICE_FIRMWARE_VERSION, "", "",
11567 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
11568 G_PARAM_STATIC_STRINGS);
11569 obj_properties[PROP_CAPABILITIES] =
11570 g_param_spec_uint (NM_DEVICE_CAPABILITIES, "", "",
11571 0, G_MAXUINT32, NM_DEVICE_CAP_NONE,
11573 G_PARAM_STATIC_STRINGS);
11574 obj_properties[PROP_CARRIER] =
11575 g_param_spec_boolean (NM_DEVICE_CARRIER, "", "",
11578 G_PARAM_STATIC_STRINGS);
11579 obj_properties[PROP_MTU] =
11580 g_param_spec_uint (NM_DEVICE_MTU, "", "",
11581 0, G_MAXUINT32, 1500,
11583 G_PARAM_STATIC_STRINGS);
11584 obj_properties[PROP_IP4_ADDRESS] =
11585 g_param_spec_uint (NM_DEVICE_IP4_ADDRESS, "", "",
11586 0, G_MAXUINT32, 0, /* FIXME */
11587 G_PARAM_READWRITE |
11588 G_PARAM_STATIC_STRINGS);
11589 obj_properties[PROP_IP4_CONFIG] =
11590 g_param_spec_string (NM_DEVICE_IP4_CONFIG, "", "",
11592 G_PARAM_READWRITE |
11593 G_PARAM_STATIC_STRINGS);
11594 obj_properties[PROP_DHCP4_CONFIG] =
11595 g_param_spec_string (NM_DEVICE_DHCP4_CONFIG, "", "",
11597 G_PARAM_READWRITE |
11598 G_PARAM_STATIC_STRINGS);
11599 obj_properties[PROP_IP6_CONFIG] =
11600 g_param_spec_string (NM_DEVICE_IP6_CONFIG, "", "",
11602 G_PARAM_READWRITE |
11603 G_PARAM_STATIC_STRINGS);
11604 obj_properties[PROP_DHCP6_CONFIG] =
11605 g_param_spec_string (NM_DEVICE_DHCP6_CONFIG, "", "",
11607 G_PARAM_READWRITE |
11608 G_PARAM_STATIC_STRINGS);
11609 obj_properties[PROP_STATE] =
11610 g_param_spec_uint (NM_DEVICE_STATE, "", "",
11611 0, G_MAXUINT32, NM_DEVICE_STATE_UNKNOWN,
11613 G_PARAM_STATIC_STRINGS);
11614 obj_properties[PROP_STATE_REASON] =
11615 g_param_spec_variant (NM_DEVICE_STATE_REASON, "", "",
11616 G_VARIANT_TYPE ("(uu)"),
11619 G_PARAM_STATIC_STRINGS);
11620 obj_properties[PROP_ACTIVE_CONNECTION] =
11621 g_param_spec_string (NM_DEVICE_ACTIVE_CONNECTION, "", "",
11624 G_PARAM_STATIC_STRINGS);
11625 obj_properties[PROP_DEVICE_TYPE] =
11626 g_param_spec_uint (NM_DEVICE_DEVICE_TYPE, "", "",
11627 0, G_MAXUINT32, NM_DEVICE_TYPE_UNKNOWN,
11628 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
11629 G_PARAM_STATIC_STRINGS);
11630 obj_properties[PROP_LINK_TYPE] =
11631 g_param_spec_uint (NM_DEVICE_LINK_TYPE, "", "",
11632 0, G_MAXUINT32, NM_LINK_TYPE_NONE,
11633 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
11634 G_PARAM_STATIC_STRINGS);
11635 obj_properties[PROP_MANAGED] =
11636 g_param_spec_boolean (NM_DEVICE_MANAGED, "", "",
11638 G_PARAM_READWRITE |
11639 G_PARAM_STATIC_STRINGS);
11640 obj_properties[PROP_AUTOCONNECT] =
11641 g_param_spec_boolean (NM_DEVICE_AUTOCONNECT, "", "",
11642 DEFAULT_AUTOCONNECT,
11643 G_PARAM_READWRITE |
11644 G_PARAM_STATIC_STRINGS);
11645 obj_properties[PROP_FIRMWARE_MISSING] =
11646 g_param_spec_boolean (NM_DEVICE_FIRMWARE_MISSING, "", "",
11648 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
11649 G_PARAM_STATIC_STRINGS);
11650 obj_properties[PROP_NM_PLUGIN_MISSING] =
11651 g_param_spec_boolean (NM_DEVICE_NM_PLUGIN_MISSING, "", "",
11653 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
11654 G_PARAM_STATIC_STRINGS);
11655 obj_properties[PROP_TYPE_DESC] =
11656 g_param_spec_string (NM_DEVICE_TYPE_DESC, "", "",
11658 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
11659 G_PARAM_STATIC_STRINGS);
11660 obj_properties[PROP_RFKILL_TYPE] =
11661 g_param_spec_uint (NM_DEVICE_RFKILL_TYPE, "", "",
11664 RFKILL_TYPE_UNKNOWN,
11665 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
11666 G_PARAM_STATIC_STRINGS);
11667 obj_properties[PROP_IFINDEX] =
11668 g_param_spec_int (NM_DEVICE_IFINDEX, "", "",
11671 G_PARAM_STATIC_STRINGS);
11672 obj_properties[PROP_AVAILABLE_CONNECTIONS] =
11673 g_param_spec_boxed (NM_DEVICE_AVAILABLE_CONNECTIONS, "", "",
11676 G_PARAM_STATIC_STRINGS);
11677 obj_properties[PROP_PHYSICAL_PORT_ID] =
11678 g_param_spec_string (NM_DEVICE_PHYSICAL_PORT_ID, "", "",
11681 G_PARAM_STATIC_STRINGS);
11682 obj_properties[PROP_IS_MASTER] =
11683 g_param_spec_boolean (NM_DEVICE_IS_MASTER, "", "",
11685 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
11686 G_PARAM_STATIC_STRINGS);
11687 obj_properties[PROP_MASTER] =
11688 g_param_spec_object (NM_DEVICE_MASTER, "", "",
11691 G_PARAM_STATIC_STRINGS);
11692 obj_properties[PROP_HW_ADDRESS] =
11693 g_param_spec_string (NM_DEVICE_HW_ADDRESS, "", "",
11695 G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY |
11696 G_PARAM_STATIC_STRINGS);
11697 obj_properties[PROP_HAS_PENDING_ACTION] =
11698 g_param_spec_boolean (NM_DEVICE_HAS_PENDING_ACTION, "", "",
11701 G_PARAM_STATIC_STRINGS);
11704 * NMDevice:metered:
11706 * Whether the connection is metered.
11710 obj_properties[PROP_METERED] =
11711 g_param_spec_uint (NM_DEVICE_METERED, "", "",
11712 0, G_MAXUINT32, NM_METERED_UNKNOWN,
11714 G_PARAM_STATIC_STRINGS);
11715 obj_properties[PROP_LLDP_NEIGHBORS] =
11716 g_param_spec_variant (NM_DEVICE_LLDP_NEIGHBORS, "", "",
11717 G_VARIANT_TYPE ("aa{sv}"),
11720 G_PARAM_STATIC_STRINGS);
11721 obj_properties[PROP_REAL] =
11722 g_param_spec_boolean (NM_DEVICE_REAL, "", "",
11725 G_PARAM_STATIC_STRINGS);
11726 obj_properties[PROP_SLAVES] =
11727 g_param_spec_boxed (NM_DEVICE_SLAVES, "", "",
11730 G_PARAM_STATIC_STRINGS);
11732 g_object_class_install_properties (object_class, _PROPERTY_ENUMS_LAST, obj_properties);
11735 signals[STATE_CHANGED] =
11736 g_signal_new (NM_DEVICE_STATE_CHANGED,
11737 G_OBJECT_CLASS_TYPE (object_class),
11739 G_STRUCT_OFFSET (NMDeviceClass, state_changed),
11742 G_TYPE_UINT, G_TYPE_UINT, G_TYPE_UINT);
11744 signals[AUTOCONNECT_ALLOWED] =
11745 g_signal_new ("autoconnect-allowed",
11746 G_OBJECT_CLASS_TYPE (object_class),
11749 autoconnect_allowed_accumulator, NULL, NULL,
11750 G_TYPE_BOOLEAN, 0);
11752 signals[AUTH_REQUEST] =
11753 g_signal_new (NM_DEVICE_AUTH_REQUEST,
11754 G_OBJECT_CLASS_TYPE (object_class),
11755 G_SIGNAL_RUN_FIRST,
11756 0, NULL, NULL, NULL,
11757 /* context, connection, permission, allow_interaction, callback, user_data */
11758 G_TYPE_NONE, 6, G_TYPE_DBUS_METHOD_INVOCATION, NM_TYPE_CONNECTION, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_POINTER, G_TYPE_POINTER);
11760 signals[IP4_CONFIG_CHANGED] =
11761 g_signal_new (NM_DEVICE_IP4_CONFIG_CHANGED,
11762 G_OBJECT_CLASS_TYPE (object_class),
11763 G_SIGNAL_RUN_FIRST,
11764 0, NULL, NULL, NULL,
11765 G_TYPE_NONE, 2, G_TYPE_OBJECT, G_TYPE_OBJECT);
11767 signals[IP6_CONFIG_CHANGED] =
11768 g_signal_new (NM_DEVICE_IP6_CONFIG_CHANGED,
11769 G_OBJECT_CLASS_TYPE (object_class),
11770 G_SIGNAL_RUN_FIRST,
11771 0, NULL, NULL, NULL,
11772 G_TYPE_NONE, 2, G_TYPE_OBJECT, G_TYPE_OBJECT);
11775 g_signal_new (NM_DEVICE_REMOVED,
11776 G_OBJECT_CLASS_TYPE (object_class),
11777 G_SIGNAL_RUN_FIRST,
11778 0, NULL, NULL, NULL,
11781 signals[RECHECK_AUTO_ACTIVATE] =
11782 g_signal_new (NM_DEVICE_RECHECK_AUTO_ACTIVATE,
11783 G_OBJECT_CLASS_TYPE (object_class),
11784 G_SIGNAL_RUN_FIRST,
11785 0, NULL, NULL, NULL,
11788 signals[RECHECK_ASSUME] =
11789 g_signal_new (NM_DEVICE_RECHECK_ASSUME,
11790 G_OBJECT_CLASS_TYPE (object_class),
11791 G_SIGNAL_RUN_FIRST,
11792 0, NULL, NULL, NULL,
11795 nm_exported_object_class_add_interface (NM_EXPORTED_OBJECT_CLASS (klass),
11796 NMDBUS_TYPE_DEVICE_SKELETON,
11797 "Reapply", impl_device_reapply,
11798 "GetAppliedConnection", impl_device_get_applied_connection,
11799 "Disconnect", impl_device_disconnect,
11800 "Delete", impl_device_delete,