Commit graph

14692 commits

Author SHA1 Message Date
Thomas Haller
83ee8bd82a
core: sort includes in "src/core/nm-manager.c"
This will be linked by CONTRIBUTING.md file as an example how to do it.
Sorting includes by name is a sensible default-choice, so do it.
2021-08-26 14:43:32 +02:00
Thomas Haller
101a7cb56d
tests: improve documentation how to generate files for "/test-client.py" 2021-08-26 13:47:04 +02:00
Thomas Haller
beeff19f6c
libnm: cleanup nm_utils_check_virtual_device_compatibility() 2021-08-25 08:19:57 +02:00
Christian Glombek
9c2d835e5c
libnm: allow addition of wireless connections to bonds in nm_utils_check_virtual_device_compatibility()
https://gitlab.gnome.org/GNOME/network-manager-applet/-/issues/140

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/969
2021-08-25 08:19:01 +02:00
Wen Liang
6da4464154 platform: track kernel support for IFLA_PERM_ADDRESS
Track whether kernel supports netlink API IFLA_PERM_ADDRESS. To use the
platform cache preferably if kernel supports IFLA_PERM_ADDRESS. To fall
back to the old ethtool call directly if kernel does not support
IFLA_PERM_ADDRESS.

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

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/961

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-08-24 16:16:27 -04:00
Wen Liang
60bad3a41e
platform: obtain l_perm_address via netlink or lookup via ethtool
Add and call the new `nm_platform_link_get_permanent_address()` to
obtain `l_perm_address` via netlink or lookup via ethtool if kernel
does not expose the `IFLA_PERM_ADDRESS`.

And call the new `nm_platform_link_get_permanent_address()` in the unit
tests.

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

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-08-24 21:04:22 +02:00
Wen Liang
2b70e02ef5
platform: rename nm_platform_link_get_permanent_address()
Rename `nm_platform_link_get_permanent_address()`, `link_get_permanent_address()` to
`nm_platform_link_get_permanent_address_ethtool()`, `link_get_permanent_address_ethtool()`.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-08-24 21:04:21 +02:00
Wen Liang
1605fa460d
platform: update nm_platform_link_get_permanent_address() to accept NMPLinkAddress argument
Replace the arguments "buf+length" of
`nm_platform_link_get_permanent_address()` with "NMPLinkAddress *out_addr"

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-08-24 21:04:21 +02:00
Wen Liang
585257509f
platform: add l_perm_address in NMPlatformLink and parse it from netlink
Add `l_perm_address` in `NMPlatformLink` and add it to
`nm_platform_link_to_string`, `nm_platform_link_hash_update`,
`nm_platform_link_cmp` functions, and parse it from netlink.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-08-24 21:04:20 +02:00
Thomas Haller
db13b93563
ifcfg-rh: fail nms_ifcfg_rh_writer_write_connection() without filename/dir
No actual caller should use the API without providing either a filename
or the directory name. I don't think this can actually happen, hence
fail and assert in that case.
2021-08-24 13:45:10 +02:00
Thomas Haller
1fa105eaef
ifcfg-rh: fix updating ifcfg file if file on disk is no longer present
Have an ifcfg file loaded in NetworkManager, then move/remove the file and try
to modify it. That will fail with:

  "failed to update connection: Could not read file '/etc/sysconfig/network-scripts/ifcfg-eth0': No such file or directory"

That is not right.

If the user didn't move/remove the file but merely modified it, NetworkManager
would silently overwrite it. There is no reason why move/remove should behave
differently and not just write a completely fresh file.

The reason why NetworkManager first loads the file before writing, is to
preserve comments and unrecognized shell variables. This is a certain effort
to play nice with users editing the file. It's not essential to load the file
first and a failure to do so should not result in a failure.

And of course, keyfile writer doesn't behave like this either.

This bug exists since 2009, but let's not add a "Fixes" comment for
commit 1974b257e0 ('ifcfg-rh: begin adding write support'), because
it seems not right to backport this patch to all the old releases.
2021-08-24 13:45:06 +02:00
Thomas Haller
8ed17ded7b
libnm-core: drop unnecessary cast from _nm_connection_ensure_setting() 2021-08-20 22:16:40 +02:00
Thomas Haller
650922eeaa
tui: fix order of includes 2021-08-20 22:16:36 +02:00
Gris Ge
e69c5e4bab
libnm: Use _nm_connection_ensure_setting()
Use `_nm_connection_ensure_setting()` to eliminate the
duplicated codes. This function will retrieve the specific setting from
connection, if not found, create new one and attach to the connection.

