Commit graph

937 commits

Author SHA1 Message Date
Iñigo Martínez 648155e4a1 license: Add license using SPDX identifiers to meson build files
License is missing in meson build files. This has been added using
SPDX identifiers and licensed under LGPL-2.1+.
2020-02-17 13:16:57 +01:00
Thomas Haller 2dde55203b license: relicense "shared/systemd/sd-adapt-shared/nm-sd-adapt-shared.h" under LGPL-2.1+
$ git shortlog -n -s a3e75f3294 -- shared/systemd/sd-adapt-shared/nm-sd-adapt-shared.h src/systemd/sd-adapt-core/nm-sd-adapt-core.c src/systemd/sd-adapt/nm-sd-adapt.'[hc]' src/systemd/nm-sd-adapt.'[hc]' src/dhcp-manager/systemd-dhcp/nm-sd-adapt.'[hc]'
      46    Thomas Haller
       7    Beniamino Galvani
       3    Lubomir Rintel
       2    Dan Williams
       2    Dan Winship
       1    Glenn Washburn
       1    Jiří Klimeš

Note that the contribution to the file by Glenn was removed in
commit e27b15c00d ('all: remove CLOCK_BOOTTIME defintions'), so
it is no longer relevant.

All other contributors agreed to the relicensing according to "RELICENSE.md".
2020-02-16 15:45:08 +01:00
Thomas Haller 46da89cb54 license: relicense "shared/nm-utils/nm-vpn-editor-plugin-call.h" under LGPL-2.1+
$ git shortlog -n -s a3e75f3294 -- shared/nm-utils/nm-vpn-editor-plugin-call.h shared/nm-vpn-editor-plugin-call.h
       5    Thomas Haller

All contributors agreed to the relicensing according to "RELICENSE.md".
2020-02-16 15:41:49 +01:00
Thomas Haller 3eef0cf387 license: relicense "shared/nm-libnm-core-intern-aux/nm-auth-subject.[hc]" under LGPL-2.1+
$ git shortlog -n -s a3e75f3294 -- shared/nm-libnm-core-intern/nm-auth-subject.'[hc]' src/nm-auth-subject.'[hc]'
      28    Thomas Haller
       7    Dan Winship
       1    Beniamino Galvani
       1    Dan Williams
       1    Jiří Klimeš

All contributors agreed to the relicensing according to "RELICENSE.md".
2020-02-16 15:41:44 +01:00
Thomas Haller fee50e17b2 license: relicense "shared/nm-glib-aux/nm-jansson.h" under LGPL-2.1+
$ git shortlog -n -s a3e75f3294 -- shared/nm-glib-aux/nm-jansson.h shared/nm-utils/nm-jansson.h
       7    Thomas Haller
       1    Lubomir Rintel
       1    Beniamino Galvani
       1    Francesco Giudici

All contributors agreed to the relicensing according to "RELICENSE.md".
2020-02-16 15:41:40 +01:00
Thomas Haller e70ce4042c license: relicense "shared/nm-glib-aux/nm-glib.h" under LGPL-2.1+
$ git shortlog -n -s a3e75f3294 -- shared/nm-glib-aux/nm-glib.h shared/nm-utils/nm-glib.h shared/nm-glib.h include/nm-glib.h include/nm-glib-compat.h
      35    Thomas Haller
      12    Dan Winship
       5    Dan Williams
       3    Lubomir Rintel
       2    Beniamino Galvani
       1    Jan Kantert
       1    Thomas Bechtold

The last two contributions by Thomas and Jan are no longer present in any
form, because they were for an older version of glib which is no longer
supported. All other contributors agree to the licences change according
to "RELICENSE.md" file.
2020-02-16 15:41:36 +01:00
Thomas Haller de62da297e all: drop explicit casts from _GET_PRIVATE() macro calls
The _GET_PRIVATE() macros are all implemented based on
_NM_GET_PRIVATE(). That macro tries to be more type safe and uses
_Generic() to do the right thing. Explicitly casting is not only
unnecessary, it defeats these (static) type checks.

Don't do that.
2020-02-14 11:04:46 +01:00
Thomas Haller d36df06c24 shared: don't require callback argument to nm_dbus_connection_call_set()
It's fine to call propery-set without caring about the result.
2020-02-14 09:48:37 +01:00
Thomas Haller 829f8e8314 shared: drop compat implementation for G_DEFINE_QUARK()
For one, we by now require glib >= 2.34.0, so this is not used.

