Commit Graph

27768 Commits

Author SHA1 Message Date
Thomas Haller
d9968b133b build: rename build option "--with-polkit-agent-helper-1{-path,}"
Suggested-by: Michael Biebl <biebl@debian.org>
2021-02-16 21:54:54 +01:00
Thomas Haller
cd86b462fc wireguard: merge branch 'th/wireguard-dns-endpoint-sticky-addr'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/754
2021-02-16 14:05:14 +01:00
Thomas Haller
98348ee539 wireguard: prefer last resolved IP from resolving endpoint from DNS
We periodically re-resolve the DNS name for entpoints. Since WireGuard
has no concept of being connected, we want to eventually pick up
if the DNS name resolves to a different IP address.

However, on resolution failure, we will never clear the endpoint we
already have. Thus, resolving names can only give a better endpoint,
not remove an IP address entirely.

DNS names might do Round-Robin load distribution and the name of the
endpoint might resolve to multiple IP addresses. Improve to stick to
the IP address that we already have -- provided that the IP address
is still among the new resolution result. Otherwise, we continue to
pick the first IP address that was resolved.
2021-02-16 13:58:31 +01:00
Thomas Haller
7bf2ddf73f platform: ensure NM_SOCK_ADDR_UNION_INIT_UNSPEC() fully initializes union
In C, initialization of a union does not define that excess memory
is initialized. Ensure that, by initializing the largest member of the
NMSockAddrUnion union.
2021-02-16 13:52:52 +01:00
Thomas Haller
b3909c36f6 policy: update vendor-URL for NetworkManager in polkit policy
The previous URL http://www.gnome.org/projects/NetworkManager/
now redirects to https://wiki.gnome.org/Apps, which isn't very
useful.

Instead, link to our NetworkManager page. The page is still sparsely
populated, but we should improve that.
2021-02-16 11:32:31 +01:00
Thomas Haller
8c04f72e36 contrib/rpm: update URL for NetworkManager in RPM package
The previous URL http://www.gnome.org/projects/NetworkManager/
now redirects to https://wiki.gnome.org/Apps, which isn't very
useful.

Instead, link to our NetworkManager page. The page is still sparsely
populated, but we should improve that.
2021-02-16 11:29:24 +01:00
Thomas Haller
0213300dce platform: downgrade severity of message for failure to create NMPNetns
Under restricted permissions (like inside a podman container) opening
"/proc/self/ns/net" fails with Permission denied. Consequently we cannot
create our bottom NMPNetns instance. That is mostly fine, however we
would log an error message with severity <error>.

Note that test "src/core/platform/tests/test-platform-general" asserts
that no <warn> and <error> messages get logged. Hence, the test will
fail.

That is undesirable. Downgrade the message to <debug> so that the test
passes. Also, it's not clear that this error message is useful here.
Being unable to open a netns fd is fine and not necessarily an error
condition.
2021-02-15 21:13:29 +01:00
Thomas Haller
f9636080ac platform: reorder code in _netns_stack_get_impl()
We should always register the GArray stack with pthread
for cleanup the thread local storage. Do that first, before
creating the NMPNetns instance at the bottom of the stack.
2021-02-15 21:11:13 +01:00
Thomas Haller
ecdbb1ab84 platform/tests: skip tests if "unshare(CLONE_NEWNET|CLONE_NEWNS)" fails
Inside a podman container (without `--priviledged`) we don't have
permissions for "unshare(CLONE_NEWNET|CLONE_NEWNS)".

It's not useful to fail tests in environments where they cannot run.
Skip them.
2021-02-15 21:11:13 +01:00
Thomas Haller
f591aa41c6 tests: add "/bin:/sbin" to "$PATH" for unit tests
We call `tc` from iproute2, which commonly is at "/sbin/tc".
That might not be in the "$PATH" of a regular user, and consequently
we fail to run the test.

Work around that by always adding "/bin" and "/sbin" to the $PATH.
2021-02-15 13:58:48 +01:00
Thomas Haller
ac1c66eb34 shared: refactor nm_assert() for NMRefString
- also check consistency of the string.

