Commit graph

1040 commits

Author SHA1 Message Date
Thomas Haller
08eff4c46e
glib-aux: rename IP address related helpers from "nm-inet-utils.h"
- name things related to `in_addr_t`, `struct in6_addr`, `NMIPAddr` as
  `nm_ip4_addr_*()`, `nm_ip6_addr_*()`, `nm_ip_addr_*()`, respectively.

- we have a wrapper `nm_inet_ntop()` for `inet_ntop()`. This name
  of our wrapper is chosen to be familiar with the libc underlying
  function. With this, also name functions that are about string
  representations of addresses `nm_inet_*()`, `nm_inet4_*()`,
  `nm_inet6_*()`. For example, `nm_inet_parse_str()`,
  `nm_inet_is_normalized()`.

<<<<

  R() {
     git grep -l "$1" | xargs sed -i "s/\<$1\>/$2/g"
  }

  R NM_CMP_DIRECT_IN4ADDR_SAME_PREFIX          NM_CMP_DIRECT_IP4_ADDR_SAME_PREFIX
  R NM_CMP_DIRECT_IN6ADDR_SAME_PREFIX          NM_CMP_DIRECT_IP6_ADDR_SAME_PREFIX
  R NM_UTILS_INET_ADDRSTRLEN                   NM_INET_ADDRSTRLEN
  R _nm_utils_inet4_ntop                       nm_inet4_ntop
  R _nm_utils_inet6_ntop                       nm_inet6_ntop
  R _nm_utils_ip4_get_default_prefix           nm_ip4_addr_get_default_prefix
  R _nm_utils_ip4_get_default_prefix0          nm_ip4_addr_get_default_prefix0
  R _nm_utils_ip4_netmask_to_prefix            nm_ip4_addr_netmask_to_prefix
  R _nm_utils_ip4_prefix_to_netmask            nm_ip4_addr_netmask_from_prefix
  R nm_utils_inet4_ntop_dup                    nm_inet4_ntop_dup
  R nm_utils_inet6_ntop_dup                    nm_inet6_ntop_dup
  R nm_utils_inet_ntop                         nm_inet_ntop
  R nm_utils_inet_ntop_dup                     nm_inet_ntop_dup
  R nm_utils_ip4_address_clear_host_address    nm_ip4_addr_clear_host_address
  R nm_utils_ip4_address_is_link_local         nm_ip4_addr_is_link_local
  R nm_utils_ip4_address_is_loopback           nm_ip4_addr_is_loopback
  R nm_utils_ip4_address_is_zeronet            nm_ip4_addr_is_zeronet
  R nm_utils_ip4_address_same_prefix           nm_ip4_addr_same_prefix
  R nm_utils_ip4_address_same_prefix_cmp       nm_ip4_addr_same_prefix_cmp
  R nm_utils_ip6_address_clear_host_address    nm_ip6_addr_clear_host_address
  R nm_utils_ip6_address_same_prefix           nm_ip6_addr_same_prefix
  R nm_utils_ip6_address_same_prefix_cmp       nm_ip6_addr_same_prefix_cmp
  R nm_utils_ip6_is_ula                        nm_ip6_addr_is_ula
  R nm_utils_ip_address_same_prefix            nm_ip_addr_same_prefix
  R nm_utils_ip_address_same_prefix_cmp        nm_ip_addr_same_prefix_cmp
  R nm_utils_ip_is_site_local                  nm_ip_addr_is_site_local
  R nm_utils_ipaddr_is_normalized              nm_inet_is_normalized
  R nm_utils_ipaddr_is_valid                   nm_inet_is_valid
  R nm_utils_ipx_address_clear_host_address    nm_ip_addr_clear_host_address
  R nm_utils_parse_inaddr                      nm_inet_parse_str
  R nm_utils_parse_inaddr_bin                  nm_inet_parse_bin
  R nm_utils_parse_inaddr_bin_full             nm_inet_parse_bin_full
  R nm_utils_parse_inaddr_prefix               nm_inet_parse_with_prefix_str
  R nm_utils_parse_inaddr_prefix_bin           nm_inet_parse_with_prefix_bin
  R test_nm_utils_ip6_address_same_prefix      test_nm_ip_addr_same_prefix

  ./contrib/scripts/nm-code-format.sh -F
