Commit Graph

27387 Commits

Author SHA1 Message Date
Thomas Haller
b9d4026f85 tools: improve detection of "ci-fairy" command in "tools/check-gitlab-ci.sh"
The previous implementation would print

    ./tools/check-gitlab-ci.sh: line 22: ci-fairy: command not found

also, it's not nice to execute the program, just to find out whether
we have it.
2020-12-11 16:08:47 +01:00
Thomas Haller
3c39ab8836 tests: skip "check-local-gitlab-ci" test on gitlab-ci 2020-12-11 16:08:47 +01:00
Thomas Haller
76f3cf41ac tests: allow to skip check-local-gitlab-ci via "$NMTST_SKIP_CHECK_GITLAB_CI"
This will be used on our gitlab-ci tests. We do have a separate,
dedicated test on gitlab-ci for checking that "gitlab-ci.yml" is
correct.

We may intentionally want to violate that condition, but then our
`make check` should not fail.

Add a way to skip that test.
2020-12-11 16:08:46 +01:00
Thomas Haller
e5699dbcb7 libnm: suppress "-Warray-bounds" warning in nm_team_link_watcher_new_ethtool()
gcc-11.0.0-0.7.fc34 warns here:

    CC       libnm-core/libnm_core_la-nm-setting-team.lo
  libnm-core/nm-setting-team.c: In function ‘nm_team_link_watcher_new_ethtool’:
  libnm-core/nm-setting-team.c:127:33: error: array subscript ‘NMTeamLinkWatcher[0]’ is partly outside array bounds of ‘unsigned char[16]’ [-Werror=array-bounds]
    127 |     watcher->ref_count          = 1;
        |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
  libnm-core/nm-setting-team.c:125:15: note: referencing an object of size 16 allocated by ‘g_malloc’
    125 |     watcher = g_malloc(nm_offsetofend(NMTeamLinkWatcher, ethtool));
        |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  libnm-core/nm-setting-team.c:128:33: error: array subscript ‘NMTeamLinkWatcher[0]’ is partly outside array bounds of ‘unsigned char[16]’ [-Werror=array-bounds]
    128 |     watcher->type               = LINK_WATCHER_ETHTOOL;
        |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
  libnm-core/nm-setting-team.c:125:15: note: referencing an object of size 16 allocated by ‘g_malloc’
    125 |     watcher = g_malloc(nm_offsetofend(NMTeamLinkWatcher, ethtool));
        |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  libnm-core/nm-setting-team.c:129:33: error: array subscript ‘NMTeamLinkWatcher[0]’ is partly outside array bounds of ‘unsigned char[16]’ [-Werror=array-bounds]
    129 |     watcher->ethtool.delay_up   = delay_up;
        |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
  libnm-core/nm-setting-team.c:125:15: note: referencing an object of size 16 allocated by ‘g_malloc’
    125 |     watcher = g_malloc(nm_offsetofend(NMTeamLinkWatcher, ethtool));
        |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  libnm-core/nm-setting-team.c:130:33: error: array subscript ‘NMTeamLinkWatcher[0]’ is partly outside array bounds of ‘unsigned char[16]’ [-Werror=array-bounds]
    130 |     watcher->ethtool.delay_down = delay_down;
        |     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
  libnm-core/nm-setting-team.c:125:15: note: referencing an object of size 16 allocated by ‘g_malloc’
    125 |     watcher = g_malloc(nm_offsetofend(NMTeamLinkWatcher, ethtool));
        |               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Maybe we should not use this trick and just malloc() a struct of the
intended size, however:

 - the code below does a similar thing, doing it differently for ethtool
   watcher is confusing.

 - the NMTeamLinkWatcher is a union which cannot alter its type. In no
   case is it correct to access the fields of the wrong union type. By
   allocating a smaller chunk, valgrind might catch such bugs.
   Also, NMTeamLinkWatcher's definition is private to the C source file,
   in no case must anybody assume that the rest of the buffer actually
   exists.

Hence, workaround the warning by suppressing it.
2020-12-11 16:08:46 +01:00
Thomas Haller
bba81ca13c libnm: merge branch 'th/ovs-external-ids-for-system-interface'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/702
2020-12-11 09:38:45 +01:00
Thomas Haller
9cc242596d libnm: allow OVS external-ids also for system interface
Note that reapply currently does not work for OVS system interface.
That is, because the code does not make it easy to implement that.
2020-12-11 09:38:16 +01:00
Thomas Haller
a9bc3eecc6 libnm: move detection/normalization of "connection.slave-type" to a separate function
We allow normalizing the slave-type, but sometimes, we may want to
validate a profile according to the set slave-type.