- disable more expensive check unless running with NM_MORE_ASSERTS>10.
2021-02-15 10:20:39 +01:00
Thomas Haller
3ceec9c6ac libnm: add assertion in _dbus_handle_properties_changed() 2021-02-15 09:59:53 +01:00
Thomas Haller
d8214144d2 libnm: merge branch 'th/nmclient-fix'
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=982613
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/662
2021-02-15 09:44:15 +01:00
Thomas Haller
e1e9abdf04 libnm: fix tracking object state in NMClient cache
NMClient has a NMLDBusObject instance for each D-Bus object
that it sees. This object can be in different states, like that we
already saw it on D-Bus or that it is only referred to by another
property. Due to a bug, we would wrongly not update the state and
trigger an assertion.

Reproduce with python-dbusmock (commit e89e28bf1bc0254a1eb71b71cf68ef7a97d11e5b)
by running `pytest -v -s tests/test_networkmanager.py -k test_one_wifi_with_accesspoints`.
With LIBNM_CLIENT_DEBUG we get:

>>> libnm-dbus[96085]: <trace> [6464.06459] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: properties-changed: properties changed for interface org.freedesktop.NetworkManager.Device { {'ActiveConnection': <objectpath '/org/freedesktop/NetworkManager/ActiveConnection/0'>} }
    libnm-dbus[96085]: <trace> [6464.06459] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: properties-changed: set property org.freedesktop.NetworkManager.Device.ActiveConnection
    libnm-dbus[96085]: <trace> [6464.06459] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: changed-type 0x01 linked
    libnm-dbus[96085]: <trace> [6464.06459] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: changed-type 0x01 consumed
>>> libnm-dbus[96085]: <trace> [6464.06459] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/ActiveConnection/0]: set D-Bus object state watched-only
    libnm-dbus[96085]: <trace> [6464.06459] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: changed-type 0x02 linked
    libnm-dbus[96085]: <trace> [6464.06459] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager]: changed-type 0x02 linked
    libnm-dbus[96085]: <trace> [6464.06459] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: changed-type 0x02 consumed
>>> libnm-dbus[96085]: <error> [6464.06459] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: property ActiveConnection references /org/freedesktop/NetworkManager/ActiveConnection/0 but object is not present on D-Bus
    libnm-dbus[96085]: <trace> [6464.06459] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager]: changed-type 0x02 consumed
    libnm-dbus[96085]: <trace> [6464.06460] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: properties-changed: properties changed for interface org.freedesktop.NetworkManager.Device { {'State': <uint32 100>} }
    libnm-dbus[96085]: <trace> [6464.06460] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: properties-changed: set property org.freedesktop.NetworkManager.Device.State
    libnm-dbus[96085]: <trace> [6464.06460] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: changed-type 0x01 linked
    libnm-dbus[96085]: <trace> [6464.06460] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: changed-type 0x01 consumed
    libnm-dbus[96085]: <trace> [6464.06460] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: changed-type 0x02 linked
    libnm-dbus[96085]: <trace> [6464.06460] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager]: changed-type 0x02 linked
    libnm-dbus[96085]: <trace> [6464.06461] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: changed-type 0x02 consumed
    libnm-dbus[96085]: <trace> [6464.06461] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager]: changed-type 0x02 consumed
    libnm-dbus[96085]: <trace> [6464.06462] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: properties-changed: properties changed for interface org.freedesktop.NetworkManager.Device { {'StateReason': <(uint32 100, uint32 0)>} }
    libnm-dbus[96085]: <trace> [6464.06462] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: properties-changed: set property org.freedesktop.NetworkManager.Device.StateReason
    libnm-dbus[96085]: <trace> [6464.06462] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: changed-type 0x01 linked
    libnm-dbus[96085]: <trace> [6464.06462] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: changed-type 0x01 consumed
    libnm-dbus[96085]: <trace> [6464.06462] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: changed-type 0x02 linked
    libnm-dbus[96085]: <trace> [6464.06462] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager]: changed-type 0x02 linked
    libnm-dbus[96085]: <trace> [6464.06462] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/Devices/mock_WiFi2]: changed-type 0x02 consumed
    libnm-dbus[96085]: <trace> [6464.06462] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager]: changed-type 0x02 consumed