2022-08-25 19:05:51 +02:00
Wen Liang
6058445aea dns: kill pending dnsmasq process when mode is not 'dnsmasq'
When NM starts, if `main.dns` is not `dnsmasq`, then the pending dnsmasq
process should be killed by NM.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1344
2022-08-25 12:31:48 -04:00
Wen Liang
9b3a96f821 dnsmasq: silently ignore if pid file is not existed when killing 2022-08-25 10:56:47 -04:00
Fernando Fernandez Mancera
7d4307e8df
bond: fix missing assignment of lp_interval_has
The variable `lp_interval` was being assigned instead of
`lp_interval_has`. The `lp_interval` bond option was not being set
correctly.

https://bugs.launchpad.net/network-manager/+bug/1987001

Fixes: e064eb9d13 ('bond: use netlink to set bond options')
2022-08-25 15:34:23 +02:00
Andrew Zaborowski
e3eac09082
iwd: nm_iwd_manager_get() once and save value
Call nm_iwd_manager_get once on NMDeviceIwd creation and save in
priv->manager to avoid using t very often now that we have 5 new call
sites.  The reasoning is explained in
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1338#note_1519684
2022-08-24 20:44:46 +02:00
Andrew Zaborowski
824f2f26db
iwd: Work around timing when new 802.1x connection activated
Try work around the issue documented by Emil Velikov in
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1264

When we mirror an 802.1x connection to an IWD config file and there's an
AP in range with matching SSID, that connection should become available
for activation.  In IWD terms when an 802.1x network becomes a Known
Network, it can be connected to using the .Connect D-Bus method.

However there's a delay between writing the IWD config file and receiving
the InterfaceAdded event for the Known Network so we don't immediately
find out that the network can now be used.  If an NM client creates a
new connection for an 802.1x AP and tries to activate it quickly enough,
NMDeviceIWD will not allow it to because it won't know the network is
known yet.  To work around this, we save the SSIDs of 802.1x connections
we recently mirrored to IWD config files, for an arbitrary 2 seconds
period, and we treat them as Known Networks in that period since in
theory activations should succeed.

The alternative proposed in the !1264 is to drop NMDeviceIWD checks that
there's a Known Network for the 802.1x connection being activated since
IWD will eventually perform the same checks and IWD is the ultimate
authority on whether the profile is IWD-connectable.
2022-08-24 20:44:46 +02:00
Andrew Zaborowski
f6cec3b584
iwd: Let IWD handle retries
When we're set to let IWD control autoconnect, don't retry connections
on NM side, set retry count to 0.
2022-08-24 20:44:45 +02:00
Andrew Zaborowski
e384ab74c2
iwd: Be extra careful not to interrupt assumed activation
The IWD backend would originally use .Disconnect() on IWD dbus "Station"
objects to make sure IWD is out of autoconnect or that it isn't
connecting to a network that NM didn't command.  Later the default became
to let IWD run autoconnect so now most of the time the backend just
mirrors IWD's state to NMDevice's state.

Now sometimes when NMDevice still seems to have an active connection but
IWD has gone through one or more state changes (which we may see after a
delay due to D-Bus) and is now connected to or connecting to a different
network, NMDevice would first have to go through .deactivate to mirror
the fact the original connection is no longer active, and it'd use
.Disconnect() which could break the new connection, so check for this
situation.
2022-08-24 20:44:45 +02:00
Thomas Haller
cbc2354854
wifi: drop duplicate include in "nm-device-wifi-p2p.c"
Base-on-patch-by: Andrew Zaborowski <andrew.zaborowski@intel.com>
2022-08-24 20:37:27 +02:00
Thomas Haller
3117198f15
Revert "wifi: support "802-1x.phase1-auth-flags=tls-allow-unsafe-renegotiation" flag"
There is still no agreement, about how to name this option, or whether
it should exist at all. Revert the addition of the flag.

As the new release is coming up, drop the new API.

https://bugzilla.redhat.com/show_bug.cgi?id=2072070#c64
https://bugzilla.redhat.com/show_bug.cgi?id=2077973#c24
http://lists.infradead.org/pipermail/hostap/2022-July/040665.html

