Commit Graph

28470 Commits

Author SHA1 Message Date
Andrew Zaborowski
38ac64ba62 glib-aux: Set file timestamps in nm_utils_file_set_contents
Extend nm_utils_file_set_contents to be able to optionally set the last
access + last modification times on the file being created, in addition
to the mode.
2021-04-19 18:11:11 +02:00
Andrew Zaborowski
caa1b5c60d iwd: Clean up old vs. new secret logic
There was an attempt in the code to allow using existing system-owned
secrets based on whether the connection had ever succeeded before but
this wasn't implemented properly.  Now decide whether existing secrets
are allowed and whether to pass the REQUEST_NEW flag to the secrets
request based on the last connection timestamp and on the network
security type (PSK vs. 802.1X) to align the policy with the policy
inside IWD.

Drop a useless nm_connection_clear_secrets call on the applied
connection just before failing the connection attempt and thus
destroying the applied connection.
2021-04-19 18:11:11 +02:00
Andrew Zaborowski
260ceff28a iwd: Add warning comment to autogenerated IWD files 2021-04-19 18:11:11 +02:00
Andrew Zaborowski
60dcb83b58 iwd: Only save system-owned secrets to IWD config
Avoid saving agent-owned secrets when converting settings connections
to IWD config files and avoid reacting to NMSettingsConnection updates
that don't seem to touch any non-secret or system-owned-secret settings.
2021-04-19 18:11:10 +02:00
Andrew Zaborowski
ee583adecf settings: add NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET flag
Along with NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_SYSTEM_SECRETS
and NM_SETTINGS_CONNECTION_UPDATE_REASON_RESET_AGENT_SECRETS, which can
be used in the NMSettingConnection's "updated" handlers to track secrets
updates, add NM_SETTINGS_CONNECTION_UPDATE_REASON_UPDATE_NON_SECRET so
that the handlers can tell when something other than secrets has been
updated in the connection.

It can also potentially be used in _connection_changed_update in
src/core/settings/nm-settings.c to stop emitting the
NetworkManager.Settings.Connection.Updated() dbus signal if only secrets
are being updated (on agent queries etc.) if it is deemed to be correct.
2021-04-19 18:11:10 +02:00
Andrew Zaborowski
195c853a80 libnm-core: Drop repeating words in NM_CONNECTION_CHANGED comment 2021-04-19 18:11:10 +02:00
Thomas Haller
34e4a3ef17 libnm/doc: clarify GMainContext handling in NMClient documentation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/819
2021-04-19 09:31:48 +02:00
Thomas Haller
a55c10c6cb nmcli/trivial: add comment about stability of connection-add success message 2021-04-17 08:36:55 +02:00
Beniamino Galvani
4a81fe13ae platform: ethtool: support new GLINKSETTINGS kernel API
Use the new GLINKSETTINGS/SLINKSETTINGS ethtool API [1] when
available. Using the old API, we can only enable the first 31 modes in
the advertising bitmask, and so interfaces can't negotiate higher
modes.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=3f1ac7a700d039c61d8d8b99f28d605d489a60cf

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/686
2021-04-16 18:47:17 +02:00
Thomas Haller
9d3a54d269 lldp: merge branch 'th/lldp-listener-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/815
2021-04-16 15:18:35 +02:00
Thomas Haller
a5f3644f70 device/lldp: use GSource for tracking ratelimit in NMLldpListener
The reason is my dislike of these guint source ids. What is their
advantage anyway? Just use the GSource pointers.
2021-04-16 15:18:27 +02:00
Thomas Haller
655dd13902 device/lldp: simplify NMLldpListener API
NMLldpListener API was a (refcounted) GObject with start/stop methods.
That means, a listener instance itself had state, namely whether it was
running and which ifindex was used. And this was not only internal
state, but the user had to care about this.

That is all entirely unnecessary. Beside requiring more code and having
more overhead (of a GObject), it is also harder to use. NMDevice not
only need to care whether priv->listener is set, it also needs to care
whether it is running.

