Commit graph

30189 commits

Author SHA1 Message Date
Lubomir Rintel e733357c91 client/test: add @nm_test_no_dbus decorator
Same as @nm_test, apart from that it doesn't spawn the mock D-Bus
service.
2022-04-19 14:12:43 +02:00
Lubomir Rintel 9108f8ecfc client/test: allow overriding all environment variables
Set extra variables after the pre-defined ones have been set. This
allows overriding then.

In particular, this allows overriding DBUS_SESSION_BUS_ADDRESS so that
the test can check the behavior of the client is correct when it's set
to some garbage.
2022-04-19 14:12:43 +02:00
Lubomir Rintel beebde9e56 client/test: allow matching and replacing regex-es in nmcli output
This allows us to sanitize unpredictable UUIDs in client output in
--offline mode (where we can't just ask the mock service about the
actual UUID).
2022-04-19 14:12:43 +02:00
Lubomir Rintel 6fa1323ce5 nmcli: add --offline option for "add" and "modify"
This adds a global "--offline" option and allows its use with "add" and
"modify" commands. The "add" looks like this:

  $ nmcli --offline conn add type ethernet ens3 ipv4.dns 192.168.1.1 \
      >output.nmconnection

The "modify" is essentially implementing what's been suggested by
Beniamino in bugzilla ticked (referred to below):

  $ nmcli --offline connection modify ens3 ipv4.dns 192.168.1.1 \
      <input.nmconnection >output.nmconnection

Other commands don't support the argument at the moment:

  $ nmcli --offline c up ens3
  Error: 'up' command doesn't support --offline mode.

https://bugzilla.redhat.com/show_bug.cgi?id=1361145
2022-04-19 14:12:42 +02:00
Lubomir Rintel 438f52b459 nmcli/trivial: consistently order the options in process_command_line()
Make the order of nmc_complete_strings() arguments consistent with the
multi-way conditional below. Doesn't have any effect, just ensures the
ommisions and mistakes are hopefully easier to spot.
2022-04-19 14:12:20 +02:00
Lubomir Rintel 2a0231469f nmcli.h: tidy up boolean struct members
Use bitfields to save a few bytes. This involves swapping gboolean for
bool and some reordering in order to get them grouped together.

The patch looks horrible, because clang-format decides to put itself and
seem to go out of its way to make this whole file look idiotic.
What can you do.
2022-04-19 14:12:20 +02:00
Thomas Haller a1ff31db3b
contrib: install nmstate+nispor in "nm-in-container.sh" 2022-04-19 11:15:08 +02:00
Thomas Haller 4d53df2911
contrib/makerepo.sh: fix name for local cache of git repository
The $URL might already contain a ".git" suffix. Then $FULLNAME would
end up having two ".git" extensions. Fix that.
2022-04-15 11:24:19 +02:00
Thomas Haller 135bc5dd1f
contrib/makerepo.sh: don't use unauthenticated github URL
It doesn't work anymore:

  $ git clone git://github.com/thom311/libnl.git
  Cloning into 'libnl'...
  fatal: remote error:
    The unauthenticated git protocol on port 9418 is no longer supported.
  Please see https://github.blog/2021-09-01-improving-git-protocol-security-github/ for more information.
2022-04-15 11:11:17 +02:00
Thomas Haller f9f7f231c8
dns: merge branch 'th/dns-update-pending-rh2049421'
https://bugzilla.redhat.com/show_bug.cgi?id=2049421

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1189
2022-04-15 09:21:28 +02:00
Thomas Haller 80c9e2d9ec
device: prevent IP state from reaching ready while DNS update pending
The goal would be to ensure that a device cannot move to activated,
while a DNS update is still pending.

This does not really work for most cases. That is, because NMDevice does
not directly push DNS updates to NMDnsManager, instead, NMPolicy is
watching all device changes, and doing it. But when NMPolicy decides to
to that, may not be the right moment.

We really should let NMDevice (or better, NML3Cfg) directly talk to
NMDnsManager. Why not? They have all the information when new DNS
configuration is available. The only thing that NMPolicy does on top of
that, is determining which device has the best default route. NMPolicy
could continue to do that (or maybe NMDnsManager could), but the update
needs to be directly triggered by NMDevice/NML3Cfg.
2022-04-15 09:04:31 +02:00
Thomas Haller 6c27e58d8d
core: delay startup complete while we have pending DNS updates
While we have DNS updates pending, we cannot reach startup complete.
2022-04-15 09:04:31 +02:00
Thomas Haller 6e35cf4a7d
core: add nm_manager_get_dns_manager() getter
nm_dns_manager_get() is already a singleton. So users usually
can just get it whenever they need -- except during shutdown
after the singleton was destroyed. This is usually fine, because
users really should not try to get it late during shutdown.