This reverts commit a5a4aea2e6.
2022-08-11 19:36:26 +02:00
Fernando Fernandez Mancera
003eb75eb6 bond: fix parsing of arp_ip_target to platform
nm_setting_bond_get_option_normalized() is returning the arp_ip_target
IPs separated by comma instead of a blank space.

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

Fixes: e064eb9d13 ('bond: use netlink to set bond options')
2022-08-11 12:41:59 +02:00
Thomas Haller
1f5a05150a
mptcp: fix nmp_global_tracker_sync_mptcp_addrs()
- drop unused "keep_deleted" parameter. It just doesn't make sense.
  Even less sense than for rules/routes, where this was taken from.

- fix nmp_global_tracker_sync_mptcp_addrs() to delete addresses
  with conflicting flags. We did not correctly delete existing
  addresses, that were to be reconfigured with different flags.

Fixes: 5374c403d2 ('platfrom: handle MPTCP addresses with NMPGlobalTracker')
2022-08-10 11:35:28 +02:00
Thomas Haller
9f0f8e0fbe
config: support hex and octal numbers in nm_config_data_get_connection_default_int64()
This affects parsing global connection defaults from
"NetworkManager.conf".

Let's use a zero base for strtoll(), which honors the prefixes
"0x" and "0" to use hex and octal numbers, respectively. Otherwise
it uses decimal (base 10).

This causes very little ambiguity, but it makes certain numbers
just work.

Also, we have flags properties, where it makes much more sense
to write them in hex, like `connection.mptcp-flags=0x52`.
2022-08-10 10:05:16 +02:00
Thomas Haller
6fb11dbe77
device: allow reapplying changes to "connection.autoconnect-priorty"
Of course, this setting has no effect while being activated. But it
should not prevent reapply.
2022-08-09 14:11:55 +02:00
Thomas Haller
f64dff6939
all: drop various NMMptcpFlags
The default behavior might be sufficient. Drop those flags for now,
and figure out a good solution when we have an actual use-case.
2022-08-09 08:02:56 +02:00
Thomas Haller
eb083eece5
all: add NMMptcpFlags and connection.mptcp-flags property 2022-08-09 08:02:54 +02:00
Thomas Haller
5374c403d2
platfrom: handle MPTCP addresses with NMPGlobalTracker
When we configure MPTCP addresses, we usually do so per interface
(ifindex). That is, because each interface (via NMDevice and NML3Cfg)
decides how to configure MPTCP, and then we always add MTCP addresses
for this certain ifindex.

With that, we could have a purely interface-specific view and not a
global sync method. However, there are two problems:

The minor problem is that we don't cache the endpoints (because we don't
get notifications). We can only get a dump of all endpoints. It seems
odd to have a mptcp-addr-sync method that is per-ifindex, when it needs
to dump all addresses.

The much more important reason is that the number of endpoints that we
can configure in kernel is very limited. So we need to make a choice
which endpoints to configure, and for that we need to holistic view that
NMPGlobalTracker has.
2022-08-09 08:02:52 +02:00
Thomas Haller
ce635c4339
platform: add dump/update function for MPTCP addresses
Since the generic netlink API does (currently) not support notifications
about changes of the MPTCP addresses, we won't get notifications when
they change, and it seems wrong to put such things in the NMPlatform
cache.

We can just get the list of endpoints by polling, so add a function
nm_platform_mptcp_addrs_dump() for that.

Also, add nm_platform_mptcp_addr_update() which can add/remove/update
MPTCP addresses.
2022-08-09 08:02:50 +02:00
Thomas Haller
f4b128c63b
device: fix reapply for lldp/mdns/llmnr/dns-over-tls settings
When only one of those connection.{lldp,mdns,llmnr,dns-over-tls}
settings changes, we still need to do a full restart of the IP
configuration to reapply the changes.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-08-09 08:02:37 +02:00
Lubomir Rintel
5cf96c4db2
bridge: fix reapply of vlan_filtering and default_pvid
Fixes: 8e8fed433f ('bridge: add reapply support')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1327
2022-08-06 21:08:51 +02:00
Thomas Haller
67a5cf7675
core: block to get good random bytes for "/var/lib/NetworkManager/secret_key"
_host_id_read() is the only place where we really care to have good
random numbers, because that is the secret key that we persist to disk.

