Commit Graph

25044 Commits

Author SHA1 Message Date
Thomas Haller
0931c4f2ea Revert "platform: fix GCC warning about zero-lenght array (2)"
This reverts commit 5076fc0ca0.
2020-02-10 11:26:59 +01:00
Thomas Haller
1fd7e45139 Revert "platform: fix GCC warning about zero-lenght array (1)"
I think this solution is not right, because "char buf" is not guaranteed
to have the correct alignment. Revert, and solve it differently.

This reverts commit 6345a66153.
2020-02-10 11:26:59 +01:00
Thomas Haller
bdd45e6afa contrib/REQUIRED_PACKAGES: ignore for non-existing packages "dbus-python", "pygobject3-base" on Fedora 32
These packages no longer exist on Fedora 32 and dnf fails due to
that. Ignore such errors.
2020-02-10 11:18:51 +01:00
Beniamino Galvani
623a1e1f99 ovs: wait that link disappears before continuing with deactivation
When we deactivate a virtual device, we usually schedule the deletion
of the link in an idle handler. That action will be executed at a
later time when the device is already in the disconnected state.

Similarly, for ovs interfaces we send the deletion command to the
ovsdb and then proceed to the disconnected state.

However, in the first case there is the guarantee that the link will
be deleted at some point, while for ovs interfaces it may happen that
ovs decides to reuse the same link if there is an addition
queued. Since reusing the same link confuses NM, let's implement
deactivate_async() for ovs-interfaces and wait that the link actually
goes away before proceeding.

https://bugzilla.redhat.com/show_bug.cgi?id=1782701
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/402
2020-02-05 22:31:21 +01:00
Beniamino Galvani
7f801685b2 shared: redefine G_SOURCE_FUNC
G_SOURCE_FUNC has attribute GLIB_AVAILABLE_MACRO_IN_2_58, which means
that the compiler will emit a warning when GLIB_VERSION_MAX_ALLOWED <
GLIB_VERSION_2_58. We currently define GLIB_VERSION_MAX_ALLOWED as
GLIB_VERSION_2_40. Redefine the macro to fix the following build error
when using glib >= 2.63.5 (the version in which the attribute was
added):

  CC       shared/nm-glib-aux/libnm_glib_aux_la-nm-shared-utils.lo
 shared/nm-glib-aux/nm-shared-utils.c: In function ‘nm_g_unix_fd_source_new’:
 shared/nm-glib-aux/nm-shared-utils.c:3679:13: error: Not available before  [-Werror]
  3679 |  g_source_set_callback (source, G_SOURCE_FUNC (source_func), user_data, destroy_notify);

Fixes: 9c5741ccd2 ('shared/nm-glib: add compat implementation for G_SOURCE_FUNC()')
2020-02-05 14:31:46 +01:00
Beniamino Galvani
9a971849b5 merge: branch 'bg/gcc10'
Fix build using GCC 10.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/406
2020-02-03 15:27:39 +01:00
Beniamino Galvani
b2620e798a n-dhcp4: fix uninitialized variable
Properly initialize 'overload' when the space in the file section
ends.

 shared/n-dhcp4/src/n-dhcp4-outgoing.c: In function ‘n_dhcp4_outgoing_append’:
 shared/n-dhcp4/src/n-dhcp4-outgoing.c:198:17: error: ‘overload’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
