2020-12-23 22:21:36 +01:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
2019-09-25 13:13:40 +02:00
|
|
|
/*
|
2008-11-03 04:13:42 +00:00
|
|
|
* Copyright (C) 2007 - 2008 Novell, Inc.
|
2011-01-10 23:39:12 -06:00
|
|
|
* Copyright (C) 2007 - 2011 Red Hat, Inc.
|
2005-12-31 08:21:24 +00:00
|
|
|
*/
|
|
|
|
|
|
all: fix up multiple-include-guard defines
Previously, src/nm-ip4-config.h, libnm/nm-ip4-config.h, and
libnm-glib/nm-ip4-config.h all used "NM_IP4_CONFIG_H" as an include
guard, which meant that nm-test-utils.h could not tell which of them
was being included (and so, eg, if you tried to include
nm-ip4-config.h in a libnm test, it would fail to compile because
nm-test-utils.h was referring to symbols in src/nm-ip4-config.h).
Fix this by changing the include guards in the non-API-stable parts of
the tree:
- libnm-glib/nm-ip4-config.h remains NM_IP4_CONFIG_H
- libnm/nm-ip4-config.h now uses __NM_IP4_CONFIG_H__
- src/nm-ip4-config.h now uses __NETWORKMANAGER_IP4_CONFIG_H__
And likewise for all other headers.
The two non-"nm"-prefixed headers, libnm/NetworkManager.h and
src/NetworkManagerUtils.h are now __NETWORKMANAGER_H__ and
__NETWORKMANAGER_UTILS_H__ respectively, which, while not entirely
consistent with the general scheme, do still mostly make sense in
isolation.
2014-08-13 14:10:11 -04:00
|
|
|
#ifndef __NETWORKMANAGER_DEVICE_PRIVATE_H__
|
|
|
|
|
#define __NETWORKMANAGER_DEVICE_PRIVATE_H__
|
2005-12-31 08:21:24 +00:00
|
|
|
|
|
|
|
|
#include "nm-device.h"
|
2021-08-06 15:17:05 +02:00
|
|
|
#include "nm-l3-config-data.h"
|
2006-10-13 19:41:47 +00:00
|
|
|
|
2011-11-17 22:39:34 -06:00
|
|
|
/* This file should only be used by subclasses of NMDevice */
|
|
|
|
|
|
device: move SR-IOV initialization to activate_stage1_device_prepare()
Note that all subclasses of NMDevice that implement act_stage1_prepare(), call
the parents implementation as very first thing.
Previously, NMDevice's act_stage1_prepare() was setting up SR-IOV. But that is
problemantic. Note that it may have returned NM_ACT_STAGE_RETURN_POSTPONE, in which
case subclasses would just skip their action and return to the caller. Later,
sriov_params_cb() would directly call nm_device_activate_schedule_stage2_device_config(),
and thus act_stage1_prepare() was never executed for the subclass. That
is wrong.
First, I don't think it is good to let subclasses decide whether to call a
parents implementation (and when). It just causes ambiguity. In
the best case we do it always in the same order, in the worst case we
call the parent at the wrong time or never. Instead, we want to initialize
SR-IOV always and early in stage1, so we should just do it directly from
activate_stage1_device_prepare(). Now NMDevice's act_stage1_prepare() does
nothing.
The bigger problem is that when a device wants to resume a stage that
it previously postponed, that it would schedule the next stage!
Instead, it should schedule the same stage again instead. That allows
to postpone the completion of a stage for multiple reasons, and each
call to a certain stage merely notifies that something changed and
we need to check whether we can now complete the stage.
For that to work, stages must become re-entrant. That means we need to
remember whether an action that we care about needs to be started, is pending
or already completed.
Compare this to nm_device_activate_schedule_stage3_ip_config_start(),
which checks whether firewall is configured. That is likewise the wrong
approach. Callers that were in stage2 and postponed stage2, and later would
schedule stage3 when they are ready.
Then nm_device_activate_schedule_stage3_ip_config_start() would check whether
firewall is also ready, and do nothing if that's not the case (relying
that when the firewall code completes to call
nm_device_activate_schedule_stage3_ip_config_start().
2019-08-21 14:30:34 +02:00
|
|
|
typedef enum {
|
|
|
|
|
NM_DEVICE_STAGE_STATE_INIT = 0,
|
|
|
|
|
NM_DEVICE_STAGE_STATE_PENDING = 1,
|
|
|
|
|
NM_DEVICE_STAGE_STATE_COMPLETED = 2,
|
|
|
|
|
} NMDeviceStageState;
|
|
|
|
|
|
2011-11-17 22:39:34 -06:00
|
|
|
enum NMActStageReturn {
|
2016-08-31 18:51:16 +02:00
|
|
|
NM_ACT_STAGE_RETURN_FAILURE = 0, /* Hard failure of activation */
|
2012-11-15 14:47:05 -06:00
|
|
|
NM_ACT_STAGE_RETURN_SUCCESS, /* Activation stage done */
|
|
|
|
|
NM_ACT_STAGE_RETURN_POSTPONE, /* Long-running operation in progress */
|
2011-11-17 22:39:34 -06:00
|
|
|
};
|
|
|
|
|
|
2013-05-07 10:23:44 -04:00
|
|
|
#define NM_DEVICE_CAP_NONSTANDARD_CARRIER 0x80000000
|
2014-11-13 17:17:06 -05:00
|
|
|
#define NM_DEVICE_CAP_IS_NON_KERNEL 0x40000000
|
2013-05-07 10:23:44 -04:00
|
|
|
|
2014-11-13 17:17:06 -05:00
|
|
|
#define NM_DEVICE_CAP_INTERNAL_MASK 0xc0000000
|
2013-05-07 10:23:44 -04:00
|
|
|
|
2016-05-16 19:01:37 +02:00
|
|
|
NMSettings *nm_device_get_settings(NMDevice *self);
|
|
|
|
|
|
2020-04-26 14:44:41 +02:00
|
|
|
NMManager *nm_device_get_manager(NMDevice *self);
|
|
|
|
|
|
2018-01-08 16:31:56 +01:00
|
|
|
gboolean nm_device_set_ip_ifindex(NMDevice *self, int ifindex);
|
2018-01-08 16:45:43 +01:00
|
|
|
|
2017-01-11 19:35:09 -06:00
|
|
|
gboolean nm_device_set_ip_iface(NMDevice *self, const char *iface);
|
2006-01-03 17:07:07 +00:00
|
|
|
|
2013-06-13 15:13:58 -05:00
|
|
|
gboolean nm_device_bring_up(NMDevice *self, gboolean wait, gboolean *no_firmware);
|
2008-05-14 01:55:49 +00:00
|
|
|
|
2013-06-13 15:13:58 -05:00
|
|
|
void nm_device_take_down(NMDevice *self, gboolean block);
|
2008-05-14 01:55:49 +00:00
|
|
|
|
2020-06-22 17:04:06 +02:00
|
|
|
gboolean nm_device_take_over_link(NMDevice *self, int ifindex, char **old_name, GError **error);
|
2017-07-03 16:24:59 +02:00
|
|
|
|
2021-11-09 13:28:54 +01:00
|
|
|
gboolean nm_device_hw_addr_set(NMDevice *device,
|
2016-10-25 16:41:42 +02:00
|
|
|
const char *addr,
|
|
|
|
|
const char *detail,
|
|
|
|
|
gboolean set_permanent);
|
device: extend MAC address handling including randomization for ethernet and wifi
Extend the "ethernet.cloned-mac-address" and "wifi.cloned-mac-address"
settings. Instead of specifying an explicit MAC address, the additional
special values "permanent", "preserve", "random", "random-bia", "stable" and
"stable-bia" are supported.
"permanent" means to use the permanent hardware address. Previously that
was the default if no explict cloned-mac-address was set. The default is
thus still "permanent", but it can be overwritten by global
configuration.
"preserve" means not to configure the MAC address when activating the
device. That was actually the default behavior before introducing MAC
address handling with commit 1b49f941a69af910b0e68530be7339e8053068e5.
"random" and "random-bia" use a randomized MAC address for each
connection. "stable" and "stable-bia" use a generated, stable
address based on some token. The "bia" suffix says to generate a
burned-in address. The stable method by default uses as token the
connection UUID, but the token can be explicitly choosen via
"stable:<TOKEN>" and "stable-bia:<TOKEN>".
On a D-Bus level, the "cloned-mac-address" is a bytestring and thus
cannot express the new forms. It is replaced by the new
"assigned-mac-address" field. For the GObject property, libnm's API,
nmcli, keyfile, etc. the old name "cloned-mac-address" is still used.
Deprecating the old field seems more complicated then just extending
the use of the existing "cloned-mac-address" field, although the name
doesn't match well with the extended meaning.
There is some overlap with the "wifi.mac-address-randomization" setting.
https://bugzilla.gnome.org/show_bug.cgi?id=705545
https://bugzilla.gnome.org/show_bug.cgi?id=708820
https://bugzilla.gnome.org/show_bug.cgi?id=758301
2016-05-24 15:57:16 +02:00
|
|
|
gboolean nm_device_hw_addr_set_cloned(NMDevice *device, NMConnection *connection, gboolean is_wifi);
|
2016-06-21 11:22:07 +02:00
|
|
|
gboolean nm_device_hw_addr_reset(NMDevice *device, const char *detail);
|
2012-06-13 11:32:47 -05:00
|
|
|
|
2010-07-01 10:32:11 -07:00
|
|
|
void nm_device_set_firmware_missing(NMDevice *self, gboolean missing);
|
|
|
|
|
|
2020-02-28 13:55:40 +01:00
|
|
|
void nm_device_activate_schedule_stage1_device_prepare(NMDevice *device, gboolean do_sync);
|
2020-02-28 13:55:40 +01:00
|
|
|
void nm_device_activate_schedule_stage2_device_config(NMDevice *device, gboolean do_sync);
|
2021-08-06 15:17:05 +02:00
|
|
|
void nm_device_activate_schedule_stage3_ip_config(NMDevice *device, gboolean do_sync);
|
2011-11-17 22:39:34 -06:00
|
|
|
|
2012-08-01 11:16:48 -06:00
|
|
|
void nm_device_recheck_available_connections(NMDevice *device);
|
|
|
|
|
|
2014-07-15 13:36:24 +02:00
|
|
|
void
|
|
|
|
|
nm_device_master_check_slave_physical_port(NMDevice *self, NMDevice *slave, NMLogDomain log_domain);
|
2013-10-11 14:59:26 -04:00
|
|
|
|
2022-02-23 21:11:04 +01:00
|
|
|
void nm_device_master_release_slaves_all(NMDevice *self);
|
2021-01-19 18:38:57 +01:00
|
|
|
|
2014-07-15 13:36:24 +02:00
|
|
|
void nm_device_set_carrier(NMDevice *self, gboolean carrier);
|
2013-05-07 10:23:44 -04:00
|
|
|
|
2014-05-28 10:18:34 -04:00
|
|
|
void nm_device_queue_recheck_assume(NMDevice *device);
|
2021-11-09 13:28:54 +01:00
|
|
|
void nm_device_queue_recheck_available(NMDevice *device,
|
2015-04-13 17:16:55 -05:00
|
|
|
NMDeviceStateReason available_reason,
|
|
|
|
|
NMDeviceStateReason unavailable_reason);
|
2014-02-24 18:10:18 -06:00
|
|
|
|
device: extend MAC address handling including randomization for ethernet and wifi
Extend the "ethernet.cloned-mac-address" and "wifi.cloned-mac-address"
settings. Instead of specifying an explicit MAC address, the additional
special values "permanent", "preserve", "random", "random-bia", "stable" and
"stable-bia" are supported.
"permanent" means to use the permanent hardware address. Previously that
was the default if no explict cloned-mac-address was set. The default is
thus still "permanent", but it can be overwritten by global
configuration.
"preserve" means not to configure the MAC address when activating the
device. That was actually the default behavior before introducing MAC
address handling with commit 1b49f941a69af910b0e68530be7339e8053068e5.
"random" and "random-bia" use a randomized MAC address for each
connection. "stable" and "stable-bia" use a generated, stable
address based on some token. The "bia" suffix says to generate a
burned-in address. The stable method by default uses as token the
connection UUID, but the token can be explicitly choosen via
"stable:<TOKEN>" and "stable-bia:<TOKEN>".
On a D-Bus level, the "cloned-mac-address" is a bytestring and thus
cannot express the new forms. It is replaced by the new
"assigned-mac-address" field. For the GObject property, libnm's API,
nmcli, keyfile, etc. the old name "cloned-mac-address" is still used.
Deprecating the old field seems more complicated then just extending
the use of the existing "cloned-mac-address" field, although the name
doesn't match well with the extended meaning.
There is some overlap with the "wifi.mac-address-randomization" setting.
https://bugzilla.gnome.org/show_bug.cgi?id=705545
https://bugzilla.gnome.org/show_bug.cgi?id=708820
https://bugzilla.gnome.org/show_bug.cgi?id=758301
2016-05-24 15:57:16 +02:00
|
|
|
gboolean nm_device_hw_addr_is_explict(NMDevice *device);
|
|
|
|
|
|
2021-08-06 15:17:05 +02:00
|
|
|
NMDeviceIPState nm_device_devip_get_state(NMDevice *self, int addr_family);
|
|
|
|
|
|
2021-11-09 13:28:54 +01:00
|
|
|
void nm_device_devip_set_state_full(NMDevice *self,
|
2021-08-06 15:17:05 +02:00
|
|
|
int addr_family,
|
|
|
|
|
NMDeviceIPState ip_state,
|
|
|
|
|
const NML3ConfigData *l3cd,
|
|
|
|
|
NMDeviceStateReason failed_reason);
|
|
|
|
|
|
|
|
|
|
static inline void
|
2021-11-09 13:28:54 +01:00
|
|
|
nm_device_devip_set_state(NMDevice *self,
|
2021-08-06 15:17:05 +02:00
|
|
|
int addr_family,
|
|
|
|
|
NMDeviceIPState ip_state,
|
|
|
|
|
const NML3ConfigData *l3cd)
|
|
|
|
|
{
|
|
|
|
|
nm_assert(NM_IS_DEVICE(self));
|
|
|
|
|
nm_assert_addr_family_or_unspec(addr_family);
|
|
|
|
|
nm_assert(!l3cd || NM_IS_L3_CONFIG_DATA(l3cd));
|
|
|
|
|
nm_assert(NM_IN_SET(ip_state, NM_DEVICE_IP_STATE_PENDING, NM_DEVICE_IP_STATE_READY));
|
|
|
|
|
|
|
|
|
|
nm_device_devip_set_state_full(self, addr_family, ip_state, l3cd, NM_DEVICE_STATE_REASON_NONE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
|
nm_device_devip_set_failed(NMDevice *self, int addr_family, NMDeviceStateReason reason)
|
|
|
|
|
{
|
|
|
|
|
nm_assert(NM_IS_DEVICE(self));
|
|
|
|
|
nm_assert_addr_family_or_unspec(addr_family);
|
|
|
|
|
nm_assert(reason != NM_DEVICE_STATE_REASON_NONE);
|
|
|
|
|
|
|
|
|
|
nm_device_devip_set_state_full(self, addr_family, NM_DEVICE_IP_STATE_FAILED, NULL, reason);
|
|
|
|
|
}
|
2016-04-07 13:48:34 +02:00
|
|
|
|
2021-11-09 13:28:54 +01:00
|
|
|
gboolean nm_device_sysctl_ip_conf_set(NMDevice *self,
|
2018-12-13 11:34:39 +01:00
|
|
|
int addr_family,
|
|
|
|
|
const char *property,
|
|
|
|
|
const char *value);
|
2014-07-15 17:16:56 -05:00
|
|
|
|
2021-08-06 15:17:05 +02:00
|
|
|
NML3ConfigData *nm_device_create_l3_config_data(NMDevice *self, NMIPConfigSource source);
|
2019-03-02 20:21:50 +01:00
|
|
|
|
2021-11-09 13:28:54 +01:00
|
|
|
const NML3ConfigData *nm_device_create_l3_config_data_from_connection(NMDevice *self,
|
2021-08-06 15:17:05 +02:00
|
|
|
NMConnection *connection);
|
2019-03-02 20:21:50 +01:00
|
|
|
|
2021-08-06 15:17:05 +02:00
|
|
|
void nm_device_ip_method_dhcp4_start(NMDevice *self);
|
2019-03-02 20:21:50 +01:00
|
|
|
|
2021-08-06 15:17:05 +02:00
|
|
|
void nm_device_ip_method_autoconf6_start(NMDevice *self);
|
2020-08-27 19:06:15 +02:00
|
|
|
|
2017-01-14 17:04:17 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-11-09 13:28:54 +01:00
|
|
|
gint64 nm_device_get_configured_mtu_from_connection_default(NMDevice *self,
|
2019-04-05 12:31:49 +02:00
|
|
|
const char *property_name,
|
|
|
|
|
guint32 max_mtu);
|
2017-01-17 13:11:07 +01:00
|
|
|
|
2021-11-09 13:28:54 +01:00
|
|
|
guint32 nm_device_get_configured_mtu_from_connection(NMDevice *device,
|
2018-06-12 14:51:28 +02:00
|
|
|
GType setting_type,
|
2018-06-12 15:12:53 +02:00
|
|
|
NMDeviceMtuSource *out_source);
|
2018-06-12 14:51:28 +02:00
|
|
|
|
2021-11-09 13:28:54 +01:00
|
|
|
guint32 nm_device_get_configured_mtu_for_wired(NMDevice *self,
|
2019-09-11 10:57:07 +02:00
|
|
|
NMDeviceMtuSource *out_source,
|
2021-11-09 13:28:54 +01:00
|
|
|
gboolean *out_force);
|
2017-01-14 17:04:17 +01:00
|
|
|
|
2021-11-09 13:28:54 +01:00
|
|
|
guint32 nm_device_get_configured_mtu_wired_parent(NMDevice *self,
|
2019-09-11 10:57:07 +02:00
|
|
|
NMDeviceMtuSource *out_source,
|
2021-11-09 13:28:54 +01:00
|
|
|
gboolean *out_force);
|
2019-09-12 17:29:49 +02:00
|
|
|
|
2017-10-12 19:36:09 +02:00
|
|
|
void nm_device_commit_mtu(NMDevice *self);
|
|
|
|
|
|
2017-01-14 17:04:17 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2018-07-10 09:26:42 +02:00
|
|
|
#define NM_DEVICE_DEFINE_LINK_TYPES(...) \
|
|
|
|
|
((NM_NARG(__VA_ARGS__) == 0) ? NULL : ({ \
|
2020-01-28 14:38:41 +01:00
|
|
|
static const NMLinkType _types[NM_NARG(__VA_ARGS__) + 1] = { \
|
2020-01-13 15:32:14 +01:00
|
|
|
__VA_ARGS__ _NM_MACRO_COMMA_IF_ARGS(__VA_ARGS__) NM_LINK_TYPE_NONE, \
|
2018-07-10 09:26:42 +02:00
|
|
|
}; \
|
|
|
|
|
\
|
2020-01-13 15:32:14 +01:00
|
|
|
nm_assert(_types[NM_NARG(__VA_ARGS__)] == NM_LINK_TYPE_NONE); \
|
|
|
|
|
_types; \
|
2018-07-10 09:26:42 +02:00
|
|
|
}))
|
2020-09-28 16:03:33 +02:00
|
|
|
|
2021-11-09 13:28:54 +01:00
|
|
|
gboolean _nm_device_hash_check_invalid_keys(GHashTable *hash,
|
|
|
|
|
const char *setting_name,
|
|
|
|
|
GError **error,
|
2018-11-30 11:37:21 +01:00
|
|
|
const char *const *whitelist);
|
2017-03-03 12:03:26 +01:00
|
|
|
#define nm_device_hash_check_invalid_keys(hash, setting_name, error, ...) \
|
2018-11-30 11:37:21 +01:00
|
|
|
_nm_device_hash_check_invalid_keys(hash, setting_name, error, NM_MAKE_STRV(__VA_ARGS__))
|
2017-03-03 12:03:26 +01:00
|
|
|
|
2017-09-27 09:40:45 +02:00
|
|
|
gboolean nm_device_match_parent(NMDevice *device, const char *parent);
|
2021-11-09 13:28:54 +01:00
|
|
|
gboolean nm_device_match_parent_hwaddr(NMDevice *device,
|
2018-06-27 22:48:50 +02:00
|
|
|
NMConnection *connection,
|
|
|
|
|
gboolean fail_if_no_hwaddr);
|
2017-09-27 09:40:45 +02:00
|
|
|
|
device: implement "auth-request" as async operation nm_manager_device_auth_request()
GObject signals only complicate the code and are less efficient.
Also, NM_DEVICE_AUTH_REQUEST signal really invoked an asynchronous
request. Of course, fundamentally emitting a signal *is* the same as
calling a method. However, implementing this as signal is really not
nice nor best practice. For one, there is a (negligible) overhead emitting
a GObject signal. But what is worse, GObject signals are not as strongly
typed and make it harder to understand what happens.
The signal had the appearance of providing some special decoupling of
NMDevice and NMManager. Of course, in practice, they were not more
decoupled (both forms are the same in nature), but it was harder to
understand how they work together.
Add and call a method nm_manager_device_auth_request() instead. This
has the notion of invoking an asynchronous method. Also, never invoke
the callback synchronously and provide a cancellable. Like every asynchronous
operation, it *must* be cancellable, and callers should make sure to
provide a mechanism to abort.
(cherry picked from commit b50702775f1b7a56ad81fe9be58294a29e805c8f)
2020-04-26 13:59:13 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2021-11-09 13:28:54 +01:00
|
|
|
void nm_device_auth_request(NMDevice *self,
|
|
|
|
|
GDBusMethodInvocation *context,
|
|
|
|
|
NMConnection *connection,
|
|
|
|
|
const char *permission,
|
device: implement "auth-request" as async operation nm_manager_device_auth_request()
GObject signals only complicate the code and are less efficient.
Also, NM_DEVICE_AUTH_REQUEST signal really invoked an asynchronous
request. Of course, fundamentally emitting a signal *is* the same as
calling a method. However, implementing this as signal is really not
nice nor best practice. For one, there is a (negligible) overhead emitting
a GObject signal. But what is worse, GObject signals are not as strongly
typed and make it harder to understand what happens.
The signal had the appearance of providing some special decoupling of
NMDevice and NMManager. Of course, in practice, they were not more
decoupled (both forms are the same in nature), but it was harder to
understand how they work together.
Add and call a method nm_manager_device_auth_request() instead. This
has the notion of invoking an asynchronous method. Also, never invoke
the callback synchronously and provide a cancellable. Like every asynchronous
operation, it *must* be cancellable, and callers should make sure to
provide a mechanism to abort.
(cherry picked from commit b50702775f1b7a56ad81fe9be58294a29e805c8f)
2020-04-26 13:59:13 +02:00
|
|
|
gboolean allow_interaction,
|
2021-11-09 13:28:54 +01:00
|
|
|
GCancellable *cancellable,
|
device: implement "auth-request" as async operation nm_manager_device_auth_request()
GObject signals only complicate the code and are less efficient.
Also, NM_DEVICE_AUTH_REQUEST signal really invoked an asynchronous
request. Of course, fundamentally emitting a signal *is* the same as
calling a method. However, implementing this as signal is really not
nice nor best practice. For one, there is a (negligible) overhead emitting
a GObject signal. But what is worse, GObject signals are not as strongly
typed and make it harder to understand what happens.
The signal had the appearance of providing some special decoupling of
NMDevice and NMManager. Of course, in practice, they were not more
decoupled (both forms are the same in nature), but it was harder to
understand how they work together.
Add and call a method nm_manager_device_auth_request() instead. This
has the notion of invoking an asynchronous method. Also, never invoke
the callback synchronously and provide a cancellable. Like every asynchronous
operation, it *must* be cancellable, and callers should make sure to
provide a mechanism to abort.
(cherry picked from commit b50702775f1b7a56ad81fe9be58294a29e805c8f)
2020-04-26 13:59:13 +02:00
|
|
|
NMManagerDeviceAuthRequestFunc callback,
|
|
|
|
|
gpointer user_data);
|
|
|
|
|
|
2018-02-02 10:55:34 +01:00
|
|
|
#endif /* NM_DEVICE_PRIVATE_H */
|