Previously, we tried only nm_random_get_bytes_full(), which is a best
effort to get strong random numbers. If it fails to generate those,
it would simply remember the generated key in memory and proceed, but not
persist it to disk.

nm_random_get_bytes_full() does not block waiting for good numbers.

Change that. Now, first call nm_random_get_crypto_bytes(), which would
block and try hard to get good random numbers. Only if that fails,
fallback to nm_random_get_bytes_full() as before. The difference is of
course only in early boot, when we might not yet have entropy. In that
case, I think it's better for NetworkManager to block.
2022-08-05 19:29:35 +02:00
Thomas Haller
d20343c9d0
glib-aux: rework random number utils
Heavily inspired by systemd ([1]).

We now also have nm_random_get_bytes{,_full}() and
nm_random_get_crypto_bytes(), like systemd's random_bytes()
and crypto_random_bytes(), respectively.

Differences:

- instead of systemd's random_bytes(), our nm_random_get_bytes_full()
  also estimates whether the output is of high quality. The caller
  may find that interesting. Due to that, we will first try to call
  getrandom(GRND_NONBLOCK) before getrandom(GRND_INSECURE). That is
  reversed from systemd's random_bytes(), because we want to find
  out whether we can get good random numbers. In most cases, kernel
  should have entropy already, and it makes no difference.

Otherwise, heavily rework the code. It should be easy to understand
and correct.

There is also a major bugfix here. Previously, if getrandom() failed
with ENOSYS and we fell back to /dev/urandom, we would assume that we
have high quality random numbers. That assumption is not warranted.
Now instead poll on /dev/random to find out.

[1] a268e7f402/src/basic/random-util.c (L81)
2022-08-05 19:29:34 +02:00
Fernando Fernandez Mancera
e064eb9d13 bond: use netlink to set bond options
Use the netlink platform implementation for setting the bond link
options.
2022-08-04 11:18:36 +02:00
Fernando Fernandez Mancera
f900f7bc2c platform: add netlink support for bond link
sysfs is deprecated and kernel people will not add new bond options to
sysfs. Netlink is a stable API and therefore is the right method to
communicate with kernel in order to set the link options.
2022-08-04 11:18:36 +02:00
Lubomir Rintel
5b7f8f3f70 device: wait for carrier even if it wasn't us who brought the device IFF_UP
The devices generally need to be IFF_UP and wait a little before the
carrier detection is reliable. Some devices, actually need to wait
more than a little -- r8169 needs up to 5 seconds.

For this reason, we delay startup complete while the carrier is down
after we bring the device up. We do this so that we don't reject
activations due to carrier down until we're sure it's really down.
This works well as long as it's us who brought the device up.

If we're restarting the daemon, the device is going to be already up
when we start up the daemon for the second time. There's, however, a
slim chance that the device was brought down and up very shortly before
the restart and therefore the carrier reporting is still not reliable.
As a matter of fact, we bring the devices down and back up on some
occassions, such as when enslaving to a team device.

Therefore, the following events in quick succession cause trouble:

  # nmcli con up team-slave-eth0
  [20099.205355] Generic FE-GE Realtek PHY r8169-0-300:00: attached PHY driver (mii_bus:phy_addr=r8169-0-300:00, irq=MAC)
  [20099.365641] nm-team: Port device eth0 added
  [20099.370728] r8169 0000:03:00.0 eth0: Link is Down
  [20099.436631] nm-team: Port device eth0 removed
  [20099.463422] Generic FE-GE Realtek PHY r8169-0-300:00: attached PHY driver (mii_bus:phy_addr=r8169-0-300:00, irq=MAC)
  [20099.628505] r8169 0000:03:00.0 eth0: Link is Down
  [20099.669425] Generic FE-GE Realtek PHY r8169-0-300:00: attached PHY driver (mii_bus:phy_addr=r8169-0-300:00, irq=MAC)
  [20099.833457] r8169 0000:03:00.0 eth0: Link is Down
  [20099.838471] nm-team: Port device eth0 added

