Commit graph

14918 commits

Author SHA1 Message Date
Lubomir Rintel
3bc14e3e88 merge: branch 'lr/pc'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1012
2021-11-15 09:28:46 +01:00
Thomas Haller
04b4982d3c
libnm: refactor some NMSetting to use direct properties
"direct" properties are the latest preferred way to implement GObject
base properties. That way, the property meta data tracks the
"direct_type" and the offset where to find the data in the struct.

That way, we can automatically

- initialize the default values
- free during finalize
- implement get_property()/set_property()

Also, the other settings operations (compare, to/from D-Bus) are
implemented more efficiently and don't need to go through
g_object_get_property()/GValue API.
2021-11-08 22:23:16 +01:00
Thomas Haller
989a6911ba
libnm: always finalize direct properties in NMSetting base class
Certain properties need to release memory when destroying the NMSetting.
For "direct" properties, we have all the information we need to do that
generically in the NMSetting base class. In practice, this only concerns
string properties.

See _finalize_direct() in "nm-setting.c".

However, if the NMSetting base class takes care of freeing the strings,
then the subclasses must not also unref the variable (to avoid double free).
Previously, subclasses had to opt-in for the base class to indicate that
they are fine with that.

Now, let the base class always handle it. We only need to make sure that
classes that implement direct string properties don't also try to free
the values during destruction.
2021-11-04 20:25:19 +01:00
Thomas Haller
2aa1fdd2bf
libnm: add direct property type "bytes" 2021-11-04 20:25:19 +01:00
Thomas Haller
37967ad717
libnm: add direct property type "enum" 2021-11-04 20:25:19 +01:00
Thomas Haller
1059b60873
libnm: add direct property type "uint64" 2021-11-04 20:25:19 +01:00
Thomas Haller
093f434cd0
libnm: add direct property type "flags"
"flags" are a g_param_spec_flags() and correspond to G_TYPE_FLAGS type.
They are internally stored as guint, and exported on D-Bus as "u" (32 bit
integer).
2021-11-04 20:25:19 +01:00
Thomas Haller
aeb2426e88
libnm: change default value for "dcb.app-fcoe-mode" property
String properties in libnm's NMSetting really should have NULL as a
default value. The only property that didn't, was "dcb.app-fcoe-mode".

Change the default so that it is also NULL.

Changing a default value is an API change, but in this case probably no
issue. For one, DCB is little used. But also, it's not clear who would
care and notice the change. Also, because previously verify() would reject
a NULL value as invalid. That means, there are no existing, valid profiles
that have this value set to NULL.  We just make NULL the default, and
define that it means the same as "fabric".

Note that when we convert integer properties to D-Bus/GVariant, we often
omit the default value. For string properties, they are serialized as
"s" variant type. As such, NULL cannot be expressed as "s" type, so we
represent NULL by omitting the property. That makes especially sense if
the default value is also NULL. Otherwise, it's rather odd. We change
that, and we will now always express non-NULL value on D-Bus and let
NULL be encoded by omitting the property.
2021-11-04 20:25:18 +01:00
Thomas Haller
38d81cfa89
ifcfg: always read/write KEY_DCB_APP_FCOE_MODE key
The settings plugin is not supposed to normalize the profile. It should
read/write what is, and let NMConnection handle what is valid and what
needs normalization.
2021-11-04 20:25:18 +01:00
Thomas Haller
d805b9ae51
libnm/tests: always check expected default value for string properties in test_setting_metadata() 2021-11-04 20:25:18 +01:00
Thomas Haller
572ce7b7a7
glib-aux/trivial: rename GBytes helper API
Give a consistent name.

