Commit graph

28933 commits

Author SHA1 Message Date
Beniamino Galvani
bace14fe1f core: introduce device 'allowed-connections' property
Configuration can have [device*] and [connection*] settings and both
can include a 'match-device=' key, which is a list of device-specs.

Introduce a new 'allowed-connections' key for [device*] sections,
which specifies a list of connection-specs to indicate which
connections can be activated on the device.

With this, it becomes possible to have a device configuration like:

  [device-enp1s0]
  match-device=interface-name:enp1s0
  allowed-connections=except:origin:nm-initrd-generator

so that NM in the real root ignores connections created by the
nm-initrd-generator, and starts activating a persistent
connection. This requires also setting 'keep-configuration=no' to not
generate an assumed connection.
2021-07-27 17:43:45 +02:00
Beniamino Galvani
604c611cd0 core: add nm_utils_connection_match_spec_list()
Add function nm_utils_connection_match_spec_list() to check whether a
connection matches a spec list. Also document the supported syntax in
the man page.
2021-07-27 17:43:45 +02:00
Beniamino Galvani
86f22ce8ba initrd: add a 'origin' user tag to connections
Introduce a user tag key to indicate where the connection comes
from. It would also be possible to have this as a standard property
(as 'connection.origin'), but since this information can be considered
'meta-data' I think the user setting is more appropriate.
2021-07-27 16:36:48 +02:00
Beniamino Galvani
df2fe15714 core: add 'keep-configuration' device configuration option
Add a new 'keep-configuration' device option, set to 'yes' by
default. When set to 'no', on startup NetworkManager ignores that the
interface is pre-configured and doesn't try to keep its
configuration. Instead, it activates one of the persistent
connections.
2021-07-27 16:36:48 +02:00
Beniamino Galvani
b1644fa826 manager: exit early in get_existing_connection()
Later the function will become more complex. Add a check to exit early
if the device can't assume connections.
2021-07-27 16:36:47 +02:00
Beniamino Galvani
bb37e30867 core: add comments about assuming connections 2021-07-27 16:36:47 +02:00
Beniamino Galvani
eaacfd249c merge: branch 'bg/dhcp-filename-rh1979387'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/929
2021-07-27 09:42:29 +02:00
Beniamino Galvani
9a09c02012 core: persist the bootfile from DHCP
The bootfile location is needed by the anaconda dracut module; write
it to the device state file.
2021-07-27 09:36:33 +02:00
Beniamino Galvani
3c79944e15 dhcp: nettools: parse the filename and the bootfile-name option 2021-07-27 09:36:33 +02:00
Beniamino Galvani
6a1349c5fb n-dhcp4: add an accessor for the file name in the lease
The name of the boot file can be either in option 67 or in a field of
the DHCP header. Add an accessor for the one from the DHCP header.
2021-07-27 09:36:33 +02:00
Beniamino Galvani
be6997d127 n-dhcp4: fix n_dhcp4_client_lease_get_server_identifier()
N_DHCP4_E_MALFORMED is an internal error code, replace it with
N_DHCP4_E_INTERNAL. Also, remove extra spaces.
2021-07-27 09:36:32 +02:00
Beniamino Galvani
0994a444e5 dhcp: add internal option for the boot file name
Add an internal option that specifies the boot file name from the DHCP
header. The option name 'filename' is the same as exposed by dhclient.
2021-07-27 09:36:32 +02:00
Beniamino Galvani
0c10e4f8b6 dhcp: escape control characters in DHCP options
Control characters (DEL (=127) or those below 32) could cause undesired
effects when a client displays or parses DHCP options. Escape them.
2021-07-27 09:35:58 +02:00
Thomas Haller
9163a5db6b
libnm: minor simplification of nm_setting_user_get_data() 2021-07-26 19:14:14 +02:00
Thomas Haller
ee5030c7bd
nm-sudo: fix printf format string in _handle_ping()
src/nm-sudo/nm-sudo.c: In function '_handle_ping':
src/nm-sudo/nm-sudo.c:92:79: error: format '%ld' expects argument of type 'long int', but argument 5 has type 'gint64' {aka 'long long int'} [-Werror=format=]
   92 |     msg = g_strdup_printf("pid=%lu, unique-name=%s, nm-name-owner=%s, since=%ld.%03d%s, pong=%s",
      |                                                                             ~~^
      |                                                                               |
      |                                                                               long int
      |                                                                             %lld
......
   96 |                           running_msec / 1000,
      |                           ~~~~~~~~~~~~~~~~~~~
      |                                        |
      |                                        gint64 {aka long long int}

Fixes: f137b32d31 ('sudo: introduce nm-sudo D-Bus service')
2021-07-26 18:13:26 +02:00
Thomas Haller
0d6adfe8e9
nm-sudo: comment environment variables in "nm-sudo.service.in" 2021-07-26 17:39:48 +02:00
Thomas Haller
438fd3aa9c
sudo: merge branch 'th/nm-sudo'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/938
2021-07-26 17:16:39 +02:00
Thomas Haller
de5dddccbe
core: get file descriptor to ovsdb unix socket from nm-sudo
To talk to ovsdb, we use the unix socket at
/var/run/openvswitch/db.sock. But that socket is owned by another user
and NetworkManager would need dac_override capability to open it.

We want to drop dac_override, but we still need to talk to ovsdb. Add a
GetFD() method to nm-sudo.

We still first try to open the socket directly. Maybe it just works.

Note that SELinux may block passing file descriptors from nm-sudo. If it
doesn't work for you, test with SELinux permissive mode and wait for an
SELinux update.
2021-07-26 15:31:46 +02:00
Thomas Haller
f137b32d31
sudo: introduce nm-sudo D-Bus service
NetworkManager runs as root and has lots of capabilities.
We want to reduce the attach surface by dropping capabilities,
but there is a genuine need to do certain things.

For example, we currently require dac_override capability, to open
the unix socket of ovsdb. Most users wouldn't use OVS, so we should
find a way to not require that dac_override capability. The solution
is to have a separate, D-Bus activate service (nm-sudo), which
has the capability to open and provide the file descriptor.

For authentication, we only rely on D-Bus. We watch the name owner
of NetworkManager, and only accept requests from that service. We trust
D-Bus to get it right a request from that name owner is really coming
from NetworkManager. If we couldn't trust that, how could PolicyKit
or any authentication via D-Bus work? For testing, the user can set
NM_SUDO_NO_AUTH_FOR_TESTING=1.

https://bugzilla.redhat.com/show_bug.cgi?id=1921826
2021-07-26 15:31:46 +02:00
Thomas Haller
684f2acffe
build: add way to keep unused symbols when linking NetworkManager
NetworkManager (and NetworkManager-all-sym) must not only contain symbols
that are used by itself. Also the device and settings plugin are dlopen'd
by NetworkManager and use symobls form the binary.

That means, if a symbols is only used by a plugin, then we must make sure
that the linker keeps it in the binary. Add a mechanism for that.
2021-07-26 15:30:10 +02:00
Thomas Haller
641f4473b7
build: fix calling test "check-local-devices-ovs" to check OVS device plugin 2021-07-26 15:30:10 +02:00
Thomas Haller
f57679dd93
all: use nm_g_idle_add() instead of g_idle_add()
g_idle_add() is discouraged, because we shouldn't use guint source
IDs.
2021-07-26 15:30:09 +02:00
Thomas Haller
a99ac7ccd8
glib-aux: add nm_g_idle_add()
g_idle_add() is discouraged, and the checkpatch.pl script warns
about it.

Sometimes there is a legitimate use of it, when you want to always
schedule an idle action (without intent to cancel or track it). That
makes more sense for g_idle_add() than it does for g_timeout_add(),
because a timeout really should be tracked and cancelled if necessary.

Add a wrapper to rename the legitimate uses. This way, we can avoid the
checkpatch.pl warnings, and can grep for the remaining illegitimate uses.
2021-07-26 15:30:04 +02:00
Beniamino Galvani
9060c14ccf initrd: support infiniband pkeys
Introduce a new "ib.pkey=<parent>.<pkey>" command line argument to
create a Infiniband partition.

The new connection has IPv4 and IPv6 enabled by default. Unlike for
VLANs, the generator doesn't create a connection for the parent
Infiniband interface.

See also: https://github.com/dracutdevs/dracut/pull/1538

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/884
2021-07-26 14:56:18 +02:00
xiangnian
109d561bed wifi: change auth-alg form "open" to NULL when authentication is wpa3
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/931
2021-07-26 10:58:09 +02:00
Thomas Haller
8887358383
libnm: merge branch 'th/setting-more-direct'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/933
2021-07-23 19:53:16 +02:00
Thomas Haller
c1157d73ad
libnm: add from_dbus_fcn for direct NMSettingIPConfig.gateway property 2021-07-23 17:02:04 +02:00
Thomas Haller
e6562493ef
libnm: add from_dbus_fcn for direct properties
There is a quest to move away from the GObject/GValue based setters.
Add _nm_setting_property_from_dbus_fcn_direct(), which can parse
the GVariant and use the direct_type to set the property.

Note that for backward compatibility, we still need
_nm_property_variant_to_gvalue() to convert alternative GVariant
types to the destination value. This means, as before, on the D-Bus
API a property of a certain type can be represented as various D-Bus
types.
2021-07-23 17:02:04 +02:00
Thomas Haller
ed8e098c30
libnm: add from_dbus_fcn for direct mac-address properties 2021-07-23 17:02:04 +02:00
Thomas Haller
525b7e2a58
libnm: add _nm_property_variant_to_gvalue() helper 2021-07-23 17:02:03 +02:00
Thomas Haller
6d07afaa8d
libnm: implement special setter for direct string property for ip address
This is a normalization employed by NMSettingIPConfig.gateway.

Also rework NMSettingIPConfig.set_property() to no longer assert against
valid input. We want to pass there untrusted strings from D-Bus,
asserting is a horrible idea. Instead, either normalize the string or
keep the invalid text that will be rejected by verify().
2021-07-23 17:02:03 +02:00
Thomas Haller
0c7286a855
libnm: implement special setter for direct string property for mac address 2021-07-23 17:02:03 +02:00
Thomas Haller
96657b1556
libnm: implement special setter for direct string property via g_ascii_strdown() 2021-07-23 17:02:03 +02:00
Thomas Haller
d5f08f4a1e
libnm: use direct properties for NMSettingTun 2021-07-23 17:02:03 +02:00
Thomas Haller
de13b9eec1
libnm: use direct properties for NMSettingConnection 2021-07-23 17:02:02 +02:00
Thomas Haller
932ba13592
libnm: use direct properties for NMSettingOvsPort 2021-07-23 17:02:02 +02:00
Thomas Haller
6cc3b00060
libnm: use direct properties for NMSettingWpan 2021-07-23 17:02:02 +02:00
Thomas Haller
b688fc3da4
libnm: use direct properties for NMSettingBluetooth 2021-07-23 17:02:02 +02:00
Thomas Haller
e399fda04c
libnm: add nm_sett_info_propert_type_direct_int32 property type 2021-07-23 17:02:02 +02:00
Thomas Haller
82e9f43289
libnm: add nm_sett_info_propert_type_direct_mac_address
A MAC address is a relatively common "type". The GObject property is of type string,
but the D-Bus type is a bytestring ("ay"). We will need a special NMSettInfoPropertType.

Note that like most implementations, the from-dbus implementation still is based
on GObject setters. This will change in the future.

Also note that the previous compare function was
_nm_setting_property_compare_fcn_default(). That is, it used to convert
the property to GVariant and compare those. The conversion to GVariant
in that case normalizes the string (e.g. it is case insensitive). Also,
only properties could be compared which were also convertible to D-Bus
(which is probably fine, because there is no guarantee the profiles that
don't verify can be compared).

The code now uses the direct comparison of the strings. That mostly
preserves the case-insensitivity of the previous comparison, because
the property setters for mac addresses all use
_nm_utils_hwaddr_canonical_or_invalid() to normalize the strings.
This is subtle, but still correct. Note that this will improve later,
by ensuring that the property setters for mac addresses automatically
perform the right normalization.
2021-07-23 17:02:01 +02:00
Thomas Haller
dc2e4d04f1
libnm: normalize mac-address properties in GObject property setter
The aim is that properties have a "type", that is, that similar
properties share a common behavior and appearance.

Most properties of type "mac-address" normalize the string in the
GObject property setter. Three don't. Let them also do that.

This is also relevant, because the compare function for mac-addresses
(_nm_setting_property_compare_fcn_default()) converts the properties
first to a "ay" GVariant. Which means the comparison is case
insensitive. Normalizing the values in the setter avoids that
inconsistency.
2021-07-23 17:02:01 +02:00
Thomas Haller
abf5d01583
glib-aux: add NM_G_PARAM_SPEC_GET_DEFAULT_INT() helper 2021-07-23 17:02:01 +02:00
Thomas Haller
faf315148b
cloud-setup,glib-aux: merge branch 'th/cloud-setup-logging'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/937
2021-07-23 16:49:20 +02:00
Thomas Haller
443f348776
glib-aux: use nm_vsprintf_buf_or_alloc() to stack allocate logging message in _nm_log_simple_printf()
Also take the timestamp first.
2021-07-23 16:43:37 +02:00
Thomas Haller
6c030ed923
glib-aux,cloud-setup: add _nm_logging_enabled*() helper API
Will also be used outside of nm-cloud-setup.
2021-07-23 16:43:37 +02:00
Thomas Haller
32b2d15021
cloud-setup: link with libnm-log-null 2021-07-23 16:43:36 +02:00
Thomas Haller
391d714b19
cloud-setup: use _nm_log_simple_printf() for plain logging 2021-07-23 16:43:36 +02:00
Thomas Haller
764ca7462f
glib-aux: add _nm_log_simple_printf() helper 2021-07-23 16:43:36 +02:00
Thomas Haller
22d6be54f3
initrd: fix handling "ip=single-dhcp:..." in reader_parse_ip()
Fixes: bf7530ccc1 ('initrd: honor "ip=single-dhcp" option as alias for "dhcp"')
2021-07-23 11:36:41 +02:00
Thomas Haller
bf7530ccc1
initrd: honor "ip=single-dhcp" option as alias for "dhcp"
This mode was added to network-legacy in [1]. NetworkManager anyway always
does DHCP in parallel, so this is basically an alias for "dhcp".
Note that network-legacy's "single-dhcp" will stop waiting for DHCP
once the first device gets an address. NetworkManager currently cannot
do that. While it runs DHCP in parallel, all devices need to settle
and there is no concept where completing one device makes the overall
"startup complete" process finish early. That could however be added.

Anyway, while not being exactly the same, it's still more useful to do
something similar instead of not working at all.

See-also: https://github.com/dracutdevs/dracut/pull/853
See-also: https://github.com/dracutdevs/dracut/pull/961
See-also: https://github.com/dracutdevs/dracut/pull/1048

[1] 4026cd3b01
2021-07-23 11:06:06 +02:00