Commit graph

1950 commits

Author SHA1 Message Date
Sayed Shah 58847f85a4 platform: use netlink for configuring bridge settings
NMDeviceBridge is currently using sysfs. The plan is to use netlink in
in the future
2020-08-20 14:03:10 -04:00
Thomas Haller 70971d1141
all: avoid wrong compiler warning about uninitalized variables with LTO
Seems with LTO the compiler can sometimes think that thes variables are
uninitialized. Usually those code paths are only after an assertion was
hit (g_return*()), but we still need to workaround the warning.
2020-08-17 15:18:02 +02:00
Sayed Shah 80c93b0e5e
platform: add support for configuring bridge settings via netlink (2)
NMDeviceBridge is currently using sysfs. The plan is to use netlink in
in the future.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/601
2020-08-14 21:26:10 +02:00
Thomas Haller 3df662f534
settings: rework wait-device-timeout handling and consider device compatibility
A profile can configure "connection.wait-device-timeout" to indicate
that startup complete is blocked until a suitable device around.
This is useful for NetworkManager-wait-online and initrd mode.

Previously, we looked at NMPlatform whether a link with matching
interface-name was present. That is wrong because it cannot handle
profiles that rely on "ethernet.mac-address" setting or other "match"
settings. Also, the mere presence of the link does not yet mean
that the NMDevice was created and ready. In fact, there is a race here:
NMPlatform indicates that the device is ready (unblocking NMSettings),
but there is no corresponding NMDevice yet which keeps NetworkManager
busy to block startup complete.

Rework this. Now, only check whether there is a compatible device for
the profile.

Since we wait for compatible devices, it works now not only for the
interface name. Note that we do some optimizations so that we don't have
to re-evaluate all profiles (w.r.t. all devices) whenever something on the
device changes: we only care about this when all devices finally become
ready.

Also, we no longer start the timeout for "connection.wait-device-timeout"
when the profile appears. Instead, there is one system-wide start time
(NMSettingsPrivate.startup_complete_start_timestamp_msec). That simplifies
code and makes sense: we start waiting when NetworkManager is starting, not
when the profile gets added. Also, we wait for all profiles to become
ready together.
2020-08-12 16:40:56 +02:00
Thomas Haller bc0d4e610f
libnm/docs: fix doc for D-Bus format of "ipv6.route-data"
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/511
2020-08-10 18:00:18 +02:00
Sayed Shah adf0420258
platform: add support for configuring bridge settings via netlink
NMDeviceBridge is currently using sysfs. The plan is to use netlink in
in the future
2020-08-07 13:20:54 +02:00
Thomas Haller 34ffd586cd
keyfile: use NM_STR_HAS_SUFFIX_ASCII_CASE_WITH_MORE() to check filename suffix
In practice, we wouldn't need the _WITH_MORE() variants here, because
all the suffixes that we check start with a ".", and we check first
that the filename itself does not start with a ".".

However, it doesn't hurt to be explicit about this, and it has no
overhead at all.
2020-08-07 11:45:41 +02:00
Thomas Haller 6bf5f014c8
shared: change NM_SWAP() macro to take pointer arguments
This makes the macro more function like. Also, taking a pointer
makes it a bit clearer that this possibly changes the value.

Of course, it's not a big difference to before, but this
form seems slightly preferable to me.
2020-08-06 18:12:01 +02:00
Thomas Haller 62c1a1b5b2
shared: move nm_utils_is_power_of_two() to nm-stdaux and add nm_utils_is_power_of_two_or_zero() 2020-07-31 08:53:04 +02:00
tk906328 cb73d0b1e2
libnm-core: avoid compiler warning in nm_connection_to_dbus_full()
Deal with compiling warning about variable not initialized before use.

[thaller@redhat.com: reworded original commit message]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/587
2020-07-24 09:12:30 +02:00
Beniamino Galvani e6acf64859 libnm-core: support 'clsact' qdisc
The 'clsact' qdisc is similar to 'ingress' but supports both ingress
and egress [1]. It uses the same handle as 'ingress' and has two child
classes :fff2 (ingress) and :fff3 (egress) on which filters can be
attached.

With clsact, for example, it becomes possible to do port mirroring
with a single qdisc:

  nmcli connection modify mirror +tc.qdisc "clsact"
  nmcli connection modify mirror +tc.tfilter
    "parent ffff:fff3 matchall action mirred egress mirror dev dummy1"
  nmcli connection modify mirror +tc.tfilter
    "parent ffff:fff2 matchall action mirred egress mirror dev dummy1"

