Commit graph

1700 commits

Author SHA1 Message Date
Iñigo Martínez 648155e4a1 license: Add license using SPDX identifiers to meson build files
License is missing in meson build files. This has been added using
SPDX identifiers and licensed under LGPL-2.1+.
2020-02-17 13:16:57 +01:00
Thomas Haller 6963ecf0d1 license: relicense "libnm-core/nm-errors.h" under LGPL-2.1+
$ git shortlog -n -s a3e75f3294 -- libnm-core/nm-errors.h
      11    Dan Winship
       5    Thomas Haller
       2    Beniamino Galvani

Note that the header also contains code that was copied from other
files. However, that code originates from libnm itself (and thus was
already LGPL licensed).

All contributors agreed to the relicensing according to "RELICENSE.md".
2020-02-16 15:55:55 +01:00
Thomas Haller 3ceb7bf099 libnm/doc: fix example for MULTI_CONNECT ifcfg-rh setting 2020-02-14 13:25:37 +01:00
Thomas Haller 5a731747c5 libnm: use NM_UTILS_STRING_TABLE_LOOKUP_DEFINE() to implement _nm_setting_bond_mode_from_string() 2020-02-13 10:46:34 +01:00
Thomas Haller 8e636186c0 core: for WireGuard devices use a default dns-priority of 50 (like for VPNs) 2020-02-12 11:55:30 +01:00
Beniamino Galvani bf4b53d453 libnm-core: fix documentation of dns-priority property
Clarify that VPNs are considered first in case of same priority, and
also that it's the *best* default route that matters.
2020-02-12 11:06:40 +01:00
Thomas Haller c69d703017 all: use g_ascii_strcasecmp() instead of the locale dependent strcasecmp()
In all the cases, we don't want to perform locale dependent comparison.

  $ sed -i 's/\<strcasecmp\>/g_ascii_\0/g' $(git grep -w -l strcasecmp -- ':(exclude)shared/systemd/' )
2020-02-11 15:23:06 +01:00
Thomas Haller 8b63b229dd shared/trivial: rename time related functions to use "nsec"/"msec" abbreviation instead of "ns"/"ms"
The "ns" abbreviation doesn't look too nice. We mostly use "nsec" at other
places. Rename.
2020-02-10 19:11:50 +01:00
Beniamino Galvani d2d6a68697 build: use -fcommon when building libnm-core
Building with GCC 10 gives the following error:

 multiple definition of_nm_jansson_json_object_iter_key';
 libnm/.libs/liblibnm.a(libnm_core_la-nm-json.o):/builddir/build/BUILD/NetworkManager-1.23.1/libnm-core/nm-json.c:24: first defined here /usr/bin/ld:
 libnm/.libs/liblibnm.a(libnm_core_la-nm-team-utils.o):/usr/include/jansson.h:202: multiple definition of _nm_jansson_json_object_iter';

This happens because GCC 10 defaults to -fno-common and so multiple
definitions of the same global variable are not merged together.

_nm_jansson_json_* symbols are defined in nm-json.c as void pointers
and, due to the following macros in nm-json.h:

 #define json_object_iter_next   (*_nm_jansson_json_object_iter_next)
 ...

the function declaration in jansson.h:

 void *json_object_iter_next(json_t *object, void *iter);

becomes a global variable as well:

 void *(*_nm_jansson_json_object_iter_next)(json_t *object, void *iter);

So, the symbol is present in nm-json.o and all other object files that
include nm-json.h, and -fcommon is required. Without it, it would be
necessary to define the symbols only in one place (for example,
nm-json.c), but then static inline functions from the jannson.h header
would still refer to the original (missing) jansson functions.

For the moment, just use -fcommon.
2020-02-03 10:53:33 +01:00
Thomas Haller b9c5c07c4d shared: add NM_IP_ADDR_ZERO macro for initializing NMIPAddr to zero 2020-01-28 11:17:41 +01:00
Thomas Haller 8f3b43f009 all: use nm_utils_ipaddr_is_valid() instead of nm_utils_ipaddr_valid()
We should use the same "is-valid" function everywhere.

Since nm_utils_ipaddr_valid() is part of libnm, it does not qualify.

