Commit graph

25000 commits

Author SHA1 Message Date
Thomas Haller
17d9b852c8 shared: explicitly implement binary search in NM_UTILS_STRING_TABLE_LOOKUP_DEFINE*()
When looking at nm_utils_array_find_binary_search(), we see that binary
search really isn't complicated. In nm_utils_array_find_binary_search()
it looks complicated, because that is our general purpose function which
accepts arbitrary lists, uses an opaque compare function, accepts a user
data argument, and returns the insertion position.

This is unnecessary for the narrow purpose in NM_UTILS_STRING_TABLE_LOOKUP_DEFINE*().
When we inline the binary search, it can be simplified, and the remaining
parts is simple enough to prefer this duplication of binary search over
using our general purpose function.

Also, this gives the compiler more chance for optimization. For
example, we can use "unsigned" as index type instead of gssize, because
we know (at compile time), that this type will always be large enough
for our LIST. Also, we can directly call strcmp().

The result is that the macro's implementation is also fast in the best
case (where the needle is found with only one strcmp()) and in the cases
where there is a small number of items to search.
It thus alleviates concerns that using the macro might be slower than
an optimized implementation.

The binary size of the defined function increases slightly (from 112
bytes to 192 bytes, on x86_64, GCC, -O2). But according to my tests it
is slightly and measurably faster.
2020-02-13 14:49:45 +01:00
Thomas Haller
760551e3fc shared/tests: add test for NM_UTILS_STRING_TABLE_LOOKUP_DEFINE*() 2020-02-13 14:20:26 +01:00
Thomas Haller
5a731747c5 libnm: use NM_UTILS_STRING_TABLE_LOOKUP_DEFINE() to implement _nm_setting_bond_mode_from_string() 2020-02-13 10:46:34 +01:00
Thomas Haller
487141d4a8 shared: add entry_cmd argument to NM_UTILS_STRING_TABLE_LOOKUP_DEFINE*() macro
This extra argument allows to tweak whether to assert for the input argument name.
2020-02-13 10:46:34 +01:00
Antonio Cardace
904050dd2d nm-logging: fix stack-use-after-scope error detected by asan
asan error:

==6291==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7ffe6af12880 at pc 0x7fc8dd3321cd bp 0x7ffe6af11be0 sp 0x7ffe6af11388
READ of size 15 at 0x7ffe6af12880 thread T0
    #0 0x7fc8dd3321cc  (/lib64/libasan.so.5+0x4e1cc)
    #1 0x7fc8dcebcf29 in sd_journal_sendv ../src/journal/journal-send.c:226
    #2 0x74d834 in _nm_log_impl ../src/nm-logging.c:778
    #3 0x42485c in main ../src/main.c:379
    #4 0x7fc8dca1b1a2 in __libc_start_main (/lib64/libc.so.6+0x271a2)
    #5 0x427e3d in _start (/work/NetworkManager/build/src/NetworkManager+0x427e3d)

Address 0x7ffe6af12880 is located in stack of thread T0 at offset 736 in frame
    #0 0x74c26f in _nm_log_impl ../src/nm-logging.c:663

  This frame has 9 object(s):
    [48, 56) 's_log_domains' (line 744)
    [80, 88) 'l_log_domains' (line 745)
    [112, 128) 'tv' (line 666)
    [144, 168) 'args' (line 664)
    [208, 240) 'g_copy' (line 670)
    [272, 312) 'cur_log_state_copy' (line 669)
    [352, 392) 'iov_free_data' (line 730)
    [432, 672) 'iov_data' (line 728)
    [736, 1024) 's_log_domains_buf' (line 743) <== Memory access at offset 736 is inside this variable
2020-02-12 16:21:47 +01:00
Thomas Haller
8e636186c0 core: for WireGuard devices use a default dns-priority of 50 (like for VPNs) 2020-02-12 11:55:30 +01:00
Thomas Haller
7d87d2b8da device: add nm_device_is_vpn() function 2020-02-12 11:55:30 +01:00
Beniamino Galvani
bf4b53d453 libnm-core: fix documentation of dns-priority property
Clarify that VPNs are considered first in case of same priority, and
also that it's the *best* default route that matters.
2020-02-12 11:06:40 +01:00
Thomas Haller
c69d703017 all: use g_ascii_strcasecmp() instead of the locale dependent strcasecmp()
In all the cases, we don't want to perform locale dependent comparison.

  $ sed -i 's/\<strcasecmp\>/g_ascii_\0/g' $(git grep -w -l strcasecmp -- ':(exclude)shared/systemd/' )