The device has been brought down, enslaved and brought up.
"Link is Down" indicates carrier not being detected.

  Connection successfully activated (D-Bus active path: /org/freedesktop/NetworkManager/ActiveConnection/7)
  # systemctl restart NetworkManager

Now NM sees the device being up, but carrier down.

  # nmcli con up testeth0
  Error: Connection activation failed: No suitable device found for this connection (...).

Activation failed, because eth0 carrier still appears down.

  # [20102.943464] r8169 0000:03:00.0 eth0: Link is Up - 1Gbps/Full - flow control rx/tx

Now it's up, but the party is already over. Shiet.

Let's wait whenever the device reaches unavailable state, whether we
bring it up at that point or not.

Fixes-test: @restart_L2_only_lacp

https://bugzilla.redhat.com/show_bug.cgi?id=2092361
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1316
2022-08-02 15:06:35 +02:00
Dylan Van Assche
0f3eb6fabb
nm-device-bt: allow Bluetooth NAP type for complete-connection
Bluetooth NAP is besides Bluetooth PAN and DUN also supported by
NetworkManager. Add NAP to the supported Bluetooth types of
nm-device-bt.c

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1320
2022-08-01 09:37:42 +02:00
Lubomir Rintel
2b4b4193be bridge: fix reapply of non-bridge properties
Return was ommited in a branch that delegates settings check to a parent
class, resulting in a bridge property check applied incorrectly.

Fixes: 8e8fed433f ('bridge: add reapply support')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1318
2022-07-29 12:45:00 +02:00
Thomas Haller
5806db7f4e
glib-aux: replace nm_ip4_addr_is_localhost() by nm_utils_ip4_address_is_loopback()
This was duplicated.
2022-07-28 13:08:31 +02:00
Beniamino Galvani
0cd3ffa7e9 build: fix compilation
Fixes: dbf29c5450 ('platform: fix build with musl libc')
2022-07-27 19:51:56 +02:00
Beniamino Galvani
dbf29c5450 platform: fix build with musl libc
Don't mix <net/ethernet.h> and <linux/if_ether.h>.