instead of two (ingress + i.e. prio). We don't support yet the
symbolic names 'ingress' and 'egress' for :fff2 and :fff3 in the
filter.

See-also: https://bugzilla.redhat.com/show_bug.cgi?id=1436535

[1] https://lwn.net/Articles/671458/
2020-07-23 14:12:02 +02:00
Thomas Haller b17e3cf707
all: add trailing semicolon to NM_AUTO_DEFINE_FCN_*() uses 2020-07-19 12:01:56 +02:00
Thomas Haller 826c83ce41
libnm: fix -Werror=maybe-uninitialized warning _setting_bond_validate_option()
Fixes: e96051d734 ('libnm: cleanup validating bond option "arp_ip_target"')
2020-07-13 17:40:40 +02:00
Thomas Haller a0b22b5b40
libnm: add _nm_setting_bond_mode_from_string() to nm-libnm-core-intern 2020-07-11 11:18:55 +02:00
Thomas Haller b55578bf6e
cli: fix alternating miimon/arp_interval settings for bond options in nmcli
Before 1.24, nm_setting_bond_add_option() would clear
miimon/arp_interval settings when the respective other was set.

That was no longer done, with the effect that enabling (for example)
miimon on a bond profile that has arp_interval enabled, sets both
conflicting options.

That is not a severe problem, because the profile still validates.
However, at runtime only one of the settings can be actually configured.

Fix that, by restoring the previous behavior for the client. But note
that this time it's implemented in the client, and not in libnm's
nm_setting_bond_add_option().
2020-07-11 11:18:54 +02:00
Thomas Haller 4aa46328ca
libnm,core: fix handling miimon and arp_interval as conflicting kernel options
We use sysfs API for setting bond options. Note that the miimon and
arp_interval settings conflict each other, and whenever setting one
of these sysfs values, the other one gets reset. That means,
NetworkManager needs to mediate and handle a profile which has both
these options set.

Before 1.24, the libnm API nm_setting_bond_add_option() API would mangle
the content of the bond settings, to clear the respective other fields
when setting miimon/arp_interval. That also had the effect that the
settings plugins, weren't able to read such (conflicting) settings
back from disk (but they would write them to disk). If a keyfile
specified both miimon and arp_interval keys, then it would depend on
their order in the keyfile which wins.
It is wrong that a libnm property setter mangles the option in such a way,
especially, because you still could set the NM_SETTING_BOND_OPTIONS
property directly and bypass this. So, since 1.24, you can create
profiles that have conflicting options.

Also, we can now not start to reject such settings as invalid, because that
would be an API break. Instead, just make sure that when one of the
settings is set, that the other one consistently gets deactivated.

Also, before 1.24 already, NMDeviceBond would mediate whether to either set
miimon or arp_interval settings. Despite that the keyfile reader would
mangle the settings, it would also prefer miimon over arp_interval,
if both were set.

This mechanism was broken since we switch to _bond_get_option_normalized()
for that. As a consequence, NetworkManager would try to set both the
conflicting options. Fix that.
2020-07-10 16:45:06 +02:00
Thomas Haller 1543f8a1a1
libnm: don't fail assertion for _bond_get_option_normalized() with invalid bond mode
_bond_get_option_normalized() gets called with code paths that don't
assume a valid options hash. That means, the bond mode might be invalid
and we should fail an assertion.
2020-07-10 16:42:23 +02:00
Thomas Haller e96051d734
libnm: cleanup validating bond option "arp_ip_target"
We already have meta data for all bond options. For example,
"arp_ip_target" has type NM_BOND_OPTION_TYPE_IP.

Also, verify() already calls nm_setting_bond_validate_option() to validate
the option. Doing a second validation below is redundant (and done
inconsistently).

Validate the setting only once.

Also beef up the validation and use nm_utils_bond_option_arp_ip_targets_split()
to parse the IP addresses. This now strips extra whitespace and (as
before) removes empty entries.
2020-07-10 13:12:43 +02:00
Thomas Haller 4ee0e8f075
libnm: add nm_utils_bond_option_arp_ip_targets_split() helper
Note yet used. The way how we split the option is relevant at various
places. The code should use the same helper function.
2020-07-10 13:12:43 +02:00
Thomas Haller ca7bb15591
shared: cleanup dlopening libjansson depending on configure options
- assert that WITH_JANSSON and JANSSON_SONAME are defined consistently.
  This check ensures that we can check at compile time that nm_json_vt()
  will always fail (because JANSSON_SONAME) is undefined.
  That is interesting, because this means you can do a compile time
  for !WITH_JANSSON, and know if nm_json_vt() will *never* succeed.
  With that, we could let the linker know when the code is unused
  and remove all uses of nm_json_vt(), without using the traditional
  conditional compilation with "#if WITH_JANSSON". But of course, we
  currently don't do this micro optimization to remove defunct code.