2020-02-11 15:23:06 +01:00
Beniamino Galvani
2e53fd4561 dhcp: merge branch 'bg/nettools-request-free'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/409
2020-02-11 09:26:43 +01:00
Beniamino Galvani
45521b1b38 dhcp: nettools: move to failed state if event dispatch fails 2020-02-11 09:26:07 +01:00
Beniamino Galvani
43016d6ebd n-dhcp4: avoid double free of NDhcp4Outgoing
n_dhcp4_c_connection_start_request() should take ownership of the
request only on success. On failure the request is freed by the
caller.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/355
2020-02-11 09:26:07 +01:00
Beniamino Galvani
a119dac998 team: merge branch 'bg/team-race-rh1798947'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/410
https://bugzilla.redhat.com/show_bug.cgi?id=1798947
2020-02-11 09:17:26 +01:00
Beniamino Galvani
554e9be5b0 team: ignore bus name appearance when killing teamd
If we are currently killing teamd, we are not interested in knowing
when it becomes ready.
2020-02-11 09:17:11 +01:00
Beniamino Galvani
e94d76382c team: ignore bus name appearance if we can't determine process id
If the GetConnectionUnixProcessID() call fails, the process that
registered on the bus has died and we should ignore the name
appearance event.
2020-02-11 09:17:11 +01:00
Thomas Haller
351644d7da license: add Jiří to RELICENSE.md
https://mail.gnome.org/archives/networkmanager-list/2020-January/msg00024.html
2020-02-10 19:34:47 +01:00
Thomas Haller
44132f6e23 supplicant: merge branch 'th/supplicant-cleanup-1'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/386
2020-02-10 19:11:57 +01:00
Thomas Haller
8a4fecbf65 wifi: cleanup property setters in "wifi/nm-wifi-p2p-peer.c" 2020-02-10 19:11:50 +01:00
Thomas Haller
cc002ed3c1 wifi: move nm_wifi_utils_parse_ies() to "src/nm-core-utils.h"
We will need it in "src/supplicant".
2020-02-10 19:11:50 +01:00
Thomas Haller
05ff735ec0 wifi: move nm_wifi_utils_level_to_quality() to "src/nm-core-utils.h"
It will be used outside of Wi-Fi device plugin. Namely, NMSupplicantInterface
needs to convert the signal strength from supplicant to percent.
2020-02-10 19:11:50 +01:00
Thomas Haller
837e71a374 supplicant: move defines for supplicant D-Bus API to header 2020-02-10 19:11:50 +01:00
Thomas Haller
bf9e016a13 supplicant: use nm_utils_error_is_cancelled() instead of g_error_matches() 2020-02-10 19:11:50 +01:00
Thomas Haller
2a831a9eae supplicant: drop unused detection for credreq 2020-02-10 19:11:50 +01:00
Thomas Haller
2685079c63 supplicant: drop unused NM_SUPPLICANT_INTERFACE_CREDENTIALS_REQUEST signal 2020-02-10 19:11:50 +01:00
Thomas Haller
c5f58619c7 supplicant: remove unused nm_supplicant_interface_credentials_reply()
Also, it is a synchronous D-Bus call. Get rid of the unused function.
2020-02-10 19:11:50 +01:00
Thomas Haller
3228fcbe9a supplicant: define wpas_state_string_to_enum() via NM_UTILS_STRING_TABLE_LOOKUP_DEFINE()
We frequently have code that converts a string to number/enum.
Use a preferred implementation via the NM_UTILS_STRING_TABLE_LOOKUP_DEFINE()
macro.

Also, this does binary search, so in most cases it's (slightly) faster.
2020-02-10 19:11:50 +01:00
Thomas Haller
6cb728e977 supplicant: use nm_utils_gbytes_to_variant_ay() in nm_supplicant_manager_set_wfd_ies() 2020-02-10 19:11:50 +01:00
Thomas Haller
c5e0bae8b4 supplicant: track supplicant interface instances in manager via embedded CList 2020-02-10 19:11:50 +01:00
Thomas Haller
0df15330ae supplicant/trivial: give WPAS defines an NM prefix
Defines in our header files should all have an NM specific prefix.

Rename.

Also rename the related defines in the source file. Usually declarations
in a source file should not have an NM prefix. But here they have for
consistency.
2020-02-10 19:11:50 +01:00
Thomas Haller
8eb1bfa87f supplicant: rework handling of capabilities (features) to use capabilities enumeration
We keep adding capabilities. Tracking them individually via boolean (or
ternary) properties is cumbersome.

Instead, use an enum NMSupplCapType and a corresponding bitmask
NMSupplCapMask. The latter can track whether a capability is detected,
detected to be absent or not detected (unknown).
2020-02-10 19:11:50 +01:00
Thomas Haller
02e5fade55 supplicant: add enum for supplicant capabilities (features)
We should handle features/capabilities more generically.
Add an enum type for that. It will be used next.