Signed-off-by: Gris Ge <fge@redhat.com>
2021-08-20 19:02:23 +02:00
Gris Ge
c265096d66
libnm-core-aux-intern: Add helper function _nm_connection_ensure_setting()
Introduce internal function `_nm_connection_ensure_setting()` to
`libnm-core-aux-intern` and add specified setting to connection if not
found.

Signed-off-by: Gris Ge <fge@redhat.com>
2021-08-20 19:02:23 +02:00
Beniamino Galvani
bbb7eb1767 8021x: request PINs for PKCS#11 certs unless explicitly not-required
Commit df0dc912cc ('8021x: don't request secrets if they are empty
and system owned') changed the setting so that NM doesn't request the
PIN for PKCS#11 certificates and keys when the password property has
NM_SETTING_SECRET_FLAG_NONE. From the commit message:

    Empty secrets are fine. In particular, for PKCS#11 it means that
    protected authentication path is used (the secrets are obtained
    on-demand from the pinpad).

This change breaks the scenario in which PINs are stored in the
connection, as the setting indicates that no secrets are required, and
thus PINs are not sent to the supplicant.

If the PIN is entered through a pinpad, users should set the secret
flags as 'not-required'.

This reverts commit df0dc912cc ('8021x: don't request secrets if
they are empty and system owned').

https://bugzilla.redhat.com/show_bug.cgi?id=1992829
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/965
2021-08-20 18:09:48 +02:00
Thomas Haller
ea49b50651
all: add some README.md files describing the purpose of our sources 2021-08-19 17:51:11 +02:00
Thomas Haller
2f3c2647d2
nmcli/docs: fix address order in ipv46.addresses documentation for man nm-settings-nmcli
For IPv4, the order is not like for IPv6. Of course not.

Fixes: 7aa4ad0fa2 ('nmcli/docs: better describe ipv[46].addresses in `man nm-settings-nmcli`')
2021-08-19 14:00:03 +02:00
Thomas Haller
c380893dc6
platform: fix capturing addresses from platform for assuming after restart
Commit c631aa48f0 ('platform: capture NMIP[46]Config from platform
with correct (reversed) order of IP addresses') changed this for IPv6
and IPv4, but it's not correct for IPv4.

For IPv6, later `ip addr add` calls adds a new primary address, which
is also listed in `ip addr show` first. Hence, as NMIP6Config tracks
addresses in increasing priority, while NMPlatform tracks them as
exposed by kernel, the order when appending addresses form platform
to NMIP6Config must be reversed.

That is not the case for IPv4. For IPv4, later `ip addr add` calls
add a secondary IP address. Also, in `ip addr show` output they are
appended. Consequently, IPv4 addresses are tracked by NMPlatform with
decreasing priority (in the reverse order than for IPv6).

Fix constructing the NMIP4Config by fixing the address order. This is
important, because during restart devices get assumed and our code would
configure the order of addresses as it finds them.

Fixes: c631aa48f0 ('platform: capture NMIP[46]Config from platform with correct (reversed) order of IP addresses')
2021-08-19 13:48:22 +02:00
Thomas Haller
8733d22343
ifcfg: read/write full IPv6 settings also for method ignore/disabled
Do "bother" to read/write settings.

For the umpteenth time, it's not up to the reader/writer to decide
what properties are valid for a profile or which makes sense.

Only nm_connection_verify() can decide that. For example nm_connection_verify()
has no problem with ipv6.method=disabled while also setting ipv6.addr-gen-mode.
We cannot just shortcut the parsing/writing.

The reader only ignores addresses, dns and dns-searches, so that we don't start
parsing invalid files, where the setting would have been ignore
previously.

In particular,

   echo "DEVICE=eth0" > /etc/sysconfig/network-scripts/ifcfg-xxx
   nmcli connection load /etc/sysconfig/network-scripts/ifcfg-xxx
   nmcli -f ipv6.method,ipv6.addr-gen-mode connection show /etc/sysconfig/network-scripts/ifcfg-xxx

needs to show eui64 addr-gen-mode.
2021-08-19 08:54:54 +02:00
Thomas Haller
7de4322d51
ifcfg: don't let write_ip[46]_setting() fail 2021-08-19 08:54:54 +02:00
Thomas Haller
00f63074d6
ifcfg: don't limit parsing DNS elements to 10 entries
It's not the task of the ifcfg reader to pre-normalize profiles
to truncate the DNS server list. It's only nm_connection_verify()'s
task to indicate what is valid and what not.

Increase the number to something excessive. Note that the parsing
scales with O(n^2). So don't have it totally unbounded and have an
overall limit (of 10000 entries).
2021-08-19 08:54:40 +02:00
Thomas Haller
1abf512831
ifcfg: fix crash due to not setting error on failure to parse DNS
Fixes: c2ad294290 ('ifcfg-rh: fix error handing in some functions that expect error != NULL')
2021-08-17 20:07:34 +02:00
Thomas Haller
02832b03ee
ifcfg/tests: fix evaluating environment variable to regenerate test files
Fixes: 1ae6719cf1 ('ifcfg-rh/tests: evalute environment for $NMTST_IFCFG_RH_UPDATE_EXPECTED only once')
2021-08-17 20:05:25 +02:00
Thomas Haller
7aa4ad0fa2
nmcli/docs: better describe ipv[46].addresses in man nm-settings-nmcli 2021-08-17 19:56:39 +02:00
Thomas Haller
c631aa48f0
platform: capture NMIP[46]Config from platform with correct (reversed) order of IP addresses
Fix the order of IP addresses when assuming devices (service restart).

The order of IP addresses matters to kernel for selection of source IP
address.

If all other properties are equal ([1]), for IPv6, the address added *last*
will be preferred. That is the address you see *first*` in `ip -6 addr show`.
NMPlatform also preserves that order, so the address *first* is the most
important one.

On the other hand, in a connection profile, `ipv6.addresses` lists
addresses in increasing priority (the last address is the primary one).
That is for compatibility with initscripts, which iterates over the
list of addresses and calls `ip addr add` (meaning, the last address
will be added last and is thus preferred by kernel).

As the priority order in the profile is reversed, also the priority
order in NMIP[46]Config is reversed. Fix creating an NMIP[46]Config
instance from platform addresses to honor the priority.

This has real consequences. When restarting NetworkManager, the interface
stays up with the addresses configured in the right order. After
restart, the device gets assumed, which means that the NMIP[46]Config
instance from the connection is not yet set, only the config from the
platform gets synchronized. Previously the order was wrong, so during
restart the order of IP addresses was reverted.

[1] https://access.redhat.com/solutions/189153

https://bugzilla.redhat.com/show_bug.cgi?id=1988751
2021-08-17 19:56:39 +02:00
Thomas Haller
9c99c948fd
platform: add nmp_cache_iter_for_each_reverse() helper 2021-08-17 19:56:38 +02:00
Thomas Haller
53070705b0
glib-aux: clear iterator in nm_dedup_multi_iter_{next,prev}() at the end
It seems slightly nicer not to leave a dangling pointer at the
end of the iteration. Then you could do something like

    nm_dedup_multi_iter_init(&iter, head_entry);
    while (nm_dedup_multi_iter_next(&iter)) {

        if (some_condition())
            break;
    }
    if (!iter.current)
        printf("iterated to the end\n");

As nm_dedup_multi_iter_next() and nm_dedup_multi_iter_init() are inline
functions, the compiler should even be able to see that the initial
setting becomes unnecessary (the field will be initialized by the
first nm_dedup_multi_iter_next()). Likewise, the final clearing
of the field might also be optimized away at the end of the iteration
(if, as in the common case, the iterator is not accessed afterwards).
2021-08-17 19:56:38 +02:00
Thomas Haller
57a519cc03
glib-aux: add nm_dedup_multi_iter_init_reverse() to iterate in reverse order 2021-08-17 19:56:38 +02:00
Ana Cabral
750d35a6e3 nm-initrd-generator: remove duplex option 2021-08-17 12:00:37 -03:00
Javier Sánchez Parra
b0f5b1d97a
tui: add WireGuard support to nmtui
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/736
2021-08-17 14:10:12 +02:00
Thomas Haller
76bcd78710
platform/netlink: use appropriate integer types in nla_policy 2021-08-17 13:18:08 +02:00
Thomas Haller
57d626c182
platform/netlink: rework static check in _nl_static_assert_tb() to use _Generic()
Depending on sizeof(policy) to be sizeof(NULL) is not a good check
whether the macro argument may be NULL. That is, because the size
of the policy array might accidentally be the same as the size of
a pointer. Use _Generic() instead.
2021-08-17 13:18:07 +02:00
Thomas Haller
fa745181dc
platform/netlink: drop unused NLA_NUL_STRING type
Kernel implemente NLA_NUL_STRING type, but we don't implement
exactly the same type checks. Drop NLA_NUL_STRING and use a plain
NLA_STRING instead.
2021-08-17 13:18:07 +02:00
Thomas Haller
f7635c9ffe
platform/netlink: use switch for type check in validate_nla() 2021-08-17 13:18:07 +02:00
Thomas Haller
68a5d1cfe5
platform/netlink: refactor handling length in validate_nla() 2021-08-17 13:18:07 +02:00
Thomas Haller
6f1274caea
platform/netlink: return uint16_t type from nla_len()
nla_len() cannot return anything larger or smaller than range uint16_t.
Change the return type of nla_len().
2021-08-17 13:18:07 +02:00
Thomas Haller
386b367bfa
platform/netlink: cleanup handling of nla_attr_minlen
- make nla_attr_minlen[] and array of uint8_t. That is large enough for
  all values we have.

- don't handle NLA_UNSPEC specially. nla_attr_minlen[NLA_UNSPEC] returns
  zero just fine.
2021-08-17 13:18:06 +02:00
Thomas Haller
0adc4fc4f6
platform/netlink: drop unused NLA type enums 2021-08-17 13:18:06 +02:00
Ana Cabral
f06c89f596 nm-initrd-generator: add kernel command line options ethtool autoneg, speed and duplex to configure NICs
Merge Request !941
2021-08-11 13:55:43 -03:00
echengqi
97041efee1
core: free config_cli before exit() from main
[thaller@redhat.com: changed commit message]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/954
2021-08-11 16:23:09 +02:00
Thomas Haller
f5dbf476e3
core: rename to_str() methods to to_string()
It's more common to name the to-string method *_to_string(). Rename.
2021-08-11 14:17:25 +02:00
Thomas Haller
ae117c588d
dhcp: ensure NMDhcpClient was stopped in destructor
The user of NMDhcpClient is supposed to call "nm_dhcp_client_stop()"
on the instance, also because it is a ref-counted GObject type. So we
wouldn't want to rely on the last unref to stop DHCP.

Still, in case that was not done, the code somehow made the assumption
it made any sense to possibly not stop the DHCP client. For the internal
client, there is of course nothing left after destroying the
NMDhcpClient instance, but what about dhclient? I don't think we should
ever leave dhclient running unsupervised. Even during restart of the
service, we need to stop it first, and restart it afterwards.

When we quit NetworkManager, we may want to leave the interface up and
configured. For that, we may need to take care that "nm_dhcp_client_stop()"
does not destory the IP configuration of the intrerface. But I don't
think that is a problem. What we still want to do, is kill the dhclient
instance.

NMDhcpClient is not supposed to be ever restarted. It starts when an
instance gets created, and it stops with "nm_dhcp_client_stop()". Hence,
the simple "is_stopped" flag is fine to prevent that multiple stop calls
are harmful.
2021-08-11 14:17:25 +02:00
Thomas Haller
359d207d95
dhcp: stop tracking NMDhcpClient instances from NMDhcpManager
NMDhcpManager was tracking DHCP clients. During start, it would check
whether an instance for the same ifindex is running, and stop it.

That seems unnecessary and wrong. Clearly, we cannot have multiple users
(like two `NMDevice`s) run DHCP on the same interface. But its up to
them to coordinate that. They also cannot configure IP addresses at the
same interface, and if they do, then there is a big problem already.

This comes from commit 1806235049 ('dhcp: convert dhcp backends to
classes'). Maybe back then there was also the idea that NetworkManager
could quit and leave dhclient running. That idea is also flawed. When
NetworkManager stops, it leaves the interface (possibly) up, so that
restart works without disruption. That does not mean that the DHCP
client needs to keep running. What works is to restart NetworkManager in
a timely manner, then NetworkManager will start a new DHCP client after
restart. What does not work is stop NetworkManager, do nothing (like
taking over the interface by running your own manager) and expect that
DHCP keeps working indefinitely. And of course, with the internal client
this cannot possibly work either. Don't stop NetworkManager for good, if
you expect NetworkManager to run DHCP on an interface.

A different things is that when NetworkManager crashes, that after
restart it kills the left over dhclient instances. That may require a
solution, for example systemd killing all processes or checking for
left-over PID files and kill the processes. But what was implemented in
NMDhcpManager was not a solution for that.

As such, it's not clear what conflicting instance we want to kill, or
why NMDhcpManager should even track NMDhcpClient instances.
2021-08-11 14:17:25 +02:00
Thomas Haller
dbdd8303fc
dhcp: replace NMDhcpClient's signals with "notify" and one notify data argument
NMDhcpClient communicates events via GObject signals. GObject signals in
principle could have several subscribers. In practice, a NMDhcpClient
instance has only one subscriber, because it was constructed with
certain parameters, so it's unlikely to be shared.

That one subscriber, always needs to subscribe to all signals
("state-changed" and "prefix-delegated"), Unless the subscriber only
creates a IPv4 client. In which case they won't subscribe to
"prefix-delegated", but that signal is also not invoked for IPv4
clients.

Combine the signals in one, and pass all parameters via a new
NMDhcpClientNotfiyData payload. I feel this is nicer, to pack all
parameters together. I find this more type-aware, where we can
switch (in the callback) based on a notify-type enum, instead
of subscribing multiple signal handlers.

With l3cfg work, DHCP handling will be refactored, where this model of
having one "generic" notify signal makes more sense than here. For the
moment, it is arguably pretty much the same. Also, because NMDhcpClient
subscribes two different handlers for IPv4 and IPv6. In the future,
there will be only one notify handler, and that can cover IPv4 and IPv6
and both "state-changed" and "prefix-delegated" (and other notification
types).
2021-08-11 14:17:24 +02:00
Thomas Haller
4d0e295317
ndisc: add nm_ndisc_dhcp_level_to_string() helper 2021-08-11 14:17:24 +02:00
Thomas Haller
1d789ca44b
std-aux: add XXX() macro 2021-08-11 14:17:24 +02:00
Wen Liang
778e1f8493 aliyun: reuse ipv4 gateway address returned by metadata server
The default ipv4 gateway address of the VPC in Aliyun cloud is not the
first IP address in the CIDR subnet block, we should instead use the
ipv4 gateway address retrieved from the metadata server in
`_nmc_mangle_connection()`.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/958

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-08-09 09:35:52 -04:00
Thomas Haller
f43bee77d6
glib-aux: drop unnecessary g_strlcpy() from nm_uuid_is_valid_nm() 2021-08-09 07:59:45 +02:00
Thomas Haller
30e7400528
ifup: extend ifup/ifdown to be smarter about NetworkManager profiles
Now that NetworkManager on Fedora 33 and RHEL 9 no longer writes
ifcfg-rh files by default ([1]), ifup/ifdown became less useful.

Possibly users shouldn't use it and it would be fine that new-style profiles
(keyfile) no longer work with these commands. But this is deemed as too
disruptive for users.

Note that our previous ifup/ifdown compat scripts only honored the argument
to be part of the ifcfg filename. That was not what initscripts were doing,
which called `need_config()` function that searched also the contents of
the files. With this extension, ifup/ifdown gets smarter too, to better
guess what the user might have wanted.

Extend the script by making it smarter, and to work with connection profile
names.

With this extension we further solidify ifup/ifdown as part of NetworkManager
command line API. That is problematic, because these tools pollute the
$PATH, by not having a clear NM-specific name. Also, these scripts
should only exist on Fedora/RHEL, which makes their usage non-portable
to other distros.
Also, other distros already ship different tools with name ifup/ifdown.
Extending the use of these scripts is thus undesirable, as it furthers
distro-specific commands.

Still, these arguments seem to not hold and users need to be "helped".
As Fedora users cannot be expected to unlearn "ifup" today, there is no
reason to assume they could in a few years. This likely means we will
never get rid of these scripts.

Also, if we truly would make ifup/ifdown part of NetworkManager, then a better
implementation would be that nmcli honors being called with these names.
That is not done, because nmcli's implementation currently is not as
nice to make that extension trivial (as it should be). It also would
mean to embrace ifup/ifdown officially. A shell script works well enough
as a hack.

[1] https://fedoraproject.org/wiki/Changes/NetworkManager_keyfile_instead_of_ifcfg_rh

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/936
2021-08-07 15:31:04 +02:00