Commit graph

24762 commits

Author SHA1 Message Date
Thomas Haller
e055bdbbc3 agent-manager: merge branch 'th/agent-manager-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/374
2019-12-31 02:18:07 +01:00
Thomas Haller
bf25081dfe agent-manager: fix races registering secret agent and track auth-chain per agent
We don't need a separate "GSList *chains" to track the NMAuthChain
requests for the agents. Every agent should only have one auth-chain in
fly at any time. We can attach that NMAuthChain to the secret-agent.

Also, fix a race where:

  1) A secret agent registers. We would start an auth-chain check, but not
    yet track the secret agent.
  2) Then the secret agent unregisters. The unregistration request will fail,
    because the secret agent is not yet in the list of fully registered agents.
    The same happens if the secret agent disconnects at this point.
    agent_disconnect_cb() would not find the secret agent to remove.
  3) afterwards, authentication completes and we register the
    secret-agent, although we should not.

There is also another race: if we get authority_changed_cb() we would
not restart the authentication for the secret-agent that is still
registering. Hence, we don't know whether the result once it completes
would already contain the latest state.
2019-12-31 02:13:45 +01:00
Thomas Haller
9bdf95458e agent-manager: move and inline _agent_remove_by_owner() to impl_agent_manager_unregister() 2019-12-31 02:13:45 +01:00
Thomas Haller
ed85842c36 agent-manager: disconnect agent_disconnected_cb handler from secret-agent
Also, we don't need to use _agent_remove_by_owner(). We know now
the agent to be removed.
2019-12-31 02:13:45 +01:00
Thomas Haller
821efd87d8 agent-manager: pass agent-manager to maybe_remove_agent_on_error() and don't lookup by name
Don't access the singleton getter here. Pass the agent-manager argument
instead to maybe_remove_agent_on_error().

Also, don't lookup the agent by name. We already know, whether the agent
is still tracked or not. Look at agent->agent_lst.
2019-12-31 02:13:45 +01:00
Thomas Haller
d4a821d53e agent-manager: let nm_settings_connection_check_permission() check all secret-agents searching for permission
nm_agent_manager_get_agent_by_user() would only return the first
matching secret agent for the user. This way, we might miss an agent
that has permissions.

Instead, add nm_agent_manager_has_agent_with_permission() and search
all agents.
2019-12-31 02:13:45 +01:00
Thomas Haller
3e0094af77 agent-manager: track secret agents with CList instead of hash table
There was literally only one place where we would make use of
O(1) lookup of secret-agents: during removal.

In all other cases (which are the common cases) we had to iterate the
known agents. CList is more efficient and more convenient to use when
the main mode of operation is iterating.

Also note that handling secret agents inevitably scales linear with
the number of agents. That is, because for every check we will have
to sort the list of agents and send requests to them. It would be
very complicated (and probably less efficient for reasonable numbers
of secret agents) to avoid O(n).
2019-12-31 02:13:45 +01:00
Thomas Haller
86ba66ee9b agent-manager: expose NMSecretAgent struct in header for tight coupling with NMAgentManager
NMAgentManager and NMSecretAgent work closely together. In particular,
the NMAgentManager creates and tracks the NMSecretAgents and controls
it.

Move NMSecretAgent struct to the header, so that some fields may become
accessible to NMAgentManager. In particular, we will track secret agents
with a CList, and this CList element can be embedded in the
NMSecretAgent structure.
2019-12-31 02:13:45 +01:00
Thomas Haller
0f32326257 agent-manager/trivial: rename CList fields to track Request instances 2019-12-31 02:13:45 +01:00
Thomas Haller
eba629fb07 agent-manager: don't handle failure of nm_secret_agent_new() in agent_manager_register_with_capabilities()
This never fails. There is no need to handle an "error".
2019-12-31 02:13:45 +01:00
Thomas Haller
2dcd9fa836 agent-manager: use cleanup macro for subject in agent_manager_register_with_capabilities()
More cleanup macros.
2019-12-31 02:13:45 +01:00
Thomas Haller
b32d656d26 agent-manager: drop unused error handling in agent_manager_register_with_capabilities()
nm_auth_chain_new_subject() cannot fail.
2019-12-31 02:13:45 +01:00
Thomas Haller
89bfb64af5 auth-chain: add nm_auth_chain_get_context() accessor
Will be used later. Also rename "struct NMAuthChain" to "struct _NMAuthChain".
It follows how we commonly name this kind of struct.
2019-12-31 02:13:45 +01:00
Thomas Haller
cb7cfc3f12 shared: don't allow NULL arguments with g_hash_table_steal_extended() compat implementation
We cannot know the key/value free functions, hence, our compat implementation
cannot free the values if they are not requested. The "solution" is to require
the caller to fetch all values, always.
2019-12-31 02:13:45 +01:00
Thomas Haller
7d5d7c6d59 libnm: sort settings when constructing GVariant for connection 2019-12-28 22:23:25 +01:00
Thomas Haller
655e1aa97f man: document connectivity.enabled option in NetworkManager.conf manual 2019-12-28 15:20:06 +01:00
Thomas Haller
72e025c33e libnm: move nm_client_get_capabilities() to separate linker version
nm_client_get_capabilities() was backported to 1.22.2. Add to to the
appropriate linker version.

