Commit graph

29034 commits

Author SHA1 Message Date
Thomas Haller
30e7400528
ifup: extend ifup/ifdown to be smarter about NetworkManager profiles
Now that NetworkManager on Fedora 33 and RHEL 9 no longer writes
ifcfg-rh files by default ([1]), ifup/ifdown became less useful.

Possibly users shouldn't use it and it would be fine that new-style profiles
(keyfile) no longer work with these commands. But this is deemed as too
disruptive for users.

Note that our previous ifup/ifdown compat scripts only honored the argument
to be part of the ifcfg filename. That was not what initscripts were doing,
which called `need_config()` function that searched also the contents of
the files. With this extension, ifup/ifdown gets smarter too, to better
guess what the user might have wanted.

Extend the script by making it smarter, and to work with connection profile
names.

With this extension we further solidify ifup/ifdown as part of NetworkManager
command line API. That is problematic, because these tools pollute the
$PATH, by not having a clear NM-specific name. Also, these scripts
should only exist on Fedora/RHEL, which makes their usage non-portable
to other distros.
Also, other distros already ship different tools with name ifup/ifdown.
Extending the use of these scripts is thus undesirable, as it furthers
distro-specific commands.

Still, these arguments seem to not hold and users need to be "helped".
As Fedora users cannot be expected to unlearn "ifup" today, there is no
reason to assume they could in a few years. This likely means we will
never get rid of these scripts.

Also, if we truly would make ifup/ifdown part of NetworkManager, then a better
implementation would be that nmcli honors being called with these names.
That is not done, because nmcli's implementation currently is not as
nice to make that extension trivial (as it should be). It also would
mean to embrace ifup/ifdown officially. A shell script works well enough
as a hack.

[1] https://fedoraproject.org/wiki/Changes/NetworkManager_keyfile_instead_of_ifcfg_rh

https://bugzilla.redhat.com/show_bug.cgi?id=1954607

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/936
2021-08-07 15:31:04 +02:00
Ana Cabral
e6583941b1
.gitignore: include files used by eclipse-cdt IDE
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/957
2021-08-06 20:18:56 +02:00
Beniamino Galvani
3f42e2005a device: store the original MTU before force-setting it
In case the MTU is force-set (e.g. for bridges), priv->mtu_initial and
priv->ip6_mtu_initial must be initialized before changing the MTU,
otherwise the wrong value will be restored on deactivation.

Fixes: e23798a5e5 ('bridge: force (hack)-set of the MTU when explicitly set in the profile')

https://bugzilla.redhat.com/show_bug.cgi?id=1973536
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/955
2021-08-06 15:31:02 +02:00
Thomas Haller
a9279d1e89
firewalld: merge branch 'th/firewalld-reloaded'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/949
2021-08-06 14:37:43 +02:00
Thomas Haller
0f100abd85
firewalld: listen to Reloaded signal and reconfigure firewall zones
During reload, firewalld drops the current runtime configuration.
NetworkManager should listen to that, and reconfigure the zones
that it cares about.
2021-08-06 14:35:35 +02:00
Thomas Haller
b2ed02dda9
firewalld: fix initialized_now argument for NMFirewalldManager's "state-changed" signal 2021-08-06 14:35:34 +02:00
Thomas Haller
3d949f98e4
firewalld: make D-Bus calls against unique name for firewalld service
As we keep track of the current name owner, use its unique name
for the D-Bus requests.

We also track when the name owner changes, so at the point when we make
the D-Bus call, the current name owner was still running. We should talk
to it directly. If at the same time, firewalld restarts, we go through
our usual tracking of the name owner and will retry -- but always
talking to the unique name.
2021-08-06 14:35:34 +02:00
Thomas Haller
9debc3d028
firewalld: track current name_owner in NMFirewalldManager
Not only track whether we have a name-owner, but also which.
2021-08-06 14:35:33 +02:00
Thomas Haller
b55f95abfa
firewalld: prefix firewalld logging messages with "firewalld"
It seems more apt than "firewall: ...".
2021-08-06 14:35:33 +02:00
Thomas Haller
ec126740ce
nm-sudo,dispatcher: merge branch 'th/nm-sudo-cleanup'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/951
2021-08-06 14:34:24 +02:00
Thomas Haller
2665fe23c2
nm-sudo,dispatcher: rename and refactor code to make them more similar
nm-sudo and nm-dispatcher are very similar from a high level. Both are D-Bus activated
services that exit on idle and all they do, is to provide a simple D-Bus API with no
objects or properties.

Hence it's not surprising that they follow the same structure.

Rename the code to make them look more similar.
2021-08-06 14:33:39 +02:00
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