2020-02-03 11:00:34 +01:00
Beniamino Galvani
f3baa7b1d5 ifcfg-rh: add missing 'extern' keyword
Add missing 'extern' keyword to fix the following error caused by GCC
10 defaulting to -fno-common:

 src/settings/plugins/ifcfg-rh/.libs/libnms-ifcfg-rh-core.a(libnms_ifcfg_rh_core_la-shvar.o):/root/NetworkManager/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h:36: multiple definition of `nms_ifcfg_well_known_keys';
 src/settings/plugins/ifcfg-rh/.libs/libnm_settings_plugin_ifcfg_rh_la-nms-ifcfg-rh-plugin.o:/root/NetworkManager/src/settings/plugins/ifcfg-rh/nms-ifcfg-rh-utils.h:36: first defined here
2020-02-03 11:00:34 +01:00
Beniamino Galvani
482e5f04ea clients: add missing 'extern' keyword 2020-02-03 11:00:34 +01:00
Beniamino Galvani
5076fc0ca0 platform: fix GCC warning about zero-lenght array (2)
GCC 10 complains about accesses to elements of zero-length arrays that
overlap other members of the same object:

  src/platform/nm-platform-utils.c: In function ‘nmp_utils_ethtool_get_permanent_address’:
  src/platform/nm-platform-utils.c:854:29: error: array subscript 0 is outside the bounds of an interior zero-length array ‘__u8[0]’ {aka ‘unsigned char[0]’} [-Werror=zero-length-bounds]
    854 |  if (NM_IN_SET (edata.e.data[0], 0, 0xFF)) {
  ./shared/nm-glib-aux/nm-macros-internal.h:731:20: note: in definition of macro ‘_NM_IN_SET_EVAL_N’

Fix this warning.
2020-02-03 11:00:34 +01:00
Beniamino Galvani
6345a66153 platform: fix GCC warning about zero-lenght array (1)
GCC 10 complains about accesses to elements of zero-length arrays that
overlap other members of the same object:

 src/platform/nm-platform-utils.c: In function ‘ethtool_get_stringset’:
 src/platform/nm-platform-utils.c:355:27: error: array subscript 0 is outside the bounds of an interior zero-length array ‘__u32[0]’ {aka ‘unsigned int[0]’} [-Werror=zero-length-bounds]
   355 |  len = sset_info.info.data[0];
       |        ~~~~~~~~~~~~~~~~~~~^~~
 In file included from src/platform/nm-platform-utils.c:12:
 /usr/include/linux/ethtool.h:647:8: note: while referencing ‘data’
   647 |  __u32 data[0];
       |        ^~~~

Fix this warning.
2020-02-03 11:00:34 +01:00
Beniamino Galvani
207e971863 build: remove duplicate definition in Makefile
Fix the following warning:

 Makefile.am:3671: warning: $(src_devices_wifi_libnm_device_plugin_wifi_la_OBJECTS) was already defined in condition TRUE, which includes condition WITH_WIFI ...
 Makefile.am:1075: ... '$(src_devices_wifi_libnm_device_plugin_wifi_la_OBJECTS)' previously defined here
2020-02-03 11:00:34 +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
Beniamino Galvani
c11ac34f4c all: remove wrong CURL option initialization
curl_multi_setopt() accepts CURLMOPT_* options, not CURLOPT_*
ones. Found by GCC 10:

clients/cloud-setup/nm-http-client.c:700:38: error: implicit conversion from ‘enum <anonymous>’ to ‘CURLMoption’ [-Werror=enum-conversion]
  700 |    curl_multi_setopt (priv->mhandle, CURLOPT_VERBOSE, 1);

Fixes: 69f048bf0c ('cloud-setup: add tool for automatic IP configuration in cloud')
2020-02-01 11:38:08 +01:00
Beniamino Galvani
3d03900e91 platform: skip VRF test if kernel support is missing
Fixes: 7c73c6a038 ('platform: add VRF support')
2020-01-31 15:45:04 +01:00
Beniamino Galvani
fc7af10cca dhcp: merge branch 'bg/dhcp-timeout-rh1791378'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/404/diffs
https://bugzilla.redhat.com/show_bug.cgi?id=1791378
2020-01-30 15:26:06 +01:00
Beniamino Galvani
d8e1f4c8ef ndisc: remove upper bound for IPv6 autoconfiguration timeout
As it is possible to configure an arbitrarily large DHCP timeout, it
should be possible to also set a large timeout for IPv6
autoconfiguration. Currently the timeout can only be changed via
sysctl. Leave the lower bound because the default kernel sysctl value
is 3 * 4 = 12 seconds and so without the lower limit the default
timeout would change from 30 to 12 seconds for every user, which seems
a big change and could possibly break users' setup.

https://bugzilla.redhat.com/show_bug.cgi?id=1795957
2020-01-30 15:23:04 +01:00
Beniamino Galvani
df75c21b4d device: accept new leases in NM_DEVICE_IP_STATE_DONE
If the current lease expires, we start the grace period in which the
clients starts again from the INIT DHCP state (i.e. sending DISCOVER
messages). If it is able to obtain a new lease, it must be accepted or
otherwise the client will not renew it.
2020-01-30 15:23:04 +01:00
Beniamino Galvani
a4ddb56923 dhcp: introduce EXTENDED state for renewals
Currently the DHCP client reports the BOUND state not only when the
lease is obtained initially but also when it is renewed. Having a
different state for the renewal will be used by NMDevice in the next
patch to determine whether the lease needs to be accept()ed or not.
2020-01-30 15:23:04 +01:00
Beniamino Galvani
182a8021f3 n-dhcp4: move back to INIT after lease expires
Move back to INIT state after the lease expires, as per section 4.4.5
of RFC 2131. Previously the client just moved to EXPIRED, closed the
connection and cleared the probe, leaving to the caller of the library
the choice to create a new client instance and to start from
scratch. However, it seems more useful that the client, once
initialized, always tries to get a lease even after an expiration.
2020-01-30 15:23:04 +01:00
Beniamino Galvani
aee78ca788 dhcp: derive the grace period duration from the timeout property
Currently the duration of the DHCP grace period (in which we try to
acquire a new lease after expiration) is hardcoded to 480
seconds. That value seems arbitrary and too long for the default
configuration. Since we already have a property that allows the user
to configure how long NM should try to get the lease initially, it
makes sense to use it also for retries after lease expirations.

In particular, setting the ipvx.dhcp-timeout to a high value extends
also the grace period to a very long time, potentially forever.
2020-01-30 15:23:04 +01:00
Beniamino Galvani
d0caad7a8d device: change return type of get_dhcp_timeout() 2020-01-30 15:23:04 +01:00
Beniamino Galvani
70f1ee0ffb device: move code around 2020-01-30 15:23:04 +01:00
Beniamino Galvani
e3a3e8bd51 po: RHEL 8.2 translations - fr,ja,zh-CN 2020-01-30 13:51:43 +01:00
Thomas Haller
c106008091 supplicant: fix memory corruption with wrong argument to NM_SUPPLICANT_INTERFACE_GROUP_FORMATION_FAILURE signal
The signal is unused (and should be removed).

Still, the parameter passed to g_signal_emit() is a C string, not a
GVariant. I think as there are no subscribers, glib wouldn't actually
do anything with the arguments. Though, I am not sure whether glib still
tries to initialize a GValue with a GVariant type, leading to a crash.

Fixes: f05b7a78c9 ('supplicant: Track P2P Group information, creation and destruction')
2020-01-30 11:39:42 +01:00
Antonio Cardace
1ccdce0c1d man: fix missing tag 2020-01-29 17:32:47 +01:00
Antonio Cardace
7ef684b1b3 man: add dnsmasq option documentation on added dns servers 2020-01-29 17:25:21 +01:00
Antonio Cardace
d450c07a31 git: ignore clangd and ctags generated files 2020-01-29 17:25:21 +01:00
Beniamino Galvani
4bdf8c31d3 merge: branch 'bg/virt-dev-check-master'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/403
https://bugzilla.redhat.com/show_bug.cgi?id=1795919
2020-01-29 16:43:39 +01:00
Beniamino Galvani
ab57b575a0 manager: check for master existence before realizing the device
If we find out that no compatible master connection exists, we
shouldn't realize the slave in the first place.
2020-01-29 16:43:19 +01:00
Beniamino Galvani
336bfcabc4 manager: skip activation of a virtual device if master is missing
Don't realize a virtual device if the master is missing because in
such case the autoactivation can't start and a stale link will be
created.
2020-01-29 16:43:19 +01:00
Will Dietz
2b17f246f0 build/meson: fix missing slash when detecting resolvconf/netconfig binaries
Fix detection for /usr/local/sbin/{resolvconf,netconfig}.
(and no longer automatically use "/usr/local/sbinnetconfig" if present)

Fixes: 5a0cef2f36 ('build: meson: uniform handling of rc managers')

[thaller@redhat.com: commit message adjusted]

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/349
2020-01-28 16:10:27 +01:00
Thomas Haller
89c8a47047 core: fix device detection due to bug in NM_DEVICE_DEFINE_LINK_TYPES()
Fixes: 86787e0278 ('core: improve implementation of NM_DEVICE_DEFINE_LINK_TYPES() macro')
2020-01-28 14:38:47 +01:00
Thomas Haller
19d0b035dd all: merge branch 'th/inet-addr-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/389
2020-01-28 11:51:49 +01:00
Thomas Haller
07b66da4a1 core: cleanup setting IP address in NMDeviceIPTunnel 2020-01-28 11:43:22 +01:00
Thomas Haller
228519fe79 shared: add nm_ip_addr_cmp()/nm_ip_addr_equal() helpers 2020-01-28 11:43:22 +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
cdfbbe651b shared: add nm_utils_ipaddr_is_valid()/nm_utils_ipaddr_is_normalized() helpers 2020-01-28 11:17:41 +01:00
Thomas Haller
0f9664f417 shared: use static array indices in function parameter declarations of _nm_utils_inet[46]_ntop()
This should give the compiler more possibilities to warn about wrong
use of the API.

In practice, my current compiler wouldn't flag any issues. However,
some compilers (or compile options) might.
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
06d6de95d6 platform: use IN6_IS_ADDR_UNSPECIFIED() to check for set IPv6 address in _nl_msg_new_link_set_linkinfo() 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
8590d2ecfb libnm/secret-agent: merge branch 'th/secret-agent-rework'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/383
2020-01-28 11:07:59 +01:00
Thomas Haller
c1ec829099 libnm/secret-agent: rework NMSecretAgentOld
Note that the name "NMSecretAgentOld" comes from when libnm was forked
from libnm-glib. There was a plan to rework the secret agent API and
replace it by a better one. That didn't happen (yet), instead our one
and only agent implementation is still lacking. Don't add a new API, instead
try to improve the existing one, without breaking existing users. Just
get over the fact that the name "NMSecretAgentOld" is ugly.

Also note how nm-applet uses NMSecretAgentOld. It subtypes a class
AppletAgent. The constructor applet_agent_new() is calling the synchronous
g_initable_init() initialization with auto-register enabled. As it was,
g_initable_init() would call nm_secret_agent_old_register(), and if the
"Register" call failed, initialization failed for good. There are even
unit tests that test this behavior. This is bad behavior. It means, when
you start nm-applet without NetworkManager running, it will fail to create
the AppletAgent instance. It would hence be the responsibility of the applet
to recover from this situation (e.g. by retrying after timeout or watching
the D-Bus name owner). Of course, nm-applet doesn't do that and won't recover
from such a failure.
NMSecretAgentOld must try hard not to fail and recover automatically. The
user of the API is not interested in implementing the registration,
unregistration and retry handling. Instead, it should just work best
effort and transparently to the user of the API.

Differences:

- no longer use gdbus-codegen generate bindings. Use GDBusConnection
  directly instead. These generated proxies complicate the code by
  introducing an additional, stateful layer.

- properly handle GMainContext and synchronous initialization by using an
  internal GMainContext.
  With this NMSecretAgentOld can be used in a multi threaded context
  with separate GMainContext. This does not mean that the object
  itself became thread safe, but that the GMainContext gives the means
  to coordinate multi-threaded access.

- there are no more blocking calls except g_initiable_init() which
  iterates an internal GMainContext until initialization completes.

- obtaining the Unix user ID with "GetConnectionUnixUser" to authenticate
  the server is now done asynchronously and only once per name-owner.

- NMSecretAgentOld will now register/export the Agent D-Bus object
  already during initialization and stay registered as long as the
  instance is alive. This is because usually registering a D-Bus
  object would not fail, unless the D-Bus path is already taken.
  Such an error would mean that another agent is registered for the same
  GDBusConnection, that likely would be a bug in the caller. Hence,
  such an issue is truly non-recoverable and should be reported early to
  the user. There is a change in behavior compared to before, where previously
  the D-Bus object would only be registered while the instance is enabled.
  This makes a difference if the user intended to keep the NMSecretAgentOld
  instance around in an unregistered state.
  Note that nm_secret_agent_old_destroy() was added to really unregister
  the D-Bus object. A destroyed instance can no longer be registered.

- the API no longer fully exposes the current registration state. The
  user either enables or disables the agent. Then, in the background
  NMSecretAgentOld will register, and serve requests as they come. It
  will also always automatically re-register and it can de-facto no
  longer fail. That is, there might be a failure to register, or the
  NetworkManager peer might not be authenticated (non-root) or there
  might be some other error, or NetworkManager might not be running.
  But such errors are not exposed to the user. The instance is just not
  able to provide the secrets in those cases, but it may recover if the
  problem can be resolved.

- In particular, it makes no sense that nm_secret_agent_old_register*()
  fails, returns an error, or waits until registration is complete. This
  API is now only to enable/disable the agent. It is idempotent and
  won't fail (there is a catch, see next point).
  In particular, nm_secret_agent_old_unregister*() cannot fail anymore.

- However, with the previous point there is a problem/race. When you create
  a NMSecretAgentOld instance and immediately afterwards activate a
  profile, then you want to be sure that the registration is complete
  first. Otherwise, NetworkManager might fail the activation because
  no secret agent registered yet. A partial solution for this is
  that g_initiable_init()/g_async_initable_init_async() will block
  until registration is complete (or with or without success). That means,
  if NetworkManager is running, initializing the NMSecretAgentOld will
  wait until registration is complete (or failed). However, that does not
  solve the race if NetworkManager was not running when creating the
  instance.
  To solve that race, the user may call nm_secret_agent_old_register_async()
  and wait for the command to finish before starting activating. While
  async registration no longer fails (in the sense of leaving the agent
  permanently disconnected), it will try to ensure that we are
  successfully registered and ready to serve requests. By using this
  API correctly, a race can be avoided and the user can know that the
  instance is now ready to serve request.
2020-01-28 10:54:14 +01:00
Thomas Haller
2c30c1a04f libnm/secret-agent: add dbus-connection and main-context properties to NMSecretAgentOld
The NMSecretAgentOld is build very much around a GDBusConnection, and GDBusConnection
is build around GMainContext. That means, a NMSecretAgentOld instance is
strongly related to these two. That is because NMSecretAgentOld will register
to signals on D-Bus, using GDBusConnection. Hence, that GDBusConnection instance
and the calling GMainContext becomes central to the NMSecretAgentOld instance.
Also, the GMainContext is the way to synchronize access to the
NMSecretAgentOld. Used properly, this allows using the API in multi
threaded context.

Expose these two in the public API. Since NMSecretAgentOld is part of
libnm and supposed to provide a flexible API, this is just useful to
have.

Also, allow to provide a GDBusConnection as construct-only property. This way,
the instance can be used independent of g_bus_get() and the user has full control.

There is no setter for the GMainContext, because it just takes the
g_main_context_get_thread_default() instance at the time of
construction.
2020-01-28 10:54:14 +01:00
Thomas Haller
0382e54d8d libnm: expose nml_cleanup_context_busy_watcher_on_idle() helper for reuse
This can be used by NMSecretAgentOld.
2020-01-28 10:54:14 +01:00