For example, a "ovs-external-ids" setting should only be allowed for
"connection.slave-type=ovs-interface". But during verify, the slave-type
may be missing and not yet normalized. We need to be able to obtain
the actually used slave-type.
2020-12-11 09:38:12 +01:00
Thomas Haller
e5b8fad96e build: merge branch 'maxice8:reallocarray-in-stdlib' into master
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/703
2020-12-10 12:36:45 +01:00
Leo
c992f460c7 build: check for reallocarray in stdlib.h 2020-12-10 12:36:38 +01:00
Leo
5e01c87cad build/meson: check for reallocarray in stdlib.h too
musl added support for reallocarray, but the function prototype is
declared in stdlib.h instead of malloc.h.

Update the check for reallocarray to check both in malloc.h and
stdlib.h.

https://man7.org/linux/man-pages/man3/reallocarray.3.html
2020-12-10 12:36:37 +01:00
Thomas Haller
8cadfed2fe wifi: fix evaluating the scanning state for wpa-supplicant
wpa_supplicant has a property "scanning" and a "state=scanning".
Previously, NetworkManager considered both parts to indicate whether
supplicant is currently scanning (if either the property or the state
indicated scanning, it took that as indication for scanning).

If NetworkManager thinks that supplicant is scanning, it suppresses
explicit "Scan" requests. That alone is not severe, because the "Scan"
request is only to trigger a scan in supplicant (which supplicant
possibly is already doing in state "scanning").

However, what is severe is that NetworkManager will also block autoconnect
while supplicant is scanning. That is because NetworkManager wants to get
a complete scan result before deciding which network to connect to.

It seems that wpa_supplicant can get into "state=scanning" and stay
there indefinitely. This prevents NetworkManager from autoactivating
a profile.

Fix that, to only honor the "scanning" property.

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