Officially (and according to docs) nm_client_get_capabilities() still
appears first in libnm 1.24.0. However, as it got backported to 1.22.2,
it needs to be part of a different symbol version on 1.22. Instead
of adding the symbol twice (once for libnm_1_24_0 and libnm_1_22_2),
move it only to the libnm_1_22_2 symbol version, also on master.
2019-12-24 14:47:27 +01:00
Antonio Cardace
34514b6294 clients/polkit: signal error when polkit setuid helper cannot be spawned
Also the child fds are set to -1 so that nm_close() doesn't throw an assertion.

Fixes: df1d214b2 (clients: polkit-agent: implement polkit agent without using libpolkit)
2019-12-24 13:39:54 +01:00
Antonio Cardace
99a8a49c27 autotools: define the polkit-agent package prefix when building without polkit-devel
Fixes: df1d214b2 (clients: polkit-agent: implement polkit agent without using libpolkit)
2019-12-24 13:39:49 +01:00
Antonio Cardace
cfbfe06da9 clients: nm-polkit-listener: fix segfault when a session id for a given uid is not found 2019-12-24 12:59:32 +01:00
Antonio Cardace
d6509baf1f clients,shared: merge branch 'ac/polkit_agent'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/365
2019-12-24 11:17:57 +01:00
Antonio Cardace
df1d214b2e clients: polkit-agent: implement polkit agent without using libpolkit 2019-12-24 10:13:51 +01:00
Antonio Cardace
1e45865e4f shared: nm-auth-subject: add unix-session type 2019-12-24 10:13:51 +01:00
Antonio Cardace
0f7994328d shared: move nm-dbus-auth-subject to shared/nm-libnm-core-intern
Move it to shared as it's useful for clients as well.

Move and rename nm_dbus_manager_new_auth_subject_from_context() and
nm_dbus_manager_new_auth_subject_from_message() in nm-dbus-manager.c
as they're needed there.
2019-12-24 10:13:51 +01:00
Antonio Cardace
c0f1a657c3 shared: add io-util to read data from a fd into a GString 2019-12-24 10:13:51 +01:00
Thomas Haller
6d86f3b661 libnm: merge branch 'th/setting-no-construct-property'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/361
2019-12-24 07:50:34 +01:00
Thomas Haller
358e743513 libnm/proxy: use int type for proxy.method property
The method field is set from (only) via a GObject property setter,
which sets a value of type int. As we afterwards validate that the
value is in a valid range, we should use a suitable type to hold
the value to begin with. Of course, in almost all cases is the
underlying type of the enum already int.
2019-12-24 07:48:35 +01:00
Thomas Haller
1cab6367b2 libnm: don't have G_PARAM_CONSTRUCT properties in NMSetting instances
G_PARAM_CONSTRUCT cause to explicitly initialize the property during
object construction. This is an unnecessary overhead that we can easily
avoid.

The overhead is because G_PARAM_CONSTRUCT parameters are always set with
g_object_set() before calling constructed(). Even if they are not specified
during g_object_new(), in which case it calls set with the property's default
value. This also requires g_object_new() to iterate all properties to
find and sort the construct properties.

NMSetting are supposed to be simple classes. They don't need to have
their properties initialized before object construction completes.
Especially if the default values are NULL or zero, in which case there
is nothing to do. If the default value is not NULL or zero, we need
to initialize the field instead in the nm_setting*_init() function.
2019-12-24 07:47:50 +01:00
Thomas Haller
0de6cd2d68 libnm: sort fields in NMSetting structures by size and alignment 2019-12-24 07:45:24 +01:00
Beniamino Galvani
b93fcddfdf merge: branch 'bg/nettools-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/368
2019-12-23 16:42:17 +01:00
Beniamino Galvani
6af6f70d81 dhcp: nettools: start from init-reboot phase when reusing address
If we know the address used previously, also tell the client to start
from the init-reboot phase, so that it will start with a DHCP request
instead of a discover.
2019-12-23 16:19:35 +01:00
Beniamino Galvani
dd3114deb0 dhcp: nettools: fix parsing of classless routes option
Fixes: 6adade6f21 ('dhcp: add nettools dhcp4 client')
2019-12-23 16:19:35 +01:00
Beniamino Galvani
c9fbdf3cb0 dhcp: test parsing of domain-search option
Add a test for the parsing of the the domain-search option.
2019-12-23 16:19:35 +01:00
Beniamino Galvani
36f8822c9b n-dhcp4: handle invalid return codes gracefully
Instead of terminating the program when the dispatch function returns
an invalid return code, log an error message and convert the error
code to a valid, generic one.

