Commit graph

29023 commits

Author SHA1 Message Date
Thomas Haller
412b5b4fa7
dispatcher: reject new requests after releasing name
After we released the well-known name (or if we failed to ever request
it), we must exit as fast as possible, so that a new instance can
be started to serve new requests.

At that point, reject new requests because they are targeted against the
unique name, which they should not do (when talking to a D-Bus activated
service that exits on idle, it's important to talk to the well-known
name).

Also, if we receive SIGTERM, start releasing the name. We are told to
shut down, and must do so in a timely manner. Again, new requests shall
not be served by this instance.
2021-08-06 14:32:55 +02:00
Thomas Haller
9f0984c63b
nm-sudo: don't register pending job for current operations
Currently we only implmement two operations (Ping() and GetFD()). Both
complete right away. There is no need to register a pending job, if
the job does not get processed asynchronously.

In the future, we may have methods that need asynchronous processing
and where we need to register them as pending job.
2021-08-06 14:32:55 +02:00
Thomas Haller
31c48ec616
nm-sudo: reject new request once we have no well-known-name
If we fail to acquire the well-known name or if we already released it,
we must not accept anymore new requests.

Otherwise, requests directly targeted to the unique name will keep the
process alive, and prevent it from restarting (and serving the
well-known name). Clients really should not talk to the unique name of a
service that exits on idle. If they do, and the service is about to shut
down, then the request will be rejected. After we released the name,
there is now turning back and we should quit fast (only processing the
requests we already have).

Also, if we receive a SIGTERM, then we are requested to quit and should
do so in a timely manner. That means, we will start with releasing the
name. As the service is D-Bus activated, new requests can be served by
the next instance (or if the service is about to be disabled altogether,
they will start failing).
2021-08-06 14:32:55 +02:00
Thomas Haller
0aaaab07d1
nm-sudo: fix clearing timeout source in _idle_timeout_cb()
Fixes: f137b32d31 ('sudo: introduce nm-sudo D-Bus service')
2021-08-06 14:32:51 +02:00
Thomas Haller
06713e7645
glib-aux: add nm_g_main_context_iterate_for_msec() helper 2021-08-06 14:31:05 +02:00
Thomas Haller
17dcef41bd
all: merge branch 'th/l3cfg-21'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/953
2021-08-05 18:34:25 +02:00
Thomas Haller
8c7ab70915
dhcp: don't log plain pointer values for debugging
We avoid logging plain pointers. The logfile should not contain pointers
as that theoretically can defeat ASLR.
2021-08-05 15:52:01 +02:00
Thomas Haller
2cbaaed820
dhcp: add nm_dhcp_client_can_accept() function 2021-08-05 15:52:00 +02:00
Thomas Haller
320a1b5a79
l3cfg: add nm_l3cfg_remove_config_all_dirty() for removing dirty configs
The "only_dirty" parameter to a remove-all() function is odd.

For one, the function is called remove-all, but depending on a parameter
it does not remove all.

Also, setting remove-all(only_dirty=TRUE) means it will remove not
everything, so passing TRUE will remove only parts. That logic seems
confusing.

Avoid that, by removing the parameter from nm_l3cfg_remove_config_all()
and add nm_l3cfg_remove_config_all_dirty().
2021-08-05 14:59:19 +02:00
Thomas Haller
a3b7030d74
dispatcher: rename NM_DISPATCHER_ACTION_DHCP_CHANGE_X enums
add a NM_DISPATCHER_ACTION_DHCP_CHANGE_X() macro that can select the
right action based on a parameter.

Also rename the IPv4/IPv6 enum values, so that their naming scheme works
better with the NM_DISPATCHER_ACTION_DHCP_CHANGE_X() macro.
2021-08-05 14:59:17 +02:00
Thomas Haller
2979297519
dhcp: drop NM_DHCP_STATE_MAX enum value
These meta flags were not actually used. But when having a switch
statement, the compiler (rightly) asks us to handle them. Drop them.
2021-08-05 14:59:15 +02:00
Thomas Haller
b4e4b8d614
core: cleanup arguments for GObject signal of NMDhcpClient 2021-08-05 14:59:13 +02:00
Thomas Haller
3f6365f5d0
all: use G_CALLBACK() macro instead of plain cast 2021-08-05 14:59:11 +02:00
Thomas Haller
5e6b50ec73
device: track pending actions with a sorted string list instead of GSList
We call add/remove pending actions for every state change.