Fixes: b83f07916a ('supplicant: large rework of wpa_supplicant handling')
2020-12-10 12:01:12 +01:00
Thomas Haller
b012877445 libnm: add warning for bindings about broken functions for transferred GPtrArray
In commit 201c153e25 ('libnm: fix GObject Introspection annotations
for functions returning a GPtrArray') these annotations were changed
to fix Vala bindings. However, bindings may treat the transfer
annotation for GPtrArray differently, so depending on the binding
we either get a leak or a double free.

It's unclear how to fix that. For now, just add a warning to the
documentation to avoid it.

The following reproducer leads to a crash:

    #!/bin/python

    import gi

    gi.require_version("NM", "1.0")
    from gi.repository import NM

    def _pr(msg):
        NM.utils_print(0, msg + "\n")

    def process(nmc):
        for device in nmc.get_devices():
            cons = device.filter_connections(nmc.get_connections())
            _pr(
                "device %s (%s) has %s compatible connections"
                % (device.get_iface(), NM.Object.get_path(device), len(cons))
            )

    process(NM.Client.new())

See-also: https://gitlab.gnome.org/GNOME/gobject-introspection/-/issues/305
2020-12-09 17:50:22 +01:00
Thomas Haller
d0a4661b65 keyfile: fix error message on failure to generate filename in _internal_write_connection() 2020-12-09 10:30:13 +01:00
Thomas Haller
3490a09a7d shared: fix race in nm_ref_string_unref()
We cannot drop the reference count to zero while having
no lock. Otherwise, another thread might race doing

  s = nm_ref_string_new("...");
  nm_ref_string_unref(s);

and already successfully delete the instance.

Hitting this race should be rather difficult, especially because
we tend to use NMRefString only from one thread. But still, access
to global variables must be race free.

Fixes: 908fadec96 ('shared: add NMRefString')
2020-12-08 20:07:10 +01:00
Thomas Haller
ef6edd8dbd libnm: fix re-entrancy of NMClient.dispose() for _init_release_all()
GObject's dispose() functions may be called multiple times
to break reference cycles.

As dispose() calls _init_release_all(), the object might
already be partially destroyed.

Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')
2020-12-08 15:41:52 +01:00
Thomas Haller
dcd0066b10 libnm: add debug logging for creating/destroying NMObject 2020-12-07 22:15:46 +01:00
Beniamino Galvani
e5113a7fd9 ovs: clean up interfaces from ovsdb at startup
During shutdown, NM always tries to remove from ovsdb all bridges,
ports, interfaces that it previously added. Currently NM doesn't run
the main loop during shutdown and so it's not possible to perform
asynchronous operations. In particular, the NMOvsdb singleton is
disposed in a destructor where it's not possible to send out all the
queued deletions.

The result is that NM deletes only one OVS interface, keeping the
others. This needs to be fixed, but requires a rework of the shutdown
procedure that involves many parts of NM.

Even when a better shutdown procedure will be implemented, we should
support an unclean shutdown caused by e.g. a kernel panic or a NM
crash. In these cases, the interfaces added by NM would still linger
in the ovsdb.

Delete all those interface at NM startup. If there are connections
profiles for them, NM will create them again.

https://bugzilla.redhat.com/show_bug.cgi?id=1861296
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/700
2020-12-07 13:57:17 +01:00
Thomas Haller
f1f10e4eb6 NEWS: belatedly mention systemd-resolved change in NEWS 2020-12-07 13:35:46 +01:00
Thomas Haller
507c7c2b8a release: bump version to 1.29.5 (development) 2020-12-06 16:17:48 +01:00
Thomas Haller
ae5ea7fa62 contrib/release: check NEWS file before release 2020-12-06 16:03:34 +01:00
Thomas Haller
6f32c5c107 release: bump version to 1.28.0 2020-12-06 15:07:17 +01:00
Thomas Haller
76bdde147f l3cfg: avoid "-Werror=maybe-uninitialized" warning in _load_link()
It's not actually an issue, but the compiler might think that
we use nacd_old_addr without initialization.

(cherry picked from commit cd0e328f7e)
2020-12-06 14:41:39 +01:00
Thomas Haller
cd0e328f7e l3cfg: avoid "-Werror=maybe-uninitialized" warning in _load_link()
It's not actually an issue, but the compiler might think that
we use nacd_old_addr without initialization.
2020-12-06 14:40:28 +01:00
Thomas Haller
903f8728b9 contrib/rpm: drop no longer supported "--enable-json-validation" from configure
Fixes: bbb1f5df2f ('libnm: always build libnm with JSON validation')
(cherry picked from commit a8ead4a4c3)
2020-12-06 11:39:41 +01:00
Thomas Haller
c9898dc9ae contrib/rpm: update default for main.plugins setting in NetworkManager.conf
With Fedora 33+ and RHEL 9+, the default plugins are
"plugins=keyfile,ifcfg-rh", instead of "plugins=ifcfg-rh,keyfile".

Update our "NetworkManager.conf" file to reflect that.
2020-12-06 11:23:46 +01:00
Thomas Haller
d0643fbf3b policy: remove unused code from "nm-policy.c" for reverse DNS lookup for hostname
By now, each NMDevice does the reverse lookup and caches the result
via nm_device_get_hostname_from_dns_lookup().

The code is no longer used in NMPolicy.

Fixes: 09c8387114 ('policy: use the hostname setting')
2020-12-04 09:32:32 +01:00
Thomas Haller
a3f2cee0e6 contrib/rpm: support default options for debug,test in generated spec file
"build_clean.sh" (and "build.sh") scripts can both create a source
tarball (via `make dist`/`make distcheck`), an SRPM (and a spec file),
or build RPMs from the SRPM.

Note that the generated spec file has various options, like

    %bcond_without nmtui
    %bcond_without debug
    %bcond_without test

When building an RPM from the SRPM, you can specify the "--with" or
"--without" option for rpmbuild. This is also what the "-w" / "-W" options
for "build_clean.sh" do.

However, the SRPM still has the intrinsic defaults, and if you later
build an RPM from it, you would have to pass "--with" / "--without"
to rpmbuild.

Often that is not conveniently possible, for example, when you build the
SRPM in koji.

Extend the scripts so that also the defaults for "-w debug" and "-w
test" can be specified when generating the SRPM. You can do that with
the new options "--default-for-{debug,test}" to "build_clean.sh".

Alternatively, it suffices to specify the previously supported
"-w" / "-W" options. That way, we will pass those options to rpmbuild,
but also set them as defaults in the generate spec file. The new
options "--default-for-{debug,test}" are only needed if you want
the default in the spec file to be different then what you use
when creating the SRPM.
2020-12-03 17:38:06 +01:00
Thomas Haller
3bf367594a contrib/rpm: add "--no-auto-with-test" option for "build_clean.sh" script
By default, "build_clean.sh" script likes to automatically add "-w test"
-- unless the user specified "-w test" or "-W test" on the command line.

That is mostly fine. However, the spec file has an internal default for the
"test" option. So if you want to use the default that gets determined
by the spec file, then we should suppress that automatism.
2020-12-03 17:34:01 +01:00
Thomas Haller
a8ead4a4c3 contrib/rpm: drop no longer supported "--enable-json-validation" from configure
Fixes: bbb1f5df2f ('libnm: always build libnm with JSON validation')
2020-12-03 17:31:30 +01:00
Thomas Haller
abccc8b8fe build: ignore "docs/api/NetworkManager.actions" build artifact
I still don't understand why we get now these ".actions" build
artifacts. Anyway, I don't think we need to care. Just ignore
it.
2020-12-03 17:31:30 +01:00
Thomas Haller
3ee35a3906 core: fix warning about unused variable in _l3_acd_data_add_all()
src/nm-l3cfg.c: In function _l3_acd_data_add_all:
    src/nm-l3cfg.c:1557:14: error: unused variable i [-Werror=unused-variable]
     1557 |     guint    i;
          |              ^
2020-12-03 14:54:15 +01:00
Thomas Haller
952e3ebbe4 release: bump version to 1.29.4 (development) 2020-12-03 13:38:19 +01:00
Thomas Haller
8ff4625db9 man: better explain default connection settings in man NetworkManager.conf 2020-12-03 08:44:26 +01:00
Beniamino Galvani
5b9479a728 policy: fix hostname lookup from DNS
Fixes: 09c8387114 ('policy: use the hostname setting')
2020-12-02 17:33:45 +01:00
Fernando Fernandez Mancera
fda6b702ba veth: peer property is D-Bus object path not a string
Signed-off-by: Fernando Fernandez Mancera <ffmancera@riseup.net>
2020-12-01 16:45:36 +01:00
Beniamino Galvani
dedcba61ef dns: sd-resolved: fix hash table iteration
g_hash_table_iter_next() wants a (gpointer *), not an (int *).

Fixes: f70ee67058 ('dns: sd-resolved: reset interface configuration on deactivation')
(cherry picked from commit 526b484be1)
2020-11-30 23:04:37 +01:00
Beniamino Galvani
526b484be1 dns: sd-resolved: fix hash table iteration
g_hash_table_iter_next() wants a (gpointer *), not an (int *).

Fixes: f70ee67058 ('dns: sd-resolved: reset interface configuration on deactivation')
2020-11-30 22:36:55 +01:00
Beniamino Galvani
d0df9bf0bd manager: return most recent connection in active_connection_find()
When a connection is reactivated, there could be two active
connections tracked by the manager: the deactivating one and the new
one. Ensure that we first return the most recent one so that slaves
will pick the right master.

Fixes-test: @iptunnel_gretap_doc_procedure
Fixes: dc6ec6ce7b ('core: reverse the order of active connections in the manager')
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/697
2020-11-30 14:43:22 +01:00
Yuri Chornoivan
587a1949b2 po: update Ukrainian (uk) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/698
2020-11-30 14:38:45 +01:00
Beniamino Galvani
b24ec6af04 release: bump version to 1.29.3 (development) 2020-11-27 15:33:07 +01:00
Thomas Haller
e749a1a5db dns: merge branch 'th/dns-resolved-default-route'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/694

(cherry picked from commit bb9dcde97f)
2020-11-27 10:54:46 +01:00
Thomas Haller
c182984469 dns: detect support of systemd-resolved's SetLinkDefaultRoute() and avoid it
We now always use SetLinkDefaultRoute(), but that API was only added in
systemd v240 ([1]).

We could just always call the non-existing method, and ignore the
error. However, that feels ugly. Would systemd-resolved log warnings
about that? Should we suppress all messages about that failure (not
good for debugging).

Instead, make an effort to detect support of the function, and avoid
calling it. That is significantly more complicated than just always
calling the method and not care.

Note that even if systemd-resolved does not support SetLinkDefaultRoute(),
we cannot do anything smart about that. We would simply rely on
systemd-resolved (hopefully) doing the right thing automatically.
That's better and simpler than explicitly adding a "~." domain in
the fallback case.

Also, detecting support is straight forward in the common case, where
there is either success or a clear "org.freedesktop.DBus.Error.UnknownMethod"
error. In cases where there is any other failure, we don't really know.
In that case, we keep trying to use the API under the assumption that
it should work.

[1] https://github.com/systemd/systemd/commit/7 ## 7673795dcf5797491e7f785cbf5077d29a15db4

(cherry picked from commit 44ebb99cfa)
2020-11-27 10:54:45 +01:00
Thomas Haller
3f16b988a4 dns: preserve DNS settings for systemd-resolved to resend
When the DNS settings change, we update the request_queue_lst_head list,
with all the requests we want to send.

Then, send_updates() will try to send it. It might not do it right away,
if resolved is not on the bus or the D-Bus connection is not fully inialized
(meaning, we don't know the name owner yet). In those cases, we would
keep the list of requests, and send them later.

However, when sending them, we would also forget about the configuration.

That means, if you restart systemd-resolved, then the daemon drops off
the bus and reappears. I think that systemd-resolved in fact persists
the configuration during restart. So, usually the settings are still the
same after restart. However, we should do better here: if the service
appears, we should send the settings again.

This means to not forget the requests after we send them once -- at
least, until a new update replaces them.

(cherry picked from commit 4fc44952f7)
2020-11-27 10:54:45 +01:00
Thomas Haller
3cb7b3a8a2 dns: minor cleanup of call_done() in "nm-dns-systemd-resolved.c"
(cherry picked from commit 42d47d1cd7)
2020-11-27 10:54:45 +01:00
Thomas Haller
4401c6d567 dns: cleanup RequestItem and track ifindex and self parameter
We will need these changes next:

- add "self" and "ifindex" fields to RequestItem struct. We will
  pass on these structs are user-data for the callbacks, so that
  we afterwards know which request completed.

- add DBUS_OP_SET_LINK_DEFAULT_ROUTE global variable. We don't
  clone the "operation" string but use string literals. However,
  string literals are not guaranteed to be deduplicated, so we
  should only compare them with strcmp(). The static variable
  avoids this: we can use pointer equality to compare it.
  This will be used next.

(cherry picked from commit 8af6647cda)
2020-11-27 10:54:45 +01:00
Thomas Haller
bb9dcde97f dns: merge branch 'th/dns-resolved-default-route'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/694
2020-11-27 10:47:05 +01:00
Thomas Haller
44ebb99cfa dns: detect support of systemd-resolved's SetLinkDefaultRoute() and avoid it
We now always use SetLinkDefaultRoute(), but that API was only added in
systemd v240 ([1]).

We could just always call the non-existing method, and ignore the
error. However, that feels ugly. Would systemd-resolved log warnings
about that? Should we suppress all messages about that failure (not
good for debugging).

Instead, make an effort to detect support of the function, and avoid
calling it. That is significantly more complicated than just always
calling the method and not care.

Note that even if systemd-resolved does not support SetLinkDefaultRoute(),
we cannot do anything smart about that. We would simply rely on
systemd-resolved (hopefully) doing the right thing automatically.
That's better and simpler than explicitly adding a "~." domain in
the fallback case.

Also, detecting support is straight forward in the common case, where
there is either success or a clear "org.freedesktop.DBus.Error.UnknownMethod"
error. In cases where there is any other failure, we don't really know.
In that case, we keep trying to use the API under the assumption that
it should work.

[1] https://github.com/systemd/systemd/commit/7 ## 7673795dcf5797491e7f785cbf5077d29a15db4
2020-11-27 10:46:42 +01:00
Thomas Haller
4fc44952f7 dns: preserve DNS settings for systemd-resolved to resend
When the DNS settings change, we update the request_queue_lst_head list,
with all the requests we want to send.

Then, send_updates() will try to send it. It might not do it right away,
if resolved is not on the bus or the D-Bus connection is not fully inialized
(meaning, we don't know the name owner yet). In those cases, we would
keep the list of requests, and send them later.

However, when sending them, we would also forget about the configuration.

That means, if you restart systemd-resolved, then the daemon drops off
the bus and reappears. I think that systemd-resolved in fact persists
the configuration during restart. So, usually the settings are still the
same after restart. However, we should do better here: if the service
appears, we should send the settings again.

This means to not forget the requests after we send them once -- at
least, until a new update replaces them.
2020-11-27 10:46:42 +01:00
Thomas Haller
42d47d1cd7 dns: minor cleanup of call_done() in "nm-dns-systemd-resolved.c" 2020-11-27 10:46:42 +01:00
Thomas Haller
8af6647cda dns: cleanup RequestItem and track ifindex and self parameter
We will need these changes next:

- add "self" and "ifindex" fields to RequestItem struct. We will
  pass on these structs are user-data for the callbacks, so that
  we afterwards know which request completed.

- add DBUS_OP_SET_LINK_DEFAULT_ROUTE global variable. We don't
  clone the "operation" string but use string literals. However,
  string literals are not guaranteed to be deduplicated, so we
  should only compare them with strcmp(). The static variable
  avoids this: we can use pointer equality to compare it.
  This will be used next.
2020-11-27 10:26:11 +01:00