Commit graph

29014 commits

Author SHA1 Message Date
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
Thomas Haller
b06aed2d66
libnm/tests: check property meta data for secrets 2021-08-02 10:01:04 +02:00
Thomas Haller
675dd0edd7
libnm: minor cleanup of _nm_setting_clear_secrets() 2021-08-02 10:01:04 +02:00
Thomas Haller
d733df8f69
libnm: use from_dbus_fcn() property callback from update_one_secret()
Our handling of properties is relatively complicated. We should have
clear code paths and responsibilities who calls who.

There is from_dbus_fcn() callback to implement parsing a GVariant and
set the property in NMSetting. This is called via:

  - _nm_setting_new_from_dbus()
    - init_from_dbus()
      - _property_set_from_dbus()

Then, one of the from_dbus_fcn() implementations is
_nm_setting_property_from_dbus_fcn_gprop(), which calls
set_property_from_dbus(). That one sets the property using GObject
setter. That's good and a clear code path.

However, set_property_from_dbus() was also called via

  - _nm_setting_update_secrets()
    - klass->update_one_secret()
      - nm-setting.c:update_one_secret()
        - set_property_from_dbus()

Meaning, there is a different code path to set_property_from_dbus(),
which bypasses from_dbus_fcn(). That is highly undesirable, because
it should be clear how a property setter gets implemented, and this
way, potentially two different implementations were used.

Refactor nm-setting.c:update_one_secret() to use
_property_set_from_dbus() instead. This behaves potentially differently
for properties like NM_SETTING_ADSL_PASSWORD, which is implemented as
a "direct" property, where from_dbus_fcn() setter no longer uses g_object_set().
This should not make a difference in practice, and in any case, now the
code paths are unified.
2021-08-02 10:01:04 +02:00
Thomas Haller
f1fee9fe27
libnm: add out_is_modified argument to from_dbus_fcn() to detect modification
Note that most implementations use g_object_set(), and it's not
easy to detect modification. In those cases, we assume that modification
happened -- just like also the GObject setter will emit a notification
(as none of our properties use G_PARAM_EXPLICIT_NOTIFY).
2021-08-02 10:01:03 +02:00
Thomas Haller
c593980b2d
libnm: add helper function for init_from_dbus() to set property
There is one caller of property_type->from_dbus_fcn(). But we will
call it from multiple places, so move the code to a helper function.
2021-08-02 10:01:03 +02:00
Thomas Haller
77421ba1be
libnm: use macros function arguments for NMSettInfoPropertType
These functions tend to have many arguments. They are also quite som
boilerplate to implement the hundereds of properties we have, while
we want that properties have common behaviors and similarities.

Instead of repeatedly spelling out the function arguments, use a macro.

Advantages:

- the usage of a _NM_SETT_INFO_PROP_*_FCN_ARGS  macro signals that this
  is an implementation of a property. You can now grep for these macros
  to find all implementation. That was previously rather imprecise, you
  could only `git grep '\.to_dbus_fcn'` to find the uses, but not the
  implementations.
  As the goal is to keep properties "similar", there is a desire to
  reduce the number of similar implementations and to find them.

- changing the arguments now no longer will require you to go through
  all implementations. At least not, if you merely add an argument that
  has a reasonable default behavior and does not require explicit
  handling by most implementation.

- it's convenient to be able to patch the argument list to let the
  compiler help to reason about something. For example, the
  "connection_dict" argument to from_dbus_fcn() is usually unused.
  If you'd like to find who uses it, rename the parameter, and
  review the (few) compiler errors.

- it does save 573 LOC of boilerplate with no actual logic or useful
  information. I argue, that this simplifies the code and review, by
  increasing the relative amount of actually meaningful code.

Disadvantages:

- the user no longer directly sees the argument list. They would need
  cscope/ctags or an IDE to jump to the macro definition and conveniently
  see all arguments.

Also use _nm_nil, so that clang-format interprets this as a function
parameter list. Otherwise, it formats the function differently.
2021-08-02 10:01:03 +02:00
Thomas Haller
2f5543b3ed
libnm: cleanup _nm_setting_use_legacy_property() by using cleanup attribute 2021-08-02 10:01:03 +02:00
Thomas Haller
17f0acfdb3
std-aux: add _nm_nil macro
This is only useful to hack the clang-formatting.
2021-08-02 10:01:03 +02:00
Thomas Haller
41937748d8
contrib: add "makerepo.sh" script
"makerepo.sh" script is a helper script for handling dist-git
repositories. It was so far part of "automation" branch. It seems
useful enough to officially add it to "main" branch.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/944
2021-08-02 09:56:44 +02:00