However, if you subscribe a signal handler on the singleton, then you
will also eventually want to unsubscribe it. While the moment when you
subscribe it is clearly not during late-shutdown, it's not clear how
to ensure that the signal listener gets destroyed before the DNS manager
singleton.

So usually, whenever you are going to subscribe a signal, you need to
make sure that the target object stays alive long enough. Which may
mean to keep a reference to it.

Next, we will have NMDevice subscribe to the singleton. With above said,
that would mean that potentially every NMDevice needs to keep a
reference to the NMDnsManager. That is not best. Also, later NMManager
will face the same problem, because it will also subscribe to
NMDnsManager.

So, instead let NMManager own a reference to the NMDnsManager. This
ensures the lifetimes are properly guarded (NMDevice also references
NMManager already).

Also, access nm_dns_manager_get() lazy on first use, to only initialize
it when needed the first time (which might be quite late).
2022-04-15 09:04:30 +02:00
Thomas Haller cef5b8dd46
dns: prevent update-pending to hang indefinitely
For example, if you have a dnsmasq service running and bound to port 53, then
NetworkManager's [main].dns=dnsmasq will fail to start. And we keep retrying
to start it. But then update pending would hang indefinitely, and devices could
not become active. That must not happen.

Give the DNS update only 5 seconds. If it's not done by then, assume we
have a problem and unblock.
2022-04-15 09:04:30 +02:00
Thomas Haller f2abcf2082
dns/dnsmasq: implement update-pending flag in NMDnsDnsmasq plugin
We want to know when we are busy (have an update pending or on-going).
Implement that.
2022-04-15 09:04:30 +02:00
Thomas Haller ccf0e8d327
dns/dnsmasq: use GSource for timeout in NMDnsDnsmasq 2022-04-15 09:04:30 +02:00
Thomas Haller 5da17c689b
dns/unbound: drop deprecated "unbound" DNS plugin
The "unbound" DNS plugin was very rudimentary and is deprecated since
commit 4a2fe09853 ('man: mark [main].dns=unbound as deprecated') (Jun
2021).

It is part of dnssec-trigger tool, but the dnssec-trigger tool doesn't
actually use it. Instead it installs a dispatcher script
"/usr/lib/NetworkManager/dispatcher.d/01-dnssec-trigger".

Especially, since the plugin requires "/usr/libexec/dnssec-trigger-script",
which is provided by "dnssec-trigger" package on Fedora. At the same
time, the package provides the dispatcher script. So I don't this works
or anybody is using this.

https://mail.gnome.org/archives/networkmanager-list/2022-April/msg00002.html
2022-04-15 09:04:30 +02:00
Thomas Haller bbbb1b7339
dns/resolved: implement update-pending flag in NMDnsSystemdResolved plugin 2022-04-15 09:04:30 +02:00
Thomas Haller a74a517f49
dns/resolved: track pending counter for D-Bus calls in NMDnsSystemdResolved
This is used to signal that an update is pending or in progress.
For this to work, we also need to implement the stop() handle.
Otherwise, we couldn't abort pending requests, which is necessary
during shutdown (not today, but in the future).
2022-04-15 09:04:30 +02:00
Thomas Haller 2f1feb9651
dns/resolved: use GPtrArray to collect ip datas in NMDnsSystemdResolved's update()
CList is a great, simple data structure. Especially, if we can embed it
into the data we track.

Here we just create a (temporary) list of pointers. A GPtrArray is the
better data structure for that.
2022-04-15 09:04:30 +02:00
Thomas Haller eb25c9ecd2
dns/resolved: use nm_utils_hash_to_array_with_buffer() in NMDnsSystemdResolved's update()
We copy the content of the hash table to an array, so that we can sort
the entries and they have a defined order.