Simplify this. The NMLldpListener is no longer ref-counted. As such, the
notify callback is set in the constructor, and the user will stop
receiving notifications by destroying the instance. Furthermore, the instance
can only use one ifindex, that is determined at construct time too.

The state that NMLldpListener now represents is simpler. This simplifies
the usage from NMDevice, which now only call lldp_setup() to enable and
disable the listener.

There is also no need to restart the LLDP listener. The only exception
is, if the ifindex changes. In that case, we throw away the old instance
and create a new one. Otherwise, the LLDP listener is itself responsible
to keep running. There is no excuse for it to fail, and if it does, it needs
to autorecover as good as it can.
2021-04-16 15:18:27 +02:00
Thomas Haller
b0d45c88c3 device: don't restart LLDP listener in nm_device_update_dynamic_ip_setup()
It's not clear why we would need to restart the instance. It
is supposed to work, and recover automatically.

The only thing that restarting should be necessary, is to change the
ifindex. But this is not the right place for handling changes of ifindex.
2021-04-16 15:18:26 +02:00
Thomas Haller
e4537e9021 all: merge branch 'th/gvariant-helpers'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/817
2021-04-16 15:17:28 +02:00
Thomas Haller
80e30f4562 all: use nm_g_variant_new_au() helper 2021-04-16 11:44:20 +02:00
Thomas Haller
f34841e196 all: use nm_g_variant_new_ay() helper 2021-04-16 11:44:19 +02:00
Thomas Haller
4d6f659e13 all: use nm_g_variant_singleton_a*() helpers 2021-04-16 11:44:19 +02:00
Thomas Haller
bbc8d3d7ad glib-aux: add nm_g_variant_new_au() helper 2021-04-16 11:44:18 +02:00
Thomas Haller
43b80016db glib-aux: add nm_g_variant_new_ay() helper 2021-04-16 11:44:18 +02:00
Thomas Haller
b01cbff087 glib-aux: add nm_g_variant_singleton_a*() helpers 2021-04-16 11:44:18 +02:00
Thomas Haller
ce9211500e platform/tests: work around rounding errors for bridge values in unit tests
For certain options, kernel stores the numeric values in jiffies scale,
while the user space value is in USER_HZ (1/100th of a second) scale.

Jiffies scale depends on HZ setting (CONFIG_HZ), and depending on kernel
configuration its 100, 250, 300, or 1000.

That means, the round trip of clock_t_to_jiffies()/jiffies_to_clock_t()
has different rounding errors, depending on CONFIG_HZ and it maybe be
+/- 1 of the requested value.

Since the rounding error depends on CONFIG_HZ, we cannot find "good"
values for testing, that always behave the same. So we need to
workaround that.

Normalize the bridge values, if they look as if the value was mangled
due to rounding.

Related: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/665
2021-04-16 11:34:58 +02:00
Thomas Haller
5de552893d glib-aux: fix compile error for g_steal_pointer() macro
Some compiler versions don't like to dereference and opaque
pointer for typeof:

