Commit graph

434 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
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
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
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
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
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
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
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
1f1c7b82fd
platform: mark routes in NMPlatform cache as "external" 2021-07-21 09:54:58 +02:00
Thomas Haller
a6649ef87b
core: preserve "is_external" route flag during _nm_ip_config_add_obj() 2021-07-21 09:54:58 +02:00
Thomas Haller
fc2f758af5
ifcfg: also ANSIC escape DEL character in ifcfg writer
This is like using nm_ascii_is_ctrl_or_del() instead of
nm_ascii_is_ctrl() in the previous version of the patch.
We thus now always will switch to ANSIC escaping if we see
a ASCII DEL character. That is probable desirable, but either
way should not make a big difference (because we can parse
the DEL character both in regular quotation and in ANSIC quotation).

The patch is however larger, to also take the opportunity to only check
for nm_ascii_is_regular() in the "fast path". The behavior is the same
as changing nm_ascii_is_ctrl() to nm_ascii_is_ctrl_or_del().
2021-07-19 09:03:52 +02:00
Thomas Haller
6841bb1b26
ifcfg: use nm_ascii_is_ctrl() helper in shvar.c
No change in behavior.
2021-07-19 08:59:34 +02:00
Thomas Haller
b49a168935
firewall/nftables: only configure "ip" address familiar for masquerading
nftables' "inet" family is both for IPv4 and IPv6, while we only want
to configure rules for IPv4.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/760

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/928
2021-07-15 15:14:58 +02:00
Thomas Haller
41be0c8fde
ifcfg: log messages about invalid an unrecognized lines in ifcfg files
Problems of this patch:

- the code does not differentiate between an ifcfg file and an alias
  file. Different shell variables are honored however depending on the
  context and the warning should reflect that.

- there are no warnings about /etc/sysconfig/network. The main problem
  is that we read this file for every ifcfg file we parse, and we would
  need to ratelimit the number of warnings. Another problem is that
  the file likely contains keys that we intentionally don't support.
  We would need a new way to omit warnings about those lines.

Example:

    TYPE=Ethernet
    PROXY_METHOD=none
    BROWSER_ONLY=no
    BOOTPROTO=dhcp
    DEFROUTE=yes
    STABLE_ID=$'xxx\xF4yy'
    IPV4_FAILURE_FATAL=no
    IPV6INIT=yes
    XX=foo
    XX1=foo'
    '
    IPV6_AUTOCONF=yes xxxx
    IPV6_DEFROUTE=yesx
    IPV6_DEFROUTE=yes
    IPV6_FAILURE_FATAL=no
    IPV6_ADDR_GEN_MODE=stable-privacy
    NAME=xxx
    UUID=9d8ed7ff-3cdd-4336-9e26-3e978dc87102
    ONBOOT=no

  <warn>  [...] ifcfg-rh: ifcfg,/etc/sysconfig/network-scripts/ifcfg-xxx:6: key STABLE_ID does not contain valid UTF-8 and is treated as ""
  <debug> [...] ifcfg-rh: ifcfg,/etc/sysconfig/network-scripts/ifcfg-xxx:9: key XX is unknown and ignored
  <warn>  [...] ifcfg-rh: ifcfg,/etc/sysconfig/network-scripts/ifcfg-xxx:10: key XX1 is badly quoted and is treated as ""
  <warn>  [...] ifcfg-rh: ifcfg,/etc/sysconfig/network-scripts/ifcfg-xxx:11: invalid line ignored
  <warn>  [...] ifcfg-rh: ifcfg,/etc/sysconfig/network-scripts/ifcfg-xxx:12: key IPV6_AUTOCONF is badly quoted and is treated as ""
  <warn>  [...] ifcfg-rh: ifcfg,/etc/sysconfig/network-scripts/ifcfg-xxx:13: key IPV6_DEFROUTE is duplicated and the early occurrence ignored

https://bugzilla.redhat.com/show_bug.cgi?id=1959656
2021-07-15 09:06:34 +02:00
Thomas Haller
7c9b0d68e4
ifcfg: reject non-UTF-8 at the lowest layer when reading shell variable
ifcfg files are a text format. It makes no sense to ever accept
non-UTF-8 blobs. If binary data is to be encoded in a ifcfg file, then
the upper layers must escape/encode it in valid UTF-8.

Let svUnescape() silently reject any binary "text". This will lead to treat such
strings as empty strings "". This is no different than some invalid
quoting: the string is not parsable as (UTF-8) text and will be treated
as such.