I think GSList is never the best choice of a data structure. Use a plain
array instead. Keep it sorted, so we can use binary search.
2021-08-05 14:59:10 +02:00
Thomas Haller
622a949ecc
glib-aux: add nm_arr_insert_at()/nm_arr_remove_at() helpers
The point is rather special, and the macros themselves are basically
simple wrappers around memmove().

When having a sorted array (for example, a strv array that is searched
using nm_strv_find_binary_search()), then we want to insert/remove
elements at a particular place (via memmove()).

Getting the memmove() arguments is not terribly hard, but hard enough to
add two helper macros for that.
2021-08-05 14:59:10 +02:00
Thomas Haller
2140bbf7f5
glib-aux: fix thread-safe initialization in _nm_g_source_sentinel_get_init()
Fixes: ce7c28c514 ('glib-aux: add nm_g_source_sentinel_get() util')
2021-08-05 14:59:09 +02:00
Thomas Haller
f9fa3fbf9f
std-aux: add nm_utils_addr_family_to_str() helper
Like nm_utils_addr_family_to_char(), but gives a different treatment to
AF_UNSPEC to return "" instead of 'X'. As such, it also needs to
return a string and not a char.
2021-08-05 14:59:09 +02:00
Thomas Haller
7459a8c67a
std-aux: use unique temporary variable in NM_IS_IPv4()
NM_IS_IPv4() should work well, also inside other macros and not
be concerned about shadowing another variable.
2021-08-05 14:59:01 +02:00
Thomas Haller
4513d4db63
nm-sudo,dispatcher: merge branch 'th/nm-sudo-exit-on-idle-race'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/950
2021-08-04 09:53:51 +02:00
Thomas Haller
ff8e85ab53
dispatcher: add D-Bus method "Ping"
This is only for testing the service. As nm-dispatcher is D-Bus activated,
have a simple method to test whether it works.
2021-08-04 09:41:11 +02:00
Thomas Haller
d25a33f604
dispatcher: support enabling debug logging via environment variable
The advantage of environment variables is that the user can use
`systemctl edit NetworkManager-dispatcher.service` for setting them,
without need to change the ExecStart= line.

Also, enabling debugging from the start is useful, despite that debug
logging can be enabled per-request.

Also, there is a difference whether we want verbose logging or whether
we want to log to stdout. There should be a flag, that only increases the
logging verbosity, but does not change the logging backend.
2021-08-04 09:41:11 +02:00
Thomas Haller
4fe20e4cbe
dispatcher: fix race for exit-on-idle
- exit-on-idle needs to be done correctly. Fix the race, by first
  notifying systemd (STOPPING=1), releasing the name, and all the
  while continue processing requests.

- don't use g_bus_own_name_on_connection(). That one also listens
  to NameLost and NameAcquired signals, but we don't care about those.
  systemd will take care to only spawn one process at a time. And
  anyway, the well-known name is only important to be reachable, we
  don't require it to be functional. We can get the first request
  before RequestName completed and we can continue getting requests
  after releasing the name.
2021-08-04 09:41:10 +02:00
Thomas Haller
d127b1fb79
dispatcher: minor various cleanup of timeout and shutdown
- use nm_g_timeout_add_source() for millisecond precision of idle timeout.
- schedule the first idle timeout before registering the D-Bus object.
- let the signal handler do nothing, if we are already quitting. In
  practice, this only silences the extra logging.
2021-08-04 09:41:10 +02:00
Thomas Haller
273491922e
dispatcher: use nm_g_bus_get_blocking() to create GDBusConnection
The difference is that nm_g_bus_get_blocking() iterates the GMainContext
of the caller, and thus it can process and handle SIGTERM signals.
Calling g_bus_get_sync() does not iterate the context, and we cannot
handle or detect early cancellation.
2021-08-04 09:41:10 +02:00
Thomas Haller
442428dbbf
dispatcher: add cancellable for tracking SIGTERM 2021-08-04 09:41:10 +02:00
Thomas Haller
4dd517ca61
dispatcher: ignore SIGPIPE 2021-08-04 09:41:10 +02:00
Thomas Haller
e21db61b6d
dispatcher: setup signal handler as first
The very first and the very last thing we want to do is
register (unregister) the signal handler.
2021-08-04 09:41:10 +02:00
Thomas Haller
33b643414f
dispatcher: use GSource instead of source ids 2021-08-04 09:41:10 +02:00
Thomas Haller
7b4cb01366
dispatcher: replace GMainLoop by explicit context iteration
Explicitly iterating the context is more flexible, as we can control the
parameters how long we iterate. GMainLoop is essentially a (thread-safe)
iteration around one boolean flag (controlled by g_main_loop_run() and
g_main_loop_quit()). We can maintain that boolean flag ourselves.
2021-08-04 09:41:10 +02:00
Thomas Haller
82174a66c6
dispatcher: add comment about exit-on-idle race 2021-08-04 09:41:09 +02:00
Thomas Haller
dbd459ec92
nm-sudo: expect unknown interface in _bus_method_call()
GDBus will invoke the method_call callback also for the Get/Set
functions. Thus, we need to check the interface_name and handle
them (actually, there is nothing to handle, no properties exist).