gcc 8.3.1-5.1.el8 on RHEL:

    In file included from ./src/libnm-glib-aux/nm-macros-internal.h:41,
                     from ./src/libnm-glib-aux/nm-default-glib.h:68,
                     from ./src/libnm-glib-aux/nm-default-glib-i18n-lib.h:13,
                     from ./src/libnm-core-impl/nm-default-libnm-core.h:11,
                     from src/libnm-core-impl/nm-setting-8021x.c:7:
    src/libnm-core-impl/nm-setting-8021x.c: In function '_nm_setting_802_1x_cert_value_to_bytes':
    ./src/libnm-glib-aux/nm-glib.h:417:16: error: dereferencing pointer to incomplete type 'GBytes' {aka 'struct _GBytes'}
             typeof(**_pp) *const         _p            = *_pp; \
                    ^~~~~
    src/libnm-core-impl/nm-setting-8021x.c:361:12: note: in expansion of macro 'g_steal_pointer'
         return g_steal_pointer(&bytes);
                ^~~~~~~~~~~~~~~
    ./src/libnm-glib-aux/nm-glib.h:417:54: error: initialization of 'int * const' from incompatible pointer type 'GBytes *' {aka 'struct _GBytes *'} [-Werror=incompatible-pointer-types]
             typeof(**_pp) *const         _p            = *_pp; \
                                                          ^
    src/libnm-core-impl/nm-setting-8021x.c:361:12: note: in expansion of macro 'g_steal_pointer'
         return g_steal_pointer(&bytes);
                ^~~~~~~~~~~~~~~
    ./src/libnm-glib-aux/nm-glib.h:415:6: error: returning 'int * const' from a function with incompatible return type 'GBytes *' {aka 'struct _GBytes *'} [-Werror=incompatible-pointer-types]
         ({                                                     \
         ~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             typeof(*(pp)) *const         _pp           = (pp); \
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             typeof(**_pp) *const         _p            = *_pp; \
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             _nm_unused const void *const _p_type_check = _p;   \
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                                                                \
                                                                ~
             *_pp = NULL;                                       \
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
             _p;                                                \
             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         })
         ~~
    src/libnm-core-impl/nm-setting-8021x.c:361:12: note: in expansion of macro 'g_steal_pointer'
         return g_steal_pointer(&bytes);
                ^~~~~~~~~~~~~~~

Fixes: 5bc511203e ('all: make nm_steal_pointer() and g_steal_pointer() more typesafe using typeof()')
2021-04-14 15:24:47 +02:00
Beniamino Galvani
4784c7dccd dhcp: set TERMINATED state when the client is stopped
NM_DHCP_STATE_DONE is for when the client reports that it is shutting
down. If we manually stop it, we should set the TERMINATED state, so
that NMDevice doesn't start a grace period waiting for a renewal.

This fixes the:

 device (enp1s0): DHCPv4: trying to acquire a new lease within 90 seconds

message printed when NM is shutting down.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/802
2021-04-14 11:54:16 +02:00
Thomas Haller
b9e6b84cb9 lldp: merge branch 'liangwen12year:wl/lldp'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/712
2021-04-14 09:19:59 +02:00
Wen Liang
b6514c6f18 libnm,device: add LLDP status flag for NMDevice's interface_flags
Add and set the flag to indicate device LLDP status.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-04-14 08:24:01 +02:00
Wen Liang
816bcac129 device: add and use function set_interface_flags_full()
When device update `interface_flags`, call the function
`set_interface_flags_full()`.

Signed-off-by: Wen Liang <liangwen12year@gmail.com>
2021-04-14 08:21:37 +02:00
Thomas Haller
5bc511203e all: make nm_steal_pointer() and g_steal_pointer() more typesafe using typeof()
The previous code would always cast the argument to "void *", and thus
loose some type information.

For example,

  gulong variable = 0;

  g_steal_pointer(&variable);

would compile, when it shouldn't.

In general, we try to avoid redefining glib macros and headers. But we
really want those extra compile time checks that we can get, so let's do
it.
2021-04-13 15:01:38 +02:00
Thomas Haller
0e9aa8001a audit: merge branch 'th/audit-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/812
2021-04-13 08:53:58 +02:00
Thomas Haller
3e393ccde3 audit: improve audit logging for setting NMDevice D-Bus objects
Previously, we would log:

  audit: op="device-autoconnect" arg="autoconnect" pid=282087 uid=0 result="success"
  audit: op="radio-control" arg="wimax-enabled" pid=559201 uid=0 result="success"

Now we log:

  audit: op="device-autoconnect" interface="eth0" ifindex=2 args="false" pid=443054 uid=0 result="success"
  audit: op="radio-control" arg="wimax-enabled:off" pid=629726 uid=0 result="success"
2021-04-12 16:47:37 +02:00
Thomas Haller
a5dfc46176 audit: pass and reuse NMStrBuf for build_message()
build_message() is an internal helper function with a very specific
purpose.