>>> libnm-dbus[96085]: <trace> [6464.06465] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/ActiveConnection/0]: interfaces-added: properties changed for interface org.freedesktop.NetworkManager.Connection.Active { {'Devices': <[objectpath '/org/freedesktop/NetworkManager/Devices/mock_WiFi2']>, 'Default6': <false>, 'Default': <true>, 'Type': <'802-11-wireless'>, 'Vpn': <false>, 'Connection': <objectpath '/org/freedesktop/NetworkManager/Settings/Mock_AP3'>, 'Master': <objectpath '/'>, 'SpecificObject': <objectpath '/org/freedesktop/NetworkManager/AccessPoint/Mock_AP3'>, 'Uuid': <'72757a57-8cb6-4052-a18f-4e2be4ba27d9'>, 'State': <uint32 2>, 'Id': <'AP_3'>} }
>>> here we lack "set D-Bus object state on-dbus"
    libnm-dbus[96085]: <trace> [6464.06465] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/ActiveConnection/0]: interfaces-added: set property org.freedesktop.NetworkManager.Connection.Active.Devices
    libnm-dbus[96085]: <trace> [6464.06465] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/ActiveConnection/0]: interfaces-added: set property org.freedesktop.NetworkManager.Connection.Active.Default6
    libnm-dbus[96085]: <trace> [6464.06465] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/ActiveConnection/0]: interfaces-added: set property org.freedesktop.NetworkManager.Connection.Active.Default
    libnm-dbus[96085]: <trace> [6464.06465] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/ActiveConnection/0]: interfaces-added: set property org.freedesktop.NetworkManager.Connection.Active.Type
    libnm-dbus[96085]: <trace> [6464.06465] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/ActiveConnection/0]: interfaces-added: set property org.freedesktop.NetworkManager.Connection.Active.Vpn
    libnm-dbus[96085]: <trace> [6464.06465] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/ActiveConnection/0]: interfaces-added: set property org.freedesktop.NetworkManager.Connection.Active.Connection
    libnm-dbus[96085]: <trace> [6464.06465] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/ActiveConnection/0]: interfaces-added: set property org.freedesktop.NetworkManager.Connection.Active.Master
    libnm-dbus[96085]: <trace> [6464.06465] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/ActiveConnection/0]: interfaces-added: set property org.freedesktop.NetworkManager.Connection.Active.SpecificObject
    libnm-dbus[96085]: <trace> [6464.06466] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/ActiveConnection/0]: interfaces-added: set property org.freedesktop.NetworkManager.Connection.Active.Uuid
    libnm-dbus[96085]: <trace> [6464.06466] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/ActiveConnection/0]: interfaces-added: set property org.freedesktop.NetworkManager.Connection.Active.State
    libnm-dbus[96085]: <trace> [6464.06466] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/ActiveConnection/0]: interfaces-added: set property org.freedesktop.NetworkManager.Connection.Active.Id
    libnm-dbus[96085]: <trace> [6464.06466] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/ActiveConnection/0]: changed-type 0x01 linked
    libnm-dbus[96085]: <trace> [6464.06466] nmclient[c9bf1eaa1f4b6c99]: [/org/freedesktop/NetworkManager/ActiveConnection/0]: changed-type 0x01 consumed
    Bail out! libnm:ERROR:libnm/nm-client.c:2863:_dbus_handle_obj_changed_dbus: assertion failed: (dbobj->obj_state >= NML_DBUS_OBJ_STATE_ON_DBUS)