Fixes the following build error with musl libc:

  In file included from /usr/include/net/ethernet.h:10,
                   from ../src/libnm-platform/nm-linux-platform.c:17:
  /usr/include/netinet/if_ether.h:115:8: error: redefinition of 'struct ethhdr'
    115 | struct ethhdr {
        |        ^~~~~~
  In file included from ../src/linux-headers/ethtool.h:19,
                   from ../src/libnm-std-aux/nm-linux-compat.h:22,
                   from ../src/libnm-platform/nm-linux-platform.c:10:
  /usr/include/linux/if_ether.h:169:8: note: originally defined here
    169 | struct ethhdr {
        |        ^~~~~~

Fixes: dc98ab807c ('platform: include "linux-headers" via "libnm-std-aux/nm-linux-compat.h"')
2022-07-27 18:46:01 +02:00
Thomas Haller
d3c9bb4666
platform: rename file "nmp-route-manager.[hc]" to "nmp-global-tracker.[hc]" 2022-07-26 12:45:55 +02:00
Thomas Haller
bf248e0400
platform: rename NMPRouteManager to NMPGlobalTracker
NetworkManager primarily manages interfaces in an independent fashion.
That means, whenever possible, we want to have a interface specific
view. In many cases, the underlying kernel API also supports that view.
For example, when configuring IP addresses or unicast routes, we do so
per interfaces and don't need a holistic view.

However, that is not always sufficient. For routing rules and certain
route types (blackhole, unreachable, etc), we need a system wide view
of all the objects in the network namespace.

Originally, NMPRulesManager was added to track routing rules. Then, it
was extended to also track certain route types, and the API was renamed to
NMPRouteManager.

This will also be used to track MPTCP addresses.

So rename again, to give it a general name that is suitable for what it
does. Still, the name is not great (suggestion welcome), but it should
cover the purpose of the API well enough. And it's the best I came
up with.

Rename.
2022-07-26 12:43:44 +02:00
Beniamino Galvani
2c70fef12e bridge: don't reset vlan filtering parameters on external connections
Fixes: 96fab7b462 ('all: add vlan-filtering and vlan-default-pvid bridge properties')

https://bugzilla.redhat.com/show_bug.cgi?id=2107647
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1305
2022-07-26 09:00:43 +02:00
Beniamino Galvani
e35f2494f8 supplicant: increase the PMK lifetime for WPA-EAP
By default, wpa_supplicant sets these parameters according to the
802.11 standard:

  dot11RSNAConfigPMKLifetime = 43200 seconds (12 hours)
  dot11RSNAConfigPMKReauthThreshold = 70%

With these, the supplicant triggers a new EAP authentication every 8
hours and 24 minutes. If the network uses one-time secrets, the
reauthentication fails and the supplicant disconnects. It doesn't seem
desirable that the client starts a reauthentication so early; bump the
lifetime to a week.

Currently, due to a bug, the new value is ignored by wpa_supplicant
when set via D-Bus. This patch needs the fix at [1], not yet merged.

[1] http://lists.infradead.org/pipermail/hostap/2022-July/040664.html

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1306
2022-07-26 08:48:45 +02:00
Lubomir Rintel
8e8fed433f bridge: add reapply support
We're able to reapply all properties in the bridge setting, aside from
"mac-address" which is used for matching the device.

https://bugzilla.redhat.com/show_bug.cgi?id=2092762
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1296
2022-07-25 13:42:50 +02:00
Lubomir Rintel
b2a6d9d2aa manager: recreate virtual devices on "nmcli net on"
"nmcli networking off" brings down all connections, resulting in virtual
devices disappearing:

  # nmcli c add type dummy ifname dummy0
  # nmcli networking off
  # nmcli networking on
  # nmcli d show dummy0
  Error: Device 'dummy0' not found.

Attempt to recreate them all upon bringing the networking back up.

Fixes-test: @ovs_cloned_mac_set_on_iface

https://bugzilla.redhat.com/show_bug.cgi?id=2093175
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1292
2022-07-25 13:41:22 +02:00
Lubomir Rintel
4d0227f3fa manager: make "nmcli net off" wait for deactivations
The current behavior of "nmcli networking off" is that it starts
disconnecting the devices, but doesn't wait for them to actually
come down.

That is not too helpful: the user never knows when the network is
actually disconnected.

Some users, notably the NetworkManager-CI test suite, seem to expect the
devices are all disconnected after the command finishes. Even worse,
it immediately proceeds activating the connections:

  @ovs_cloned_mac_set_on_iface
  ...
  * Execute "nmcli networking off && nmcli networking on"

This results in pure utter chaos. In particular, the slave connections
sometimes refuse to activate after "nmcli networking on", because the
master connections are still getting disconnected in response to
preceding "nmcli networking off".

Let's make Enable(FALSE) and Sleep(TRUE) block until none of the devices
are expected to go down.

Note that this makes those call also return when Enable(TRUE) and
Sleep(FALSE) is issued in meanwhile. Therefore a return from
Enable(FALSE) doesn't necessarily imply the networking is disabled.
This is a feature, not a bug -- the actual manager state is available in
the "state" property.

Fixes-test: @ovs_cloned_mac_set_on_iface

https://bugzilla.redhat.com/show_bug.cgi?id=2093175
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1292
2022-07-25 13:40:43 +02:00
Thomas Haller
5077018ff4
dhcp: fix EXTENDED DHCP event to accept lease for dhclient plugin
n-dhcp4 only supports calling ACCEPT during the GRANTED state.
Not during a EXTENDED event. So usually, we would not want
to call accept in that case.

And we didn't. During EXTENDED event, we would usually skip ACD (because
it's either not enabled or we already passed ACD for the current address).
In that case, in _nm_dhcp_client_notify() we hit the line

     if (client_event_type == NM_DHCP_CLIENT_EVENT_TYPE_BOUND && priv->l3cd_curr
         && nm_l3_config_data_get_num_addresses(priv->l3cd_curr, priv->config.addr_family) > 0)
         priv->l3cfg_notify.wait_dhcp_commit = TRUE;
     else
         priv->l3cfg_notify.wait_dhcp_commit = FALSE;

and would not set `wait_dhpc_commit`. That means, we never called _dhcp_client_accept().
For nettools, that doesn't really matter because calling ACCEPT during EXTENDED
is invalid anyway. However, for dhclient that is fatal because we wouldn't reply the
D-Bus request from nm-dhcp-helper. The helper times out after 60 seconds and dhclient
would misbehave.

We need to fix that by also calling _dhcp_client_accept() in the case when we don't
need to wait (the EXTENDED case).

However, previously _dhcp_client_accept() was rather peculiar and didn't like to be
called in an unexpected state. Relax that. Now, when calling accept in an unexpected
state, just do nothing and signal success. That frees the caller from the complexity
to understand when they must/must not call accept.

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

Fixes: 156d84217c ('dhcp/dhclient: implement accept/decline (ACD) for dhclient plugin')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1308
2022-07-22 13:13:27 +02:00
Beniamino Galvani
93372e8100 ovs: fail device only when it's activating
It doesn't make sense to fail a device that is not activating.

Especially, if the device was in state UNMANAGED, it would enter state
FAILED (and then DISCONNECTED) or ACTIVATED (when external or
assumed); both are wrong.

https://bugzilla.redhat.com/show_bug.cgi?id=2077950
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1302
2022-07-19 14:02:24 +02:00
Thomas Haller
3b58404712
platform: add NMPGenlFamilyType enum for generic netlink types
The genl types that we care about are well known. Add an enum
for them, so we can do a lookup by index.

To kernel, the corresponding names (like "wireguard") are also well
known. However, the family-id, that we need when using genl are
allocated dynamically. So we need to lookup the family-id, and by having
an enum for the genl type, we can do so generically.
2022-07-19 12:33:50 +02:00
Thomas Haller
5c84fe0db5
core: support "nm.debug" kernel command line to enable verbose logging
When NetworkManager runs in initrd, it can be cumbersome to enable debug logging.
Granted, when using dracut, the NetworkManager dracut module will honor "rd.debug".
However, a user may use NetworkManager in initrd without dracut. Then,
the only way to enable debug logging would be by changing
"NetworkManager.conf" and rebuild the initrd (or having some script in
place, that allows to more conveniently enable debug logging for
NetworkManager).

To make it easier for debugging, honor "nm.debug" on the kernel command
line.

Note that if "nm.debug" is set on the kernel command line, it always overrides
both the command line arguments and the configuration from NetworkManager.conf.
That is intentional. The only way to override that is by overriding the
kernel command line with a file "/run/NetworkManager/proc-cmdline".

https://bugzilla.redhat.com/show_bug.cgi?id=2102313
2022-07-18 15:00:04 +02:00
Thomas Haller
d4b7934997
core: support "/run/NetworkManager/proc-cmdline" to overwrite /proc/cmdline
We read /proc/cmdline for "match.kernel-command-line". But next we will
also honor "nm.debug" on the kernel command line, to enable debug
logging. For "nm.debug" it makes sense that it overwrites the debug
options from the command line and from "NetworkManager.conf". That
means, if you set "nm.debug", then verbose logging will be enabled. It
can only be turned off again at runtime (via D-Bus), otherwise, it's
hard to avoid.

It still can make sense to overrule this setting once again. Support
that, by honoring a file "/run/NetworkManager/proc-cmdline" to be used
instead of "/proc/cmdline".

This option is mainly for debugging and testing, but it might be useful
in production too, if you had "nm.debug" enabled during boot, but later
want to disable it until next reboot. Then you could do:

  sed 's/ *\<nm\.debug\> */ /g' /proc/cmdline > /run/NetworkManager/proc-cmdline
  nmcli general logging level DEFAULT domains DEFAULT
2022-07-18 14:58:00 +02:00
Beniamino Galvani
8c17760f62 ppp,wwan: remove explicit initialization of DNS priority
It's no longer necessary, as modem devices get the priority from the
ipmanual configuration created from the profile.
2022-07-18 07:48:13 +02:00
Beniamino Galvani
0717589972 wwan: enable manual IP configuration
Before 1.36, manual addresses from the profile were assigned to the
interface; restore that behavior.

The manual IP configuration also contains the DNS priority from the
profile; so this change ensures that the merged l3cd has a DNS
priority and that dynamically discovered DNS servers are not ignored
by the DNS manager.

Fixes: 58287cbcc0 ('core: rework IP configuration in NetworkManager using layer 3 configuration')
2022-07-18 07:48:12 +02:00
Beniamino Galvani
2ae8433520 device: add "is_manual" argument to ready_for_ip_config() device method
Some device types might want to run manual ip configuration while
skipping other methods.
2022-07-18 07:48:12 +02:00
Thomas Haller
a9818692b8
policy: downgrade verbosity of hostname change logging message
This message seems not useful at <info> level. Downgrade logging level.
2022-07-15 09:22:56 +02:00
Fernando Fernandez Mancera
4655b7c308 veth: fix veth activation on booting
When creating one profile for each veth during activation the creation
of the veth could fail. When the link for the first profile is created
the link for the peer is generated in kernel. Therefore when trying to
activate the second profile it will fail because the link already
exists. NetworkManager must check if the link already exists and
corresponds to the same veth, if so, it should skip the link creation.

https://bugzilla.redhat.com/show_bug.cgi?id=2036023
https://bugzilla.redhat.com/show_bug.cgi?id=2105956
2022-07-12 13:34:18 +02:00
Beniamino Galvani
1784fc9fa1 core: update DNS when the device enters IP_CONFIG state
Update DNS information when the device enters the IP_CONFIG state. In
this way, when dispatcher events "dhcp4-change,dhcp6-change" are
emitted resolv.conf already contains the information received from
the DHCP lease.

https://bugzilla.redhat.com/show_bug.cgi?id=2100456
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1283
2022-07-11 15:51:37 +02:00
Thomas Haller
d8a4b3bec2
all: reformat with clang-format (clang-tools-extra-14.0.0-1.fc36) and update gitlab-ci to f36 2022-07-06 11:06:53 +02:00
Slava Monich
8c5356cec6 supplicant: fix a memory leak
==30980== 8 bytes in 1 blocks are definitely lost in loss record 1,117 of 6,137
==30980==    at 0x4841C38: malloc (vg_replace_malloc.c:309)
==30980==    by 0x4A246C7: g_malloc (gmem.c:106)
==30980==    by 0x4A4A4BB: g_variant_get_strv (gvariant.c:1607)
==30980==    by 0x4A4CA73: g_variant_valist_get_nnp (gvariant.c:4901)
==30980==    by 0x4A4CA73: g_variant_valist_get_leaf (gvariant.c:5058)
==30980==    by 0x4A4CA73: g_variant_valist_get (gvariant.c:5239)
==30980==    by 0x4A4D11D: g_variant_get_va (gvariant.c:5502)
==30980==    by 0x4A4D1BD: g_variant_lookup (gvariant.c:989)
==30980==    by 0xE9389: parse_capabilities (nm-supplicant-interface.c:1241)
==30980==    by 0xEBF99: _properties_changed_main (nm-supplicant-interface.c:1941)
==30980==    by 0xEF549: _properties_changed (nm-supplicant-interface.c:2867)
==30980==    by 0xEF7ED: _get_all_main_cb (nm-supplicant-interface.c:2972)
==30980==    by 0x262057: _nm_dbus_connection_call_default_cb (nm-dbus-aux.c:70)
==30980==    by 0x48DB6A3: g_task_return_now (gtask.c:1215)
==30980==    by 0x48DBF43: g_task_return.part.3 (gtask.c:1285)
==30980==    by 0x4918885: g_dbus_connection_call_done (gdbusconnection.c:5765)
==30980==    by 0x48DB6A3: g_task_return_now (gtask.c:1215)
==30980==    by 0x48DB6D7: complete_in_idle_cb (gtask.c:1229)
==30980==    by 0x4A20981: g_main_dispatch (gmain.c:3325)
==30980==    by 0x4A20981: g_main_context_dispatch (gmain.c:4016)
==30980==    by 0x4A20BEF: g_main_context_iterate.isra.23 (gmain.c:4092)
==30980==    by 0x4A20E33: g_main_loop_run (gmain.c:4290)
==30980==    by 0x2C5C9: main (main.c:509)

Fixes: cd1e0193ab ('supplicant: add BIP interface capability')
2022-07-04 15:39:40 +03:00