This is potentially a breaking change. But the benefit is that all the
upper layers can rely on only getting valid UTF-8 strings. For example,
a non-UTF-8 string cannot be converted to a "s" GVariant (of course not,
it's not a string). But our nm_connection_verify() commonly does not
check that all strings are in fact valid UTF-8. So a user who edits
an ifcfg file could inject non-valid strings, and cause assertion
failures later on.

It's actually easy to provoke a crash (or at least an assertion failure)
by writing an ifcfg file with certain keys as binary.

Note that you can either reproduce the binary files by writing non-UTF-8
"strings" dirctly, or by using \x, \u, or \U escape sequences.

Note that also '\0' gets rejected and renders the string as invalid
(i.e. as empty). Before the returned string would have been simply
truncated and the rest ignored. Such NUL bytes can only be produced
using the escape sequences, because the ifcfg reader already (silently)
truncates the file on the first binary NUL.
2021-07-15 08:22:24 +02:00
Thomas Haller
5877928b46
ifcfg: ANSIC escape non-UTF-8 "strings" and preserve valid unicode
Note that previously the check

    if (s[slen] < ' ') {
        ...
        return (*to_free = _escape_ansic(s));
    }

would be TRUE for all UTF-8 characters if `char` is signed. That means,
depending on the compiler, we would always ANSI escape all UTF-8
characters. With this patch, we no longer do that!
Instead, valid unicode gets now preserved (albeit quoted).

On the other hand, always ANSIC escape invalid UTF-8 (regardless of the
compiler). ifcfg-rh is really a text based format. If a caller wants to store
binary data, they need to escape it first, for example with some own escaping
scheme, base64 or bin2hexstr.

A caller passing a non-text to svEscape() is likely a bug already and
they should have not done that.

Still, let svEscape() handle that by using ANSIC escaping. That works
as far as escaping is concerned, but likely later will be a problem
during unescaping, when the reader expects a valid UTF-8 string.
svEscape() is in no place to signal a sensible error, so proceed the
best it can, by escaping.
2021-07-15 08:19:05 +02:00
Thomas Haller
85f53f43e9
device/dhcp: avoid crash by not starting DHCPv6 client without ifindex
https://bugzilla.redhat.com/show_bug.cgi?id=1973199
2021-07-14 18:19:46 +02:00
Thomas Haller
63a248ecb2
device: avoid crash setting VPN config during unrealize
During nm_device_unrealize(), we first clear the device's ifindex. Then
we call _set_state_full(NM_DEVICE_STATE_UNMANAGED).

NMVpnConnection are subclasses of NMActiveConnection, it is that way
connected to NM_DEVICE_STATE_CHANGED signal. And this leads to a call
to _set_vpn_state(), which then calls nm_device_replace_vpn6_config()
to unregister the config. Thereby an assertion fails because the
ifindex no longer matches.

Fix that by relaxing the assertion. Also, don't apply the IP
configuration in unexpected device states.

https://bugzilla.redhat.com/show_bug.cgi?id=1912423

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/927
2021-07-13 17:23:55 +02:00
Thomas Haller
fa786e1f46
core/wwan: avoid assertion failure in modem_ip{4,6}_config_result()
NMDeviceModem has priv->modem set from construction to dispose, and
the NM_MODEM_IP4_CONFIG_RESULT/NM_MODEM_IP6_CONFIG_RESULT signals
connected all the time.

On the other hand, NMModem may hook up to NMPPPManager's
NM_PPP_MANAGER_SIGNAL_IP{4,6}_CONFIG signals, which emit the
config-results signals. And PPP manager emits the config signals
from impl_ppp_manager_set_ip{4,6}_config().

That means, at any moment can be a D-Bus calls, which leads to emitting
those signals and calling into modem_ip4_config_result() and
modem_ip6_config_result().

At least, it's not clear from review what would prevent that from
happening. If you cannot easily verify that certain conditions are
satisfied, then this is not the place to assert, but to handle the case
as something that can happen regularly.

Handle signals in the unexpected state by ignoring them.

https://bugzilla.redhat.com/show_bug.cgi?id=1916192

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/926
2021-07-13 17:14:02 +02:00
Beniamino Galvani
62869621bd device: start DHCPv6 when a prefix delegation is needed
If a prefix delegation is needed, currently NM restarts DHCPv6 on the
device with default route, but only if DHCPv6 was already running.

Allow the device to start DHCPv6 for a PD even if it was running
without DHCPv6.

See also: https://github.com/coreos/fedora-coreos-tracker/issues/888
2021-07-13 09:43:04 +02:00
Beniamino Galvani
1377f160ed device: send ARP announcements when there is carrier
Previously we sent announcements immediately for non-controllers, or
after the first port was attached for controllers.

This has two problems:

 - announcements can be sent when there is no carrier and they would
   be lost;

 - if a controller has a port, the port could be itself a controller;
   in that case we start sending ARPs with the fake address of the
   port. Later, when a leaf port is added to the second-level
   controller, the correct port MAC will be propagated by kernel up to
   both controllers.

To solve both problems, send ARP announcements only when the interface
has carrier. This also solves the second issue because controllers
created by NM have carrier only when there is a port with carrier.

Fixes: de1022285a ('device: do ARP announcements only after masters have a slave')

https://bugzilla.redhat.com/show_bug.cgi?id=1956793
2021-07-13 09:27:20 +02:00
Beniamino Galvani
314024ea96 acd: log the MAC when announcing an IP 2021-07-13 09:27:20 +02:00
Thomas Haller
4e109bacab
clang-format: use "IndentPPDirectives:None" instead of "BeforeHash"
Subjectively, I think this looks better.
2021-07-09 08:49:06 +02:00
Thomas Haller
e5484476f6
device: don't add-and-activate dummy profiles with autoconf enabled
Let the default normalization from nm_connection_normalize() choose
'ipv6.method'. It will now choose "disabled" for dummy profiles, which
is just what we need.

In particular, we don't want to enable autoconf for dummy devices --
unless the profile which the user provides already has it enabled (in
which case nm_connection_normalize() doesn't change it).
2021-07-08 17:20:15 +02:00
Thomas Haller
a32d04f0bb
core: fix nmcli device connect dummy0 to add-and-activate dummy profile
$ ip link add dd type dummy

   $ nmcli device
   DEVICE             TYPE      STATE                   CONNECTION
   ...
   dd                 dummy     unmanaged               --

   $ nmcli device connect dd
   Error: Failed to add/activate new connection: A 'dummy' setting is required.

There are two problems here. The first is that we don't pass
the interface name to nm_utils_complete_generic(), but dummy
devices require "connection.interface-name" set. As a consequence,
nm_utils_complete_generic() fails to normalize the connection
and there is no [dummy] setting. Which then results in a failure
with complete_connection().

The important part of the fix is to set the interface name. Once
we do that, nm_utils_complete_generic() should be able to add
the [dummy] setting and the second part is not strictly necessary.
Still, the job of complete_connection() is not to verify the
profile but to create it with best effort. If a [dummy] setting
is still missing, we should just add it. The caller will then
again try to normalize/verify the connection, and that might then
fail -- but this time not with the wrong error message about
missing 'dummy' setting.

https://bugzilla.redhat.com/show_bug.cgi?id=1763054
2021-07-08 17:20:15 +02:00
Thomas Haller
f9b43ed7d4
core: add parameters options to nm_utils_complete_generic() 2021-07-08 17:20:15 +02:00
Thomas Haller
eb634c6077
core: don't override user provided "connection.interface-name" in nm_utils_complete_generic()
nm_utils_complete_generic() is supposed to complete information which the user
didn't provide. If the profile already has an interface-name, keep it.
2021-07-08 17:20:15 +02:00
Thomas Haller
0c4a65929c
glib-aux: use nm_utils_gettid() instead of gettid()
I missed that we already have a gettid() wrapper. Drop the duplicated
again and use nm_utils_gettid().

Fixes: e874c5bf6b ('random: Provide missing gettid() declaration')
2021-07-08 08:31:47 +02:00
Thomas Haller
c6be3404f8
platform/tests: add assertions to nmtstp_link_bridge_normalize_jiffies_time()
This is supposed to workaround a coverity warning.
2021-07-06 09:04:37 +02:00
Björn Lindqvist
44481bd7c7
core: fail IPv6 early if disabled in kernel
Adds the following info message in case ipv6 is disabled:

    <info>  device (enp0s18f2u3): The kernel does not support IPv6.

[thaller@redhat.com: modified original patch]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/401
2021-07-05 16:27:48 +02:00
Beniamino Galvani
35cccc41cb device: use the 'required-timeout' property from IP setting
Change the logic in check_ip_state() to delay the connection ACTIVATED
state if an address family is pending and its required-timeout has not
expired.
2021-07-05 15:15:45 +02:00
Beniamino Galvani
cb5960cef7 all: add a new ipv{4,6}.required-timeout property
Add a new property to specify the minimum time interval in
milliseconds for which dynamic IP configuration should be tried before
the connection succeeds.

This property is useful for example if both IPv4 and IPv6 are enabled
and are allowed to fail. Normally the connection succeeds as soon as
one of the two address families completes; by setting a required
timeout for e.g. IPv4, one can ensure that even if IP6 succeeds
earlier than IPv4, NetworkManager waits some time for IPv4 before the
connection becomes active.
2021-07-05 15:15:44 +02:00
Thomas Haller
09fb7877a9
build: fix linking libnm-log-null into different test programs
We require these, otherwise we can get a linker error about
_nm_utils_monotonic_timestamp_initialized symbol being undefined.
2021-07-05 14:51:27 +02:00
acabral
e5dca403dc bond: support the peer_notif_delay bond option
Merge Request NetworkManager/NetworkManager!913
2021-07-01 15:20:22 -03:00
Thomas Haller
34c663ca1a
settings: cleanup left over temporary files for timestamps/seen-bssids 2021-07-01 11:21:00 +02:00
Thomas Haller
2e720a1dc8
settings: prune old entries from keyfile databases
We have two GKeyfile files (timestamps and seen-bssids).

When a profile was deleted while NetworkManager was running, then
entries were removed from these keyfiles. But if a profile disappeared
while NetworkManger was stopped, then those UUIDs piled up.
This also happens if you have temporary connections in /run and reboot.

We need a way to garbage collect entries that are no longer relevant.

As the keyfile databases only get loaded once from disk, we will prune
all UUIDs for which we have no more connection loaded, on the first time
we write out the files again.

Note what this means: if you "temporarily" remove a connection profile
(without NetworkManager noticing) and restore it later, then the additional
information might have been pruned. There is no way how NetworkManager
could know that this UUID is coming back. The alternative is what we did
before: pile them up indefinitely. That seems more problematic.
2021-07-01 11:20:34 +02:00
Thomas Haller
8278719840
settings: limit number of seen-bssids and preserve order
Previously, there was no limit how many seen-bssids are tracked.
That seems problematic, also because there is no API how to get
rid of an excessive list of entries.

We should limit the number of entries. Add an (arbitrary) limit
of 30.

But this means that we drop the surplus of entries, and for that it
seems important to keep the newest, most recently seen entries.
Previously, entries were merely sorted ASCIIbetically. Now, honor
their order (with most recently seen first).

Also, normalize the BSSIDs. From internal code, we should only get
normalize strings, but when we load them from disk, they might be bogus.
As we might cut of the list, we don't want that invalid entries
cut of valid ones. And of course, invalid entries make no sense at
all.
2021-07-01 11:17:06 +02:00
Thomas Haller
15a0271781
settings: don't populate seen-bssids list from connection profile
ifcfg-rh plugin never stored the seen bssid list to file, and
keyfile no longer does, and it's no longer parsed from GVariant.

So there is actually no way how anything could be set here.

The seen-bssids should only be populate from
"/var/lib/NetworkManager/seen-bssids". Nowhere else.
2021-07-01 11:04:22 +02:00
Thomas Haller
6c5070da55
core: set _nm_utils_is_manager_process as first thing in daemon 2021-07-01 11:04:22 +02:00
Thomas Haller
37b72e8984
hostname: cleanup file monitors in NMHostnameManager 2021-06-30 08:00:35 +02:00
Thomas Haller
05aa751957
core,glib-aux: move nm_hostname_manager_validate_hostname() to shared-utils
This function is badly named, because it has no NMHostnameManager self
argument. It's just a simple function that entirely operates on a string
argument.

Move it away from "nm-hostname-manager.h" to "libnm-glib-aux/nm-shared-utils.h".

Hostname handling is complicated enough. Simple string validation
functions should not obscure the view on the complicated parts.
2021-06-28 14:32:05 +02:00
Thomas Haller
dbe4803d84
hostname: use nm_utils_user_data_pack() instead of SetHostnameInfo struct 2021-06-28 14:32:05 +02:00
Thomas Haller
429816080e
hostname: simplify _set_hostname() code
- drop nm_hostname_manager_read_hostname() from header file.
  It's only used internally.

- inline some code and drop helper functions.
2021-06-28 14:32:05 +02:00