Also, I think G_DEFINE_QUARK() is rather ugly because it constructs
the defined function name (so you cannot grep for it). We should use
NM_CACHED_QUARK_FCN() instead.
2020-02-13 17:17:07 +01:00
Thomas Haller cd31437024 shared: drop _STATIC variant of macros that define functions
Several macros are used to define function. They had a "_STATIC" variant,
to define the function as static.

I think those macros should not try to abstract entirely what they do.
They should not accept the function scope as argument (or have two
variants per scope). This also because it might make sense to add
additional __attribute__(()) to the function. That only works, if
the macro does not pretend to *not* define a plain function.

Instead, embrace what the function does and let the users place the
function scope as they see fit.

This also follows what is already done with

    static NM_CACHED_QUARK_FCN ("autoconnect-root", autoconnect_root_quark)
2020-02-13 17:17:07 +01:00
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 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
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
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 90c5d1d99c shared: add debugging statement for assertion in nm_utils_parse_inaddr_bin_full()
There are crashes where this assertion fails, but it's not clear
how that could happen (because the input text seems a usual IPv4 address).

Try to collect some more information about what failed. It's only
enabled with NM_MORE_ASSERTS anyway.

Related: https://bugzilla.redhat.com/show_bug.cgi?id=1797915
2020-02-10 16:44:17 +01:00
Beniamino Galvani df6129d93a n-dhcp4: fix initialization of the 'secs' DHCP header field
Due to wrong type conversions, the value was always zero.

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/341
2020-02-10 16:36:25 +01:00
Beniamino Galvani 7f801685b2 shared: redefine G_SOURCE_FUNC
G_SOURCE_FUNC has attribute GLIB_AVAILABLE_MACRO_IN_2_58, which means
that the compiler will emit a warning when GLIB_VERSION_MAX_ALLOWED <
GLIB_VERSION_2_58. We currently define GLIB_VERSION_MAX_ALLOWED as
GLIB_VERSION_2_40. Redefine the macro to fix the following build error
when using glib >= 2.63.5 (the version in which the attribute was
added):

  CC       shared/nm-glib-aux/libnm_glib_aux_la-nm-shared-utils.lo
 shared/nm-glib-aux/nm-shared-utils.c: In function ‘nm_g_unix_fd_source_new’:
 shared/nm-glib-aux/nm-shared-utils.c:3679:13: error: Not available before  [-Werror]
  3679 |  g_source_set_callback (source, G_SOURCE_FUNC (source_func), user_data, destroy_notify);

Fixes: 9c5741ccd2 ('shared/nm-glib: add compat implementation for G_SOURCE_FUNC()')
2020-02-05 14:31:46 +01:00
Beniamino Galvani b2620e798a n-dhcp4: fix uninitialized variable
Properly initialize 'overload' when the space in the file section
ends.

 shared/n-dhcp4/src/n-dhcp4-outgoing.c: In function ‘n_dhcp4_outgoing_append’:
 shared/n-dhcp4/src/n-dhcp4-outgoing.c:198:17: error: ‘overload’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
2020-02-03 11:00:34 +01:00
Beniamino Galvani 182a8021f3 n-dhcp4: move back to INIT after lease expires
Move back to INIT state after the lease expires, as per section 4.4.5
of RFC 2131. Previously the client just moved to EXPIRED, closed the
connection and cleared the probe, leaving to the caller of the library
the choice to create a new client instance and to start from
scratch. However, it seems more useful that the client, once
initialized, always tries to get a lease even after an expiration.
2020-01-30 15:23:04 +01:00
Thomas Haller 228519fe79 shared: add nm_ip_addr_cmp()/nm_ip_addr_equal() helpers 2020-01-28 11:43:22 +01:00
Thomas Haller b9c5c07c4d shared: add NM_IP_ADDR_ZERO macro for initializing NMIPAddr to zero 2020-01-28 11:17:41 +01:00
Thomas Haller 8f3b43f009 all: use nm_utils_ipaddr_is_valid() instead of nm_utils_ipaddr_valid()
We should use the same "is-valid" function everywhere.