Also, "Ping" method only exists for testing. It is usually not called
in production, so check for "GetFD" first.
2021-08-04 09:41:09 +02:00
Thomas Haller
1e71a00817
nm-sudo: return result from _bus_register_service()
Instead of adding a flag to global state.
2021-08-04 09:41:09 +02:00
Thomas Haller
5105995514
nm-sudo: use nm_dbus_connection_call_blocking() in _bus_register_service() 2021-08-04 09:41:09 +02:00
Thomas Haller
eeb01bcba9
nm-sudo: use nm_g_main_context_iterate_ready() helper 2021-08-04 09:41:09 +02:00
Thomas Haller
2b8add959f
nm-sudo: cancel quit_cancellable during shutdown 2021-08-04 09:41:09 +02:00
Thomas Haller
62a9a48cc2
nm-sudo: use nm_g_bus_get_blocking() to create GDBusConnection 2021-08-04 09:41:09 +02:00
Thomas Haller
a210e9a6f4
nm-sudo: fix race during exit-on-idle
nm-sudo is D-Bus activated and exits-on-idle. To do that race-free we
need:

  - sd_notify("STOPPING=1")
  - ReleaseName
  - keep processing pending requests
2021-08-04 09:41:09 +02:00
Thomas Haller
5d9a46ad34
nm-sudo: use nm_io_sockaddr_un_set() in nm_sudo_utils_open_fd() 2021-08-04 08:23:59 +02:00
Thomas Haller
292cf4c42f
nm-sudo: drop semicolon after _nm_log() macro 2021-08-04 08:23:59 +02:00
Thomas Haller
864bfb4052
glib-aux: add nm_dbus_connection_call_blocking() helper 2021-08-04 08:23:58 +02:00
Thomas Haller
dc2e0d30bb
glib-aux: add nm_dbus_connection_call_request_name() helper 2021-08-04 08:23:58 +02:00
Thomas Haller
68e049119a
glib-aux: add nm_g_main_context_iterate_ready() helper 2021-08-04 08:23:58 +02:00
Thomas Haller
133dc3d43c
glib-aux: add nm_g_bus_get_blocking() helper 2021-08-04 08:23:58 +02:00
Thomas Haller
b7c77d51eb
glib-aux: add nm_g_child_watch_source_new() and nm_g_child_watch_add_source() helpers 2021-08-04 08:23:58 +02:00
Thomas Haller
5d08d3a7ef
glib-aux: use GUnixFDSourceFunc for nm_g_unix_fd_source_new() signature 2021-08-04 08:23:58 +02:00
Thomas Haller
b87d7a8b40
glib-aux: add nm_sd_notify() helper
Reimplements systemd's sd_notify(). We want to notify, but we don't
want to link with libsystemd.
2021-08-04 08:23:58 +02:00
Thomas Haller
5e658530ab
glib-aux: add nm_io_sockaddr_un_set() helper 2021-08-04 08:23:50 +02:00
Thomas Haller
a29d8b712f
l3cfg: set NMIPConfigSource for NML3ConfigData at construct time
Each NML3ConfigData should have a source set, and in fact most callers
would call nm_l3_config_data_set_source() right after creating the
instance.

Move the source parameter to the new() constructor function. Also remove
the setter, making the source of an instance immutable.

As every l3cfg instance generally has a clear purpose, the source should
always be known from the start and doesn't need to change.
2021-08-03 20:36:08 +02:00
Thomas Haller
7a39f1f7e7
man: update URL for networkmanager.dev home page 2021-08-03 14:57:35 +02:00
Thomas Haller
b13dfcbc5b
libm: merge branch 'th/setting-update-one-secret'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/942
2021-08-02 14:16:14 +02:00