Commit Graph

30605 Commits

Author SHA1 Message Date
Igor Ponomarev
daecc226ee tools: Fix generate-docs-nm-settings-docs-gir.py on Python 2
On python2 the following error is raised:

`LookupError: unknown encoding: unicode`

Seems like `unicode` is a correct encoding in Python 3 but not 2.

Fix:

1. Change encoding to `utf-8`
2. Pass output path string instead of opening file and passing
   opened file object. Python2 and 3 might need different file
   modes, passing just path lets ElementTree select appropriate
   file mode.

Fixes: f00e90923c ('tools: Use ElementTree to write XML in generate-docs-nm-settings-docs-gir.py')

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1249
2022-06-03 08:26:12 +02:00
Thomas Haller
68e9f92a81 gitlab-ci: test build with python2 on Centos7
Currently, for all tests we have python3 installed. So effectively,
even on CentOS 7, we would test the build with python3 only.

The package build on CentOS7/epel7 however uses python2. This happens
for example for our copr builds.

Also test that configuration in gitlab-ci.
2022-06-02 14:35:04 +02:00
Thomas Haller
68aafe4942 build: print python path for autotools 2022-06-02 14:04:12 +02:00
Thomas Haller
fe7bdaa7e4 wifi: fix crash in NMDeviceWifi.check_connection_compatible() checking WEP capability
https://bugzilla.redhat.com/show_bug.cgi?id=2092782

Fixes: feee84aac4 ('wifi: mark WEP connections incompatible if supplicant lacks capability')
2022-06-02 13:25:10 +02:00
Beniamino Galvani
3d272d264c release: bump version to 1.39.6 (development) 2022-06-01 16:40:28 +02:00
Thomas Haller
3079628263 dhcp: merge branch 'th/dhcp-acd'
https://bugzilla.redhat.com/show_bug.cgi?id=1713380

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1230
2022-06-01 10:38:08 +02:00
Thomas Haller
240ec7f891 dhcp: implement ACD (address collision detection) for DHCPv4
This was working for internal plugin in the past, but broken by l3cfg
rework with 1.36. Re-add it. Not it also works with dhclient. For other
plugins, it's not really working, because we can't decline.

Now NMDhcpClient does ACD (using NML3Cfg) and abstracts that from
the caller (NMDevice).

It is complicated. Because there is state involved, meaning, we need
to remember the current state for ACD and react on and handle a
multitude of events. Getting this right, is non-trivial.

What we want is that if ACD fails, we decline the lease (and don't use
it).

https://bugzilla.redhat.com/show_bug.cgi?id=1713380
2022-06-01 10:37:44 +02:00
Thomas Haller
156d84217c dhcp/dhclient: implement accept/decline (ACD) for dhclient plugin
dhclient itself doesn't do ACD. However, it expects the dhclient-script
to exit with non-zero status, which causes dhclient to send a DECLINE.

`man dhclient-script`:

  BOUND:
     Before actually configuring the address, dhclient-script should
     somehow ARP for it and exit with a nonzero status if it receives a
     reply. In this case, the client will send a DHCPDECLINE  message  to
     the server and acquire a different address.   This may also be done in
     the RENEW, REBIND, or REBOOT states, but is not required, and indeed may
     not be desirable.

See also Fedora's dhclient-script ([1]).

https://gitlab.isc.org/isc-projects/dhcp/-/issues/67#note_97226
33226f2d76/client/dhclient.c (L1652)

[1] a8f6fd046f/f/dhclient-script (_878)

https://bugzilla.redhat.com/show_bug.cgi?id=1713380
2022-05-31 18:32:36 +02:00
Thomas Haller
0f6df633fa dhcp: minor cleanup of accept/decline functions in "nm-dhcp-client.c"
- assign the result of NM_DHCP_CLIENT_GET_CLASS() to a local variable.
  It feels nicer to only call the macro once. Of course, the macro
  expands to plain pointer dereferences, so there is little difference
  in terms of executed code.

