Commit graph

1786 commits

Author SHA1 Message Date
Eliot Lear
295e6678dd dhcp: add support for MUD URL (RFC 8520)
[thaller@redhat.com: rewritten commit message]

https://tools.ietf.org/html/rfc8520
https://blog.apnic.net/2019/05/14/protecting-the-internet-of-things-with-mud/

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/463
2020-04-24 10:07:38 +02:00
Thomas Haller
411255d51f cli: unset "ipv[46].never-default" when setting "ipv[46].gateway"
Since commit c1907a218a ('libnm-core: remove gateway when
never-default=yes in NMSettingIPConfig'), the gateway gets normalized
away when the profile has never-default set.

That means,

  $ nmcli connection modify "$PROFILE" ipv4.never-default yes ipv4.gateway 192.168.77.1

does not set the gateway. Likewise, if your profile has already never-default
enabled,

  $ nmcli connection modify "$PROFILE" ipv4.gateway 192.168.77.1

will have no effect. That is confusing and undesirable.

Note that we don't adjust the GObject property setter for "gateway" to clear
never-default. I feel, setting one property in libnm should preferably
not unset another (there are exceptions to the rule, like for team
properties). However, for nmcli it's clear in which order properties
are set, so this change is right for the client tool.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/475
2020-04-22 21:04:42 +02:00
Thomas Haller
115291a46f wireguard: don't let explicit gateway override WireGuard's peer route
The profile's "ipv4.gateway" and "ipv6.gateway" has only one real
purpose: to define the next hop of a static default route.

Usually, when specifying a gateway in this way, the default route from
other addressing methods (like DHCPv4 or IPv6 autoconf) gets ignored.

If you have a WireGuard peer with "AllowedIPs=0.0.0.0/0" and
"wireguard.peer-routes" enabled, NetworkManager would automatically add
a route to the peer. Previously, if the user also set a gateway, that
route was suppressed.

That doesn't feel right. Note that configuring a gateway on a WireGuard
profile is likely to be wrong to begin with. At least, unless you take
otherwise care to avoid routing loops. If you take care, setting a
gateway may work, but it would feel clearer to instead just add an
explicit /0 manual route instead.

Also, note that usually you don't need a gateway anyway. WireGuard is a
Layer 3 (IP) tunnel, where the next hop is alway just the other side of
the tunnel. The next hop has little effect on the routes that you
configure on a WireGuard interface. What however matters is whether a
default route is present or not.

Also, an explicit gateway probably works badly with "ipv[46].ip4-auto-default-route",
because in that case the automatism should add a /0 peer-route route in a
separate routing table. The explicit gateway interferes with that too.

Nonetheless, without this patch it's not obvious why the /0 peer
route gets suppressed when a gateway is set. Don't allow for that, and
always add the peer-route.

Probably the profile's gateway setting is still wrong and causes the
profile not to work. But at least, you see all routes configured, and
it's clearer where the (wrong) default route to the gateway comes from.
2020-04-22 11:36:51 +02:00
Thomas Haller
5da82ee3ea wireguard: suppress automatic "wireguard.peer-routes" for default routes if "ipv[46].never-default" is enabled
Enabling both peer-routes and never-default conflicts with having
AllowedIPs set to a default route. Let never-default win.
2020-04-22 11:05:39 +02:00
Thomas Haller
61a97f8b0f libnm: cleanup _nm_utils_dns_option_validate()
Avoid unnecessary string copies. Most option don't have a delimiter
and numerical argument, and there is no need to clone the string.
2020-04-20 15:54:43 +02:00
Thomas Haller
5e47fb630b dns: add trust-ad DNS option only if all contributing settings agree
https://bugzilla.redhat.com/show_bug.cgi?id=1825285
2020-04-20 15:54:43 +02:00
Thomas Haller
e261e941fd libnm: document supported "ipv[46].dns-option" values 2020-04-20 15:54:43 +02:00
Beniamino Galvani
40b2cf7a0c libnm-core: add 'no-reload' and 'trust-ad' resolv.conf options
https://sourceware.org/git/?p=glibc.git;a=blob;f=resolv/res_init.c;h=95dce098aa7ec80f2e36f5c25022641d65e1d5e5;hb=9ea3686266dca3f004ba874745a4087a89682617#l681

https://bugzilla.redhat.com/show_bug.cgi?id=1825285
2020-04-20 11:28:29 +02:00
Thomas Haller
12c2aacea7 keyfile: cleanup mac_address_parser() 2020-04-15 11:25:23 +02:00
Beniamino Galvani
f2756b930e release: bump version to 1.25.0 (development) 2020-04-10 18:08:10 +02:00
Antonio Cardace
2a5d9eb60b
bond: small cleanups
* Use an enum instead of a string, is faster for comparisons.
* Add debug assertions
* Have NMBondMode enum correspond to Kernel numbering
2020-04-10 17:46:22 +02:00
Antonio Cardace
d73a98a3e8
nm-setting-bond: also accept bond mode as a numerical id
That corresponds to how the Kernel numbers the different modes.
2020-04-10 17:46:18 +02:00
Thomas Haller
1ef894f489 libnm: don't use local variable in _bond_get_option_or_default()
Brevity is the Soul of Wit.
2020-04-10 08:45:00 +02:00
Antonio Cardace
ad052c3d67
nm-setting-bridge: add 'multicast-querier' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
a685cce70a
nm-setting-bridge: add 'multicast-query-use-ifaddr' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
e01d3b4c2b
nm-setting-bridge: add 'multicast-router' bridge option
Also add related unit test.

https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
bd30491f42
nm-setting-bridge: add 'vlan-stats-enabled' bridge option
https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
f5352ff656
nm-setting-bridge: add 'vlan-protocol' bridge option
Also add related unit test.

https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
93e38cbe56
nm-setting-bridge: add 'group-address' bridge option
Also add related unit test.

https://bugzilla.redhat.com/show_bug.cgi?id=1755768
2020-04-06 09:56:11 +02:00
Antonio Cardace
d5538efb31
nm-setting-bridge: hide GObject structs from public API and embed private data
Hide the object and class structures from public API.

This is an API and ABI break, but of something that is very likely
unused.

This is mainly done to embed the private structure in the object itself.
This has benefits for performance and debugability.
2020-04-06 09:56:07 +02:00
Thomas Haller
5cc7abd7a4 shared: add nm_utils_escaped_tokens_options_*() API
This will be used for splitting and escaping option parameters in
nmcli (vpn.data).
2020-04-04 19:51:34 +02:00
Thomas Haller
7842da1606 libnm: convert vpn-secrets to D-Bus in stable order
We should generate the GVariant in a stable manner. That implies
to sort the keys first.

Also, don't use the NM_SETTING_VPN_SECRETS getter, which first needs
to clone all secrets.
2020-04-04 19:51:34 +02:00
Thomas Haller
3d9d2ad651 libnm: avoid cloning secrets during vpn_secrets_from_dbus()
When we use _nm_utils_strdict_from_dbus(), we clone the secrets, but don't use
nm_free_secret() for freeing them.

And in fact, we clone the setings twice. It't really not too nice. Implement
this without the property setter.
2020-04-04 19:51:34 +02:00
Thomas Haller
3bca926d20 libnm: refactor property setters of data and secrets in NMSettingVpn
Don't use _nm_utils_copy_strdict().

On a minor note, that function will always allocate a GHashTable, even if
it only contains "" as only key. Later we would throw that out again,
so it was unnecessary.

Worse, using _nm_utils_copy_strdict() does not use nm_free_secrets as
destroy function. While it's in general difficult to clear all places
in memory where we copy the secrets around, we can easily avoid that.

Also skip over %NULL keys and values. It probably would be a bug passing
such arguments to the property. Better ignore them and not crash.
2020-04-04 19:51:34 +02:00
Thomas Haller
117cbd1894 libnm: allow setting empty vpn.secrets item
Like for data, now also allow empty secrets to be added to the VPN
setting.

For one, this avoids an assertion failure, where keyfile reader wouldn't
check whether a secret key is set to the empty word.

For data, it's more clear that we want to allow setting empty data
values. VPN settings are only interpreted by the VPN plugin, so libnm
and the daemon shouldn't prevent empty settings. It can be useful to
distinguish between unset (NULL) and empty values.

For secrets, it's less clear that empty secrets shall be allowed. I
think it should. Of course, the empty secret likely isn't a correct
nor valid secret. But libnm cannot validate the secrets anyway. It's
up to the VPN plugin to handle this in any way they see fit.

Also, already before, the user could set NM_SETTING_VPN_SECRETS to
a string dictionary with empty passwords. So, the API didn't fully
prevent that. Only certain API wouldn't play along.
2020-04-04 19:51:34 +02:00
Thomas Haller
64da830b07 libnm: allow setting empty vpn.data item
Until now, nm_setting_vpn_add_data_item() would reject empty data values.
This leads for example to an assertion failure, if you write a keyfile
that assigns an empty value to a key. Keyfile reader would not check that
the value is non-empty before calling nm_setting_vpn_add_data_item().

Anyway, I think we should not require having non-empty data elements. It's
an unnecessary and sometimes harmful restriction. NetworkManager doesn't understand
not care about the content of the vpn data. That is up the VPN plugins. Sometimes
and empty value may be desirable.

Also, the NM_SETTING_VPN_DATA property setter wouldn't filter out empty
values either. So it was always possible to use some libnm API to set data
with empty values. The restriction in nm_setting_vpn_add_data_item() was
inconsistent.
2020-04-04 19:51:34 +02:00
Thomas Haller
8280c85fac libnm: ensure we have no empty secret keys in NMSettingVpn
Also drop the g_warn_if_fail() from update_secret_dict(). We
may get the variant from D-Bus, so avoiding this assertion (g_warn*() is
an assertion!) would require us to prevalidate the variant.
That would be very cumbersome, and we would probably not want to
handle that as an error and silently ignore them anyway. Just shut
up.
2020-04-04 19:51:34 +02:00
Thomas Haller
f51cf10ccc libnm: ensure we have no empty data keys in NMSettingVpn
Ensure that the data hash doesn't contain keys with empty key-name.
It just doesn't make sense, and will lead to potential problems later,
if we would allow this to happen.

For example, keyfile writer may naively try to set all keys, without
checking for empty keys. That may lead to assertion failures or worse,
later on. Don't allow that.

Also, assert against non-empty keys in nm_setting_vpn_get_data_item()
and nm_setting_vpn_remove_data_item(). This stricter handling is a
change in behavior, however it would have always been a bug trying to
refer to empty key names. So, this assertion will only help to find
those bugs.
2020-04-04 19:51:34 +02:00
Thomas Haller
05756ddc3a libnm: allocate "secrets" hash for NMSettingVpn lazily 2020-04-04 19:51:34 +02:00
Thomas Haller
7047fd212e libnm: allocate "data" hash for NMSettingVpn lazily
We always initialized priv->data in nm_setting_vpn_init(), but usually
soon after this hash would be replaced by NM_SETTING_VPN_DATA property
setter.

Avoid that. Allow for priv->data to be %NULL, which of course has the
meaning that no keys are set.
2020-04-04 19:51:34 +02:00
Thomas Haller
68328e0f21 libnm: fail get_secret_flags(),set_secret_flags() for empty secret name in NMSettingVpn 2020-04-04 19:51:34 +02:00
Thomas Haller
40e2603d4c libnm: make NMSettingVpn's foreach_item_helper() robust against changes
When we invoke the user's callback, be more robust about the user
modifying or unreferencing the NMSettingVpn, while iterating.

While it would be odd to modify the NMSettingVpn from inside the foreach
callback, we should behave consistently and sensibly.

That means, to ensure that the NMSettingVpn instance stays alive all
the time, that we don't crash, and that we always iterate over the
previously determined, planned list of keys.

Also, avoid some unnecessary string copies, like the clone of the first key.
2020-04-04 19:51:34 +02:00
Thomas Haller
c9bfdc2f75 libnm: use streq() instead of strcmp() for NMSettingVpn 2020-04-04 19:51:34 +02:00
Thomas Haller
c97b217772 libnm: drop unrechable g_warn_if_fail() assertion from NMSettingVpn's update_secret_dict()
For one, this code was unreachable, because we checked these conditions
already before.

That aside, g_warn_*() is for all intended purposes an assertion.
The caller probably gets the GVariant from an untrusted source (e.g. via
D-Bus). Asserting here is not helpful.
It's up to the caller to validate the argument. Or, in case the caller
doesn't care, update_secret_dict() should just do the sensible thing.
But be silent about it!
2020-04-04 19:51:34 +02:00
Thomas Haller
63ad9b7b1d libnm: avoid strlen() to determine whether a string is empty
Yes, the compiler probably can optimize strlen() in these cases. That
still doesn't make strlen() the right API to check whether a NUL
terminated string is empty.
2020-04-04 19:51:34 +02:00
Thomas Haller
7a1beb5667 libnm: use NM_STR_HAS_SUFFIX() in nm-setting-vpn.c's aggregate() 2020-04-04 19:51:34 +02:00
Thomas Haller
55a058aeef libnmm,shared: extract and move nm_utils_strdict_to_variant_ass() to shared
This is a helper function that converts a string dictionary to an "a{ss}"
GVariant. It is generally useful, and should be independent from the
caller.
2020-04-04 19:51:34 +02:00
Thomas Haller
27e788cce8 shared: add NM_UTILS_STR_UTF8_SAFE_FLAG_SECRET flag
The new flag tells that as we re-allocate data buffers during
escaping, we bzero the memory to avoid leaking secrets.
2020-04-03 11:31:12 +02:00
Thomas Haller
7e49f4a199 all: use wrappers for g_ascii_strtoll(), g_ascii_strtoull(), g_ascii_strtod()
Sometimes these function may set errno to unexpected values like EAGAIN.
This causes confusion. Avoid that by using our own wrappers that retry
in that case. For example, in rhbz#1797915 we have failures like:

    errno = 0;
    v = g_ascii_strtoll ("10", 0, &end);
    if (errno != 0)
        g_assert_not_reached ();

as g_ascii_strtoll() would return 10, but also set errno to EAGAIN.

Work around that by using wrapper functions that retry. This certainly
should be fixed in glib (or glibc), but the issues are severe enough to
warrant a workaround.

Note that our workarounds are very defensive. We only retry 2 times, if
we get an unexpected errno value. This is in the hope to recover from
a spurious EAGAIN. It won't recover from other errors.

https://bugzilla.redhat.com/show_bug.cgi?id=1797915
2020-04-01 17:18:37 +02:00
Thomas Haller
46dd4d0fbf meson: merge branch 'inigomartinez/meson-license'
Add SPDX license headers for meson files.

As far as I can tell, according to RELICENSE.md file, almost everybody
who contributed to the meson files agreed to the LGPL-2.1+ licensing.
This entails the vast majority of code in question.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/397
2020-03-28 12:45:19 +01:00
Thomas Haller
6f9a478b7d tests: replace NMTST_SWAP() by new NM_SWAP() macro
NMTST_SWAP() used memcpy() for copying the value, while NM_SWAP() uses
a temporary variable with typeof(). I think the latter is preferable.

Also, the macro is essentially doing the same thing.
2020-03-26 21:28:56 +01:00
Niklas Goerke
bddba4ca8b Add domain_match mode for wifi certificate domain comparison
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/308
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/437
2020-03-23 20:31:09 +01:00
Beniamino Galvani
0d0c79d5ab libnm-core: slightly improve sriov setting documentation 2020-03-23 11:42:57 +01:00
Beniamino Galvani
78f1977ecd libnm-core: remove trailing dot from setting description
The trailing dot is already added when generating the man page.
2020-03-23 11:42:57 +01:00
Thomas Haller
52dbab7d07 all: use nm_clear_pointer() instead of g_clear_pointer()
g_clear_pointer() would always cast the destroy notify function
pointer to GDestroyNotify. That means, it lost some type safety, like

   GPtrArray *ptr_arr = ...

   g_clear_pointer (&ptr_arr, g_array_unref);

Since glib 2.58 ([1]), g_clear_pointer() is also more type safe. But
this is not used by NetworkManager, because we don't set
GLIB_VERSION_MIN_REQUIRED to 2.58.

[1] f9a9902aac

We have nm_clear_pointer() to avoid this issue for a long time (pre
1.12.0). Possibly we should redefine in our source tree g_clear_pointer()
as nm_clear_pointer(). However, I don't like to patch glib functions
with our own variant. Arguably, we do patch g_clear_error() in
such a manner. But there the point is to make the function inlinable.

Also, nm_clear_pointer() returns a boolean that indicates whether
anything was cleared. That is sometimes useful. I think we should
just consistently use nm_clear_pointer() instead, which does always
the preferable thing.

Replace:

   sed 's/\<g_clear_pointer *(\([^;]*\), *\([a-z_A-Z0-9]\+\) *)/nm_clear_pointer (\1, \2)/g' $(git grep -l g_clear_pointer) -i
2020-03-23 11:22:38 +01:00
Thomas Haller
073994ca42 all: use nm_clear_g_free() instead of g_clear_pointer()
I think it's preferable to use nm_clear_g_free() instead of
g_clear_pointer(, g_free). The reasons are not very strong,
but I think it is overall preferable to have a shorthand for this
frequently used functionality.

   sed 's/\<g_clear_pointer *(\([^;]*\), *\(g_free\) *)/nm_clear_g_free (\1)/g' $(git grep -l g_clear_pointer) -i
2020-03-23 11:05:34 +01:00
Thomas Haller
431c349b47 libnm: enable macros for marking sync libnm methods as deprecated 2020-03-23 09:38:24 +01:00
Thomas Haller
61615781c5 libnm/doc: fix gtk-doc for deprecated markers in libnm 2020-03-23 09:32:04 +01:00
Antonio Cardace
97d3f1b4b9 nm-setting-bond: don't take default values into account when comparing options
This solves a bug exposed by the following cmds:
$ nmcli c add type bond ifname bond0 con-name bond0
$ nmcli c modify bond0 +bond.options miimon=100
$ nmcli -f bond.options c show bond0
bond.options:                           mode=balance-rr

Here we just added the option 'miimon=100', but it doesn't get saved in
because nm_settings_connection_set_connection() which is responsible for
actually updating the connection compares the new connection with old
one and if and only if the 2 are different the update is carried out.

The bug is triggered because when comparing, if default values are taken into
account, then having 'miimon=100' or not having it it's essentially the
same for compare(). While this doesn't cause a bond to have a wrong
setting when activated it's wrong from a user experience point of view
and thus must be fixed.

When this patch is applied, the above
commands will give the following results:
$ nmcli c add type bond ifname bond0 con-name bond0
$ nmcli c modify bond0 +bond.options miimon=100
$ nmcli -f bond.options c show bond0
bond.options:                           mode=balance-rr,miimon=100

Fix unit tests and also add a new case covering this bug.

https://bugzilla.redhat.com/show_bug.cgi?id=1806549
2020-03-19 17:26:08 +01:00
Antonio Cardace
fc8784a011 libnm-core: fix wording for 'nm_sett_info_propert_type_mac_addrees'
$ sed -i 's/nm_sett_info_propert_type_mac_addrees/nm_sett_info_propert_type_mac_address/' $(git grep -l 'nm_sett_info_propert_type_mac_addrees' | tr '\n' ' ')
2020-03-19 16:59:07 +01:00