Use nm_utils_ipaddr_is_valid() instead.
2020-01-28 11:17:41 +01:00
Thomas Haller 95ea3ccad8 libnm: use nm_utils_ipaddr_is_valid() to implement nm_utils_ipaddr_valid() 2020-01-28 11:17:41 +01:00
Thomas Haller cd0863a339 all: use _nm_utils_inet4_ntop() instead of nm_utils_inet4_ntop()
and _nm_utils_inet6_ntop() instead of nm_utils_inet6_ntop().

nm_utils_inet4_ntop()/nm_utils_inet6_ntop() are public API of libnm.
For one, that means they are only available in code that links with
libnm/libnm-core. But such basic helpers should be available everywhere.

Also, they accept NULL as destination buffers. We keep that behavior
for potential libnm users, but internally we never want to use the
static buffers. This patch needs to take care that there are no callers
of _nm_utils_inet[46]_ntop() that pass NULL buffers.

Also, _nm_utils_inet[46]_ntop() are inline functions and the compiler
can get rid of them.

We should consistently use the same variant of the helper. The only
downside is that the "good" name is already taken. The leading
underscore is rather ugly and inconsistent.

Also, with our internal variants we can use "static array indices in
function parameter declarations" next. Thereby the compiler helps
to ensure that the provided buffers are of the right size.
2020-01-28 11:17:41 +01:00
Thomas Haller c0bd6752b9 shared: move nm_utils_inet* helpers from libnm-core to shared 2020-01-28 11:17:41 +01:00
Thomas Haller 299fc555b4 libnm/tests: test nm_ip_addr_zero is all-zero and compares to IP addresse as expected 2020-01-28 11:17:41 +01:00
Thomas Haller e49e509262 libnm: use nm_utils_addr_family_to_size() in "nm-setting-ip-config.c" 2020-01-28 11:17:41 +01:00
Thomas Haller 90bb46c8ee shared/tests/trivial: rename nmtst_main_context_iterate_until() to nmtst_main_context_iterate_until_assert()
nmtst_main_context_iterate_until*() iterates until the condition is
satisfied. If that doesn't happen within timeout, it fails an assertion.

Rename the function to make that clearer.
2020-01-28 10:54:14 +01:00
Beniamino Galvani 667568d1b2 core,libnm: add VRF support
Add VRF support to the daemon. When the device we are activating is a
VRF or a VRF's slave, put routes in the table specified by the VRF
connection.

Also, introduce a VRF device type in libnm.
2020-01-14 09:51:56 +01:00
Beniamino Galvani f4ced16791 libnm-core,cli: add VRF setting
Add new VRF setting and connection types to libnm-core and support
them in nmcli.
2020-01-14 09:49:01 +01:00
Thomas Haller e90c1de868 all: use nm_g_unix_fd_source_new() instead of g_unix_fd_source_new()
Its source-func argument has the right signature. Otherwise, this is an
easy to make mistake.
2020-01-13 15:46:04 +01:00
Thomas Haller 4e9119c52e libnm: let nm_utils_security_valid() reject TKIP with SAE (WPA3)
SAE should always use CCMP.
2020-01-08 09:47:57 +01:00
Thomas Haller 31aac7a9d8 libnm: let nm_utils_security_valid() reject adhoc mode with SAE 2020-01-08 09:47:57 +01:00
Thomas Haller 3d20c9985d libnm: avoid deep nesting in checks of nm_utils_security_valid() 2020-01-08 09:47:57 +01:00
Thomas Haller e9d4980d6b libnm: cleanup conditions by moving pre-check in nm_utils_security_valid()
Do the switch based on the type on the top level, don't split the
conditions to first handle some cases, and some later.
2020-01-08 09:47:57 +01:00
Thomas Haller 936bb8716b libnm: break lines in conditions of nm_utils_security_valid() 2020-01-08 09:47:57 +01:00
Thomas Haller 2e72403cb7 libnm: add missing braces to multi-line condition in nm_utils_security_valid() 2020-01-08 09:47:57 +01:00
Thomas Haller cffe3a3ef6 libnm: return early from nm_utils_security_valid()
Once we know the outcome of the check, just return it instead of
falling though to return a variable "good" which was initialized
two pages earlier.

