Commit graph

22102 commits

Author SHA1 Message Date
Thomas Haller
93c848ca03 clients: don't tread secret agent as NMSecretAgentOld
Most of the times we actually need a NMSecretAgentSimple typed pointer.
This way, need need to cast less.

But even if we would need to cast more, it's better to have pointers
point to the actual type, not merely to avoid shortcomings of C.
2019-02-05 08:27:42 +01:00
Thomas Haller
82472c557c clients/secret-agent: use nm-utils error reason for callback while disposing NMSecretAgentSimple
No caller cared about the NM_SECRET_AGENT_ERROR_AGENT_CANCELED reason.
In particular, because previously the requests would keep the secret-agent
instance alive, and this never happend.

Also, NM_SECRET_AGENT_ERROR_AGENT_CANCELED precicley exists for
NMSecretAgentOld:cancel_get_secrets() (as documented). During finalize
we are not cancelled -- at least not the same way as
cancel_get_secrets(). Setting NM_SECRET_AGENT_ERROR_AGENT_CANCELED
is wrong.

Anyway, we have a default error for such cases already.
2019-02-05 08:27:42 +01:00
Thomas Haller
d68bdce206 clients/secret-agent: minor cleanup of child-watch-id for secret-agent
The code was correct. But it's hard to follow when and whether
the child-watch-id was destroyed at the right time.

Instead, always let _auth_dialog_data_free() clear the signal handlers.
2019-02-05 08:27:42 +01:00
Thomas Haller
8b951afac9 clients/secret-agent: don't let request keep secret-agent alive
Don't let RequestData keep the parent NMSecretAgentSimple instance
alive. Previously, the code in finalize() was never actually reached.

Also, move the final callback from finalize() to dispose(). It feels
wrong to invoke callbacks from finalize().
2019-02-05 08:27:42 +01:00
Thomas Haller
16e0f38c3e clients/secret-agent: cancel pending operations
We must actually cancel the GCancellable. Otherwise, the pending async
operations are not cancelled. _auth_dialog_write_done() doesn't care
about that, but _auth_dialog_read_done() does. It must not touch the
destroyed data, after the operation is cancelled.
2019-02-05 08:27:42 +01:00
Thomas Haller
f2973fd72e clients/secret-agent: remove request in finalize loop early
It's ugly to keep the request in the list. Just remove it
right away.
2019-02-05 08:27:42 +01:00
Thomas Haller
4157092a8a clients/secret-agent: rework tracking of requests in secret-agent-simple
Note that previously the @requests hash took the request-id as key and
the RequestData as value. Likewise, the destroy functions of the head
would destroy the key and the value.

However, RequestData also had a field "request_id". But that pointer was
not owned (nor freed) by the RequestData structure. Instead, it was
relied that the hash kept the request-id alive long enough.

That is confusing. Let RequestData own the request-id.

Also, we don't need to track a separate key. Just move the request-id
as first filed in RequestData, and use compare/hash functions that
handle that correctly (nm_pstr_*()).
2019-02-05 08:27:12 +01:00
Thomas Haller
5572c8f81c clients/secret-agent: only pass char buffer to _auth_dialog_write_done()
We don't need the entire GString. It's only to keep the buffer alive
for long enough.
2019-02-05 08:22:01 +01:00
Thomas Haller
73f423c5e5 clients/secret-agent: various cleanups in secret-agent-simple 2019-02-05 08:22:01 +01:00
Thomas Haller
378a4a8e1a clients/secret-agent: drop strv_has() implementation 2019-02-05 08:22:01 +01:00
Thomas Haller
aaaa8902fd clients/secret-agent/trival: rename internal types, functions and variables
Code that is internal to a source file should not have a "nm" prefix.
That is what differenciates it from declarations in header files. It
makes it clearer that these names are only defined in the current file.