Backtrace:

  #3  0x00007f0bd11173bf in g_assertion_message_expr
      (domain=domain@entry=0x7f0bd1576018 "libnm", file=file@entry=0x7f0bd1576006 "libnm/nm-client.c", line=line@entry=2863, func=func@entry=0x7f0bd157f1b0 <__func__.170> "_dbus_handle_obj_changed_dbus", expr=expr@entry=0x7f0bd157cba0 "dbobj->obj_state >= NML_DBUS_OBJ_STATE_ON_DBUS") at ../glib/gtestutils.c:2963
  #4  0x00007f0bd14959dd in _dbus_handle_obj_changed_dbus (self=self@entry=0x5612d4f5a130, log_context=<optimized out>) at libnm/nm-client.c:2863
  #5  0x00007f0bd1495c29 in _dbus_handle_changes (self=self@entry=0x5612d4f5a130, log_context=<optimized out>, allow_init_start_check_complete=allow_init_start_check_complete@entry=1)
      at libnm/nm-client.c:2909
  #6  0x00007f0bd1497e56 in _dbus_managed_objects_changed_cb
      (connection=<optimized out>, sender_name=<optimized out>, arg_object_path=<optimized out>, interface_name=<optimized out>, signal_name=<optimized out>, parameters=0x7f0bb800d720, user_data=0x5612d4f5a130) at libnm/nm-client.c:3172
  #7  0x00007f0bd132a8df in emit_signal_instance_in_idle_cb (data=data@entry=0x7f0bb8003700) at ../gio/gdbusconnection.c:3789
  #8  0x00007f0bd10f1b5b in g_idle_dispatch (source=source@entry=0x7f0bb8012260, callback=0x7f0bd132a860 <emit_signal_instance_in_idle_cb>, user_data=0x7f0bb8003700) at ../glib/gmain.c:5836
  #9  0x00007f0bd10f2a9f in g_main_dispatch (context=0x5612d4f4b630) at ../glib/gmain.c:3325
  #10 g_main_context_dispatch (context=0x5612d4f4b630) at ../glib/gmain.c:4043
  #11 0x00007f0bd1144a98 in g_main_context_iterate.constprop.0 (context=0x5612d4f4b630, block=block@entry=1, dispatch=dispatch@entry=1, self=<optimized out>) at ../glib/gmain.c:4119
  #12 0x00007f0bd10f2163 in g_main_loop_run (loop=0x5612d4f4b720) at ../glib/gmain.c:4317
  #13 0x00005612d44b6543 in main (argc=7, argv=0x7fff4414f1d8) at clients/cli/nmcli.c:1036

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=982613
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/662

Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')
2021-02-15 09:42:14 +01:00
Thomas Haller
1f9622358a libnm: avoid assertion failure in _dbus_handle_properties_changed() for logging no properties 2021-02-15 09:16:58 +01:00
Thomas Haller
6da5fc59d8 libnm: log PID in LIBNM_CLIENT_DEBUG debug logging 2021-02-15 09:16:58 +01:00
Andrew Zaborowski
5ccb8ce17a iwd: Fix the leaks in get_agent_request_network_path
Don't request new copies of strings from g_variant_get() to avoid
leaking memory as pointed out by Thomas Haller.

Fixes: dc0e31fb70 ('iwd: Add the wifi.iwd.autoconnect setting')
2021-02-12 14:36:30 +01:00
Thomas Haller
e23bafe5d5 contrib/rpm: revert building "--with test" for RHEL 9
"--with test" does two things:

(1) it enables "-Werror" compiler option. We always enable all
    compiler warnings we care about, but this option makes all
    warnings fatal.
    Compiler warnings depend on compiler version and build options.
    It's hard to build without any compiler warnings, in particular
    for *future* compiler versions which we don't know yet. It
    is desirable that a SRPM from yesterday can also be build
    tomorrow.

(2) it fails build if any unit tests fail. We always run all
    unit tests, but "--with test" makes it fatal. Again, we
    have many unit tests that interact with the system (that is,
    make system calls, like creating IP addresses or write files).
    It is surprisingly hard to get them pass 100% on all the systems
    we care. For example, on copr a test setup randomly fails during

         ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
         nm_utils_ifname_cpy(ifr.ifr_name, TEST_IFNAME);
         r = ioctl(fd, TUNSETIFF, &ifr);

    It's not clear why, nor is it at all clear that there is a bug
    in NetworkManager. Making tests fatal basically means that a build
    on copr infrastructure fails with a probability from a few percent.
    Enough to be seriously annoying.

Note that on copr we actually build "--with test", because we want to catch these
issues. Likewise for our CI builds we explicitly specify "--with test".

