Commit graph

15932 commits

Author SHA1 Message Date
Thomas Haller
61d74b0c15 ifcfg-rh: rework error handling in parse_infiniband_p_key() 2022-09-07 10:47:35 -04:00
Wen Liang
4c32dd9d25 ipoib: skip validating the DEVICE when reading the ifcfg file
For the ipoib connection, it is still considered as valid if the
profile does not set the device name. Also, the ifcfg reader should not
duplicate the checks that `nm_connection_verify()` performs (especially
not wrongly). Therefore, NM should skip validating the DEVICE when
reading the ifcfg file for the ipoib connection.

https://bugzilla.redhat.com/show_bug.cgi?id=2122703
2022-09-07 10:47:35 -04:00
Wen Liang
a4fe16a426 infiniband: avoid normalizing the p-key when reading from ifcfg
When writing the p-key setting to the ifcfg file and reading the
setting back, the value has to be consistent. This is not limited to
p-key only, any setting value during the ifcfg write and read also has
to be consistent.

This was probably added in commit cb5606cf1c ('ifcfg-rh:
add support for Infiniband partitions') as this is also what
ifup-ib does ([1]). For NetworkManager profiles however, the
p-key is also valid without the high bit set, so the ifcfg-rh
reader must honor that.

[1] 0c9fb6ca7b/rdma.ifup-ib (L75)
2022-09-07 10:47:35 -04:00
Wen Liang
72144946c9
Revert "platform: add the a_no_auto_noprefixroute flag"
This flag won't be used. Instead we will pass a flag to
nm_platform_ip_route_sync() to disable addition of the prefix route
flag.

This reverts commit bd84ae4dc5.
2022-09-07 15:51:56 +02:00
Lubomir Rintel
0e0ac364a1 manager: don't bring up master connections on devices that are not disconnected
Otherwise we're likely interfering with an in-progress activation.
Consider the following connections, first two being active:

  id=bond0a type=bond interface-name=bond0, (Active)
    id=dummy0a type=dummy interface-name=dummy0 master=bond0a, (Active)
  id=bond0b type=bond interface-name=bond0
    id=dummy0b type=dummy interface-name=dummy0 master=bond0b

Note there's two hierarchies with bond0 bond having a dummy0 port,
first one (bond0a, dummy0a) being active.

Suppose the users wants to bring the other one up (bond0b, dummy0b) and
does a "nmcli c up bond0b". This is what happens:

  1.) bond0b starts activation due to user request
  2.) bond0a starts deactivation due to new activation
  3.) dummy0 loses its master, begins deactivation
  4.) dummy0 finishes deactivation
  5.) both dummy0 being deactivated and bond0b check for slaves enqueues
      auto-activation check for dummy0
  6.) auto-activation picks dummy0a for dummy0
  7.) dummy0a begins activation
  8.) dummy0a looks for master connection, picks bond0a
  9.) bond0a starts activating on bond0, kicks bond0b away
  10.) bond0a and dummy0a end up finishing activation
  11.) Everybody unhappy :(

NM's auto-activation logic is only takes autoconnect priority into
account when figuring out a connection to activate and can't be expected
to bring up most sensible combination of connection when there's
multiple ones for the same devices with complex dependencies.

Nevertheless, it shouldn't ever undo the activations if the user is
bringing up the connections manually.

This patch prevents bringing up of master devices that are not
DISCONNECTED and therefore shouldn't be up for grabs. This was
previously done for hardware devices only whereas I believe it should be
the case for *all* realized devices.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager-ci/-/merge_requests/1172
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1364
2022-09-07 14:28:26 +02:00
Lubomir Rintel
5c3b553ea3 merge: branch 'lr/docs-deprec-props'
The documentation of property deprecation was not great in nm-settings-nmcli(5).

This aims to improve that, essentially changing:

  number
      Legacy setting that used to help establishing PPP data sessions for GSM-based modems. Deprecated: 1

Into

  number
      Legacy setting that used to help establishing PPP data sessions for GSM-based modems.

      This property is deprecated since version 1.16. User-provided values for this setting are no longer used.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1367
2022-09-07 14:15:39 +02:00
Lubomir Rintel
d3ffd2f90a setting-bridge,wireless: improve some deprecation warnings
The documentation paragraph contained deprecation information redundant
with the deprecation tag. It looks ugly when rendered into a manual
page.
2022-09-07 11:06:38 +02:00
Lubomir Rintel
09c402d903 setting-8021x: add deprecation tags
Add deprecation tags to "subject-match" and "phase2-subject-match"
properties and adjust the documentation slightly.

They've been deprecated since commit 64b76ba906 ('libnm-core: add
domain-suffix-match properties to NMSetting8021x').
2022-09-07 11:04:17 +02:00
Lubomir Rintel
4d42b81d2a generate-docs-nm-settings-docs-gir: move deprecation info to a separate tag
Previously, the deprecation data was included in <description*>, in form
of an integer. E.g.:

  /**
   * NMSettingLala:hello:
   *
   * Does this and that.
   *
   * Deprecated: 1.12: Be sad instead.
   **/

Results in:

  <property name="hello">
    <description>Does this and that. Deprecated: 1</description>
  </property>

Let's make it do this instead:

  <property name="hello">
    <description>Does this and that.</description>
    <deprecated since="1.12">Be sad instead.</description>
  </property>
2022-09-07 11:01:40 +02:00
Fernando Fernandez Mancera
652b2a3885
l3cfg: re-use plen variable in NMIPRoute creation 2022-09-06 17:12:15 +02:00
Beniamino Galvani
e4aefbc556 dhcp: implement decline on IPv6 DAD failure with dhclient
The dhclient plugin already supports sending a decline when IPv4 ACD
fails. Also implement support for IPv6 DAD.

See-also: 156d84217c ("dhcp/dhclient: implement accept/decline (ACD) for dhclient plugin")
2022-09-05 09:40:08 +02:00
Beniamino Galvani
a7eb77260a dhcp: decline IPv6 lease if all adresses fail DAD
Currently we accept the DHCPv6 just after addresses are configured on
kernel, without waiting DAD result. Instead, wait that DAD completes
and decline the lease if all addresses are detected as duplicate.

Note that when an address has non-infinite lifetime and fails DAD,
kernel removes it automatically. With iproute2 we see something like:

602: testX6    inet6 2620:🔢5678/128 scope global tentative dynamic noprefixroute
       valid_lft 7500sec preferred_lft 7200sec
Deleted 602: testX6    inet6 2620:🔢5678/128 scope global dadfailed tentative dynamic noprefixroute
       valid_lft 7500sec preferred_lft 7200sec

Since the address gets removed from the platform cache, at the moment
we don't have a way to check the flags of the removal
message. Therefore, we assume that any address that goes away in
tentative state was detected as duplicate.

https://bugzilla.redhat.com/show_bug.cgi?id=2096386
2022-09-05 09:40:08 +02:00
Beniamino Galvani
9eb8cbca76 device: don't emit recheck-assume if there is a queued activation request
The @dracut_NM_vlan_over_team_no_boot sometimes fails, among other
things, because it fails to assume an indicated connection after a
restart.

That seems to happen because after the decision to activate the
indicated connection, the device does not move from DISCONNECTED state
quickly enough. Another assumption recheck runs in between and decides
to generate a connection, because the assume state was already reset
in between.

First start, creates and activates b3a61b68-f744-4a4c-a513-61399c154a67
on vlan0017:

  NetworkManager (version 1.41.1-30921.55767cf5.el9) is starting...
      (asserts:10000, boot:caf7301a-19cd-498b-b5ba-5d36ee939ffe)
  ...
  settings: update[b3a61b68-f744-4a4c-a513-61399c154a67]: adding connection "vlan0017"
      (45113870df0a4cfb/keyfile)

Second start:

  NetworkManager (version 1.41.1-30921.55767cf5.el9) is starting...
      (after a restart, asserts:10000, boot:caf7301a-19cd-498b-b5ba-5d36ee939ffe)

Assumption attempt successfully picks the right connection and thus
proceeds to reset the assume state:

  manager: (vlan0017): assume: will attempt to assume matching connection 'vlan0017'
      (b3a61b68-f744-4a4c-a513-61399c154a67) (indicated)
  device[c7c5101cf0b73f5f] (vlan0017): assume-state: set guess-assume=0, connection=(null)

Everything great so far, activation of the right connection is enqueued
and the device moves away from unavailable state. However, the
activation can't proceed immediately:

  device (vlan0017): state change: unmanaged -> unavailable
      (reason 'connection-assumed', sys-iface-state: 'assume')
  device (vlan0017): state change: unavailable -> disconnected
      (reason 'connection-assumed', sys-iface-state: 'assume')
  active-connection[0x55ba1162f1c0]: set device "vlan0017" [0x55ba1163c4f0]
  device[c7c5101cf0b73f5f] (vlan0017): queue activation request waiting for carrier

Now another assumption attempt is done. The original assume state is
gone, so a connection is generated:

  platform-linux: UDEV event: action 'add' subsys 'net' device 'vlan0017' (6); seqnum=1959
  device[c7c5101cf0b73f5f] (vlan0017): queued link change for ifindex 6
  manager: (vlan0017): assume: generated connection 'vlan0017' (57627119-8c20-4f9e-bf4d-4fc427b4a6a9)
  keyfile: commit: 57627119-8c20-4f9e-bf4d-4fc427b4a6a9 (vlan0017) added as
      "/run/NetworkManager/system-connections/vlan0017-57627119-8c20-4f9e-bf4d-4fc427b4a6a9.nmconnection"
      (nm-generated,volatile,external)

I think this shouldn't have happened. We've picked the correct
connection already and it's enqueued for activation!

Change the check in nm_device_emit_recheck_assume() to also consider
any queued activation.

Fixes-test: @dracut_NM_vlan_over_team_no_boot

Co-authored-by: Lubomir Rintel <lkundrak@v3.sk>

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1351
2022-09-03 16:41:52 +02:00
Thomas Haller
18eeb4bf6c
libnm: fix invalid doc annotations for missing end tag 2022-09-02 19:03:35 +02:00
Thomas Haller
2ccbf8af3b
libnm: style cleanups for property annotations
The parser will become stricter, and expect certain
things. The strictness should help, to avoid writing wrong annotations.

Adjust for that.
2022-09-02 19:03:35 +02:00
Thomas Haller
e70607aa55
libnm: avoid "tag:" text inside documentation
The parser is reworked, and this line could be wrongly parsed
because it starts with " *     value:" which could be misinterpreted
as a tag. It actually won't be parsed wrongly and is not parsed
wrongly now. Still, avoid this potential ambiguity by breaking
the line differently.
2022-09-02 19:02:57 +02:00
Thomas Haller
29dae2939a
libnm: drop invalid "---ifcfg-rh---" blocks 2022-09-02 19:02:25 +02:00
Thomas Haller
6d945b4fd3
libnm: fix documentation annotations for ifcfg-rh plugin 2022-09-02 19:02:24 +02:00
Lubomir Rintel
f3327835c1 team: restore port configuration after teamd respawn
If teamd crashes, we restore it. That's very nice, but if it really
crashed then it left ports attached and the slave connections are not
going to fail and the port configuration (e.g. priority or link watcher) in
teamd's memory will be gone.

This will restore the port configuration when the teamd connection is
re-established. This probably also fixes a race where a slave connection
would be enslaved (only possible externally and manually?) while we
didn't establish a connection to teamd yet. We'll just send the port
configuration in once're connected.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1361
2022-09-02 12:51:25 +02:00
Lubomir Rintel
38251ad59f team: trivial: use a variable instead of nm_device_get_ip_iface() calls
This reads a little better and performs marginally better.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1361
2022-09-02 12:51:09 +02:00
Vojtech Bubela
5fde7814dc ovs: add ofport_request option to ovs interface
Add option to set ofport_request when configuring ovs interface. When
connection with ofport_request configured is activated ovsdb will first
try to activated on the port set by ofport_request.
2022-09-02 08:46:36 +00:00
Thomas Haller
39e8707f0d
version: reformat file for latest style
the .h.in file is not formatted by our nm-code-format.sh
file. It also contains .in template parameters that the
formatting would destroy.

Still, follow our current style and reformat the parts manually.
2022-09-01 16:33:39 +02:00
Lubomir Rintel
222bd85fdc nmcli: don't translate "%s"
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1354
2022-09-01 13:07:23 +02:00
Lubomir Rintel
b071041d17 manager: drop useless use of a format string
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1355
2022-09-01 13:05:57 +02:00
Vojtech Bubela
7dccb5f548
version: add 1.42 macros 2022-08-31 19:23:26 +02:00
Thomas Haller
130479c8b2
nmcli: allow setting the "connection.uuid" for new profiles
Because, why not?

The client side determines the UUID, so there is no security implication
by letting the nmcli user explicitly choose it.

  $ nmcli connection add type ethernet con-name x connection.uuid 6965f79c-4424-4918-98e8-3c0982434011
  Connection 'x' (6965f79c-4424-4918-98e8-3c0982434011) successfully added.
  $ nmcli connection add type ethernet con-name x connection.uuid 6965f79c-4424-4918-98e8-3c0982434011
  Error: Failed to add 'x' connection: a connection with this UUID already exists
  $ nmcli connection modify x connection.uuid 6965f79c-4424-4918-98e8-3c0982434011
  $ nmcli connection modify x connection.uuid 6965f79c-4424-4918-98e8-3c0982434012
  Error: failed to modify connection.uuid: the property can't be changed.
2022-08-31 19:20:12 +02:00
Thomas Haller
fcf32d81bd
nmcli: allow changing the UUID of a profile in offline mode
It is useful to modify the UUID in offline mode. Otherwise, it's
cumbersome to clone a profile, because the cloned profile will
have the same UUID (and NetworkManager cannot load them both
at the same time).

  umask 077
  nmcli --offline connection modify \
      connection.id profile2 \
      connection.uuid new \
    < /etc/NetworkManager/system-connections/profile1.nmconnection \
    > /etc/NetworkManager/system-connections/profile2.nmconnection \

The doctext doesn't actually work for `man nm-settings-nmcli`. The
generation of our docs is still an incomprehensible mess that needs
fixing.
2022-08-31 19:20:11 +02:00
Thomas Haller
14828a0932
nmcli: support changing the connection type in offline mode 2022-08-31 19:20:11 +02:00
Thomas Haller
71a111bb9c
nmcli: add get_env_flags() accessor to NMMetaEnvironment for checking offline mode
We will want to know whether we are in offline mode.
Add an accessor to get environment flags, which libnmc-setting
can use.
2022-08-31 19:20:11 +02:00
Thomas Haller
686d9ebd4f
libnmc: avoid "g_set_error(error, 1, 0, ...)" and use nm_utils_error_set()
We really should not pass bogus values "1, 0" to g_set_error().
As we don't care about a particular error code, use
NM_UTILS_ERROR_UNKNOWN.

While at it, use nm_utils_error_set() everywhere.
2022-08-31 19:20:11 +02:00
Thomas Haller
f16a6f55fb
glib-aux/trivial: fix typo in comment 2022-08-31 19:20:10 +02:00
Thomas Haller
1326e42823
glib-aux: first try stack allocated temporary buffer in nm_uuid_generate_from_strings()
Try to first use a stack allocated buffer for the temporary string.
Only if the data is too large, NMStrBuf will automatically grow
the buffer on the heap.

In many cases, this buffer will be large enough, and we can avoid the
heap allocation.
2022-08-31 19:20:10 +02:00
Thomas Haller
c5ec4ebd77
glib-aux: fix spurious semicolon after NM_STR_BUF_INIT() macros
It's wrong, and it breaks certain uses.

Fixes: 13d25f9d0b ('glib-aux: add support for starting with stack-allocated buffer in NMStrBuf')
2022-08-31 19:20:10 +02:00
Thomas Haller
6b74f3cc14
cloud-setup,glib-aux: use NULL instead of g_direct_equal() for hash tables 2022-08-31 09:47:48 +02:00
Thomas Haller
4c48864972
initrd: avoid duplicate file check and NULL pointer dereference in nmi_ibft_read()
- move the second g_file_test() inside the if-block. No need to check
  twice, if the file exists.

- load_one_nic() can return NULL. Use nm_g_hash_table_lookup() to avoid
  NULL pointer assertion.

- use cleanup attribute for "nic" variable, and explicitly pass
  ownership on with g_steal_pointer().
2022-08-31 09:42:23 +02:00
Adrian Freihofer
ff7c5f4024
device: load only required modules
Honor firewall-backend for modules loading and ip forwarding enabling as
well:
* iptables: do not load nftables modules
* nftables: do not load iptables modules
* none: do not load any modules and do not enable ip forwarding

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1356
2022-08-31 09:19:01 +02:00
Thomas Haller
b336b249f5
wifi: use GSource instead of source ID for Wi-Fi scan_kickoff_timeout 2022-08-30 10:09:23 +02:00
Thomas Haller
ade9e17664
wifi: allow explicit scans during AP/ADHOC modes
The user might still want to see the scan list, to decide whether to
stop the hotspot/ADHOC connection and connect to something else.

Allow explicit scans.
2022-08-30 09:58:03 +02:00
Thomas Haller
9902373c6d
tests: fix "test-client.py" for early python3 versions
ModuleNotFoundError was only introduced in later python 3 versions.
Use just "ImportError", which is the parent class anyway.

Fixes: f7e484c8ed ('tests: fix "test-client.py" ignoring missing "NM" module')
2022-08-26 00:00:14 +02:00
Thomas Haller
befbad7375
style: fix code formatting
Fixes: eec9efd989 ('glib-aux: fix nicks for zero flag in nm_utils_enum_to_str()')
2022-08-25 23:27:36 +02:00
Beniamino Galvani
905adabdba
device: restart DHCP when the MAC changes
If the MAC changes there is the possibility that the DHCP client will
not be able to renew the address because it uses the old MAC as
CHADDR. Depending on the implementation, the DHCP server might use
CHADDR (so, the old address) as the destination MAC for DHCP replies,
and those packets will be lost.

To avoid this problem, restart the DHCP client when the MAC changes.

https://bugzilla.redhat.com/show_bug.cgi?id=2110000
2022-08-25 23:19:13 +02:00
Beniamino Galvani
6cd69fde33
core: log when dynamic IP configuration is restarted and why 2022-08-25 23:18:53 +02:00
Lubomir Rintel
c183f10f65
device: wait for carrier on unavailable device even when it gets a connection assumed
The test in question leaves the device with a master set, which caused a
connection to get assumed and therefore the previous fix didn't kick in.

Fixes-test: @restart_L2_only_lacp
Fixes: 5b7f8f3f70 ('device: wait for carrier even if it wasn't us who brought the device IFF_UP')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1348
2022-08-25 23:15:24 +02:00
Thomas Haller
eec9efd989
glib-aux: fix nicks for zero flag in nm_utils_enum_to_str()
nm_utils_enum_to_str() can print flags, that is, combinations of
powers of two integers.

It also supports nicks, for certain flags.

When we have a nick for value zero, then that requires special
handling. Otherwise, that zero nick will always show up in the
string representation, although, it should only be used if the
enum value is exactly zero.
2022-08-25 23:07:44 +02:00
Thomas Haller
c00873e08f
mptcp: rework "connection.mptcp-flags" for enabling MPTCP
1) The "enabled-on-global-iface" flag was odd. Instead, have only
and "enabled" flag and skip (by default) endpoints on interface
that have no default route. With the new flag "also-without-default-route",
this can be overruled. So previous "enabled-on-global-default" now is
the same as "enabled", and "enabled" from before behaves now like
"enabled,also-without-default-route".

2) What was also odd, as that the fallback default value for the flags
depends on "/proc/sys/net/mptcp/enabled". There was not one fixed
fallback default, instead the used fallback value was either
"enabled-on-global-iface,subflow" or "disabled".
Usually that is not a problem (e.g. the default value for
"ipv6.ip6-privacy" also depends on use_tempaddr sysctl). In this case
it is a problem, because the mptcp-flags (for better or worse) encode
different things at the same time.
Consider that the mptcp-flags can also have their default configured in
"NetworkManager.conf", a user who wants to switch the address flags
could previously do:

  [connection.mptcp]
  connection.mptcp-flags=0x32   # enabled-on-global-iface,signal,subflow