Also, our implementations of virtual functions shall have the same
name as the function pointer of the VTable (or at least, it shouldn't
have a "nm" prefix).
2019-02-05 08:22:01 +01:00
Thomas Haller
9d1becb0dd clients/secret-agent: embed private data in NMSecretAgentSimple class 2019-02-05 08:22:01 +01:00
Thomas Haller
a6600f5ae6 clients/secret-agent: reorder code in nm-secret-agent-simple.c 2019-02-05 08:22:01 +01:00
Thomas Haller
2626eb6d8c cli: clear fields in nmc_cleanup()
Don't leave dangling pointers.
2019-02-05 08:22:01 +01:00
Thomas Haller
7fb18004b3 libnm/trival: fix indention in "libnm/nm-secret-agent-old.c" 2019-02-05 08:22:01 +01:00
Thomas Haller
d80be7825d shared: add nm_clear_g_cancellable_disconnect() 2019-02-05 08:22:01 +01:00
Thomas Haller
9f558e4d15 logging: merge branch 'th/logging-mt'
https://github.com/NetworkManager/NetworkManager/pull/286
2019-02-05 08:18:09 +01:00
Thomas Haller
c6c6295a96 platform: refactor NMPNetns avoiding global variable
Avoid accessing the global variable @_netns_stack (formerly @netns_stack)
directly. Access it once when needed, and pass it on as parameter.
2019-02-05 08:18:09 +01:00
Thomas Haller
12df49f8ab platform: make NMPNetns thread-safe
NMPNetns instances are immutable, hence they can be easily shared
between threads. All we need, is that the stack of namespaces is
thread-local.

Also note that NMPNetns uses almost no other API, except some bits from
"shared/nm-utils/" and nm-logging. These parts are already supposed to
be thread-safe.

The only complications is that when the thread exits, we need to
destroy the NMPNetns instances. That is especially important because
they hold file descriptors. This is accomplished using pthread's
thread-specific data. An alternative would be C11 threads' tss_create(),
but not all systems that we run against support that yet. This means,
we need to link with pthreads, but we already do that anyway.
Note that glib also requires pthreads. So, we don't get an additional
dependency here.
2019-02-05 08:18:08 +01:00
Thomas Haller
fcfd4f4ff2 logging: make nm-logging thread-safe
NetworkManager is single-threaded and uses a mainloop.

However, sometimes we may need multiple threads. For example, we will
need to write sysctl values asynchronously, using the glib thread-pool.
For that to work, we also need to switch the network-namespace of the
thread-pool thread. We want to use NMPNetns for that. Hence it's better
to have NMPNetns thread-safe, instead of coming up with a duplicate
implementation. But NMPNetns may want to log, so we also need nm-logging
thread-safe.

In general, code under "shared/nm-utils" and nm-logging should be usable
from multiple threads. It's simpler to make this code thread-safe than
re-implementing it. Also, it's a bad limitation to be unable to log
from other threads. If there is an error, the best we can often do is to
log about it.

Make nm-logging thread-safe. Actually, we only need to be able to log
from multiple threads. We don't need to setup or configure logging from
multiple threads. This restriction allows us to access logging from the
main-thread without any thread-synchronization (because all changes in
the logging setup are also done from the main-thread).

So, while logging from other threads requires a mutex, logging from the
main-thread is lock-free.
2019-02-05 08:18:08 +01:00
Thomas Haller
834c092b51 logging: avoid accessing global data from helper functions
We need to see where we modify/access global data. Instead of letting
helper functions access global data, pass it as arguments.
2019-02-05 08:18:08 +01:00
Thomas Haller
729feb0a93 logging: refactor and merge early logging initialization
Instead of having two functions nm_logging_set_syslog_identifier()
and nm_logging_set_prefix(), merge them.

They must both be called at earliest point and together. No point
in giving them the appearance that they could be called any time.
2019-02-05 08:18:08 +01:00
Thomas Haller
83338428d9 logging: move global "logging_domains_to_string" variable
This variable has other requirements for multi-threaded access (it will
only be accessible from the main-thread). Move it to a separate global
variable to make that clearer.
2019-02-05 08:18:08 +01:00
Thomas Haller
5e2202f41f logging: refactor globals in "nm-logging.c" to see where global gets modified
The distinction between only reading static data and modifying it,
is important when making nm-logging thread-safe.