Also, avoid the "default" switch case. This way, we get a compiler
warning about missing enum values.
2020-01-08 09:47:57 +01:00
Thomas Haller d964decbbd libnm/keyfile: build keyfile code as separate GPL licensed internal library
Keyfile support was initially added under GPL-2.0+ license as part of
core. It was moved to "libnm-core" in commit 59eb5312a5 ('keyfile: merge
branch 'th/libnm-keyfile-bgo744699'').

"libnm-core" is statically linked with by core and "libnm". In
the former case under terms of GPL-2.0+ (good) and in the latter case
under terms of LGPL-2.1+ (bad).

In fact, to this day, "libnm" doesn't actually use the code. The linker
will probably remove all the GPL-2.0+ symbols when compiled with
gc-sections or LTO. Still, linking them together in the first place
makes "libnm" only available under GPL code (despite the code
not actually being used).

Instead, move the GPL code to a separate static library
"shared/nm-keyfile/libnm-keyfile.la" and only link it to the part
that actually uses the code (and which is GPL licensed too).

This fixes the license violation.

Eventually, it would be very useful to be able to expose keyfile
handling via "libnm". However that is not straight forward due to the
licensing conflict.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/381
2020-01-07 13:17:47 +01:00
Thomas Haller 7d5d7c6d59 libnm: sort settings when constructing GVariant for connection 2019-12-28 22:23:25 +01:00
Antonio Cardace 0f7994328d shared: move nm-dbus-auth-subject to shared/nm-libnm-core-intern
Move it to shared as it's useful for clients as well.

Move and rename nm_dbus_manager_new_auth_subject_from_context() and
nm_dbus_manager_new_auth_subject_from_message() in nm-dbus-manager.c
as they're needed there.
2019-12-24 10:13:51 +01:00
Thomas Haller 358e743513 libnm/proxy: use int type for proxy.method property
The method field is set from (only) via a GObject property setter,
which sets a value of type int. As we afterwards validate that the
value is in a valid range, we should use a suitable type to hold
the value to begin with. Of course, in almost all cases is the
underlying type of the enum already int.
2019-12-24 07:48:35 +01:00
Thomas Haller 1cab6367b2 libnm: don't have G_PARAM_CONSTRUCT properties in NMSetting instances
G_PARAM_CONSTRUCT cause to explicitly initialize the property during
object construction. This is an unnecessary overhead that we can easily
avoid.

The overhead is because G_PARAM_CONSTRUCT parameters are always set with
g_object_set() before calling constructed(). Even if they are not specified
during g_object_new(), in which case it calls set with the property's default
value. This also requires g_object_new() to iterate all properties to
find and sort the construct properties.

NMSetting are supposed to be simple classes. They don't need to have
their properties initialized before object construction completes.
Especially if the default values are NULL or zero, in which case there
is nothing to do. If the default value is not NULL or zero, we need
to initialize the field instead in the nm_setting*_init() function.
2019-12-24 07:47:50 +01:00
Thomas Haller 0de6cd2d68 libnm: sort fields in NMSetting structures by size and alignment 2019-12-24 07:45:24 +01:00
Thomas Haller 785da51d83 core: add and indicate NM_CAPABILITY_OVS capability on D-Bus
https://bugzilla.redhat.com/show_bug.cgi?id=1785147
2019-12-21 11:33:59 +01:00
Thomas Haller d65aabd518 libnm: use designated initalizers for NMSriovVF and VFVlan 2019-12-20 14:46:58 +01:00
Thomas Haller c4a728217d libnm: fix type annotation for nm_sriov_vf_get_vlan_ids()
Otherwise, this function cannot really be used via generated bindings.
Also, it's the only way to actually retrieve the set vlan-ids, without
it, you wouldn't know which ones are set.

Fixes: a9b4532fa7 ('libnm-core: add SR-IOV setting')
2019-12-20 14:42:12 +01:00
Antonio Cardace 730adf2afd clients,libnm-core: zero-out memory used to store plain-text secrets 2019-12-18 16:15:06 +01:00
Thomas Haller 3d07708f59 doc: clarify default values for ipv4.mdns and ipv4.llmnr settings
LLMNR and mDNS settings can have their global default value configured
in "NetworkManager.conf".

Global default values should work the way that all regular values of the property
can be configured explicitly in the connection profile. The special "default" value
only indicates to allow lookup of the global default, but it should not have a
meaning of its own.

Note that if mDNS/LLMNR settings are left unspecified, we will set the
argument to SetLinkMulticastDNS() and SetLinkLLMNR() functions to "",
which means that systemd-resolved decides on a default. Also, depending
on the DNS plugin, the default value differs. This is all fine however.
In this case, the ultimate default value depends on other things (like
the DNS plugin), but each possible value is in fact explicitly
configurable. We also do that for "ipv6.ip6-privacy".

Anyway, cleanup the documentation a bit and try to better explain what
the default is.
2019-12-10 16:49:23 +01:00
Thomas Haller 5ad095374f libnm: move NMClientPermission/NMClientPermissionResult enums from libnm to libnm-core
We will also use the enum from core.
2019-12-10 07:53:25 +01:00
Thomas Haller 4eed1a6596 libnm/docs: fix gtk-doc for #NMDhcpHostnameFlags 2019-12-09 07:49:16 +01:00
David Bauer fc42a74ece libnm-core: support OWE when determining AP compatibility 2019-12-05 14:00:10 +01:00
David Bauer cb33a27f96 libnm/utils: add OWE security type 2019-12-05 14:00:10 +01:00
David Bauer 85c4a757ad libnm-core/setting-wireless-security: add support for OWE key-management 2019-12-05 14:00:10 +01:00
David Bauer ba299d0d0c libnm-core: add OWE support flag 2019-12-05 14:00:10 +01:00
Thomas Haller 66ea6e01c8 libnm: drop unused _nm_dbus_proxy_call_sync() helper
It's unused and:

  - we probably should avoid GDBusProxy altogether

  - we very likely should avoid blocking D-Bus calls
2019-12-03 16:32:08 +01:00
Thomas Haller 0c06a0f368 release: bump version to 1.23.0 (development) 2019-11-29 15:46:22 +01:00
Thomas Haller 61381b8ee4 libnm: add nm_ip_address_cmp_full() function
Not being able to compare two NMIPAddress instances is a major
limitation. Add nm_ip_address_cmp_full(). The choice here for adding
a "cmp()" function instead of a "equals()" function is that cmp is
more useful. We only want to add one of the two, so choose the
more powerful one. Yes, usually its also not the variant we want
or the variant that is convenient to use, such is life.

Compare this to:

  - nm_ip_route_equal_full(), which is an equal() method and not
    a cmp().

  - nm_ip_route_equal_full() which has a guint flags argument,
    instead of a typedef for an enum, with a proper generated
    GType.
2019-11-28 19:20:33 +01:00
Beniamino Galvani 292d3f2b57 ifcfg-rh: add support for DHCP hostname flags 2019-11-28 17:56:35 +01:00
Beniamino Galvani 1bde86396b libnm: add ipvx.dhcp-hostname-flags properties
When using the dhclient DHCP backend users can tweak the behavior in
the dhclient configuration file. One of the options that was reported
as useful in the past was the FQDN flags [1] [2].

Add native support for FQDN flags to NM by introducing new
ipv{4,6}.dhcp-hostname-flags properties.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1684595
[2] https://bugzilla.redhat.com/show_bug.cgi?id=1255507
2019-11-28 17:56:35 +01:00
Thomas Haller b9f1beb06e all: add support for "scope" attribute for IPv4 routes
- systemd-networkd and initscripts both support it.

- it seems suggested to configure routes with scope "link" on AWS.

- the scope is only supported for IPv4 routes. Kernel ignores the
  attribute for IPv6 routes.

- we don't support the aliases like "link" or "global". Instead
  only the numeric value is supported. This is different from
  systemd-networkd, which accepts names like "global" and "link",
  but no numerical values. I think restricting ourself only to
  the aliases unnecessarily limits what is possible on netlink.
  The alternative would be to allow aliases and numbers both,
  but that causes multiple ways to define something and has
  thus downsides. So, only numeric values.

- when setting rtm_scope to RT_SCOPE_NOWHERE (0, the default), kernel
  will coerce that to RT_SCOPE_LINK. This ambiguity of nowhere vs. link
  is a problem, but we don't do anything about it.

- The other problem is, that when deleting a route with scope RT_SCOPE_NOWHERE,
  this acts as a wild care and removes the first route that matches (given the
  other route attributes). That means, NetworkManager has no meaningful
  way to delete a route with scope zero, there is always the danger that
  we might delete the wrong route. But this is nothing new to this
  patch. The problem existed already previously, except that
  NetworkManager could only add routes with scope nowhere (i.e. link).
2019-11-28 00:11:15 +01:00