Let's change it to take an NMStrBuf argument for generating
the string. The advantage is that we don't need to allocate and
free the buffers in between, but can just reuse it.
2021-04-12 16:47:37 +02:00
Thomas Haller
c82b7c94c0 audit: don't use GValue for tracking values in AuditField struct
When using a GValue, we really should call g_value_unset(). Otherwise
it is a code smell, even if we technically only created GValue with
static strings and integers.

But changing that is not easy, because the AuditField structs are
allocated on the stack, and in different functions. So we cannot just
pass a GDestroyNotify to GPtrArray to cleanup all those fields, because
by then they will be out of scope.

The proper solution would be to heap allocate the AuditField struct, add
them to the GPtrArray, and free them with the free function. But that
seams really unnecessary overhead, for something that is correct in
practice. Let's accept the fact that by the time the fields array gets
destroyed, it contains dangling pointers.

If we already embrace the dangling pointers and that stuff is allocated
on the stack and that we don't need to free, also get rid of GValue
and use our plain NMValueType and NMValueTypUnion. GValue really doesn't
give us much here. And it only makes us wonder: is it OK to not call
g_value_unset()? With the plain tracking of the values, we know that
it is OK.
2021-04-12 16:46:02 +02:00
Thomas Haller
ba2bb8d741 audit: use NMStrBuf in audit's build_message() 2021-04-12 16:46:01 +02:00
Thomas Haller
ab3546b8e1 audit: fix using original file:line information for audit logging
With structured logging (journald), the file, line and func information
is relevant. Propagate the right value to the audit logging line.
2021-04-12 16:46:01 +02:00
Thomas Haller
1353a0e8da logging: add _nm_log_full() macro
_nm_log_impl() is the underlying implementation. As we have
multiple implementations, it's a bit confusing how it all works
together.

We thus should not call this directly, so that there are few (literal)
uses of this symbol.

Still, we may need to call this version of the logging statement,
because it's the only one that allows to provide the file location.

Add a wrapper macro for this, that callers can use.
2021-04-12 16:46:01 +02:00
Thomas Haller
7074fa0ef5 glib-aux: add nm_va_args_one_ptr() helper macro 2021-04-12 16:46:01 +02:00
Thomas Haller
9a2c47fc34 glib-aux: add int64/uint64 types to NMValueType 2021-04-12 16:46:00 +02:00
Thomas Haller
6107a94085 std-aux: add NM_UTILS_GET_NEXT_REALLOC_SIZE_232 define 2021-04-12 16:46:00 +02:00
Thomas Haller
e706769ee7 build: fix build dependency for systemd's fundamental for "config-extra.h"
$ make src/libnm-systemd-shared/src/fundamental/libnm_systemd_shared_la-string-util-fundamental.lo
    CC       src/libnm-systemd-shared/src/fundamental/libnm_systemd_shared_la-string-util-fundamental.lo
  In file included from ./src/libnm-glib-aux/nm-default-glib.h:11,
                   from ./src/libnm-systemd-shared/nm-default-systemd-shared.h:11,
                   from ./src/libnm-systemd-shared/sd-adapt-shared/nm-sd-adapt-shared.h:9,
                   from src/libnm-systemd-shared/src/fundamental/string-util-fundamental.c:3:
  ./src/libnm-std-aux/nm-default-std.h:32:10: fatal error: config-extra.h: No such file or directory
     32 | #include "config-extra.h"
        |          ^~~~~~~~~~~~~~~~
  compilation terminated.
  make: *** [Makefile:15660: src/libnm-systemd-shared/src/fundamental/libnm_systemd_shared_la-string-util-fundamental.lo] Error 1