- handle the default case with no virtual function first.
2022-05-31 18:32:36 +02:00
Thomas Haller
4f13383460 dhcp/nettools: pop n-dhcp4 events after select/accept/decline to process logging events 2022-05-31 18:32:36 +02:00
Thomas Haller
8f8839dd2a dhcp/nettools: add helper function dhcp4_event_pop_all_events()
Will be used next.
2022-05-31 18:32:35 +02:00
Thomas Haller
85b15e02fd dhcp/nettools: cleanup logging for dhcp4_event_handle()
It's pretty pointless to log

  <trace> [1653389116.6288] dhcp4 (br0): client event 7
  <debug> [1653389116.6288] dhcp4 (br0): received OFFER of 192.168.121.110 from 192.168.121.1

where the obscure event #7 is only telling you that we are going
to log something.  Handle logging events first.

In general, drop the "client event %d" message and make sure that all
code paths log something (useful), so we can see in the log that the
event was reached.
2022-05-31 18:32:35 +02:00
Thomas Haller
52a0fe584c dhcp/nettools: better track currently granted lease
When we accept/decline a lease, then that only works if we are in state
GRANTED. n-dhcp4 API also requires us, to provide the exact lease, that
we were announced earlier.

As such, we need to make sure that we don't accept/decline in the wrong
state. That means, to keep track of what we are doing more carefully.

The functions _dhcp_client_accept()/_dhcp_client_decline() now take
a l3cd argument, the one that we announced earlier. And we check that it
still matches.
2022-05-31 18:32:35 +02:00
Thomas Haller
4a256092ee dhcp: move accept/decline function inside "nm-dhcp-client.c"
They are no longer used from outside, NMDhcpClient fully handles this.
Make them static and internal.

Also, decline is currently unused. It will be used soon, with ACD
support.
2022-05-31 18:32:35 +02:00
Thomas Haller
65cfece4c5 n-dhcp4: fix internal state after declining lease
Previously, during decline we would clear probe->current_lease,
however leave the state at GRANTED.

That is a wrong state, and can easily lead to a crash later.

For example, on the next timeout we will end up at
n_dhcp4_client_dispatch_timer(), then current-lease gets
accessed unconditionally:

            case N_DHCP4_CLIENT_PROBE_STATE_GRANTED:
                    if (ns_now >= probe->current_lease->lifetime) {

Instead, return to INIT state and schedule a timer. As suggested
by RFC 2131, section 3.1, 5) ([1]).

[1] https://datatracker.ietf.org/doc/html/rfc2131#section-3.1
2022-05-31 18:32:35 +02:00
Thomas Haller
f40bbb819f n-dhcp4: maintain the probe's lease list in "n-dhcp4-c-probe.c"
The lease list and the probe's state are strongly related. That is
evidenced by the fact that sometimes we check the state and then
access probe->current_lease without further checking.

The code in "n-dhcp4-c-probe.c" (select_lease, accept, decline) already
changes and maintains the state, it should also maintain the lease list.
Move the code.
2022-05-31 18:32:35 +02:00
Thomas Haller
825bf49430 n-dhcp4: return error when calling accept/decline/select in unexpected state
The caller is supposed to call accept/decline/select with the lease that
was just announced. Calling it in the wrong state or with the wrong
lease is a user error.