but then the global toggle "/proc/sys/net/mptcp/enabled" was no longer
honored. That means, MPTCP handling was always on, even if the sysctl was
disabled. Now, "enabled" means that it's only enabled if the sysctl
is enabled too. Now the user could write to "NetworkManager.conf"

  [connection.mptcp]
  connection.mptcp-flags=0x32   # enabled,signal,subflow

and MPTCP handling would still be disabled unless the sysctl
is enabled.

There is now also a new flag "also-without-sysctl", so if you want
to really enable MPTCP handling regardless of the sysctl, you can.
The point of that might be, that we still can configure endpoints,
even if kernel won't do anything with them. Then you could just flip
the sysctl, and it would start working (as NetworkManager configured
the endpoints already).

Fixes: eb083eece5 ('all: add NMMptcpFlags and connection.mptcp-flags property')
2022-08-25 21:31:45 +02:00
Thomas Haller
04a97e4e85
std-aux: workaround maybe uninitialized warning with LTO on nm_ip_addr_is_null()
LTO without assertion enabled, thinks that certain code paths
result in uninitialized code. Technically, it's not wrong, in practice
those are only in cases where we already failed an assertion.

  In function 'nm_ip_addr_is_null',
      inlined from 'canonicalize_ip_binary' at src/libnm-core-impl/nm-setting-ip-config.c:67:21,
      inlined from 'nm_ip_route_set_next_hop_binary' at src/libnm-core-impl/nm-setting-ip-config.c:1062:23:
  ./src/libnm-glib-aux/nm-inet-utils.h:80:12: error: 'a' may be used uninitialized [-Werror=maybe-uninitialized]
     80 |     return IN6_IS_ADDR_UNSPECIFIED(&a.addr6);
        |            ^
  src/libnm-core-impl/nm-setting-ip-config.c: In function 'nm_ip_route_set_next_hop_binary':
  ./src/libnm-glib-aux/nm-inet-utils.h:73:14: note: 'a' declared here
     73 |     NMIPAddr a;
        |              ^