Also, wpa_supplicant calls this "Capabilities", not features.
Use that name.
2020-02-10 19:11:50 +01:00
Thomas Haller
1cc65fff1d supplicant: remove unused NM_SUPPLICANT_INTERFACE_GROUP_FORMATION_FAILURE signal 2020-02-10 19:11:50 +01:00
Thomas Haller
49931d1637 core: forward declare opaque NMRefString typedef 2020-02-10 19:11:50 +01:00
Thomas Haller
0d4eedda07 shared/tests: add nmtst_get_rand_uint64() util 2020-02-10 19:11:50 +01:00
Thomas Haller
190a8ed425 shared: add nm_ref_string_equals_str() helper 2020-02-10 19:11:50 +01:00
Thomas Haller
333e6f66fb shared: rename local variable in _NM_GET_PRIVATE_PTR() macro
The _NM_GET_PRIVATE_PTR() macro is possibly used from other macros. And
"_self" is a pretty good name to use. Don't let the lower layer macro
use this name.
2020-02-10 19:11:50 +01:00
Thomas Haller
8c23586a77 shared: drop nm_utils_dbus_normalize_object_path() in favor of nm_dbus_path_not_empty()
They do the same thing. Unify and drop one.
2020-02-10 19:11:50 +01:00
Thomas Haller
c7e6573eb4 shared: add nm_g_variant_lookup() and nm_g_variant_lookup_value() helpers
It's often convenient to accept %NULL as dictionary argument.
2020-02-10 19:11:50 +01:00
Thomas Haller
455cec9986 shared: add nm_utils_strdup_reset() helper 2020-02-10 19:11:50 +01:00
Thomas Haller
45a832ac50 shared: add NM_FLAGS_ASSIGN_MASK() helper 2020-02-10 19:11:50 +01:00
Thomas Haller
5528086ec5 shared: add nm_dbus_connection_call_set() util 2020-02-10 19:11:50 +01:00
Thomas Haller
5ce7ea38ff shared: add NM_PRINT_FMT_QUOTE_REF_STRING() macro 2020-02-10 19:11:50 +01:00
Thomas Haller
f4fa003434 shared: add NM_UTILS_STRING_TABLE_LOOKUP_DEFINE() macro to simplify defining string lookup functions 2020-02-10 19:11:50 +01:00
Thomas Haller
9153e7912f shared: add nm_utils_get_monotonic_timestamp_msec_cached() helper 2020-02-10 19:11:50 +01:00
Thomas Haller
8b63b229dd shared/trivial: rename time related functions to use "nsec"/"msec" abbreviation instead of "ns"/"ms"
The "ns" abbreviation doesn't look too nice. We mostly use "nsec" at other
places. Rename.
2020-02-10 19:11:50 +01:00
Thomas Haller
53f6858a27 all: add nm_utils_error_is_cancelled() and nm_utils_error_is_cancelled_or_disposing()
Most callers would pass FALSE to nm_utils_error_is_cancelled(). That's
not very useful. Split the two functions and have nm_utils_error_is_cancelled()
and nm_utils_error_is_cancelled_is_disposing().
2020-02-10 19:11:50 +01:00
Thomas Haller
08f86ce04d platform: use C99 static array index in parameter of nm_platform_if_indextoname()
It gives the compiler a possibility to warn about some misuses of the
function.
2020-02-10 19:11:50 +01:00
Thomas Haller
2d3a1af5d6 libnm: merge branch 'th/libnm-active-connection-delay-ready'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/405
2020-02-10 19:04:10 +01:00
Thomas Haller
425412a363 libnm: hide NMActiveConnection until NMRemoteConnection is ready
Generally, libnm's NMClient cache only wants to expose NMObjects that
are fully initalized. Most objects don't require anything special,
except NMRemoteConnection which waits for the GetSettings() call to complete.

NMObjects reference each other. For example, NMActiveConnection
references NMDevice and NMRemoteConnection. There is a desire that an
object is only ready, if the objects that it references are ready too.
In practice that is not done, because usually every objects references
other objects, that means all objects would be declared as non-ready
as long as any of them is still initializing. That does not seem
desirable. Instead, most objects (except NMRemoteConnection and now
NMActiveConnection) are considered ready and visible, once their first
notification completes. In case the objects reference any object that is
not yet ready, the references is NULL (but the source object is visible
already). This is also done this way, to cope with cycles where
objects reference each other. In practice, such cycles should not be
exposed by NetworkManager. However, libnm should be robust against that.

This has the undesired effect that when you call AddAndActivate(), then
the NMActiveConnection might already be visible while its
NMRemoteConnection isn't. That means, ac.get_connection() will
initially return NULL, until the remote connection becomes ready.
Also add a special handling that NMActiveConnection waits for their
NMRemoteConnection to be ready, before being ready itself.

Fixes: ce0e898fb4 ('libnm: refactor caching of D-Bus objects in NMClient')
2020-02-10 19:02:42 +01:00
Thomas Haller
6b745e0725 libnm: minor cleanup of libnm trace logging 2020-02-10 19:02:42 +01:00