This change should make it easier to find the places where we modify
data.
2019-02-05 08:18:08 +01:00
Thomas Haller
db2d6a1808 logging: cleanup type definition and global variables
First define types, then declare global variables.

Reorder the code.
2019-02-05 08:18:07 +01:00
Thomas Haller
eea11faf9a logging: split out enum type definition for LogBackend 2019-02-05 08:18:07 +01:00
Thomas Haller
8dcc3cd51a logging: split out @level_desc and @domain_desc variables from global data
@level_desc and @domain_desc are two immutable arrays with information
about logging levels and logging domains. Since they are immutable and
intialized from the start, they are pretty trival w.r.t. tread-safety and
general maintainability (code readability).

Refactor them to be separate variables.
2019-02-05 08:18:07 +01:00
Thomas Haller
ba1bf0390d logging: make _nm_logging_clear_platform_logging_cache() a regular function
Previously, _nm_logging_clear_platform_logging_cache was an extern variable,
and NMLinuxPlatform would set it to a function pointer at certain points.

That's unnecessary complex, also when trying to make nm-logging thread-safe,
it's just more global variables that need to be considered. Don't do it
that way, but just link in a regular function.
2019-02-05 08:18:07 +01:00
Thomas Haller
40b0d7ce1e shared: define NM_THREAD_SAFE_ON_MAIN_THREAD
This will be used by nm-logging to opportunistically avoid locking.
2019-02-05 08:18:07 +01:00
Thomas Haller
61e76e97dc shared: add nm_utils_gettid() and NM_ASSERT_ON_MAIN_THREAD() 2019-02-05 08:18:07 +01:00
Thomas Haller
953dd4ac49 core: drop unused <pthread.h> include from src/main.c 2019-02-05 08:18:06 +01:00
Lubomir Rintel
ef6d461b7f platform/linux: fix setting of IFA_ADDRESS without a peer
Since commit 9ecdba316 ('platform: create netlink messages directly
without libnl-route-3') we're unconditionally setting IFA_ADDRESS to
the peer address, even if there's no peer and it's all zeroes.

The kernel actually stopped caring somewhere around commit caeaba790
('ipv6: add support of peer address') in v3.10, but Ubuntu Touch likes
to run Android's v3.4 on some poorly supported hardware.

Fixes: 9ecdba316c

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/77
2019-02-05 07:11:12 +01:00
Thomas Haller
2727c713ca libnm,core: merge branch 'th/various-for-wireguard-2'
https://github.com/NetworkManager/NetworkManager/pull/291
2019-02-04 20:15:55 +01:00
Thomas Haller
b4e9efd724 libnm-core: drop unused includes from "nm-setting.c" 2019-02-04 20:15:20 +01:00
Thomas Haller
353e619c9f libnm,core: make for-each-secret implementation virtual functions of NMSetting
We already need to special handle regular settings (with secrets as
GObject properties) and VPN secrets.

Next, we will also need to special handle WireGuard peers, which can
have secrets too.

Move the code to a virtual function, so that "nm-connection.c" and
"nm-setting.c" does not have explicit per-setting knowledge.
2019-02-04 20:15:20 +01:00
Thomas Haller
866ac505a8 libnm,core: various cleanups of _nm_connection_for_each_secret()
- use cleanup attribute to free memory

- return floating reference from _nm_connection_for_each_secret().
  It's more idiomatic that a function that constructs a variant and
  returns it, returns a floating variant.
2019-02-04 20:15:20 +01:00
Thomas Haller
79a0238c5e libnm,core: move _nm_connection_for_each_secret() from core to libnm-core
_nm_connection_for_each_secret() (formerly for_each_secret()) and
_nm_connection_find_secret() (formerly find_secret()) operate on a
GVariant of secrets. For that, they implement certain assumptions
of how to handle secrets. For example, it must special-case VPN settings,
because there is no generic abstraction to handle regular secret and VPN
secrets the same.

Such special casing should only be done in libnm-core, at one place.

Move the code to libnm-core as internal API.
2019-02-04 20:15:20 +01:00
Thomas Haller
4ea6c83e9b settings: fix handling of VPN secrets in for_each_secret()
nm_setting_get_secret_flags() looks whether we have a suitable "-flags"
data value, or whether we have a secret with that name.

In fact, we know this is a valid secret-name. Even if there are no secret-flags
and the secret (currently) does not exists. We shall not care about the
return value.

Note that nm_setting_get_secret_flags() also for non-secrets will set
the flags to "NONE", which is just what we need.
2019-02-04 20:15:20 +01:00
Thomas Haller
5eac241578 settings: fix for_each_secret() to check variant type of VPN secrets
We cannot just blindly assume that the variant is of the right type
to iterate over it.
2019-02-04 20:15:20 +01:00
Thomas Haller
cabc1ddca5 settings: fix leaking variant in for_each_secret()
Fixes: df6706813a
2019-02-04 20:15:20 +01:00
Thomas Haller
b64e24dcd7 libnm: rework _nm_setting_aggregate() to delegate to setting class
Instead of special-casing the aggregate implementation for NMSettingVpn,
delegate to a virtual function.

This will also work with other settings, that have properties/secrets
that are not GObject based properties.
2019-02-04 20:15:20 +01:00
Thomas Haller
52368678d6 libnm: extend nm_setting_enumerate_values() to support non-GObject base properties
While nm_setting_enumerate_values() should not be used anymore, still
extend it to make it workable also for properties that are not based on
GObject properties.
2019-02-04 20:15:20 +01:00
Thomas Haller
879820ccd5 libnm: emit "notify:name" signal when changing gendata property (NMSettingEthtool)
We want to emit a change notification when gendata-based settings (like
NMSettingEthtool) change. But instead of adding a separate signal, just
emit a fake "notify:name" notification.
2019-02-04 20:15:20 +01:00
Thomas Haller
0b20b44c99 libnm: add _nm_setting_emit_property_changed() function
Will be used next.
2019-02-04 20:15:20 +01:00
Thomas Haller
c7b3c23af2 ifcfg-rh/tests: avoid duplicate const warning for NO_EXPECTED
../src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c:126:19: warning: duplicate 'const' declaration specifier [-Wduplicate-decl-specifier]
     static const char const NO_EXPECTED[1];
                       ^~~~~

Fixes: f04bf45e84
2019-02-04 16:55:43 +01:00
Beniamino Galvani
797eab2f6b vpn: add route to vpn gw when parent has a default device route
When the parent device has a device default route (i.e. without
gateway) and we establish a VPN on top of it, 'ip route get' for the
VPN gateway returns a device route, which is the same result we get
for an unreachable VPN gateway. However it is necessary to add the
route to the gateway or otherwise it will possibly become unreachable
once the VPN gets activated.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/93
2019-02-04 11:07:02 +01:00
Beniamino Galvani
483dc40047 build: merge branch 'bg/lto'
Fix LTO builds.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/76
https://bugzilla.gnome.org/show_bug.cgi?id=782525#c4
2019-02-04 10:56:25 +01:00
Thomas Haller
9891217a78 contrib/rpm: add option to enable LTO for RPM build 2019-02-04 10:55:25 +01:00
Thomas Haller
c77871e5e9 all: avoid bogus compiler warning about uninitialized variable
With LTO and optimizations, gcc issues several bogus
"maybe-uninitialized" warnings.

Work-around them by initializing the variables.
2019-02-04 10:55:25 +01:00
Thomas Haller
14957e914a tests: use NM_CONST_MAX() macro where a constant expression is required
Otherwise, "nm-utils/nm-test-utils.h" won't work after we
include systemd headers.
2019-02-04 10:55:25 +01:00