We are not only interested in the keys, but the keys and the values.
Hence, use nm_utils_hash_to_array_with_buffer() which gives both at
the same time.
2022-04-15 09:04:29 +02:00
Thomas Haller 51cec67253
dns/resolved: sort dirty interfaces to prune in "nm-dns-systemd-resolved.c"
When we do something where the order makes a visible difference,
we should do it in a consistent way, that does not depend on arbitray
things. Sort the ifindexes from dirty_interfaces hash table.
2022-04-15 09:04:29 +02:00
Thomas Haller 39b68d72d3
dns/resolved: add const to parameters in "nm-dns-systemd-resolved.c" 2022-04-15 09:04:29 +02:00
Thomas Haller 4564adfb53
dns/resolved: minor cleanups in "nm-dns-systemd-resolved.c" 2022-04-15 09:04:29 +02:00
Thomas Haller a60b971003
dns: add update-pending property to NMDnsManager 2022-04-15 09:04:29 +02:00
Thomas Haller b7ca08e971
dns: add "update-pending" state to NMDnsPlugin
Theoretically, this should be a GObject property, and not a signal.
But then I'd  also have to implement the get_property() function,
which is more hazzle than necessary. A signal will do nicely.
2022-04-15 09:04:29 +02:00
Thomas Haller f68230fbe9
dns: call nm_dns_plugin_stop() also for NMDnsSystemdResolved instance
Currently NMDnsSystemdResolved does not implement "stop()". That is
about to change. Make sure to call stop before unreferencing the
instance.
2022-04-15 09:04:29 +02:00
Thomas Haller 0001a2fd0c
dns: fix NMDnsPluginPrivate and drop unused fields
NM_DNS_PLUGIN_GET_PRIVATE() macro was broken. Also NMDnsPluginPrivate
contained unused fields. Fix that.

The private data is unused at the moment, but will be used next.
Hence it is fixed and not removed.
2022-04-15 09:04:28 +02:00
Thomas Haller 068ca09d16
dns: obfuscate pointer value for NMDnsPlugin logging 2022-04-15 09:04:28 +02:00
Thomas Haller f7b41fc18c
dns: avoid printing pointer value for NMDnsManager logging statements
We avoid printing raw pointer values. Also, in this case this is a
singleton, and we only create one instance of this type.

Note that we would still have printed the pointer instance while
constructing the instances, before setting it as singleton.

Just drop this.
2022-04-15 09:04:28 +02:00
Thomas Haller bd95a5c0ec
dns: register NMDnsPlugin instance as wait-obj for shutdown
nm_shutdown_wait_obj_register_object() today has no practical effect.
In the future it will block shutdown until the object gets destroyed.
We will want that NMDnsPlugin gets wrapped up during shut down, before
quitting.
2022-04-15 09:04:28 +02:00
Thomas Haller de926723f0
glib-aux: add nm_utils_hash_to_array() helper
We effectively already have this function, with the name
nm_utils_named_values_from_strdict(). Which is a decent name,
if you have a strdict. But it seems odd to use for other dictionaries.

Instead, add a variant with a different name. Naming is important,
and just to have the better name, the function is effectively duplicated.
2022-04-15 09:04:28 +02:00
Thomas Haller 78aad6cf51
glib-aux: add "name_ptr" union field to NMUtilsNamedValue
NMUtilsNamedValue is a key-value tuple, usually the key is a string
(hence the name "Named").

But this struct is also useful for keys that are not strings.
Add another "name_ptr" union field to access the key that way.

The alternative would be to add another struct, which serves
a very similar purpose though.
2022-04-14 21:31:36 +02:00
Thomas Haller e05f439ff4
dhcp: merge branch 'th/systemd-no-dhcp4'
https://bugzilla.redhat.com/show_bug.cgi?id=2073067

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1188
2022-04-14 21:22:49 +02:00
Thomas Haller 6150a495c9
dhcp/systemd: drop dhcp4 client (and related files)
This code is now unused.
2022-04-14 14:51:03 +02:00
Thomas Haller 54119d4105
dhcp: drop internal systemd DHCPv4 client
This is long replaced by nettools' n-dhcp4 client.
Drop it.

We still require NMDhcpSystemd for the DHCPv6 client.

Note that "[main].dhcp=systemd" now falls back to the internal client.
But this option was undocumented and internal anyway.
2022-04-14 14:51:02 +02:00
Thomas Haller b1575e814f
dhcp: don't use systemd's dhcp_lease_load() in nettools' n-dhcp4 ip4_start() 2022-04-14 14:51:02 +02:00
Thomas Haller c44b49db6f
glib-aux: add nm_parse_env_file() helpers for parsing systemd's env-files
We write lease files for internal DHCP client ("systemd" and "nettools")
in a systemd-specific format. We want to drop systemd code, so we need
to have our own parsing code.