A bit odd are now the names nm_g_bytes_hash() and nm_g_bytes_equal()
as they go together with nm_pg_bytes_hash()/nm_pg_bytes_equal().
But here the problem is more with the naming of "nm_p*_{equal,hash}()"
functions, which probably should be renamed to "nm_*_ptr_{equal,hash}()".
2021-11-04 20:25:18 +01:00
Thomas Haller
9876623363
glib-aux: add nm_g_bytes_new_from_variant_ay() helper 2021-11-04 20:25:18 +01:00
Thomas Haller
974bf61428
glib-aux: make GBytes parameter const for read-only helper functions 2021-11-04 20:25:18 +01:00
Thomas Haller
f730edfcb1
glib-aux: add nm_g_variant_maybe_singleton_i() helper 2021-11-04 20:25:18 +01:00
Thomas Haller
b450221195
glib-aux: fix assertion in nm_strdup_reset_take()
Fixes: c4d981959e ('shared: add nm_utils_strdup_reset_take() helper')
2021-11-04 20:25:18 +01:00
Thomas Haller
ea7ce48c00
trivial: fix code style
Fixes: de6d069dce ('ndisc: send router solicitations before expiry')
2021-11-04 20:23:07 +01:00
Lubomir Rintel
065fa15a0a libnm.pc: plugindir & configdir
Carry them over from NetworkManager.pc, they're potentially useful.
2021-11-03 12:19:36 +01:00
Harald van Dijk
58bfcffd59 core: support linking with LLD 13
LLD 13 adds -z start-stop-gc and makes it the default, resulting in:

    CCLD     src/core/NetworkManager-all-sym
  ld.lld: error: undefined symbol: __stop_connection_defaults
  >>> referenced by nm-config.c:0 (src/core/nm-config.c:0)
  >>>               libNetworkManager_la-nm-config.o:(read_config) in archive src/core/.libs/libNetworkManager.a
  >>> referenced by nm-config-data.c:1598 (src/core/nm-config-data.c:1598)
  >>>               libNetworkManager_la-nm-config-data.o:(nm_config_data_get_connection_default) in archive src/core/.libs/libNetworkManager.a
  >>> referenced by nm-config-data.c:0 (src/core/nm-config-data.c:0)
  >>>               libNetworkManager_la-nm-config-data.o:(nm_config_data_get_connection_default) in archive src/core/.libs/libNetworkManager.a

  ld.lld: error: undefined symbol: __start_connection_defaults
  >>> referenced by nm-config.c:0 (src/core/nm-config.c:0)
  >>>               libNetworkManager_la-nm-config.o:(read_config) in archive src/core/.libs/libNetworkManager.a
  >>> referenced by nm-config.c:0 (src/core/nm-config.c:0)
  >>>               libNetworkManager_la-nm-config.o:(read_config) in archive src/core/.libs/libNetworkManager.a
  >>> referenced by nm-config.c:0 (src/core/nm-config.c:0)
  >>>               libNetworkManager_la-nm-config.o:(read_config) in archive src/core/.libs/libNetworkManager.a
  >>> referenced 2 more times
  clang: error: linker command failed with exit code 1 (use -v to see invocation)

Add __attribute__((__retain__)) to prevent GC of the connection
defaults.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1008
2021-11-02 12:42:51 +01:00
Lubomir Rintel
73ac6dfb8a policy: send ip configs to the DNS manager earlier
Don't wait until the device is ACTIVATED -- pass them as soon as they're
valid. They should be applied at the moment the device enters ACTIVATED
state.

https://bugzilla.redhat.com/show_bug.cgi?id=2006677
2021-11-02 12:42:51 +01:00
Lubomir Rintel
5ec8ee47b4 Revert "core: make ActiveConnection emit StateChanged a bit later"
Thomas thinks this is a bad idea and probably is right:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1000#note_1122853

This reverts commit 4ae846b9c6.
2021-11-02 12:42:51 +01:00
Lubomir Rintel
c6dc7a7ea7 Revert "core: make Device emit StateChanged a bit later"
Thomas thinks this is a bad idea and probably is right:
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1000#note_1122853

This reverts commit c75b7dd893.
2021-11-02 12:42:51 +01:00
Beniamino Galvani
28770eb394 initrd: handle ip=dhcp,dhcp6 specially
With "ip=dhcp,dhcp6" the legacy dracut module does first DHCPv4 and
then IPv6 autoconf (even if DHCPv4 succeeded) [1]. In this way, there
is the guarantee that an address family is always configured if the
network supports it.

Currently "ip=dhcp,dhcp6" is treated a bit differently by NM, which
generates a connection with only ipv4.required-timeout=20s. Therefore
it's possible that NM in initrd quits (or signals startup-complete)
without an IPv6 even if the network is configured for IPv6.

Make NM's behavior similar to the legacy module by also setting an
ipv6.required-timeout for "ip=dhcp,dhcp6".