Return an error when called in the wrong state, so that the user
notices they did something wrong.
2022-05-31 18:32:35 +02:00
Thomas Haller
31c52545ed dhcp: add and use _NMLOG() macro for "nm-dhcp-manager.c" 2022-05-31 18:32:35 +02:00
Thomas Haller
1760cea47c dhcp: improve warning logging for dhcp4_event_handle() failure 2022-05-31 18:32:34 +02:00
Thomas Haller
479562815c dhcp: ensure a valid DHCPv4 lease has an address for dhclient
The same check is also for nettools' n-dhcp4 client. It's useful to
being able to rely on certain things, like that an DHCPv4 lease always
has exactly one address (not equal to 0.0.0.0).
2022-05-31 18:32:34 +02:00
Thomas Haller
9abcf3a53c dhcp/trivial: rename connect_l3cfg_notify() to l3_cfg_notify_check_connected()
The function subscribes a callback l3_cfg_notify_cb(). Rename so that
related functions have a clearly related name.
2022-05-31 18:32:34 +02:00
Thomas Haller
7db07faa5e dhcp: replace switch in l3_cfg_notify_cb() with if blocks
The l3_cfg_notify_cb() handler is used for different purposes, and
different events will be considered.

Usually a switch statement is very nice for enums, especially if all
enum values should be handled (because the compiler can warn about
unhandled cases). In this case, not all events are supposed to be
handled. At this point, it seems nicer to just use an if block. It
better composes.

The compiler should be able to optimize both variants to the same
result. In any case, checking some integers for equality is in any case
going to be efficient.
2022-05-31 18:32:34 +02:00
Thomas Haller
e756533002 dhcp: move addr-family specific data to union in NMDhcpClientPrivate 2022-05-31 18:32:34 +02:00
Thomas Haller
05cc160494 dhcp/trivial: drop obsolete code comment
This is done already.
2022-05-31 18:32:34 +02:00
Thomas Haller
cd09f3d364 dhcp: fix logging of event in _nm_dhcp_client_notify() 2022-05-31 18:32:34 +02:00
Thomas Haller
d60ba91c87 core: move NM_ACD_TIMEOUT_MAX_MSEC define to "nm-l3cfg.h" header for reuse 2022-05-31 18:32:34 +02:00
Thomas Haller
f9d601ef06 device: initialize full v4/v6 union of NMDhcpClientConfig in _dev_ipdhcpx_start()
I think the previous was technically correct in any case too.
Still change it, because I feel with union and struct initialization,
we should always explicitly pick one union member that we fully
initialize.
2022-05-31 18:32:34 +02:00
Thomas Haller
eed9acc191 glib-aux: add assertions to nm_strvarray_*() helpers 2022-05-31 18:32:33 +02:00
Thomas Haller
08c010cb2b glib-aux: add nm_g_array_index_p() helper and cleanup nm_g_array*() helpers 2022-05-31 18:32:33 +02:00
Thomas Haller
d81a9aec31 glib-aux/logging: add LOGD_DHCP_af() helper macro 2022-05-31 18:32:33 +02:00
Thomas Haller
65992349d0 contrib: install black/clang-format in nm-in-container.sh
It's just convenient to have some tools around, not only
for testing, but also for (some limited) development.

In particular, because we bind-mount .vimrc inside the container, and
if I use vim, black/clang-format is just one key binding away.
2022-05-31 18:32:33 +02:00
Thomas Haller
a6b8f050a0 contrib: add "journal" command to "nm-in-container.sh" for showing logs 2022-05-31 18:32:33 +02:00
Thomas Haller
a55d2a5035 contrib: improve bashrc for nm-in-container.sh 2022-05-31 18:13:29 +02:00
Thomas Haller
3a478b3ec1 contrib: add script "nm-setup-git.sh" for setting up NetworkManager git repository
You can of course just clone NetworkManager repository and start hacking
as you like. However, there are a few things like git-notest which are
interesting to setup.

Add a script to do this.

The script is supposed to be idempotent and do nothing, unless
necessary. By default it also only prints what it would do.
2022-05-31 18:04:03 +02:00
Thomas Haller
b9af281ac0 tools: merge branch 'gfm:generate-docs-nm-settings-docs-gir-preserve-newlines'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1246
2022-05-31 13:29:24 +02:00
Igor Ponomarev
f00e90923c tools: Use ElementTree to write XML in generate-docs-nm-settings-docs-gir.py
Instead of manually writting XML line by line.
Quoting is automatic.
Makes it much easier to modify. (just add new elements)