Try to workaround that by letting nm_utils_addr_family_to_size() always
return a non-zero size. This is ugly, because in the assertion case fail
we might now also get an additional memory corruption that could have
been avoided by returning zero. However, it probably doesn't matter, because
in this scenario we are already in a bad situation.

Fixes: b02aeaf2f3 ('glib-aux: fix various nm_ip_addr_*() functions for unaligned addresses')
2022-08-25 21:15:38 +02:00
Thomas Haller
97a2a566b4
glib-aux/trivial: rename function for consistency 2022-08-25 19:23:41 +02:00
Thomas Haller
0e3ab2782a
glib-aux: simplify nm_inet_parse_str() by using nm_inet_parse_bin() 2022-08-25 19:05:57 +02:00
Thomas Haller
b02aeaf2f3
glib-aux: fix various nm_ip_addr_*() functions for unaligned addresses
Most of our nm_ip_addr_*() functions take an opaque pointer, that
can be either in_addr_t, struct in6_addr or NMIPAddr.

They also tend to support that their argument pointer is not aligned.
The reason is not very strong, except that usually it's simple to
support and it allows the caller to use those low-level functions for
pointers of unknown alignment (e.g. from a package on the network).

Fix a few cases for that.
2022-08-25 19:05:55 +02:00
Thomas Haller
232df1c08d
glib-aux/tests: test nm_ip_addr_is_site_local() 2022-08-25 19:05:53 +02:00