Since nm_utils_ipaddr_valid() is part of libnm, it does not qualify.

Use nm_utils_ipaddr_is_valid() instead.
2020-01-28 11:17:41 +01:00
Thomas Haller cdfbbe651b shared: add nm_utils_ipaddr_is_valid()/nm_utils_ipaddr_is_normalized() helpers 2020-01-28 11:17:41 +01:00
Thomas Haller 0f9664f417 shared: use static array indices in function parameter declarations of _nm_utils_inet[46]_ntop()
This should give the compiler more possibilities to warn about wrong
use of the API.

In practice, my current compiler wouldn't flag any issues. However,
some compilers (or compile options) might.
2020-01-28 11:17:41 +01:00
Thomas Haller c0bd6752b9 shared: move nm_utils_inet* helpers from libnm-core to shared 2020-01-28 11:17:41 +01:00
Thomas Haller 15888fc3a8 libnm/tests: cleanup add_device_common() test helper
- use NMClient's GMainContext instead of the default main context.
- add some more assertions.
- use cleanup attribute to free resources.
2020-01-28 10:54:14 +01:00
Thomas Haller 6acdc42e04 libnm/tests: extend nmtstc_client_new() to create other GObject types
nmtstc_client_new() exists to test creating a GInitiable/GAsyncInitiable
in different GMainContext combinations.

This is not only useful for NMClient but will also be useful for
NMSecretAgentOld. Add nmtstc_context_object_new() to allow for that.

Also, allow passing parameters when creating the object.

The resulting nmtstc_context_object_new() is relatively complex. But
this is only testing code, that aims to construct the respective GObject
instance in various manners (randomly using the sync or async initialization).
It is complex, but delivers at testing various code paths of the
underlying code. The API that it provides however is simple.

Also drop _nmtstc_client_new_extra_context() to create the instance with
a different context. For one, this requires that the internal context is
integrated as long as the context-busy-watcher exists. That was not
handled correctly. Also, creating a NMClient instance with a different
context than the current thread default at construct time has
implications to the test later. The tests don't want this variant, and
don't handle them properly. So drop this.
2020-01-28 10:54:14 +01:00
Thomas Haller f2baa10bb8 shared/tests: add nmtst_main_context_iterate_until() helper
Like nmtst_main_context_iterate_until_assert(), but allows to
run into timeout.
2020-01-28 10:54:14 +01:00
Thomas Haller 90bb46c8ee shared/tests/trivial: rename nmtst_main_context_iterate_until() to nmtst_main_context_iterate_until_assert()
nmtst_main_context_iterate_until*() iterates until the condition is
satisfied. If that doesn't happen within timeout, it fails an assertion.

Rename the function to make that clearer.
2020-01-28 10:54:14 +01:00
Thomas Haller eceaa39a1e shared/tests: use nmtst_g_source_set_boolean_true() in nmtst_main_context_iterate_until() 2020-01-28 10:54:14 +01:00
Thomas Haller c4690eeeff shared/tests: add nmtst_main_context_assert_no_dispatch() helper 2020-01-28 10:54:14 +01:00
Thomas Haller 0008c6c801 shared/tests: add nmtst_g_source_set_boolean_true() helper 2020-01-28 10:54:14 +01:00
Thomas Haller 71fb823a43 shared/tests: add nmtst_context_busy_watcher_wait() helper 2020-01-28 10:54:14 +01:00
Thomas Haller 6e7e18c86f shared: add nm_g_main_context_is_thread_default() util 2020-01-28 10:54:14 +01:00
Thomas Haller 24b50625bd shared: add NM_UTILS_USEC_PER_SEC macro 2020-01-28 10:54:14 +01:00
Thomas Haller 0cb0ee0482 shared: add _NM_MACRO_COMMA_IF_ARGS() helper macro 2020-01-28 10:42:08 +01:00
Thomas Haller 9b8dcc2665 shared: cleanup NM_NARG() and related macros
- add new helper macros NM_MACRO_CALL(), _NM_MACRO_SELECT_ARG_64(),
  NM_NARG_MAX1(), NM_NARG_MAX2().

- cleanup implementation of NM_NARG() and _NM_UTILS_MACRO_REST() macros
  by reusing helper macros.
2020-01-28 10:42:08 +01:00