Fixes: 2a88de2280 ('systemd: merge branch systemd into master')
2021-04-12 15:47:34 +02:00
Thomas Haller
6b64fac06d libnm: fix nm_device_set_autoconnect() to use correct D-Bus property name
Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')
2021-04-09 12:37:21 +02:00
Thomas Haller
79903065e4 nmtui: cleanup includes in "nmt-newt-utils.c" 2021-04-08 16:03:35 +02:00
Vojtech Bubela
6c9728d0d5 nmtui: support setting nmtui colors via environment variables
Previously, nmtui would set the newt color "checkbox" to a hard coded
value. This made it impossible to override the color via "$NEWT_COLORS".
With this change, nmtui also parses "$NEWT_COLORS" to allow setting
newt colors:

  $ NEWT_COLORS='
      window=white,red
      border=white,red
      checkbox=white,red
      actcheckbox=white,green
    ' nmtui

Custom nmtui colors can now also be set via "$NMT_NEWT_COLORS":

  "badLabel"
  "plainLabel"
  "disabledButton"
  "textboxWithBackground"

For example:

  $ NMT_NEWT_COLORS='plainLabel=green,lightgray' nmtui

The environment variables "$NEWT_COLORS_FILE" and "NMT_NEWT_COLORS_FILE"
are honored too.

The code is based on libnewt code ([1]), authored by Miroslav Lichvar.
That patch is originally LGPL-2.0-only licensed, but for inclusion in
NetworkManager we require it to be LGPL-2.1-or-later. Miroslav kindly
agreed to use his original contribution in NetworkManager.

[1] https://pagure.io/newt/c/34e56d12931a25222d7debb22f95bb2f9fa696a0

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>

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

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/793
2021-04-08 16:00:28 +02:00
Thomas Haller
3ce2dd4959 glib-aux: only evaluate arguments to NM_FLAGS_ALL() macro once
In many cases, macros should aim to be function-like. That is,
to evaluate all arguments and evaluate them exactly once.

Fix NM_FLAGS_ALL() to evaluate the "check" argument only once.

One downside of this change is that the result is no longer a compile
time constance and cannot be used to initialize static variables. But
that isn't used much anyway.
2021-04-07 14:36:46 +02:00
Javier Jardón
af360238be m4/ax_lib_readline.m4: Update after running aclocal
See-also: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/796
See-also: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/807
2021-04-07 09:17:17 +02:00
orbea
3affccf29b tests: fix undefined references to pthread
When building NetworkManger with --enable-tests or using 'make check'
and slibtool the build will fail in many places with undefined references
to pthreads.

This is because -lpthread is never explicitly added to the appropriate
variable, src_core_libNetworkManagerTest_la_LIBADD. When analyzing the
build log with GNU libtool it can be seen that it silently adds -pthread
on its own which hides the issue.

To solve this ax_pthread.m4 from the autoconf-archives project can be
used which provides the $(PTHREAD_LIBS) linker flag.

Source: https://github.com/autoconf-archive/autoconf-archive/blob/master/m4/ax_pthread.m4
See-also: https://www.gnu.org/software/autoconf-archive/ax_pthread.html

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/804
2021-04-07 08:29:50 +02:00
Thomas Haller
0d8fe37d64 dns: merge branch 'th/dns-minor-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/809
2021-04-07 07:58:21 +02:00
Thomas Haller
6d2a60b99c dns: use C99 static array indexes in function parameters for compute_hash() 2021-04-07 07:57:35 +02:00
Thomas Haller
44fbff63fc dns/trivial: add code comment 2021-04-07 07:57:35 +02:00
Thomas Haller
e38938b3db dns/trivial: rename "ip_configs_lst" to "ip_config_lst"
The "_lst" suffix already indicates that this is a list. We have
a list of ip-configs, so the prefix should be singular. It also matches
the "NMDnsConfigIPData.ip_config_lst" field.

The main reason for this renaming is that I want to search the file
for /ip_config_lst/ and find both the list head and the list elements.
2021-04-07 07:57:35 +02:00
Thomas Haller
821d2f645d dns: also log empty DNS info during _collect_resolv_conf_data() 2021-04-07 07:57:34 +02:00
Thomas Haller
1983f4c1e3 dns: use NMStrBuf in _collect_resolv_conf_data() 2021-04-07 07:57:31 +02:00