In general, we build with various build configurations (compiler warnings)
and run unit tests on a source package many times. Starting on the
developer machine (`make check`), gitlab-ci, copr builds,
NetworkManager-ci. If you build an SRPM with such sources, a failure
of the unit tests is much more likely a glitch than an actual issue.

This is about changing the default if you build a Fedora/RHEL package.
That is with the Fedora/RHEL packages that are build in koji/brew.

Well, at least usually. In practice, we don't build frequently on non
x64_86 archs, so what I said there is less true. But the package build
is not there to replace CI/testing. The package build is there to get
a (mostly) working binary.

Note that RHEL packages anyway go through rpmdiff too, and rpmdiff
parses the build log and complain if `make check` fails.

This reverts commit e68e5c0a4c.
2021-02-12 13:35:24 +01:00
Thomas Haller
4d66d6c7a1 Revert "service: don't give CAP_DAC_OVERRIDE capability to NetworkManager"
Well, that was short. Seems we need CAP_DAC_OVERRIDE at least for the
OVS plugin. The OVS socket is

  srwxr-x---. 1 openvswitch openvswitch 0 Xxx xx xx:xx /run/openvswitch/db.sock

and without CAP_DAC_OVERRIDE, NetworkManager cannot talk to OVS.

We should fix that differently by adding a nm-sudo D-Bus service that
can hand a file descriptor to NetworkManager.

This reverts commit 2e334f54b2.
2021-02-12 13:32:33 +01:00
Thomas Haller
801c41a11c build: make path to polkit-agent-helper-1 binary configurable
Add new configure option to set the path to "polkit-agent-helper-1".

The path cannot be obtained from pkg-config and `pkg-config
--variable=prefix polkit-agent-1` is not good enough.