- drop the "mode" helper variable and pass the flags directly to
  dlopen().
2020-07-09 12:57:15 +02:00
Thomas Haller 57de0c27a7
shared,libnm: rename nm_json_aux_gstr_*() API to nm_json_gstr_*() 2020-07-09 11:47:06 +02:00
Thomas Haller 4a7da1ca4b
shared: merge nm-glib-aux/nm-json.[hc] into nm-json-aux.[hc]
They serve a similar purpose.

Previously, nm-json-aux.h contained the virtual function table for accessing
the dynamically loaded libjansson. But there is no reason why our own
helper functions from nm-json.h cannot be there too.
2020-07-09 11:47:06 +02:00
Thomas Haller bbb1f5df2f
libnm: always build libnm with JSON validation
We anyway load libjansson with dlopen(), and already before it could
happen that libjansson is not available. In that case, we would not
crash, but simply proceed without json validation.

Since libnm-core no longer uses libjansson directly, but only via
"nm-glib-aux/nm-json.h", we can just always compile with that, and use
it at runtime. That means, libjansson is not a build dependency for
libnm anymore, so we don't need a compile time check.

Note that if you build without libjansson, then JANSSON_SONAME is
undefined, and loading it will still fail at runtime. So, even if
we now always build with all our code enabled, it only works if you
actually build with libjansson. Still, it's simpler to drop the
conditional build, as the only benefit is a (minimally) smaller
build.
2020-07-09 11:47:06 +02:00
Thomas Haller 3814467b88
libnm,shared: move nm-json.[hc] to shared/nm-glib-aux
nm-json.[hc] uses libjansson, but only loads it at runtime with dlopen. There
is no more run compile time dependency. Move it to shared, so that it can be
(theoretically) used by other components.

Also, drop the conditional compilation. Granted, if you don't build with
libjansson enabled, then the JANSSON_SONAME define is unset and the code
will fail to load at runtime (which is fine). However, we can still build
against our JSON wrappers. The code savings of conditional build are minimal
so drop it.
2020-07-09 11:47:05 +02:00
Thomas Haller 7df0229c62
libnm: don't include <jansson.h> in libnm but use own variants
It's error prone to include the header and trying not to use it.
Don't include <jansson.h>. Instead, redefine our nm variants of
everything.

Note that we only redefine stuff that is in public headers (like
"json_t" typedef). libjansson anyway must not change the struct layout
and the like, without breaking all applications. That is because the
non-opaque code from the header anyway is part of the applications that
include it. Later we will add additional unit test that checks that our
redefinition matches to what we had at compile time.
2020-07-09 11:47:05 +02:00
Thomas Haller 185dca22bc
libnm: don't redefine symbols in jansson.h header
Redefining symbols before including <jansson.h> is confusing.

Instead, only use our symbols and access libjansson via NMJsonVt.
2020-07-09 11:47:05 +02:00
Thomas Haller a9e3987e7c
libnm: merge "shared/nm-glib-aux/nm-jansson.h" into "libnm-core/nm-json.h"
"shared/nm-glib-aux/nm-jansson.h" is a compat header for <jansson.h>. It
includes <jansson.h> and adds some compatibility workarounds and helper
functions.

We want that "libnm-core/nm-json.h" no longer includes <jansson.h>, so
that we don't accidentally use symbols from there.
Hence, "libnm-core/nm-json.h" must no longer include "nm-jansson.h".

In preparation of that, copy the content of "shared/nm-glib-aux/nm-jansson.h"
also to "libnm-core/nm-json.h". It will be reworked later.
2020-07-09 11:47:05 +02:00
Thomas Haller 125d362177
libnm: don't use any symbols from jansson.h directly
Some symbols in jansson.h are macros, some are regular functions,
and some are inline functions.

Regular functions must not be used directly, only via dlsym().

Macros must be used directly, but it is non-obvious which symbols
are macros. Hence, for each json_* macro add an nm_json_* alias.

