2020-12-23 22:21:36 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2019-09-25 13:13:40 +02:00
|
|
|
/*
|
2013-02-05 17:29:15 +01:00
|
|
|
* Copyright (C) 2004 - 2013 Red Hat, Inc.
|
2008-11-03 04:13:42 +00:00
|
|
|
* Copyright (C) 2007 - 2008 Novell, Inc.
|
2004-06-24 14:18:37 +00:00
|
|
|
*/
|
|
|
|
|
|
2021-02-04 18:04:13 +01:00
|
|
|
#include "src/core/nm-default-daemon.h"
|
2014-11-13 10:07:02 -05:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
#include "nm-policy.h"
|
|
|
|
|
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
#include <netdb.h>
|
2004-06-24 14:18:37 +00:00
|
|
|
|
2021-08-06 15:17:05 +02:00
|
|
|
#include "libnm-core-intern/nm-core-internal.h"
|
|
|
|
|
#include "libnm-platform/nm-platform.h"
|
|
|
|
|
#include "libnm-platform/nmp-object.h"
|
|
|
|
|
|
2004-06-24 14:18:37 +00:00
|
|
|
#include "NetworkManagerUtils.h"
|
2016-11-21 00:43:52 +01:00
|
|
|
#include "devices/nm-device.h"
|
2024-07-29 14:42:05 -04:00
|
|
|
#include "devices/nm-device-factory.h"
|
2016-11-21 00:43:52 +01:00
|
|
|
#include "dns/nm-dns-manager.h"
|
2021-08-06 15:17:05 +02:00
|
|
|
#include "nm-act-request.h"
|
2014-08-16 01:33:46 +02:00
|
|
|
#include "nm-auth-utils.h"
|
2021-08-06 15:17:05 +02:00
|
|
|
#include "nm-config.h"
|
|
|
|
|
#include "nm-dhcp-config.h"
|
2012-06-03 19:32:16 -05:00
|
|
|
#include "nm-dispatcher.h"
|
2021-08-06 15:17:05 +02:00
|
|
|
#include "nm-firewalld-manager.h"
|
|
|
|
|
#include "nm-hostname-manager.h"
|
|
|
|
|
#include "nm-keep-alive.h"
|
|
|
|
|
#include "nm-l3-config-data.h"
|
2014-07-17 17:06:44 -04:00
|
|
|
#include "nm-manager.h"
|
2017-04-17 20:17:45 +02:00
|
|
|
#include "nm-netns.h"
|
2021-08-06 15:17:05 +02:00
|
|
|
#include "nm-setting-connection.h"
|
|
|
|
|
#include "nm-setting-ip4-config.h"
|
|
|
|
|
#include "nm-utils.h"
|
|
|
|
|
#include "settings/nm-agent-manager.h"
|
|
|
|
|
#include "settings/nm-settings-connection.h"
|
|
|
|
|
#include "settings/nm-settings.h"
|
|
|
|
|
#include "vpn/nm-vpn-manager.h"
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
2016-03-03 09:20:18 +01:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
NM_GOBJECT_PROPERTIES_DEFINE(NMPolicy,
|
|
|
|
|
PROP_MANAGER,
|
|
|
|
|
PROP_SETTINGS,
|
2018-06-28 18:05:05 +02:00
|
|
|
PROP_DEFAULT_IP4_AC,
|
|
|
|
|
PROP_DEFAULT_IP6_AC,
|
|
|
|
|
PROP_ACTIVATING_IP4_AC,
|
|
|
|
|
PROP_ACTIVATING_IP6_AC, );
|
2016-04-04 13:58:44 +02:00
|
|
|
|
2024-07-31 17:08:43 +02:00
|
|
|
#define HOSTNAME_RETRY_INTERVAL_MIN 30U
|
|
|
|
|
#define HOSTNAME_RETRY_INTERVAL_MAX (60U * 60 * 12) /* 12 hours */
|
|
|
|
|
#define HOSTNAME_RETRY_INTERVAL_MULTIPLIER 8U
|
|
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
typedef struct {
|
2021-11-09 13:28:54 +01:00
|
|
|
NMManager *manager;
|
|
|
|
|
NMNetns *netns;
|
2021-05-04 16:01:13 +02:00
|
|
|
NMFirewalldManager *firewalld_manager;
|
2023-04-05 11:55:28 +02:00
|
|
|
CList policy_auto_activate_lst_head;
|
2016-04-04 13:44:30 +02:00
|
|
|
|
2017-11-27 09:07:28 +01:00
|
|
|
NMAgentManager *agent_mgr;
|
|
|
|
|
|
2016-04-04 13:44:30 +02:00
|
|
|
GHashTable *devices;
|
2017-09-25 22:20:47 +02:00
|
|
|
GHashTable *pending_active_connections;
|
2008-03-07 Dan Williams <dcbw@redhat.com>
First pass of multiple active device support. Expect bugs.
* src/nm-ip4-config.c
src/nm-ip4-config.h
- (nm_ip4_config_get_secondary, nm_ip4_config_set_secondary): remove;
there are better ways to do this in the named manager
* src/nm-device.c
src/nm-device.h
- (nm_device_can_activate): return whether the device can activate a
connection right now; taking into account things like carrier state
and rfkill state
- (nm_device_get_best_auto_connection): renamed from
nm_device_get_best_connection
- (real_act_stage4_get_ip4_config): MTU stuff is now handled in the
device subclasses themselves, so that each device can override the
MTU from it's NMSetting subclass if needed
- (nm_device_set_ip4_config): set MTU when setting up routes and stuff
in NetworkManagerSystem.c, not here
* src/named-manager/nm-named-manager.c
src/named-manager/nm-named-manager.h
- (nm_named_manager_name_owner_changed,
nm_named_manager_dbus_connection_changed): fix for changes to
rewrite_resolv_conf()
- (compute_nameservers): don't need the NMNamedManager at all, remove
from parameter list
- (merge_one_ip4_config): new function; merge ip4 configs together
- (rewrite_resolv_conf): write out resolv.conf from all the stored
ip4 configs; the VPN config takes precedence, then the best
device config, then the rest of the configs
- (get_domain_for_config): take the NMNamedManager as an argument
to check whether the config is the VPN config
- (add_ip4_config_to_named): fixups for removal of the 'secondary'
attribute from ip4 configs
- (add_all_ip4_configs_to_named): add all the configs in priority order
- (remove_ip4_config_from_named): fix for changes to
get_domain_for_config()
- (nm_named_manager_add_ip4_config): assign the config to the right slot
based on its type; callers must pass in the type now
- (get_last_default_domain): remove, unused
- (nm_named_manager_remove_ip4_config): handle config slots correctly
* src/nm-device-802-11-wireless.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): handle MTU override
* src/nm-device-802-3-ethernet.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): new function; handle MTU override
* src/vpn-manager/nm-vpn-connection.c
- (nm_vpn_connection_ip4_config_get): don't need to set the 'secondary'
attribute on the ip4 config
* src/NetworkManagerPolicy.c
- (nm_policy_auto_get_best_device): remove
- (nm_policy_device_change_check): remove
- (update_default_route): new function; set the default route via
the specified device
- (get_device_priority): new function; return the priority number of
a device type WRT which one should have the default route. Order is
(highest to lowest) wired, wireless, GSM, CDMA.
- (update_routing_and_dns): new function; determine which device should
have the default route, then update the routing table and DNS
- (maybe_auto_activate_device): new function; if a device is now
available for activation, find out what connection it would like to
activate and do it
- (schedule_activate_check): new function; if a device can be activated
now, schedule the activation. Each device may have only one
pending activation at a given time.
- (device_state_changed): if activation was canceled, try again,
possibly with another connection; if the device was activated,
update routing and DNS; if the device was deactivated, try again
with another connection
- (device_carrier_changed): if there is no carrier, deactivate the
device; otherwise schedule an activation check for the device
- (wireless_networks_changed): schedule an activation check for the
device
- (device_added): keep track of the signal handler IDs so they can
be removed when the device goes away
- (device_removed): remove any signal handlers that might be attached
to the device; update routing and DNS
- (schedule_activate_all): new function
- (connections_added, connection_added, connection_updated): when
connections change, schedule all devices for an activation check
- (connection_removed): when a device is deactivated because its
connection was removed, schedule another activation check for it
- (nm_policy_destroy): destroy pending activations and disconnect
all device signal handlers
* src/nm-manager.c
- (nm_manager_activate_device): if the device was already actived,
deactivate it
- (deactivate_old_device): remove
- (connection_added_default_handler, impl_manager_activate_device):
don't deactivate other devices when activating this one
* src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerSuSE.c
src/backends/NetworkManagerDebian.c
- (nm_system_get_mtu): remove; MTU should be provided through the
distro's system settings service plugin instead
- (nm_system_device_add_default_route_via_device): remove
- (nm_system_device_add_default_route_via_device_with_iface): remove
- (nm_system_device_replace_default_route): new function; call
generic implementation
* src/backends/NetworkManagerGeneric.c
src/backends/NetworkManagerGeneric.h
- (nm_generic_device_add_default_route_via_device,
nm_generic_device_add_default_route_via_device_with_iface): remove
- (nm_generic_device_replace_default_route): replace the default route
with the given route via some gateway
* src/NetworkManagerSystem.c
src/NetworkManagerSystem.h
- (nm_system_device_set_from_ip4_config): let the policy handle updates
to routing and DNS; but set the MTU here
- (nm_system_vpn_device_set_from_ip4_config): set the route with the
ip_iface of the active device; use the standard MTU setting function
- (nm_system_set_mtu): remove
- (nm_system_device_set_mtu): consolidate MTU setting code in one place
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3391 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-07 19:41:32 +00:00
|
|
|
|
2012-08-21 17:49:41 +02:00
|
|
|
GSList *pending_secondaries;
|
|
|
|
|
|
2010-10-27 20:05:23 -05:00
|
|
|
NMSettings *settings;
|
2010-10-27 15:47:10 -05:00
|
|
|
|
2023-04-07 12:55:57 +02:00
|
|
|
GSource *device_recheck_auto_activate_all_idle_source;
|
|
|
|
|
|
2023-04-07 13:08:14 +02:00
|
|
|
GSource *reset_connections_retries_idle_source;
|
|
|
|
|
|
2017-04-23 00:40:46 +02:00
|
|
|
NMHostnameManager *hostname_manager;
|
|
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
NMActiveConnection *default_ac4, *activating_ac4;
|
|
|
|
|
NMActiveConnection *default_ac6, *activating_ac6;
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
|
2013-02-05 17:29:15 +01:00
|
|
|
NMDnsManager *dns_manager;
|
2020-12-17 14:13:45 +01:00
|
|
|
gulong config_changed_id;
|
2010-01-27 17:13:35 -08:00
|
|
|
|
2017-03-02 19:18:49 +01:00
|
|
|
NMPolicyHostnameMode hostname_mode;
|
2022-03-04 08:10:17 +01:00
|
|
|
char *orig_hostname; /* hostname at NM start time */
|
|
|
|
|
char *cur_hostname; /* hostname we want to assign */
|
|
|
|
|
char *cur_hostname_full; /* similar to @last_hostname, but before shortening */
|
2024-07-31 17:08:43 +02:00
|
|
|
char *last_hostname; /* last hostname NM set (to detect if someone else
|
|
|
|
|
* changed it in the meanwhile) */
|
|
|
|
|
struct {
|
|
|
|
|
GSource *source;
|
|
|
|
|
guint interval_sec;
|
|
|
|
|
gboolean do_restart; /* when something changes, set this to TRUE so that the next retry
|
|
|
|
|
* will restart from the lowest timeout. */
|
|
|
|
|
} hostname_retry;
|
2020-12-17 14:13:45 +01:00
|
|
|
|
|
|
|
|
bool changing_hostname : 1; /* hostname set operation in progress */
|
|
|
|
|
bool dhcp_hostname : 1; /* current hostname was set from dhcp */
|
|
|
|
|
bool updating_dns : 1;
|
2016-10-31 23:31:14 +01:00
|
|
|
|
|
|
|
|
GArray *ip6_prefix_delegations; /* pool of ip6 prefixes delegated to all devices */
|
2025-04-30 12:21:23 +02:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
} NMPolicyPrivate;
|
|
|
|
|
|
|
|
|
|
struct _NMPolicy {
|
|
|
|
|
GObject parent;
|
|
|
|
|
NMPolicyPrivate _priv;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct _NMPolicyClass {
|
|
|
|
|
GObjectClass parent;
|
2016-04-04 13:58:44 +02:00
|
|
|
};
|
2013-08-22 10:10:17 -04:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
G_DEFINE_TYPE(NMPolicy, nm_policy, G_TYPE_OBJECT)
|
|
|
|
|
|
|
|
|
|
#define NM_POLICY_GET_PRIVATE(self) _NM_GET_PRIVATE(self, NMPolicy, NM_IS_POLICY)
|
|
|
|
|
|
|
|
|
|
static NMPolicy *
|
|
|
|
|
_PRIV_TO_SELF(NMPolicyPrivate *priv)
|
2016-04-04 13:58:44 +02:00
|
|
|
{
|
2016-09-29 13:49:01 +02:00
|
|
|
NMPolicy *self;
|
|
|
|
|
|
|
|
|
|
nm_assert(priv);
|
|
|
|
|
|
2022-12-01 14:07:22 +01:00
|
|
|
self = NM_CAST_ALIGN(NMPolicy, (((char *) priv) - G_STRUCT_OFFSET(NMPolicy, _priv)));
|
2016-09-29 13:49:01 +02:00
|
|
|
|
2016-04-04 13:58:44 +02:00
|
|
|
nm_assert(NM_IS_POLICY(self));
|
2022-12-01 14:07:22 +01:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
return self;
|
2016-04-04 13:58:44 +02:00
|
|
|
}
|
2013-08-22 10:10:17 -04:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
2007-02-08 15:34:26 +00:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
#define _NMLOG_PREFIX_NAME "policy"
|
2020-11-12 08:47:25 +01:00
|
|
|
#undef _NMLOG_ENABLED
|
|
|
|
|
#define _NMLOG_ENABLED(level, domain) (nm_logging_enabled((level), (domain)))
|
2016-09-29 13:49:01 +02:00
|
|
|
#define _NMLOG(level, domain, ...) \
|
|
|
|
|
G_STMT_START \
|
|
|
|
|
{ \
|
2017-03-01 10:20:01 +00:00
|
|
|
nm_log((level), \
|
|
|
|
|
(domain), \
|
|
|
|
|
NULL, \
|
|
|
|
|
NULL, \
|
2016-09-29 13:49:01 +02:00
|
|
|
"%s" _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
|
|
|
|
|
_NMLOG_PREFIX_NAME ": " _NM_UTILS_MACRO_REST(__VA_ARGS__)); \
|
|
|
|
|
} \
|
|
|
|
|
G_STMT_END
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-08-22 13:06:51 -04:00
|
|
|
|
2024-07-31 17:08:43 +02:00
|
|
|
static void update_system_hostname(NMPolicy *self, const char *msg, gboolean reset_retry_interval);
|
|
|
|
|
static void nm_policy_device_recheck_auto_activate_all_schedule(NMPolicy *self);
|
2018-06-28 18:05:05 +02:00
|
|
|
static NMDevice *get_default_device(NMPolicy *self, int addr_family);
|
2024-07-31 17:08:43 +02:00
|
|
|
static gboolean hostname_retry_cb(gpointer user_data);
|
2011-12-06 16:33:00 -06:00
|
|
|
|
2016-09-29 13:49:01 +02:00
|
|
|
/*****************************************************************************/
|
2011-12-06 16:33:00 -06:00
|
|
|
|
2016-10-31 23:31:14 +01:00
|
|
|
typedef struct {
|
|
|
|
|
NMPlatformIP6Address prefix;
|
2025-03-10 16:39:58 +01:00
|
|
|
NMDevice *device; /* The requesting ("uplink") device */
|
|
|
|
|
GHashTable *map_subnet_id_to_ifindex; /* (guint64 *) subnet_id -> int ifindex */
|
|
|
|
|
GHashTable *map_ifindex_to_subnet; /* int ifindex -> (NMPlatformIP6Address *) prefix */
|
2016-10-31 23:31:14 +01:00
|
|
|
} IP6PrefixDelegation;
|
|
|
|
|
|
|
|
|
|
static void
|
2025-03-10 16:39:58 +01:00
|
|
|
clear_ip6_subnet(int ifindex, NMPlatformIP6Address *subnet)
|
2016-10-31 23:31:14 +01:00
|
|
|
{
|
2025-03-10 16:39:58 +01:00
|
|
|
NMDevice *device = nm_manager_get_device_by_ifindex(NM_MANAGER_GET, ifindex);
|
2016-10-31 23:31:14 +01:00
|
|
|
|
2016-11-09 18:06:53 +01:00
|
|
|
if (device) {
|
|
|
|
|
/* We can not remove a subnet we already started announcing.
|
|
|
|
|
* Just un-prefer it. */
|
|
|
|
|
subnet->preferred = 0;
|
|
|
|
|
nm_device_use_ip6_subnet(device, subnet);
|
|
|
|
|
}
|
2016-10-31 23:31:14 +01:00
|
|
|
g_slice_free(NMPlatformIP6Address, subnet);
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-10 16:39:58 +01:00
|
|
|
static void
|
|
|
|
|
clear_ip6_subnet_entry(gpointer key, gpointer value, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
clear_ip6_subnet(GPOINTER_TO_INT(key), value);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 23:31:14 +01:00
|
|
|
static void
|
|
|
|
|
clear_ip6_prefix_delegation(gpointer data)
|
|
|
|
|
{
|
|
|
|
|
IP6PrefixDelegation *delegation = data;
|
glib-aux: rename IP address related helpers from "nm-inet-utils.h"
- name things related to `in_addr_t`, `struct in6_addr`, `NMIPAddr` as
`nm_ip4_addr_*()`, `nm_ip6_addr_*()`, `nm_ip_addr_*()`, respectively.
- we have a wrapper `nm_inet_ntop()` for `inet_ntop()`. This name
of our wrapper is chosen to be familiar with the libc underlying
function. With this, also name functions that are about string
representations of addresses `nm_inet_*()`, `nm_inet4_*()`,
`nm_inet6_*()`. For example, `nm_inet_parse_str()`,
`nm_inet_is_normalized()`.
<<<<
R() {
git grep -l "$1" | xargs sed -i "s/\<$1\>/$2/g"
}
R NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX
R NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX
R NM_UTILS_INET_ADDRSTRLEN NM_INET_ADDRSTRLEN
R _nm_utils_inet4_ntop nm_inet4_ntop
R _nm_utils_inet6_ntop nm_inet6_ntop
R _nm_utils_ip4_get_default_prefix nm_ip4_addr_get_default_prefix
R _nm_utils_ip4_get_default_prefix0 nm_ip4_addr_get_default_prefix0
R _nm_utils_ip4_netmask_to_prefix nm_ip4_addr_netmask_to_prefix
R _nm_utils_ip4_prefix_to_netmask nm_ip4_addr_netmask_from_prefix
R nm_utils_inet4_ntop_dup nm_inet4_ntop_dup
R nm_utils_inet6_ntop_dup nm_inet6_ntop_dup
R nm_utils_inet_ntop nm_inet_ntop
R nm_utils_inet_ntop_dup nm_inet_ntop_dup
R nm_utils_ip4_address_clear_host_address nm_ip4_addr_clear_host_address
R nm_utils_ip4_address_is_link_local nm_ip4_addr_is_link_local
R nm_utils_ip4_address_is_loopback nm_ip4_addr_is_loopback
R nm_utils_ip4_address_is_zeronet nm_ip4_addr_is_zeronet
R nm_utils_ip4_address_same_prefix nm_ip4_addr_same_prefix
R nm_utils_ip4_address_same_prefix_cmp nm_ip4_addr_same_prefix_cmp
R nm_utils_ip6_address_clear_host_address nm_ip6_addr_clear_host_address
R nm_utils_ip6_address_same_prefix nm_ip6_addr_same_prefix
R nm_utils_ip6_address_same_prefix_cmp nm_ip6_addr_same_prefix_cmp
R nm_utils_ip6_is_ula nm_ip6_addr_is_ula
R nm_utils_ip_address_same_prefix nm_ip_addr_same_prefix
R nm_utils_ip_address_same_prefix_cmp nm_ip_addr_same_prefix_cmp
R nm_utils_ip_is_site_local nm_ip_addr_is_site_local
R nm_utils_ipaddr_is_normalized nm_inet_is_normalized
R nm_utils_ipaddr_is_valid nm_inet_is_valid
R nm_utils_ipx_address_clear_host_address nm_ip_addr_clear_host_address
R nm_utils_parse_inaddr nm_inet_parse_str
R nm_utils_parse_inaddr_bin nm_inet_parse_bin
R nm_utils_parse_inaddr_bin_full nm_inet_parse_bin_full
R nm_utils_parse_inaddr_prefix nm_inet_parse_with_prefix_str
R nm_utils_parse_inaddr_prefix_bin nm_inet_parse_with_prefix_bin
R test_nm_utils_ip6_address_same_prefix test_nm_ip_addr_same_prefix
./contrib/scripts/nm-code-format.sh -F
2022-08-19 13:15:20 +02:00
|
|
|
char sbuf[NM_INET_ADDRSTRLEN];
|
2016-10-31 23:31:14 +01:00
|
|
|
|
|
|
|
|
_LOGD(LOGD_IP6,
|
|
|
|
|
"ipv6-pd: undelegating prefix %s/%d",
|
glib-aux: rename IP address related helpers from "nm-inet-utils.h"
- name things related to `in_addr_t`, `struct in6_addr`, `NMIPAddr` as
`nm_ip4_addr_*()`, `nm_ip6_addr_*()`, `nm_ip_addr_*()`, respectively.
- we have a wrapper `nm_inet_ntop()` for `inet_ntop()`. This name
of our wrapper is chosen to be familiar with the libc underlying
function. With this, also name functions that are about string
representations of addresses `nm_inet_*()`, `nm_inet4_*()`,
`nm_inet6_*()`. For example, `nm_inet_parse_str()`,
`nm_inet_is_normalized()`.
<<<<
R() {
git grep -l "$1" | xargs sed -i "s/\<$1\>/$2/g"
}
R NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX
R NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX
R NM_UTILS_INET_ADDRSTRLEN NM_INET_ADDRSTRLEN
R _nm_utils_inet4_ntop nm_inet4_ntop
R _nm_utils_inet6_ntop nm_inet6_ntop
R _nm_utils_ip4_get_default_prefix nm_ip4_addr_get_default_prefix
R _nm_utils_ip4_get_default_prefix0 nm_ip4_addr_get_default_prefix0
R _nm_utils_ip4_netmask_to_prefix nm_ip4_addr_netmask_to_prefix
R _nm_utils_ip4_prefix_to_netmask nm_ip4_addr_netmask_from_prefix
R nm_utils_inet4_ntop_dup nm_inet4_ntop_dup
R nm_utils_inet6_ntop_dup nm_inet6_ntop_dup
R nm_utils_inet_ntop nm_inet_ntop
R nm_utils_inet_ntop_dup nm_inet_ntop_dup
R nm_utils_ip4_address_clear_host_address nm_ip4_addr_clear_host_address
R nm_utils_ip4_address_is_link_local nm_ip4_addr_is_link_local
R nm_utils_ip4_address_is_loopback nm_ip4_addr_is_loopback
R nm_utils_ip4_address_is_zeronet nm_ip4_addr_is_zeronet
R nm_utils_ip4_address_same_prefix nm_ip4_addr_same_prefix
R nm_utils_ip4_address_same_prefix_cmp nm_ip4_addr_same_prefix_cmp
R nm_utils_ip6_address_clear_host_address nm_ip6_addr_clear_host_address
R nm_utils_ip6_address_same_prefix nm_ip6_addr_same_prefix
R nm_utils_ip6_address_same_prefix_cmp nm_ip6_addr_same_prefix_cmp
R nm_utils_ip6_is_ula nm_ip6_addr_is_ula
R nm_utils_ip_address_same_prefix nm_ip_addr_same_prefix
R nm_utils_ip_address_same_prefix_cmp nm_ip_addr_same_prefix_cmp
R nm_utils_ip_is_site_local nm_ip_addr_is_site_local
R nm_utils_ipaddr_is_normalized nm_inet_is_normalized
R nm_utils_ipaddr_is_valid nm_inet_is_valid
R nm_utils_ipx_address_clear_host_address nm_ip_addr_clear_host_address
R nm_utils_parse_inaddr nm_inet_parse_str
R nm_utils_parse_inaddr_bin nm_inet_parse_bin
R nm_utils_parse_inaddr_bin_full nm_inet_parse_bin_full
R nm_utils_parse_inaddr_prefix nm_inet_parse_with_prefix_str
R nm_utils_parse_inaddr_prefix_bin nm_inet_parse_with_prefix_bin
R test_nm_utils_ip6_address_same_prefix test_nm_ip_addr_same_prefix
./contrib/scripts/nm-code-format.sh -F
2022-08-19 13:15:20 +02:00
|
|
|
nm_inet6_ntop(&delegation->prefix.address, sbuf),
|
2016-10-31 23:31:14 +01:00
|
|
|
delegation->prefix.plen);
|
|
|
|
|
|
2025-03-10 16:39:58 +01:00
|
|
|
g_hash_table_foreach(delegation->map_ifindex_to_subnet, clear_ip6_subnet_entry, NULL);
|
|
|
|
|
g_hash_table_destroy(delegation->map_ifindex_to_subnet);
|
|
|
|
|
g_hash_table_destroy(delegation->map_subnet_id_to_ifindex);
|
2016-10-31 23:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
expire_ip6_delegations(NMPolicy *self)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2019-12-13 16:54:30 +01:00
|
|
|
guint32 now = nm_utils_get_monotonic_timestamp_sec();
|
2016-11-09 17:58:11 +01:00
|
|
|
IP6PrefixDelegation *delegation = NULL;
|
|
|
|
|
guint i;
|
2016-10-31 23:31:14 +01:00
|
|
|
|
|
|
|
|
for (i = 0; i < priv->ip6_prefix_delegations->len; i++) {
|
2022-09-08 12:05:56 +02:00
|
|
|
delegation = &nm_g_array_index(priv->ip6_prefix_delegations, IP6PrefixDelegation, i);
|
2016-10-31 23:31:14 +01:00
|
|
|
if (delegation->prefix.timestamp + delegation->prefix.lifetime < now)
|
|
|
|
|
g_array_remove_index_fast(priv->ip6_prefix_delegations, i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Try to obtain a new subnet for a particular active connection from given
|
|
|
|
|
* delegated prefix, possibly reusing the existing subnet.
|
|
|
|
|
* Return value of FALSE indicates no more subnets are available from
|
|
|
|
|
* this prefix (and other prefix should be used -- and requested if necessary).
|
|
|
|
|
*/
|
|
|
|
|
static gboolean
|
|
|
|
|
ip6_subnet_from_delegation(IP6PrefixDelegation *delegation, NMDevice *device)
|
|
|
|
|
{
|
2025-03-10 16:39:58 +01:00
|
|
|
NMPlatformIP6Address *subnet;
|
|
|
|
|
int ifindex = nm_device_get_ifindex(device);
|
|
|
|
|
char sbuf[NM_INET_ADDRSTRLEN];
|
|
|
|
|
NMSettingPrefixDelegation *s_pd;
|
|
|
|
|
gint64 wanted_subnet_id = -1;
|
|
|
|
|
guint64 num_subnets;
|
|
|
|
|
guint64 old_subnet_id;
|
|
|
|
|
|
|
|
|
|
nm_assert(delegation->prefix.plen > 0 && delegation->prefix.plen <= 64);
|
|
|
|
|
|
|
|
|
|
s_pd = nm_device_get_applied_setting(device, NM_TYPE_SETTING_PREFIX_DELEGATION);
|
|
|
|
|
if (s_pd) {
|
|
|
|
|
wanted_subnet_id = nm_setting_prefix_delegation_get_subnet_id(s_pd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Try to use the cached subnet assigned to the interface */
|
|
|
|
|
subnet = g_hash_table_lookup(delegation->map_ifindex_to_subnet, GINT_TO_POINTER(ifindex));
|
|
|
|
|
if (subnet) {
|
|
|
|
|
old_subnet_id = nm_ip6_addr_get_subnet_id(&subnet->address, delegation->prefix.plen);
|
|
|
|
|
if (wanted_subnet_id != -1 && wanted_subnet_id != old_subnet_id) {
|
|
|
|
|
/* The device had a subnet assigned before, but now wants a
|
|
|
|
|
* different subnet-id. Release the old subnet and continue below
|
|
|
|
|
* to get a new one. */
|
|
|
|
|
clear_ip6_subnet(ifindex, subnet);
|
|
|
|
|
subnet = NULL;
|
|
|
|
|
g_hash_table_remove(delegation->map_ifindex_to_subnet, GINT_TO_POINTER(ifindex));
|
|
|
|
|
g_hash_table_remove(delegation->map_subnet_id_to_ifindex, &old_subnet_id);
|
|
|
|
|
} else {
|
|
|
|
|
goto subnet_found;
|
2016-10-31 23:31:14 +01:00
|
|
|
}
|
2025-03-10 16:39:58 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2025-03-10 16:39:58 +01:00
|
|
|
/* Check for out-of-prefixes condition */
|
|
|
|
|
num_subnets = 1 << (64 - delegation->prefix.plen);
|
|
|
|
|
if (nm_g_hash_table_size(delegation->map_subnet_id_to_ifindex) >= num_subnets) {
|
|
|
|
|
_LOGD(LOGD_IP6,
|
|
|
|
|
"ipv6-pd: no more prefixes in %s/%u",
|
|
|
|
|
nm_inet6_ntop(&delegation->prefix.address, sbuf),
|
|
|
|
|
delegation->prefix.plen);
|
|
|
|
|
return FALSE;
|
2016-10-31 23:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
2025-03-10 16:39:58 +01:00
|
|
|
/* Try to honor the "prefix-delegation.subnet-id" property */
|
|
|
|
|
if (wanted_subnet_id >= 0) {
|
|
|
|
|
gpointer value;
|
|
|
|
|
NMDevice *other_device;
|
|
|
|
|
|
|
|
|
|
if (g_hash_table_lookup_extended(delegation->map_subnet_id_to_ifindex,
|
|
|
|
|
&wanted_subnet_id,
|
|
|
|
|
NULL,
|
|
|
|
|
&value)) {
|
|
|
|
|
other_device = nm_manager_get_device_by_ifindex(NM_MANAGER_GET, GPOINTER_TO_INT(value));
|
|
|
|
|
_LOGW(LOGD_IP6,
|
|
|
|
|
"ipv6-pd: subnet-id 0x%" G_GINT64_MODIFIER
|
|
|
|
|
"x wanted by device %s is already in use by "
|
|
|
|
|
"device %s (ifindex %d)",
|
|
|
|
|
(guint64) wanted_subnet_id,
|
|
|
|
|
nm_device_get_iface(device),
|
|
|
|
|
other_device ? nm_device_get_ip_iface(other_device) : NULL,
|
|
|
|
|
GPOINTER_TO_INT(value));
|
|
|
|
|
wanted_subnet_id = -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* If we don't have a subnet-id yet, find the first one available */
|
|
|
|
|
if (wanted_subnet_id < 0) {
|
|
|
|
|
guint64 i;
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < num_subnets; i++) {
|
|
|
|
|
if (!g_hash_table_lookup_extended(delegation->map_subnet_id_to_ifindex,
|
|
|
|
|
&i,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL)) {
|
|
|
|
|
wanted_subnet_id = (gint64) i;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (wanted_subnet_id < 0) {
|
|
|
|
|
/* We already verified that there are available subnets, this should not happen */
|
|
|
|
|
return nm_assert_unreachable_val(FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Allocate a new subnet */
|
|
|
|
|
subnet = g_slice_new0(NMPlatformIP6Address);
|
|
|
|
|
g_hash_table_insert(delegation->map_ifindex_to_subnet, GINT_TO_POINTER(ifindex), subnet);
|
|
|
|
|
g_hash_table_insert(delegation->map_subnet_id_to_ifindex,
|
|
|
|
|
nm_memdup(&wanted_subnet_id, sizeof(guint64)),
|
|
|
|
|
GINT_TO_POINTER(ifindex));
|
|
|
|
|
|
|
|
|
|
subnet->plen = 64;
|
|
|
|
|
subnet->address.s6_addr32[0] =
|
|
|
|
|
delegation->prefix.address.s6_addr32[0] | htonl(wanted_subnet_id >> 32);
|
|
|
|
|
subnet->address.s6_addr32[1] =
|
|
|
|
|
delegation->prefix.address.s6_addr32[1] | htonl(wanted_subnet_id);
|
|
|
|
|
|
|
|
|
|
subnet_found:
|
2016-10-31 23:31:14 +01:00
|
|
|
subnet->timestamp = delegation->prefix.timestamp;
|
|
|
|
|
subnet->lifetime = delegation->prefix.lifetime;
|
|
|
|
|
subnet->preferred = delegation->prefix.preferred;
|
|
|
|
|
|
|
|
|
|
_LOGD(LOGD_IP6,
|
2025-03-10 16:39:58 +01:00
|
|
|
"ipv6-pd: %s/64 (subnet-id 0x%" G_GINT64_MODIFIER "x) allocated from a /%d prefix on %s",
|
glib-aux: rename IP address related helpers from "nm-inet-utils.h"
- name things related to `in_addr_t`, `struct in6_addr`, `NMIPAddr` as
`nm_ip4_addr_*()`, `nm_ip6_addr_*()`, `nm_ip_addr_*()`, respectively.
- we have a wrapper `nm_inet_ntop()` for `inet_ntop()`. This name
of our wrapper is chosen to be familiar with the libc underlying
function. With this, also name functions that are about string
representations of addresses `nm_inet_*()`, `nm_inet4_*()`,
`nm_inet6_*()`. For example, `nm_inet_parse_str()`,
`nm_inet_is_normalized()`.
<<<<
R() {
git grep -l "$1" | xargs sed -i "s/\<$1\>/$2/g"
}
R NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX
R NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX
R NM_UTILS_INET_ADDRSTRLEN NM_INET_ADDRSTRLEN
R _nm_utils_inet4_ntop nm_inet4_ntop
R _nm_utils_inet6_ntop nm_inet6_ntop
R _nm_utils_ip4_get_default_prefix nm_ip4_addr_get_default_prefix
R _nm_utils_ip4_get_default_prefix0 nm_ip4_addr_get_default_prefix0
R _nm_utils_ip4_netmask_to_prefix nm_ip4_addr_netmask_to_prefix
R _nm_utils_ip4_prefix_to_netmask nm_ip4_addr_netmask_from_prefix
R nm_utils_inet4_ntop_dup nm_inet4_ntop_dup
R nm_utils_inet6_ntop_dup nm_inet6_ntop_dup
R nm_utils_inet_ntop nm_inet_ntop
R nm_utils_inet_ntop_dup nm_inet_ntop_dup
R nm_utils_ip4_address_clear_host_address nm_ip4_addr_clear_host_address
R nm_utils_ip4_address_is_link_local nm_ip4_addr_is_link_local
R nm_utils_ip4_address_is_loopback nm_ip4_addr_is_loopback
R nm_utils_ip4_address_is_zeronet nm_ip4_addr_is_zeronet
R nm_utils_ip4_address_same_prefix nm_ip4_addr_same_prefix
R nm_utils_ip4_address_same_prefix_cmp nm_ip4_addr_same_prefix_cmp
R nm_utils_ip6_address_clear_host_address nm_ip6_addr_clear_host_address
R nm_utils_ip6_address_same_prefix nm_ip6_addr_same_prefix
R nm_utils_ip6_address_same_prefix_cmp nm_ip6_addr_same_prefix_cmp
R nm_utils_ip6_is_ula nm_ip6_addr_is_ula
R nm_utils_ip_address_same_prefix nm_ip_addr_same_prefix
R nm_utils_ip_address_same_prefix_cmp nm_ip_addr_same_prefix_cmp
R nm_utils_ip_is_site_local nm_ip_addr_is_site_local
R nm_utils_ipaddr_is_normalized nm_inet_is_normalized
R nm_utils_ipaddr_is_valid nm_inet_is_valid
R nm_utils_ipx_address_clear_host_address nm_ip_addr_clear_host_address
R nm_utils_parse_inaddr nm_inet_parse_str
R nm_utils_parse_inaddr_bin nm_inet_parse_bin
R nm_utils_parse_inaddr_bin_full nm_inet_parse_bin_full
R nm_utils_parse_inaddr_prefix nm_inet_parse_with_prefix_str
R nm_utils_parse_inaddr_prefix_bin nm_inet_parse_with_prefix_bin
R test_nm_utils_ip6_address_same_prefix test_nm_ip_addr_same_prefix
./contrib/scripts/nm-code-format.sh -F
2022-08-19 13:15:20 +02:00
|
|
|
nm_inet6_ntop(&subnet->address, sbuf),
|
2025-03-10 16:39:58 +01:00
|
|
|
(guint64) wanted_subnet_id,
|
2016-10-31 23:31:14 +01:00
|
|
|
delegation->prefix.plen,
|
|
|
|
|
nm_device_get_iface(device));
|
|
|
|
|
|
|
|
|
|
nm_device_use_ip6_subnet(device, subnet);
|
|
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Try to obtain a subnet from each prefix delegated to given requesting
|
|
|
|
|
* ("uplink") device and assign it to the downlink device.
|
|
|
|
|
* Requests a new prefix if no subnet could be found.
|
|
|
|
|
*/
|
|
|
|
|
static void
|
|
|
|
|
ip6_subnet_from_device(NMPolicy *self, NMDevice *from_device, NMDevice *device)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2016-10-31 23:31:14 +01:00
|
|
|
IP6PrefixDelegation *delegation = NULL;
|
|
|
|
|
gboolean got_subnet = FALSE;
|
2016-11-09 17:58:11 +01:00
|
|
|
guint have_prefixes = 0;
|
|
|
|
|
guint i;
|
2016-10-31 23:31:14 +01:00
|
|
|
|
|
|
|
|
expire_ip6_delegations(self);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < priv->ip6_prefix_delegations->len; i++) {
|
2022-09-08 12:05:56 +02:00
|
|
|
delegation = &nm_g_array_index(priv->ip6_prefix_delegations, IP6PrefixDelegation, i);
|
2016-10-31 23:31:14 +01:00
|
|
|
|
|
|
|
|
if (delegation->device != from_device)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (ip6_subnet_from_delegation(delegation, device))
|
|
|
|
|
got_subnet = TRUE;
|
|
|
|
|
have_prefixes++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!got_subnet) {
|
2016-11-09 17:58:11 +01:00
|
|
|
_LOGI(LOGD_IP6,
|
|
|
|
|
"ipv6-pd: none of %u prefixes of %s can be shared on %s",
|
2016-10-31 23:31:14 +01:00
|
|
|
have_prefixes,
|
|
|
|
|
nm_device_get_iface(from_device),
|
|
|
|
|
nm_device_get_iface(device));
|
|
|
|
|
nm_device_request_ip6_prefixes(from_device, have_prefixes + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
ip6_remove_device_prefix_delegations(NMPolicy *self, NMDevice *device)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2016-11-09 17:58:11 +01:00
|
|
|
IP6PrefixDelegation *delegation = NULL;
|
|
|
|
|
guint i;
|
2016-10-31 23:31:14 +01:00
|
|
|
|
|
|
|
|
for (i = 0; i < priv->ip6_prefix_delegations->len; i++) {
|
2022-09-08 12:05:56 +02:00
|
|
|
delegation = &nm_g_array_index(priv->ip6_prefix_delegations, IP6PrefixDelegation, i);
|
2016-10-31 23:31:14 +01:00
|
|
|
if (delegation->device == device)
|
|
|
|
|
g_array_remove_index_fast(priv->ip6_prefix_delegations, i);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2021-11-09 13:28:54 +01:00
|
|
|
device_ip6_prefix_delegated(NMDevice *device,
|
2021-08-05 09:11:14 +02:00
|
|
|
const NMPlatformIP6Address *prefix,
|
|
|
|
|
gpointer user_data)
|
2016-10-31 23:31:14 +01:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = user_data;
|
|
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
2016-11-09 17:58:11 +01:00
|
|
|
IP6PrefixDelegation *delegation = NULL;
|
|
|
|
|
guint i;
|
2021-11-09 13:28:54 +01:00
|
|
|
const CList *tmp_list;
|
|
|
|
|
NMActiveConnection *ac;
|
glib-aux: rename IP address related helpers from "nm-inet-utils.h"
- name things related to `in_addr_t`, `struct in6_addr`, `NMIPAddr` as
`nm_ip4_addr_*()`, `nm_ip6_addr_*()`, `nm_ip_addr_*()`, respectively.
- we have a wrapper `nm_inet_ntop()` for `inet_ntop()`. This name
of our wrapper is chosen to be familiar with the libc underlying
function. With this, also name functions that are about string
representations of addresses `nm_inet_*()`, `nm_inet4_*()`,
`nm_inet6_*()`. For example, `nm_inet_parse_str()`,
`nm_inet_is_normalized()`.
<<<<
R() {
git grep -l "$1" | xargs sed -i "s/\<$1\>/$2/g"
}
R NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX
R NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX
R NM_UTILS_INET_ADDRSTRLEN NM_INET_ADDRSTRLEN
R _nm_utils_inet4_ntop nm_inet4_ntop
R _nm_utils_inet6_ntop nm_inet6_ntop
R _nm_utils_ip4_get_default_prefix nm_ip4_addr_get_default_prefix
R _nm_utils_ip4_get_default_prefix0 nm_ip4_addr_get_default_prefix0
R _nm_utils_ip4_netmask_to_prefix nm_ip4_addr_netmask_to_prefix
R _nm_utils_ip4_prefix_to_netmask nm_ip4_addr_netmask_from_prefix
R nm_utils_inet4_ntop_dup nm_inet4_ntop_dup
R nm_utils_inet6_ntop_dup nm_inet6_ntop_dup
R nm_utils_inet_ntop nm_inet_ntop
R nm_utils_inet_ntop_dup nm_inet_ntop_dup
R nm_utils_ip4_address_clear_host_address nm_ip4_addr_clear_host_address
R nm_utils_ip4_address_is_link_local nm_ip4_addr_is_link_local
R nm_utils_ip4_address_is_loopback nm_ip4_addr_is_loopback
R nm_utils_ip4_address_is_zeronet nm_ip4_addr_is_zeronet
R nm_utils_ip4_address_same_prefix nm_ip4_addr_same_prefix
R nm_utils_ip4_address_same_prefix_cmp nm_ip4_addr_same_prefix_cmp
R nm_utils_ip6_address_clear_host_address nm_ip6_addr_clear_host_address
R nm_utils_ip6_address_same_prefix nm_ip6_addr_same_prefix
R nm_utils_ip6_address_same_prefix_cmp nm_ip6_addr_same_prefix_cmp
R nm_utils_ip6_is_ula nm_ip6_addr_is_ula
R nm_utils_ip_address_same_prefix nm_ip_addr_same_prefix
R nm_utils_ip_address_same_prefix_cmp nm_ip_addr_same_prefix_cmp
R nm_utils_ip_is_site_local nm_ip_addr_is_site_local
R nm_utils_ipaddr_is_normalized nm_inet_is_normalized
R nm_utils_ipaddr_is_valid nm_inet_is_valid
R nm_utils_ipx_address_clear_host_address nm_ip_addr_clear_host_address
R nm_utils_parse_inaddr nm_inet_parse_str
R nm_utils_parse_inaddr_bin nm_inet_parse_bin
R nm_utils_parse_inaddr_bin_full nm_inet_parse_bin_full
R nm_utils_parse_inaddr_prefix nm_inet_parse_with_prefix_str
R nm_utils_parse_inaddr_prefix_bin nm_inet_parse_with_prefix_bin
R test_nm_utils_ip6_address_same_prefix test_nm_ip_addr_same_prefix
./contrib/scripts/nm-code-format.sh -F
2022-08-19 13:15:20 +02:00
|
|
|
char sbuf[NM_INET_ADDRSTRLEN];
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-10-31 23:31:14 +01:00
|
|
|
_LOGI(LOGD_IP6,
|
|
|
|
|
"ipv6-pd: received a prefix %s/%d from %s",
|
glib-aux: rename IP address related helpers from "nm-inet-utils.h"
- name things related to `in_addr_t`, `struct in6_addr`, `NMIPAddr` as
`nm_ip4_addr_*()`, `nm_ip6_addr_*()`, `nm_ip_addr_*()`, respectively.
- we have a wrapper `nm_inet_ntop()` for `inet_ntop()`. This name
of our wrapper is chosen to be familiar with the libc underlying
function. With this, also name functions that are about string
representations of addresses `nm_inet_*()`, `nm_inet4_*()`,
`nm_inet6_*()`. For example, `nm_inet_parse_str()`,
`nm_inet_is_normalized()`.
<<<<
R() {
git grep -l "$1" | xargs sed -i "s/\<$1\>/$2/g"
}
R NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX
R NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX
R NM_UTILS_INET_ADDRSTRLEN NM_INET_ADDRSTRLEN
R _nm_utils_inet4_ntop nm_inet4_ntop
R _nm_utils_inet6_ntop nm_inet6_ntop
R _nm_utils_ip4_get_default_prefix nm_ip4_addr_get_default_prefix
R _nm_utils_ip4_get_default_prefix0 nm_ip4_addr_get_default_prefix0
R _nm_utils_ip4_netmask_to_prefix nm_ip4_addr_netmask_to_prefix
R _nm_utils_ip4_prefix_to_netmask nm_ip4_addr_netmask_from_prefix
R nm_utils_inet4_ntop_dup nm_inet4_ntop_dup
R nm_utils_inet6_ntop_dup nm_inet6_ntop_dup
R nm_utils_inet_ntop nm_inet_ntop
R nm_utils_inet_ntop_dup nm_inet_ntop_dup
R nm_utils_ip4_address_clear_host_address nm_ip4_addr_clear_host_address
R nm_utils_ip4_address_is_link_local nm_ip4_addr_is_link_local
R nm_utils_ip4_address_is_loopback nm_ip4_addr_is_loopback
R nm_utils_ip4_address_is_zeronet nm_ip4_addr_is_zeronet
R nm_utils_ip4_address_same_prefix nm_ip4_addr_same_prefix
R nm_utils_ip4_address_same_prefix_cmp nm_ip4_addr_same_prefix_cmp
R nm_utils_ip6_address_clear_host_address nm_ip6_addr_clear_host_address
R nm_utils_ip6_address_same_prefix nm_ip6_addr_same_prefix
R nm_utils_ip6_address_same_prefix_cmp nm_ip6_addr_same_prefix_cmp
R nm_utils_ip6_is_ula nm_ip6_addr_is_ula
R nm_utils_ip_address_same_prefix nm_ip_addr_same_prefix
R nm_utils_ip_address_same_prefix_cmp nm_ip_addr_same_prefix_cmp
R nm_utils_ip_is_site_local nm_ip_addr_is_site_local
R nm_utils_ipaddr_is_normalized nm_inet_is_normalized
R nm_utils_ipaddr_is_valid nm_inet_is_valid
R nm_utils_ipx_address_clear_host_address nm_ip_addr_clear_host_address
R nm_utils_parse_inaddr nm_inet_parse_str
R nm_utils_parse_inaddr_bin nm_inet_parse_bin
R nm_utils_parse_inaddr_bin_full nm_inet_parse_bin_full
R nm_utils_parse_inaddr_prefix nm_inet_parse_with_prefix_str
R nm_utils_parse_inaddr_prefix_bin nm_inet_parse_with_prefix_bin
R test_nm_utils_ip6_address_same_prefix test_nm_ip_addr_same_prefix
./contrib/scripts/nm-code-format.sh -F
2022-08-19 13:15:20 +02:00
|
|
|
nm_inet6_ntop(&prefix->address, sbuf),
|
2016-10-31 23:31:14 +01:00
|
|
|
prefix->plen,
|
|
|
|
|
nm_device_get_iface(device));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-10-31 23:31:14 +01:00
|
|
|
expire_ip6_delegations(self);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-11-09 17:58:11 +01:00
|
|
|
for (i = 0; i < priv->ip6_prefix_delegations->len; i++) {
|
|
|
|
|
/* Look for an already known prefix to update. */
|
2022-09-08 12:05:56 +02:00
|
|
|
delegation = &nm_g_array_index(priv->ip6_prefix_delegations, IP6PrefixDelegation, i);
|
2016-11-09 17:58:11 +01:00
|
|
|
if (IN6_ARE_ADDR_EQUAL(&delegation->prefix.address, &prefix->address))
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-11-09 17:58:11 +01:00
|
|
|
if (i == priv->ip6_prefix_delegations->len) {
|
2020-07-04 11:37:01 +03:00
|
|
|
/* Allocate a delegation for new prefix. */
|
2022-09-08 12:57:10 +02:00
|
|
|
delegation = nm_g_array_append_new(priv->ip6_prefix_delegations, IP6PrefixDelegation);
|
2025-03-10 16:39:58 +01:00
|
|
|
delegation->map_subnet_id_to_ifindex =
|
|
|
|
|
g_hash_table_new_full(nm_puint64_hash, nm_puint64_equal, g_free, NULL);
|
|
|
|
|
delegation->map_ifindex_to_subnet = g_hash_table_new(nm_direct_hash, NULL);
|
2016-11-09 17:58:11 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-10-31 23:31:14 +01:00
|
|
|
delegation->device = device;
|
|
|
|
|
delegation->prefix = *prefix;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-11-04 13:53:57 +01:00
|
|
|
/* The newly activated connections are added to the end of the list,
|
|
|
|
|
* so traversing it from the end makes it likely for newly
|
2016-10-31 23:31:14 +01:00
|
|
|
* activated connections that have no subnet assigned to be served
|
|
|
|
|
* first. That is a simple yet fair policy, which is good. */
|
2020-11-04 13:53:57 +01:00
|
|
|
nm_manager_for_each_active_connection_prev (priv->manager, ac, tmp_list) {
|
2017-11-23 21:30:09 +01:00
|
|
|
NMDevice *to_device;
|
2016-10-31 23:31:14 +01:00
|
|
|
|
2017-11-23 21:30:09 +01:00
|
|
|
to_device = nm_active_connection_get_device(ac);
|
2016-10-31 23:31:14 +01:00
|
|
|
if (nm_device_needs_ip6_subnet(to_device))
|
|
|
|
|
ip6_subnet_from_delegation(delegation, to_device);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
device_ip6_subnet_needed(NMDevice *device, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMPolicyPrivate *priv = user_data;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
2016-10-31 23:31:14 +01:00
|
|
|
|
|
|
|
|
_LOGD(LOGD_IP6, "ipv6-pd: %s needs a subnet", nm_device_get_iface(device));
|
|
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
if (!priv->default_ac6) {
|
2016-10-31 23:31:14 +01:00
|
|
|
/* We request the prefixes when the default IPv6 device is set. */
|
|
|
|
|
_LOGI(LOGD_IP6,
|
|
|
|
|
"ipv6-pd: no device to obtain a subnet to share on %s from",
|
|
|
|
|
nm_device_get_iface(device));
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-06-28 18:05:05 +02:00
|
|
|
ip6_subnet_from_device(self, get_default_device(self, AF_INET6), device);
|
|
|
|
|
nm_device_copy_ip6_dns_config(device, get_default_device(self, AF_INET6));
|
2016-10-31 23:31:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
static NMDevice *
|
2018-06-28 18:05:05 +02:00
|
|
|
get_default_device(NMPolicy *self, int addr_family)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2018-06-28 18:05:05 +02:00
|
|
|
NMActiveConnection *ac;
|
|
|
|
|
|
|
|
|
|
nm_assert_addr_family(addr_family);
|
|
|
|
|
|
|
|
|
|
ac = (addr_family == AF_INET) ? priv->default_ac4 : priv->default_ac6;
|
|
|
|
|
|
|
|
|
|
return ac ? nm_active_connection_get_device(ac) : NULL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static NMActiveConnection *
|
|
|
|
|
get_best_active_connection(NMPolicy *self, int addr_family, gboolean fully_activated)
|
2008-03-07 Dan Williams <dcbw@redhat.com>
First pass of multiple active device support. Expect bugs.
* src/nm-ip4-config.c
src/nm-ip4-config.h
- (nm_ip4_config_get_secondary, nm_ip4_config_set_secondary): remove;
there are better ways to do this in the named manager
* src/nm-device.c
src/nm-device.h
- (nm_device_can_activate): return whether the device can activate a
connection right now; taking into account things like carrier state
and rfkill state
- (nm_device_get_best_auto_connection): renamed from
nm_device_get_best_connection
- (real_act_stage4_get_ip4_config): MTU stuff is now handled in the
device subclasses themselves, so that each device can override the
MTU from it's NMSetting subclass if needed
- (nm_device_set_ip4_config): set MTU when setting up routes and stuff
in NetworkManagerSystem.c, not here
* src/named-manager/nm-named-manager.c
src/named-manager/nm-named-manager.h
- (nm_named_manager_name_owner_changed,
nm_named_manager_dbus_connection_changed): fix for changes to
rewrite_resolv_conf()
- (compute_nameservers): don't need the NMNamedManager at all, remove
from parameter list
- (merge_one_ip4_config): new function; merge ip4 configs together
- (rewrite_resolv_conf): write out resolv.conf from all the stored
ip4 configs; the VPN config takes precedence, then the best
device config, then the rest of the configs
- (get_domain_for_config): take the NMNamedManager as an argument
to check whether the config is the VPN config
- (add_ip4_config_to_named): fixups for removal of the 'secondary'
attribute from ip4 configs
- (add_all_ip4_configs_to_named): add all the configs in priority order
- (remove_ip4_config_from_named): fix for changes to
get_domain_for_config()
- (nm_named_manager_add_ip4_config): assign the config to the right slot
based on its type; callers must pass in the type now
- (get_last_default_domain): remove, unused
- (nm_named_manager_remove_ip4_config): handle config slots correctly
* src/nm-device-802-11-wireless.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): handle MTU override
* src/nm-device-802-3-ethernet.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): new function; handle MTU override
* src/vpn-manager/nm-vpn-connection.c
- (nm_vpn_connection_ip4_config_get): don't need to set the 'secondary'
attribute on the ip4 config
* src/NetworkManagerPolicy.c
- (nm_policy_auto_get_best_device): remove
- (nm_policy_device_change_check): remove
- (update_default_route): new function; set the default route via
the specified device
- (get_device_priority): new function; return the priority number of
a device type WRT which one should have the default route. Order is
(highest to lowest) wired, wireless, GSM, CDMA.
- (update_routing_and_dns): new function; determine which device should
have the default route, then update the routing table and DNS
- (maybe_auto_activate_device): new function; if a device is now
available for activation, find out what connection it would like to
activate and do it
- (schedule_activate_check): new function; if a device can be activated
now, schedule the activation. Each device may have only one
pending activation at a given time.
- (device_state_changed): if activation was canceled, try again,
possibly with another connection; if the device was activated,
update routing and DNS; if the device was deactivated, try again
with another connection
- (device_carrier_changed): if there is no carrier, deactivate the
device; otherwise schedule an activation check for the device
- (wireless_networks_changed): schedule an activation check for the
device
- (device_added): keep track of the signal handler IDs so they can
be removed when the device goes away
- (device_removed): remove any signal handlers that might be attached
to the device; update routing and DNS
- (schedule_activate_all): new function
- (connections_added, connection_added, connection_updated): when
connections change, schedule all devices for an activation check
- (connection_removed): when a device is deactivated because its
connection was removed, schedule another activation check for it
- (nm_policy_destroy): destroy pending activations and disconnect
all device signal handlers
* src/nm-manager.c
- (nm_manager_activate_device): if the device was already actived,
deactivate it
- (deactivate_old_device): remove
- (connection_added_default_handler, impl_manager_activate_device):
don't deactivate other devices when activating this one
* src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerSuSE.c
src/backends/NetworkManagerDebian.c
- (nm_system_get_mtu): remove; MTU should be provided through the
distro's system settings service plugin instead
- (nm_system_device_add_default_route_via_device): remove
- (nm_system_device_add_default_route_via_device_with_iface): remove
- (nm_system_device_replace_default_route): new function; call
generic implementation
* src/backends/NetworkManagerGeneric.c
src/backends/NetworkManagerGeneric.h
- (nm_generic_device_add_default_route_via_device,
nm_generic_device_add_default_route_via_device_with_iface): remove
- (nm_generic_device_replace_default_route): replace the default route
with the given route via some gateway
* src/NetworkManagerSystem.c
src/NetworkManagerSystem.h
- (nm_system_device_set_from_ip4_config): let the policy handle updates
to routing and DNS; but set the MTU here
- (nm_system_vpn_device_set_from_ip4_config): set the route with the
ip_iface of the active device; use the standard MTU setting function
- (nm_system_set_mtu): remove
- (nm_system_device_set_mtu): consolidate MTU setting code in one place
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3391 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-07 19:41:32 +00:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
const CList *tmp_lst;
|
|
|
|
|
NMDevice *device;
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
guint32 best_metric = G_MAXUINT32;
|
|
|
|
|
gboolean best_is_fully_activated = FALSE;
|
2018-06-28 18:05:05 +02:00
|
|
|
NMActiveConnection *best_ac, *prev_ac;
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
|
|
|
|
|
nm_assert(NM_IN_SET(addr_family, AF_INET, AF_INET6));
|
|
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
/* we prefer the current AC in case of identical metric.
|
|
|
|
|
* Hence, try that one first. */
|
|
|
|
|
prev_ac = addr_family == AF_INET ? (fully_activated ? priv->default_ac4 : priv->activating_ac4)
|
|
|
|
|
: (fully_activated ? priv->default_ac6 : priv->activating_ac6);
|
|
|
|
|
best_ac = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-03-29 08:52:45 +02:00
|
|
|
nm_manager_for_each_device (priv->manager, device, tmp_lst) {
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
NMDeviceState state;
|
2021-11-09 13:28:54 +01:00
|
|
|
const NMPObject *r;
|
2018-06-28 18:05:05 +02:00
|
|
|
NMActiveConnection *ac;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *connection;
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
guint32 metric;
|
|
|
|
|
gboolean is_fully_activated;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
state = nm_device_get_state(device);
|
|
|
|
|
if (state <= NM_DEVICE_STATE_DISCONNECTED || state >= NM_DEVICE_STATE_DEACTIVATING)
|
|
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2024-08-27 10:26:50 +02:00
|
|
|
if (nm_device_managed_type_is_external(device))
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
r = nm_device_get_best_default_route(device, addr_family);
|
|
|
|
|
if (r) {
|
2018-01-23 12:24:29 +01:00
|
|
|
/* NOTE: the best route might have rt_source NM_IP_CONFIG_SOURCE_VPN,
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
* which means it was injected by a VPN, not added by device.
|
|
|
|
|
*
|
|
|
|
|
* In this case, is it really the best device? Why do we even need the best
|
|
|
|
|
* device?? */
|
2020-07-03 15:25:51 +02:00
|
|
|
metric = NMP_OBJECT_CAST_IP_ROUTE(r)->metric;
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
is_fully_activated = TRUE;
|
|
|
|
|
} else if (!fully_activated && (connection = nm_device_get_applied_connection(device))
|
|
|
|
|
&& nm_utils_connection_has_default_route(connection, addr_family, NULL)) {
|
2020-07-03 15:25:51 +02:00
|
|
|
metric = nm_device_get_route_metric(device, addr_family);
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
is_fully_activated = FALSE;
|
|
|
|
|
} else
|
|
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
ac = (NMActiveConnection *) nm_device_get_act_request(device);
|
|
|
|
|
nm_assert(ac);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
if (!best_ac || (!best_is_fully_activated && is_fully_activated)
|
2018-06-28 18:05:05 +02:00
|
|
|
|| (metric < best_metric || (metric == best_metric && ac == prev_ac))) {
|
|
|
|
|
best_ac = ac;
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
best_metric = metric;
|
|
|
|
|
best_is_fully_activated = is_fully_activated;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
|
|
|
|
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
if (!fully_activated && best_ac && best_is_fully_activated) {
|
2018-06-28 18:05:05 +02:00
|
|
|
/* There's a best activating AC only if the best device
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
* among all activating and already-activated devices is a
|
|
|
|
|
* still-activating one. */
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
return best_ac;
|
2010-04-23 22:11:22 -07:00
|
|
|
}
|
|
|
|
|
|
2017-03-10 15:17:02 +01:00
|
|
|
static gboolean
|
2022-10-26 13:50:41 +02:00
|
|
|
any_devices_active(NMPolicy *self)
|
2017-03-10 15:17:02 +01:00
|
|
|
{
|
|
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2021-11-09 13:28:54 +01:00
|
|
|
const CList *tmp_lst;
|
|
|
|
|
NMDevice *device;
|
2017-03-10 15:17:02 +01:00
|
|
|
|
2018-03-29 08:52:45 +02:00
|
|
|
nm_manager_for_each_device (priv->manager, device, tmp_lst) {
|
2017-03-10 15:17:02 +01:00
|
|
|
NMDeviceState state;
|
|
|
|
|
|
core: track devices in manager via embedded CList
Instead of using a GSList for tracking the devices, use a CList.
I think a CList is in most cases the more suitable data structure
then GSList:
- you can find out in O(1) whether the object is linked. That
is nice, for example to assert in NMDevice's destructor that
the object was unlinked, and we will use that later in
nm_manager_get_device_by_path().
- you can unlink the element in O(1) and you can unlink the
element without having access to the link's head
- Contrary to GSList, this does not require an extra slice
allocation for the link node. It quite possibliy consumes
slightly less memory because the CList structure is embedded
in a struct that we already allocate. Even if slice allocation
would be perfect to only consume 2*sizeof(gpointer) for the link
note, it would at most be as-good as CList. Quite possibly,
there is an overhead though.
- CList possibly has better memory locality, because the link
structure and the data are close to each other.
Something which could be seen as disavantage, is that with CList
one device can only be tracked in one NMManager instance at a time.
But that is fine. There exists only one NMManager instance for now,
and even if we would ever introduce multiple managers, we probably
would not associate one NMDevice instance with multiple managers.
The advantages are arguably not huge, but CList is IMHO clearly the
more suited data structure. No need to stick to a suboptimal data
structure for the job. Refactor it.
2018-03-23 21:51:07 +01:00
|
|
|
state = nm_device_get_state(device);
|
2022-10-26 14:29:28 +02:00
|
|
|
if (state <= NM_DEVICE_STATE_DISCONNECTED || state >= NM_DEVICE_STATE_DEACTIVATING)
|
|
|
|
|
continue;
|
2024-08-27 10:26:50 +02:00
|
|
|
if (nm_device_managed_type_is_external(device))
|
2017-03-10 15:17:02 +01:00
|
|
|
continue;
|
2022-10-26 13:50:41 +02:00
|
|
|
return TRUE;
|
2017-03-10 15:17:02 +01:00
|
|
|
}
|
2022-10-26 13:50:41 +02:00
|
|
|
return FALSE;
|
2017-03-10 15:17:02 +01:00
|
|
|
}
|
|
|
|
|
|
2013-02-24 13:51:56 +01:00
|
|
|
#define FALLBACK_HOSTNAME4 "localhost.localdomain"
|
|
|
|
|
|
2016-03-29 10:46:07 +02:00
|
|
|
static void
|
|
|
|
|
settings_set_hostname_cb(const char *hostname, gboolean result, gpointer user_data)
|
2013-02-24 13:51:56 +01:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = NM_POLICY(user_data);
|
2017-02-17 16:22:30 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2016-02-18 18:19:30 +01:00
|
|
|
int ret = 0;
|
2019-01-31 13:29:21 +01:00
|
|
|
int errsv;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-02-18 18:19:30 +01:00
|
|
|
if (!result) {
|
2017-03-03 12:11:57 +01:00
|
|
|
_LOGT(LOGD_DNS, "set-hostname: hostname set via dbus failed, fallback to \"sethostname\"");
|
2016-02-18 18:19:30 +01:00
|
|
|
ret = sethostname(hostname, strlen(hostname));
|
|
|
|
|
if (ret != 0) {
|
2019-01-31 13:29:21 +01:00
|
|
|
errsv = errno;
|
2017-03-03 12:11:57 +01:00
|
|
|
_LOGW(LOGD_DNS,
|
|
|
|
|
"set-hostname: couldn't set the system hostname to '%s': (%d) %s",
|
2019-01-31 17:22:18 +01:00
|
|
|
hostname,
|
|
|
|
|
errsv,
|
|
|
|
|
nm_strerror_native(errsv));
|
2016-02-18 18:19:30 +01:00
|
|
|
if (errsv == EPERM)
|
2017-03-03 12:11:57 +01:00
|
|
|
_LOGW(
|
|
|
|
|
LOGD_DNS,
|
|
|
|
|
"set-hostname: you should use hostnamed when systemd hardening is in effect!");
|
2016-02-18 18:19:30 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
|
|
|
|
|
2017-02-17 16:22:30 +01:00
|
|
|
priv->changing_hostname = FALSE;
|
2016-02-18 18:19:30 +01:00
|
|
|
if (!ret)
|
2017-03-08 14:11:22 +01:00
|
|
|
nm_dispatcher_call_hostname(NULL, NULL, NULL);
|
2017-02-17 16:22:30 +01:00
|
|
|
g_object_unref(self);
|
2016-02-18 18:19:30 +01:00
|
|
|
}
|
|
|
|
|
|
2017-02-17 15:33:27 +01:00
|
|
|
#define HOST_NAME_BUFSIZE (HOST_NAME_MAX + 2)
|
|
|
|
|
|
|
|
|
|
static char *
|
2017-04-23 19:54:39 +02:00
|
|
|
_get_hostname(NMPolicy *self)
|
2017-02-17 15:33:27 +01:00
|
|
|
{
|
|
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2021-11-09 13:28:54 +01:00
|
|
|
char *hostname = NULL;
|
2019-01-31 13:29:21 +01:00
|
|
|
int errsv;
|
2017-02-17 15:33:27 +01:00
|
|
|
|
2017-02-17 16:22:30 +01:00
|
|
|
/* If there is an in-progress hostname change, return
|
|
|
|
|
* the last hostname set as would be set soon...
|
|
|
|
|
*/
|
|
|
|
|
if (priv->changing_hostname) {
|
2017-03-03 12:11:57 +01:00
|
|
|
_LOGT(LOGD_DNS, "get-hostname: \"%s\" (last on set)", priv->last_hostname);
|
2017-04-23 19:54:39 +02:00
|
|
|
return g_strdup(priv->last_hostname);
|
2017-02-17 16:22:30 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-02-17 15:33:27 +01:00
|
|
|
/* try to get the hostname via dbus... */
|
2017-04-23 19:54:39 +02:00
|
|
|
if (nm_hostname_manager_get_transient_hostname(priv->hostname_manager, &hostname)) {
|
|
|
|
|
_LOGT(LOGD_DNS, "get-hostname: \"%s\" (from dbus)", hostname);
|
|
|
|
|
return hostname;
|
2017-02-17 15:33:27 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-02-17 15:33:27 +01:00
|
|
|
/* ...or retrieve it by yourself */
|
2017-04-23 19:54:39 +02:00
|
|
|
hostname = g_malloc(HOST_NAME_BUFSIZE);
|
|
|
|
|
if (gethostname(hostname, HOST_NAME_BUFSIZE - 1) != 0) {
|
2019-01-31 13:29:21 +01:00
|
|
|
errsv = errno;
|
2017-03-03 12:11:57 +01:00
|
|
|
_LOGT(LOGD_DNS,
|
|
|
|
|
"get-hostname: couldn't get the system hostname: (%d) %s",
|
2019-01-31 17:08:03 +01:00
|
|
|
errsv,
|
|
|
|
|
nm_strerror_native(errsv));
|
2017-04-23 19:54:39 +02:00
|
|
|
g_free(hostname);
|
2017-02-17 15:33:27 +01:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-02-17 15:33:27 +01:00
|
|
|
/* the name may be truncated... */
|
2017-04-23 19:54:39 +02:00
|
|
|
hostname[HOST_NAME_BUFSIZE - 1] = '\0';
|
|
|
|
|
if (strlen(hostname) >= HOST_NAME_BUFSIZE - 1) {
|
|
|
|
|
_LOGT(LOGD_DNS, "get-hostname: system hostname too long: \"%s\"", hostname);
|
|
|
|
|
g_free(hostname);
|
2017-02-17 15:33:27 +01:00
|
|
|
return NULL;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-23 19:54:39 +02:00
|
|
|
_LOGT(LOGD_DNS, "get-hostname: \"%s\"", hostname);
|
|
|
|
|
return hostname;
|
2017-02-17 15:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
static void
|
2024-07-31 17:08:43 +02:00
|
|
|
hostname_retry_schedule(NMPolicy *self)
|
|
|
|
|
{
|
|
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
|
|
|
|
|
if (priv->hostname_retry.source && !priv->hostname_retry.do_restart)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
nm_clear_g_source_inst(&priv->hostname_retry.source);
|
|
|
|
|
|
|
|
|
|
if (priv->hostname_retry.do_restart)
|
|
|
|
|
priv->hostname_retry.interval_sec = 0;
|
|
|
|
|
|
|
|
|
|
priv->hostname_retry.interval_sec *= HOSTNAME_RETRY_INTERVAL_MULTIPLIER;
|
|
|
|
|
priv->hostname_retry.interval_sec = NM_CLAMP(priv->hostname_retry.interval_sec,
|
|
|
|
|
HOSTNAME_RETRY_INTERVAL_MIN,
|
|
|
|
|
HOSTNAME_RETRY_INTERVAL_MAX);
|
|
|
|
|
|
|
|
|
|
_LOGT(LOGD_DNS,
|
|
|
|
|
"hostname-retry: schedule in %u seconds%s",
|
|
|
|
|
priv->hostname_retry.interval_sec,
|
|
|
|
|
priv->hostname_retry.do_restart ? " (restarted)" : "");
|
|
|
|
|
priv->hostname_retry.source =
|
|
|
|
|
nm_g_timeout_add_seconds_source(priv->hostname_retry.interval_sec, hostname_retry_cb, self);
|
|
|
|
|
|
|
|
|
|
priv->hostname_retry.do_restart = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
hostname_retry_cb(gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMPolicy *self = NM_POLICY(user_data);
|
|
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
const CList *tmp_lst;
|
|
|
|
|
NMDevice *device;
|
|
|
|
|
|
|
|
|
|
_LOGT(LOGD_DNS, "hostname-retry: timeout");
|
|
|
|
|
|
|
|
|
|
nm_clear_g_source_inst(&priv->hostname_retry.source);
|
|
|
|
|
|
|
|
|
|
/* Clear any cached DNS results before retrying */
|
|
|
|
|
nm_manager_for_each_device (priv->manager, device, tmp_lst) {
|
|
|
|
|
nm_device_clear_dns_lookup_data(device, "hostname retry timeout");
|
|
|
|
|
}
|
|
|
|
|
update_system_hostname(self, "hostname retry timeout", FALSE);
|
|
|
|
|
|
|
|
|
|
return G_SOURCE_CONTINUE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_set_hostname(NMPolicy *self, const char *new_hostname, const char *msg, gboolean do_retry)
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
{
|
2016-03-29 10:46:07 +02:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2021-11-09 13:28:54 +01:00
|
|
|
gs_free char *old_hostname = NULL;
|
2022-03-04 08:10:17 +01:00
|
|
|
gboolean cur_hostname_full_changed;
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *name;
|
2013-08-22 10:10:17 -04:00
|
|
|
|
2011-11-02 15:21:52 -05:00
|
|
|
/* The incoming hostname *can* be NULL, which will get translated to
|
|
|
|
|
* 'localhost.localdomain' or such in the hostname policy code, but we
|
|
|
|
|
* keep cur_hostname = NULL in the case because we need to know that
|
|
|
|
|
* there was no valid hostname to start with.
|
|
|
|
|
*/
|
|
|
|
|
|
2022-03-04 08:10:17 +01:00
|
|
|
if (nm_strdup_reset(&priv->cur_hostname_full, new_hostname)) {
|
|
|
|
|
gs_free char *shortened = NULL;
|
|
|
|
|
|
|
|
|
|
cur_hostname_full_changed = TRUE;
|
|
|
|
|
|
|
|
|
|
if (priv->cur_hostname_full
|
|
|
|
|
&& !nm_utils_shorten_hostname(priv->cur_hostname_full, &shortened)) {
|
|
|
|
|
_LOGW(LOGD_DNS,
|
|
|
|
|
"set-hostname: hostname '%s' %s is invalid",
|
|
|
|
|
priv->cur_hostname_full,
|
|
|
|
|
msg);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (shortened) {
|
|
|
|
|
_LOGI(LOGD_DNS,
|
|
|
|
|
"set-hostname: shortened hostname %s from '%s' to '%s'",
|
|
|
|
|
msg,
|
|
|
|
|
priv->cur_hostname_full,
|
|
|
|
|
shortened);
|
|
|
|
|
nm_strdup_reset_take(&priv->cur_hostname, g_steal_pointer(&shortened));
|
|
|
|
|
} else
|
|
|
|
|
nm_strdup_reset(&priv->cur_hostname, priv->cur_hostname_full);
|
|
|
|
|
} else
|
|
|
|
|
cur_hostname_full_changed = FALSE;
|
|
|
|
|
|
2017-02-27 15:47:43 +01:00
|
|
|
/* Update the DNS only if the hostname is actually
|
|
|
|
|
* going to change.
|
|
|
|
|
*/
|
2022-03-04 08:10:17 +01:00
|
|
|
if (cur_hostname_full_changed) {
|
2016-08-17 18:40:17 +02:00
|
|
|
/* Notify the DNS manager of the hostname change so that the domain part, if
|
2020-12-17 14:13:45 +01:00
|
|
|
* present, can be added to the search list. Set the @updating_dns flag
|
|
|
|
|
* so that dns_config_changed() doesn't try again to restart DNS lookup.
|
2016-08-17 18:40:17 +02:00
|
|
|
*/
|
2020-12-17 14:13:45 +01:00
|
|
|
priv->updating_dns = TRUE;
|
2017-03-10 15:17:02 +01:00
|
|
|
nm_dns_manager_set_hostname(priv->dns_manager,
|
2022-03-04 09:31:49 +01:00
|
|
|
priv->cur_hostname_full,
|
2022-10-26 13:50:41 +02:00
|
|
|
!any_devices_active(self));
|
2020-12-17 14:13:45 +01:00
|
|
|
priv->updating_dns = FALSE;
|
2016-08-17 18:40:17 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2024-07-31 17:08:43 +02:00
|
|
|
if (!do_retry) {
|
|
|
|
|
_LOGT(LOGD_DNS, "hostname-retry: clear");
|
|
|
|
|
nm_clear_g_source_inst(&priv->hostname_retry.source);
|
|
|
|
|
priv->hostname_retry.interval_sec = 0;
|
|
|
|
|
priv->hostname_retry.do_restart = FALSE;
|
|
|
|
|
} else if (!priv->hostname_retry.source) {
|
|
|
|
|
hostname_retry_schedule(self);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-22 10:10:15 +01:00
|
|
|
/* Finally, set kernel hostname */
|
2022-03-04 08:10:17 +01:00
|
|
|
nm_assert(!priv->cur_hostname || priv->cur_hostname[0]);
|
|
|
|
|
name = priv->cur_hostname ?: FALLBACK_HOSTNAME4;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-02-17 15:33:27 +01:00
|
|
|
/* Don't set the hostname if it isn't actually changing */
|
2017-04-23 19:54:39 +02:00
|
|
|
if ((old_hostname = _get_hostname(self)) && (nm_streq(name, old_hostname))) {
|
2017-03-03 12:11:57 +01:00
|
|
|
_LOGT(LOGD_DNS, "set-hostname: hostname already set to '%s' (%s)", name, msg);
|
2017-02-17 15:33:27 +01:00
|
|
|
return;
|
2016-02-22 10:10:15 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-02-17 16:22:30 +01:00
|
|
|
/* Keep track of the last set hostname */
|
2022-03-04 08:10:17 +01:00
|
|
|
nm_strdup_reset(&priv->last_hostname, name);
|
2017-02-17 16:22:30 +01:00
|
|
|
priv->changing_hostname = TRUE;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-03-03 12:11:57 +01:00
|
|
|
_LOGI(LOGD_DNS, "set-hostname: set hostname to '%s' (%s)", name, msg);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-02-22 10:10:15 +01:00
|
|
|
/* Ask NMSettings to update the transient hostname using its
|
2022-02-10 18:23:59 +01:00
|
|
|
* systemd-hostnamed proxy.
|
|
|
|
|
*
|
|
|
|
|
* FIXME(shutdown): an async request must be cancellable, so we are guaranteed
|
|
|
|
|
* to tear down in a reasonable time.*/
|
2017-04-23 00:40:46 +02:00
|
|
|
nm_hostname_manager_set_transient_hostname(priv->hostname_manager,
|
|
|
|
|
name,
|
|
|
|
|
settings_set_hostname_cb,
|
|
|
|
|
g_object_ref(self));
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
}
|
|
|
|
|
|
2020-11-12 08:47:25 +01:00
|
|
|
typedef struct {
|
|
|
|
|
NMDevice *device;
|
|
|
|
|
int priority;
|
|
|
|
|
bool from_dhcp : 1;
|
|
|
|
|
bool from_dns : 1;
|
2021-01-15 09:41:41 +01:00
|
|
|
bool IS_IPv4 : 1;
|
|
|
|
|
bool is_default : 1;
|
2020-11-12 08:47:25 +01:00
|
|
|
} DeviceHostnameInfo;
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
device_hostname_info_compare(gconstpointer a, gconstpointer b)
|
|
|
|
|
{
|
|
|
|
|
const DeviceHostnameInfo *info1 = a;
|
|
|
|
|
const DeviceHostnameInfo *info2 = b;
|
|
|
|
|
|
|
|
|
|
NM_CMP_FIELD(info1, info2, priority);
|
2021-01-15 09:41:41 +01:00
|
|
|
NM_CMP_FIELD_UNSAFE(info2, info1, is_default);
|
2021-06-17 11:35:54 +02:00
|
|
|
NM_CMP_FIELD_UNSAFE(info2, info1, IS_IPv4);
|
2020-11-12 08:47:25 +01:00
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NM_CON_DEFAULT_NOP("hostname.from-dhcp");
|
|
|
|
|
NM_CON_DEFAULT_NOP("hostname.from-dns-lookup");
|
|
|
|
|
NM_CON_DEFAULT_NOP("hostname.only-from-default");
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
|
device_get_hostname_property_boolean(NMDevice *device, const char *name)
|
|
|
|
|
{
|
|
|
|
|
NMSettingHostname *s_hostname;
|
|
|
|
|
char buf[128];
|
|
|
|
|
int value;
|
2021-01-15 09:50:36 +01:00
|
|
|
NMTernary default_value;
|
2020-11-12 08:47:25 +01:00
|
|
|
|
|
|
|
|
nm_assert(NM_IN_STRSET(name,
|
|
|
|
|
NM_SETTING_HOSTNAME_FROM_DHCP,
|
|
|
|
|
NM_SETTING_HOSTNAME_FROM_DNS_LOOKUP,
|
|
|
|
|
NM_SETTING_HOSTNAME_ONLY_FROM_DEFAULT));
|
|
|
|
|
|
|
|
|
|
s_hostname = nm_device_get_applied_setting(device, NM_TYPE_SETTING_HOSTNAME);
|
|
|
|
|
|
|
|
|
|
if (s_hostname) {
|
|
|
|
|
g_object_get(s_hostname, name, &value, NULL);
|
|
|
|
|
if (NM_IN_SET(value, NM_TERNARY_FALSE, NM_TERNARY_TRUE))
|
|
|
|
|
return value;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-15 09:50:36 +01:00
|
|
|
if (nm_streq(name, NM_SETTING_HOSTNAME_ONLY_FROM_DEFAULT))
|
|
|
|
|
default_value = NM_TERNARY_FALSE;
|
|
|
|
|
else
|
|
|
|
|
default_value = NM_TERNARY_TRUE;
|
|
|
|
|
|
2020-11-12 08:47:25 +01:00
|
|
|
return nm_config_data_get_connection_default_int64(NM_CONFIG_GET_DATA,
|
|
|
|
|
nm_sprintf_buf(buf, "hostname.%s", name),
|
|
|
|
|
device,
|
|
|
|
|
NM_TERNARY_FALSE,
|
|
|
|
|
NM_TERNARY_TRUE,
|
2021-01-15 09:50:36 +01:00
|
|
|
default_value);
|
2020-11-12 08:47:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int
|
|
|
|
|
device_get_hostname_priority(NMDevice *device)
|
|
|
|
|
{
|
|
|
|
|
NMSettingHostname *s_hostname;
|
|
|
|
|
int priority;
|
|
|
|
|
|
|
|
|
|
s_hostname = nm_device_get_applied_setting(device, NM_TYPE_SETTING_HOSTNAME);
|
|
|
|
|
if (s_hostname) {
|
|
|
|
|
priority = nm_setting_hostname_get_priority(s_hostname);
|
|
|
|
|
if (priority != 0)
|
|
|
|
|
return priority;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return nm_config_data_get_connection_default_int64(NM_CONFIG_GET_DATA,
|
|
|
|
|
NM_CON_DEFAULT("hostname.priority"),
|
|
|
|
|
device,
|
|
|
|
|
G_MININT,
|
|
|
|
|
G_MAXINT,
|
|
|
|
|
100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static GArray *
|
|
|
|
|
build_device_hostname_infos(NMPolicy *self)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
const CList *tmp_clist;
|
2020-11-12 08:47:25 +01:00
|
|
|
NMActiveConnection *ac;
|
2021-11-09 13:28:54 +01:00
|
|
|
GArray *array = NULL;
|
2020-11-12 08:47:25 +01:00
|
|
|
|
|
|
|
|
nm_manager_for_each_active_connection (priv->manager, ac, tmp_clist) {
|
|
|
|
|
DeviceHostnameInfo *info;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMDevice *device;
|
2020-11-12 08:47:25 +01:00
|
|
|
gboolean only_from_default;
|
2021-01-15 09:41:41 +01:00
|
|
|
gboolean is_default;
|
|
|
|
|
int IS_IPv4;
|
2020-11-12 08:47:25 +01:00
|
|
|
|
|
|
|
|
device = nm_active_connection_get_device(ac);
|
|
|
|
|
if (!device)
|
|
|
|
|
continue;
|
|
|
|
|
|
2024-08-27 10:26:50 +02:00
|
|
|
if (nm_device_managed_type_is_external(device))
|
2022-10-27 19:48:41 +02:00
|
|
|
continue;
|
|
|
|
|
|
2020-11-12 08:47:25 +01:00
|
|
|
only_from_default =
|
|
|
|
|
device_get_hostname_property_boolean(device, NM_SETTING_HOSTNAME_ONLY_FROM_DEFAULT);
|
|
|
|
|
|
2021-01-15 09:41:41 +01:00
|
|
|
for (IS_IPv4 = 1; IS_IPv4 >= 0; IS_IPv4--) {
|
|
|
|
|
is_default = (ac == (IS_IPv4 ? priv->default_ac4 : priv->default_ac6));
|
|
|
|
|
if (only_from_default && !is_default)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!array)
|
|
|
|
|
array = g_array_sized_new(FALSE, FALSE, sizeof(DeviceHostnameInfo), 4);
|
|
|
|
|
|
|
|
|
|
info = nm_g_array_append_new(array, DeviceHostnameInfo);
|
2024-10-04 10:45:56 +02:00
|
|
|
*info = (DeviceHostnameInfo) {
|
2021-01-15 09:41:41 +01:00
|
|
|
.device = device,
|
|
|
|
|
.priority = device_get_hostname_priority(device),
|
|
|
|
|
.from_dhcp =
|
|
|
|
|
device_get_hostname_property_boolean(device, NM_SETTING_HOSTNAME_FROM_DHCP),
|
|
|
|
|
.from_dns =
|
|
|
|
|
device_get_hostname_property_boolean(device,
|
|
|
|
|
NM_SETTING_HOSTNAME_FROM_DNS_LOOKUP),
|
|
|
|
|
.IS_IPv4 = IS_IPv4,
|
|
|
|
|
.is_default = is_default,
|
|
|
|
|
};
|
|
|
|
|
}
|
2020-11-12 08:47:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (array && array->len > 1) {
|
|
|
|
|
const DeviceHostnameInfo *info0;
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
g_array_sort(array, device_hostname_info_compare);
|
|
|
|
|
|
2022-12-01 16:16:51 +01:00
|
|
|
info0 = &nm_g_array_first(array, DeviceHostnameInfo);
|
2020-11-12 08:47:25 +01:00
|
|
|
if (info0->priority < 0) {
|
|
|
|
|
for (i = 1; i < array->len; i++) {
|
2022-09-08 12:05:56 +02:00
|
|
|
const DeviceHostnameInfo *info = &nm_g_array_index(array, DeviceHostnameInfo, i);
|
2020-11-12 08:47:25 +01:00
|
|
|
|
|
|
|
|
if (info->priority > info0->priority) {
|
|
|
|
|
g_array_set_size(array, i);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return array;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
device_dns_lookup_done(NMDevice *device, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMPolicy *self = user_data;
|
|
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_func(device, device_dns_lookup_done, self);
|
|
|
|
|
|
2024-07-31 17:08:43 +02:00
|
|
|
update_system_hostname(self, "lookup finished", FALSE);
|
2020-11-12 08:47:25 +01:00
|
|
|
}
|
|
|
|
|
|
2022-09-07 16:50:02 +02:00
|
|
|
static void
|
|
|
|
|
device_carrier_changed(NMDevice *device, GParamSpec *pspec, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMPolicyPrivate *priv = user_data;
|
|
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
|
|
|
|
gs_free char *msg = NULL;
|
|
|
|
|
|
|
|
|
|
if (nm_device_has_carrier(device)) {
|
|
|
|
|
g_signal_handlers_disconnect_by_func(device, device_carrier_changed, priv);
|
|
|
|
|
msg = g_strdup_printf("device '%s' got carrier", nm_device_get_iface(device));
|
2024-07-31 17:08:43 +02:00
|
|
|
update_system_hostname(self, msg, TRUE);
|
2022-09-07 16:50:02 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-31 17:08:43 +02:00
|
|
|
/*
|
|
|
|
|
* This function evaluates different sources (static configuration, DHCP, DNS, ...)
|
|
|
|
|
* to set the system hostname.
|
|
|
|
|
*
|
|
|
|
|
* When the function needs to perform a blocking action like a DNS resolution, it
|
|
|
|
|
* subscribes to a signal for the completion event, registering a callback that
|
|
|
|
|
* invokes this function again. In the new invocation, any previous DNS result is
|
|
|
|
|
* cached and doesn't need a new resolution.
|
|
|
|
|
*
|
|
|
|
|
* In case no hostname is found when after sources have been evaluated, it schedules
|
|
|
|
|
* a timer to retry later with an interval that is increased at each attempt. When
|
|
|
|
|
* this function is called after something changed (for example, carrier went up, a
|
|
|
|
|
* new address was added), @reset_retry_interval should be set to TRUE so that the
|
|
|
|
|
* next retry will use the smallest interval. In this way, it can quickly adapt to
|
|
|
|
|
* temporary misconfigurations at boot or when the network environment changes.
|
|
|
|
|
*/
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
static void
|
2024-07-31 17:08:43 +02:00
|
|
|
update_system_hostname(NMPolicy *self, const char *msg, gboolean reset_retry_interval)
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
const char *configured_hostname;
|
|
|
|
|
gs_free char *temp_hostname = NULL;
|
|
|
|
|
const char *dhcp_hostname, *p;
|
|
|
|
|
gboolean external_hostname = FALSE;
|
|
|
|
|
NMDhcpConfig *dhcp_config;
|
2020-11-12 08:47:25 +01:00
|
|
|
gs_unref_array GArray *infos = NULL;
|
2021-11-09 13:28:54 +01:00
|
|
|
DeviceHostnameInfo *info;
|
2020-11-12 08:47:25 +01:00
|
|
|
guint i;
|
2021-01-15 09:41:41 +01:00
|
|
|
int addr_family;
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
|
2016-03-29 10:46:07 +02:00
|
|
|
g_return_if_fail(self != NULL);
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
|
2024-07-31 17:08:43 +02:00
|
|
|
if (reset_retry_interval)
|
|
|
|
|
priv->hostname_retry.do_restart = TRUE;
|
|
|
|
|
|
2017-03-03 12:11:57 +01:00
|
|
|
if (priv->hostname_mode == NM_POLICY_HOSTNAME_MODE_NONE) {
|
|
|
|
|
_LOGT(LOGD_DNS, "set-hostname: hostname is unmanaged");
|
2017-03-02 19:18:49 +01:00
|
|
|
return;
|
2017-03-03 12:11:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_LOGT(LOGD_DNS, "set-hostname: updating hostname (%s)", msg);
|
2017-03-02 19:18:49 +01:00
|
|
|
|
2017-02-17 16:22:30 +01:00
|
|
|
/* Check if the hostname was set externally to NM, so that in that case
|
|
|
|
|
* we can avoid to fallback to the one we got when we started.
|
|
|
|
|
* Consider "not specific" hostnames as equal. */
|
|
|
|
|
if ((temp_hostname = _get_hostname(self)) && !nm_streq0(temp_hostname, priv->last_hostname)
|
|
|
|
|
&& (nm_utils_is_specific_hostname(temp_hostname)
|
|
|
|
|
|| nm_utils_is_specific_hostname(priv->last_hostname))) {
|
|
|
|
|
external_hostname = TRUE;
|
2022-07-14 17:10:38 +02:00
|
|
|
_LOGD(LOGD_DNS,
|
2017-03-03 12:11:57 +01:00
|
|
|
"set-hostname: current hostname was changed outside NetworkManager: '%s'",
|
2017-02-17 16:22:30 +01:00
|
|
|
temp_hostname);
|
2017-03-03 18:32:08 +01:00
|
|
|
priv->dhcp_hostname = FALSE;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-23 20:31:31 +02:00
|
|
|
if (!nm_utils_is_specific_hostname(temp_hostname))
|
|
|
|
|
nm_clear_g_free(&temp_hostname);
|
2017-02-17 16:22:30 +01:00
|
|
|
if (!nm_streq0(temp_hostname, priv->orig_hostname)) {
|
|
|
|
|
/* Update original (fallback) hostname */
|
|
|
|
|
g_free(priv->orig_hostname);
|
2017-04-23 20:31:31 +02:00
|
|
|
priv->orig_hostname = g_steal_pointer(&temp_hostname);
|
|
|
|
|
_LOGT(LOGD_DNS,
|
|
|
|
|
"hostname-original: update to %s%s%s",
|
|
|
|
|
NM_PRINT_FMT_QUOTE_STRING(priv->orig_hostname));
|
2017-02-17 16:22:30 +01:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2010-01-27 17:13:35 -08:00
|
|
|
/* Hostname precedence order:
|
|
|
|
|
*
|
2010-10-27 20:22:14 -05:00
|
|
|
* 1) a configured hostname (from settings)
|
2020-11-12 08:47:25 +01:00
|
|
|
* 2) automatic hostname from DHCP of eligible interfaces
|
|
|
|
|
* 3) reverse-DNS lookup of the first address on eligible interfaces
|
|
|
|
|
* 4) the last hostname set outside NM
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
*/
|
|
|
|
|
|
2010-01-27 17:13:35 -08:00
|
|
|
/* Try a persistent hostname first */
|
2022-01-04 18:28:46 +01:00
|
|
|
configured_hostname = nm_hostname_manager_get_static_hostname(priv->hostname_manager);
|
2025-02-24 11:47:25 +01:00
|
|
|
if (configured_hostname && nm_utils_is_not_empty_hostname(configured_hostname)) {
|
2024-07-31 17:08:43 +02:00
|
|
|
_set_hostname(self, configured_hostname, "from system configuration", FALSE);
|
2017-03-03 18:32:08 +01:00
|
|
|
priv->dhcp_hostname = FALSE;
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
return;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-11-12 08:47:25 +01:00
|
|
|
infos = build_device_hostname_infos(self);
|
|
|
|
|
|
|
|
|
|
if (infos && _LOGT_ENABLED(LOGD_DNS)) {
|
|
|
|
|
_LOGT(LOGD_DNS, "device hostname info:");
|
|
|
|
|
for (i = 0; i < infos->len; i++) {
|
2022-09-08 12:05:56 +02:00
|
|
|
info = &nm_g_array_index(infos, DeviceHostnameInfo, i);
|
2020-11-12 08:47:25 +01:00
|
|
|
_LOGT(LOGD_DNS,
|
2021-01-15 09:41:41 +01:00
|
|
|
" - prio:%5d ipv%c%s %s %s dev:%s",
|
2020-11-12 08:47:25 +01:00
|
|
|
info->priority,
|
2021-01-15 09:41:41 +01:00
|
|
|
info->IS_IPv4 ? '4' : '6',
|
|
|
|
|
info->is_default ? " (def)" : " ",
|
|
|
|
|
info->from_dhcp ? "dhcp " : " ",
|
|
|
|
|
info->from_dns ? "dns " : " ",
|
2020-11-12 08:47:25 +01:00
|
|
|
nm_device_get_iface(info->device));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (i = 0; infos && i < infos->len; i++) {
|
2022-09-08 12:05:56 +02:00
|
|
|
info = &nm_g_array_index(infos, DeviceHostnameInfo, i);
|
2021-01-15 09:41:41 +01:00
|
|
|
addr_family = info->IS_IPv4 ? AF_INET : AF_INET6;
|
2020-11-12 08:47:25 +01:00
|
|
|
g_signal_handlers_disconnect_by_func(info->device, device_dns_lookup_done, self);
|
2022-09-07 16:50:02 +02:00
|
|
|
g_signal_handlers_disconnect_by_func(info->device, device_carrier_changed, priv);
|
2021-01-15 09:41:41 +01:00
|
|
|
|
|
|
|
|
if (info->from_dhcp) {
|
|
|
|
|
dhcp_config = nm_device_get_dhcp_config(info->device, addr_family);
|
|
|
|
|
if (dhcp_config) {
|
|
|
|
|
dhcp_hostname =
|
|
|
|
|
nm_dhcp_config_get_option(dhcp_config,
|
|
|
|
|
info->IS_IPv4 ? "host_name" : "fqdn_fqdn");
|
|
|
|
|
if (dhcp_hostname && dhcp_hostname[0]) {
|
|
|
|
|
p = nm_str_skip_leading_spaces(dhcp_hostname);
|
|
|
|
|
if (p[0]) {
|
2024-07-31 17:08:43 +02:00
|
|
|
_set_hostname(self,
|
|
|
|
|
p,
|
|
|
|
|
info->IS_IPv4 ? "from DHCPv4" : "from DHCPv6",
|
|
|
|
|
FALSE);
|
2021-01-15 09:41:41 +01:00
|
|
|
priv->dhcp_hostname = TRUE;
|
|
|
|
|
return;
|
2020-11-12 08:47:25 +01:00
|
|
|
}
|
2021-01-15 09:41:41 +01:00
|
|
|
_LOGW(LOGD_DNS,
|
|
|
|
|
"set-hostname: DHCPv%c-provided hostname '%s' looks invalid; "
|
|
|
|
|
"ignoring it",
|
|
|
|
|
nm_utils_addr_family_to_char(addr_family),
|
|
|
|
|
dhcp_hostname);
|
2010-01-27 17:13:35 -08:00
|
|
|
}
|
2010-06-08 10:40:08 -07:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-11-12 08:47:25 +01:00
|
|
|
if (priv->hostname_mode != NM_POLICY_HOSTNAME_MODE_DHCP) {
|
2021-01-15 09:41:41 +01:00
|
|
|
if (info->from_dns) {
|
2022-09-07 16:50:02 +02:00
|
|
|
const char *result = NULL;
|
|
|
|
|
gboolean wait = FALSE;
|
2021-01-15 09:41:41 +01:00
|
|
|
|
2022-09-07 16:50:02 +02:00
|
|
|
if (nm_device_has_carrier(info->device)) {
|
|
|
|
|
result =
|
|
|
|
|
nm_device_get_hostname_from_dns_lookup(info->device, addr_family, &wait);
|
|
|
|
|
} else {
|
|
|
|
|
g_signal_connect(info->device,
|
|
|
|
|
"notify::" NM_DEVICE_CARRIER,
|
|
|
|
|
G_CALLBACK(device_carrier_changed),
|
|
|
|
|
priv);
|
|
|
|
|
}
|
2021-01-15 09:41:41 +01:00
|
|
|
if (result) {
|
2024-07-31 17:08:43 +02:00
|
|
|
_set_hostname(self, result, "from address lookup", FALSE);
|
2021-01-15 09:41:41 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (wait) {
|
|
|
|
|
g_signal_connect(info->device,
|
|
|
|
|
NM_DEVICE_DNS_LOOKUP_DONE,
|
2021-08-05 09:06:12 +02:00
|
|
|
G_CALLBACK(device_dns_lookup_done),
|
2021-01-15 09:41:41 +01:00
|
|
|
self);
|
|
|
|
|
return;
|
2010-06-08 10:40:08 -07:00
|
|
|
}
|
2010-01-27 17:13:35 -08:00
|
|
|
}
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
}
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-02-17 16:22:30 +01:00
|
|
|
/* If an hostname was set outside NetworkManager keep it */
|
2024-07-31 17:08:43 +02:00
|
|
|
if (external_hostname) {
|
|
|
|
|
hostname_retry_schedule(self);
|
2017-02-17 16:22:30 +01:00
|
|
|
return;
|
2024-07-31 17:08:43 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-03-03 18:32:08 +01:00
|
|
|
if (priv->hostname_mode == NM_POLICY_HOSTNAME_MODE_DHCP) {
|
|
|
|
|
/* In dhcp hostname-mode, the hostname is updated only if it comes from
|
|
|
|
|
* a DHCP host-name option: if last set was from a host-name option and
|
|
|
|
|
* we are here than that connection is gone (with its host-name option),
|
|
|
|
|
* so reset the hostname to the previous value
|
|
|
|
|
*/
|
|
|
|
|
if (priv->dhcp_hostname) {
|
2024-07-31 17:08:43 +02:00
|
|
|
_set_hostname(self, priv->orig_hostname, "reset dhcp hostname", TRUE);
|
2017-03-03 18:32:08 +01:00
|
|
|
priv->dhcp_hostname = FALSE;
|
|
|
|
|
}
|
2017-03-02 19:18:49 +01:00
|
|
|
return;
|
2017-03-03 18:32:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
priv->dhcp_hostname = FALSE;
|
2017-03-02 19:18:49 +01:00
|
|
|
|
2017-02-17 16:22:30 +01:00
|
|
|
/* If no automatically-configured hostname, try using the last hostname
|
|
|
|
|
* set externally to NM
|
2010-01-27 17:13:35 -08:00
|
|
|
*/
|
2013-08-22 10:10:17 -04:00
|
|
|
if (priv->orig_hostname) {
|
2024-07-31 17:08:43 +02:00
|
|
|
_set_hostname(self, priv->orig_hostname, "from system startup", TRUE);
|
2010-01-27 17:13:35 -08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-31 17:08:43 +02:00
|
|
|
_set_hostname(self, NULL, "no hostname found", TRUE);
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-03-29 10:46:07 +02:00
|
|
|
update_default_ac(NMPolicy *self, int addr_family, NMActiveConnection *best)
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
const CList *tmp_list;
|
2017-11-23 21:30:09 +01:00
|
|
|
NMActiveConnection *ac;
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
|
2012-05-29 10:01:07 -05:00
|
|
|
/* Clear the 'default[6]' flag on all active connections that aren't the new
|
|
|
|
|
* default active connection. We'll set the new default after; this ensures
|
|
|
|
|
* we don't ever have two marked 'default[6]' simultaneously.
|
|
|
|
|
*/
|
2017-11-23 21:30:09 +01:00
|
|
|
nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) {
|
|
|
|
|
if (ac != best)
|
2017-11-23 21:53:04 +01:00
|
|
|
nm_active_connection_set_default(ac, addr_family, FALSE);
|
2012-05-29 10:01:07 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Mark new default active connection */
|
|
|
|
|
if (best)
|
2017-11-23 21:53:04 +01:00
|
|
|
nm_active_connection_set_default(best, addr_family, TRUE);
|
2012-05-29 10:01:07 -05:00
|
|
|
}
|
|
|
|
|
|
2021-08-06 15:17:05 +02:00
|
|
|
static const NML3ConfigData *
|
2021-11-09 13:28:54 +01:00
|
|
|
get_best_ip_config(NMPolicy *self,
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
int addr_family,
|
2021-11-09 13:28:54 +01:00
|
|
|
const char **out_ip_iface,
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
NMActiveConnection **out_ac,
|
2021-11-09 13:28:54 +01:00
|
|
|
NMDevice **out_device,
|
|
|
|
|
NMVpnConnection **out_vpn)
|
2012-05-29 10:01:07 -05:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2021-08-06 15:17:05 +02:00
|
|
|
const NML3ConfigData *l3cd_best = NULL;
|
2021-11-09 13:28:54 +01:00
|
|
|
const CList *tmp_list;
|
|
|
|
|
NMActiveConnection *ac;
|
2021-08-06 15:17:05 +02:00
|
|
|
guint64 best_metric = G_MAXUINT64;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMVpnConnection *best_vpn = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
nm_assert(NM_IN_SET(addr_family, AF_INET, AF_INET6));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-23 21:30:09 +01:00
|
|
|
nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) {
|
2021-08-06 15:17:05 +02:00
|
|
|
const NML3ConfigData *l3cd;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMVpnConnection *candidate;
|
2021-08-06 15:17:05 +02:00
|
|
|
NMVpnConnectionState vpn_state;
|
2021-11-09 13:28:54 +01:00
|
|
|
const NMPObject *obj;
|
2021-08-06 15:17:05 +02:00
|
|
|
guint32 metric;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-23 21:30:09 +01:00
|
|
|
if (!NM_IS_VPN_CONNECTION(ac))
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-23 21:30:09 +01:00
|
|
|
candidate = NM_VPN_CONNECTION(ac);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
vpn_state = nm_vpn_connection_get_vpn_state(candidate);
|
|
|
|
|
if (vpn_state != NM_VPN_CONNECTION_STATE_ACTIVATED)
|
|
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2021-08-06 15:17:05 +02:00
|
|
|
l3cd = nm_vpn_connection_get_l3cd(candidate);
|
|
|
|
|
if (!l3cd)
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2021-08-06 15:17:05 +02:00
|
|
|
obj = nm_l3_config_data_get_best_default_route(l3cd, addr_family);
|
2018-06-28 17:16:15 +02:00
|
|
|
if (!obj)
|
|
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-06-28 17:16:15 +02:00
|
|
|
metric = NMP_OBJECT_CAST_IPX_ROUTE(obj)->rx.metric;
|
|
|
|
|
if (metric <= best_metric) {
|
|
|
|
|
best_metric = metric;
|
2021-08-06 15:17:05 +02:00
|
|
|
l3cd_best = l3cd;
|
2018-06-28 17:16:15 +02:00
|
|
|
best_vpn = candidate;
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
}
|
2018-06-28 17:16:15 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-06-28 17:16:15 +02:00
|
|
|
if (best_metric != G_MAXUINT64) {
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
NM_SET_OUT(out_device, NULL);
|
2018-06-28 17:16:15 +02:00
|
|
|
NM_SET_OUT(out_vpn, best_vpn);
|
|
|
|
|
NM_SET_OUT(out_ac, NM_ACTIVE_CONNECTION(best_vpn));
|
|
|
|
|
NM_SET_OUT(out_ip_iface, nm_vpn_connection_get_ip_iface(best_vpn, TRUE));
|
2021-08-06 15:17:05 +02:00
|
|
|
return l3cd_best;
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
ac = get_best_active_connection(self, addr_family, TRUE);
|
|
|
|
|
if (ac) {
|
|
|
|
|
NMDevice *device = nm_active_connection_get_device(ac);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2021-08-06 15:17:05 +02:00
|
|
|
nm_assert(NM_IS_DEVICE(device));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
NM_SET_OUT(out_device, device);
|
|
|
|
|
NM_SET_OUT(out_vpn, NULL);
|
|
|
|
|
NM_SET_OUT(out_ac, ac);
|
|
|
|
|
NM_SET_OUT(out_ip_iface, nm_device_get_ip_iface(device));
|
2021-08-06 15:17:05 +02:00
|
|
|
return nm_device_get_l3cd(device, TRUE);
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
NM_SET_OUT(out_device, NULL);
|
|
|
|
|
NM_SET_OUT(out_vpn, NULL);
|
|
|
|
|
NM_SET_OUT(out_ac, NULL);
|
|
|
|
|
NM_SET_OUT(out_ip_iface, NULL);
|
|
|
|
|
return NULL;
|
2012-05-29 10:01:07 -05:00
|
|
|
}
|
2008-10-10 Dan Williams <dcbw@redhat.com>
Rework default route handling to consolidate decisions in the policy,
and to take active VPN connections into account when changing the default
route (bgo #545912)
* src/NetworkManager.c
- (main): pass the vpn_manager to the policy so it knows about active
VPN connections; clean up the named manager which wasn't done before
* src/NetworkManagerPolicy.c
src/NetworkManagerPolicy.h
- (nm_policy_new): get a clue about the vpn_manager
- (update_default_route): remove, fold into update_routing_and_dns()
- (update_routing_and_dns): handle active VPN connections too; an
active VPN connection becomes the default route if it does not have
server-specified or user-specified custom routes. Otherwise, the
best active device gets the default route
- (vpn_connection_activated, vpn_connection_deactivated, nm_policy_new,
nm_policy_destroy): track VPN connection activation and deactivation
and update the default route when appropriate
* src/NetworkManagerSystem.c
src/NetworkManagerSystem.h
- (nm_system_vpn_device_unset_from_ip4_config): remove, put functionality
in the VPN connection itself
- (nm_system_vpn_device_set_from_ip4_config,
nm_system_device_set_from_ip4_config): merge together to make
nm_system_apply_ip4_config()
- (add_vpn_gateway_route): add a route to the VPN's external gateway
via the parent device
- (nm_system_apply_ip4_config): simplify
- (add_ip4_route_to_gateway): new function; add a direct route to the
gateway if needed
- (nm_system_device_replace_default_ip4_route): simplify, break gateway
route stuff out into add_ip4_route_to_gateway() for clarity
* src/nm-device.c
- (nm_device_set_ip4_config): update for nm_system_apply_ip4_config()
* src/vpn-manager/nm-vpn-connection.c
src/vpn-manager/nm-vpn-connection.h
- (nm_vpn_connection_get_ip4_config, nm_vpn_connection_get_ip_iface,
nm_vpn_connection_get_parent_device): add
- (nm_vpn_connection_ip4_config_get): make the requirement of a tunnel
device explicit
- (connection_state_changed): update the named manager now that
nm_system_vpn_device_unset_from_ip4_config() is gone; do something
useful on errors
* src/vpn-manager/nm-vpn-manager.c
src/vpn-manager/nm-vpn-manager.h
- Add a 'connection-activated' signal
- (nm_vpn_manager_get_active_connections): new function; mainly for the
policy to find out about active VPN connections
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4167 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-10-10 23:05:45 +00:00
|
|
|
|
2012-05-29 10:01:07 -05:00
|
|
|
static void
|
2016-03-29 10:46:07 +02:00
|
|
|
update_ip4_routing(NMPolicy *self, gboolean force_update)
|
2012-05-29 10:01:07 -05:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
NMDevice *best = NULL;
|
|
|
|
|
NMVpnConnection *vpn = NULL;
|
2012-05-29 10:01:07 -05:00
|
|
|
NMActiveConnection *best_ac = NULL;
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *ip_iface = NULL;
|
2008-03-07 Dan Williams <dcbw@redhat.com>
First pass of multiple active device support. Expect bugs.
* src/nm-ip4-config.c
src/nm-ip4-config.h
- (nm_ip4_config_get_secondary, nm_ip4_config_set_secondary): remove;
there are better ways to do this in the named manager
* src/nm-device.c
src/nm-device.h
- (nm_device_can_activate): return whether the device can activate a
connection right now; taking into account things like carrier state
and rfkill state
- (nm_device_get_best_auto_connection): renamed from
nm_device_get_best_connection
- (real_act_stage4_get_ip4_config): MTU stuff is now handled in the
device subclasses themselves, so that each device can override the
MTU from it's NMSetting subclass if needed
- (nm_device_set_ip4_config): set MTU when setting up routes and stuff
in NetworkManagerSystem.c, not here
* src/named-manager/nm-named-manager.c
src/named-manager/nm-named-manager.h
- (nm_named_manager_name_owner_changed,
nm_named_manager_dbus_connection_changed): fix for changes to
rewrite_resolv_conf()
- (compute_nameservers): don't need the NMNamedManager at all, remove
from parameter list
- (merge_one_ip4_config): new function; merge ip4 configs together
- (rewrite_resolv_conf): write out resolv.conf from all the stored
ip4 configs; the VPN config takes precedence, then the best
device config, then the rest of the configs
- (get_domain_for_config): take the NMNamedManager as an argument
to check whether the config is the VPN config
- (add_ip4_config_to_named): fixups for removal of the 'secondary'
attribute from ip4 configs
- (add_all_ip4_configs_to_named): add all the configs in priority order
- (remove_ip4_config_from_named): fix for changes to
get_domain_for_config()
- (nm_named_manager_add_ip4_config): assign the config to the right slot
based on its type; callers must pass in the type now
- (get_last_default_domain): remove, unused
- (nm_named_manager_remove_ip4_config): handle config slots correctly
* src/nm-device-802-11-wireless.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): handle MTU override
* src/nm-device-802-3-ethernet.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): new function; handle MTU override
* src/vpn-manager/nm-vpn-connection.c
- (nm_vpn_connection_ip4_config_get): don't need to set the 'secondary'
attribute on the ip4 config
* src/NetworkManagerPolicy.c
- (nm_policy_auto_get_best_device): remove
- (nm_policy_device_change_check): remove
- (update_default_route): new function; set the default route via
the specified device
- (get_device_priority): new function; return the priority number of
a device type WRT which one should have the default route. Order is
(highest to lowest) wired, wireless, GSM, CDMA.
- (update_routing_and_dns): new function; determine which device should
have the default route, then update the routing table and DNS
- (maybe_auto_activate_device): new function; if a device is now
available for activation, find out what connection it would like to
activate and do it
- (schedule_activate_check): new function; if a device can be activated
now, schedule the activation. Each device may have only one
pending activation at a given time.
- (device_state_changed): if activation was canceled, try again,
possibly with another connection; if the device was activated,
update routing and DNS; if the device was deactivated, try again
with another connection
- (device_carrier_changed): if there is no carrier, deactivate the
device; otherwise schedule an activation check for the device
- (wireless_networks_changed): schedule an activation check for the
device
- (device_added): keep track of the signal handler IDs so they can
be removed when the device goes away
- (device_removed): remove any signal handlers that might be attached
to the device; update routing and DNS
- (schedule_activate_all): new function
- (connections_added, connection_added, connection_updated): when
connections change, schedule all devices for an activation check
- (connection_removed): when a device is deactivated because its
connection was removed, schedule another activation check for it
- (nm_policy_destroy): destroy pending activations and disconnect
all device signal handlers
* src/nm-manager.c
- (nm_manager_activate_device): if the device was already actived,
deactivate it
- (deactivate_old_device): remove
- (connection_added_default_handler, impl_manager_activate_device):
don't deactivate other devices when activating this one
* src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerSuSE.c
src/backends/NetworkManagerDebian.c
- (nm_system_get_mtu): remove; MTU should be provided through the
distro's system settings service plugin instead
- (nm_system_device_add_default_route_via_device): remove
- (nm_system_device_add_default_route_via_device_with_iface): remove
- (nm_system_device_replace_default_route): new function; call
generic implementation
* src/backends/NetworkManagerGeneric.c
src/backends/NetworkManagerGeneric.h
- (nm_generic_device_add_default_route_via_device,
nm_generic_device_add_default_route_via_device_with_iface): remove
- (nm_generic_device_replace_default_route): replace the default route
with the given route via some gateway
* src/NetworkManagerSystem.c
src/NetworkManagerSystem.h
- (nm_system_device_set_from_ip4_config): let the policy handle updates
to routing and DNS; but set the MTU here
- (nm_system_vpn_device_set_from_ip4_config): set the route with the
ip_iface of the active device; use the standard MTU setting function
- (nm_system_set_mtu): remove
- (nm_system_device_set_mtu): consolidate MTU setting code in one place
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3391 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-07 19:41:32 +00:00
|
|
|
|
2012-05-29 10:01:07 -05:00
|
|
|
/* Note that we might have an IPv4 VPN tunneled over an IPv6-only device,
|
|
|
|
|
* so we can get (vpn != NULL && best == NULL).
|
2008-06-10 02:06:42 +00:00
|
|
|
*/
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
if (!get_best_ip_config(self, AF_INET, &ip_iface, &best_ac, &best, &vpn)) {
|
2018-06-28 18:05:05 +02:00
|
|
|
if (nm_clear_g_object(&priv->default_ac4)) {
|
|
|
|
|
_LOGt(LOGD_DNS, "set-default-ac-4: %p", NULL);
|
|
|
|
|
_notify(self, PROP_DEFAULT_IP4_AC);
|
2017-09-06 13:39:28 +02:00
|
|
|
}
|
2012-05-29 10:01:07 -05:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
g_assert((best || vpn) && best_ac);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
if (!force_update && best_ac && best_ac == priv->default_ac4)
|
2012-05-29 10:01:07 -05:00
|
|
|
return;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-10-23 17:04:49 -05:00
|
|
|
if (best) {
|
2021-11-09 13:28:54 +01:00
|
|
|
const CList *tmp_list;
|
2021-08-06 15:17:05 +02:00
|
|
|
NMActiveConnection *ac;
|
|
|
|
|
|
2017-11-23 21:30:09 +01:00
|
|
|
nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) {
|
2021-08-06 15:17:05 +02:00
|
|
|
if (NM_IS_VPN_CONNECTION(ac) && !nm_active_connection_get_device(ac))
|
2017-11-23 21:30:09 +01:00
|
|
|
nm_active_connection_set_device(ac, best);
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
2014-10-23 17:04:49 -05:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-23 21:53:04 +01:00
|
|
|
update_default_ac(self, AF_INET, best_ac);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
if (!nm_g_object_ref_set(&priv->default_ac4, best_ac))
|
2013-07-15 20:17:25 +02:00
|
|
|
return;
|
2018-06-28 18:05:05 +02:00
|
|
|
_LOGt(LOGD_DNS, "set-default-ac-4: %p", priv->default_ac4);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-03-03 09:20:18 +01:00
|
|
|
_LOGI(LOGD_CORE,
|
|
|
|
|
"set '%s' (%s) as default for IPv4 routing and DNS",
|
2017-09-06 13:39:28 +02:00
|
|
|
nm_connection_get_id(nm_active_connection_get_applied_connection(best_ac)),
|
|
|
|
|
ip_iface);
|
2018-06-28 18:05:05 +02:00
|
|
|
_notify(self, PROP_DEFAULT_IP4_AC);
|
2010-04-23 22:11:22 -07:00
|
|
|
}
|
|
|
|
|
|
2016-10-31 23:31:14 +01:00
|
|
|
static void
|
|
|
|
|
update_ip6_prefix_delegation(NMPolicy *self)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
NMDevice *device;
|
2017-11-23 21:30:09 +01:00
|
|
|
NMActiveConnection *ac;
|
2021-11-09 13:28:54 +01:00
|
|
|
const CList *tmp_list;
|
2016-10-31 23:31:14 +01:00
|
|
|
|
|
|
|
|
/* There's new default IPv6 connection, try to get a prefix for everyone. */
|
2017-11-23 21:30:09 +01:00
|
|
|
nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) {
|
|
|
|
|
device = nm_active_connection_get_device(ac);
|
2016-10-31 23:31:14 +01:00
|
|
|
if (device && nm_device_needs_ip6_subnet(device))
|
2018-06-28 18:05:05 +02:00
|
|
|
ip6_subnet_from_device(self, get_default_device(self, AF_INET6), device);
|
2016-10-31 23:31:14 +01:00
|
|
|
}
|
2012-05-29 10:01:07 -05:00
|
|
|
}
|
2010-04-23 22:11:22 -07:00
|
|
|
|
2012-05-29 10:01:07 -05:00
|
|
|
static void
|
2016-03-29 10:46:07 +02:00
|
|
|
update_ip6_routing(NMPolicy *self, gboolean force_update)
|
2012-05-29 10:01:07 -05:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
NMDevice *best = NULL;
|
|
|
|
|
NMVpnConnection *vpn = NULL;
|
2012-05-29 10:01:07 -05:00
|
|
|
NMActiveConnection *best_ac = NULL;
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *ip_iface = NULL;
|
2010-04-23 22:11:22 -07:00
|
|
|
|
2012-05-29 10:01:07 -05:00
|
|
|
/* Note that we might have an IPv6 VPN tunneled over an IPv4-only device,
|
|
|
|
|
* so we can get (vpn != NULL && best == NULL).
|
2010-04-23 22:11:22 -07:00
|
|
|
*/
|
core: rework handling of default-routes and drop NMDefaultRouteManager
Remove NMDefaultRouteManager. Instead, add the default-route to the
NMIP4Config/NMIP6Config instance.
This basically reverts commit e8824f6a5205ffcf761abd3e0897a22b254c7797.
We added NMDefaultRouteManager because we used the corresponding to `ip
route replace` when configuring routes. That would replace default-routes
on other interfaces so we needed a central manager to coordinate routes.
Now, we use the corresponding of `ip route append` to configure routes,
and each interface can configure routes indepdentently.
In NMDevice, when creating the default-route, ignore @auto_method for
external devices. We shall not touch these devices.
Especially the code in NMPolicy regarding selection of the best-device
seems wrong. It probably needs further adjustments in the future.
Especially get_best_ip_config() should be replaced, because this
distinction VPN vs. devices seems wrong to me.
Thereby, remove the @ignore_never_default argument. It was added by
commit bb750260045239ab85574366bae8102eff8058cc, I don't think it's
needed anymore.
This brings another change. Now that we track default-routes in
NMIP4Config/NMIP6Config, they are also exposed on D-Bus like regular
routes. I think that makes sense, but it is a change in behavior, as
previously such routes were not exposed there.
2017-08-30 11:46:42 +02:00
|
|
|
if (!get_best_ip_config(self, AF_INET6, &ip_iface, &best_ac, &best, &vpn)) {
|
2018-06-28 18:05:05 +02:00
|
|
|
if (nm_clear_g_object(&priv->default_ac6)) {
|
|
|
|
|
_LOGt(LOGD_DNS, "set-default-ac-6: %p", NULL);
|
|
|
|
|
_notify(self, PROP_DEFAULT_IP6_AC);
|
2017-09-06 13:39:28 +02:00
|
|
|
}
|
2012-05-29 10:01:07 -05:00
|
|
|
return;
|
2010-04-23 22:11:22 -07:00
|
|
|
}
|
2012-05-29 10:01:07 -05:00
|
|
|
g_assert((best || vpn) && best_ac);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
if (!force_update && best_ac && best_ac == priv->default_ac6)
|
2012-05-29 10:01:07 -05:00
|
|
|
return;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-10-23 17:04:49 -05:00
|
|
|
if (best) {
|
2021-11-09 13:28:54 +01:00
|
|
|
const CList *tmp_list;
|
2021-08-06 15:17:05 +02:00
|
|
|
NMActiveConnection *ac;
|
|
|
|
|
|
2017-11-23 21:30:09 +01:00
|
|
|
nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) {
|
2021-08-06 15:17:05 +02:00
|
|
|
if (NM_IS_VPN_CONNECTION(ac) && !nm_active_connection_get_device(ac))
|
2017-11-23 21:30:09 +01:00
|
|
|
nm_active_connection_set_device(ac, best);
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
2014-10-23 17:04:49 -05:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-23 21:53:04 +01:00
|
|
|
update_default_ac(self, AF_INET6, best_ac);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
if (!nm_g_object_ref_set(&priv->default_ac6, best_ac))
|
2013-07-15 20:17:25 +02:00
|
|
|
return;
|
2018-06-28 18:05:05 +02:00
|
|
|
_LOGt(LOGD_DNS, "set-default-ac-6: %p", priv->default_ac6);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-10-31 23:31:14 +01:00
|
|
|
update_ip6_prefix_delegation(self);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-03-03 09:20:18 +01:00
|
|
|
_LOGI(LOGD_CORE,
|
|
|
|
|
"set '%s' (%s) as default for IPv6 routing and DNS",
|
2017-09-06 13:39:28 +02:00
|
|
|
nm_connection_get_id(nm_active_connection_get_applied_connection(best_ac)),
|
|
|
|
|
ip_iface);
|
2018-06-28 18:05:05 +02:00
|
|
|
_notify(self, PROP_DEFAULT_IP6_AC);
|
2010-04-23 16:37:45 -07:00
|
|
|
}
|
|
|
|
|
|
2017-11-08 13:44:28 +01:00
|
|
|
static void
|
2020-03-17 10:52:29 +01:00
|
|
|
update_ip_dns(NMPolicy *self, int addr_family, NMDevice *changed_device)
|
2017-11-08 13:44:28 +01:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2021-08-06 15:17:05 +02:00
|
|
|
const NML3ConfigData *l3cd;
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *ip_iface = NULL;
|
|
|
|
|
NMVpnConnection *vpn = NULL;
|
|
|
|
|
NMDevice *device = NULL;
|
2017-11-08 13:44:28 +01:00
|
|
|
|
|
|
|
|
nm_assert_addr_family(addr_family);
|
|
|
|
|
|
2021-08-06 15:17:05 +02:00
|
|
|
l3cd = get_best_ip_config(self, addr_family, &ip_iface, NULL, &device, &vpn);
|
|
|
|
|
if (l3cd) {
|
|
|
|
|
NMDnsIPConfigType ip_config_type;
|
|
|
|
|
|
|
|
|
|
nm_assert(!device || NM_IS_DEVICE(device));
|
|
|
|
|
nm_assert(!vpn || NM_IS_VPN_CONNECTION(vpn));
|
|
|
|
|
nm_assert((!!device) != (!!vpn));
|
|
|
|
|
|
2017-11-08 13:44:28 +01:00
|
|
|
/* Tell the DNS manager this config is preferred by re-adding it with
|
|
|
|
|
* a different IP config type.
|
|
|
|
|
*/
|
2024-08-27 10:26:50 +02:00
|
|
|
if (device && nm_device_managed_type_is_external(device))
|
2021-08-06 15:17:05 +02:00
|
|
|
ip_config_type = NM_DNS_IP_CONFIG_TYPE_REMOVED;
|
|
|
|
|
else if (vpn || (device && nm_device_is_vpn(device)))
|
|
|
|
|
ip_config_type = NM_DNS_IP_CONFIG_TYPE_VPN;
|
|
|
|
|
else
|
|
|
|
|
ip_config_type = NM_DNS_IP_CONFIG_TYPE_BEST_DEVICE;
|
|
|
|
|
|
|
|
|
|
nm_dns_manager_set_ip_config(NM_POLICY_GET_PRIVATE(self)->dns_manager,
|
|
|
|
|
addr_family,
|
|
|
|
|
((gconstpointer) device) ?: ((gconstpointer) vpn),
|
|
|
|
|
l3cd,
|
|
|
|
|
ip_config_type,
|
|
|
|
|
TRUE);
|
2017-11-08 13:44:28 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-17 10:52:29 +01:00
|
|
|
if (addr_family == AF_INET6) {
|
|
|
|
|
NMActiveConnection *ac;
|
2021-11-09 13:28:54 +01:00
|
|
|
const CList *tmp_list;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-03-17 10:52:29 +01:00
|
|
|
/* Tell devices needing a subnet about the new DNS configuration */
|
|
|
|
|
nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) {
|
|
|
|
|
device = nm_active_connection_get_device(ac);
|
|
|
|
|
if (device && device != changed_device && nm_device_needs_ip6_subnet(device))
|
|
|
|
|
nm_device_copy_ip6_dns_config(device, get_default_device(self, AF_INET6));
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-11-08 13:44:28 +01:00
|
|
|
}
|
|
|
|
|
|
2010-04-23 16:37:45 -07:00
|
|
|
static void
|
2020-03-17 10:52:29 +01:00
|
|
|
update_routing_and_dns(NMPolicy *self, gboolean force_update, NMDevice *changed_device)
|
2010-04-23 16:37:45 -07:00
|
|
|
{
|
2016-03-29 10:46:07 +02:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2012-05-29 10:01:07 -05:00
|
|
|
|
2013-12-19 11:05:43 -05:00
|
|
|
nm_dns_manager_begin_updates(priv->dns_manager, __func__);
|
2012-05-29 10:01:07 -05:00
|
|
|
|
2020-03-17 10:52:29 +01:00
|
|
|
update_ip_dns(self, AF_INET, changed_device);
|
|
|
|
|
update_ip_dns(self, AF_INET6, changed_device);
|
2012-05-29 10:01:07 -05:00
|
|
|
|
2016-03-29 10:46:07 +02:00
|
|
|
update_ip4_routing(self, force_update);
|
|
|
|
|
update_ip6_routing(self, force_update);
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
|
2010-04-23 16:37:45 -07:00
|
|
|
/* Update the system hostname */
|
2024-07-31 17:08:43 +02:00
|
|
|
update_system_hostname(self, "routing and dns", FALSE);
|
2012-05-29 10:01:07 -05:00
|
|
|
|
2013-12-19 11:05:43 -05:00
|
|
|
nm_dns_manager_end_updates(priv->dns_manager, __func__);
|
2004-07-15 Dan Williams <dcbw@redhat.com>
* src/Makefile.am
- Turn on warnings
* src/NetworkManager.c
- nm_create_device_and_add_to_list(): call nm_device_deactivate() rather
that doing the deactivation ourselves
- Cancel an pending actions on a device if its being removed
- Break up link state checking a bit, make non-active wireless cards
deactivated to save power
- Remove unused variables
* src/NetworkManager.h
- Add support for "pending" device
* src/NetworkManagerAP.h
src/NetworkManagerAP.c
- Add support for determining whether and AP has encryption enabled or not
- AP address is now "struct ether_addr" rather than a string
* src/NetworkManagerDbus.h
src/NetworkManagerDbus.c
- Add signal NeedKeyForNetwork, method SetKeyForNetwork (testing only)
- Changes for AP address from struct ether_addr->string
* src/NetworkManagerDevice.h
src/NetworkManagerDevice.c
- Remove unused variables, fix warnings
- Add support for Pending Actions (things that block a device from being "active"
until they are completed).
- First pending action: Get a WEP key from the user
- Add nm_device_is_wire[d|less](), rename nm_device_is_wireless()
- Clean up explicit testing of dev->iface_type to use nm_device_is_wireless()
- Update wireless link checking to try to determine if the AP we are associated
with is correct, but the WEP key we are using is just wrong. If its wrong,
trigger the GetUserKey pending action on the device
- If dhclient can't get an IP address, it brings the device down. Bring it back
up in that case, otherwise we can't scan or link-check on it
- Add IP address change notifications at appropriate points (still needs some work)
- Add nm_device_need_ap_switch(), checks whether we need to switch access points or not
* src/NetworkManagerPolicy.h
src/NetworkManagerPolicy.c
- Split out "best" access point determiniation into separate function
- Make device activation 2-stage: first the device is pending, then
in the next iteration through it becomes "active" unless it has
pending actions
* src/NetworkManagerUtils.h
src/NetworkManagerUtils.c
- Clean up unused variables and warnings
- Wrap our debug macros in {} to prevent possible confusion
* src/NetworkManagerWireless.c
- Forgot to return current best priority, which lead to last available AP always
being chosen no matter what its priority was. Corrected.
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@15 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2004-07-15 16:51:48 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-22 13:06:51 -04:00
|
|
|
static void
|
2018-06-28 18:05:05 +02:00
|
|
|
check_activating_active_connections(NMPolicy *self)
|
2013-08-22 13:06:51 -04:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2018-06-28 18:05:05 +02:00
|
|
|
NMActiveConnection *best4, *best6 = NULL;
|
2013-08-22 13:06:51 -04:00
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
best4 = get_best_active_connection(self, AF_INET, FALSE);
|
|
|
|
|
best6 = get_best_active_connection(self, AF_INET6, FALSE);
|
2013-08-22 13:06:51 -04:00
|
|
|
|
2017-09-06 15:41:12 +02:00
|
|
|
g_object_freeze_notify(G_OBJECT(self));
|
2013-08-22 13:06:51 -04:00
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
if (nm_g_object_ref_set(&priv->activating_ac4, best4)) {
|
|
|
|
|
_LOGt(LOGD_DNS, "set-activating-ac-4: %p", priv->activating_ac4);
|
|
|
|
|
_notify(self, PROP_ACTIVATING_IP4_AC);
|
2013-08-22 13:06:51 -04:00
|
|
|
}
|
2018-06-28 18:05:05 +02:00
|
|
|
if (nm_g_object_ref_set(&priv->activating_ac6, best6)) {
|
|
|
|
|
_LOGt(LOGD_DNS, "set-activating-ac-6: %p", priv->activating_ac6);
|
|
|
|
|
_notify(self, PROP_ACTIVATING_IP6_AC);
|
2013-08-22 13:06:51 -04:00
|
|
|
}
|
|
|
|
|
|
2017-09-06 15:41:12 +02:00
|
|
|
g_object_thaw_notify(G_OBJECT(self));
|
2013-08-22 13:06:51 -04:00
|
|
|
}
|
|
|
|
|
|
2017-09-25 22:20:47 +02:00
|
|
|
static void
|
|
|
|
|
pending_ac_gone(gpointer data, GObject *where_the_object_was)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = NM_POLICY(data);
|
2017-09-25 22:20:47 +02:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
|
|
|
|
|
/* Active connections should reach the DEACTIVATED state
|
|
|
|
|
* before disappearing. */
|
|
|
|
|
nm_assert_not_reached();
|
|
|
|
|
|
|
|
|
|
if (g_hash_table_remove(priv->pending_active_connections, where_the_object_was))
|
|
|
|
|
g_object_unref(self);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pending_ac_state_changed(NMActiveConnection *ac, guint state, guint reason, NMPolicy *self)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2017-09-25 22:20:47 +02:00
|
|
|
NMSettingsConnection *con;
|
|
|
|
|
|
|
|
|
|
if (state >= NM_ACTIVE_CONNECTION_STATE_DEACTIVATING) {
|
|
|
|
|
/* The AC is being deactivated before the device had a chance
|
|
|
|
|
* to move to PREPARE. Schedule a new auto-activation on the
|
|
|
|
|
* device, but block the current connection to avoid an activation
|
|
|
|
|
* loop.
|
|
|
|
|
*/
|
2023-03-28 23:13:08 +02:00
|
|
|
if (reason != NM_ACTIVE_CONNECTION_STATE_REASON_DEVICE_DISCONNECTED
|
|
|
|
|
&& reason != NM_ACTIVE_CONNECTION_STATE_REASON_CONNECTION_REMOVED) {
|
2018-05-25 02:31:59 +02:00
|
|
|
con = nm_active_connection_get_settings_connection(ac);
|
2023-02-15 10:35:08 +01:00
|
|
|
nm_manager_devcon_autoconnect_blocked_reason_set(
|
|
|
|
|
priv->manager,
|
|
|
|
|
nm_active_connection_get_device(ac),
|
2018-05-25 02:31:59 +02:00
|
|
|
con,
|
2023-02-09 21:04:15 +01:00
|
|
|
NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED,
|
2018-05-25 02:31:59 +02:00
|
|
|
TRUE);
|
2023-04-05 10:57:57 +02:00
|
|
|
nm_policy_device_recheck_auto_activate_schedule(self,
|
|
|
|
|
nm_active_connection_get_device(ac));
|
2018-05-25 02:31:59 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-09-25 22:20:47 +02:00
|
|
|
/* Cleanup */
|
|
|
|
|
g_signal_handlers_disconnect_by_func(ac, pending_ac_state_changed, self);
|
|
|
|
|
if (!g_hash_table_remove(priv->pending_active_connections, ac))
|
|
|
|
|
nm_assert_not_reached();
|
|
|
|
|
g_object_weak_unref(G_OBJECT(ac), pending_ac_gone, self);
|
|
|
|
|
g_object_unref(self);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-26 16:40:15 +02:00
|
|
|
static void
|
2023-04-05 11:55:28 +02:00
|
|
|
_auto_activate_device(NMPolicy *self, NMDevice *device)
|
2004-08-26 20:05:24 +00:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv;
|
|
|
|
|
NMSettingsConnection *best_connection;
|
|
|
|
|
gs_free char *specific_object = NULL;
|
|
|
|
|
gs_free NMSettingsConnection **connections = NULL;
|
2017-02-03 15:13:03 +01:00
|
|
|
guint i, len;
|
2021-11-09 13:28:54 +01:00
|
|
|
gs_free_error GError *error = NULL;
|
2018-04-13 11:21:59 +02:00
|
|
|
gs_unref_object NMAuthSubject *subject = NULL;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMActiveConnection *ac;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-09-26 16:40:15 +02:00
|
|
|
nm_assert(NM_IS_POLICY(self));
|
|
|
|
|
nm_assert(NM_IS_DEVICE(device));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-09-26 16:40:15 +02:00
|
|
|
priv = NM_POLICY_GET_PRIVATE(self);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2008-03-11 16:37:41 +00:00
|
|
|
// FIXME: if a device is already activating (or activated) with a connection
|
|
|
|
|
// but another connection now overrides the current one for that device,
|
|
|
|
|
// deactivate the device and activate the new connection instead of just
|
|
|
|
|
// bailing if the device is already active
|
2022-07-22 10:28:30 -04:00
|
|
|
if (nm_device_get_act_request(device)) {
|
2024-08-27 10:26:50 +02:00
|
|
|
if (nm_device_managed_type_is_external(device)
|
2022-07-22 10:28:30 -04:00
|
|
|
&& nm_device_get_allow_autoconnect_on_external(device)) {
|
|
|
|
|
/* this is an external activation, and we allow autoconnecting on
|
|
|
|
|
* top of that.
|
|
|
|
|
*
|
|
|
|
|
* pass. */
|
|
|
|
|
} else
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-02 18:48:02 +01:00
|
|
|
if (!nm_device_autoconnect_allowed(device))
|
|
|
|
|
return;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-04-18 11:08:05 +02:00
|
|
|
connections = nm_manager_get_activatable_connections(priv->manager, TRUE, TRUE, &len);
|
2017-02-03 15:13:03 +01:00
|
|
|
if (!connections[0])
|
2016-09-26 16:40:15 +02:00
|
|
|
return;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-08-26 15:18:47 +02:00
|
|
|
/* Find the first connection that should be auto-activated */
|
|
|
|
|
best_connection = NULL;
|
2017-02-03 15:13:03 +01:00
|
|
|
for (i = 0; i < len; i++) {
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
NMSettingsConnection *candidate = connections[i];
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *cand_conn;
|
|
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
const char *permission;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2023-02-15 10:35:08 +01:00
|
|
|
if (nm_manager_devcon_autoconnect_is_blocked(priv->manager, device, candidate))
|
2014-08-26 15:18:47 +02:00
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
cand_conn = nm_settings_connection_get_connection(candidate);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
s_con = nm_connection_get_setting_connection(cand_conn);
|
2017-10-25 22:17:47 +02:00
|
|
|
if (!nm_setting_connection_get_autoconnect(s_con))
|
|
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
permission = nm_utils_get_shared_wifi_permission(cand_conn);
|
2017-10-25 22:17:47 +02:00
|
|
|
if (permission && !nm_settings_connection_check_permission(candidate, permission))
|
|
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
if (nm_device_can_auto_connect(device, candidate, &specific_object)) {
|
2015-07-14 16:53:24 +02:00
|
|
|
best_connection = candidate;
|
2014-08-26 15:18:47 +02:00
|
|
|
break;
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
2014-08-26 15:18:47 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-02 18:50:19 +01:00
|
|
|
if (!best_connection)
|
|
|
|
|
return;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-06-07 11:57:17 +02:00
|
|
|
_LOGI(LOGD_DEVICE,
|
|
|
|
|
"auto-activating connection '%s' (%s)",
|
|
|
|
|
nm_settings_connection_get_id(best_connection),
|
|
|
|
|
nm_settings_connection_get_uuid(best_connection));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-02 18:50:19 +01:00
|
|
|
subject = nm_auth_subject_new_internal();
|
|
|
|
|
ac = nm_manager_activate_connection(
|
|
|
|
|
priv->manager,
|
|
|
|
|
best_connection,
|
|
|
|
|
NULL,
|
|
|
|
|
specific_object,
|
|
|
|
|
device,
|
|
|
|
|
subject,
|
|
|
|
|
NM_ACTIVATION_TYPE_MANAGED,
|
2018-03-28 17:18:04 +02:00
|
|
|
NM_ACTIVATION_REASON_AUTOCONNECT,
|
core: improve and fix keeping connection active based on "connection.permissions"
By setting "connection.permissions", a profile is restricted to a
particular user.
That means for example, that another user cannot see, modify, delete,
activate or deactivate the profile. It also means, that the profile
will only autoconnect when the user is logged in (has a session).
Note that root is always able to activate the profile. Likewise, the
user is also allowed to manually activate the own profile, even if no
session currently exists (which can easily happen with `sudo`).
When the user logs out (the session goes away), we want do disconnect
the profile, however there are conflicting goals here:
1) if the profile was activate by root user, then logging out the user
should not disconnect the profile. The patch fixes that by not
binding the activation to the connection, if the activation is done
by the root user.
2) if the profile was activated by the owner when it had no session,
then it should stay alive until the user logs in (once) and logs
out again. This is already handled by the previous commit.
Yes, this point is odd. If you first do
$ sudo -u $OTHER_USER nmcli connection up $PROFILE
the profile activates despite not having a session. If you then
$ ssh guest@localhost nmcli device
you'll still see the profile active. However, the moment the SSH session
ends, a session closes and the profile disconnects. It's unclear, how to
solve that any better. I think, a user who cares about this, should not
activate the profile without having a session in the first place.
There are quite some special cases, in particular with internal
activations. In those cases we need to decide whether to bind the
activation to the profile's visibility.
Also, expose the "bind" setting in the D-Bus API. Note, that in the future
this flag may be modified via D-Bus API. Like we may also add related API
that allows to tweak the lifetime of the activation.
Also, I think we broke handling of connection visiblity with 37e8c53eeed
"core: Introduce helper class to track connection keep alive". This
should be fixed now too, with improved behavior.
Fixes: 37e8c53eeed579fe34a68819cd12f3295d581394
https://bugzilla.redhat.com/show_bug.cgi?id=1530977
2018-11-21 13:30:16 +01:00
|
|
|
NM_ACTIVATION_STATE_FLAG_LIFETIME_BOUND_TO_PROFILE_VISIBILITY,
|
2017-11-02 18:50:19 +01:00
|
|
|
&error);
|
|
|
|
|
if (!ac) {
|
2017-11-22 20:09:47 +01:00
|
|
|
_LOGI(LOGD_DEVICE,
|
|
|
|
|
"connection '%s' auto-activation failed: %s",
|
2017-11-02 18:50:19 +01:00
|
|
|
nm_settings_connection_get_id(best_connection),
|
|
|
|
|
error->message);
|
2023-02-15 10:35:08 +01:00
|
|
|
nm_manager_devcon_autoconnect_blocked_reason_set(
|
|
|
|
|
priv->manager,
|
|
|
|
|
device,
|
2017-11-02 18:50:19 +01:00
|
|
|
best_connection,
|
2023-02-09 21:04:15 +01:00
|
|
|
NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED,
|
2017-11-24 10:53:39 +01:00
|
|
|
TRUE);
|
2023-04-05 10:57:57 +02:00
|
|
|
nm_policy_device_recheck_auto_activate_schedule(self, device);
|
2017-11-02 18:50:19 +01:00
|
|
|
return;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-02 18:50:19 +01:00
|
|
|
/* Subscribe to AC state-changed signal to detect when the
|
|
|
|
|
* activation fails in early stages without changing device
|
|
|
|
|
* state.
|
|
|
|
|
*/
|
2018-01-02 15:47:37 +01:00
|
|
|
if (g_hash_table_add(priv->pending_active_connections, ac)) {
|
2017-11-02 18:50:19 +01:00
|
|
|
g_signal_connect(ac,
|
|
|
|
|
NM_ACTIVE_CONNECTION_STATE_CHANGED,
|
|
|
|
|
G_CALLBACK(pending_ac_state_changed),
|
|
|
|
|
g_object_ref(self));
|
|
|
|
|
g_object_weak_ref(G_OBJECT(ac), (GWeakNotify) pending_ac_gone, self);
|
2005-01-07 18:07:06 +00:00
|
|
|
}
|
2016-09-26 16:40:15 +02:00
|
|
|
}
|
|
|
|
|
|
2023-04-05 11:55:28 +02:00
|
|
|
static void
|
|
|
|
|
_auto_activate_device_clear(NMPolicy *self, NMDevice *device, gboolean do_activate)
|
2016-09-26 16:40:15 +02:00
|
|
|
{
|
2023-04-05 11:55:28 +02:00
|
|
|
nm_assert(NM_IS_DEVICE(device));
|
|
|
|
|
nm_assert(NM_IS_POLICY(self));
|
|
|
|
|
nm_assert(c_list_is_linked(&device->policy_auto_activate_lst));
|
|
|
|
|
nm_assert(c_list_contains(&NM_POLICY_GET_PRIVATE(self)->policy_auto_activate_lst_head,
|
|
|
|
|
&device->policy_auto_activate_lst));
|
|
|
|
|
|
|
|
|
|
c_list_unlink(&device->policy_auto_activate_lst);
|
|
|
|
|
nm_clear_g_source_inst(&device->policy_auto_activate_idle_source);
|
2016-09-26 16:40:15 +02:00
|
|
|
|
2023-04-05 11:55:28 +02:00
|
|
|
if (do_activate)
|
|
|
|
|
_auto_activate_device(self, device);
|
2005-01-07 18:07:06 +00:00
|
|
|
|
2023-04-05 11:55:28 +02:00
|
|
|
nm_device_remove_pending_action(device, NM_PENDING_ACTION_AUTOACTIVATE, TRUE);
|
2005-01-07 18:07:06 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-05 11:55:28 +02:00
|
|
|
static gboolean
|
|
|
|
|
_auto_activate_idle_cb(gpointer user_data)
|
2011-04-19 00:26:37 -05:00
|
|
|
{
|
2023-04-05 11:55:28 +02:00
|
|
|
NMDevice *device = user_data;
|
2011-04-19 00:26:37 -05:00
|
|
|
|
2023-04-05 11:55:28 +02:00
|
|
|
nm_assert(NM_IS_DEVICE(device));
|
|
|
|
|
|
|
|
|
|
_auto_activate_device_clear(nm_manager_get_policy(nm_device_get_manager(device)), device, TRUE);
|
|
|
|
|
return G_SOURCE_CONTINUE;
|
2011-04-19 00:26:37 -05:00
|
|
|
}
|
|
|
|
|
|
2007-02-08 15:34:26 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2012-08-21 17:49:41 +02:00
|
|
|
typedef struct {
|
|
|
|
|
NMDevice *device;
|
2021-11-09 13:28:54 +01:00
|
|
|
GSList *secondaries;
|
2012-08-21 17:49:41 +02:00
|
|
|
} PendingSecondaryData;
|
|
|
|
|
|
|
|
|
|
static PendingSecondaryData *
|
|
|
|
|
pending_secondary_data_new(NMDevice *device, GSList *secondaries)
|
|
|
|
|
{
|
|
|
|
|
PendingSecondaryData *data;
|
|
|
|
|
|
2016-03-29 10:48:01 +02:00
|
|
|
data = g_slice_new(PendingSecondaryData);
|
2012-08-21 17:49:41 +02:00
|
|
|
data->device = g_object_ref(device);
|
|
|
|
|
data->secondaries = secondaries;
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
pending_secondary_data_free(PendingSecondaryData *data)
|
|
|
|
|
{
|
|
|
|
|
g_object_unref(data->device);
|
2013-10-07 17:35:03 -05:00
|
|
|
g_slist_free_full(data->secondaries, g_object_unref);
|
2016-03-29 10:48:01 +02:00
|
|
|
g_slice_free(PendingSecondaryData, data);
|
2012-08-21 17:49:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2016-03-29 10:46:07 +02:00
|
|
|
process_secondaries(NMPolicy *self, NMActiveConnection *active, gboolean connected)
|
2012-08-21 17:49:41 +02:00
|
|
|
{
|
2016-03-29 10:46:07 +02:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2021-11-09 13:28:54 +01:00
|
|
|
GSList *iter, *iter2, *next, *next2;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-10-07 17:35:03 -05:00
|
|
|
/* Loop through devices waiting for secondary connections to activate */
|
2015-11-04 15:48:28 +01:00
|
|
|
for (iter = priv->pending_secondaries; iter; iter = next) {
|
2012-08-21 17:49:41 +02:00
|
|
|
PendingSecondaryData *secondary_data = (PendingSecondaryData *) iter->data;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMDevice *item_device = secondary_data->device;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-11-04 15:48:28 +01:00
|
|
|
next = g_slist_next(iter);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-10-07 17:35:03 -05:00
|
|
|
/* Look for 'active' in each device's secondary connections list */
|
2015-11-04 15:48:28 +01:00
|
|
|
for (iter2 = secondary_data->secondaries; iter2; iter2 = next2) {
|
2013-10-07 17:35:03 -05:00
|
|
|
NMActiveConnection *secondary_active = NM_ACTIVE_CONNECTION(iter2->data);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-11-04 15:48:28 +01:00
|
|
|
next2 = g_slist_next(iter2);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-10-07 17:35:03 -05:00
|
|
|
if (active != secondary_active)
|
|
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-10-07 17:35:03 -05:00
|
|
|
if (connected) {
|
2016-03-03 09:20:18 +01:00
|
|
|
_LOGD(LOGD_DEVICE,
|
|
|
|
|
"secondary connection '%s' succeeded; active path '%s'",
|
|
|
|
|
nm_active_connection_get_settings_connection_id(active),
|
core/dbus: rework D-Bus implementation to use lower layer GDBusConnection API
Previously, we used the generated GDBusInterfaceSkeleton types and glued
them via the NMExportedObject base class to our NM types. We also used
GDBusObjectManagerServer.
Don't do that anymore. The resulting code was more complicated despite (or
because?) using generated classes. It was hard to understand, complex, had
ordering-issues, and had a runtime and memory overhead.
This patch refactors this entirely and uses the lower layer API GDBusConnection
directly. It replaces the generated code, GDBusInterfaceSkeleton, and
GDBusObjectManagerServer. All this is now done by NMDbusObject and NMDBusManager
and static descriptor instances of type GDBusInterfaceInfo.
This adds a net plus of more then 1300 lines of hand written code. I claim
that this implementation is easier to understand. Note that previously we
also required extensive and complex glue code to bind our objects to the
generated skeleton objects. Instead, now glue our objects directly to
GDBusConnection. The result is more immediate and gets rid of layers of
code in between.
Now that the D-Bus glue us more under our control, we can address issus and
bottlenecks better, instead of adding code to bend the generated skeletons
to our needs.
Note that the current implementation now only supports one D-Bus connection.
That was effectively the case already, although there were places (and still are)
where the code pretends it could also support connections from a private socket.
We dropped private socket support mainly because it was unused, untested and
buggy, but also because GDBusObjectManagerServer could not export the same
objects on multiple connections. Now, it would be rather straight forward to
fix that and re-introduce ObjectManager on each private connection. But this
commit doesn't do that yet, and the new code intentionally supports only one
D-Bus connection.
Also, the D-Bus startup was simplified. There is no retry, either nm_dbus_manager_start()
succeeds, or it detects the initrd case. In the initrd case, bus manager never tries to
connect to D-Bus. Since the initrd scenario is not yet used/tested, this is good enough
for the moment. It could be easily extended later, for example with polling whether the
system bus appears (like was done previously). Also, restart of D-Bus daemon isn't
supported either -- just like before.
Note how NMDBusManager now implements the ObjectManager D-Bus interface
directly.
Also, this fixes race issues in the server, by no longer delaying
PropertiesChanged signals. NMExportedObject would collect changed
properties and send the signal out in idle_emit_properties_changed()
on idle. This messes up the ordering of change events w.r.t. other
signals and events on the bus. Note that not only NMExportedObject
messed up the ordering. Also the generated code would hook into
notify() and process change events in and idle handle, exhibiting the
same ordering issue too.
No longer do that. PropertiesChanged signals will be sent right away
by hooking into dispatch_properties_changed(). This means, changing
a property in quick succession will no longer be combined and is
guaranteed to emit signals for each individual state. Quite possibly
we emit now more PropertiesChanged signals then before.
However, we are now able to group a set of changes by using standard
g_object_freeze_notify()/g_object_thaw_notify(). We probably should
make more use of that.
Also, now that our signals are all handled in the right order, we
might find places where we still emit them in the wrong order. But that
is then due to the order in which our GObjects emit signals, not due
to an ill behavior of the D-Bus glue. Possibly we need to identify
such ordering issues and fix them.
Numbers (for contrib/rpm --without debug on x86_64):
- the patch changes the code size of NetworkManager by
- 2809360 bytes
+ 2537528 bytes (-9.7%)
- Runtime measurements are harder because there is a large variance
during testing. In other words, the numbers are not reproducible.
Currently, the implementation performs no caching of GVariants at all,
but it would be rather simple to add it, if that turns out to be
useful.
Anyway, without strong claim, it seems that the new form tends to
perform slightly better. That would be no surprise.
$ time (for i in {1..1000}; do nmcli >/dev/null || break; echo -n .; done)
- real 1m39.355s
+ real 1m37.432s
$ time (for i in {1..2000}; do busctl call org.freedesktop.NetworkManager /org/freedesktop org.freedesktop.DBus.ObjectManager GetManagedObjects > /dev/null || break; echo -n .; done)
- real 0m26.843s
+ real 0m25.281s
- Regarding RSS size, just looking at the processes in similar
conditions, doesn't give a large difference. On my system they
consume about 19MB RSS. It seems that the new version has a
slightly smaller RSS size.
- 19356 RSS
+ 18660 RSS
2018-02-26 13:51:52 +01:00
|
|
|
nm_dbus_object_get_path(NM_DBUS_OBJECT(active)));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-10-07 17:35:03 -05:00
|
|
|
/* Secondary connection activated */
|
|
|
|
|
secondary_data->secondaries =
|
|
|
|
|
g_slist_remove(secondary_data->secondaries, secondary_active);
|
|
|
|
|
g_object_unref(secondary_active);
|
|
|
|
|
if (!secondary_data->secondaries) {
|
|
|
|
|
/* No secondary UUID remained -> remove the secondary data item */
|
|
|
|
|
priv->pending_secondaries =
|
|
|
|
|
g_slist_remove(priv->pending_secondaries, secondary_data);
|
|
|
|
|
pending_secondary_data_free(secondary_data);
|
2014-04-15 11:51:56 +02:00
|
|
|
if (nm_device_get_state(item_device) == NM_DEVICE_STATE_SECONDARIES)
|
|
|
|
|
nm_device_state_changed(item_device,
|
|
|
|
|
NM_DEVICE_STATE_ACTIVATED,
|
|
|
|
|
NM_DEVICE_STATE_REASON_NONE);
|
2013-10-07 17:35:03 -05:00
|
|
|
break;
|
2012-08-21 17:49:41 +02:00
|
|
|
}
|
2013-10-07 17:35:03 -05:00
|
|
|
} else {
|
2016-03-03 09:20:18 +01:00
|
|
|
_LOGD(LOGD_DEVICE,
|
|
|
|
|
"secondary connection '%s' failed; active path '%s'",
|
|
|
|
|
nm_active_connection_get_settings_connection_id(active),
|
core/dbus: rework D-Bus implementation to use lower layer GDBusConnection API
Previously, we used the generated GDBusInterfaceSkeleton types and glued
them via the NMExportedObject base class to our NM types. We also used
GDBusObjectManagerServer.
Don't do that anymore. The resulting code was more complicated despite (or
because?) using generated classes. It was hard to understand, complex, had
ordering-issues, and had a runtime and memory overhead.
This patch refactors this entirely and uses the lower layer API GDBusConnection
directly. It replaces the generated code, GDBusInterfaceSkeleton, and
GDBusObjectManagerServer. All this is now done by NMDbusObject and NMDBusManager
and static descriptor instances of type GDBusInterfaceInfo.
This adds a net plus of more then 1300 lines of hand written code. I claim
that this implementation is easier to understand. Note that previously we
also required extensive and complex glue code to bind our objects to the
generated skeleton objects. Instead, now glue our objects directly to
GDBusConnection. The result is more immediate and gets rid of layers of
code in between.
Now that the D-Bus glue us more under our control, we can address issus and
bottlenecks better, instead of adding code to bend the generated skeletons
to our needs.
Note that the current implementation now only supports one D-Bus connection.
That was effectively the case already, although there were places (and still are)
where the code pretends it could also support connections from a private socket.
We dropped private socket support mainly because it was unused, untested and
buggy, but also because GDBusObjectManagerServer could not export the same
objects on multiple connections. Now, it would be rather straight forward to
fix that and re-introduce ObjectManager on each private connection. But this
commit doesn't do that yet, and the new code intentionally supports only one
D-Bus connection.
Also, the D-Bus startup was simplified. There is no retry, either nm_dbus_manager_start()
succeeds, or it detects the initrd case. In the initrd case, bus manager never tries to
connect to D-Bus. Since the initrd scenario is not yet used/tested, this is good enough
for the moment. It could be easily extended later, for example with polling whether the
system bus appears (like was done previously). Also, restart of D-Bus daemon isn't
supported either -- just like before.
Note how NMDBusManager now implements the ObjectManager D-Bus interface
directly.
Also, this fixes race issues in the server, by no longer delaying
PropertiesChanged signals. NMExportedObject would collect changed
properties and send the signal out in idle_emit_properties_changed()
on idle. This messes up the ordering of change events w.r.t. other
signals and events on the bus. Note that not only NMExportedObject
messed up the ordering. Also the generated code would hook into
notify() and process change events in and idle handle, exhibiting the
same ordering issue too.
No longer do that. PropertiesChanged signals will be sent right away
by hooking into dispatch_properties_changed(). This means, changing
a property in quick succession will no longer be combined and is
guaranteed to emit signals for each individual state. Quite possibly
we emit now more PropertiesChanged signals then before.
However, we are now able to group a set of changes by using standard
g_object_freeze_notify()/g_object_thaw_notify(). We probably should
make more use of that.
Also, now that our signals are all handled in the right order, we
might find places where we still emit them in the wrong order. But that
is then due to the order in which our GObjects emit signals, not due
to an ill behavior of the D-Bus glue. Possibly we need to identify
such ordering issues and fix them.
Numbers (for contrib/rpm --without debug on x86_64):
- the patch changes the code size of NetworkManager by
- 2809360 bytes
+ 2537528 bytes (-9.7%)
- Runtime measurements are harder because there is a large variance
during testing. In other words, the numbers are not reproducible.
Currently, the implementation performs no caching of GVariants at all,
but it would be rather simple to add it, if that turns out to be
useful.
Anyway, without strong claim, it seems that the new form tends to
perform slightly better. That would be no surprise.
$ time (for i in {1..1000}; do nmcli >/dev/null || break; echo -n .; done)
- real 1m39.355s
+ real 1m37.432s
$ time (for i in {1..2000}; do busctl call org.freedesktop.NetworkManager /org/freedesktop org.freedesktop.DBus.ObjectManager GetManagedObjects > /dev/null || break; echo -n .; done)
- real 0m26.843s
+ real 0m25.281s
- Regarding RSS size, just looking at the processes in similar
conditions, doesn't give a large difference. On my system they
consume about 19MB RSS. It seems that the new version has a
slightly smaller RSS size.
- 19356 RSS
+ 18660 RSS
2018-02-26 13:51:52 +01:00
|
|
|
nm_dbus_object_get_path(NM_DBUS_OBJECT(active)));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-10-07 17:35:03 -05:00
|
|
|
/* Secondary connection failed -> do not watch other connections */
|
|
|
|
|
priv->pending_secondaries =
|
|
|
|
|
g_slist_remove(priv->pending_secondaries, secondary_data);
|
|
|
|
|
pending_secondary_data_free(secondary_data);
|
2014-04-15 11:51:56 +02:00
|
|
|
if (nm_device_get_state(item_device) == NM_DEVICE_STATE_SECONDARIES
|
|
|
|
|
|| nm_device_get_state(item_device) == NM_DEVICE_STATE_ACTIVATED)
|
|
|
|
|
nm_device_state_changed(item_device,
|
|
|
|
|
NM_DEVICE_STATE_FAILED,
|
|
|
|
|
NM_DEVICE_STATE_REASON_SECONDARY_CONNECTION_FAILED);
|
2013-10-07 17:35:03 -05:00
|
|
|
break;
|
2012-08-21 17:49:41 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
static void
|
2022-01-04 18:28:46 +01:00
|
|
|
_static_hostname_changed_cb(NMHostnameManager *hostname_manager,
|
|
|
|
|
GParamSpec *pspec,
|
|
|
|
|
gpointer user_data)
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
{
|
2016-04-04 14:36:34 +02:00
|
|
|
NMPolicyPrivate *priv = user_data;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
2016-04-04 14:36:34 +02:00
|
|
|
|
2024-07-31 17:08:43 +02:00
|
|
|
update_system_hostname(self, "hostname changed", FALSE);
|
2008-09-18 Dan Williams <dcbw@redhat.com>
Implement support for honoring configured and automatic hostnames, and for
setting the configured hostname.
* introspection/nm-ip4-config.xml
src/nm-ip4-config.c
src/nm-ip4-config.h
src/dhcp-manager/nm-dhcp-manager.c
- Remove useless hostname property; it's not really part of the IPv4
config
* introspection/nm-settings-system.xml
libnm-glib/nm-dbus-settings-system.c
libnm-glib/nm-dbus-settings-system.h
- Add SetHostname() call to system settings D-Bus interface
- Add Hostname property to system settings D-Bus interface
- (nm_dbus_settings_system_save_hostname,
nm_dbus_settings_system_get_hostname): implement
* src/nm-device.c
src/nm-device.h
- (nm_device_get_dhcp4_config): implement
* src/nm-manager.c
src/nm-manager.h
- Fetch and track system settings service hostname changes, and proxy
the changes via a GObject property of the manager
* system-settings/src/nm-system-config-interface.c
system-settings/src/nm-system-config-interface.h
- Replace nm_system_config_interface_supports_add() with a capabilities
bitfield
* system-settings/src/nm-system-config-error.c
system-settings/src/nm-system-config-error.h
- Add additional errors
* system-settings/src/dbus-settings.c
system-settings/src/dbus-settings.h
- (get_property, nm_sysconfig_settings_class_init): add hostname
property; first plugin returning a hostname wins
- (impl_settings_add_connection): use plugin capabilities instead of
nm_system_config_interface_supports_add()
- (impl_settings_save_hostname): implement hostname saving
* src/NetworkManagerPolicy.c
- (lookup_thread_run_cb, lookup_thread_worker, lookup_thread_new,
lookup_thread_die): implement an asynchronous hostname lookup thread
which given an IPv4 address tries to look up the hostname for that
address with reverse DNS
- (get_best_device): split out best device code from
update_routing_and_dns()
- (update_etc_hosts): update /etc/hosts with the machine's new hostname
to preserve the 127.0.0.1 reverse mapping that so many things require
- (set_system_hostname): set a given hostname
- (update_system_hostname): implement hostname policy; a configured
hostname (from the system settings service) is used if available,
otherwise an automatically determined hostname from DHCP, VPN, etc.
If there was no automatically determined hostname, reverse DNS of
the best device's IP address will be used, and as a last resort the
hostname 'localhost.localdomain' is set.
- (update_routing_and_dns): use get_best_device(); update the system
hostname when the network config changes
- (hostname_changed): update system hostname if the system settings
service signals a hostname change
- (nm_policy_new): list for system settings service hostname changes
- (nm_policy_destroy): ensure that an in-progress hostname lookup thread
gets told to die
* system-settings/plugins/keyfile/plugin.c
system-settings/plugins/ifcfg-suse/plugin.c
- (get_property, sc_plugin_ifcfg_class_init): implement hostname and
capabilities properties
* system-settings/plugins/ifcfg-fedora/shvar.c
- (svOpenFile): re-enable R/W access of ifcfg files since the plugin
writes out /etc/sysconfig/network now
* system-settings/plugins/ifcfg-fedora/plugin.c
- (plugin_get_hostname): get hostname from /etc/sysconfig/network
- (plugin_set_hostname): save hostname to /etc/sysconfig/network
- (sc_network_changed_cb): handle changes to /etc/sysconfig/network
- (sc_plugin_ifcfg_init): monitor /etc/sysconfig/network for changes
- (get_property, set_property, sc_plugin_ifcfg_class_init): implement
hostname get/set and capabilities get
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@4077 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-09-18 15:16:44 +00:00
|
|
|
}
|
|
|
|
|
|
2021-01-25 15:02:35 +01:00
|
|
|
void
|
|
|
|
|
nm_policy_unblock_failed_ovs_interfaces(NMPolicy *self)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2021-01-25 15:02:35 +01:00
|
|
|
NMSettingsConnection *const *connections = NULL;
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
_LOGT(LOGD_DEVICE, "unblocking failed OVS interfaces");
|
|
|
|
|
|
|
|
|
|
connections = nm_settings_get_connections(priv->settings, NULL);
|
|
|
|
|
for (i = 0; connections[i]; i++) {
|
|
|
|
|
NMSettingsConnection *sett_conn = connections[i];
|
2021-11-09 13:28:54 +01:00
|
|
|
NMConnection *connection = nm_settings_connection_get_connection(sett_conn);
|
2021-01-25 15:02:35 +01:00
|
|
|
|
|
|
|
|
if (nm_connection_get_setting_ovs_interface(connection)) {
|
2023-02-15 10:35:08 +01:00
|
|
|
nm_manager_devcon_autoconnect_retries_reset(priv->manager, NULL, sett_conn);
|
|
|
|
|
nm_manager_devcon_autoconnect_blocked_reason_set(
|
|
|
|
|
priv->manager,
|
|
|
|
|
NULL,
|
2021-01-25 15:02:35 +01:00
|
|
|
sett_conn,
|
2023-02-09 21:04:15 +01:00
|
|
|
NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED,
|
2021-01-25 15:02:35 +01:00
|
|
|
FALSE);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-11-22 14:52:54 +01:00
|
|
|
static gboolean
|
|
|
|
|
reset_autoconnect_all(
|
|
|
|
|
NMPolicy *self,
|
|
|
|
|
NMDevice *device, /* if present, only reset connections compatible with @device */
|
2017-11-24 12:14:42 +01:00
|
|
|
gboolean only_no_secrets)
|
2011-05-20 13:01:04 +02:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2017-11-22 11:02:06 +01:00
|
|
|
NMSettingsConnection *const *connections = NULL;
|
2017-02-03 14:15:16 +01:00
|
|
|
guint i;
|
2022-12-20 16:11:16 +01:00
|
|
|
gboolean changed = FALSE;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-22 14:52:54 +01:00
|
|
|
_LOGD(LOGD_DEVICE,
|
|
|
|
|
"re-enabling autoconnect for all connections%s%s%s",
|
|
|
|
|
device ? " on " : "",
|
|
|
|
|
device ? nm_device_get_iface(device) : "",
|
2017-11-24 12:14:42 +01:00
|
|
|
only_no_secrets ? " (only clear no-secrets flag)" : "");
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-22 11:02:06 +01:00
|
|
|
connections = nm_settings_get_connections(priv->settings, NULL);
|
2017-02-03 14:15:16 +01:00
|
|
|
for (i = 0; connections[i]; i++) {
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
NMSettingsConnection *sett_conn = connections[i];
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-22 14:52:54 +01:00
|
|
|
if (device
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
&& !nm_device_check_connection_compatible(
|
|
|
|
|
device,
|
|
|
|
|
nm_settings_connection_get_connection(sett_conn),
|
2023-01-24 12:00:42 +01:00
|
|
|
TRUE,
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
NULL))
|
2017-11-22 14:52:54 +01:00
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2023-02-15 10:35:08 +01:00
|
|
|
if (nm_manager_devcon_autoconnect_reset_reconnect_all(priv->manager,
|
|
|
|
|
device,
|
|
|
|
|
sett_conn,
|
|
|
|
|
only_no_secrets))
|
|
|
|
|
changed = TRUE;
|
2011-06-28 15:48:12 +02:00
|
|
|
}
|
2017-11-22 14:52:54 +01:00
|
|
|
return changed;
|
2011-06-28 15:48:12 +02:00
|
|
|
}
|
|
|
|
|
|
2009-10-20 15:25:04 -07:00
|
|
|
static void
|
|
|
|
|
sleeping_changed(NMManager *manager, GParamSpec *pspec, gpointer user_data)
|
|
|
|
|
{
|
2016-04-04 14:36:34 +02:00
|
|
|
NMPolicyPrivate *priv = user_data;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
2010-05-22 08:55:30 -07:00
|
|
|
gboolean sleeping = FALSE, enabled = FALSE;
|
2009-10-20 15:25:04 -07:00
|
|
|
|
|
|
|
|
g_object_get(G_OBJECT(manager), NM_MANAGER_SLEEPING, &sleeping, NULL);
|
2010-05-22 08:55:30 -07:00
|
|
|
g_object_get(G_OBJECT(manager), NM_MANAGER_NETWORKING_ENABLED, &enabled, NULL);
|
2009-10-20 15:25:04 -07:00
|
|
|
|
2011-04-01 18:50:58 -05:00
|
|
|
/* Reset retries on all connections so they'll checked on wakeup */
|
2017-11-29 09:37:05 +01:00
|
|
|
if (sleeping || !enabled)
|
|
|
|
|
reset_autoconnect_all(self, NULL, FALSE);
|
2009-10-20 15:25:04 -07:00
|
|
|
}
|
|
|
|
|
|
2023-04-05 10:57:57 +02:00
|
|
|
void
|
|
|
|
|
nm_policy_device_recheck_auto_activate_schedule(NMPolicy *self, NMDevice *device)
|
2007-02-08 15:34:26 +00:00
|
|
|
{
|
2023-04-05 10:57:57 +02:00
|
|
|
NMPolicyPrivate *priv;
|
2017-11-23 21:30:09 +01:00
|
|
|
NMActiveConnection *ac;
|
2021-11-09 13:28:54 +01:00
|
|
|
const CList *tmp_list;
|
2008-03-07 Dan Williams <dcbw@redhat.com>
First pass of multiple active device support. Expect bugs.
* src/nm-ip4-config.c
src/nm-ip4-config.h
- (nm_ip4_config_get_secondary, nm_ip4_config_set_secondary): remove;
there are better ways to do this in the named manager
* src/nm-device.c
src/nm-device.h
- (nm_device_can_activate): return whether the device can activate a
connection right now; taking into account things like carrier state
and rfkill state
- (nm_device_get_best_auto_connection): renamed from
nm_device_get_best_connection
- (real_act_stage4_get_ip4_config): MTU stuff is now handled in the
device subclasses themselves, so that each device can override the
MTU from it's NMSetting subclass if needed
- (nm_device_set_ip4_config): set MTU when setting up routes and stuff
in NetworkManagerSystem.c, not here
* src/named-manager/nm-named-manager.c
src/named-manager/nm-named-manager.h
- (nm_named_manager_name_owner_changed,
nm_named_manager_dbus_connection_changed): fix for changes to
rewrite_resolv_conf()
- (compute_nameservers): don't need the NMNamedManager at all, remove
from parameter list
- (merge_one_ip4_config): new function; merge ip4 configs together
- (rewrite_resolv_conf): write out resolv.conf from all the stored
ip4 configs; the VPN config takes precedence, then the best
device config, then the rest of the configs
- (get_domain_for_config): take the NMNamedManager as an argument
to check whether the config is the VPN config
- (add_ip4_config_to_named): fixups for removal of the 'secondary'
attribute from ip4 configs
- (add_all_ip4_configs_to_named): add all the configs in priority order
- (remove_ip4_config_from_named): fix for changes to
get_domain_for_config()
- (nm_named_manager_add_ip4_config): assign the config to the right slot
based on its type; callers must pass in the type now
- (get_last_default_domain): remove, unused
- (nm_named_manager_remove_ip4_config): handle config slots correctly
* src/nm-device-802-11-wireless.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): handle MTU override
* src/nm-device-802-3-ethernet.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): new function; handle MTU override
* src/vpn-manager/nm-vpn-connection.c
- (nm_vpn_connection_ip4_config_get): don't need to set the 'secondary'
attribute on the ip4 config
* src/NetworkManagerPolicy.c
- (nm_policy_auto_get_best_device): remove
- (nm_policy_device_change_check): remove
- (update_default_route): new function; set the default route via
the specified device
- (get_device_priority): new function; return the priority number of
a device type WRT which one should have the default route. Order is
(highest to lowest) wired, wireless, GSM, CDMA.
- (update_routing_and_dns): new function; determine which device should
have the default route, then update the routing table and DNS
- (maybe_auto_activate_device): new function; if a device is now
available for activation, find out what connection it would like to
activate and do it
- (schedule_activate_check): new function; if a device can be activated
now, schedule the activation. Each device may have only one
pending activation at a given time.
- (device_state_changed): if activation was canceled, try again,
possibly with another connection; if the device was activated,
update routing and DNS; if the device was deactivated, try again
with another connection
- (device_carrier_changed): if there is no carrier, deactivate the
device; otherwise schedule an activation check for the device
- (wireless_networks_changed): schedule an activation check for the
device
- (device_added): keep track of the signal handler IDs so they can
be removed when the device goes away
- (device_removed): remove any signal handlers that might be attached
to the device; update routing and DNS
- (schedule_activate_all): new function
- (connections_added, connection_added, connection_updated): when
connections change, schedule all devices for an activation check
- (connection_removed): when a device is deactivated because its
connection was removed, schedule another activation check for it
- (nm_policy_destroy): destroy pending activations and disconnect
all device signal handlers
* src/nm-manager.c
- (nm_manager_activate_device): if the device was already actived,
deactivate it
- (deactivate_old_device): remove
- (connection_added_default_handler, impl_manager_activate_device):
don't deactivate other devices when activating this one
* src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerSuSE.c
src/backends/NetworkManagerDebian.c
- (nm_system_get_mtu): remove; MTU should be provided through the
distro's system settings service plugin instead
- (nm_system_device_add_default_route_via_device): remove
- (nm_system_device_add_default_route_via_device_with_iface): remove
- (nm_system_device_replace_default_route): new function; call
generic implementation
* src/backends/NetworkManagerGeneric.c
src/backends/NetworkManagerGeneric.h
- (nm_generic_device_add_default_route_via_device,
nm_generic_device_add_default_route_via_device_with_iface): remove
- (nm_generic_device_replace_default_route): replace the default route
with the given route via some gateway
* src/NetworkManagerSystem.c
src/NetworkManagerSystem.h
- (nm_system_device_set_from_ip4_config): let the policy handle updates
to routing and DNS; but set the MTU here
- (nm_system_vpn_device_set_from_ip4_config): set the route with the
ip_iface of the active device; use the standard MTU setting function
- (nm_system_set_mtu): remove
- (nm_system_device_set_mtu): consolidate MTU setting code in one place
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3391 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-07 19:41:32 +00:00
|
|
|
|
2023-04-05 10:57:57 +02:00
|
|
|
g_return_if_fail(NM_IS_POLICY(self));
|
|
|
|
|
g_return_if_fail(NM_IS_DEVICE(device));
|
2023-08-21 14:11:28 -04:00
|
|
|
nm_assert(g_signal_handler_find(device,
|
|
|
|
|
G_SIGNAL_MATCH_DATA,
|
|
|
|
|
0,
|
|
|
|
|
0,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
NM_POLICY_GET_PRIVATE(self))
|
|
|
|
|
!= 0);
|
2023-04-05 10:57:57 +02:00
|
|
|
|
2023-04-05 11:55:28 +02:00
|
|
|
if (!c_list_is_empty(&device->policy_auto_activate_lst)) {
|
|
|
|
|
/* already queued. Return. */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-05 10:57:57 +02:00
|
|
|
priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
|
2025-09-15 14:43:22 +02:00
|
|
|
if (nm_manager_get_state(priv->manager) == NM_STATE_DISABLED)
|
2008-03-07 Dan Williams <dcbw@redhat.com>
First pass of multiple active device support. Expect bugs.
* src/nm-ip4-config.c
src/nm-ip4-config.h
- (nm_ip4_config_get_secondary, nm_ip4_config_set_secondary): remove;
there are better ways to do this in the named manager
* src/nm-device.c
src/nm-device.h
- (nm_device_can_activate): return whether the device can activate a
connection right now; taking into account things like carrier state
and rfkill state
- (nm_device_get_best_auto_connection): renamed from
nm_device_get_best_connection
- (real_act_stage4_get_ip4_config): MTU stuff is now handled in the
device subclasses themselves, so that each device can override the
MTU from it's NMSetting subclass if needed
- (nm_device_set_ip4_config): set MTU when setting up routes and stuff
in NetworkManagerSystem.c, not here
* src/named-manager/nm-named-manager.c
src/named-manager/nm-named-manager.h
- (nm_named_manager_name_owner_changed,
nm_named_manager_dbus_connection_changed): fix for changes to
rewrite_resolv_conf()
- (compute_nameservers): don't need the NMNamedManager at all, remove
from parameter list
- (merge_one_ip4_config): new function; merge ip4 configs together
- (rewrite_resolv_conf): write out resolv.conf from all the stored
ip4 configs; the VPN config takes precedence, then the best
device config, then the rest of the configs
- (get_domain_for_config): take the NMNamedManager as an argument
to check whether the config is the VPN config
- (add_ip4_config_to_named): fixups for removal of the 'secondary'
attribute from ip4 configs
- (add_all_ip4_configs_to_named): add all the configs in priority order
- (remove_ip4_config_from_named): fix for changes to
get_domain_for_config()
- (nm_named_manager_add_ip4_config): assign the config to the right slot
based on its type; callers must pass in the type now
- (get_last_default_domain): remove, unused
- (nm_named_manager_remove_ip4_config): handle config slots correctly
* src/nm-device-802-11-wireless.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): handle MTU override
* src/nm-device-802-3-ethernet.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): new function; handle MTU override
* src/vpn-manager/nm-vpn-connection.c
- (nm_vpn_connection_ip4_config_get): don't need to set the 'secondary'
attribute on the ip4 config
* src/NetworkManagerPolicy.c
- (nm_policy_auto_get_best_device): remove
- (nm_policy_device_change_check): remove
- (update_default_route): new function; set the default route via
the specified device
- (get_device_priority): new function; return the priority number of
a device type WRT which one should have the default route. Order is
(highest to lowest) wired, wireless, GSM, CDMA.
- (update_routing_and_dns): new function; determine which device should
have the default route, then update the routing table and DNS
- (maybe_auto_activate_device): new function; if a device is now
available for activation, find out what connection it would like to
activate and do it
- (schedule_activate_check): new function; if a device can be activated
now, schedule the activation. Each device may have only one
pending activation at a given time.
- (device_state_changed): if activation was canceled, try again,
possibly with another connection; if the device was activated,
update routing and DNS; if the device was deactivated, try again
with another connection
- (device_carrier_changed): if there is no carrier, deactivate the
device; otherwise schedule an activation check for the device
- (wireless_networks_changed): schedule an activation check for the
device
- (device_added): keep track of the signal handler IDs so they can
be removed when the device goes away
- (device_removed): remove any signal handlers that might be attached
to the device; update routing and DNS
- (schedule_activate_all): new function
- (connections_added, connection_added, connection_updated): when
connections change, schedule all devices for an activation check
- (connection_removed): when a device is deactivated because its
connection was removed, schedule another activation check for it
- (nm_policy_destroy): destroy pending activations and disconnect
all device signal handlers
* src/nm-manager.c
- (nm_manager_activate_device): if the device was already actived,
deactivate it
- (deactivate_old_device): remove
- (connection_added_default_handler, impl_manager_activate_device):
don't deactivate other devices when activating this one
* src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerSuSE.c
src/backends/NetworkManagerDebian.c
- (nm_system_get_mtu): remove; MTU should be provided through the
distro's system settings service plugin instead
- (nm_system_device_add_default_route_via_device): remove
- (nm_system_device_add_default_route_via_device_with_iface): remove
- (nm_system_device_replace_default_route): new function; call
generic implementation
* src/backends/NetworkManagerGeneric.c
src/backends/NetworkManagerGeneric.h
- (nm_generic_device_add_default_route_via_device,
nm_generic_device_add_default_route_via_device_with_iface): remove
- (nm_generic_device_replace_default_route): replace the default route
with the given route via some gateway
* src/NetworkManagerSystem.c
src/NetworkManagerSystem.h
- (nm_system_device_set_from_ip4_config): let the policy handle updates
to routing and DNS; but set the MTU here
- (nm_system_vpn_device_set_from_ip4_config): set the route with the
ip_iface of the active device; use the standard MTU setting function
- (nm_system_set_mtu): remove
- (nm_system_device_set_mtu): consolidate MTU setting code in one place
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3391 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-07 19:41:32 +00:00
|
|
|
return;
|
|
|
|
|
|
2009-09-14 13:33:06 -07:00
|
|
|
if (!nm_device_autoconnect_allowed(device))
|
2008-03-07 Dan Williams <dcbw@redhat.com>
First pass of multiple active device support. Expect bugs.
* src/nm-ip4-config.c
src/nm-ip4-config.h
- (nm_ip4_config_get_secondary, nm_ip4_config_set_secondary): remove;
there are better ways to do this in the named manager
* src/nm-device.c
src/nm-device.h
- (nm_device_can_activate): return whether the device can activate a
connection right now; taking into account things like carrier state
and rfkill state
- (nm_device_get_best_auto_connection): renamed from
nm_device_get_best_connection
- (real_act_stage4_get_ip4_config): MTU stuff is now handled in the
device subclasses themselves, so that each device can override the
MTU from it's NMSetting subclass if needed
- (nm_device_set_ip4_config): set MTU when setting up routes and stuff
in NetworkManagerSystem.c, not here
* src/named-manager/nm-named-manager.c
src/named-manager/nm-named-manager.h
- (nm_named_manager_name_owner_changed,
nm_named_manager_dbus_connection_changed): fix for changes to
rewrite_resolv_conf()
- (compute_nameservers): don't need the NMNamedManager at all, remove
from parameter list
- (merge_one_ip4_config): new function; merge ip4 configs together
- (rewrite_resolv_conf): write out resolv.conf from all the stored
ip4 configs; the VPN config takes precedence, then the best
device config, then the rest of the configs
- (get_domain_for_config): take the NMNamedManager as an argument
to check whether the config is the VPN config
- (add_ip4_config_to_named): fixups for removal of the 'secondary'
attribute from ip4 configs
- (add_all_ip4_configs_to_named): add all the configs in priority order
- (remove_ip4_config_from_named): fix for changes to
get_domain_for_config()
- (nm_named_manager_add_ip4_config): assign the config to the right slot
based on its type; callers must pass in the type now
- (get_last_default_domain): remove, unused
- (nm_named_manager_remove_ip4_config): handle config slots correctly
* src/nm-device-802-11-wireless.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): handle MTU override
* src/nm-device-802-3-ethernet.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): new function; handle MTU override
* src/vpn-manager/nm-vpn-connection.c
- (nm_vpn_connection_ip4_config_get): don't need to set the 'secondary'
attribute on the ip4 config
* src/NetworkManagerPolicy.c
- (nm_policy_auto_get_best_device): remove
- (nm_policy_device_change_check): remove
- (update_default_route): new function; set the default route via
the specified device
- (get_device_priority): new function; return the priority number of
a device type WRT which one should have the default route. Order is
(highest to lowest) wired, wireless, GSM, CDMA.
- (update_routing_and_dns): new function; determine which device should
have the default route, then update the routing table and DNS
- (maybe_auto_activate_device): new function; if a device is now
available for activation, find out what connection it would like to
activate and do it
- (schedule_activate_check): new function; if a device can be activated
now, schedule the activation. Each device may have only one
pending activation at a given time.
- (device_state_changed): if activation was canceled, try again,
possibly with another connection; if the device was activated,
update routing and DNS; if the device was deactivated, try again
with another connection
- (device_carrier_changed): if there is no carrier, deactivate the
device; otherwise schedule an activation check for the device
- (wireless_networks_changed): schedule an activation check for the
device
- (device_added): keep track of the signal handler IDs so they can
be removed when the device goes away
- (device_removed): remove any signal handlers that might be attached
to the device; update routing and DNS
- (schedule_activate_all): new function
- (connections_added, connection_added, connection_updated): when
connections change, schedule all devices for an activation check
- (connection_removed): when a device is deactivated because its
connection was removed, schedule another activation check for it
- (nm_policy_destroy): destroy pending activations and disconnect
all device signal handlers
* src/nm-manager.c
- (nm_manager_activate_device): if the device was already actived,
deactivate it
- (deactivate_old_device): remove
- (connection_added_default_handler, impl_manager_activate_device):
don't deactivate other devices when activating this one
* src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerSuSE.c
src/backends/NetworkManagerDebian.c
- (nm_system_get_mtu): remove; MTU should be provided through the
distro's system settings service plugin instead
- (nm_system_device_add_default_route_via_device): remove
- (nm_system_device_add_default_route_via_device_with_iface): remove
- (nm_system_device_replace_default_route): new function; call
generic implementation
* src/backends/NetworkManagerGeneric.c
src/backends/NetworkManagerGeneric.h
- (nm_generic_device_add_default_route_via_device,
nm_generic_device_add_default_route_via_device_with_iface): remove
- (nm_generic_device_replace_default_route): replace the default route
with the given route via some gateway
* src/NetworkManagerSystem.c
src/NetworkManagerSystem.h
- (nm_system_device_set_from_ip4_config): let the policy handle updates
to routing and DNS; but set the MTU here
- (nm_system_vpn_device_set_from_ip4_config): set the route with the
ip_iface of the active device; use the standard MTU setting function
- (nm_system_set_mtu): remove
- (nm_system_device_set_mtu): consolidate MTU setting code in one place
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3391 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-07 19:41:32 +00:00
|
|
|
return;
|
|
|
|
|
|
2017-11-23 21:30:09 +01:00
|
|
|
nm_manager_for_each_active_connection (priv->manager, ac, tmp_list) {
|
2022-07-22 10:28:30 -04:00
|
|
|
if (nm_active_connection_get_device(ac) == device) {
|
2024-08-27 10:26:50 +02:00
|
|
|
if (nm_device_managed_type_is_external(device)
|
2022-07-22 10:28:30 -04:00
|
|
|
&& nm_device_get_allow_autoconnect_on_external(device)) {
|
|
|
|
|
/* pass */
|
|
|
|
|
} else
|
|
|
|
|
return;
|
|
|
|
|
}
|
2013-08-28 16:19:20 -05:00
|
|
|
}
|
|
|
|
|
|
2017-01-27 13:57:15 +01:00
|
|
|
nm_device_add_pending_action(device, NM_PENDING_ACTION_AUTOACTIVATE, TRUE);
|
2014-02-13 14:45:25 -05:00
|
|
|
|
2023-04-05 11:55:28 +02:00
|
|
|
c_list_link_tail(&priv->policy_auto_activate_lst_head, &device->policy_auto_activate_lst);
|
|
|
|
|
device->policy_auto_activate_idle_source = nm_g_idle_add_source(_auto_activate_idle_cb, device);
|
2007-02-08 15:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
2011-06-17 12:43:28 +02:00
|
|
|
static gboolean
|
|
|
|
|
reset_connections_retries(gpointer user_data)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = (NMPolicy *) user_data;
|
|
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2017-11-22 11:02:06 +01:00
|
|
|
NMSettingsConnection *const *connections = NULL;
|
2017-02-03 14:15:16 +01:00
|
|
|
guint i;
|
2013-12-10 20:39:48 +01:00
|
|
|
gint32 con_stamp, min_stamp, now;
|
2022-12-20 16:11:16 +01:00
|
|
|
gboolean changed = FALSE;
|
2011-06-17 12:43:28 +02:00
|
|
|
|
2023-04-07 13:08:14 +02:00
|
|
|
nm_clear_g_source_inst(&priv->reset_connections_retries_idle_source);
|
2011-06-17 12:43:28 +02:00
|
|
|
|
2013-12-05 04:57:01 -05:00
|
|
|
min_stamp = 0;
|
2019-12-13 16:54:30 +01:00
|
|
|
now = nm_utils_get_monotonic_timestamp_sec();
|
2017-11-22 11:02:06 +01:00
|
|
|
connections = nm_settings_get_connections(priv->settings, NULL);
|
2017-02-03 14:15:16 +01:00
|
|
|
for (i = 0; connections[i]; i++) {
|
|
|
|
|
NMSettingsConnection *connection = connections[i];
|
2013-12-05 04:57:01 -05:00
|
|
|
|
2023-02-15 10:35:08 +01:00
|
|
|
con_stamp =
|
|
|
|
|
nm_manager_devcon_autoconnect_retries_blocked_until(priv->manager, NULL, connection);
|
2011-06-17 12:43:28 +02:00
|
|
|
if (con_stamp == 0)
|
|
|
|
|
continue;
|
2013-12-05 04:57:01 -05:00
|
|
|
|
2014-01-30 15:59:40 +01:00
|
|
|
if (con_stamp <= now) {
|
2023-02-15 10:35:08 +01:00
|
|
|
nm_manager_devcon_autoconnect_retries_reset(priv->manager, NULL, connection);
|
2011-12-06 16:33:00 -06:00
|
|
|
changed = TRUE;
|
2013-12-05 04:57:01 -05:00
|
|
|
} else if (min_stamp == 0 || min_stamp > con_stamp)
|
2011-06-17 12:43:28 +02:00
|
|
|
min_stamp = con_stamp;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Schedule the handler again if there are some stamps left */
|
2023-04-07 13:08:14 +02:00
|
|
|
if (min_stamp != 0) {
|
|
|
|
|
priv->reset_connections_retries_idle_source =
|
|
|
|
|
nm_g_timeout_add_seconds_source(min_stamp - now, reset_connections_retries, self);
|
|
|
|
|
}
|
2011-12-06 16:33:00 -06:00
|
|
|
|
|
|
|
|
/* If anything changed, try to activate the newly re-enabled connections */
|
|
|
|
|
if (changed)
|
2023-04-05 11:02:36 +02:00
|
|
|
nm_policy_device_recheck_auto_activate_all_schedule(self);
|
2011-12-06 16:33:00 -06:00
|
|
|
|
2023-04-07 13:08:14 +02:00
|
|
|
return G_SOURCE_CONTINUE;
|
2011-06-17 12:43:28 +02:00
|
|
|
}
|
|
|
|
|
|
2017-11-22 17:03:22 +01:00
|
|
|
static void
|
2023-02-15 10:35:08 +01:00
|
|
|
_connection_autoconnect_retries_set(NMPolicy *self,
|
|
|
|
|
NMDevice *device,
|
|
|
|
|
NMSettingsConnection *connection,
|
|
|
|
|
guint32 tries)
|
2017-11-22 17:03:22 +01:00
|
|
|
{
|
2022-12-20 16:11:16 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2017-11-22 17:03:22 +01:00
|
|
|
|
|
|
|
|
nm_assert(NM_IS_SETTINGS_CONNECTION(connection));
|
|
|
|
|
|
2023-02-15 10:35:08 +01:00
|
|
|
nm_manager_devcon_autoconnect_retries_set(priv->manager, device, connection, tries);
|
2017-11-22 17:03:22 +01:00
|
|
|
|
|
|
|
|
if (tries == 0) {
|
|
|
|
|
/* Schedule a handler to reset retries count */
|
2023-04-07 13:08:14 +02:00
|
|
|
if (!priv->reset_connections_retries_idle_source) {
|
2023-04-28 11:47:20 +02:00
|
|
|
gint32 retry_time;
|
|
|
|
|
|
|
|
|
|
retry_time = nm_manager_devcon_autoconnect_retries_blocked_until(priv->manager,
|
|
|
|
|
device,
|
|
|
|
|
connection);
|
|
|
|
|
nm_assert(retry_time != 0);
|
2022-12-20 16:11:16 +01:00
|
|
|
|
2023-04-07 13:08:14 +02:00
|
|
|
priv->reset_connections_retries_idle_source = nm_g_timeout_add_seconds_source(
|
2023-10-27 14:36:56 +02:00
|
|
|
NM_MAX(0, retry_time - nm_utils_get_monotonic_timestamp_sec()),
|
2023-04-07 13:08:14 +02:00
|
|
|
reset_connections_retries,
|
|
|
|
|
self);
|
2017-11-22 17:03:22 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
2017-11-22 17:03:22 +01:00
|
|
|
}
|
|
|
|
|
|
2024-07-29 14:42:05 -04:00
|
|
|
static void
|
|
|
|
|
unblock_autoconnect_for_children(NMPolicy *self,
|
|
|
|
|
const char *parent_device,
|
|
|
|
|
const char *parent_uuid_settings,
|
|
|
|
|
const char *parent_uuid_applied,
|
2025-02-12 10:58:39 +01:00
|
|
|
const char *parent_mac_addr)
|
2024-07-29 14:42:05 -04:00
|
|
|
{
|
|
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
NMSettingsConnection *const *connections;
|
|
|
|
|
gboolean changed;
|
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
|
|
_LOGT(LOGD_CORE,
|
|
|
|
|
"block-autoconnect: unblocking child profiles for parent ifname=%s%s%s, uuid=%s%s%s"
|
|
|
|
|
"%s%s%s",
|
|
|
|
|
NM_PRINT_FMT_QUOTE_STRING(parent_device),
|
|
|
|
|
NM_PRINT_FMT_QUOTE_STRING(parent_uuid_settings),
|
|
|
|
|
NM_PRINT_FMT_QUOTED(parent_uuid_applied,
|
|
|
|
|
", applied-uuid=\"",
|
|
|
|
|
parent_uuid_applied,
|
|
|
|
|
"\"",
|
|
|
|
|
""));
|
|
|
|
|
|
|
|
|
|
changed = FALSE;
|
|
|
|
|
connections = nm_settings_get_connections(priv->settings, NULL);
|
|
|
|
|
for (i = 0; connections[i]; i++) {
|
|
|
|
|
NMSettingsConnection *sett_conn = connections[i];
|
|
|
|
|
NMConnection *connection;
|
|
|
|
|
NMDeviceFactory *factory;
|
|
|
|
|
const char *parent_name = NULL;
|
|
|
|
|
|
|
|
|
|
connection = nm_settings_connection_get_connection(sett_conn);
|
|
|
|
|
factory = nm_device_factory_manager_find_factory_for_connection(connection);
|
|
|
|
|
if (factory)
|
|
|
|
|
parent_name = nm_device_factory_get_connection_parent(factory, connection);
|
|
|
|
|
|
|
|
|
|
if (!parent_name)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
if (!NM_IN_STRSET(parent_name,
|
|
|
|
|
parent_device,
|
|
|
|
|
parent_uuid_applied,
|
|
|
|
|
parent_uuid_settings,
|
|
|
|
|
parent_mac_addr))
|
|
|
|
|
continue;
|
|
|
|
|
|
2025-02-12 10:58:39 +01:00
|
|
|
if (nm_manager_devcon_autoconnect_retries_reset(priv->manager, NULL, sett_conn))
|
|
|
|
|
changed = TRUE;
|
2024-07-29 14:42:05 -04:00
|
|
|
|
|
|
|
|
/* unblock the devices associated with that connection */
|
|
|
|
|
if (nm_manager_devcon_autoconnect_blocked_reason_set(
|
|
|
|
|
priv->manager,
|
|
|
|
|
NULL,
|
|
|
|
|
sett_conn,
|
|
|
|
|
NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED,
|
|
|
|
|
FALSE)) {
|
|
|
|
|
if (!nm_settings_connection_autoconnect_is_blocked(sett_conn))
|
|
|
|
|
changed = TRUE;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (changed)
|
|
|
|
|
nm_policy_device_recheck_auto_activate_all_schedule(self);
|
|
|
|
|
}
|
|
|
|
|
|
2011-12-07 13:15:24 +01:00
|
|
|
static void
|
2023-04-28 13:08:10 +02:00
|
|
|
unblock_autoconnect_for_ports(NMPolicy *self,
|
2024-05-27 17:58:08 +02:00
|
|
|
const char *controller_device,
|
|
|
|
|
const char *controller_uuid_settings,
|
2025-02-12 10:58:39 +01:00
|
|
|
const char *controller_uuid_applied)
|
2011-12-07 13:15:24 +01:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2017-11-22 11:02:06 +01:00
|
|
|
NMSettingsConnection *const *connections;
|
2025-02-19 08:55:04 +01:00
|
|
|
gboolean changed = FALSE;
|
2023-04-28 13:08:10 +02:00
|
|
|
guint i;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2023-05-05 10:11:18 +02:00
|
|
|
_LOGT(LOGD_CORE,
|
|
|
|
|
"block-autoconnect: unblocking port profiles for controller ifname=%s%s%s, uuid=%s%s%s"
|
|
|
|
|
"%s%s%s",
|
2024-05-27 17:58:08 +02:00
|
|
|
NM_PRINT_FMT_QUOTE_STRING(controller_device),
|
|
|
|
|
NM_PRINT_FMT_QUOTE_STRING(controller_uuid_settings),
|
|
|
|
|
NM_PRINT_FMT_QUOTED(controller_uuid_applied,
|
2023-05-05 10:11:18 +02:00
|
|
|
", applied-uuid=\"",
|
2024-05-27 17:58:08 +02:00
|
|
|
controller_uuid_applied,
|
2023-05-05 10:11:18 +02:00
|
|
|
"\"",
|
|
|
|
|
""));
|
|
|
|
|
|
2017-11-22 11:02:06 +01:00
|
|
|
connections = nm_settings_get_connections(priv->settings, NULL);
|
2017-09-28 16:43:06 +02:00
|
|
|
for (i = 0; connections[i]; i++) {
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
NMSettingsConnection *sett_conn = connections[i];
|
2024-07-04 12:45:42 +02:00
|
|
|
NMSettingConnection *s_port_con;
|
|
|
|
|
const char *port_controller;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2024-07-04 12:45:42 +02:00
|
|
|
s_port_con = nm_settings_connection_get_setting(sett_conn, NM_META_SETTING_TYPE_CONNECTION);
|
|
|
|
|
port_controller = nm_setting_connection_get_controller(s_port_con);
|
|
|
|
|
if (!port_controller)
|
2017-09-28 16:43:06 +02:00
|
|
|
continue;
|
2023-04-28 13:08:10 +02:00
|
|
|
|
2024-07-04 12:45:42 +02:00
|
|
|
if (!NM_IN_STRSET(port_controller,
|
2024-05-27 17:58:08 +02:00
|
|
|
controller_device,
|
|
|
|
|
controller_uuid_applied,
|
|
|
|
|
controller_uuid_settings))
|
2017-11-22 22:23:13 +01:00
|
|
|
continue;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2025-02-12 10:58:39 +01:00
|
|
|
if (nm_manager_devcon_autoconnect_retries_reset(priv->manager, NULL, sett_conn))
|
|
|
|
|
changed = TRUE;
|
2023-04-28 13:08:10 +02:00
|
|
|
|
2023-02-15 10:35:08 +01:00
|
|
|
/* unblock the devices associated with that connection */
|
|
|
|
|
if (nm_manager_devcon_autoconnect_blocked_reason_set(
|
|
|
|
|
priv->manager,
|
|
|
|
|
NULL,
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
sett_conn,
|
2023-02-09 21:04:15 +01:00
|
|
|
NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED,
|
2017-11-24 12:59:15 +01:00
|
|
|
FALSE)) {
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
if (!nm_settings_connection_autoconnect_is_blocked(sett_conn))
|
2017-11-24 12:59:15 +01:00
|
|
|
changed = TRUE;
|
|
|
|
|
}
|
2011-12-07 13:15:24 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-24 12:47:59 +01:00
|
|
|
if (changed)
|
2023-04-05 11:02:36 +02:00
|
|
|
nm_policy_device_recheck_auto_activate_all_schedule(self);
|
2011-12-07 13:15:24 +01:00
|
|
|
}
|
|
|
|
|
|
2023-05-03 11:34:06 +02:00
|
|
|
static void
|
|
|
|
|
unblock_autoconnect_for_ports_for_sett_conn(NMPolicy *self, NMSettingsConnection *sett_conn)
|
|
|
|
|
{
|
2024-05-27 17:58:08 +02:00
|
|
|
const char *controller_device;
|
|
|
|
|
const char *controller_uuid_settings;
|
2023-05-03 11:34:06 +02:00
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
|
|
|
|
|
nm_assert(NM_IS_POLICY(self));
|
|
|
|
|
nm_assert(NM_IS_SETTINGS_CONNECTION(sett_conn));
|
|
|
|
|
|
|
|
|
|
s_con = nm_settings_connection_get_setting(sett_conn, NM_META_SETTING_TYPE_CONNECTION);
|
|
|
|
|
|
|
|
|
|
nm_assert(NM_IS_SETTING_CONNECTION(s_con));
|
|
|
|
|
|
2024-05-27 17:58:08 +02:00
|
|
|
controller_uuid_settings = nm_setting_connection_get_uuid(s_con);
|
|
|
|
|
controller_device = nm_setting_connection_get_interface_name(s_con);
|
2023-05-03 11:34:06 +02:00
|
|
|
|
2025-02-12 10:58:39 +01:00
|
|
|
unblock_autoconnect_for_ports(self, controller_device, controller_uuid_settings, NULL);
|
2023-05-03 11:34:06 +02:00
|
|
|
}
|
|
|
|
|
|
2023-04-28 13:08:10 +02:00
|
|
|
static void
|
2024-07-29 14:42:05 -04:00
|
|
|
activate_port_or_children_connections(NMPolicy *self,
|
|
|
|
|
NMDevice *device,
|
|
|
|
|
gboolean activate_children_connections_only)
|
2023-04-28 13:08:10 +02:00
|
|
|
{
|
2024-07-29 14:42:05 -04:00
|
|
|
const char *controller_device;
|
|
|
|
|
const char *controller_uuid_settings = NULL;
|
|
|
|
|
const char *controller_uuid_applied = NULL;
|
|
|
|
|
const char *parent_mac_addr = NULL;
|
2023-04-28 13:08:10 +02:00
|
|
|
NMActRequest *req;
|
|
|
|
|
|
2024-07-29 14:42:05 -04:00
|
|
|
controller_device = nm_device_get_iface(device);
|
|
|
|
|
nm_assert(controller_device);
|
|
|
|
|
|
|
|
|
|
parent_mac_addr = nm_device_get_permanent_hw_address(device);
|
2023-04-28 13:08:10 +02:00
|
|
|
|
|
|
|
|
req = nm_device_get_act_request(device);
|
|
|
|
|
if (req) {
|
|
|
|
|
NMConnection *connection;
|
|
|
|
|
NMSettingsConnection *sett_conn;
|
|
|
|
|
|
2023-05-05 10:11:18 +02:00
|
|
|
sett_conn = nm_active_connection_get_settings_connection(NM_ACTIVE_CONNECTION(req));
|
|
|
|
|
if (sett_conn)
|
2024-07-29 14:42:05 -04:00
|
|
|
controller_uuid_settings = nm_settings_connection_get_uuid(sett_conn);
|
2023-05-05 10:11:18 +02:00
|
|
|
|
2023-04-28 13:08:10 +02:00
|
|
|
connection = nm_active_connection_get_applied_connection(NM_ACTIVE_CONNECTION(req));
|
|
|
|
|
if (connection)
|
2024-07-29 14:42:05 -04:00
|
|
|
controller_uuid_applied = nm_connection_get_uuid(connection);
|
2023-04-28 13:08:10 +02:00
|
|
|
|
2024-07-29 14:42:05 -04:00
|
|
|
if (nm_streq0(controller_uuid_settings, controller_uuid_applied))
|
|
|
|
|
controller_uuid_applied = NULL;
|
2023-04-28 13:08:10 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-29 14:42:05 -04:00
|
|
|
if (!activate_children_connections_only) {
|
|
|
|
|
unblock_autoconnect_for_ports(self,
|
|
|
|
|
controller_device,
|
|
|
|
|
controller_uuid_settings,
|
2025-02-12 10:58:39 +01:00
|
|
|
controller_uuid_applied);
|
2024-07-29 14:42:05 -04:00
|
|
|
}
|
|
|
|
|
unblock_autoconnect_for_children(self,
|
|
|
|
|
controller_device,
|
|
|
|
|
controller_uuid_settings,
|
|
|
|
|
controller_uuid_applied,
|
2025-02-12 10:58:39 +01:00
|
|
|
parent_mac_addr);
|
2023-04-28 13:08:10 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-21 17:49:41 +02:00
|
|
|
static gboolean
|
2016-03-29 10:46:07 +02:00
|
|
|
activate_secondary_connections(NMPolicy *self, NMConnection *connection, NMDevice *device)
|
2012-08-21 17:49:41 +02:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
NMActiveConnection *ac;
|
|
|
|
|
PendingSecondaryData *secondary_data;
|
|
|
|
|
GSList *secondary_ac_list = NULL;
|
|
|
|
|
GError *error = NULL;
|
2012-08-21 17:49:41 +02:00
|
|
|
guint32 i;
|
|
|
|
|
gboolean success = TRUE;
|
core: improve and fix keeping connection active based on "connection.permissions"
By setting "connection.permissions", a profile is restricted to a
particular user.
That means for example, that another user cannot see, modify, delete,
activate or deactivate the profile. It also means, that the profile
will only autoconnect when the user is logged in (has a session).
Note that root is always able to activate the profile. Likewise, the
user is also allowed to manually activate the own profile, even if no
session currently exists (which can easily happen with `sudo`).
When the user logs out (the session goes away), we want do disconnect
the profile, however there are conflicting goals here:
1) if the profile was activate by root user, then logging out the user
should not disconnect the profile. The patch fixes that by not
binding the activation to the connection, if the activation is done
by the root user.
2) if the profile was activated by the owner when it had no session,
then it should stay alive until the user logs in (once) and logs
out again. This is already handled by the previous commit.
Yes, this point is odd. If you first do
$ sudo -u $OTHER_USER nmcli connection up $PROFILE
the profile activates despite not having a session. If you then
$ ssh guest@localhost nmcli device
you'll still see the profile active. However, the moment the SSH session
ends, a session closes and the profile disconnects. It's unclear, how to
solve that any better. I think, a user who cares about this, should not
activate the profile without having a session in the first place.
There are quite some special cases, in particular with internal
activations. In those cases we need to decide whether to bind the
activation to the profile's visibility.
Also, expose the "bind" setting in the D-Bus API. Note, that in the future
this flag may be modified via D-Bus API. Like we may also add related API
that allows to tweak the lifetime of the activation.
Also, I think we broke handling of connection visiblity with 37e8c53eeed
"core: Introduce helper class to track connection keep alive". This
should be fixed now too, with improved behavior.
Fixes: 37e8c53eeed579fe34a68819cd12f3295d581394
https://bugzilla.redhat.com/show_bug.cgi?id=1530977
2018-11-21 13:30:16 +01:00
|
|
|
NMActivationStateFlags initial_state_flags;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2012-08-21 17:49:41 +02:00
|
|
|
s_con = nm_connection_get_setting_connection(connection);
|
core: improve and fix keeping connection active based on "connection.permissions"
By setting "connection.permissions", a profile is restricted to a
particular user.
That means for example, that another user cannot see, modify, delete,
activate or deactivate the profile. It also means, that the profile
will only autoconnect when the user is logged in (has a session).
Note that root is always able to activate the profile. Likewise, the
user is also allowed to manually activate the own profile, even if no
session currently exists (which can easily happen with `sudo`).
When the user logs out (the session goes away), we want do disconnect
the profile, however there are conflicting goals here:
1) if the profile was activate by root user, then logging out the user
should not disconnect the profile. The patch fixes that by not
binding the activation to the connection, if the activation is done
by the root user.
2) if the profile was activated by the owner when it had no session,
then it should stay alive until the user logs in (once) and logs
out again. This is already handled by the previous commit.
Yes, this point is odd. If you first do
$ sudo -u $OTHER_USER nmcli connection up $PROFILE
the profile activates despite not having a session. If you then
$ ssh guest@localhost nmcli device
you'll still see the profile active. However, the moment the SSH session
ends, a session closes and the profile disconnects. It's unclear, how to
solve that any better. I think, a user who cares about this, should not
activate the profile without having a session in the first place.
There are quite some special cases, in particular with internal
activations. In those cases we need to decide whether to bind the
activation to the profile's visibility.
Also, expose the "bind" setting in the D-Bus API. Note, that in the future
this flag may be modified via D-Bus API. Like we may also add related API
that allows to tweak the lifetime of the activation.
Also, I think we broke handling of connection visiblity with 37e8c53eeed
"core: Introduce helper class to track connection keep alive". This
should be fixed now too, with improved behavior.
Fixes: 37e8c53eeed579fe34a68819cd12f3295d581394
https://bugzilla.redhat.com/show_bug.cgi?id=1530977
2018-11-21 13:30:16 +01:00
|
|
|
nm_assert(NM_IS_SETTING_CONNECTION(s_con));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
core: improve and fix keeping connection active based on "connection.permissions"
By setting "connection.permissions", a profile is restricted to a
particular user.
That means for example, that another user cannot see, modify, delete,
activate or deactivate the profile. It also means, that the profile
will only autoconnect when the user is logged in (has a session).
Note that root is always able to activate the profile. Likewise, the
user is also allowed to manually activate the own profile, even if no
session currently exists (which can easily happen with `sudo`).
When the user logs out (the session goes away), we want do disconnect
the profile, however there are conflicting goals here:
1) if the profile was activate by root user, then logging out the user
should not disconnect the profile. The patch fixes that by not
binding the activation to the connection, if the activation is done
by the root user.
2) if the profile was activated by the owner when it had no session,
then it should stay alive until the user logs in (once) and logs
out again. This is already handled by the previous commit.
Yes, this point is odd. If you first do
$ sudo -u $OTHER_USER nmcli connection up $PROFILE
the profile activates despite not having a session. If you then
$ ssh guest@localhost nmcli device
you'll still see the profile active. However, the moment the SSH session
ends, a session closes and the profile disconnects. It's unclear, how to
solve that any better. I think, a user who cares about this, should not
activate the profile without having a session in the first place.
There are quite some special cases, in particular with internal
activations. In those cases we need to decide whether to bind the
activation to the profile's visibility.
Also, expose the "bind" setting in the D-Bus API. Note, that in the future
this flag may be modified via D-Bus API. Like we may also add related API
that allows to tweak the lifetime of the activation.
Also, I think we broke handling of connection visiblity with 37e8c53eeed
"core: Introduce helper class to track connection keep alive". This
should be fixed now too, with improved behavior.
Fixes: 37e8c53eeed579fe34a68819cd12f3295d581394
https://bugzilla.redhat.com/show_bug.cgi?id=1530977
2018-11-21 13:30:16 +01:00
|
|
|
/* we propagate the activation's state flags. */
|
|
|
|
|
initial_state_flags = nm_device_get_activation_state_flags(device)
|
|
|
|
|
& NM_ACTIVATION_STATE_FLAG_LIFETIME_BOUND_TO_PROFILE_VISIBILITY;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2012-08-21 17:49:41 +02:00
|
|
|
for (i = 0; i < nm_setting_connection_get_num_secondaries(s_con); i++) {
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
NMSettingsConnection *sett_conn;
|
2021-11-09 13:28:54 +01:00
|
|
|
const char *sec_uuid = nm_setting_connection_get_secondary(s_con, i);
|
|
|
|
|
NMActRequest *req;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
sett_conn = nm_settings_get_connection_by_uuid(priv->settings, sec_uuid);
|
|
|
|
|
if (!sett_conn) {
|
2016-03-03 09:20:18 +01:00
|
|
|
_LOGW(LOGD_DEVICE,
|
|
|
|
|
"secondary connection '%s' auto-activation failed: The connection doesn't exist.",
|
|
|
|
|
sec_uuid);
|
2012-08-21 17:49:41 +02:00
|
|
|
success = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
if (!nm_connection_is_type(nm_settings_connection_get_connection(sett_conn),
|
|
|
|
|
NM_SETTING_VPN_SETTING_NAME)) {
|
2016-03-03 09:20:18 +01:00
|
|
|
_LOGW(LOGD_DEVICE,
|
|
|
|
|
"secondary connection '%s (%s)' auto-activation failed: The connection is not a "
|
|
|
|
|
"VPN.",
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
nm_settings_connection_get_id(sett_conn),
|
|
|
|
|
sec_uuid);
|
2013-11-06 10:35:59 -05:00
|
|
|
success = FALSE;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-11-06 10:35:59 -05:00
|
|
|
req = nm_device_get_act_request(device);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-03-03 09:20:18 +01:00
|
|
|
_LOGD(LOGD_DEVICE,
|
|
|
|
|
"activating secondary connection '%s (%s)' for base connection '%s (%s)'",
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
nm_settings_connection_get_id(sett_conn),
|
|
|
|
|
sec_uuid,
|
2016-03-03 09:20:18 +01:00
|
|
|
nm_connection_get_id(connection),
|
|
|
|
|
nm_connection_get_uuid(connection));
|
2013-11-06 10:35:59 -05:00
|
|
|
ac = nm_manager_activate_connection(
|
|
|
|
|
priv->manager,
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
sett_conn,
|
2016-09-07 17:47:26 +02:00
|
|
|
NULL,
|
core/dbus: rework D-Bus implementation to use lower layer GDBusConnection API
Previously, we used the generated GDBusInterfaceSkeleton types and glued
them via the NMExportedObject base class to our NM types. We also used
GDBusObjectManagerServer.
Don't do that anymore. The resulting code was more complicated despite (or
because?) using generated classes. It was hard to understand, complex, had
ordering-issues, and had a runtime and memory overhead.
This patch refactors this entirely and uses the lower layer API GDBusConnection
directly. It replaces the generated code, GDBusInterfaceSkeleton, and
GDBusObjectManagerServer. All this is now done by NMDbusObject and NMDBusManager
and static descriptor instances of type GDBusInterfaceInfo.
This adds a net plus of more then 1300 lines of hand written code. I claim
that this implementation is easier to understand. Note that previously we
also required extensive and complex glue code to bind our objects to the
generated skeleton objects. Instead, now glue our objects directly to
GDBusConnection. The result is more immediate and gets rid of layers of
code in between.
Now that the D-Bus glue us more under our control, we can address issus and
bottlenecks better, instead of adding code to bend the generated skeletons
to our needs.
Note that the current implementation now only supports one D-Bus connection.
That was effectively the case already, although there were places (and still are)
where the code pretends it could also support connections from a private socket.
We dropped private socket support mainly because it was unused, untested and
buggy, but also because GDBusObjectManagerServer could not export the same
objects on multiple connections. Now, it would be rather straight forward to
fix that and re-introduce ObjectManager on each private connection. But this
commit doesn't do that yet, and the new code intentionally supports only one
D-Bus connection.
Also, the D-Bus startup was simplified. There is no retry, either nm_dbus_manager_start()
succeeds, or it detects the initrd case. In the initrd case, bus manager never tries to
connect to D-Bus. Since the initrd scenario is not yet used/tested, this is good enough
for the moment. It could be easily extended later, for example with polling whether the
system bus appears (like was done previously). Also, restart of D-Bus daemon isn't
supported either -- just like before.
Note how NMDBusManager now implements the ObjectManager D-Bus interface
directly.
Also, this fixes race issues in the server, by no longer delaying
PropertiesChanged signals. NMExportedObject would collect changed
properties and send the signal out in idle_emit_properties_changed()
on idle. This messes up the ordering of change events w.r.t. other
signals and events on the bus. Note that not only NMExportedObject
messed up the ordering. Also the generated code would hook into
notify() and process change events in and idle handle, exhibiting the
same ordering issue too.
No longer do that. PropertiesChanged signals will be sent right away
by hooking into dispatch_properties_changed(). This means, changing
a property in quick succession will no longer be combined and is
guaranteed to emit signals for each individual state. Quite possibly
we emit now more PropertiesChanged signals then before.
However, we are now able to group a set of changes by using standard
g_object_freeze_notify()/g_object_thaw_notify(). We probably should
make more use of that.
Also, now that our signals are all handled in the right order, we
might find places where we still emit them in the wrong order. But that
is then due to the order in which our GObjects emit signals, not due
to an ill behavior of the D-Bus glue. Possibly we need to identify
such ordering issues and fix them.
Numbers (for contrib/rpm --without debug on x86_64):
- the patch changes the code size of NetworkManager by
- 2809360 bytes
+ 2537528 bytes (-9.7%)
- Runtime measurements are harder because there is a large variance
during testing. In other words, the numbers are not reproducible.
Currently, the implementation performs no caching of GVariants at all,
but it would be rather simple to add it, if that turns out to be
useful.
Anyway, without strong claim, it seems that the new form tends to
perform slightly better. That would be no surprise.
$ time (for i in {1..1000}; do nmcli >/dev/null || break; echo -n .; done)
- real 1m39.355s
+ real 1m37.432s
$ time (for i in {1..2000}; do busctl call org.freedesktop.NetworkManager /org/freedesktop org.freedesktop.DBus.ObjectManager GetManagedObjects > /dev/null || break; echo -n .; done)
- real 0m26.843s
+ real 0m25.281s
- Regarding RSS size, just looking at the processes in similar
conditions, doesn't give a large difference. On my system they
consume about 19MB RSS. It seems that the new version has a
slightly smaller RSS size.
- 19356 RSS
+ 18660 RSS
2018-02-26 13:51:52 +01:00
|
|
|
nm_dbus_object_get_path(NM_DBUS_OBJECT(req)),
|
2013-11-06 10:35:59 -05:00
|
|
|
device,
|
|
|
|
|
nm_active_connection_get_subject(NM_ACTIVE_CONNECTION(req)),
|
2017-03-07 11:04:36 +01:00
|
|
|
NM_ACTIVATION_TYPE_MANAGED,
|
2018-03-28 17:18:04 +02:00
|
|
|
nm_active_connection_get_activation_reason(NM_ACTIVE_CONNECTION(req)),
|
core: improve and fix keeping connection active based on "connection.permissions"
By setting "connection.permissions", a profile is restricted to a
particular user.
That means for example, that another user cannot see, modify, delete,
activate or deactivate the profile. It also means, that the profile
will only autoconnect when the user is logged in (has a session).
Note that root is always able to activate the profile. Likewise, the
user is also allowed to manually activate the own profile, even if no
session currently exists (which can easily happen with `sudo`).
When the user logs out (the session goes away), we want do disconnect
the profile, however there are conflicting goals here:
1) if the profile was activate by root user, then logging out the user
should not disconnect the profile. The patch fixes that by not
binding the activation to the connection, if the activation is done
by the root user.
2) if the profile was activated by the owner when it had no session,
then it should stay alive until the user logs in (once) and logs
out again. This is already handled by the previous commit.
Yes, this point is odd. If you first do
$ sudo -u $OTHER_USER nmcli connection up $PROFILE
the profile activates despite not having a session. If you then
$ ssh guest@localhost nmcli device
you'll still see the profile active. However, the moment the SSH session
ends, a session closes and the profile disconnects. It's unclear, how to
solve that any better. I think, a user who cares about this, should not
activate the profile without having a session in the first place.
There are quite some special cases, in particular with internal
activations. In those cases we need to decide whether to bind the
activation to the profile's visibility.
Also, expose the "bind" setting in the D-Bus API. Note, that in the future
this flag may be modified via D-Bus API. Like we may also add related API
that allows to tweak the lifetime of the activation.
Also, I think we broke handling of connection visiblity with 37e8c53eeed
"core: Introduce helper class to track connection keep alive". This
should be fixed now too, with improved behavior.
Fixes: 37e8c53eeed579fe34a68819cd12f3295d581394
https://bugzilla.redhat.com/show_bug.cgi?id=1530977
2018-11-21 13:30:16 +01:00
|
|
|
initial_state_flags,
|
2013-11-06 10:35:59 -05:00
|
|
|
&error);
|
|
|
|
|
if (ac)
|
|
|
|
|
secondary_ac_list = g_slist_append(secondary_ac_list, g_object_ref(ac));
|
|
|
|
|
else {
|
2016-03-03 09:20:18 +01:00
|
|
|
_LOGW(LOGD_DEVICE,
|
|
|
|
|
"secondary connection '%s (%s)' auto-activation failed: (%d) %s",
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
nm_settings_connection_get_id(sett_conn),
|
|
|
|
|
sec_uuid,
|
2016-03-03 09:20:18 +01:00
|
|
|
error->code,
|
|
|
|
|
error->message);
|
2013-11-06 10:35:59 -05:00
|
|
|
g_clear_error(&error);
|
|
|
|
|
success = FALSE;
|
|
|
|
|
break;
|
2012-08-21 17:49:41 +02:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
|
|
|
|
|
2012-08-21 17:49:41 +02:00
|
|
|
if (success && secondary_ac_list != NULL) {
|
|
|
|
|
secondary_data = pending_secondary_data_new(device, secondary_ac_list);
|
2013-08-22 10:10:17 -04:00
|
|
|
priv->pending_secondaries = g_slist_append(priv->pending_secondaries, secondary_data);
|
2012-08-21 17:49:41 +02:00
|
|
|
} else
|
2013-10-07 17:35:03 -05:00
|
|
|
g_slist_free_full(secondary_ac_list, g_object_unref);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2012-08-21 17:49:41 +02:00
|
|
|
return success;
|
|
|
|
|
}
|
|
|
|
|
|
2007-02-08 15:34:26 +00:00
|
|
|
static void
|
2021-11-09 13:28:54 +01:00
|
|
|
device_state_changed(NMDevice *device,
|
2008-07-11 10:28:53 +00:00
|
|
|
NMDeviceState new_state,
|
|
|
|
|
NMDeviceState old_state,
|
|
|
|
|
NMDeviceStateReason reason,
|
|
|
|
|
gpointer user_data)
|
2007-02-08 15:34:26 +00:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = user_data;
|
|
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
|
|
|
|
NMActiveConnection *ac;
|
2025-04-30 12:21:23 +02:00
|
|
|
NMSettingsConnection *sett_conn = nm_device_get_settings_connection(device);
|
|
|
|
|
NMSettingConnection *s_con = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-10-25 21:29:45 +02:00
|
|
|
switch (nm_device_state_reason_check(reason)) {
|
|
|
|
|
case NM_DEVICE_STATE_REASON_GSM_SIM_PIN_REQUIRED:
|
|
|
|
|
case NM_DEVICE_STATE_REASON_GSM_SIM_PUK_REQUIRED:
|
|
|
|
|
case NM_DEVICE_STATE_REASON_SIM_PIN_INCORRECT:
|
|
|
|
|
case NM_DEVICE_STATE_REASON_GSM_APN_FAILED:
|
2018-12-11 15:50:41 +01:00
|
|
|
/* Block autoconnection at settings level if there is any settings-specific
|
|
|
|
|
* error reported by the modem (e.g. wrong SIM-PIN or wrong APN). Do not block
|
|
|
|
|
* autoconnection at settings level for errors in the device domain (e.g.
|
|
|
|
|
* a missing SIM or wrong modem initialization).
|
2017-10-25 21:29:45 +02:00
|
|
|
*/
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
if (sett_conn) {
|
2023-02-15 10:35:08 +01:00
|
|
|
nm_manager_devcon_autoconnect_blocked_reason_set(
|
|
|
|
|
priv->manager,
|
|
|
|
|
device,
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
sett_conn,
|
2023-02-09 21:04:15 +01:00
|
|
|
NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED,
|
2017-11-24 10:53:39 +01:00
|
|
|
TRUE);
|
2017-10-25 21:29:45 +02:00
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2008-07-11 10:28:53 +00:00
|
|
|
switch (new_state) {
|
2008-04-07 Dan Williams <dcbw@redhat.com>
* include/NetworkManager.h
- Remove the DOWN and CANCELLED device states
- Add UNMANAGED and UNAVAILABLE device states
- Document the device states
* introspection/nm-device.xml
src/nm-device-interface.c
src/nm-device-interface.h
- Add the 'managed' property
* test/nm-tool.c
- (detail_device): print out device state
* src/NetworkManagerSystem.h
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerDebian.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerMandriva.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerSuSE.c
- (nm_system_device_get_system_config, nm_system_device_get_disabled
nm_system_device_free_system_config): remove; they were unused and
their functionality should be re-implemented in each distro's
system settings service plugin
* src/nm-gsm-device.c
src/nm-gsm-device.h
src/nm-cdma-device.c
src/nm-cdma-device.h
- (*_new): take the 'managed' argument
* src/nm-device.c
- (nm_device_set_address): remove, fold into nm_device_bring_up()
- (nm_device_init): start in unmanaged state, not disconnected
- (constructor): don't start device until the system settings service
has had a chance to figure out if the device is managed or not
- (nm_device_deactivate, nm_device_bring_up, nm_device_bring_down):
don't set device state here, let callers handle that as appropriate
- (nm_device_dispose): don't touch the device if it's not managed
- (set_property, get_property, nm_device_class_init): implement the
'managed' property
- (nm_device_state_changed): bring the device up if its now managed,
and deactivate it if it used to be active
- (nm_device_get_managed, nm_device_set_managed): do the right thing
with the managed state
* src/nm-hal-manager.c
- (wired_device_creator, wireless_device_creator, modem_device_creator):
take initial managed state and pass it along to device constructors
- (create_device_and_add_to_list): get managed state and pass to
type creators
* src/nm-device-802-11-wireless.c
- (real_can_activate): fold in most of
nm_device_802_11_wireless_can_activate()
- (can_scan): can't scan in UNAVAILABLE or UNMANAGED
- (link_timeout_cb): instead of deactivating, change device state and
let the device state handler to it
- (real_update_hw_address): clean up
- (state_changed_cb): when entering UNAVAILABLE state, schedule an idle
handler to transition to DISCONNECTED if the device isn't rfkilled
* src/nm-device-802-3-ethernet.c
- (set_carrier): move above callers and get rid of prototype
- (device_state_changed): when entering UNAVAILABLE state, schedule an
idle handler to transition to DISCONNECTED if the device has a
carrier
- (real_update_hw_address): clean up
- (link_timeout_cb, ppp_state_changed): change state instead of calling
deactivation directly as deactivation doesn't change state anymore
* src/NetworkManagerPolicy.c
- (schedule_activate_check): yay, remove wireless_enabled hack since
the NMManager and wireless devices work that out themselves now
- (device_state_changed): change to a switch and update for new device
states
- (device_carrier_changed): remove; device handles this now through
state changes
- (device_added): don't care about carrier any more; the initial
activation check will happen when the device transitions to
DISCONNECTED
* src/nm-manager.c
- (dispose): clear unmanaged devices
- (handle_unmanaged_devices): update unmanaged device list and toggle
the managed property on each device when needed
- (system_settings_properties_changed_cb): handle signals from the
system settings service
- (system_settings_get_unmanaged_devices_cb): handle callback from
getting the unmanaged device list method call
- (query_unmanaged_devices): ask the system settings service for its
list of unmanaged devices
- (nm_manager_name_owner_changed, initial_get_connections): get unmanaged
devices
- (manager_set_wireless_enabled): push rfkill state down to wireless
devices directly and let them handle the necessary state transitions
- (manager_device_state_changed): update for new device states
- (nm_manager_add_device): set initial rfkill state on wireless devices
- (nm_manager_remove_device): don't touch the device if it's unmanaged
- (nm_manager_activate_connection): return error if the device is
unmanaged
- (nm_manager_sleep): handle new device states correctly; don't change
the state of unavailable/unmanaged devices
* libnm-glib/nm-device-802-11-wireless.c
- (state_changed_cb): update for new device states
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3540 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-04-08 02:58:02 +00:00
|
|
|
case NM_DEVICE_STATE_FAILED:
|
2020-11-12 08:47:25 +01:00
|
|
|
g_signal_handlers_disconnect_by_func(device, device_dns_lookup_done, self);
|
|
|
|
|
|
2009-09-09 12:21:55 -07:00
|
|
|
/* Mark the connection invalid if it failed during activation so that
|
|
|
|
|
* it doesn't get automatically chosen over and over and over again.
|
|
|
|
|
*/
|
2011-11-17 22:56:51 -06:00
|
|
|
if (sett_conn && old_state >= NM_DEVICE_STATE_PREPARE
|
|
|
|
|
&& old_state <= NM_DEVICE_STATE_ACTIVATED) {
|
2020-07-16 11:58:20 +02:00
|
|
|
gboolean blocked = FALSE;
|
core: fix race of blocking autoconnect for no-secrets when a new secret-agent registers
When activation of the connection fails with no-secrets, we block
autoconnect due to that. However, NMPolicy also unblocks such
autoconnect, whenever a new secret-agent registers. The reason
is obviously, that the new secret-agent might be able to provide
the previously missing secrets.
However, there is a race between
- making the secret request, failing activation and blocking autoconnect
- new secret-agent registers
If the secret-agent registers after making the request, but before we
block autoconnect, then autoconnect stays blocked.
[1511468634.5759] device (wlp4s0): state change: config -> need-auth (reason 'none', sys-iface-state: 'managed')
[1511468634.5772] device (wlp4s0): No agents were available for this request.
[1511468638.4082] agent-manager: req[0x55ea7e58a5d0, :1.32/org.kde.plasma.networkmanagement/1000]: agent registered
[1511468638.4082] policy: re-enabling autoconnect for all connections with failed secrets
[1511468664.6280] device (wlp4s0): state change: need-auth -> failed (reason 'no-secrets', sys-iface-state: 'managed')
[1511468664.6287] policy: connection 'tuxmobil' now blocked from autoconnect due to no secrets
Note the long timing between making the secret request and the
activation failure. This race already existed before, but now with
WPS push-button method enabled by default, the duraction of the
activation is much longer and the race is easy to hit.
https://bugzilla.gnome.org/show_bug.cgi?id=790571
2017-11-27 09:33:32 +01:00
|
|
|
guint64 con_v;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2023-04-28 12:12:21 +02:00
|
|
|
switch (nm_device_state_reason_check(reason)) {
|
|
|
|
|
case NM_DEVICE_STATE_REASON_NO_SECRETS:
|
core: fix race of blocking autoconnect for no-secrets when a new secret-agent registers
When activation of the connection fails with no-secrets, we block
autoconnect due to that. However, NMPolicy also unblocks such
autoconnect, whenever a new secret-agent registers. The reason
is obviously, that the new secret-agent might be able to provide
the previously missing secrets.
However, there is a race between
- making the secret request, failing activation and blocking autoconnect
- new secret-agent registers
If the secret-agent registers after making the request, but before we
block autoconnect, then autoconnect stays blocked.
[1511468634.5759] device (wlp4s0): state change: config -> need-auth (reason 'none', sys-iface-state: 'managed')
[1511468634.5772] device (wlp4s0): No agents were available for this request.
[1511468638.4082] agent-manager: req[0x55ea7e58a5d0, :1.32/org.kde.plasma.networkmanagement/1000]: agent registered
[1511468638.4082] policy: re-enabling autoconnect for all connections with failed secrets
[1511468664.6280] device (wlp4s0): state change: need-auth -> failed (reason 'no-secrets', sys-iface-state: 'managed')
[1511468664.6287] policy: connection 'tuxmobil' now blocked from autoconnect due to no secrets
Note the long timing between making the secret request and the
activation failure. This race already existed before, but now with
WPS push-button method enabled by default, the duraction of the
activation is much longer and the race is easy to hit.
https://bugzilla.gnome.org/show_bug.cgi?id=790571
2017-11-27 09:33:32 +01:00
|
|
|
/* we want to block the connection from auto-connect if it failed due to no-secrets.
|
|
|
|
|
* However, if a secret-agent registered, since the connection made the last
|
|
|
|
|
* secret-request, we do not block it. The new secret-agent might not yet
|
|
|
|
|
* been consulted, and it may be able to provide the secrets.
|
|
|
|
|
*
|
|
|
|
|
* We detect this by using a version-id of the agent-manager, which increments
|
2018-03-06 13:04:00 +00:00
|
|
|
* whenever new agents register. Note that the agent-manager's version-id is
|
|
|
|
|
* never zero and strictly increasing.
|
|
|
|
|
*
|
|
|
|
|
* A connection's version-id of zero means that the connection never tried to request secrets.
|
|
|
|
|
* That can happen when nm_settings_connection_get_secrets() fails early without actually
|
|
|
|
|
* consulting any agents.
|
|
|
|
|
*/
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
con_v = nm_settings_connection_get_last_secret_agent_version_id(sett_conn);
|
2020-07-16 11:58:20 +02:00
|
|
|
if (con_v == 0 || con_v == nm_agent_manager_get_agent_version_id(priv->agent_mgr)) {
|
|
|
|
|
_LOGD(LOGD_DEVICE,
|
2025-02-10 12:53:26 +01:00
|
|
|
"block-autoconnect: connection[" NM_HASH_OBFUSCATE_PTR_FMT
|
|
|
|
|
"] (%s) now blocked from "
|
|
|
|
|
"autoconnect due to no secrets",
|
|
|
|
|
NM_HASH_OBFUSCATE_PTR(sett_conn),
|
2020-07-16 11:58:20 +02:00
|
|
|
nm_settings_connection_get_id(sett_conn));
|
|
|
|
|
nm_settings_connection_autoconnect_blocked_reason_set(
|
|
|
|
|
sett_conn,
|
2023-02-09 21:04:15 +01:00
|
|
|
NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_NO_SECRETS,
|
2020-07-16 11:58:20 +02:00
|
|
|
TRUE);
|
|
|
|
|
blocked = TRUE;
|
|
|
|
|
}
|
2023-04-28 12:12:21 +02:00
|
|
|
break;
|
|
|
|
|
case NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED:
|
2024-07-29 14:42:05 -04:00
|
|
|
/* A connection that fails due to dependency-failed is not able to
|
|
|
|
|
* reconnect until the connection it depends on activates again;
|
|
|
|
|
* when this happens, the controller or parent clears the blocked
|
|
|
|
|
* reason for all its dependent devices in activate_port_or_children_connections()
|
|
|
|
|
* and tries to reconnect them. For this to work, the port should
|
|
|
|
|
* be marked as blocked when it fails with dependency-failed.
|
2020-07-16 11:58:20 +02:00
|
|
|
*/
|
|
|
|
|
_LOGD(LOGD_DEVICE,
|
2025-02-10 12:53:26 +01:00
|
|
|
"block-autoconnect: connection[" NM_HASH_OBFUSCATE_PTR_FMT
|
|
|
|
|
"] (%s) now blocked "
|
|
|
|
|
"from autoconnect due to failed dependency",
|
|
|
|
|
NM_HASH_OBFUSCATE_PTR(sett_conn),
|
2020-07-16 11:58:20 +02:00
|
|
|
nm_settings_connection_get_id(sett_conn));
|
2023-02-15 10:35:08 +01:00
|
|
|
nm_manager_devcon_autoconnect_blocked_reason_set(
|
|
|
|
|
priv->manager,
|
|
|
|
|
device,
|
2020-07-16 11:58:20 +02:00
|
|
|
sett_conn,
|
2023-02-09 21:04:15 +01:00
|
|
|
NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED,
|
2020-07-16 11:58:20 +02:00
|
|
|
TRUE);
|
|
|
|
|
blocked = TRUE;
|
2023-04-28 12:12:21 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
core: fix race of blocking autoconnect for no-secrets when a new secret-agent registers
When activation of the connection fails with no-secrets, we block
autoconnect due to that. However, NMPolicy also unblocks such
autoconnect, whenever a new secret-agent registers. The reason
is obviously, that the new secret-agent might be able to provide
the previously missing secrets.
However, there is a race between
- making the secret request, failing activation and blocking autoconnect
- new secret-agent registers
If the secret-agent registers after making the request, but before we
block autoconnect, then autoconnect stays blocked.
[1511468634.5759] device (wlp4s0): state change: config -> need-auth (reason 'none', sys-iface-state: 'managed')
[1511468634.5772] device (wlp4s0): No agents were available for this request.
[1511468638.4082] agent-manager: req[0x55ea7e58a5d0, :1.32/org.kde.plasma.networkmanagement/1000]: agent registered
[1511468638.4082] policy: re-enabling autoconnect for all connections with failed secrets
[1511468664.6280] device (wlp4s0): state change: need-auth -> failed (reason 'no-secrets', sys-iface-state: 'managed')
[1511468664.6287] policy: connection 'tuxmobil' now blocked from autoconnect due to no secrets
Note the long timing between making the secret request and the
activation failure. This race already existed before, but now with
WPS push-button method enabled by default, the duraction of the
activation is much longer and the race is easy to hit.
https://bugzilla.gnome.org/show_bug.cgi?id=790571
2017-11-27 09:33:32 +01:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-07-16 11:58:20 +02:00
|
|
|
if (!blocked) {
|
2023-02-15 10:35:08 +01:00
|
|
|
guint32 tries;
|
|
|
|
|
|
|
|
|
|
tries = nm_manager_devcon_autoconnect_retries_get(priv->manager, device, sett_conn);
|
|
|
|
|
if (tries == 0) {
|
|
|
|
|
/* blocked */
|
|
|
|
|
} else if (tries != NM_AUTOCONNECT_RETRIES_FOREVER) {
|
2017-10-04 13:57:15 +02:00
|
|
|
_LOGD(LOGD_DEVICE,
|
2025-02-10 12:53:26 +01:00
|
|
|
"autoconnect: connection[" NM_HASH_OBFUSCATE_PTR_FMT "] (%s): failed to "
|
|
|
|
|
"autoconnect; %u tries left",
|
|
|
|
|
NM_HASH_OBFUSCATE_PTR(sett_conn),
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
nm_settings_connection_get_id(sett_conn),
|
2023-02-15 10:35:08 +01:00
|
|
|
tries - 1u);
|
|
|
|
|
_connection_autoconnect_retries_set(self, device, sett_conn, tries - 1u);
|
|
|
|
|
} else {
|
2017-10-04 13:57:15 +02:00
|
|
|
_LOGD(LOGD_DEVICE,
|
2025-02-10 12:53:26 +01:00
|
|
|
"autoconnect: connection[" NM_HASH_OBFUSCATE_PTR_FMT "] (%s) failed to "
|
|
|
|
|
"autoconnect; infinite tries left",
|
|
|
|
|
NM_HASH_OBFUSCATE_PTR(sett_conn),
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
nm_settings_connection_get_id(sett_conn));
|
2011-04-01 18:50:58 -05:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
2007-10-08 18:07:36 +00:00
|
|
|
}
|
2008-04-07 Dan Williams <dcbw@redhat.com>
* include/NetworkManager.h
- Remove the DOWN and CANCELLED device states
- Add UNMANAGED and UNAVAILABLE device states
- Document the device states
* introspection/nm-device.xml
src/nm-device-interface.c
src/nm-device-interface.h
- Add the 'managed' property
* test/nm-tool.c
- (detail_device): print out device state
* src/NetworkManagerSystem.h
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerDebian.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerMandriva.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerSuSE.c
- (nm_system_device_get_system_config, nm_system_device_get_disabled
nm_system_device_free_system_config): remove; they were unused and
their functionality should be re-implemented in each distro's
system settings service plugin
* src/nm-gsm-device.c
src/nm-gsm-device.h
src/nm-cdma-device.c
src/nm-cdma-device.h
- (*_new): take the 'managed' argument
* src/nm-device.c
- (nm_device_set_address): remove, fold into nm_device_bring_up()
- (nm_device_init): start in unmanaged state, not disconnected
- (constructor): don't start device until the system settings service
has had a chance to figure out if the device is managed or not
- (nm_device_deactivate, nm_device_bring_up, nm_device_bring_down):
don't set device state here, let callers handle that as appropriate
- (nm_device_dispose): don't touch the device if it's not managed
- (set_property, get_property, nm_device_class_init): implement the
'managed' property
- (nm_device_state_changed): bring the device up if its now managed,
and deactivate it if it used to be active
- (nm_device_get_managed, nm_device_set_managed): do the right thing
with the managed state
* src/nm-hal-manager.c
- (wired_device_creator, wireless_device_creator, modem_device_creator):
take initial managed state and pass it along to device constructors
- (create_device_and_add_to_list): get managed state and pass to
type creators
* src/nm-device-802-11-wireless.c
- (real_can_activate): fold in most of
nm_device_802_11_wireless_can_activate()
- (can_scan): can't scan in UNAVAILABLE or UNMANAGED
- (link_timeout_cb): instead of deactivating, change device state and
let the device state handler to it
- (real_update_hw_address): clean up
- (state_changed_cb): when entering UNAVAILABLE state, schedule an idle
handler to transition to DISCONNECTED if the device isn't rfkilled
* src/nm-device-802-3-ethernet.c
- (set_carrier): move above callers and get rid of prototype
- (device_state_changed): when entering UNAVAILABLE state, schedule an
idle handler to transition to DISCONNECTED if the device has a
carrier
- (real_update_hw_address): clean up
- (link_timeout_cb, ppp_state_changed): change state instead of calling
deactivation directly as deactivation doesn't change state anymore
* src/NetworkManagerPolicy.c
- (schedule_activate_check): yay, remove wireless_enabled hack since
the NMManager and wireless devices work that out themselves now
- (device_state_changed): change to a switch and update for new device
states
- (device_carrier_changed): remove; device handles this now through
state changes
- (device_added): don't care about carrier any more; the initial
activation check will happen when the device transitions to
DISCONNECTED
* src/nm-manager.c
- (dispose): clear unmanaged devices
- (handle_unmanaged_devices): update unmanaged device list and toggle
the managed property on each device when needed
- (system_settings_properties_changed_cb): handle signals from the
system settings service
- (system_settings_get_unmanaged_devices_cb): handle callback from
getting the unmanaged device list method call
- (query_unmanaged_devices): ask the system settings service for its
list of unmanaged devices
- (nm_manager_name_owner_changed, initial_get_connections): get unmanaged
devices
- (manager_set_wireless_enabled): push rfkill state down to wireless
devices directly and let them handle the necessary state transitions
- (manager_device_state_changed): update for new device states
- (nm_manager_add_device): set initial rfkill state on wireless devices
- (nm_manager_remove_device): don't touch the device if it's unmanaged
- (nm_manager_activate_connection): return error if the device is
unmanaged
- (nm_manager_sleep): handle new device states correctly; don't change
the state of unavailable/unmanaged devices
* libnm-glib/nm-device-802-11-wireless.c
- (state_changed_cb): update for new device states
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3540 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-04-08 02:58:02 +00:00
|
|
|
break;
|
|
|
|
|
case NM_DEVICE_STATE_ACTIVATED:
|
2024-07-29 14:42:05 -04:00
|
|
|
if (nm_device_get_device_type(device) == NM_DEVICE_TYPE_OVS_INTERFACE) {
|
|
|
|
|
/* When parent is ovs-interface, the kernel link is only created in stage3, we have to
|
|
|
|
|
* delay unblocking the children and schedule them for activation until parent is activated */
|
|
|
|
|
activate_port_or_children_connections(self, device, TRUE);
|
|
|
|
|
}
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
if (sett_conn) {
|
2011-04-01 18:50:58 -05:00
|
|
|
/* Reset auto retries back to default since connection was successful */
|
2025-10-15 14:57:08 +02:00
|
|
|
nm_manager_devcon_autoconnect_reset_reconnect_all(priv->manager,
|
|
|
|
|
device,
|
|
|
|
|
sett_conn,
|
|
|
|
|
FALSE);
|
2010-04-06 12:48:53 -07:00
|
|
|
}
|
2022-01-19 12:03:04 +01:00
|
|
|
|
|
|
|
|
/* Since there is no guarantee that device_l3cd_changed() is called
|
|
|
|
|
* again when the device becomes ACTIVATED, we need also to update
|
|
|
|
|
* routing and DNS here. */
|
|
|
|
|
nm_dns_manager_begin_updates(priv->dns_manager, __func__);
|
2024-08-27 10:26:50 +02:00
|
|
|
if (!nm_device_managed_type_is_external(device)) {
|
2022-01-19 12:03:04 +01:00
|
|
|
nm_dns_manager_set_ip_config(priv->dns_manager,
|
|
|
|
|
AF_UNSPEC,
|
|
|
|
|
device,
|
|
|
|
|
nm_device_get_l3cd(device, TRUE),
|
2022-02-16 13:50:09 +01:00
|
|
|
nm_device_is_vpn(device) ? NM_DNS_IP_CONFIG_TYPE_VPN
|
|
|
|
|
: NM_DNS_IP_CONFIG_TYPE_DEFAULT,
|
2022-01-19 12:03:04 +01:00
|
|
|
TRUE);
|
|
|
|
|
}
|
|
|
|
|
update_ip_dns(self, AF_INET, device);
|
|
|
|
|
update_ip_dns(self, AF_INET6, device);
|
|
|
|
|
update_ip4_routing(self, TRUE);
|
|
|
|
|
update_ip6_routing(self, TRUE);
|
2024-07-31 17:08:43 +02:00
|
|
|
update_system_hostname(self, "routing and dns", TRUE);
|
2022-01-19 12:03:04 +01:00
|
|
|
nm_dns_manager_end_updates(priv->dns_manager, __func__);
|
|
|
|
|
|
2008-04-07 Dan Williams <dcbw@redhat.com>
* include/NetworkManager.h
- Remove the DOWN and CANCELLED device states
- Add UNMANAGED and UNAVAILABLE device states
- Document the device states
* introspection/nm-device.xml
src/nm-device-interface.c
src/nm-device-interface.h
- Add the 'managed' property
* test/nm-tool.c
- (detail_device): print out device state
* src/NetworkManagerSystem.h
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerDebian.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerMandriva.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerSuSE.c
- (nm_system_device_get_system_config, nm_system_device_get_disabled
nm_system_device_free_system_config): remove; they were unused and
their functionality should be re-implemented in each distro's
system settings service plugin
* src/nm-gsm-device.c
src/nm-gsm-device.h
src/nm-cdma-device.c
src/nm-cdma-device.h
- (*_new): take the 'managed' argument
* src/nm-device.c
- (nm_device_set_address): remove, fold into nm_device_bring_up()
- (nm_device_init): start in unmanaged state, not disconnected
- (constructor): don't start device until the system settings service
has had a chance to figure out if the device is managed or not
- (nm_device_deactivate, nm_device_bring_up, nm_device_bring_down):
don't set device state here, let callers handle that as appropriate
- (nm_device_dispose): don't touch the device if it's not managed
- (set_property, get_property, nm_device_class_init): implement the
'managed' property
- (nm_device_state_changed): bring the device up if its now managed,
and deactivate it if it used to be active
- (nm_device_get_managed, nm_device_set_managed): do the right thing
with the managed state
* src/nm-hal-manager.c
- (wired_device_creator, wireless_device_creator, modem_device_creator):
take initial managed state and pass it along to device constructors
- (create_device_and_add_to_list): get managed state and pass to
type creators
* src/nm-device-802-11-wireless.c
- (real_can_activate): fold in most of
nm_device_802_11_wireless_can_activate()
- (can_scan): can't scan in UNAVAILABLE or UNMANAGED
- (link_timeout_cb): instead of deactivating, change device state and
let the device state handler to it
- (real_update_hw_address): clean up
- (state_changed_cb): when entering UNAVAILABLE state, schedule an idle
handler to transition to DISCONNECTED if the device isn't rfkilled
* src/nm-device-802-3-ethernet.c
- (set_carrier): move above callers and get rid of prototype
- (device_state_changed): when entering UNAVAILABLE state, schedule an
idle handler to transition to DISCONNECTED if the device has a
carrier
- (real_update_hw_address): clean up
- (link_timeout_cb, ppp_state_changed): change state instead of calling
deactivation directly as deactivation doesn't change state anymore
* src/NetworkManagerPolicy.c
- (schedule_activate_check): yay, remove wireless_enabled hack since
the NMManager and wireless devices work that out themselves now
- (device_state_changed): change to a switch and update for new device
states
- (device_carrier_changed): remove; device handles this now through
state changes
- (device_added): don't care about carrier any more; the initial
activation check will happen when the device transitions to
DISCONNECTED
* src/nm-manager.c
- (dispose): clear unmanaged devices
- (handle_unmanaged_devices): update unmanaged device list and toggle
the managed property on each device when needed
- (system_settings_properties_changed_cb): handle signals from the
system settings service
- (system_settings_get_unmanaged_devices_cb): handle callback from
getting the unmanaged device list method call
- (query_unmanaged_devices): ask the system settings service for its
list of unmanaged devices
- (nm_manager_name_owner_changed, initial_get_connections): get unmanaged
devices
- (manager_set_wireless_enabled): push rfkill state down to wireless
devices directly and let them handle the necessary state transitions
- (manager_device_state_changed): update for new device states
- (nm_manager_add_device): set initial rfkill state on wireless devices
- (nm_manager_remove_device): don't touch the device if it's unmanaged
- (nm_manager_activate_connection): return error if the device is
unmanaged
- (nm_manager_sleep): handle new device states correctly; don't change
the state of unavailable/unmanaged devices
* libnm-glib/nm-device-802-11-wireless.c
- (state_changed_cb): update for new device states
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3540 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-04-08 02:58:02 +00:00
|
|
|
break;
|
2008-04-22 02:38:05 +00:00
|
|
|
case NM_DEVICE_STATE_UNMANAGED:
|
|
|
|
|
case NM_DEVICE_STATE_UNAVAILABLE:
|
2012-05-29 22:17:26 -05:00
|
|
|
if (old_state > NM_DEVICE_STATE_DISCONNECTED)
|
2020-03-17 10:52:29 +01:00
|
|
|
update_routing_and_dns(self, FALSE, device);
|
2011-04-19 00:31:53 -05:00
|
|
|
break;
|
2014-01-03 14:04:54 -05:00
|
|
|
case NM_DEVICE_STATE_DEACTIVATING:
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
if (sett_conn) {
|
2017-11-24 10:33:23 +01:00
|
|
|
NMSettingsAutoconnectBlockedReason blocked_reason =
|
2023-02-09 21:04:15 +01:00
|
|
|
NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_NONE;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-24 10:33:23 +01:00
|
|
|
switch (nm_device_state_reason_check(reason)) {
|
|
|
|
|
case NM_DEVICE_STATE_REASON_USER_REQUESTED:
|
2023-02-09 21:04:15 +01:00
|
|
|
blocked_reason = NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_USER_REQUEST;
|
2017-11-24 10:33:23 +01:00
|
|
|
break;
|
|
|
|
|
case NM_DEVICE_STATE_REASON_DEPENDENCY_FAILED:
|
2023-02-09 21:04:15 +01:00
|
|
|
blocked_reason = NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED;
|
2017-11-24 10:33:23 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-02-09 21:04:15 +01:00
|
|
|
if (blocked_reason != NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_NONE) {
|
2017-11-09 16:16:53 +01:00
|
|
|
_LOGD(LOGD_DEVICE,
|
2023-04-27 17:00:10 +02:00
|
|
|
"block-autoconnect: blocking autoconnect of connection '%s': %s",
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
nm_settings_connection_get_id(sett_conn),
|
2021-08-09 14:54:17 +02:00
|
|
|
NM_UTILS_LOOKUP_STR_A(nm_device_state_reason_to_string,
|
2019-01-10 09:17:28 +01:00
|
|
|
nm_device_state_reason_check(reason)));
|
2023-02-09 21:04:15 +01:00
|
|
|
if (blocked_reason == NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED)
|
2023-02-15 10:35:08 +01:00
|
|
|
nm_manager_devcon_autoconnect_blocked_reason_set(priv->manager,
|
|
|
|
|
device,
|
|
|
|
|
sett_conn,
|
|
|
|
|
blocked_reason,
|
|
|
|
|
TRUE);
|
|
|
|
|
else
|
|
|
|
|
nm_settings_connection_autoconnect_blocked_reason_set(sett_conn,
|
|
|
|
|
blocked_reason,
|
|
|
|
|
TRUE);
|
2013-12-17 10:09:47 -05:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
}
|
2016-10-31 23:31:14 +01:00
|
|
|
ip6_remove_device_prefix_delegations(self, device);
|
2014-01-03 14:04:54 -05:00
|
|
|
break;
|
2008-04-07 Dan Williams <dcbw@redhat.com>
* include/NetworkManager.h
- Remove the DOWN and CANCELLED device states
- Add UNMANAGED and UNAVAILABLE device states
- Document the device states
* introspection/nm-device.xml
src/nm-device-interface.c
src/nm-device-interface.h
- Add the 'managed' property
* test/nm-tool.c
- (detail_device): print out device state
* src/NetworkManagerSystem.h
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerDebian.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerMandriva.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerSuSE.c
- (nm_system_device_get_system_config, nm_system_device_get_disabled
nm_system_device_free_system_config): remove; they were unused and
their functionality should be re-implemented in each distro's
system settings service plugin
* src/nm-gsm-device.c
src/nm-gsm-device.h
src/nm-cdma-device.c
src/nm-cdma-device.h
- (*_new): take the 'managed' argument
* src/nm-device.c
- (nm_device_set_address): remove, fold into nm_device_bring_up()
- (nm_device_init): start in unmanaged state, not disconnected
- (constructor): don't start device until the system settings service
has had a chance to figure out if the device is managed or not
- (nm_device_deactivate, nm_device_bring_up, nm_device_bring_down):
don't set device state here, let callers handle that as appropriate
- (nm_device_dispose): don't touch the device if it's not managed
- (set_property, get_property, nm_device_class_init): implement the
'managed' property
- (nm_device_state_changed): bring the device up if its now managed,
and deactivate it if it used to be active
- (nm_device_get_managed, nm_device_set_managed): do the right thing
with the managed state
* src/nm-hal-manager.c
- (wired_device_creator, wireless_device_creator, modem_device_creator):
take initial managed state and pass it along to device constructors
- (create_device_and_add_to_list): get managed state and pass to
type creators
* src/nm-device-802-11-wireless.c
- (real_can_activate): fold in most of
nm_device_802_11_wireless_can_activate()
- (can_scan): can't scan in UNAVAILABLE or UNMANAGED
- (link_timeout_cb): instead of deactivating, change device state and
let the device state handler to it
- (real_update_hw_address): clean up
- (state_changed_cb): when entering UNAVAILABLE state, schedule an idle
handler to transition to DISCONNECTED if the device isn't rfkilled
* src/nm-device-802-3-ethernet.c
- (set_carrier): move above callers and get rid of prototype
- (device_state_changed): when entering UNAVAILABLE state, schedule an
idle handler to transition to DISCONNECTED if the device has a
carrier
- (real_update_hw_address): clean up
- (link_timeout_cb, ppp_state_changed): change state instead of calling
deactivation directly as deactivation doesn't change state anymore
* src/NetworkManagerPolicy.c
- (schedule_activate_check): yay, remove wireless_enabled hack since
the NMManager and wireless devices work that out themselves now
- (device_state_changed): change to a switch and update for new device
states
- (device_carrier_changed): remove; device handles this now through
state changes
- (device_added): don't care about carrier any more; the initial
activation check will happen when the device transitions to
DISCONNECTED
* src/nm-manager.c
- (dispose): clear unmanaged devices
- (handle_unmanaged_devices): update unmanaged device list and toggle
the managed property on each device when needed
- (system_settings_properties_changed_cb): handle signals from the
system settings service
- (system_settings_get_unmanaged_devices_cb): handle callback from
getting the unmanaged device list method call
- (query_unmanaged_devices): ask the system settings service for its
list of unmanaged devices
- (nm_manager_name_owner_changed, initial_get_connections): get unmanaged
devices
- (manager_set_wireless_enabled): push rfkill state down to wireless
devices directly and let them handle the necessary state transitions
- (manager_device_state_changed): update for new device states
- (nm_manager_add_device): set initial rfkill state on wireless devices
- (nm_manager_remove_device): don't touch the device if it's unmanaged
- (nm_manager_activate_connection): return error if the device is
unmanaged
- (nm_manager_sleep): handle new device states correctly; don't change
the state of unavailable/unmanaged devices
* libnm-glib/nm-device-802-11-wireless.c
- (state_changed_cb): update for new device states
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3540 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-04-08 02:58:02 +00:00
|
|
|
case NM_DEVICE_STATE_DISCONNECTED:
|
2020-11-12 08:47:25 +01:00
|
|
|
g_signal_handlers_disconnect_by_func(device, device_dns_lookup_done, self);
|
|
|
|
|
|
2013-12-05 04:57:01 -05:00
|
|
|
/* Reset retry counts for a device's connections when carrier on; if cable
|
|
|
|
|
* was unplugged and plugged in again, we should try to reconnect.
|
|
|
|
|
*/
|
2017-02-23 15:19:03 +01:00
|
|
|
if (nm_device_state_reason_check(reason) == NM_DEVICE_STATE_REASON_CARRIER
|
|
|
|
|
&& old_state == NM_DEVICE_STATE_UNAVAILABLE)
|
2017-11-22 14:52:54 +01:00
|
|
|
reset_autoconnect_all(self, device, FALSE);
|
2011-05-30 12:07:41 +01:00
|
|
|
|
2017-12-16 15:11:16 +01:00
|
|
|
if (old_state > NM_DEVICE_STATE_DISCONNECTED)
|
2020-03-17 10:52:29 +01:00
|
|
|
update_routing_and_dns(self, FALSE, device);
|
2012-05-29 22:17:26 -05:00
|
|
|
|
2011-04-19 00:31:53 -05:00
|
|
|
/* Device is now available for auto-activation */
|
2023-04-05 10:57:57 +02:00
|
|
|
nm_policy_device_recheck_auto_activate_schedule(self, device);
|
2008-04-07 Dan Williams <dcbw@redhat.com>
* include/NetworkManager.h
- Remove the DOWN and CANCELLED device states
- Add UNMANAGED and UNAVAILABLE device states
- Document the device states
* introspection/nm-device.xml
src/nm-device-interface.c
src/nm-device-interface.h
- Add the 'managed' property
* test/nm-tool.c
- (detail_device): print out device state
* src/NetworkManagerSystem.h
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerDebian.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerMandriva.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerSuSE.c
- (nm_system_device_get_system_config, nm_system_device_get_disabled
nm_system_device_free_system_config): remove; they were unused and
their functionality should be re-implemented in each distro's
system settings service plugin
* src/nm-gsm-device.c
src/nm-gsm-device.h
src/nm-cdma-device.c
src/nm-cdma-device.h
- (*_new): take the 'managed' argument
* src/nm-device.c
- (nm_device_set_address): remove, fold into nm_device_bring_up()
- (nm_device_init): start in unmanaged state, not disconnected
- (constructor): don't start device until the system settings service
has had a chance to figure out if the device is managed or not
- (nm_device_deactivate, nm_device_bring_up, nm_device_bring_down):
don't set device state here, let callers handle that as appropriate
- (nm_device_dispose): don't touch the device if it's not managed
- (set_property, get_property, nm_device_class_init): implement the
'managed' property
- (nm_device_state_changed): bring the device up if its now managed,
and deactivate it if it used to be active
- (nm_device_get_managed, nm_device_set_managed): do the right thing
with the managed state
* src/nm-hal-manager.c
- (wired_device_creator, wireless_device_creator, modem_device_creator):
take initial managed state and pass it along to device constructors
- (create_device_and_add_to_list): get managed state and pass to
type creators
* src/nm-device-802-11-wireless.c
- (real_can_activate): fold in most of
nm_device_802_11_wireless_can_activate()
- (can_scan): can't scan in UNAVAILABLE or UNMANAGED
- (link_timeout_cb): instead of deactivating, change device state and
let the device state handler to it
- (real_update_hw_address): clean up
- (state_changed_cb): when entering UNAVAILABLE state, schedule an idle
handler to transition to DISCONNECTED if the device isn't rfkilled
* src/nm-device-802-3-ethernet.c
- (set_carrier): move above callers and get rid of prototype
- (device_state_changed): when entering UNAVAILABLE state, schedule an
idle handler to transition to DISCONNECTED if the device has a
carrier
- (real_update_hw_address): clean up
- (link_timeout_cb, ppp_state_changed): change state instead of calling
deactivation directly as deactivation doesn't change state anymore
* src/NetworkManagerPolicy.c
- (schedule_activate_check): yay, remove wireless_enabled hack since
the NMManager and wireless devices work that out themselves now
- (device_state_changed): change to a switch and update for new device
states
- (device_carrier_changed): remove; device handles this now through
state changes
- (device_added): don't care about carrier any more; the initial
activation check will happen when the device transitions to
DISCONNECTED
* src/nm-manager.c
- (dispose): clear unmanaged devices
- (handle_unmanaged_devices): update unmanaged device list and toggle
the managed property on each device when needed
- (system_settings_properties_changed_cb): handle signals from the
system settings service
- (system_settings_get_unmanaged_devices_cb): handle callback from
getting the unmanaged device list method call
- (query_unmanaged_devices): ask the system settings service for its
list of unmanaged devices
- (nm_manager_name_owner_changed, initial_get_connections): get unmanaged
devices
- (manager_set_wireless_enabled): push rfkill state down to wireless
devices directly and let them handle the necessary state transitions
- (manager_device_state_changed): update for new device states
- (nm_manager_add_device): set initial rfkill state on wireless devices
- (nm_manager_remove_device): don't touch the device if it's unmanaged
- (nm_manager_activate_connection): return error if the device is
unmanaged
- (nm_manager_sleep): handle new device states correctly; don't change
the state of unavailable/unmanaged devices
* libnm-glib/nm-device-802-11-wireless.c
- (state_changed_cb): update for new device states
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3540 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-04-08 02:58:02 +00:00
|
|
|
break;
|
2011-12-07 13:15:24 +01:00
|
|
|
|
|
|
|
|
case NM_DEVICE_STATE_PREPARE:
|
2024-07-29 14:42:05 -04:00
|
|
|
/* Reset auto-connect retries of all ports or children and schedule them for
|
2011-12-07 13:15:24 +01:00
|
|
|
* activation. */
|
2024-07-29 14:42:05 -04:00
|
|
|
activate_port_or_children_connections(self, device, FALSE);
|
2017-09-25 22:20:47 +02:00
|
|
|
|
|
|
|
|
/* Now that the device state is progressing, we don't care
|
|
|
|
|
* anymore for the AC state. */
|
|
|
|
|
ac = (NMActiveConnection *) nm_device_get_act_request(device);
|
|
|
|
|
if (ac && g_hash_table_remove(priv->pending_active_connections, ac)) {
|
|
|
|
|
g_signal_handlers_disconnect_by_func(ac, pending_ac_state_changed, self);
|
|
|
|
|
g_object_weak_unref(G_OBJECT(ac), pending_ac_gone, self);
|
|
|
|
|
g_object_unref(self);
|
|
|
|
|
}
|
2011-12-07 13:15:24 +01:00
|
|
|
break;
|
2014-01-23 10:30:50 -05:00
|
|
|
case NM_DEVICE_STATE_IP_CONFIG:
|
|
|
|
|
/* We must have secrets if we got here. */
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
if (sett_conn)
|
2023-02-15 10:35:08 +01:00
|
|
|
nm_manager_devcon_autoconnect_blocked_reason_set(
|
|
|
|
|
priv->manager,
|
|
|
|
|
device,
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
sett_conn,
|
2023-05-02 14:19:14 +02:00
|
|
|
NM_SETTINGS_AUTOCONNECT_BLOCKED_REASON_FAILED,
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
FALSE);
|
2014-01-23 10:30:50 -05:00
|
|
|
break;
|
2012-08-21 17:49:41 +02:00
|
|
|
case NM_DEVICE_STATE_SECONDARIES:
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
if (sett_conn)
|
|
|
|
|
s_con = nm_connection_get_setting_connection(
|
|
|
|
|
nm_settings_connection_get_connection(sett_conn));
|
|
|
|
|
if (s_con && nm_setting_connection_get_num_secondaries(s_con) > 0) {
|
2012-08-21 17:49:41 +02:00
|
|
|
/* Make routes and DNS up-to-date before activating dependent connections */
|
2020-03-17 10:52:29 +01:00
|
|
|
update_routing_and_dns(self, FALSE, device);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2012-08-21 17:49:41 +02:00
|
|
|
/* Activate secondary (VPN) connections */
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
if (!activate_secondary_connections(self,
|
|
|
|
|
nm_settings_connection_get_connection(sett_conn),
|
|
|
|
|
device)) {
|
|
|
|
|
nm_device_queue_state(device,
|
|
|
|
|
NM_DEVICE_STATE_FAILED,
|
2012-10-05 16:41:02 -04:00
|
|
|
NM_DEVICE_STATE_REASON_SECONDARY_CONNECTION_FAILED);
|
settings: use delegation instead of inheritance for NMSettingsConnection and NMConnection
NMConnection is an interface, which is implemented by the types
NMSimpleConnection (libnm-core), NMSettingsConnection (src) and
NMRemoteConnection (libnm).
NMSettingsConnection does a lot of things already:
1) it "is-a" NMDBusObject and exports the API of a connection profile
on D-Bus
2) it interacts with NMSettings and contains functionality
for tracking the profiles.
3) it is the base-class of types like NMSKeyfileConnection and
NMIfcfgConnection. These handle how the profile is persisted
on disk.
4) it implements NMConnection interface, to itself track the
settings of the profile.
3) and 4) would be better implemented via delegation than inheritance.
Address 4) and don't let NMSettingsConnection implemente the NMConnection
interface. Instead, a settings-connection references now a NMSimpleConnection
instance, to which it delegates for keeping the actual profiles.
Advantages:
- by delegating, there is a clearer separation of what
NMSettingsConnection does. For example, in C we often required
casts from NMSettingsConnection to NMConnection. NMConnection
is a very trivial object with very little logic. When we have
a NMConnection instance at hand, it's good to know that it is
*only* that simple instead of also being an entire
NMSettingsConnection instance.
The main purpose of this patch is to simplify the code by separating
the NMConnection from the NMSettingsConnection. We should generally
be aware whether we handle a NMSettingsConnection or a trivial
NMConnection instance. Now, because NMSettingsConnection no longer
"is-a" NMConnection, this distinction is apparent.
- NMConnection is implemented as an interface and we create
NMSimpleConnection instances whenever we need a real instance.
In GLib, interfaces have a performance overhead, that we needlessly
pay all the time. With this change, we no longer require
NMConnection to be an interface. Thus, in the future we could compile
a version of libnm-core for the daemon, where NMConnection is not an
interface but a GObject implementation akin to NMSimpleConnection.
- In the previous implementation, we cannot treat NMConnection immutable
and copy-on-write.
For example, when NMDevice needs a snapshot of the activated
profile as applied-connection, all it can do is clone the entire
NMSettingsConnection as a NMSimpleConnection.
Likewise, when we get a NMConnection instance and want to keep
a reference to it, we cannot do that, because we never know
who also references and modifies the instance.
By separating NMSettingsConnection we could in the future have
NMConnection immutable and copy-on-write, to avoid all unnecessary
clones.
2018-08-11 11:08:17 +02:00
|
|
|
}
|
2012-08-21 17:49:41 +02:00
|
|
|
} else
|
2012-10-05 16:41:02 -04:00
|
|
|
nm_device_queue_state(device, NM_DEVICE_STATE_ACTIVATED, NM_DEVICE_STATE_REASON_NONE);
|
2012-08-21 17:49:41 +02:00
|
|
|
break;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2008-04-07 Dan Williams <dcbw@redhat.com>
* include/NetworkManager.h
- Remove the DOWN and CANCELLED device states
- Add UNMANAGED and UNAVAILABLE device states
- Document the device states
* introspection/nm-device.xml
src/nm-device-interface.c
src/nm-device-interface.h
- Add the 'managed' property
* test/nm-tool.c
- (detail_device): print out device state
* src/NetworkManagerSystem.h
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerDebian.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerMandriva.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerSuSE.c
- (nm_system_device_get_system_config, nm_system_device_get_disabled
nm_system_device_free_system_config): remove; they were unused and
their functionality should be re-implemented in each distro's
system settings service plugin
* src/nm-gsm-device.c
src/nm-gsm-device.h
src/nm-cdma-device.c
src/nm-cdma-device.h
- (*_new): take the 'managed' argument
* src/nm-device.c
- (nm_device_set_address): remove, fold into nm_device_bring_up()
- (nm_device_init): start in unmanaged state, not disconnected
- (constructor): don't start device until the system settings service
has had a chance to figure out if the device is managed or not
- (nm_device_deactivate, nm_device_bring_up, nm_device_bring_down):
don't set device state here, let callers handle that as appropriate
- (nm_device_dispose): don't touch the device if it's not managed
- (set_property, get_property, nm_device_class_init): implement the
'managed' property
- (nm_device_state_changed): bring the device up if its now managed,
and deactivate it if it used to be active
- (nm_device_get_managed, nm_device_set_managed): do the right thing
with the managed state
* src/nm-hal-manager.c
- (wired_device_creator, wireless_device_creator, modem_device_creator):
take initial managed state and pass it along to device constructors
- (create_device_and_add_to_list): get managed state and pass to
type creators
* src/nm-device-802-11-wireless.c
- (real_can_activate): fold in most of
nm_device_802_11_wireless_can_activate()
- (can_scan): can't scan in UNAVAILABLE or UNMANAGED
- (link_timeout_cb): instead of deactivating, change device state and
let the device state handler to it
- (real_update_hw_address): clean up
- (state_changed_cb): when entering UNAVAILABLE state, schedule an idle
handler to transition to DISCONNECTED if the device isn't rfkilled
* src/nm-device-802-3-ethernet.c
- (set_carrier): move above callers and get rid of prototype
- (device_state_changed): when entering UNAVAILABLE state, schedule an
idle handler to transition to DISCONNECTED if the device has a
carrier
- (real_update_hw_address): clean up
- (link_timeout_cb, ppp_state_changed): change state instead of calling
deactivation directly as deactivation doesn't change state anymore
* src/NetworkManagerPolicy.c
- (schedule_activate_check): yay, remove wireless_enabled hack since
the NMManager and wireless devices work that out themselves now
- (device_state_changed): change to a switch and update for new device
states
- (device_carrier_changed): remove; device handles this now through
state changes
- (device_added): don't care about carrier any more; the initial
activation check will happen when the device transitions to
DISCONNECTED
* src/nm-manager.c
- (dispose): clear unmanaged devices
- (handle_unmanaged_devices): update unmanaged device list and toggle
the managed property on each device when needed
- (system_settings_properties_changed_cb): handle signals from the
system settings service
- (system_settings_get_unmanaged_devices_cb): handle callback from
getting the unmanaged device list method call
- (query_unmanaged_devices): ask the system settings service for its
list of unmanaged devices
- (nm_manager_name_owner_changed, initial_get_connections): get unmanaged
devices
- (manager_set_wireless_enabled): push rfkill state down to wireless
devices directly and let them handle the necessary state transitions
- (manager_device_state_changed): update for new device states
- (nm_manager_add_device): set initial rfkill state on wireless devices
- (nm_manager_remove_device): don't touch the device if it's unmanaged
- (nm_manager_activate_connection): return error if the device is
unmanaged
- (nm_manager_sleep): handle new device states correctly; don't change
the state of unavailable/unmanaged devices
* libnm-glib/nm-device-802-11-wireless.c
- (state_changed_cb): update for new device states
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3540 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-04-08 02:58:02 +00:00
|
|
|
default:
|
|
|
|
|
break;
|
2007-10-08 18:07:36 +00:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
check_activating_active_connections(self);
|
2007-02-08 15:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
2008-03-11 22:26:46 +00:00
|
|
|
static void
|
2021-11-09 13:28:54 +01:00
|
|
|
device_l3cd_changed(NMDevice *device,
|
2021-08-06 15:17:05 +02:00
|
|
|
const NML3ConfigData *l3cd_old,
|
|
|
|
|
const NML3ConfigData *l3cd_new,
|
|
|
|
|
gpointer user_data)
|
2008-03-11 22:26:46 +00:00
|
|
|
{
|
2016-04-04 14:36:34 +02:00
|
|
|
NMPolicyPrivate *priv = user_data;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
2021-11-01 11:12:01 +01:00
|
|
|
NMDeviceState state;
|
2012-05-29 22:17:26 -05:00
|
|
|
|
2021-08-06 15:17:05 +02:00
|
|
|
nm_assert(!l3cd_new || NM_IS_L3_CONFIG_DATA(l3cd_new));
|
|
|
|
|
nm_assert(!l3cd_old || NM_IS_L3_CONFIG_DATA(l3cd_old));
|
2012-05-29 22:17:26 -05:00
|
|
|
|
2013-08-22 10:10:17 -04:00
|
|
|
nm_dns_manager_begin_updates(priv->dns_manager, __func__);
|
2012-05-29 22:17:26 -05:00
|
|
|
|
2022-07-01 13:42:26 +02:00
|
|
|
/* FIXME(l3cfg): Note that this function is not always called when the
|
|
|
|
|
* device becomes ACTIVATED. Previously, we would also update the DNS
|
|
|
|
|
* manager's IP config in device_state_change(ACTIVATED). There we would
|
|
|
|
|
* also special-case pseudo-VPNs like wireguard. I don't see the code where
|
|
|
|
|
* this is handled now.
|
2012-05-29 22:17:26 -05:00
|
|
|
*/
|
2021-11-01 11:12:01 +01:00
|
|
|
state = nm_device_get_state(device);
|
2022-07-01 13:42:26 +02:00
|
|
|
if (l3cd_new && state >= NM_DEVICE_STATE_IP_CONFIG && state < NM_DEVICE_STATE_DEACTIVATING) {
|
2024-10-03 15:22:51 +02:00
|
|
|
/* Since the device L3CD_CHANGED signal is emitted *after* the commit of
|
|
|
|
|
* configuration, addresses and routes are already set in kernel when we
|
|
|
|
|
* write the configuration to resolv.conf or send it to the DNS plugin.
|
|
|
|
|
* This prevents "leaks" of DNS queries via the wrong routes.*/
|
2021-08-06 15:17:05 +02:00
|
|
|
nm_dns_manager_set_ip_config(priv->dns_manager,
|
|
|
|
|
AF_UNSPEC,
|
|
|
|
|
device,
|
|
|
|
|
l3cd_new,
|
2022-02-16 13:50:09 +01:00
|
|
|
nm_device_is_vpn(device) ? NM_DNS_IP_CONFIG_TYPE_VPN
|
|
|
|
|
: NM_DNS_IP_CONFIG_TYPE_DEFAULT,
|
2021-08-06 15:17:05 +02:00
|
|
|
TRUE);
|
|
|
|
|
update_ip_dns(self, AF_INET, device);
|
|
|
|
|
update_ip_dns(self, AF_INET6, device);
|
|
|
|
|
update_ip4_routing(self, TRUE);
|
|
|
|
|
update_ip6_routing(self, TRUE);
|
2021-10-25 11:47:26 +02:00
|
|
|
/* FIXME: since we already monitor platform addresses changes,
|
|
|
|
|
* this is probably no longer necessary? */
|
2024-07-31 17:08:43 +02:00
|
|
|
update_system_hostname(self, "ip conf", FALSE);
|
2013-09-06 11:56:41 +02:00
|
|
|
} else {
|
2021-08-06 15:17:05 +02:00
|
|
|
nm_dns_manager_set_ip_config(priv->dns_manager,
|
|
|
|
|
AF_UNSPEC,
|
|
|
|
|
device,
|
|
|
|
|
l3cd_old,
|
|
|
|
|
NM_DNS_IP_CONFIG_TYPE_REMOVED,
|
|
|
|
|
TRUE);
|
2012-05-29 22:17:26 -05:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-08-22 10:10:17 -04:00
|
|
|
nm_dns_manager_end_updates(priv->dns_manager, __func__);
|
2008-03-11 22:26:46 +00:00
|
|
|
}
|
|
|
|
|
|
2021-10-25 11:47:26 +02:00
|
|
|
static void
|
|
|
|
|
device_platform_address_changed(NMDevice *device, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
NMPolicyPrivate *priv = user_data;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
2021-10-25 11:47:26 +02:00
|
|
|
NMDeviceState state;
|
|
|
|
|
|
|
|
|
|
state = nm_device_get_state(device);
|
|
|
|
|
if (state > NM_DEVICE_STATE_DISCONNECTED && state < NM_DEVICE_STATE_DEACTIVATING) {
|
2024-07-31 17:08:43 +02:00
|
|
|
update_system_hostname(self, "address changed", TRUE);
|
2021-10-25 11:47:26 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-31 23:31:14 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2012-05-14 15:32:54 +02:00
|
|
|
static void
|
|
|
|
|
device_autoconnect_changed(NMDevice *device, GParamSpec *pspec, gpointer user_data)
|
|
|
|
|
{
|
2016-04-04 14:36:34 +02:00
|
|
|
NMPolicyPrivate *priv = user_data;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
2016-04-04 14:36:34 +02:00
|
|
|
|
2023-04-05 10:57:57 +02:00
|
|
|
nm_policy_device_recheck_auto_activate_schedule(self, device);
|
2012-05-14 15:32:54 +02:00
|
|
|
}
|
|
|
|
|
|
2010-10-27 16:57:31 -05:00
|
|
|
static void
|
2016-04-04 13:44:30 +02:00
|
|
|
devices_list_unregister(NMPolicy *self, NMDevice *device)
|
2008-03-07 Dan Williams <dcbw@redhat.com>
First pass of multiple active device support. Expect bugs.
* src/nm-ip4-config.c
src/nm-ip4-config.h
- (nm_ip4_config_get_secondary, nm_ip4_config_set_secondary): remove;
there are better ways to do this in the named manager
* src/nm-device.c
src/nm-device.h
- (nm_device_can_activate): return whether the device can activate a
connection right now; taking into account things like carrier state
and rfkill state
- (nm_device_get_best_auto_connection): renamed from
nm_device_get_best_connection
- (real_act_stage4_get_ip4_config): MTU stuff is now handled in the
device subclasses themselves, so that each device can override the
MTU from it's NMSetting subclass if needed
- (nm_device_set_ip4_config): set MTU when setting up routes and stuff
in NetworkManagerSystem.c, not here
* src/named-manager/nm-named-manager.c
src/named-manager/nm-named-manager.h
- (nm_named_manager_name_owner_changed,
nm_named_manager_dbus_connection_changed): fix for changes to
rewrite_resolv_conf()
- (compute_nameservers): don't need the NMNamedManager at all, remove
from parameter list
- (merge_one_ip4_config): new function; merge ip4 configs together
- (rewrite_resolv_conf): write out resolv.conf from all the stored
ip4 configs; the VPN config takes precedence, then the best
device config, then the rest of the configs
- (get_domain_for_config): take the NMNamedManager as an argument
to check whether the config is the VPN config
- (add_ip4_config_to_named): fixups for removal of the 'secondary'
attribute from ip4 configs
- (add_all_ip4_configs_to_named): add all the configs in priority order
- (remove_ip4_config_from_named): fix for changes to
get_domain_for_config()
- (nm_named_manager_add_ip4_config): assign the config to the right slot
based on its type; callers must pass in the type now
- (get_last_default_domain): remove, unused
- (nm_named_manager_remove_ip4_config): handle config slots correctly
* src/nm-device-802-11-wireless.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): handle MTU override
* src/nm-device-802-3-ethernet.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): new function; handle MTU override
* src/vpn-manager/nm-vpn-connection.c
- (nm_vpn_connection_ip4_config_get): don't need to set the 'secondary'
attribute on the ip4 config
* src/NetworkManagerPolicy.c
- (nm_policy_auto_get_best_device): remove
- (nm_policy_device_change_check): remove
- (update_default_route): new function; set the default route via
the specified device
- (get_device_priority): new function; return the priority number of
a device type WRT which one should have the default route. Order is
(highest to lowest) wired, wireless, GSM, CDMA.
- (update_routing_and_dns): new function; determine which device should
have the default route, then update the routing table and DNS
- (maybe_auto_activate_device): new function; if a device is now
available for activation, find out what connection it would like to
activate and do it
- (schedule_activate_check): new function; if a device can be activated
now, schedule the activation. Each device may have only one
pending activation at a given time.
- (device_state_changed): if activation was canceled, try again,
possibly with another connection; if the device was activated,
update routing and DNS; if the device was deactivated, try again
with another connection
- (device_carrier_changed): if there is no carrier, deactivate the
device; otherwise schedule an activation check for the device
- (wireless_networks_changed): schedule an activation check for the
device
- (device_added): keep track of the signal handler IDs so they can
be removed when the device goes away
- (device_removed): remove any signal handlers that might be attached
to the device; update routing and DNS
- (schedule_activate_all): new function
- (connections_added, connection_added, connection_updated): when
connections change, schedule all devices for an activation check
- (connection_removed): when a device is deactivated because its
connection was removed, schedule another activation check for it
- (nm_policy_destroy): destroy pending activations and disconnect
all device signal handlers
* src/nm-manager.c
- (nm_manager_activate_device): if the device was already actived,
deactivate it
- (deactivate_old_device): remove
- (connection_added_default_handler, impl_manager_activate_device):
don't deactivate other devices when activating this one
* src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerSuSE.c
src/backends/NetworkManagerDebian.c
- (nm_system_get_mtu): remove; MTU should be provided through the
distro's system settings service plugin instead
- (nm_system_device_add_default_route_via_device): remove
- (nm_system_device_add_default_route_via_device_with_iface): remove
- (nm_system_device_replace_default_route): new function; call
generic implementation
* src/backends/NetworkManagerGeneric.c
src/backends/NetworkManagerGeneric.h
- (nm_generic_device_add_default_route_via_device,
nm_generic_device_add_default_route_via_device_with_iface): remove
- (nm_generic_device_replace_default_route): replace the default route
with the given route via some gateway
* src/NetworkManagerSystem.c
src/NetworkManagerSystem.h
- (nm_system_device_set_from_ip4_config): let the policy handle updates
to routing and DNS; but set the MTU here
- (nm_system_vpn_device_set_from_ip4_config): set the route with the
ip_iface of the active device; use the standard MTU setting function
- (nm_system_set_mtu): remove
- (nm_system_device_set_mtu): consolidate MTU setting code in one place
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3391 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-07 19:41:32 +00:00
|
|
|
{
|
2016-04-04 14:36:34 +02:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
|
|
|
|
|
g_signal_handlers_disconnect_by_data((GObject *) device, priv);
|
2016-04-04 13:44:30 +02:00
|
|
|
}
|
2008-03-07 Dan Williams <dcbw@redhat.com>
First pass of multiple active device support. Expect bugs.
* src/nm-ip4-config.c
src/nm-ip4-config.h
- (nm_ip4_config_get_secondary, nm_ip4_config_set_secondary): remove;
there are better ways to do this in the named manager
* src/nm-device.c
src/nm-device.h
- (nm_device_can_activate): return whether the device can activate a
connection right now; taking into account things like carrier state
and rfkill state
- (nm_device_get_best_auto_connection): renamed from
nm_device_get_best_connection
- (real_act_stage4_get_ip4_config): MTU stuff is now handled in the
device subclasses themselves, so that each device can override the
MTU from it's NMSetting subclass if needed
- (nm_device_set_ip4_config): set MTU when setting up routes and stuff
in NetworkManagerSystem.c, not here
* src/named-manager/nm-named-manager.c
src/named-manager/nm-named-manager.h
- (nm_named_manager_name_owner_changed,
nm_named_manager_dbus_connection_changed): fix for changes to
rewrite_resolv_conf()
- (compute_nameservers): don't need the NMNamedManager at all, remove
from parameter list
- (merge_one_ip4_config): new function; merge ip4 configs together
- (rewrite_resolv_conf): write out resolv.conf from all the stored
ip4 configs; the VPN config takes precedence, then the best
device config, then the rest of the configs
- (get_domain_for_config): take the NMNamedManager as an argument
to check whether the config is the VPN config
- (add_ip4_config_to_named): fixups for removal of the 'secondary'
attribute from ip4 configs
- (add_all_ip4_configs_to_named): add all the configs in priority order
- (remove_ip4_config_from_named): fix for changes to
get_domain_for_config()
- (nm_named_manager_add_ip4_config): assign the config to the right slot
based on its type; callers must pass in the type now
- (get_last_default_domain): remove, unused
- (nm_named_manager_remove_ip4_config): handle config slots correctly
* src/nm-device-802-11-wireless.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): handle MTU override
* src/nm-device-802-3-ethernet.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): new function; handle MTU override
* src/vpn-manager/nm-vpn-connection.c
- (nm_vpn_connection_ip4_config_get): don't need to set the 'secondary'
attribute on the ip4 config
* src/NetworkManagerPolicy.c
- (nm_policy_auto_get_best_device): remove
- (nm_policy_device_change_check): remove
- (update_default_route): new function; set the default route via
the specified device
- (get_device_priority): new function; return the priority number of
a device type WRT which one should have the default route. Order is
(highest to lowest) wired, wireless, GSM, CDMA.
- (update_routing_and_dns): new function; determine which device should
have the default route, then update the routing table and DNS
- (maybe_auto_activate_device): new function; if a device is now
available for activation, find out what connection it would like to
activate and do it
- (schedule_activate_check): new function; if a device can be activated
now, schedule the activation. Each device may have only one
pending activation at a given time.
- (device_state_changed): if activation was canceled, try again,
possibly with another connection; if the device was activated,
update routing and DNS; if the device was deactivated, try again
with another connection
- (device_carrier_changed): if there is no carrier, deactivate the
device; otherwise schedule an activation check for the device
- (wireless_networks_changed): schedule an activation check for the
device
- (device_added): keep track of the signal handler IDs so they can
be removed when the device goes away
- (device_removed): remove any signal handlers that might be attached
to the device; update routing and DNS
- (schedule_activate_all): new function
- (connections_added, connection_added, connection_updated): when
connections change, schedule all devices for an activation check
- (connection_removed): when a device is deactivated because its
connection was removed, schedule another activation check for it
- (nm_policy_destroy): destroy pending activations and disconnect
all device signal handlers
* src/nm-manager.c
- (nm_manager_activate_device): if the device was already actived,
deactivate it
- (deactivate_old_device): remove
- (connection_added_default_handler, impl_manager_activate_device):
don't deactivate other devices when activating this one
* src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerSuSE.c
src/backends/NetworkManagerDebian.c
- (nm_system_get_mtu): remove; MTU should be provided through the
distro's system settings service plugin instead
- (nm_system_device_add_default_route_via_device): remove
- (nm_system_device_add_default_route_via_device_with_iface): remove
- (nm_system_device_replace_default_route): new function; call
generic implementation
* src/backends/NetworkManagerGeneric.c
src/backends/NetworkManagerGeneric.h
- (nm_generic_device_add_default_route_via_device,
nm_generic_device_add_default_route_via_device_with_iface): remove
- (nm_generic_device_replace_default_route): replace the default route
with the given route via some gateway
* src/NetworkManagerSystem.c
src/NetworkManagerSystem.h
- (nm_system_device_set_from_ip4_config): let the policy handle updates
to routing and DNS; but set the MTU here
- (nm_system_vpn_device_set_from_ip4_config): set the route with the
ip_iface of the active device; use the standard MTU setting function
- (nm_system_set_mtu): remove
- (nm_system_device_set_mtu): consolidate MTU setting code in one place
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3391 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-07 19:41:32 +00:00
|
|
|
|
2016-04-04 13:44:30 +02:00
|
|
|
static void
|
|
|
|
|
devices_list_register(NMPolicy *self, NMDevice *device)
|
|
|
|
|
{
|
2016-04-04 14:36:34 +02:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-04-04 13:44:30 +02:00
|
|
|
/* Connect state-changed with _after, so that the handler is invoked after other handlers. */
|
2021-08-05 09:06:12 +02:00
|
|
|
g_signal_connect_after(device, NM_DEVICE_STATE_CHANGED, G_CALLBACK(device_state_changed), priv);
|
2021-08-06 15:17:05 +02:00
|
|
|
g_signal_connect(device, NM_DEVICE_L3CD_CHANGED, G_CALLBACK(device_l3cd_changed), priv);
|
2021-10-25 11:47:26 +02:00
|
|
|
g_signal_connect(device,
|
|
|
|
|
NM_DEVICE_PLATFORM_ADDRESS_CHANGED,
|
|
|
|
|
G_CALLBACK(device_platform_address_changed),
|
|
|
|
|
priv);
|
2018-01-08 15:44:05 +01:00
|
|
|
g_signal_connect(device,
|
2016-10-31 23:31:14 +01:00
|
|
|
NM_DEVICE_IP6_PREFIX_DELEGATED,
|
2021-08-05 09:06:12 +02:00
|
|
|
G_CALLBACK(device_ip6_prefix_delegated),
|
2016-10-31 23:31:14 +01:00
|
|
|
priv);
|
|
|
|
|
g_signal_connect(device,
|
|
|
|
|
NM_DEVICE_IP6_SUBNET_NEEDED,
|
2021-08-05 09:06:12 +02:00
|
|
|
G_CALLBACK(device_ip6_subnet_needed),
|
2016-10-31 23:31:14 +01:00
|
|
|
priv);
|
|
|
|
|
g_signal_connect(device,
|
2016-04-04 14:36:34 +02:00
|
|
|
"notify::" NM_DEVICE_AUTOCONNECT,
|
2021-08-05 09:06:12 +02:00
|
|
|
G_CALLBACK(device_autoconnect_changed),
|
2016-04-04 14:36:34 +02:00
|
|
|
priv);
|
2007-02-09 08:50:35 +00:00
|
|
|
}
|
|
|
|
|
|
2007-02-08 15:34:26 +00:00
|
|
|
static void
|
|
|
|
|
device_added(NMManager *manager, NMDevice *device, gpointer user_data)
|
|
|
|
|
{
|
2016-04-04 14:36:34 +02:00
|
|
|
NMPolicyPrivate *priv = user_data;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
2007-02-08 15:34:26 +00:00
|
|
|
|
2016-04-04 13:44:30 +02:00
|
|
|
g_return_if_fail(NM_IS_POLICY(self));
|
|
|
|
|
|
|
|
|
|
priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
|
2018-01-02 15:47:37 +01:00
|
|
|
if (!g_hash_table_add(priv->devices, device))
|
2016-04-04 13:44:30 +02:00
|
|
|
g_return_if_reached();
|
|
|
|
|
|
|
|
|
|
devices_list_register(self, device);
|
2007-02-08 15:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
device_removed(NMManager *manager, NMDevice *device, gpointer user_data)
|
|
|
|
|
{
|
2016-04-04 14:36:34 +02:00
|
|
|
NMPolicyPrivate *priv = user_data;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
2009-02-06 15:38:09 -05:00
|
|
|
|
2020-08-27 17:00:35 +02:00
|
|
|
/* TODO: is this needed? The delegations are cleaned up
|
2016-10-31 23:31:14 +01:00
|
|
|
* on transition to deactivated too. */
|
|
|
|
|
ip6_remove_device_prefix_delegations(self, device);
|
|
|
|
|
|
2023-04-05 11:55:28 +02:00
|
|
|
if (c_list_is_linked(&device->policy_auto_activate_lst))
|
|
|
|
|
_auto_activate_device_clear(self, device, FALSE);
|
2008-03-07 Dan Williams <dcbw@redhat.com>
First pass of multiple active device support. Expect bugs.
* src/nm-ip4-config.c
src/nm-ip4-config.h
- (nm_ip4_config_get_secondary, nm_ip4_config_set_secondary): remove;
there are better ways to do this in the named manager
* src/nm-device.c
src/nm-device.h
- (nm_device_can_activate): return whether the device can activate a
connection right now; taking into account things like carrier state
and rfkill state
- (nm_device_get_best_auto_connection): renamed from
nm_device_get_best_connection
- (real_act_stage4_get_ip4_config): MTU stuff is now handled in the
device subclasses themselves, so that each device can override the
MTU from it's NMSetting subclass if needed
- (nm_device_set_ip4_config): set MTU when setting up routes and stuff
in NetworkManagerSystem.c, not here
* src/named-manager/nm-named-manager.c
src/named-manager/nm-named-manager.h
- (nm_named_manager_name_owner_changed,
nm_named_manager_dbus_connection_changed): fix for changes to
rewrite_resolv_conf()
- (compute_nameservers): don't need the NMNamedManager at all, remove
from parameter list
- (merge_one_ip4_config): new function; merge ip4 configs together
- (rewrite_resolv_conf): write out resolv.conf from all the stored
ip4 configs; the VPN config takes precedence, then the best
device config, then the rest of the configs
- (get_domain_for_config): take the NMNamedManager as an argument
to check whether the config is the VPN config
- (add_ip4_config_to_named): fixups for removal of the 'secondary'
attribute from ip4 configs
- (add_all_ip4_configs_to_named): add all the configs in priority order
- (remove_ip4_config_from_named): fix for changes to
get_domain_for_config()
- (nm_named_manager_add_ip4_config): assign the config to the right slot
based on its type; callers must pass in the type now
- (get_last_default_domain): remove, unused
- (nm_named_manager_remove_ip4_config): handle config slots correctly
* src/nm-device-802-11-wireless.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): handle MTU override
* src/nm-device-802-3-ethernet.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): new function; handle MTU override
* src/vpn-manager/nm-vpn-connection.c
- (nm_vpn_connection_ip4_config_get): don't need to set the 'secondary'
attribute on the ip4 config
* src/NetworkManagerPolicy.c
- (nm_policy_auto_get_best_device): remove
- (nm_policy_device_change_check): remove
- (update_default_route): new function; set the default route via
the specified device
- (get_device_priority): new function; return the priority number of
a device type WRT which one should have the default route. Order is
(highest to lowest) wired, wireless, GSM, CDMA.
- (update_routing_and_dns): new function; determine which device should
have the default route, then update the routing table and DNS
- (maybe_auto_activate_device): new function; if a device is now
available for activation, find out what connection it would like to
activate and do it
- (schedule_activate_check): new function; if a device can be activated
now, schedule the activation. Each device may have only one
pending activation at a given time.
- (device_state_changed): if activation was canceled, try again,
possibly with another connection; if the device was activated,
update routing and DNS; if the device was deactivated, try again
with another connection
- (device_carrier_changed): if there is no carrier, deactivate the
device; otherwise schedule an activation check for the device
- (wireless_networks_changed): schedule an activation check for the
device
- (device_added): keep track of the signal handler IDs so they can
be removed when the device goes away
- (device_removed): remove any signal handlers that might be attached
to the device; update routing and DNS
- (schedule_activate_all): new function
- (connections_added, connection_added, connection_updated): when
connections change, schedule all devices for an activation check
- (connection_removed): when a device is deactivated because its
connection was removed, schedule another activation check for it
- (nm_policy_destroy): destroy pending activations and disconnect
all device signal handlers
* src/nm-manager.c
- (nm_manager_activate_device): if the device was already actived,
deactivate it
- (deactivate_old_device): remove
- (connection_added_default_handler, impl_manager_activate_device):
don't deactivate other devices when activating this one
* src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerSuSE.c
src/backends/NetworkManagerDebian.c
- (nm_system_get_mtu): remove; MTU should be provided through the
distro's system settings service plugin instead
- (nm_system_device_add_default_route_via_device): remove
- (nm_system_device_add_default_route_via_device_with_iface): remove
- (nm_system_device_replace_default_route): new function; call
generic implementation
* src/backends/NetworkManagerGeneric.c
src/backends/NetworkManagerGeneric.h
- (nm_generic_device_add_default_route_via_device,
nm_generic_device_add_default_route_via_device_with_iface): remove
- (nm_generic_device_replace_default_route): replace the default route
with the given route via some gateway
* src/NetworkManagerSystem.c
src/NetworkManagerSystem.h
- (nm_system_device_set_from_ip4_config): let the policy handle updates
to routing and DNS; but set the MTU here
- (nm_system_vpn_device_set_from_ip4_config): set the route with the
ip_iface of the active device; use the standard MTU setting function
- (nm_system_set_mtu): remove
- (nm_system_device_set_mtu): consolidate MTU setting code in one place
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3391 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-07 19:41:32 +00:00
|
|
|
|
2016-04-04 13:44:30 +02:00
|
|
|
if (g_hash_table_remove(priv->devices, device))
|
|
|
|
|
devices_list_unregister(self, device);
|
2008-03-07 Dan Williams <dcbw@redhat.com>
First pass of multiple active device support. Expect bugs.
* src/nm-ip4-config.c
src/nm-ip4-config.h
- (nm_ip4_config_get_secondary, nm_ip4_config_set_secondary): remove;
there are better ways to do this in the named manager
* src/nm-device.c
src/nm-device.h
- (nm_device_can_activate): return whether the device can activate a
connection right now; taking into account things like carrier state
and rfkill state
- (nm_device_get_best_auto_connection): renamed from
nm_device_get_best_connection
- (real_act_stage4_get_ip4_config): MTU stuff is now handled in the
device subclasses themselves, so that each device can override the
MTU from it's NMSetting subclass if needed
- (nm_device_set_ip4_config): set MTU when setting up routes and stuff
in NetworkManagerSystem.c, not here
* src/named-manager/nm-named-manager.c
src/named-manager/nm-named-manager.h
- (nm_named_manager_name_owner_changed,
nm_named_manager_dbus_connection_changed): fix for changes to
rewrite_resolv_conf()
- (compute_nameservers): don't need the NMNamedManager at all, remove
from parameter list
- (merge_one_ip4_config): new function; merge ip4 configs together
- (rewrite_resolv_conf): write out resolv.conf from all the stored
ip4 configs; the VPN config takes precedence, then the best
device config, then the rest of the configs
- (get_domain_for_config): take the NMNamedManager as an argument
to check whether the config is the VPN config
- (add_ip4_config_to_named): fixups for removal of the 'secondary'
attribute from ip4 configs
- (add_all_ip4_configs_to_named): add all the configs in priority order
- (remove_ip4_config_from_named): fix for changes to
get_domain_for_config()
- (nm_named_manager_add_ip4_config): assign the config to the right slot
based on its type; callers must pass in the type now
- (get_last_default_domain): remove, unused
- (nm_named_manager_remove_ip4_config): handle config slots correctly
* src/nm-device-802-11-wireless.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): handle MTU override
* src/nm-device-802-3-ethernet.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): new function; handle MTU override
* src/vpn-manager/nm-vpn-connection.c
- (nm_vpn_connection_ip4_config_get): don't need to set the 'secondary'
attribute on the ip4 config
* src/NetworkManagerPolicy.c
- (nm_policy_auto_get_best_device): remove
- (nm_policy_device_change_check): remove
- (update_default_route): new function; set the default route via
the specified device
- (get_device_priority): new function; return the priority number of
a device type WRT which one should have the default route. Order is
(highest to lowest) wired, wireless, GSM, CDMA.
- (update_routing_and_dns): new function; determine which device should
have the default route, then update the routing table and DNS
- (maybe_auto_activate_device): new function; if a device is now
available for activation, find out what connection it would like to
activate and do it
- (schedule_activate_check): new function; if a device can be activated
now, schedule the activation. Each device may have only one
pending activation at a given time.
- (device_state_changed): if activation was canceled, try again,
possibly with another connection; if the device was activated,
update routing and DNS; if the device was deactivated, try again
with another connection
- (device_carrier_changed): if there is no carrier, deactivate the
device; otherwise schedule an activation check for the device
- (wireless_networks_changed): schedule an activation check for the
device
- (device_added): keep track of the signal handler IDs so they can
be removed when the device goes away
- (device_removed): remove any signal handlers that might be attached
to the device; update routing and DNS
- (schedule_activate_all): new function
- (connections_added, connection_added, connection_updated): when
connections change, schedule all devices for an activation check
- (connection_removed): when a device is deactivated because its
connection was removed, schedule another activation check for it
- (nm_policy_destroy): destroy pending activations and disconnect
all device signal handlers
* src/nm-manager.c
- (nm_manager_activate_device): if the device was already actived,
deactivate it
- (deactivate_old_device): remove
- (connection_added_default_handler, impl_manager_activate_device):
don't deactivate other devices when activating this one
* src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerSuSE.c
src/backends/NetworkManagerDebian.c
- (nm_system_get_mtu): remove; MTU should be provided through the
distro's system settings service plugin instead
- (nm_system_device_add_default_route_via_device): remove
- (nm_system_device_add_default_route_via_device_with_iface): remove
- (nm_system_device_replace_default_route): new function; call
generic implementation
* src/backends/NetworkManagerGeneric.c
src/backends/NetworkManagerGeneric.h
- (nm_generic_device_add_default_route_via_device,
nm_generic_device_add_default_route_via_device_with_iface): remove
- (nm_generic_device_replace_default_route): replace the default route
with the given route via some gateway
* src/NetworkManagerSystem.c
src/NetworkManagerSystem.h
- (nm_system_device_set_from_ip4_config): let the policy handle updates
to routing and DNS; but set the MTU here
- (nm_system_vpn_device_set_from_ip4_config): set the route with the
ip_iface of the active device; use the standard MTU setting function
- (nm_system_set_mtu): remove
- (nm_system_device_set_mtu): consolidate MTU setting code in one place
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3391 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-07 19:41:32 +00:00
|
|
|
|
2012-05-29 22:17:26 -05:00
|
|
|
/* Don't update routing and DNS here as we've already handled that
|
|
|
|
|
* for devices that need it when the device's state changed to UNMANAGED.
|
|
|
|
|
*/
|
2008-03-07 Dan Williams <dcbw@redhat.com>
First pass of multiple active device support. Expect bugs.
* src/nm-ip4-config.c
src/nm-ip4-config.h
- (nm_ip4_config_get_secondary, nm_ip4_config_set_secondary): remove;
there are better ways to do this in the named manager
* src/nm-device.c
src/nm-device.h
- (nm_device_can_activate): return whether the device can activate a
connection right now; taking into account things like carrier state
and rfkill state
- (nm_device_get_best_auto_connection): renamed from
nm_device_get_best_connection
- (real_act_stage4_get_ip4_config): MTU stuff is now handled in the
device subclasses themselves, so that each device can override the
MTU from it's NMSetting subclass if needed
- (nm_device_set_ip4_config): set MTU when setting up routes and stuff
in NetworkManagerSystem.c, not here
* src/named-manager/nm-named-manager.c
src/named-manager/nm-named-manager.h
- (nm_named_manager_name_owner_changed,
nm_named_manager_dbus_connection_changed): fix for changes to
rewrite_resolv_conf()
- (compute_nameservers): don't need the NMNamedManager at all, remove
from parameter list
- (merge_one_ip4_config): new function; merge ip4 configs together
- (rewrite_resolv_conf): write out resolv.conf from all the stored
ip4 configs; the VPN config takes precedence, then the best
device config, then the rest of the configs
- (get_domain_for_config): take the NMNamedManager as an argument
to check whether the config is the VPN config
- (add_ip4_config_to_named): fixups for removal of the 'secondary'
attribute from ip4 configs
- (add_all_ip4_configs_to_named): add all the configs in priority order
- (remove_ip4_config_from_named): fix for changes to
get_domain_for_config()
- (nm_named_manager_add_ip4_config): assign the config to the right slot
based on its type; callers must pass in the type now
- (get_last_default_domain): remove, unused
- (nm_named_manager_remove_ip4_config): handle config slots correctly
* src/nm-device-802-11-wireless.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): handle MTU override
* src/nm-device-802-3-ethernet.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): new function; handle MTU override
* src/vpn-manager/nm-vpn-connection.c
- (nm_vpn_connection_ip4_config_get): don't need to set the 'secondary'
attribute on the ip4 config
* src/NetworkManagerPolicy.c
- (nm_policy_auto_get_best_device): remove
- (nm_policy_device_change_check): remove
- (update_default_route): new function; set the default route via
the specified device
- (get_device_priority): new function; return the priority number of
a device type WRT which one should have the default route. Order is
(highest to lowest) wired, wireless, GSM, CDMA.
- (update_routing_and_dns): new function; determine which device should
have the default route, then update the routing table and DNS
- (maybe_auto_activate_device): new function; if a device is now
available for activation, find out what connection it would like to
activate and do it
- (schedule_activate_check): new function; if a device can be activated
now, schedule the activation. Each device may have only one
pending activation at a given time.
- (device_state_changed): if activation was canceled, try again,
possibly with another connection; if the device was activated,
update routing and DNS; if the device was deactivated, try again
with another connection
- (device_carrier_changed): if there is no carrier, deactivate the
device; otherwise schedule an activation check for the device
- (wireless_networks_changed): schedule an activation check for the
device
- (device_added): keep track of the signal handler IDs so they can
be removed when the device goes away
- (device_removed): remove any signal handlers that might be attached
to the device; update routing and DNS
- (schedule_activate_all): new function
- (connections_added, connection_added, connection_updated): when
connections change, schedule all devices for an activation check
- (connection_removed): when a device is deactivated because its
connection was removed, schedule another activation check for it
- (nm_policy_destroy): destroy pending activations and disconnect
all device signal handlers
* src/nm-manager.c
- (nm_manager_activate_device): if the device was already actived,
deactivate it
- (deactivate_old_device): remove
- (connection_added_default_handler, impl_manager_activate_device):
don't deactivate other devices when activating this one
* src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerSuSE.c
src/backends/NetworkManagerDebian.c
- (nm_system_get_mtu): remove; MTU should be provided through the
distro's system settings service plugin instead
- (nm_system_device_add_default_route_via_device): remove
- (nm_system_device_add_default_route_via_device_with_iface): remove
- (nm_system_device_replace_default_route): new function; call
generic implementation
* src/backends/NetworkManagerGeneric.c
src/backends/NetworkManagerGeneric.h
- (nm_generic_device_add_default_route_via_device,
nm_generic_device_add_default_route_via_device_with_iface): remove
- (nm_generic_device_replace_default_route): replace the default route
with the given route via some gateway
* src/NetworkManagerSystem.c
src/NetworkManagerSystem.h
- (nm_system_device_set_from_ip4_config): let the policy handle updates
to routing and DNS; but set the MTU here
- (nm_system_vpn_device_set_from_ip4_config): set the route with the
ip_iface of the active device; use the standard MTU setting function
- (nm_system_set_mtu): remove
- (nm_system_device_set_mtu): consolidate MTU setting code in one place
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3391 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-07 19:41:32 +00:00
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2012-08-22 18:34:45 -05:00
|
|
|
|
|
|
|
|
static void
|
2021-08-06 15:17:05 +02:00
|
|
|
vpn_connection_update_dns(NMPolicy *self, NMVpnConnection *vpn, gboolean remove)
|
2012-08-22 18:34:45 -05:00
|
|
|
{
|
2016-03-29 10:46:07 +02:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2021-08-06 15:17:05 +02:00
|
|
|
int IS_IPv4;
|
2012-08-22 18:34:45 -05:00
|
|
|
|
2013-12-19 11:05:43 -05:00
|
|
|
nm_dns_manager_begin_updates(priv->dns_manager, __func__);
|
2012-08-22 18:34:45 -05:00
|
|
|
|
2021-08-06 15:17:05 +02:00
|
|
|
for (IS_IPv4 = 1; IS_IPv4 >= 0; IS_IPv4--) {
|
|
|
|
|
int addr_family = IS_IPv4 ? AF_INET : AF_INET6;
|
|
|
|
|
const NML3ConfigData *l3cd;
|
2012-08-22 18:34:45 -05:00
|
|
|
|
2021-08-06 15:17:05 +02:00
|
|
|
l3cd = nm_vpn_connection_get_l3cd(vpn);
|
2017-12-16 15:11:16 +01:00
|
|
|
nm_dns_manager_set_ip_config(priv->dns_manager,
|
2021-08-06 15:17:05 +02:00
|
|
|
addr_family,
|
|
|
|
|
vpn,
|
|
|
|
|
l3cd,
|
|
|
|
|
remove ? NM_DNS_IP_CONFIG_TYPE_REMOVED
|
|
|
|
|
: NM_DNS_IP_CONFIG_TYPE_VPN,
|
|
|
|
|
TRUE);
|
|
|
|
|
}
|
2012-08-22 18:34:45 -05:00
|
|
|
|
2020-03-17 10:52:29 +01:00
|
|
|
update_routing_and_dns(self, TRUE, NULL);
|
2012-08-22 18:34:45 -05:00
|
|
|
|
2013-12-19 11:05:43 -05:00
|
|
|
nm_dns_manager_end_updates(priv->dns_manager, __func__);
|
2013-09-27 10:12:08 -05:00
|
|
|
}
|
2012-08-22 18:34:45 -05:00
|
|
|
|
2013-09-27 10:12:08 -05:00
|
|
|
static void
|
2021-11-09 13:28:54 +01:00
|
|
|
vpn_connection_state_changed(NMVpnConnection *vpn,
|
libnm, core, cli, tui: fix the capitalization of various types
GLib/Gtk have mostly settled on the convention that two-letter
acronyms in type names remain all-caps (eg, "IO"), but longer acronyms
become initial-caps-only (eg, "Tcp").
NM was inconsistent, with most long acronyms using initial caps only
(Adsl, Cdma, Dcb, Gsm, Olpc, Vlan), but others using all caps (DHCP,
PPP, PPPOE, VPN). Fix libnm and src/ to use initial-caps only for all
three-or-more-letter-long acronyms (and update nmcli and nmtui for the
libnm changes).
2014-06-26 13:44:36 -04:00
|
|
|
NMVpnConnectionState new_state,
|
|
|
|
|
NMVpnConnectionState old_state,
|
2017-03-11 14:39:07 +01:00
|
|
|
NMActiveConnectionStateReason reason,
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self)
|
2013-09-27 10:12:08 -05:00
|
|
|
{
|
2021-08-06 15:17:05 +02:00
|
|
|
/* FIXME(l3cfg): we need to track changes to nm_vpn_connection_get_l3cd(). */
|
2013-09-27 10:12:08 -05:00
|
|
|
if (new_state == NM_VPN_CONNECTION_STATE_ACTIVATED)
|
2021-08-06 15:17:05 +02:00
|
|
|
vpn_connection_update_dns(self, vpn, FALSE);
|
2013-09-27 10:12:08 -05:00
|
|
|
else if (new_state >= NM_VPN_CONNECTION_STATE_FAILED) {
|
|
|
|
|
/* Only clean up IP/DNS if the connection ever got past IP_CONFIG */
|
|
|
|
|
if (old_state >= NM_VPN_CONNECTION_STATE_IP_CONFIG_GET
|
|
|
|
|
&& old_state <= NM_VPN_CONNECTION_STATE_ACTIVATED)
|
2021-08-06 15:17:05 +02:00
|
|
|
vpn_connection_update_dns(self, vpn, TRUE);
|
2013-09-27 10:12:08 -05:00
|
|
|
}
|
2012-08-22 18:34:45 -05:00
|
|
|
}
|
|
|
|
|
|
2014-09-26 16:03:06 -05:00
|
|
|
static void
|
2016-03-29 10:46:07 +02:00
|
|
|
vpn_connection_retry_after_failure(NMVpnConnection *vpn, NMPolicy *self)
|
2014-09-26 16:03:06 -05:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
NMActiveConnection *ac = NM_ACTIVE_CONNECTION(vpn);
|
2015-07-14 16:53:24 +02:00
|
|
|
NMSettingsConnection *connection = nm_active_connection_get_settings_connection(ac);
|
2021-11-09 13:28:54 +01:00
|
|
|
GError *error = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-09-26 16:03:06 -05:00
|
|
|
/* Attempt to reconnect VPN connections that failed after being connected */
|
|
|
|
|
if (!nm_manager_activate_connection(
|
|
|
|
|
priv->manager,
|
|
|
|
|
connection,
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
2016-09-07 17:47:26 +02:00
|
|
|
NULL,
|
2014-09-26 16:03:06 -05:00
|
|
|
nm_active_connection_get_subject(ac),
|
2017-03-07 11:04:36 +01:00
|
|
|
NM_ACTIVATION_TYPE_MANAGED,
|
2018-03-28 17:18:04 +02:00
|
|
|
nm_active_connection_get_activation_reason(ac),
|
core: improve and fix keeping connection active based on "connection.permissions"
By setting "connection.permissions", a profile is restricted to a
particular user.
That means for example, that another user cannot see, modify, delete,
activate or deactivate the profile. It also means, that the profile
will only autoconnect when the user is logged in (has a session).
Note that root is always able to activate the profile. Likewise, the
user is also allowed to manually activate the own profile, even if no
session currently exists (which can easily happen with `sudo`).
When the user logs out (the session goes away), we want do disconnect
the profile, however there are conflicting goals here:
1) if the profile was activate by root user, then logging out the user
should not disconnect the profile. The patch fixes that by not
binding the activation to the connection, if the activation is done
by the root user.
2) if the profile was activated by the owner when it had no session,
then it should stay alive until the user logs in (once) and logs
out again. This is already handled by the previous commit.
Yes, this point is odd. If you first do
$ sudo -u $OTHER_USER nmcli connection up $PROFILE
the profile activates despite not having a session. If you then
$ ssh guest@localhost nmcli device
you'll still see the profile active. However, the moment the SSH session
ends, a session closes and the profile disconnects. It's unclear, how to
solve that any better. I think, a user who cares about this, should not
activate the profile without having a session in the first place.
There are quite some special cases, in particular with internal
activations. In those cases we need to decide whether to bind the
activation to the profile's visibility.
Also, expose the "bind" setting in the D-Bus API. Note, that in the future
this flag may be modified via D-Bus API. Like we may also add related API
that allows to tweak the lifetime of the activation.
Also, I think we broke handling of connection visiblity with 37e8c53eeed
"core: Introduce helper class to track connection keep alive". This
should be fixed now too, with improved behavior.
Fixes: 37e8c53eeed579fe34a68819cd12f3295d581394
https://bugzilla.redhat.com/show_bug.cgi?id=1530977
2018-11-21 13:30:16 +01:00
|
|
|
(nm_active_connection_get_state_flags(ac)
|
|
|
|
|
& NM_ACTIVATION_STATE_FLAG_LIFETIME_BOUND_TO_PROFILE_VISIBILITY),
|
2014-09-26 16:03:06 -05:00
|
|
|
&error)) {
|
2016-03-03 09:20:18 +01:00
|
|
|
_LOGW(LOGD_DEVICE,
|
|
|
|
|
"VPN '%s' reconnect failed: %s",
|
|
|
|
|
nm_settings_connection_get_id(connection),
|
2018-04-24 11:20:03 +02:00
|
|
|
error->message ?: "unknown");
|
2014-09-26 16:03:06 -05:00
|
|
|
g_clear_error(&error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 18:34:45 -05:00
|
|
|
static void
|
|
|
|
|
active_connection_state_changed(NMActiveConnection *active, GParamSpec *pspec, NMPolicy *self)
|
|
|
|
|
{
|
2013-09-27 10:12:08 -05:00
|
|
|
NMActiveConnectionState state = nm_active_connection_get_state(active);
|
|
|
|
|
|
|
|
|
|
if (state == NM_ACTIVE_CONNECTION_STATE_ACTIVATED)
|
2016-03-29 10:46:07 +02:00
|
|
|
process_secondaries(self, active, TRUE);
|
2013-09-27 10:12:08 -05:00
|
|
|
else if (state == NM_ACTIVE_CONNECTION_STATE_DEACTIVATED)
|
2016-03-29 10:46:07 +02:00
|
|
|
process_secondaries(self, active, FALSE);
|
2012-08-22 18:34:45 -05:00
|
|
|
}
|
|
|
|
|
|
2018-10-10 17:10:01 +02:00
|
|
|
static void
|
2018-11-20 14:51:22 +01:00
|
|
|
active_connection_keep_alive_changed(NMKeepAlive *keep_alive, GParamSpec *pspec, NMPolicy *self)
|
2018-10-10 17:10:01 +02:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv;
|
2018-11-20 14:51:22 +01:00
|
|
|
NMActiveConnection *ac;
|
2021-11-09 13:28:54 +01:00
|
|
|
GError *error = NULL;
|
2018-10-10 17:10:01 +02:00
|
|
|
|
2018-11-20 14:51:22 +01:00
|
|
|
nm_assert(NM_IS_POLICY(self));
|
|
|
|
|
nm_assert(NM_IS_KEEP_ALIVE(keep_alive));
|
|
|
|
|
nm_assert(NM_IS_ACTIVE_CONNECTION(nm_keep_alive_get_owner(keep_alive)));
|
|
|
|
|
|
|
|
|
|
if (nm_keep_alive_is_alive(keep_alive))
|
2018-11-17 13:35:02 +01:00
|
|
|
return;
|
|
|
|
|
|
2018-11-20 14:51:22 +01:00
|
|
|
ac = nm_keep_alive_get_owner(keep_alive);
|
|
|
|
|
|
|
|
|
|
if (nm_active_connection_get_state(ac) > NM_ACTIVE_CONNECTION_STATE_ACTIVATED)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
|
|
|
|
|
if (!nm_manager_deactivate_connection(priv->manager,
|
|
|
|
|
ac,
|
|
|
|
|
NM_DEVICE_STATE_REASON_CONNECTION_REMOVED,
|
|
|
|
|
&error)) {
|
|
|
|
|
_LOGW(LOGD_DEVICE,
|
|
|
|
|
"connection '%s' is no longer kept alive, but error deactivating it: %s",
|
|
|
|
|
nm_active_connection_get_settings_connection_id(ac),
|
|
|
|
|
error->message);
|
|
|
|
|
g_clear_error(&error);
|
2018-10-10 17:10:01 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-22 18:34:45 -05:00
|
|
|
static void
|
|
|
|
|
active_connection_added(NMManager *manager, NMActiveConnection *active, gpointer user_data)
|
|
|
|
|
{
|
2016-04-04 14:36:34 +02:00
|
|
|
NMPolicyPrivate *priv = user_data;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
|
|
|
|
NMKeepAlive *keep_alive;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-09-27 10:12:08 -05:00
|
|
|
if (NM_IS_VPN_CONNECTION(active)) {
|
|
|
|
|
g_signal_connect(active,
|
|
|
|
|
NM_VPN_CONNECTION_INTERNAL_STATE_CHANGED,
|
|
|
|
|
G_CALLBACK(vpn_connection_state_changed),
|
2016-03-29 10:46:07 +02:00
|
|
|
self);
|
2014-09-26 16:03:06 -05:00
|
|
|
g_signal_connect(active,
|
|
|
|
|
NM_VPN_CONNECTION_INTERNAL_RETRY_AFTER_FAILURE,
|
|
|
|
|
G_CALLBACK(vpn_connection_retry_after_failure),
|
2016-03-29 10:46:07 +02:00
|
|
|
self);
|
2013-09-27 10:12:08 -05:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-11-20 14:51:22 +01:00
|
|
|
keep_alive = nm_active_connection_get_keep_alive(active);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
device: arm keep-alive instance when queuing active-connection for activation
Now that the keep-alive instance defaults to ALIVE by default, we can
always arm it when starting to activate the active-connection.
The keep-alive instance may have been armed earlier already:
for example, when binding its lifetime to a D-Bus name or
when watching the connection's visible state.
However, at the moment when we queue the active-connection for
activation, we also want to make sure that the keep-alive instance is
armed. It is nicer for consistancy reasons.
Note, that nm_keep_alive_arm() has no effect if nm_keep_alive_disarm()
was called earlier already. Also note, that NMActiveConnection will
disarm the keep-alive instance, when changing to a state greater than
ACTIVATED. So, all works together nicely.
Also, no longer arm the keep-alive instance in the constructor of
NMActiveConnection. It would essentially mean, that the instances
is aremd very early.
Also, as alternative point of interest, arm the keep-alive instance
when registering the signal handler in "nm-policy.c".
2018-11-20 16:01:32 +01:00
|
|
|
nm_keep_alive_arm(keep_alive);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2012-08-22 18:34:45 -05:00
|
|
|
g_signal_connect(active,
|
|
|
|
|
"notify::" NM_ACTIVE_CONNECTION_STATE,
|
|
|
|
|
G_CALLBACK(active_connection_state_changed),
|
2016-03-29 10:46:07 +02:00
|
|
|
self);
|
2018-11-20 14:51:22 +01:00
|
|
|
g_signal_connect(keep_alive,
|
|
|
|
|
"notify::" NM_KEEP_ALIVE_ALIVE,
|
2018-10-10 17:10:01 +02:00
|
|
|
G_CALLBACK(active_connection_keep_alive_changed),
|
|
|
|
|
self);
|
2018-11-20 14:51:22 +01:00
|
|
|
active_connection_keep_alive_changed(keep_alive, NULL, self);
|
2012-08-22 18:34:45 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
active_connection_removed(NMManager *manager, NMActiveConnection *active, gpointer user_data)
|
|
|
|
|
{
|
2016-04-04 14:36:34 +02:00
|
|
|
NMPolicyPrivate *priv = user_data;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2014-09-26 16:03:06 -05:00
|
|
|
g_signal_handlers_disconnect_by_func(active, vpn_connection_state_changed, self);
|
|
|
|
|
g_signal_handlers_disconnect_by_func(active, vpn_connection_retry_after_failure, self);
|
2012-08-22 18:34:45 -05:00
|
|
|
g_signal_handlers_disconnect_by_func(active, active_connection_state_changed, self);
|
2018-11-20 14:51:22 +01:00
|
|
|
g_signal_handlers_disconnect_by_func(nm_active_connection_get_keep_alive(active),
|
2018-11-20 15:47:24 +01:00
|
|
|
active_connection_keep_alive_changed,
|
|
|
|
|
self);
|
2012-08-22 18:34:45 -05:00
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2012-08-22 18:34:45 -05:00
|
|
|
|
2016-04-13 14:14:36 +02:00
|
|
|
static gboolean
|
2023-04-05 11:02:36 +02:00
|
|
|
_device_recheck_auto_activate_all_cb(gpointer user_data)
|
2008-03-07 Dan Williams <dcbw@redhat.com>
First pass of multiple active device support. Expect bugs.
* src/nm-ip4-config.c
src/nm-ip4-config.h
- (nm_ip4_config_get_secondary, nm_ip4_config_set_secondary): remove;
there are better ways to do this in the named manager
* src/nm-device.c
src/nm-device.h
- (nm_device_can_activate): return whether the device can activate a
connection right now; taking into account things like carrier state
and rfkill state
- (nm_device_get_best_auto_connection): renamed from
nm_device_get_best_connection
- (real_act_stage4_get_ip4_config): MTU stuff is now handled in the
device subclasses themselves, so that each device can override the
MTU from it's NMSetting subclass if needed
- (nm_device_set_ip4_config): set MTU when setting up routes and stuff
in NetworkManagerSystem.c, not here
* src/named-manager/nm-named-manager.c
src/named-manager/nm-named-manager.h
- (nm_named_manager_name_owner_changed,
nm_named_manager_dbus_connection_changed): fix for changes to
rewrite_resolv_conf()
- (compute_nameservers): don't need the NMNamedManager at all, remove
from parameter list
- (merge_one_ip4_config): new function; merge ip4 configs together
- (rewrite_resolv_conf): write out resolv.conf from all the stored
ip4 configs; the VPN config takes precedence, then the best
device config, then the rest of the configs
- (get_domain_for_config): take the NMNamedManager as an argument
to check whether the config is the VPN config
- (add_ip4_config_to_named): fixups for removal of the 'secondary'
attribute from ip4 configs
- (add_all_ip4_configs_to_named): add all the configs in priority order
- (remove_ip4_config_from_named): fix for changes to
get_domain_for_config()
- (nm_named_manager_add_ip4_config): assign the config to the right slot
based on its type; callers must pass in the type now
- (get_last_default_domain): remove, unused
- (nm_named_manager_remove_ip4_config): handle config slots correctly
* src/nm-device-802-11-wireless.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): handle MTU override
* src/nm-device-802-3-ethernet.c
- (real_can_activate): new function
- (real_get_best_auto_connection): renamed from real_get_best_connection
- (real_act_stage4_get_ip4_config): new function; handle MTU override
* src/vpn-manager/nm-vpn-connection.c
- (nm_vpn_connection_ip4_config_get): don't need to set the 'secondary'
attribute on the ip4 config
* src/NetworkManagerPolicy.c
- (nm_policy_auto_get_best_device): remove
- (nm_policy_device_change_check): remove
- (update_default_route): new function; set the default route via
the specified device
- (get_device_priority): new function; return the priority number of
a device type WRT which one should have the default route. Order is
(highest to lowest) wired, wireless, GSM, CDMA.
- (update_routing_and_dns): new function; determine which device should
have the default route, then update the routing table and DNS
- (maybe_auto_activate_device): new function; if a device is now
available for activation, find out what connection it would like to
activate and do it
- (schedule_activate_check): new function; if a device can be activated
now, schedule the activation. Each device may have only one
pending activation at a given time.
- (device_state_changed): if activation was canceled, try again,
possibly with another connection; if the device was activated,
update routing and DNS; if the device was deactivated, try again
with another connection
- (device_carrier_changed): if there is no carrier, deactivate the
device; otherwise schedule an activation check for the device
- (wireless_networks_changed): schedule an activation check for the
device
- (device_added): keep track of the signal handler IDs so they can
be removed when the device goes away
- (device_removed): remove any signal handlers that might be attached
to the device; update routing and DNS
- (schedule_activate_all): new function
- (connections_added, connection_added, connection_updated): when
connections change, schedule all devices for an activation check
- (connection_removed): when a device is deactivated because its
connection was removed, schedule another activation check for it
- (nm_policy_destroy): destroy pending activations and disconnect
all device signal handlers
* src/nm-manager.c
- (nm_manager_activate_device): if the device was already actived,
deactivate it
- (deactivate_old_device): remove
- (connection_added_default_handler, impl_manager_activate_device):
don't deactivate other devices when activating this one
* src/backends/NetworkManagerGentoo.c
src/backends/NetworkManagerFrugalware.c
src/backends/NetworkManagerPaldo.c
src/backends/NetworkManagerRedHat.c
src/backends/NetworkManagerSlackware.c
src/backends/NetworkManagerArch.c
src/backends/NetworkManagerSuSE.c
src/backends/NetworkManagerDebian.c
- (nm_system_get_mtu): remove; MTU should be provided through the
distro's system settings service plugin instead
- (nm_system_device_add_default_route_via_device): remove
- (nm_system_device_add_default_route_via_device_with_iface): remove
- (nm_system_device_replace_default_route): new function; call
generic implementation
* src/backends/NetworkManagerGeneric.c
src/backends/NetworkManagerGeneric.h
- (nm_generic_device_add_default_route_via_device,
nm_generic_device_add_default_route_via_device_with_iface): remove
- (nm_generic_device_replace_default_route): replace the default route
with the given route via some gateway
* src/NetworkManagerSystem.c
src/NetworkManagerSystem.h
- (nm_system_device_set_from_ip4_config): let the policy handle updates
to routing and DNS; but set the MTU here
- (nm_system_vpn_device_set_from_ip4_config): set the route with the
ip_iface of the active device; use the standard MTU setting function
- (nm_system_set_mtu): remove
- (nm_system_device_set_mtu): consolidate MTU setting code in one place
git-svn-id: http://svn-archive.gnome.org/svn/NetworkManager/trunk@3391 4912f4e0-d625-0410-9fb7-b9a5a253dbdc
2008-03-07 19:41:32 +00:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = user_data;
|
2016-03-29 10:46:07 +02:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2021-11-09 13:28:54 +01:00
|
|
|
const CList *tmp_lst;
|
|
|
|
|
NMDevice *device;
|
2007-02-08 15:34:26 +00:00
|
|
|
|
2023-04-07 12:55:57 +02:00
|
|
|
nm_clear_g_source_inst(&priv->device_recheck_auto_activate_all_idle_source);
|
2016-04-13 14:14:36 +02:00
|
|
|
|
2018-03-29 08:52:45 +02:00
|
|
|
nm_manager_for_each_device (priv->manager, device, tmp_lst)
|
2023-04-05 10:57:57 +02:00
|
|
|
nm_policy_device_recheck_auto_activate_schedule(self, device);
|
2016-04-13 14:14:36 +02:00
|
|
|
|
2023-04-07 12:55:57 +02:00
|
|
|
return G_SOURCE_CONTINUE;
|
2016-04-13 14:14:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2023-04-05 11:02:36 +02:00
|
|
|
nm_policy_device_recheck_auto_activate_all_schedule(NMPolicy *self)
|
2016-04-13 14:14:36 +02:00
|
|
|
{
|
|
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
|
|
|
|
|
/* always restart the idle handler. That way, we settle
|
|
|
|
|
* all other events before restarting to activate them. */
|
2023-04-07 12:55:57 +02:00
|
|
|
nm_clear_g_source_inst(&priv->device_recheck_auto_activate_all_idle_source);
|
|
|
|
|
|
|
|
|
|
priv->device_recheck_auto_activate_all_idle_source =
|
|
|
|
|
nm_g_idle_add_source(_device_recheck_auto_activate_all_cb, self);
|
2007-02-08 15:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
2023-04-05 11:02:36 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2007-10-07 23:33:28 +00:00
|
|
|
static void
|
2010-10-27 20:05:23 -05:00
|
|
|
connection_added(NMSettings *settings, NMSettingsConnection *connection, gpointer user_data)
|
2007-05-07 15:17:45 +00:00
|
|
|
{
|
2016-04-04 14:36:34 +02:00
|
|
|
NMPolicyPrivate *priv = user_data;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
2013-12-05 04:57:01 -05:00
|
|
|
|
2023-05-03 11:34:06 +02:00
|
|
|
unblock_autoconnect_for_ports_for_sett_conn(self, connection);
|
|
|
|
|
|
2023-04-05 11:02:36 +02:00
|
|
|
nm_policy_device_recheck_auto_activate_all_schedule(self);
|
2007-08-13 01:45:47 +00:00
|
|
|
}
|
|
|
|
|
|
2012-03-01 18:54:22 +01:00
|
|
|
static void
|
2021-08-02 09:14:10 +02:00
|
|
|
firewall_state_changed(NMFirewalldManager *manager, int signal_type_i, gpointer user_data)
|
2012-03-01 18:54:22 +01:00
|
|
|
{
|
2021-08-02 09:14:10 +02:00
|
|
|
const NMFirewalldManagerStateChangedType signal_type = signal_type_i;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = user_data;
|
|
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
const CList *tmp_lst;
|
|
|
|
|
NMDevice *device;
|
2012-03-01 18:54:22 +01:00
|
|
|
|
2021-08-02 09:14:10 +02:00
|
|
|
if (signal_type == NM_FIREWALLD_MANAGER_STATE_CHANGED_TYPE_INITIALIZED) {
|
2017-04-20 18:52:06 +02:00
|
|
|
/* the firewall manager was initializing, but all requests
|
|
|
|
|
* so fare were queued and are already sent. No need to
|
|
|
|
|
* re-update the firewall zone of the devices. */
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-04 16:01:13 +02:00
|
|
|
if (!nm_firewalld_manager_get_running(manager))
|
2017-04-20 18:30:01 +02:00
|
|
|
return;
|
|
|
|
|
|
2012-03-01 18:54:23 +01:00
|
|
|
/* add interface of each device to correct zone */
|
2018-03-29 08:52:45 +02:00
|
|
|
nm_manager_for_each_device (priv->manager, device, tmp_lst)
|
core: track devices in manager via embedded CList
Instead of using a GSList for tracking the devices, use a CList.
I think a CList is in most cases the more suitable data structure
then GSList:
- you can find out in O(1) whether the object is linked. That
is nice, for example to assert in NMDevice's destructor that
the object was unlinked, and we will use that later in
nm_manager_get_device_by_path().
- you can unlink the element in O(1) and you can unlink the
element without having access to the link's head
- Contrary to GSList, this does not require an extra slice
allocation for the link node. It quite possibliy consumes
slightly less memory because the CList structure is embedded
in a struct that we already allocate. Even if slice allocation
would be perfect to only consume 2*sizeof(gpointer) for the link
note, it would at most be as-good as CList. Quite possibly,
there is an overhead though.
- CList possibly has better memory locality, because the link
structure and the data are close to each other.
Something which could be seen as disavantage, is that with CList
one device can only be tracked in one NMManager instance at a time.
But that is fine. There exists only one NMManager instance for now,
and even if we would ever introduce multiple managers, we probably
would not associate one NMDevice instance with multiple managers.
The advantages are arguably not huge, but CList is IMHO clearly the
more suited data structure. No need to stick to a suboptimal data
structure for the job. Refactor it.
2018-03-23 21:51:07 +01:00
|
|
|
nm_device_update_firewall_zone(device);
|
2012-03-01 18:54:22 +01:00
|
|
|
}
|
|
|
|
|
|
2020-12-17 14:13:45 +01:00
|
|
|
static void
|
|
|
|
|
dns_config_changed(NMDnsManager *dns_manager, gpointer user_data)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = (NMPolicy *) user_data;
|
2020-12-17 14:13:45 +01:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2021-11-09 13:28:54 +01:00
|
|
|
NMDevice *device;
|
|
|
|
|
const CList *tmp_lst;
|
2020-12-17 14:13:45 +01:00
|
|
|
|
|
|
|
|
/* We are currently updating the hostname in the DNS manager.
|
|
|
|
|
* This doesn't warrant a new DNS lookup.*/
|
|
|
|
|
if (priv->updating_dns)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-09-26 15:00:32 +08:00
|
|
|
if (!nm_dns_manager_is_unmanaged(dns_manager)) {
|
|
|
|
|
nm_manager_for_each_device (priv->manager, device, tmp_lst) {
|
|
|
|
|
nm_device_clear_dns_lookup_data(device, "DNS configuration changed");
|
|
|
|
|
}
|
2020-12-17 14:13:45 +01:00
|
|
|
|
2024-07-31 17:08:43 +02:00
|
|
|
update_system_hostname(self, "DNS configuration changed", FALSE);
|
2023-09-26 15:00:32 +08:00
|
|
|
}
|
2023-09-26 17:14:58 +08:00
|
|
|
|
|
|
|
|
nm_dispatcher_call_dns_change();
|
2020-12-17 14:13:45 +01:00
|
|
|
}
|
|
|
|
|
|
2007-10-06 04:31:13 +00:00
|
|
|
static void
|
2021-11-09 13:28:54 +01:00
|
|
|
connection_updated(NMSettings *settings,
|
2016-04-13 16:03:06 +02:00
|
|
|
NMSettingsConnection *connection,
|
settings: rework tracking settings connections and settings plugins
Completely rework how settings plugin handle connections and how
NMSettings tracks the list of connections.
Previously, settings plugins would return objects of (a subtype of) type
NMSettingsConnection. The NMSettingsConnection was tightly coupled with
the settings plugin. That has a lot of downsides.
Change that. When changing this basic relation how settings connections
are tracked, everything falls appart. That's why this is a huge change.
Also, since I have to largely rewrite the settings plugins, I also
added support for multiple keyfile directories, handle in-memory
connections only by keyfile plugin and (partly) use copy-on-write NMConnection
instances. I don't want to spend effort rewriting large parts while
preserving the old way, that anyway should change. E.g. while rewriting ifcfg-rh,
I don't want to let it handle in-memory connections because that's not right
long-term.
--
If the settings plugins themself create subtypes of NMSettingsConnection
instances, then a lot of knowledge about tracking connections moves
to the plugins.
Just try to follow the code what happend during nm_settings_add_connection().
Note how the logic is spread out:
- nm_settings_add_connection() calls plugin's add_connection()
- add_connection() creates a NMSettingsConnection subtype
- the plugin has to know that it's called during add-connection and
not emit NM_SETTINGS_PLUGIN_CONNECTION_ADDED signal
- NMSettings calls claim_connection() which hocks up the new
NMSettingsConnection instance and configures the instance
(like calling nm_settings_connection_added()).
This summary does not sound like a lot, but try to follow that code. The logic
is all over the place.
Instead, settings plugins should have a very simple API for adding, modifying,
deleting, loading and reloading connections. All the plugin does is to return a
NMSettingsStorage handle. The storage instance is a handle to identify a profile
in storage (e.g. a particular file). The settings plugin is free to subtype
NMSettingsStorage, but it's not necessary.
There are no more events raised, and the settings plugin implements the small
API in a straightforward manner.
NMSettings now drives all of this. Even NMSettingsConnection has now
very little concern about how it's tracked and delegates only to NMSettings.
This should make settings plugins simpler. Currently settings plugins
are so cumbersome to implement, that we avoid having them. It should not be
like that and it should be easy, beneficial and lightweight to create a new
settings plugin.
Note also how the settings plugins no longer care about duplicate UUIDs.
Duplicated UUIDs are a fact of life and NMSettings must handle them. No
need to overly concern settings plugins with that.
--
NMSettingsConnection is exposed directly on D-Bus (being a subtype of
NMDBusObject) but it was also a GObject type provided by the settings
plugin. Hence, it was not possible to migrate a profile from one plugin to
another.
However that would be useful when one profile does not support a
connection type (like ifcfg-rh not supporting VPN). Currently such
migration is not implemented except for migrating them to/from keyfile's
run directory. The problem is that migrating profiles in general is
complicated but in some cases it is important to do.
For example checkpoint rollback should recreate the profile in the right
settings plugin, not just add it to persistent storage. This is not yet
properly implemented.
--
Previously, both keyfile and ifcfg-rh plugin implemented in-memory (unsaved)
profiles, while ifupdown plugin cannot handle them. That meant duplication of code
and a ifupdown profile could not be modified or made unsaved.
This is now unified and only keyfile plugin handles in-memory profiles (bgo #744711).
Also, NMSettings is aware of such profiles and treats them specially.
In particular, NMSettings drives the migration between persistent and non-persistent
storage.
Note that a settings plugins may create truly generated, in-memory profiles.
The settings plugin is free to generate and persist the profiles in any way it
wishes. But the concept of "unsaved" profiles is now something explicitly handled
by keyfile plugin. Also, these "unsaved" keyfile profiles are persisted to file system
too, to the /run directory. This is great for two reasons: first of all, all
profiles from keyfile storage in fact have a backing file -- even the
unsaved ones. It also means you can create "unsaved" profiles in /run
and load them with `nmcli connection load`, meaning there is a file
based API for creating unsaved profiles.
The other advantage is that these profiles now survive restarting
NetworkManager. It's paramount that restarting the daemon is as
non-disruptive as possible. Persisting unsaved files to /run improves
here significantly.
--
In the past, NMSettingsConnection also implemented NMConnection interface.
That was already changed a while ago and instead users call now
nm_settings_connection_get_connection() to delegate to a
NMSimpleConnection. What however still happened was that the NMConnection
instance gets never swapped but instead the instance was modified with
nm_connection_replace_settings_from_connection(), clear-secrets, etc.
Change that and treat the NMConnection instance immutable. Instead of modifying
it, reference/clone a new instance. This changes that previously when somebody
wanted to keep a reference to an NMConnection, then the profile would be cloned.
Now, it is supposed to be safe to reference the instance directly and everybody
must ensure not to modify the instance. nmtst_connection_assert_unchanging()
should help with that.
The point is that the settings plugins may keep references to the
NMConnection instance, and so does the NMSettingsConnection. We want
to avoid cloning the instances as long as they are the same.
Likewise, the device's applied connection can now also be referenced
instead of cloning it. This is not yet done, and possibly there are
further improvements possible.
--
Also implement multiple keyfile directores /usr/lib, /etc, /run (rh #1674545,
bgo #772414).
It was always the case that multiple files could provide the same UUID
(both in case of keyfile and ifcfg-rh). For keyfile plugin, if a profile in
read-only storage in /usr/lib gets modified, then it gets actually stored in
/etc (or /run, if the profile is unsaved).
--
While at it, make /etc/network/interfaces profiles for ifupdown plugin reloadable.
--
https://bugzilla.gnome.org/show_bug.cgi?id=772414
https://bugzilla.gnome.org/show_bug.cgi?id=744711
https://bugzilla.redhat.com/show_bug.cgi?id=1674545
2019-06-13 17:12:20 +02:00
|
|
|
guint update_reason_u,
|
2007-10-06 04:31:13 +00:00
|
|
|
gpointer user_data)
|
2015-09-07 14:17:39 +02:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicyPrivate *priv = user_data;
|
|
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
settings: rework tracking settings connections and settings plugins
Completely rework how settings plugin handle connections and how
NMSettings tracks the list of connections.
Previously, settings plugins would return objects of (a subtype of) type
NMSettingsConnection. The NMSettingsConnection was tightly coupled with
the settings plugin. That has a lot of downsides.
Change that. When changing this basic relation how settings connections
are tracked, everything falls appart. That's why this is a huge change.
Also, since I have to largely rewrite the settings plugins, I also
added support for multiple keyfile directories, handle in-memory
connections only by keyfile plugin and (partly) use copy-on-write NMConnection
instances. I don't want to spend effort rewriting large parts while
preserving the old way, that anyway should change. E.g. while rewriting ifcfg-rh,
I don't want to let it handle in-memory connections because that's not right
long-term.
--
If the settings plugins themself create subtypes of NMSettingsConnection
instances, then a lot of knowledge about tracking connections moves
to the plugins.
Just try to follow the code what happend during nm_settings_add_connection().
Note how the logic is spread out:
- nm_settings_add_connection() calls plugin's add_connection()
- add_connection() creates a NMSettingsConnection subtype
- the plugin has to know that it's called during add-connection and
not emit NM_SETTINGS_PLUGIN_CONNECTION_ADDED signal
- NMSettings calls claim_connection() which hocks up the new
NMSettingsConnection instance and configures the instance
(like calling nm_settings_connection_added()).
This summary does not sound like a lot, but try to follow that code. The logic
is all over the place.
Instead, settings plugins should have a very simple API for adding, modifying,
deleting, loading and reloading connections. All the plugin does is to return a
NMSettingsStorage handle. The storage instance is a handle to identify a profile
in storage (e.g. a particular file). The settings plugin is free to subtype
NMSettingsStorage, but it's not necessary.
There are no more events raised, and the settings plugin implements the small
API in a straightforward manner.
NMSettings now drives all of this. Even NMSettingsConnection has now
very little concern about how it's tracked and delegates only to NMSettings.
This should make settings plugins simpler. Currently settings plugins
are so cumbersome to implement, that we avoid having them. It should not be
like that and it should be easy, beneficial and lightweight to create a new
settings plugin.
Note also how the settings plugins no longer care about duplicate UUIDs.
Duplicated UUIDs are a fact of life and NMSettings must handle them. No
need to overly concern settings plugins with that.
--
NMSettingsConnection is exposed directly on D-Bus (being a subtype of
NMDBusObject) but it was also a GObject type provided by the settings
plugin. Hence, it was not possible to migrate a profile from one plugin to
another.
However that would be useful when one profile does not support a
connection type (like ifcfg-rh not supporting VPN). Currently such
migration is not implemented except for migrating them to/from keyfile's
run directory. The problem is that migrating profiles in general is
complicated but in some cases it is important to do.
For example checkpoint rollback should recreate the profile in the right
settings plugin, not just add it to persistent storage. This is not yet
properly implemented.
--
Previously, both keyfile and ifcfg-rh plugin implemented in-memory (unsaved)
profiles, while ifupdown plugin cannot handle them. That meant duplication of code
and a ifupdown profile could not be modified or made unsaved.
This is now unified and only keyfile plugin handles in-memory profiles (bgo #744711).
Also, NMSettings is aware of such profiles and treats them specially.
In particular, NMSettings drives the migration between persistent and non-persistent
storage.
Note that a settings plugins may create truly generated, in-memory profiles.
The settings plugin is free to generate and persist the profiles in any way it
wishes. But the concept of "unsaved" profiles is now something explicitly handled
by keyfile plugin. Also, these "unsaved" keyfile profiles are persisted to file system
too, to the /run directory. This is great for two reasons: first of all, all
profiles from keyfile storage in fact have a backing file -- even the
unsaved ones. It also means you can create "unsaved" profiles in /run
and load them with `nmcli connection load`, meaning there is a file
based API for creating unsaved profiles.
The other advantage is that these profiles now survive restarting
NetworkManager. It's paramount that restarting the daemon is as
non-disruptive as possible. Persisting unsaved files to /run improves
here significantly.
--
In the past, NMSettingsConnection also implemented NMConnection interface.
That was already changed a while ago and instead users call now
nm_settings_connection_get_connection() to delegate to a
NMSimpleConnection. What however still happened was that the NMConnection
instance gets never swapped but instead the instance was modified with
nm_connection_replace_settings_from_connection(), clear-secrets, etc.
Change that and treat the NMConnection instance immutable. Instead of modifying
it, reference/clone a new instance. This changes that previously when somebody
wanted to keep a reference to an NMConnection, then the profile would be cloned.
Now, it is supposed to be safe to reference the instance directly and everybody
must ensure not to modify the instance. nmtst_connection_assert_unchanging()
should help with that.
The point is that the settings plugins may keep references to the
NMConnection instance, and so does the NMSettingsConnection. We want
to avoid cloning the instances as long as they are the same.
Likewise, the device's applied connection can now also be referenced
instead of cloning it. This is not yet done, and possibly there are
further improvements possible.
--
Also implement multiple keyfile directores /usr/lib, /etc, /run (rh #1674545,
bgo #772414).
It was always the case that multiple files could provide the same UUID
(both in case of keyfile and ifcfg-rh). For keyfile plugin, if a profile in
read-only storage in /usr/lib gets modified, then it gets actually stored in
/etc (or /run, if the profile is unsaved).
--
While at it, make /etc/network/interfaces profiles for ifupdown plugin reloadable.
--
https://bugzilla.gnome.org/show_bug.cgi?id=772414
https://bugzilla.gnome.org/show_bug.cgi?id=744711
https://bugzilla.redhat.com/show_bug.cgi?id=1674545
2019-06-13 17:12:20 +02:00
|
|
|
NMSettingsConnectionUpdateReason update_reason = update_reason_u;
|
2015-09-07 12:02:54 +02:00
|
|
|
|
2023-05-03 11:34:06 +02:00
|
|
|
unblock_autoconnect_for_ports_for_sett_conn(self, connection);
|
|
|
|
|
|
settings: rework tracking settings connections and settings plugins
Completely rework how settings plugin handle connections and how
NMSettings tracks the list of connections.
Previously, settings plugins would return objects of (a subtype of) type
NMSettingsConnection. The NMSettingsConnection was tightly coupled with
the settings plugin. That has a lot of downsides.
Change that. When changing this basic relation how settings connections
are tracked, everything falls appart. That's why this is a huge change.
Also, since I have to largely rewrite the settings plugins, I also
added support for multiple keyfile directories, handle in-memory
connections only by keyfile plugin and (partly) use copy-on-write NMConnection
instances. I don't want to spend effort rewriting large parts while
preserving the old way, that anyway should change. E.g. while rewriting ifcfg-rh,
I don't want to let it handle in-memory connections because that's not right
long-term.
--
If the settings plugins themself create subtypes of NMSettingsConnection
instances, then a lot of knowledge about tracking connections moves
to the plugins.
Just try to follow the code what happend during nm_settings_add_connection().
Note how the logic is spread out:
- nm_settings_add_connection() calls plugin's add_connection()
- add_connection() creates a NMSettingsConnection subtype
- the plugin has to know that it's called during add-connection and
not emit NM_SETTINGS_PLUGIN_CONNECTION_ADDED signal
- NMSettings calls claim_connection() which hocks up the new
NMSettingsConnection instance and configures the instance
(like calling nm_settings_connection_added()).
This summary does not sound like a lot, but try to follow that code. The logic
is all over the place.
Instead, settings plugins should have a very simple API for adding, modifying,
deleting, loading and reloading connections. All the plugin does is to return a
NMSettingsStorage handle. The storage instance is a handle to identify a profile
in storage (e.g. a particular file). The settings plugin is free to subtype
NMSettingsStorage, but it's not necessary.
There are no more events raised, and the settings plugin implements the small
API in a straightforward manner.
NMSettings now drives all of this. Even NMSettingsConnection has now
very little concern about how it's tracked and delegates only to NMSettings.
This should make settings plugins simpler. Currently settings plugins
are so cumbersome to implement, that we avoid having them. It should not be
like that and it should be easy, beneficial and lightweight to create a new
settings plugin.
Note also how the settings plugins no longer care about duplicate UUIDs.
Duplicated UUIDs are a fact of life and NMSettings must handle them. No
need to overly concern settings plugins with that.
--
NMSettingsConnection is exposed directly on D-Bus (being a subtype of
NMDBusObject) but it was also a GObject type provided by the settings
plugin. Hence, it was not possible to migrate a profile from one plugin to
another.
However that would be useful when one profile does not support a
connection type (like ifcfg-rh not supporting VPN). Currently such
migration is not implemented except for migrating them to/from keyfile's
run directory. The problem is that migrating profiles in general is
complicated but in some cases it is important to do.
For example checkpoint rollback should recreate the profile in the right
settings plugin, not just add it to persistent storage. This is not yet
properly implemented.
--
Previously, both keyfile and ifcfg-rh plugin implemented in-memory (unsaved)
profiles, while ifupdown plugin cannot handle them. That meant duplication of code
and a ifupdown profile could not be modified or made unsaved.
This is now unified and only keyfile plugin handles in-memory profiles (bgo #744711).
Also, NMSettings is aware of such profiles and treats them specially.
In particular, NMSettings drives the migration between persistent and non-persistent
storage.
Note that a settings plugins may create truly generated, in-memory profiles.
The settings plugin is free to generate and persist the profiles in any way it
wishes. But the concept of "unsaved" profiles is now something explicitly handled
by keyfile plugin. Also, these "unsaved" keyfile profiles are persisted to file system
too, to the /run directory. This is great for two reasons: first of all, all
profiles from keyfile storage in fact have a backing file -- even the
unsaved ones. It also means you can create "unsaved" profiles in /run
and load them with `nmcli connection load`, meaning there is a file
based API for creating unsaved profiles.
The other advantage is that these profiles now survive restarting
NetworkManager. It's paramount that restarting the daemon is as
non-disruptive as possible. Persisting unsaved files to /run improves
here significantly.
--
In the past, NMSettingsConnection also implemented NMConnection interface.
That was already changed a while ago and instead users call now
nm_settings_connection_get_connection() to delegate to a
NMSimpleConnection. What however still happened was that the NMConnection
instance gets never swapped but instead the instance was modified with
nm_connection_replace_settings_from_connection(), clear-secrets, etc.
Change that and treat the NMConnection instance immutable. Instead of modifying
it, reference/clone a new instance. This changes that previously when somebody
wanted to keep a reference to an NMConnection, then the profile would be cloned.
Now, it is supposed to be safe to reference the instance directly and everybody
must ensure not to modify the instance. nmtst_connection_assert_unchanging()
should help with that.
The point is that the settings plugins may keep references to the
NMConnection instance, and so does the NMSettingsConnection. We want
to avoid cloning the instances as long as they are the same.
Likewise, the device's applied connection can now also be referenced
instead of cloning it. This is not yet done, and possibly there are
further improvements possible.
--
Also implement multiple keyfile directores /usr/lib, /etc, /run (rh #1674545,
bgo #772414).
It was always the case that multiple files could provide the same UUID
(both in case of keyfile and ifcfg-rh). For keyfile plugin, if a profile in
read-only storage in /usr/lib gets modified, then it gets actually stored in
/etc (or /run, if the profile is unsaved).
--
While at it, make /etc/network/interfaces profiles for ifupdown plugin reloadable.
--
https://bugzilla.gnome.org/show_bug.cgi?id=772414
https://bugzilla.gnome.org/show_bug.cgi?id=744711
https://bugzilla.redhat.com/show_bug.cgi?id=1674545
2019-06-13 17:12:20 +02:00
|
|
|
if (NM_FLAGS_HAS(update_reason, NM_SETTINGS_CONNECTION_UPDATE_REASON_REAPPLY_PARTIAL)) {
|
2019-07-11 13:08:52 +02:00
|
|
|
const CList *tmp_lst;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMDevice *device;
|
2019-07-11 13:08:52 +02:00
|
|
|
|
2016-04-13 16:03:06 +02:00
|
|
|
/* find device with given connection */
|
2019-07-11 13:08:52 +02:00
|
|
|
nm_manager_for_each_device (priv->manager, device, tmp_lst) {
|
|
|
|
|
if (nm_device_get_settings_connection(device) == connection)
|
|
|
|
|
nm_device_reapply_settings_immediately(device);
|
2015-09-07 12:02:54 +02:00
|
|
|
}
|
2016-04-13 16:03:06 +02:00
|
|
|
}
|
2015-07-14 16:53:24 +02:00
|
|
|
|
2023-04-05 11:02:36 +02:00
|
|
|
nm_policy_device_recheck_auto_activate_all_schedule(self);
|
2013-12-12 20:00:38 +01:00
|
|
|
}
|
|
|
|
|
|
2010-06-04 13:05:27 -07:00
|
|
|
static void
|
2010-10-27 20:05:23 -05:00
|
|
|
connection_removed(NMSettings *settings, NMSettingsConnection *connection, gpointer user_data)
|
2010-10-27 15:47:10 -05:00
|
|
|
{
|
2017-11-28 13:30:22 +01:00
|
|
|
NMPolicyPrivate *priv = user_data;
|
|
|
|
|
|
2023-03-28 23:10:25 +02:00
|
|
|
nm_manager_deactivate_ac(priv->manager, connection);
|
2010-10-27 15:47:10 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-12-04 16:05:26 +01:00
|
|
|
connection_flags_changed(NMSettings *settings, NMSettingsConnection *connection, gpointer user_data)
|
2010-06-04 13:05:27 -07:00
|
|
|
{
|
2016-04-04 14:36:34 +02:00
|
|
|
NMPolicyPrivate *priv = user_data;
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = _PRIV_TO_SELF(priv);
|
2010-10-27 15:47:10 -05:00
|
|
|
|
2017-12-05 12:10:16 +01:00
|
|
|
if (NM_FLAGS_HAS(nm_settings_connection_get_flags(connection),
|
2018-04-05 20:02:45 +02:00
|
|
|
NM_SETTINGS_CONNECTION_INT_FLAGS_VISIBLE)) {
|
2017-12-05 12:20:41 +01:00
|
|
|
if (!nm_settings_connection_autoconnect_is_blocked(connection))
|
2023-04-05 11:02:36 +02:00
|
|
|
nm_policy_device_recheck_auto_activate_all_schedule(self);
|
2018-10-10 17:10:01 +02:00
|
|
|
}
|
2010-06-04 13:05:27 -07:00
|
|
|
}
|
|
|
|
|
|
2011-06-28 15:48:12 +02:00
|
|
|
static void
|
|
|
|
|
secret_agent_registered(NMSettings *settings, NMSecretAgent *agent, gpointer user_data)
|
|
|
|
|
{
|
2017-11-27 09:07:28 +01:00
|
|
|
NMPolicy *self = NM_POLICY(user_data);
|
2013-12-05 04:57:01 -05:00
|
|
|
|
2011-06-28 15:48:12 +02:00
|
|
|
/* The registered secret agent may provide some missing secrets. Thus we
|
|
|
|
|
* reset retries count here and schedule activation, so that the
|
|
|
|
|
* connections failed due to missing secrets may re-try auto-connection.
|
|
|
|
|
*/
|
2017-11-22 14:52:54 +01:00
|
|
|
if (reset_autoconnect_all(self, NULL, TRUE))
|
2023-04-05 11:02:36 +02:00
|
|
|
nm_policy_device_recheck_auto_activate_all_schedule(self);
|
2011-06-28 15:48:12 +02:00
|
|
|
}
|
|
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
NMActiveConnection *
|
|
|
|
|
nm_policy_get_default_ip4_ac(NMPolicy *self)
|
2016-03-28 16:21:07 +02:00
|
|
|
{
|
2018-06-28 18:05:05 +02:00
|
|
|
return NM_POLICY_GET_PRIVATE(self)->default_ac4;
|
2016-03-28 16:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
NMActiveConnection *
|
|
|
|
|
nm_policy_get_default_ip6_ac(NMPolicy *self)
|
2016-03-28 16:21:07 +02:00
|
|
|
{
|
2018-06-28 18:05:05 +02:00
|
|
|
return NM_POLICY_GET_PRIVATE(self)->default_ac6;
|
2016-03-28 16:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
NMActiveConnection *
|
|
|
|
|
nm_policy_get_activating_ip4_ac(NMPolicy *self)
|
2016-03-28 16:21:07 +02:00
|
|
|
{
|
2018-06-28 18:05:05 +02:00
|
|
|
return NM_POLICY_GET_PRIVATE(self)->activating_ac4;
|
2016-03-28 16:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
NMActiveConnection *
|
|
|
|
|
nm_policy_get_activating_ip6_ac(NMPolicy *self)
|
2016-03-28 16:21:07 +02:00
|
|
|
{
|
2018-06-28 18:05:05 +02:00
|
|
|
return NM_POLICY_GET_PRIVATE(self)->activating_ac6;
|
2016-03-28 16:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2020-02-13 14:55:26 +01:00
|
|
|
static NM_UTILS_LOOKUP_STR_DEFINE(_hostname_mode_to_string,
|
|
|
|
|
NMPolicyHostnameMode,
|
2017-04-23 18:35:24 +02:00
|
|
|
NM_UTILS_LOOKUP_DEFAULT_NM_ASSERT("unknown"),
|
|
|
|
|
NM_UTILS_LOOKUP_STR_ITEM(NM_POLICY_HOSTNAME_MODE_NONE, "none"),
|
|
|
|
|
NM_UTILS_LOOKUP_STR_ITEM(NM_POLICY_HOSTNAME_MODE_DHCP, "dhcp"),
|
|
|
|
|
NM_UTILS_LOOKUP_STR_ITEM(NM_POLICY_HOSTNAME_MODE_FULL, "full"), );
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-03-28 16:21:07 +02:00
|
|
|
static void
|
|
|
|
|
get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = NM_POLICY(object);
|
2016-03-29 10:46:07 +02:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-03-28 16:21:07 +02:00
|
|
|
switch (prop_id) {
|
2018-06-28 18:05:05 +02:00
|
|
|
case PROP_DEFAULT_IP4_AC:
|
|
|
|
|
g_value_set_object(value, priv->default_ac4);
|
2016-03-28 16:21:07 +02:00
|
|
|
break;
|
2018-06-28 18:05:05 +02:00
|
|
|
case PROP_DEFAULT_IP6_AC:
|
|
|
|
|
g_value_set_object(value, priv->default_ac6);
|
2016-03-28 16:21:07 +02:00
|
|
|
break;
|
2018-06-28 18:05:05 +02:00
|
|
|
case PROP_ACTIVATING_IP4_AC:
|
|
|
|
|
g_value_set_object(value, priv->activating_ac4);
|
2016-03-28 16:21:07 +02:00
|
|
|
break;
|
2018-06-28 18:05:05 +02:00
|
|
|
case PROP_ACTIVATING_IP6_AC:
|
|
|
|
|
g_value_set_object(value, priv->activating_ac6);
|
2016-03-28 16:21:07 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-29 10:36:51 +02:00
|
|
|
static void
|
|
|
|
|
set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = NM_POLICY(object);
|
2016-03-29 10:46:07 +02:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-03-29 10:36:51 +02:00
|
|
|
switch (prop_id) {
|
|
|
|
|
case PROP_MANAGER:
|
|
|
|
|
/* construct-only */
|
|
|
|
|
priv->manager = g_value_get_object(value);
|
|
|
|
|
g_return_if_fail(NM_IS_MANAGER(priv->manager));
|
|
|
|
|
break;
|
|
|
|
|
case PROP_SETTINGS:
|
|
|
|
|
/* construct-only */
|
|
|
|
|
priv->settings = g_value_dup_object(value);
|
|
|
|
|
g_return_if_fail(NM_IS_SETTINGS(priv->settings));
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-28 16:21:07 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void
|
2016-03-29 10:46:07 +02:00
|
|
|
nm_policy_init(NMPolicy *self)
|
2016-03-28 16:21:07 +02:00
|
|
|
{
|
2016-09-29 13:49:01 +02:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2021-11-09 13:28:54 +01:00
|
|
|
gs_free char *hostname_mode = NULL;
|
2017-03-02 19:18:49 +01:00
|
|
|
|
2023-04-05 11:55:28 +02:00
|
|
|
c_list_init(&priv->policy_auto_activate_lst_head);
|
2017-11-22 12:15:24 +01:00
|
|
|
|
2017-04-17 20:17:45 +02:00
|
|
|
priv->netns = g_object_ref(nm_netns_get());
|
|
|
|
|
|
2017-04-23 00:40:46 +02:00
|
|
|
priv->hostname_manager = g_object_ref(nm_hostname_manager_get());
|
|
|
|
|
|
2017-03-02 19:18:49 +01:00
|
|
|
hostname_mode =
|
|
|
|
|
nm_config_data_get_value(NM_CONFIG_GET_DATA_ORIG,
|
|
|
|
|
NM_CONFIG_KEYFILE_GROUP_MAIN,
|
|
|
|
|
NM_CONFIG_KEYFILE_KEY_MAIN_HOSTNAME_MODE,
|
|
|
|
|
NM_CONFIG_GET_VALUE_STRIP | NM_CONFIG_GET_VALUE_NO_EMPTY);
|
|
|
|
|
if (nm_streq0(hostname_mode, "none"))
|
|
|
|
|
priv->hostname_mode = NM_POLICY_HOSTNAME_MODE_NONE;
|
|
|
|
|
else if (nm_streq0(hostname_mode, "dhcp"))
|
|
|
|
|
priv->hostname_mode = NM_POLICY_HOSTNAME_MODE_DHCP;
|
|
|
|
|
else /* default - full mode */
|
|
|
|
|
priv->hostname_mode = NM_POLICY_HOSTNAME_MODE_FULL;
|
2016-04-04 13:44:30 +02:00
|
|
|
|
2017-11-15 16:06:43 +01:00
|
|
|
priv->devices = g_hash_table_new(nm_direct_hash, NULL);
|
|
|
|
|
priv->pending_active_connections = g_hash_table_new(nm_direct_hash, NULL);
|
2016-10-31 23:31:14 +01:00
|
|
|
priv->ip6_prefix_delegations = g_array_new(FALSE, FALSE, sizeof(IP6PrefixDelegation));
|
|
|
|
|
g_array_set_clear_func(priv->ip6_prefix_delegations, clear_ip6_prefix_delegation);
|
2016-03-28 16:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
2016-03-29 10:36:51 +02:00
|
|
|
static void
|
|
|
|
|
constructed(GObject *object)
|
2007-02-08 15:34:26 +00:00
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = NM_POLICY(object);
|
2016-03-29 10:46:07 +02:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2021-11-09 13:28:54 +01:00
|
|
|
char *hostname = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2010-01-27 17:13:35 -08:00
|
|
|
/* Grab hostname on startup and use that if nothing provides one */
|
2017-04-23 19:54:39 +02:00
|
|
|
if ((hostname = _get_hostname(self))) {
|
2017-02-17 16:22:30 +01:00
|
|
|
/* init last_hostname */
|
|
|
|
|
priv->last_hostname = hostname;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2010-01-27 17:13:35 -08:00
|
|
|
/* only cache it if it's a valid hostname */
|
2017-02-17 15:33:27 +01:00
|
|
|
if (nm_utils_is_specific_hostname(hostname))
|
2017-02-17 16:22:30 +01:00
|
|
|
priv->orig_hostname = g_strdup(hostname);
|
2010-01-27 17:13:35 -08:00
|
|
|
}
|
2017-04-23 20:31:31 +02:00
|
|
|
_LOGT(LOGD_DNS,
|
|
|
|
|
"hostname-original: set to %s%s%s",
|
|
|
|
|
NM_PRINT_FMT_QUOTE_STRING(priv->orig_hostname));
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-27 09:07:28 +01:00
|
|
|
priv->agent_mgr = g_object_ref(nm_agent_manager_get());
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2021-05-04 16:01:13 +02:00
|
|
|
priv->firewalld_manager = g_object_ref(nm_firewalld_manager_get());
|
|
|
|
|
g_signal_connect(priv->firewalld_manager,
|
|
|
|
|
NM_FIREWALLD_MANAGER_STATE_CHANGED,
|
2017-04-20 18:30:01 +02:00
|
|
|
G_CALLBACK(firewall_state_changed),
|
|
|
|
|
self);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2015-01-05 17:20:23 +01:00
|
|
|
priv->dns_manager = g_object_ref(nm_dns_manager_get());
|
2022-03-04 09:29:38 +01:00
|
|
|
nm_dns_manager_set_hostname(priv->dns_manager, priv->orig_hostname, TRUE);
|
2020-12-17 14:13:45 +01:00
|
|
|
priv->config_changed_id = g_signal_connect(priv->dns_manager,
|
|
|
|
|
NM_DNS_MANAGER_CONFIG_CHANGED,
|
|
|
|
|
G_CALLBACK(dns_config_changed),
|
|
|
|
|
self);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-23 19:30:07 +02:00
|
|
|
g_signal_connect(priv->hostname_manager,
|
2022-01-04 18:28:46 +01:00
|
|
|
"notify::" NM_HOSTNAME_MANAGER_STATIC_HOSTNAME,
|
|
|
|
|
G_CALLBACK(_static_hostname_changed_cb),
|
2017-04-23 14:20:37 +02:00
|
|
|
priv);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-23 14:20:37 +02:00
|
|
|
g_signal_connect(priv->manager,
|
2016-04-04 14:36:34 +02:00
|
|
|
"notify::" NM_MANAGER_SLEEPING,
|
2021-08-05 09:06:12 +02:00
|
|
|
G_CALLBACK(sleeping_changed),
|
2016-04-04 14:36:34 +02:00
|
|
|
priv);
|
|
|
|
|
g_signal_connect(priv->manager,
|
|
|
|
|
"notify::" NM_MANAGER_NETWORKING_ENABLED,
|
2021-08-05 09:06:12 +02:00
|
|
|
G_CALLBACK(sleeping_changed),
|
2016-04-04 14:36:34 +02:00
|
|
|
priv);
|
|
|
|
|
g_signal_connect(priv->manager,
|
|
|
|
|
NM_MANAGER_INTERNAL_DEVICE_ADDED,
|
2021-08-05 09:06:12 +02:00
|
|
|
G_CALLBACK(device_added),
|
2016-04-04 14:36:34 +02:00
|
|
|
priv);
|
|
|
|
|
g_signal_connect(priv->manager,
|
|
|
|
|
NM_MANAGER_INTERNAL_DEVICE_REMOVED,
|
2021-08-05 09:06:12 +02:00
|
|
|
G_CALLBACK(device_removed),
|
2016-04-04 14:36:34 +02:00
|
|
|
priv);
|
|
|
|
|
g_signal_connect(priv->manager,
|
|
|
|
|
NM_MANAGER_ACTIVE_CONNECTION_ADDED,
|
2021-08-05 09:06:12 +02:00
|
|
|
G_CALLBACK(active_connection_added),
|
2016-04-04 14:36:34 +02:00
|
|
|
priv);
|
|
|
|
|
g_signal_connect(priv->manager,
|
|
|
|
|
NM_MANAGER_ACTIVE_CONNECTION_REMOVED,
|
2021-08-05 09:06:12 +02:00
|
|
|
G_CALLBACK(active_connection_removed),
|
2016-04-04 14:36:34 +02:00
|
|
|
priv);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-12-04 16:05:26 +01:00
|
|
|
g_signal_connect(priv->settings,
|
|
|
|
|
NM_SETTINGS_SIGNAL_CONNECTION_ADDED,
|
2021-08-05 09:06:12 +02:00
|
|
|
G_CALLBACK(connection_added),
|
2017-12-04 16:05:26 +01:00
|
|
|
priv);
|
|
|
|
|
g_signal_connect(priv->settings,
|
|
|
|
|
NM_SETTINGS_SIGNAL_CONNECTION_UPDATED,
|
2021-08-05 09:06:12 +02:00
|
|
|
G_CALLBACK(connection_updated),
|
2017-12-04 16:05:26 +01:00
|
|
|
priv);
|
|
|
|
|
g_signal_connect(priv->settings,
|
|
|
|
|
NM_SETTINGS_SIGNAL_CONNECTION_REMOVED,
|
2021-08-05 09:06:12 +02:00
|
|
|
G_CALLBACK(connection_removed),
|
2017-12-04 16:05:26 +01:00
|
|
|
priv);
|
|
|
|
|
g_signal_connect(priv->settings,
|
|
|
|
|
NM_SETTINGS_SIGNAL_CONNECTION_FLAGS_CHANGED,
|
2021-08-05 09:06:12 +02:00
|
|
|
G_CALLBACK(connection_flags_changed),
|
2017-12-04 16:05:26 +01:00
|
|
|
priv);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-27 09:07:28 +01:00
|
|
|
g_signal_connect(priv->agent_mgr,
|
|
|
|
|
NM_AGENT_MANAGER_AGENT_REGISTERED,
|
|
|
|
|
G_CALLBACK(secret_agent_registered),
|
|
|
|
|
self);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-03-29 10:36:51 +02:00
|
|
|
G_OBJECT_CLASS(nm_policy_parent_class)->constructed(object);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-04-23 18:35:24 +02:00
|
|
|
_LOGD(LOGD_DNS, "hostname-mode: %s", _hostname_mode_to_string(priv->hostname_mode));
|
2024-07-31 17:08:43 +02:00
|
|
|
update_system_hostname(self, "initial hostname", FALSE);
|
2016-03-29 10:36:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NMPolicy *
|
|
|
|
|
nm_policy_new(NMManager *manager, NMSettings *settings)
|
|
|
|
|
{
|
|
|
|
|
g_return_val_if_fail(NM_IS_MANAGER(manager), NULL);
|
|
|
|
|
g_return_val_if_fail(NM_IS_SETTINGS(settings), NULL);
|
2016-03-29 10:39:47 +02:00
|
|
|
|
|
|
|
|
return g_object_new(NM_TYPE_POLICY,
|
|
|
|
|
NM_POLICY_MANAGER,
|
|
|
|
|
manager,
|
|
|
|
|
NM_POLICY_SETTINGS,
|
|
|
|
|
settings,
|
|
|
|
|
NULL);
|
2007-02-08 15:34:26 +00:00
|
|
|
}
|
|
|
|
|
|
2013-08-22 10:10:17 -04:00
|
|
|
static void
|
|
|
|
|
dispose(GObject *object)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = NM_POLICY(object);
|
2016-03-29 10:46:07 +02:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
2023-04-07 13:34:34 +02:00
|
|
|
|
2024-07-09 10:44:21 +02:00
|
|
|
nm_assert(c_list_is_empty(&priv->policy_auto_activate_lst_head));
|
2023-04-07 13:34:34 +02:00
|
|
|
nm_assert(g_hash_table_size(priv->devices) == 0);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2018-06-28 18:05:05 +02:00
|
|
|
nm_clear_g_object(&priv->default_ac4);
|
|
|
|
|
nm_clear_g_object(&priv->default_ac6);
|
|
|
|
|
nm_clear_g_object(&priv->activating_ac4);
|
|
|
|
|
nm_clear_g_object(&priv->activating_ac6);
|
all: use nm_clear_pointer() instead of g_clear_pointer()
g_clear_pointer() would always cast the destroy notify function
pointer to GDestroyNotify. That means, it lost some type safety, like
GPtrArray *ptr_arr = ...
g_clear_pointer (&ptr_arr, g_array_unref);
Since glib 2.58 ([1]), g_clear_pointer() is also more type safe. But
this is not used by NetworkManager, because we don't set
GLIB_VERSION_MIN_REQUIRED to 2.58.
[1] https://gitlab.gnome.org/GNOME/glib/-/commit/f9a9902aac826ab4aecc25f6eb533a418a4fa559
We have nm_clear_pointer() to avoid this issue for a long time (pre
1.12.0). Possibly we should redefine in our source tree g_clear_pointer()
as nm_clear_pointer(). However, I don't like to patch glib functions
with our own variant. Arguably, we do patch g_clear_error() in
such a manner. But there the point is to make the function inlinable.
Also, nm_clear_pointer() returns a boolean that indicates whether
anything was cleared. That is sometimes useful. I think we should
just consistently use nm_clear_pointer() instead, which does always
the preferable thing.
Replace:
sed 's/\<g_clear_pointer *(\([^;]*\), *\([a-z_A-Z0-9]\+\) *)/nm_clear_pointer (\1, \2)/g' $(git grep -l g_clear_pointer) -i
2020-03-23 11:09:24 +01:00
|
|
|
nm_clear_pointer(&priv->pending_active_connections, g_hash_table_unref);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-08-22 10:10:17 -04:00
|
|
|
g_slist_free_full(priv->pending_secondaries, (GDestroyNotify) pending_secondary_data_free);
|
|
|
|
|
priv->pending_secondaries = NULL;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2021-05-04 16:01:13 +02:00
|
|
|
if (priv->firewalld_manager) {
|
|
|
|
|
g_signal_handlers_disconnect_by_func(priv->firewalld_manager, firewall_state_changed, self);
|
|
|
|
|
g_clear_object(&priv->firewalld_manager);
|
2013-08-22 10:10:17 -04:00
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2017-11-27 09:07:28 +01:00
|
|
|
if (priv->agent_mgr) {
|
|
|
|
|
g_signal_handlers_disconnect_by_func(priv->agent_mgr, secret_agent_registered, self);
|
|
|
|
|
g_clear_object(&priv->agent_mgr);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2020-12-17 14:13:45 +01:00
|
|
|
if (priv->dns_manager) {
|
|
|
|
|
nm_clear_g_signal_handler(priv->dns_manager, &priv->config_changed_id);
|
|
|
|
|
g_clear_object(&priv->dns_manager);
|
|
|
|
|
}
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-08-30 17:57:56 -05:00
|
|
|
/* The manager should have disposed of ActiveConnections already, which
|
|
|
|
|
* will have called active_connection_removed() and thus we don't need
|
|
|
|
|
* to clean anything up. Assert that this is TRUE.
|
|
|
|
|
*/
|
2017-11-23 21:30:09 +01:00
|
|
|
nm_assert(c_list_is_empty(nm_manager_get_active_connections(priv->manager)));
|
2013-08-22 10:10:17 -04:00
|
|
|
|
2023-04-07 13:08:14 +02:00
|
|
|
nm_clear_g_source_inst(&priv->reset_connections_retries_idle_source);
|
2023-04-07 12:55:57 +02:00
|
|
|
nm_clear_g_source_inst(&priv->device_recheck_auto_activate_all_idle_source);
|
2024-07-31 17:08:43 +02:00
|
|
|
nm_clear_g_source_inst(&priv->hostname_retry.source);
|
2012-08-22 18:34:45 -05:00
|
|
|
|
2020-03-23 11:00:43 +01:00
|
|
|
nm_clear_g_free(&priv->orig_hostname);
|
|
|
|
|
nm_clear_g_free(&priv->cur_hostname);
|
2022-03-04 08:10:17 +01:00
|
|
|
nm_clear_g_free(&priv->cur_hostname_full);
|
2020-03-23 11:00:43 +01:00
|
|
|
nm_clear_g_free(&priv->last_hostname);
|
2011-06-17 12:43:28 +02:00
|
|
|
|
2017-04-23 14:20:37 +02:00
|
|
|
if (priv->hostname_manager) {
|
|
|
|
|
g_signal_handlers_disconnect_by_data(priv->hostname_manager, priv);
|
|
|
|
|
g_clear_object(&priv->hostname_manager);
|
|
|
|
|
}
|
|
|
|
|
|
2016-04-04 14:07:46 +02:00
|
|
|
if (priv->settings) {
|
2016-04-04 14:36:34 +02:00
|
|
|
g_signal_handlers_disconnect_by_data(priv->settings, priv);
|
2016-04-04 14:07:46 +02:00
|
|
|
g_clear_object(&priv->settings);
|
2016-04-04 14:07:46 +02:00
|
|
|
|
|
|
|
|
/* we don't clear priv->manager as we don't own a reference to it,
|
|
|
|
|
* that is, NMManager must outlive NMPolicy anyway.
|
|
|
|
|
*
|
|
|
|
|
* Hence, we unsubscribe the signals here together with the signals
|
|
|
|
|
* for settings. */
|
2016-04-04 14:36:34 +02:00
|
|
|
g_signal_handlers_disconnect_by_data(priv->manager, priv);
|
2016-04-04 14:07:46 +02:00
|
|
|
}
|
2010-01-27 17:13:35 -08:00
|
|
|
|
2016-11-09 17:58:11 +01:00
|
|
|
if (priv->ip6_prefix_delegations) {
|
|
|
|
|
g_array_free(priv->ip6_prefix_delegations, TRUE);
|
|
|
|
|
priv->ip6_prefix_delegations = NULL;
|
|
|
|
|
}
|
2016-10-31 23:31:14 +01:00
|
|
|
|
2016-03-29 10:36:51 +02:00
|
|
|
nm_assert(NM_IS_MANAGER(priv->manager));
|
|
|
|
|
|
2013-08-22 10:10:17 -04:00
|
|
|
G_OBJECT_CLASS(nm_policy_parent_class)->dispose(object);
|
2007-02-08 15:34:26 +00:00
|
|
|
}
|
2007-08-15 01:59:19 +00:00
|
|
|
|
2016-04-04 13:44:30 +02:00
|
|
|
static void
|
|
|
|
|
finalize(GObject *object)
|
|
|
|
|
{
|
2021-11-09 13:28:54 +01:00
|
|
|
NMPolicy *self = NM_POLICY(object);
|
2016-04-04 13:44:30 +02:00
|
|
|
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
|
|
|
|
|
|
|
|
|
|
g_hash_table_unref(priv->devices);
|
|
|
|
|
|
|
|
|
|
G_OBJECT_CLASS(nm_policy_parent_class)->finalize(object);
|
2017-04-17 20:17:45 +02:00
|
|
|
|
|
|
|
|
g_object_unref(priv->netns);
|
2016-04-04 13:44:30 +02:00
|
|
|
}
|
|
|
|
|
|
2013-08-22 10:10:17 -04:00
|
|
|
static void
|
|
|
|
|
nm_policy_class_init(NMPolicyClass *policy_class)
|
|
|
|
|
{
|
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS(policy_class);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2013-08-22 13:06:51 -04:00
|
|
|
object_class->get_property = get_property;
|
2016-03-29 10:36:51 +02:00
|
|
|
object_class->set_property = set_property;
|
|
|
|
|
object_class->constructed = constructed;
|
2013-08-22 10:10:17 -04:00
|
|
|
object_class->dispose = dispose;
|
2016-04-04 13:44:30 +02:00
|
|
|
object_class->finalize = finalize;
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-03-29 10:36:51 +02:00
|
|
|
obj_properties[PROP_MANAGER] =
|
|
|
|
|
g_param_spec_object(NM_POLICY_MANAGER,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
NM_TYPE_MANAGER,
|
|
|
|
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
|
|
|
|
obj_properties[PROP_SETTINGS] =
|
|
|
|
|
g_param_spec_object(NM_POLICY_SETTINGS,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
NM_TYPE_SETTINGS,
|
|
|
|
|
G_PARAM_WRITABLE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
2018-06-28 18:05:05 +02:00
|
|
|
obj_properties[PROP_DEFAULT_IP4_AC] =
|
|
|
|
|
g_param_spec_object(NM_POLICY_DEFAULT_IP4_AC,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
|
|
|
|
NM_TYPE_ACTIVE_CONNECTION,
|
2016-03-28 20:49:18 +02:00
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
2018-06-28 18:05:05 +02:00
|
|
|
obj_properties[PROP_DEFAULT_IP6_AC] =
|
|
|
|
|
g_param_spec_object(NM_POLICY_DEFAULT_IP6_AC,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
2016-03-28 20:49:18 +02:00
|
|
|
NM_TYPE_DEVICE,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
2018-06-28 18:05:05 +02:00
|
|
|
obj_properties[PROP_ACTIVATING_IP4_AC] =
|
|
|
|
|
g_param_spec_object(NM_POLICY_ACTIVATING_IP4_AC,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
2016-03-28 20:49:18 +02:00
|
|
|
NM_TYPE_DEVICE,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
2018-06-28 18:05:05 +02:00
|
|
|
obj_properties[PROP_ACTIVATING_IP6_AC] =
|
|
|
|
|
g_param_spec_object(NM_POLICY_ACTIVATING_IP6_AC,
|
|
|
|
|
"",
|
|
|
|
|
"",
|
2016-03-28 20:49:18 +02:00
|
|
|
NM_TYPE_DEVICE,
|
|
|
|
|
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2016-03-28 20:49:18 +02:00
|
|
|
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
2013-08-22 10:10:17 -04:00
|
|
|
}
|