Granted, nettools only writes a single "ADDRESS=" line, so parsing that
would be easy. On the other hand, systemd's parser is not complicated
either (in particular, if we can steal their implementation). Also, it's
a commonly used format in systemd, so having the parser would allow us
to parse similar formats.

Also, we could opt to choose that format, where it makes sense.
2022-04-14 14:51:02 +02:00
Thomas Haller 7df494bc9a
glib-aux: add nm_ascii_is_{whitespace,newline}() helper 2022-04-14 14:51:02 +02:00
Thomas Haller 4b9ea28cd4
tests: improve nmtst_assert_strv() helper macro 2022-04-14 14:51:01 +02:00
Thomas Haller c20e3a72e2
release: bump version to 1.39.1 (development) 2022-04-14 13:42:16 +02:00
Thomas Haller 6bada7fb9e
contrib/rpm: reorder variable in spec file and set rpm_version
On recent Fedora and RHEL we no longer have differing "rpm_version"
and "real_version". So usually "rpm_version" is just the same as
"real_version".

Update the template spec file to reflect that. For the "build_clean.sh"
script, we anyway always set them both to "__VERSION__".
2022-04-14 12:47:07 +02:00
Thomas Haller 335afba2e6
c-stdaux: re-import git-subtree for 'src/c-stdaux'
git subtree pull --prefix src/c-stdaux git@github.com:c-util/c-stdaux.git main --squash
2022-04-13 12:49:59 +02:00
Thomas Haller e5b6639624 Squashed 'src/c-stdaux/' changes from 9582a563c25e..f20e1cf2dfb1
f20e1cf2dfb1 build: verify cflags do not contain spaces
5333735eeb74 build: export cflags via declare_dependency()
d050374b1c1a build: export basic CFLAGS

git-subtree-dir: src/c-stdaux
git-subtree-split: f20e1cf2dfb177e77cc946331ed2d2a83169d8b9
2022-04-13 12:49:04 +02:00
Thomas Haller a0c92bb9a4
c-stdaux: re-import git-subtree for 'src/c-stdaux'
git subtree pull --prefix src/c-stdaux git@github.com:c-util/c-stdaux.git main --squash
2022-04-13 11:03:41 +02:00
Thomas Haller 5da47deadd Squashed 'src/c-stdaux/' changes from 8652c488b8f1..9582a563c25e
9582a563c25e build: update dependency handling
c1cda3600991 test: remove possible wrong warning in possible unused variable

git-subtree-dir: src/c-stdaux
git-subtree-split: 9582a563c25e75896794a7b32e4d6b0f0bdfa19a
2022-04-13 11:01:09 +02:00
Thomas Haller 2fff437955
n-dhcp4: re-import git-subtree for 'src/n-dhcp4'
git subtree pull --prefix src/n-dhcp4 git@github.com:nettools/n-dhcp4.git master --squash
2022-04-13 10:57:58 +02:00
Thomas Haller aba56902d1 Squashed 'src/n-dhcp4/' changes from 281f431756e3..64513e31c01a
64513e31c01a connection: dynamically allocate the receive buffer
2b55ae2f0bda merge branch 'bengal:lease-boot-file'
d0f13d174b1a lease: add an accessor for the file name
0c64aedd80bf lease: fix n_dhcp4_client_lease_get_server_identifier()
745ca63afb44 lease: fix typo
b9d907d32ec0 Make n_dhcp4_client_lease_get_basetime publicly visible

git-subtree-dir: src/n-dhcp4
git-subtree-split: 64513e31c01a88db54c89321f89bcc85da27ffc5
2022-04-13 10:57:10 +02:00
Beniamino Galvani a5a5654f18
n-dhcp4/connection: dynamically allocate the receive buffer
Each connection object includes a 64KiB scratch buffer used for
receiving packets. When many instances of the client are created,
those buffers use a significant amount of memory. For example, 500
clients take ~30MiB of memory constantly reserved only for those
buffers.

Since the buffer is used only in the function and is never passed
outside, a stack allocation would suffice; however, it's not wise to
do such large allocations on the stack; dynamically allocate it.

https://github.com/nettools/n-dhcp4/issues/26
https://github.com/nettools/n-dhcp4/pull/27

64513e31c0
2022-04-13 10:56:50 +02:00
Thomas Haller 197e73ac7c
dhcp/dhclient: fix setting "src" attribute for certain routes
Fixes: 2dc7a3d9f9 ('dhcp: set "src" for DHCPv4 routes')
2022-04-13 10:43:27 +02:00