Inline functions are a bit odd. If they are inlined and don't use
any non-inlined symbols from libjansson, they could be used directly.
However, it's non obvious whether both of the conditions are met.
Hence, we reimplement them in nm-json.h. The only function of this kind
is json_decref().

The point is to not use any json_* symbols directly -- except structs
and typedefs.

Seemingly, with this change we don't use any jansson symbols directly.
However, that is not true, as macros like nm_json_object_foreach()
still are implemented based on what is included from <jansson.h>.
Hence, we cannot drop patching the included jansson.h header yet and
still need our wrapper functions.
2020-07-09 11:47:05 +02:00
Thomas Haller c0c10896e9
libnm: introduce NMJsonVt virtual table for accessing libjansson symbols
Rework the code how we access libjansson.

libnm wants to use libjansson, but it doesn't directly link to it.
The reason is that (until recently), libjansson has conflicting symbols
with libjson-c and libjson-glib. That means, if libnm would directly
link against libjansson, then if the using application happens to drag
in one of the conflicting libraries, the application would crash. Instead,
we dlopen() the library (with flags RTLD_LOCAL|RTLD_DEEPBIND).

However, as it is currently done, it doesn't fully work, as unit test
failures of libnm show on Debian sid (where libmount links against
libcryptsetup which links against libjson-c). Theoretically, our current
approach should work. At least for libnm; not for the OVS and team
plugins which use libjansson directly in NetworkManager core.