https://bugs.archlinux.org/task/64880
2019-12-23 16:19:35 +01:00
Beniamino Galvani
f860e929c0 n-dhcp4: use packet socket in rebinding state
After t1, the client tries to renew the lease by contacting via the
udp socket the server specified in the server-id option. If this
fails, after t2 it tries to contact any server using broadcast. For
this to work, the packet socket must be used.
2019-12-23 15:42:09 +01:00
Beniamino Galvani
af03b77980 n-dhcp4: support init-reboot state
Currently the client always starts from the INIT state (i.e. sending a
discover message). If a requested-ip was specified by the caller, it
is added as an option in the discover.

It was reported that some DHCP servers don't respond to discover
messages with the requested-ip option set [1][2].

The RFC allows to skip the discover by entering the INIT-REBOOT state
and starting directly with a broadcast request message containing the
requested IP address. Implement that.

[1] https://bugzilla.redhat.com/show_bug.cgi?id=1781856
[2] https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/310
2019-12-23 15:42:09 +01:00
Beniamino Galvani
30798e0af4 n-dhcp4: fix logging broadcast messages
Log the broadcast address instead of the server IP as destination when
needed.
2019-12-23 15:42:09 +01:00
Antonio Cardace
924c20bf55 Merge branch 'ac/meson_improvements' into 'master'
ac/meson improvements

See merge request NetworkManager/NetworkManager!369
2019-12-23 13:58:46 +00:00
Antonio Cardace
559893a081 meson: bump up min version to 0.46 according to minimum requirements
The following used functions:
	`compiler.has_link_argument`,
	`link_whole arg in declare_dependency`,
	`compiler.has_multi_link_argument`