Generated XML not indented at the moment.
2022-05-31 13:28:59 +02:00
Igor Ponomarev
a2298d31c0 tools: Modernize generate-docs-nm-settings-docs-gir.py to 2022 standards
* Create main() function and put its execution under
  __name__ == '__main__' guard.
* Only one module import per line
* Use required=True to check if necessary arguments have
  been passed.
* Remove usage() as ArgumentParser handles that already
2022-05-31 13:28:51 +02:00
Thomas Haller
8df3cb1355 core: fix unused variable in _write_hostname_on_idle_cb()
Fixes: 4dc3f3da17 ('core/hostname: avoid blocking calls in NMHostnameManager setting static hostname')
2022-05-30 18:46:40 +02:00
Thomas Haller
9c07f29e27 gitlab-ci: add f37 and Ubuntu 22.04 containers 2022-05-30 18:01:18 +02:00
Thomas Haller
cbad660225 core: merge branch 'th/save-hostname-fixes'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1238
2022-05-30 16:57:10 +02:00
Thomas Haller
4dc3f3da17 core/hostname: avoid blocking calls in NMHostnameManager setting static hostname
Of course, blocking and synchronous code is much simpler. But it's also
fundamentally wrong to block while we talk to systemd-hostnamed.

Refactor to use async operations.
2022-05-30 16:56:38 +02:00
Thomas Haller
c9fcd30758 core: minor cleanup in hostname code 2022-05-30 16:56:38 +02:00
Thomas Haller
442b6630de core: fix unsetting static hostname via empty argument
This was broken for a very long time, since 6a60dc2fe9 ('settings:
validate hostnames from D-Bus (bgo #711179)') from October 2013.

But there is really no reason to use this API, as we have
systemd-hostnamed.

https://bugzilla.redhat.com/show_bug.cgi?id=2090946
2022-05-30 16:56:38 +02:00
Ana Cabral
41b5831331 rpm: make the ifcfg informational message available from RHEL 9 2022-05-30 10:11:00 +02:00
Yuri Chornoivan
9d8a2d1ba0 po: update Ukrainian (uk) translation
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1244
2022-05-30 08:30:16 +02:00
Ana Cabral
ddf300853e Merge branch 'ac/spec' into 'main'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1236
2022-05-27 11:07:44 -03:00
Ana Cabral
96d7362613 rpm: include a warning message for network configuration on /etc/sysconfig/network-scripts directory
NetworkManager now does not support network configuration through
ifcfg files by default anymore, it is provided in a separated
package:
https://fedoramagazine.org/converting-networkmanager-from-ifcfg-to-keyfiles/

This commits include a file in rpm packages located in ifcfg scripts
directory, /etc/sysconfig/network-scripts/, to inform the user of
the new location of network configuration files.

https://bugzilla.redhat.com/show_bug.cgi?id=2074020
2022-05-27 14:04:20 +00:00
Ana Cabral
0415d904cb rpm: move ifcfg scripts directory to the NetworkManager package
NetworkManager does not support by default legacy ifcfg configuration
files anymore, this support is now provided in a separate package
(https://fedoramagazine.org/converting-networkmanager-from-ifcfg-to-keyfiles/).

ifcfg directory (/etc/sysconfig/network-scripts/) should always be present,
regardless of NetworkManager support for network scripts. This change makes the
directory always present, not only when the recently splitted ifcfg subpackage
is installed, and also make it persistent after the package removal.

Fixes: 50a6627fd7 ('rpm: split ifcfg-rh settings plugin into a separate package')
2022-05-27 14:04:20 +00:00
Thomas Haller
bc4d317302 examples: reword comments in "30-anon.conf" snippet 2022-05-27 15:05:03 +02:00
Adrian Freihofer
7e690ad496 mailmap: update to add Adrian
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1237
2022-05-27 12:42:56 +02:00