What I dislike about the current approach is that we still include
<jansson.h>, but somehow try not to use any symbols from it (via #define
we remap the json functions). The previous approach is "smaller", but also highly
confusing, and error prone, as there is a subtle bug as the unit test failure
shows (which I don't understand).

Instead, add and load a virtual function table NMJsonVt. Later, we will
go further ad drop all direct uses of <jansson.h> header.
2020-07-09 11:47:05 +02:00
Antonio Cardace e3e7bdf96e
utils: add 'unspecified' to nm_utils_route_type2str()
https://bugzilla.redhat.com/show_bug.cgi?id=1821787
2020-07-08 15:10:36 +02:00
Beniamino Galvani ce432a3abc libnm-core: add test for mirred tc filter 2020-07-08 09:43:06 +02:00
Beniamino Galvani 7c60895d1e libnm-core: pass variant-attribute-spec for tc actions 2020-07-08 09:43:06 +02:00
Beniamino Galvani ee946ca27d libnm-core: pass variant-attribute-spec to format function
The output of nm_utils_format_variant_attributes() must be accepted by
nm_utils_parse_variant_attributes(), producing the initial attributes.

The latter has a special handling of some attributes, depending on the
input NMVariantAttributeSpec list. For example, if the
NMVariantAttributeSpec is a boolean with the 'no_value' flag, the
parser doesn't look for a value.

Pass the NMVariantAttributeSpec list to the format function so that it
can behave in the same way as the parse one.
2020-07-08 09:43:06 +02:00
Yuri Chornoivan 4e33f8cd89
all: fix minor typos
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/565
2020-07-07 11:33:46 +02:00
Sayed Shah 7337ab8959
all: fix typo in man pages
There should be a comma after 'Otherwise' and 'Currently'.

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/560
2020-07-03 10:48:04 +02:00
Beniamino Galvani dbfe219d5b all: add ap-isolation property to wifi setting
Add a new 'ap-isolation' property to the wifi setting, useful to
prevent communication between wireless clients.
2020-07-01 17:36:20 +02:00
Thomas Haller 1cf11ccbca
libnm: fix leak in nm_utils_is_json_object()
Fixes: 32f78ae6c3 ('libnm: expose nm_utils_is_json_object() utility function')
2020-07-01 15:42:06 +02:00
Thomas Haller b9aa7ef81c
libnm/doc: clarify values for "bridge.multicast-router"
Kernel (sysfs) and iproute2 only use numbers for the multicast_router
option. It's confusing that we name the options differently. Anyway,
that cannot be changed anymore. Clarify the meanings in the
documentation.

https://bugzilla.redhat.com/show_bug.cgi?id=1845608
2020-06-30 16:30:38 +02:00
Beniamino Galvani edf7003660
version: add 1.28 macros 2020-06-30 11:29:04 +02:00
Thomas Haller 824ad6275d
libnm/match: extend syntax for match patterns with '|', '&', '!' and '\\'
For simple matches like match.interface-name, match.driver, and
match.path, arguably what we had was fine. There each element
(like "eth*") is a wildcard for a single name (like "eth1").

However, for match.kernel-command-line, the elements match individual
command line options, so we should have more flexibility of whether
a parameter is optional or mandatory. Extend the syntax for that.

- the elements can now be prefixed by either '|' or '&'. This makes
  optional or mandatory elements, respectively. The entire match
  evaluates to true if all mandatory elements match (if any) and
  at least one of the optional elements (if any).
  As before, if neither '|' nor '&' is specified, then the element
  is optional (that means, "foo" is the same as "|foo").

- the exclamation mark is still used to invert the match. If used
  alone (like "!foo") it is a shortcut for defining a mandatory match
  ("&!foo").

- the backslash can now be used to escape the special characters
  above. Basically, the special characters ('|', '&', '!') are
  stripped from the start of the element. If what is left afterwards
  is a backslash, it also gets stripped and the remainder is the
  pattern. For example, "\\&foo" has the pattern "&foo" where
  '&' is no longer treated specially. This special handling of
  the backslash is only done at the beginning of the element (after
  the optional special characters). The remaining string is part
  of the pattern, where backslashes might have their own meaning.

This change is mostly backward compatible, except for existing matches
that started with one of the special characters '|', '&', '!', and '\\'.
2020-06-26 13:29:01 +02:00
Thomas Haller 5f202414d9
libnm: refactor wifi frequency handling in libnm
- mark global variables as const. This allows the linker to
  mark the variable as read only.

- for nm_utils_wifi_[25]ghz_freqs(), don't generate a list based
  on bg_table/a_table. Instead, keep static array of frequencies.
  Since we have unit tests that check the consistency, this has
  little maintenance effort.

- add unit tests
2020-06-26 09:29:57 +02:00
Thomas Haller bd7d8b6f3d
libnm: don't use assert for validating arguments to nm_utils_wifi_find_next_channel() 2020-06-26 09:29:56 +02:00
Thomas Haller 3945471752
libnm: use nm_streq() in "libnm-core/nm-utils.c" 2020-06-26 09:29:56 +02:00
Thomas Haller 6adf4b9a56
libnm: use NMStrBuf in nm_utils_file_search_in_paths() 2020-06-26 09:29:55 +02:00
Thomas Haller 2edb3aa81a
libnm: use NMStrBuf in _nm_utils_uuid_generate_from_strings() 2020-06-26 09:29:55 +02:00
Thomas Haller 936e457cc0
libnm: use NMStrBuf in nm_ip_routing_rule_to_string() 2020-06-26 09:29:54 +02:00
Thomas Haller 3be4f38a15
keyfile: cleanup uses of GString in keyfile code
- in _keyfile_key_decode(), don't use GString. We know the maximum
  string length before, so we can just allocated one buffer.

- in qdisc and tfilter writers, reuse the same GString instance.
  No need to allocate a new temporary string buffer for each iteration.

- at other places, replace GString by NMStrBuf. This avoids the heap
  allocated GString instance. Also, most operations can be inlined.
  This results in larger code side, but avoids function calls to glib.
2020-06-26 09:29:54 +02:00
Thomas Haller f7715c6680
libnm: use NMStrBuf in "nm-setting-bridge.c" 2020-06-26 09:29:53 +02:00
Thomas Haller 10779d545a
shared: add nm_utils_strsplit_quoted()
We want to parse "/proc/cmdline". That is space separated with support
for quoting and escaping. Our implementation becomes part of stable
behavior, and we should interpret the kernel command line the same way
as the system does. That means, our implementation should match
systemd's.
2020-06-23 00:42:37 +02:00
Thomas Haller 8a13b02d96
libnm: avoid deprecation warning about NMUtilsPredicateStr
NMUtilsPredicateStr got introduced in 1.26.0 API. However, marking the typedef
to be available only in 1.26, causes a compiler warning when using the header:

    /usr/include/libnm/nm-setting.h:372:39: error: ‘NMUtilsPredicateStr’ is deprecated: Not available before 1.26 [-Werror=deprecated-declarations]
      372 |                                       NMUtilsPredicateStr predicate);
          |                                       ^~~~~~~~~~~~~~~~~~~
    cc1: all warnings being treated as errors

Avoid that. It's not a problem in practice, because all users of the typedef
are functions that are marked to be available in 1.26 themselves.
2020-06-22 13:24:43 +02:00