Note that if the command line contains "rd.neednet=1" without an "ip="
argument, we still generate a default connection with IPv4 preferred
over IPv6 (i.e. only ipv4.required-timeout set). That's similar to
what the legacy module does [2]. See [3] for a description of
different scenarios for "rd.neednet=1".

[1] https://github.com/dracutdevs/dracut/blob/055/modules.d/35network-legacy/ifup.sh#L459-L484
[2] https://github.com/dracutdevs/dracut/blob/055/modules.d/35network-legacy/ifup.sh#L529-L537
[3] https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/729

https://bugzilla.redhat.com/show_bug.cgi?id=1961666
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/994
2021-11-02 11:02:38 +01:00
Jonas Kümmerlin
de6d069dce ndisc: send router solicitations before expiry
There are routers out in the wild which won't send unsolicited
router advertisements.

In the past, these setups still worked because NetworkManager
used to send router solicitations whenever the half-life of
dns servers and dns domains expired, but this has been changed
in commit 03c6d8280c ('ndisc: don't call solicit_routers()
from clean_dns_*() functions').

We will now schedule router solicitation to be started again
about one minute before advertised entities expire.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/997
2021-11-02 10:32:14 +01:00
Thomas Haller
db53e5f3cd nmcli: fix import WireGuard profile with DNS domain and address family disabled
In NetworkManager, a profile cannot have "ipvx.dns" or "ipvx.dns-search"
while the corresponding IP method is disabled. Together with the oddity
that in NetworkManager DNS settings are separate per IPv4 and IPv6, this
causes problems:

  $ cat wg0.conf
  [Interface]
  PrivateKey = CBXpiLxQ98TLISJ2cypEFtQb/djzYzENyy0jzhWa/UA=
  Address = 192.168.1.100
  DNS = 10.11.12.13, foobar.de

  [Peer]
  PublicKey = Wus1sBzZiQkyxr6ZitUFNvfYD7KJkwTsWlcxvJ/4SHI=
  Endpoint = 1.2.3.4:51827
  AllowedIPs = 0.0.0.0/0

  $ nmcli connection import type wireguard file wg0.conf
  Error: failed to import 'wg0.conf': Failed to create WireGuard connection: ipv6.dns-search: this property is not allowed for 'method=disabled'.

Fixes: 3ab082ed96 ('cli: support dns-search for import of WireGuard profiles')
2021-11-02 09:15:01 +00:00
Beniamino Galvani
d8186b1253 core: better handle sd-resolved errors when resolving hostnames
If NM tries to resolve a link-local address, systemd-resolved returns
error "org.freedesktop.resolve1.NoNameServers" because those addresses
can only be resolved via other protocols like LLMNR or mDNS.

Previously NM would fall back to spawning the helper, which would ask
again to systemd-resolved via /etc/resolv.conf. In this way, a
synthetic result (or one obtained not from DNS) would be returned.

We must avoid non-DNS results. When systemd-resolved returns an error
that is not a D-Bus one (as MethodNotFound) but is a
"org.fd.resolve1.*" [1], we can assume that systemd-resolved is
running properly and we shall never fall back to spawning the helper.

[1] https://www.freedesktop.org/wiki/Software/systemd/resolved/#commonerrors

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/833
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1006
2021-10-29 16:43:27 +02:00
Lubomir Rintel
4ae846b9c6 core: make ActiveConnection emit StateChanged a bit later
We need to make sure StateChanged goes on the D-Bus only after the
policy is done dealing with the state change internally.

This is done so that we can be sure the DNS changes are committed at the
time "nmcli c up" returns.

https://bugzilla.redhat.com/show_bug.cgi?id=2006677
2021-10-28 13:21:15 +02:00
Lubomir Rintel
c75b7dd893 core: make Device emit StateChanged a bit later
We need to make sure StateChanged goes on the D-Bus only after the
policy is done dealing with the state change internally.

This is done so that we can be sure the DNS changes are committed at the
time "nmcli c up" returns.

https://bugzilla.redhat.com/show_bug.cgi?id=2006677
2021-10-27 15:53:16 +02:00
Fernando Fernandez Mancera
ff9b64c923 core: reload config for active devices
When NetworkManager is reloaded the config from active devices is not
being reloaded properly.

Related: https://bugzilla.redhat.com/1852445

Fixes: 121c58f0c4 ('core: set number of SR-IOV VFs asynchronously')

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2021-10-18 09:53:15 +02:00
Thomas Haller
30fa9949e5
l3cfg: fix "maybe-uninitialized" warning in _l3_commit_ndisc_params() 2021-10-17 14:59:31 +02:00
Thomas Haller
5c48c5d5d6
l3cfg: set IPv6 sysctls during NML3Cfg commit 2021-10-17 10:41:32 +02:00
Thomas Haller
4b270448e4
l3cfg: add addr_family parameter to nm_l3cfg_check_ready()
We have "ipv[46].may-fail", which are per-address family. This works
together with nm_l3cfg_check_ready(), where we check whether an
NML3ConfigData is ready. We need to have that check also per-address
family.
2021-10-17 10:41:31 +02:00
Robin Ebert
a2f6cde3eb
core: Save whether SetLinkDNSOverTLS is supported 2021-10-15 10:01:13 +02:00
Robin Ebert
b652202829
ifcfg-rh: add support for connection.dns-over-tls 2021-10-15 10:00:53 +02:00
Robin Ebert
879e4f3546
cli: add support for connection.dns-over-tls 2021-10-15 10:00:46 +02:00
Robin Ebert
1a98cf1669
core: add support for connection.dns-over-tls 2021-10-15 10:00:31 +02:00
Robin Ebert
5582f658cd
libnm-core: Add connection.dns-over-tls property 2021-10-15 10:00:20 +02:00
Fernando Fernandez Mancera
c50a03f2f1 libnm-core: improve SR-IOV VF vlan support documentation
Currently kernel only support one VLAN per VF. This must be specified in
the methods documentation.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2021-10-14 19:09:00 +02:00
Thomas Haller
f146d38a92
glib-aux: add nm_auto_g_object_thaw_notify and related helpers 2021-10-13 15:36:43 +02:00
Beniamino Galvani
21782d1fdb core: fix signal emission for device ports
The MASTER property must be emitted on the port; while PORTS and
SLAVES on the controller.

Fixes: 9d2ed74e74 ('core: introduce device::ports property')
2021-10-13 09:38:41 +02:00
Thomas Haller
e81c2baf70
wwan: drop workaround to use GTE DNS servers for PPP
Drop a workaround added by commit a8ca7f537d ('ppp: work around PPP
bug that returns bogus nameservers'), in 2009.

Also drop the second workaround (`if (!num ...`), which was introduced
by commit 294a5e3153 ('modem: substitute known-good nameservers if PPP
doesn't return any (lp:434477)').

I hope this doesn't break something, but it really doesn't seem right in
2021.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/988
2021-10-12 13:24:26 +02:00
Thomas Haller
07d570766f
l3cfg: various fixes and improvments (e.g. add pre-commit hook)
- add "pre-commit" signal.

- fix assertion in nm_l3_config_data_get_ip6_privacy().

- set IPv6 privacy in _init_from_connection_ip() from profile.

- fix leaking "os_zombie_lst" in _obj_state_data_free().

- remove wrong assertion about VRF.

- fix _routes_temporary_not_available_update() to honor only the
  requested object type. Otherwise, we always prune unrelated objects
  too.
2021-10-12 09:37:02 +02:00
Thomas Haller
8b575f7553
l3cfg: add nm_l3cfg_commit_type_clear() helper 2021-10-12 09:18:15 +02:00
Thomas Haller
841c45a4f5
libnm: fix crash on failure of nm_vpn_plugin_info_new_from_file()
nm_vpn_plugin_info_new_from_file() may fail as NMVpnPlugin is an
GInitable. As such, the destructor must handle the case where the
instance was only partly initialized.

  #0  g_logv (log_domain=0x7f7144703071 "GLib", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=<optimized out>) at ../glib/gmessages.c:1413
  #1  0x00007f71446b3903 in g_log (log_domain=<optimized out>, log_level=<optimized out>, format=<optimized out>) at ../glib/gmessages.c:1451
  #2  0x000056455b8e58d0 in finalize (object=0x7f7128008180 [NMVpnPluginInfo]) at src/libnm-core-impl/nm-vpn-plugin-info.c:1280
  #3  0x00007f71447b8b18 in g_object_unref (_object=<optimized out>) at ../gobject/gobject.c:3524
  #4  g_object_unref (_object=0x7f7128008180) at ../gobject/gobject.c:3416
  #5  0x00007f714486bc09 in g_initable_new_valist
      (object_type=<optimized out>, first_property_name=0x56455b925c20 "filename", var_args=var_args@entry=0x7ffe702b1140, cancellable=cancellable@entry=0x0, error=error@entry=0x7ffe702b1248) at ../gio/ginitable.c:250
  #6  0x00007f714486bcad in g_initable_new
      (object_type=<optimized out>, cancellable=cancellable@entry=0x0, error=error@entry=0x7ffe702b1248, first_property_name=first_property_name@entry=0x56455b925c20 "filename")
      at ../gio/ginitable.c:162
  #7  0x000056455b8e69f6 in nm_vpn_plugin_info_new_from_file
      (filename=filename@entry=0x56455c951ec0 "/opt/test/lib/NetworkManager/VPN/nm-openvpn-service.name", error=error@entry=0x7ffe702b1248) at src/libnm-core-impl/nm-vpn-plugin-info.c:1221
  #8  0x000056455b88ce9a in vpn_dir_changed
      (monitor=monitor@entry=0x7f7128007860 [GInotifyFileMonitor], file=file@entry=0x7f712c005600, other_file=other_file@entry=0x0, event_type=<optimized out>, user_data=<optimized out>)
      at src/core/vpn/nm-vpn-manager.c:182
  #9  0x00007f71448697a3 in _g_cclosure_marshal_VOID__OBJECT_OBJECT_ENUMv
      (closure=0x56455c7e4250, return_value=<optimized out>, instance=<optimized out>, args=<optimized out>, marshal_data=<optimized out>, n_params=<optimized out>, param_types=0x56455c7355a0) at ../gio/gmarshal-internal.c:1380

Fixes: d6226bd987 ('libnm: add NMVpnPluginInfo class')
2021-10-12 09:18:15 +02:00
Thomas Haller
e0e58fd5bc
dns: fix format string for printing size_t in send_updates()
This in particular breaks i386 builds.

Fixes: 6f663b8f8e ('dns: log about what NMDnsSystemdResolved is doing')
2021-10-11 20:44:52 +02:00
Thomas Haller
544c223557
l3cfg: keep NML3Cfg alive while having a commit scheduled
We might want to schedule a last update and unref the NML3Cfg instance.
We need to make sure that the last update gets processed. Do that by
taking a reference while an idle source is pending.
2021-10-11 13:54:29 +02:00
Thomas Haller
7d33540316
glib-aux: add nm_g_variant_tuple_get_u() helper 2021-10-11 13:54:29 +02:00
Thomas Haller
3b08e27f08
glib-aux: add nm_ip_addr_set_from_variant() helper 2021-10-11 13:54:29 +02:00
Thomas Haller
2675e18f13
platform: return non-const pointer from nm_platform_ip_address_get_peer_address()
This is an accessor to the peer_address field. It should work
both for const and non-const arguments.

Similar like strchr() casts the constness away, we also need to
do that here.
2021-10-11 13:49:28 +02:00
Fernando Fernandez Mancera
74dfc86aa4 libnm: introduce nm_device_get_ports() to NMDevice
This patch is introducing a "ports" property to NMDevice. In addition it
is introducing nm_device_get_ports() and deprecating
nm_device_bond_get_slaves(), nm_device_bridge_get_slaves(),
nm_device_ovs_bridge_get_slaves(), nm_device_ovs_interface_get_slaves()
and nm_device_team_get_slaves().

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2021-10-11 09:38:24 +02:00
Fernando Fernandez Mancera
cf867e8ff5 dbus-metadata: make 'extra' available from NML_DBUS_META_PROPERTY_INIT_FCN()
Currently a NML_DBUS_META_PROPERTY_INIT_FCN() property does not have
'extra' field available. In order to be able to call
'nml_dbus_property_ao_notify()' from the callback, the 'extra' field
must be available.

The patch is also dropping 'use_notify_update_prop' field as it only
existed to differentiate the union.

Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2021-10-11 09:35:15 +02:00