On Fedora, the path is "/usr/lib/polkit-1/polkit-agent-helper-1".
On Debian Buster, the path is "/usr/lib/policykit-1/polkit-agent-helper-1"
On Debian Sid, the path is "/usr/libexec/polkit-agent-helper-1" (but
currently it is also symlinked from "/usr/lib/policykit-1/polkit-agent-helper-1".
2021-02-12 11:34:24 +01:00
Thomas Haller
2e334f54b2 service: don't give CAP_DAC_OVERRIDE capability to NetworkManager
https://bugzilla.redhat.com/show_bug.cgi?id=1921826

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/742
2021-02-12 09:39:01 +01:00
Thomas Haller
e2df6c7503 release: bump version to 1.31.0 (development) 2021-02-11 16:52:45 +01:00
Thomas Haller
4e11b182a0 release: bump version to 1.29.90 (1.30-rc1) 2021-02-11 16:41:29 +01:00
Andrew Zaborowski
190ed7b2c9 iwd: Fix agent DBus method parameter types
The object path DBus type wasn't being used correctly in the parameters
signatures, fix them.
2021-02-11 16:34:09 +01:00
Andrew Zaborowski
c8b283b818 settings: Fix REASON_CLEAR_DEFAULT_WIRED comment typos 2021-02-11 16:34:08 +01:00
Thomas Haller
5ca018c0db lldp/tests: try workaround failure with ioctl(TUNSETIFF)
On copr build, it seems possible that the ioctl fails with

  ERROR: src/core/devices/tests/test-lldp - Bail out! NetworkManager:ERROR:src/core/devices/tests/test-lldp.c:823:_test_recv_fixture_setup: assertion failed (errno == 0): (1 == 0)

(1 is EPERM). Unclear why this happens. But as it only affects the
test setup, retry a few times.
2021-02-11 16:04:46 +01:00
Thomas Haller
a21fdd4237 dhcp: merge branch 'th/dhcp-nettools-lease-parse'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/750
2021-02-11 14:43:45 +01:00
Thomas Haller
4b874019ad dhcp: downgrade logging messages for DHCP to <debug>
Granted, for debugging this information is useful. However, to actually
debug an issue thoroughly, level=TRACE is anyway required. There is simply
no way how we can log useful debug information and not flood logging
messages for regular use.

For example, logging the DHCP lease options can easily print 30 lines.
And this, every time you get a lease update (e.g. every 30 minutes) and
for every interface that does DHCP.

It's simply too verbose. Downgrade the logging level.

Yes, now our default <info> level is even less useful to understand what
is going on. But the majority of time, users don't care so not spamming
the log is more important.

However, we still log the DHCP event (and the IP address) with <info>
level.
2021-02-11 14:33:32 +01:00
Thomas Haller
24abf13239 dhcp: binary search in nm_dhcp_option_find()
Let's use binary search.

Test patch:

    diff --git a/src/core/dhcp/tests/test-dhcp-utils.c b/src/core/dhcp/tests/test-dhcp-utils.c
    index 9b54e2cd0228..007993341672 100644
    --- a/src/core/dhcp/tests/test-dhcp-utils.c
    +++ b/src/core/dhcp/tests/test-dhcp-utils.c
    @@ -788,6 +788,24 @@ NMTST_DEFINE();
     int
     main(int argc, char **argv)
     {
    +    int i;
    +    guint idx;
    +    guint c;
    +
    +    idx = 0;
    +    c = 0;
    +    for (i = 0; i < 1000000; i++) {
    +        const guint option = _nm_dhcp_option_dhcp4_options[idx % G_N_ELEMENTS(_nm_dhcp_option_dhcp4_options)].option_num;
    +
    +        idx += 2010055757;
    +
    +        if (nm_dhcp_option_find(AF_INET, option)->name)
    +            c++;
    +    }
    +    g_print(">%u\n", c);
    +
    +    return 0;
    +
         nmtst_init_assert_logging(&argc, &argv, "WARN", "DEFAULT");

         g_test_add_func("/dhcp/generic-options", test_generic_options);

Build:

  CFLAGS='-O2' ./autogen.sh --with-more-asserts=0
  make -j 10 src/core/dhcp/tests/test-dhcp-utils && \
    src/core/dhcp/tests/test-dhcp-utils && \
    perf stat -r 200 -B src/core/dhcp/tests/test-dhcp-utils

Before:

 Performance counter stats for 'src/core/dhcp/tests/test-dhcp-utils' (200 runs):

             82.83 msec task-clock:u              #    0.994 CPUs utilized            ( +-  0.21% )
                 0      context-switches:u        #    0.000 K/sec
                 0      cpu-migrations:u          #    0.000 K/sec
               579      page-faults:u             #    0.007 M/sec                    ( +-  0.03% )
       264,676,245      cycles:u                  #    3.195 GHz                      ( +-  0.06% )
       544,792,266      instructions:u            #    2.06  insn per cycle           ( +-  0.00% )
       151,624,848      branches:u                # 1830.472 M/sec                    ( +-  0.00% )
         1,083,780      branch-misses:u           #    0.71% of all branches          ( +-  0.01% )

          0.083328 +- 0.000178 seconds time elapsed  ( +-  0.21% )

After:

 Performance counter stats for 'src/core/dhcp/tests/test-dhcp-utils' (200 runs):

             39.21 msec task-clock:u              #    0.987 CPUs utilized            ( +-  0.57% )
                 0      context-switches:u        #    0.000 K/sec
                 0      cpu-migrations:u          #    0.000 K/sec
               579      page-faults:u             #    0.015 M/sec                    ( +-  0.03% )
       115,396,123      cycles:u                  #    2.943 GHz                      ( +-  0.23% )
       137,664,630      instructions:u            #    1.19  insn per cycle           ( +-  0.00% )
        25,866,025      branches:u                #  659.597 M/sec                    ( +-  0.00% )
         1,919,616      branch-misses:u           #    7.42% of all branches          ( +-  0.12% )

          0.039717 +- 0.000227 seconds time elapsed  ( +-  0.57% )
2021-02-11 13:00:18 +01:00
Thomas Haller
1cbe926c20 dhcp: rework DHCP options to not carry around option array
Previously, we would pass around the list of options. However,

- that isn't too nice to read. Also, usually when we want to treat
  IP address families generically, then we have an addr_family argument.
  Having to first resolve the addr_family to another set of variables
  is inconvenient.

- the option array itself doesn't have enough information. For example,
  we don't know how many elements there are, we don't know which address
  family it is (unless we compare it to one of the two well known
  lists).
  For example, I'd like to do a binary search for the option. But that's
  not immediately possible, because the length is unknown.

- in practice, there are only two address families: AF_INET and
  AF_INET6. It is extremely unlikely that we will require a third
  DHCP options list, and even if we had that, the addr_family argument
  still abstracts them nicely.
  We also don't need two different lists for one DHCP type. While that
  would currently be possible (and afterwards not anymore), it would
  be wrong to do.

- also add a new accessor nm_dhcp_option_find() to find the NMDhcpOption
  instance by option number.
2021-02-11 12:26:18 +01:00
Thomas Haller
53f137af6e dhcp/nettools: accept any number of trailing NULs in string options
https://tools.ietf.org/html/rfc2132#section-2 says:

   Options containing NVT ASCII data SHOULD NOT include a trailing NULL;
   however, the receiver of such options MUST be prepared to delete trailing
   nulls if they exist.

It speaks in plurals.
2021-02-11 09:23:20 +01:00
Thomas Haller
3b8882b978 dhcp/nettools: use NMStrBuf in lease_save() 2021-02-11 09:23:19 +01:00
Thomas Haller
4707cf5fab dhcp/nettools: cleanup lease_parse_search_domains() 2021-02-11 09:23:19 +01:00
Thomas Haller
8366fd87b9 dhcp/nettools: make data pointer const 2021-02-11 09:23:18 +01:00
Thomas Haller
ce72563a8c dhcp/nettools: cleanup nm_dhcp_lease_data_parse_search_list() 2021-02-11 09:23:17 +01:00
Thomas Haller
6e0d2e5850 dhcp/nettools: move nm_dhcp_lease_data_parse_search_list() to nm-dhcp-utils.c 2021-02-11 09:23:16 +01:00
Thomas Haller
67dd25a396 shared,dhcp: add _nm_utils_ip4_get_default_prefix0() helper 2021-02-11 09:23:15 +01:00
Thomas Haller
94e474fa62 dhcp/nettools: cleanup lease_parse_routes() 2021-02-11 09:23:15 +01:00
Thomas Haller
2be43d79f7 dhcp/nettools: refactor parsing of DHCP lease (ntps) 2021-02-11 09:23:14 +01:00
Thomas Haller
f986d409f9 dhcp/nettools: cleanup lease_parse_address_list() 2021-02-11 09:23:14 +01:00
Thomas Haller
30911a305f dhcp/nettools: cleanup lease_parse_address() 2021-02-11 09:23:13 +01:00
Thomas Haller
58b3b7ec3c dhcp/nettools: refactor parsing of DHCP lease (server-id)
No change in behavior.
2021-02-11 09:23:12 +01:00
Thomas Haller
6850e3640e dhcp/nettools: refactor parsing of DHCP lease (broadcast)
No change in behavior.
2021-02-11 09:23:12 +01:00
Thomas Haller
a24b7287d8 dhcp/nettools: validate domain-name option (15) differently 2021-02-11 09:23:12 +01:00
Thomas Haller
94c6f3c14e dhcp/nettools: refactor parsing of DHCP lease (domain-name)
No change in behavior.
2021-02-11 09:23:11 +01:00
Thomas Haller
6c8a9e8bd6 dhcp/nettools: validate nis-domain option (40) differently
Previously, we would check that all characters are ASCII. But we would
also accept NUL characters (and truncate on the first NUL).

Now:

- reject any NUL characters inside the string (except trailing NUL).

- accept all characters, and if necessary backslash-encode non UTF-8.
2021-02-11 09:23:11 +01:00
Thomas Haller
0c93bff179 dhcp/nettools: refactor parsing of DHCP lease (nis-domain) 2021-02-11 09:23:10 +01:00
Thomas Haller
0ef37431cf dhcp/nettools: validate root-path option (17) to not contain any NUL characters
And make it UTF-8 (by backslash escaping).
2021-02-11 09:23:10 +01:00
Thomas Haller
f2885cdf02 dhcp/nettools: refactor parsing of DHCP lease (root-path) 2021-02-11 09:23:10 +01:00
Thomas Haller
eb16cb6563 dhcp/nettools: validate proxy-autodiscovery option (252) to not contain any NUL characters 2021-02-11 09:23:09 +01:00