are present only from meson 0.46.
2019-12-23 11:05:50 +01:00
Antonio Cardace
eaa26408f3 meson: remove pid_t redefinition
For some reason has_type() does not work correctly and causes
redefinition of the type.
2019-12-23 11:05:50 +01:00
Antonio Cardace
6dc8167588 meson: add additional debug CFLAGS to use the same ones autotools uses 2019-12-23 11:05:50 +01:00
Antonio Cardace
65572f5329 meson: use has_link_argument() to check linker flags support 2019-12-23 11:05:50 +01:00
Piotr Drąg
a3c9dccfd0 po: update Polish (pl) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/373
2019-12-22 08:03:03 +01:00
Thomas Haller
85ae90896c ifcfg-rh: remove calls to svUnsetAll()
We no longer need to explicitly clear values. Those that
we don't set, will be cleared automatically.
2019-12-21 13:37:11 +01:00
Thomas Haller
003a657c5c ifcfg-rh: treat base name as numbered tag and fix detection of NETMASK
We call svFindFirstNumberedKey() to check whether we have any NETMASK
set. Since commit 9085c5c3a9 ('ifcfg-rh: rename
svFindFirstKeyWithPrefix() to svFindFirstNumberedKey() for finding
NETMASK') that function would no longer find the "NETMASK" without
number.

Fix that, by letting nms_ifcfg_rh_utils_is_numbered_tag() return TRUE
for the tag itself. This also makes more sense, because it matches our
common understanding what numbered tags are.

Adjust the other callers that don't want this behavior to explicitly
check.

Fixes: 9085c5c3a9 ('ifcfg-rh: rename svFindFirstKeyWithPrefix() to svFindFirstNumberedKey() for finding NETMASK')
2019-12-21 13:37:11 +01:00
Thomas Haller
6404a363bd ifcfg-rh: merge branch 'th/ifcfg-unset-well-known-keys'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/367
2019-12-21 12:57:42 +01:00
Thomas Haller
d9bb13f8e3 ifcfg-rh: add index for O(1) access of variables in shvarFile
Previously, setting or getting a variable required to scan all lines.

Note that frequently we would look up variables that didn't actually
exist, which we could only determine after searching the entire list.

Also, since we needed to handle having the same variable specified
multiple times (where the last occurrence wins), we always had to search
all keys and couldn't stop when finding the first key. Well, technically
we could have searched in reverse order for the getter, but that wasn't
done. For the setter we wanted to delete all but the last occurrences,
so to find them, we really had to search them all.

We want to support profiles with hundreds or thousands of addresses and routes.
This does not scale well.

Add an hash table to find the variables in constant time.

Test this commit and the parent commit:

   $ git clean -fdx &&
     CFLAGS=-O2 ./autogen.sh --with-more-asserts=0 &&
     ./tools/run-nm-test.sh -m src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh &&
     perf stat -r 50 -B src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh 1>/dev/null

Before:

 Performance counter stats for 'src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh' (50 runs):

            330.94 msec task-clock:u              #    0.961 CPUs utilized            ( +-  0.33% )
                 0      context-switches:u        #    0.000 K/sec
                 0      cpu-migrations:u          #    0.000 K/sec
             1,081      page-faults:u             #    0.003 M/sec                    ( +-  0.07% )
     1,035,923,116      cycles:u                  #    3.130 GHz                      ( +-  0.29% )
     1,800,084,022      instructions:u            #    1.74  insn per cycle           ( +-  0.01% )
       362,313,301      branches:u                # 1094.784 M/sec                    ( +-  0.02% )
         6,259,421      branch-misses:u           #    1.73% of all branches          ( +-  0.13% )

           0.34454 +- 0.00116 seconds time elapsed  ( +-  0.34% )

Now:

 Performance counter stats for 'src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh' (50 runs):

            329.78 msec task-clock:u              #    0.962 CPUs utilized            ( +-  0.39% )
                 0      context-switches:u        #    0.000 K/sec
                 0      cpu-migrations:u          #    0.000 K/sec
             1,084      page-faults:u             #    0.003 M/sec                    ( +-  0.05% )
     1,036,130,698      cycles:u                  #    3.142 GHz                      ( +-  0.13% )
     1,799,851,979      instructions:u            #    1.74  insn per cycle           ( +-  0.01% )
       360,374,338      branches:u                # 1092.756 M/sec                    ( +-  0.01% )
         6,160,796      branch-misses:u           #    1.71% of all branches          ( +-  0.08% )

           0.34287 +- 0.00133 seconds time elapsed  ( +-  0.39% )

So, not much difference. But this is not surprising, because test-ifcfg-rh loads and
writes predominantly ifcfg files with few variables. The difference should be visible
when having large files.
2019-12-21 12:56:23 +01:00
Thomas Haller
9085c5c3a9 ifcfg-rh: rename svFindFirstKeyWithPrefix() to svFindFirstNumberedKey() for finding NETMASK
svFindFirstKeyWithPrefix() only had one caller: to find whether there are
any NETMASK variables set. NETMASK is a numbered variable, so we should only
find variables that indeed follow the pattern. Since there was only
one caller, rename and repurpose the function.
2019-12-21 12:47:50 +01:00
Thomas Haller
820696f352 ifcfg-rh: remove explicit svUnsetValue() calls and rely on automatic removal of unvisited keys
Part 2 of previous commit. See there.
2019-12-21 12:47:50 +01:00
Thomas Haller
07262b165d ifcfg-rh: clear all untouched, known keys before writing ifcfg-rh file
When we write a connection profile to ifcfg-rh file, we first load the
possibly existing file and modify it. The purpose is to preserve
variables that we don't know about, keep comments and preserve the order
of the variables.

Note that the writer sets a bunch of variables according to the
profile's setting. At various places the writer would explicitly
clear variables with svUnsetValue(). However, that was problematic:

- we would not unset all variables that we care about. We really should
  not leave previous variables if they make no sense anymore for the
  profile. The only thing we want to preserve are entirely unknown keys
  and comments. Note that when the writer omits to clear an unset variable,
  it usually does so assuming that the reader would anyway ignore the
  key, become some other key renders it irrelevant. Given the complexity
  of the reader and writer, that is often not the case and hard to ensure.

  We might have simply forgotten a svUnsetValue(), which was an easy
  to make mistake and hard to find (because you'd have to test with
  a pre-existing profile that happens to contain that key, which leaves
  countless combinations for testing.

  That means, a profile written by the writter might be interpreted
  differently by the reader depending on which pre-existing keys were set.

- it was cumbersome to explicitly call svUnsetValue().
  Note that for numbered tags in particular we would iterate the keys
  trying to unset them. For example for addresses (like "IPADDR5") we
  would iterate over the first 256 IPADDR keys, trying to unset them.
  That is horrible. For one, it doesn't cover the case where there might
  be more than 256 addresses. Also, it adds a significant overhead every
  time.
  While writing a ifcfg file currently is O(n^2) because setting one key
  is O(l), with l being the number of keys/lines. So, if you set n keys
  in a file with l lines, you get O(n*l). Which is basically O(n^2),
  because the number of lines and the number of keys to set usually
  corresponds.
  So when setting 256 times IPADDR, the overall complexity was still
  O(n^2 + 256 * n) and didn't change. However, the 256 factor here can
  be very significant.

We should not explicitly unset variables, we should always unset all
known variables that we don't explicitly set.

The svUnsetValue() calls are still there. They will be dropped next.
2019-12-21 12:44:23 +01:00