summaryrefslogtreecommitdiff
path: root/shared
Commit message (Collapse)AuthorAgeFilesLines
...
* shared: add debugging statement for assertion in ↵Thomas Haller2020-02-101-1/+5
| | | | | | | | | | | | 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
* n-dhcp4: fix initialization of the 'secs' DHCP header fieldBeniamino Galvani2020-02-103-6/+6
| | | | | | Due to wrong type conversions, the value was always zero. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/341
* shared: redefine G_SOURCE_FUNCBeniamino Galvani2020-02-051-2/+2
| | | | | | | | | | | | | | | | 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: 9c5741ccd2b8 ('shared/nm-glib: add compat implementation for G_SOURCE_FUNC()')
* n-dhcp4: fix uninitialized variablebg/gcc10Beniamino Galvani2020-02-031-0/+1
| | | | | | | | 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]
* n-dhcp4: move back to INIT after lease expiresBeniamino Galvani2020-01-301-4/+3
| | | | | | | | | 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.
* shared: add nm_ip_addr_cmp()/nm_ip_addr_equal() helpersThomas Haller2020-01-281-0/+16
|
* shared: add NM_IP_ADDR_ZERO macro for initializing NMIPAddr to zeroThomas Haller2020-01-281-0/+4
|
* all: use nm_utils_ipaddr_is_valid() instead of nm_utils_ipaddr_valid()Thomas Haller2020-01-282-5/+5
| | | | | | | | 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.
* shared: add nm_utils_ipaddr_is_valid()/nm_utils_ipaddr_is_normalized() helpersThomas Haller2020-01-282-0/+45
|
* shared: use static array indices in function parameter declarations of ↵Thomas Haller2020-01-281-2/+2
| | | | | | | | | | _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.
* shared: move nm_utils_inet* helpers from libnm-core to sharedThomas Haller2020-01-281-0/+58
|
* libnm/tests: cleanup add_device_common() test helperThomas Haller2020-01-281-33/+43
| | | | | | - use NMClient's GMainContext instead of the default main context. - add some more assertions. - use cleanup attribute to free resources.
* libnm/tests: extend nmtstc_client_new() to create other GObject typesThomas Haller2020-01-282-85/+129
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* shared/tests: add nmtst_main_context_iterate_until() helperThomas Haller2020-01-281-3/+12
| | | | | Like nmtst_main_context_iterate_until_assert(), but allows to run into timeout.
* shared/tests/trivial: rename nmtst_main_context_iterate_until() to ↵Thomas Haller2020-01-281-1/+1
| | | | | | | | | 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.
* shared/tests: use nmtst_g_source_set_boolean_true() in ↵Thomas Haller2020-01-281-11/+1
| | | | nmtst_main_context_iterate_until()
* shared/tests: add nmtst_main_context_assert_no_dispatch() helperThomas Haller2020-01-281-0/+20
|
* shared/tests: add nmtst_g_source_set_boolean_true() helperThomas Haller2020-01-281-9/+20
|
* shared/tests: add nmtst_context_busy_watcher_wait() helperThomas Haller2020-01-281-0/+68
|
* shared: add nm_g_main_context_is_thread_default() utilThomas Haller2020-01-281-0/+19
|
* shared: add NM_UTILS_USEC_PER_SEC macroThomas Haller2020-01-281-1/+2
|
* shared: add _NM_MACRO_COMMA_IF_ARGS() helper macroThomas Haller2020-01-281-0/+5
|
* shared: cleanup NM_NARG() and related macrosThomas Haller2020-01-281-40/+48
| | | | | | | | - 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.
* n-dhcp4: accept options that are longer than requestedBeniamino Galvani2020-01-251-4/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If the server sends a packet with multiple instances of the same option, they are concatenated during n_dhcp4_incoming_linearize() and evaluated as a single option as per section 7 of RFC 3396. However, there are broken server implementations that send self-contained options in multiple copies. They are reassembled to form a single instance by the nettools client, which then fails to parse them because they have a length greater than the expected one. This problem can be reproduced by starting a server with: dnsmasq --bind-interfaces --interface veth1 -d --dhcp-range=172.25.1.100,172.25.1.200,1m --dhcp-option=54,172.25.1.1 In this way dnsmasq sends a duplicate option 54 (server-id) when the client requests it in the 'parameter request list' option, as dhcp=systemd and dhcp=nettools currently do. While this is a violation of the RFC by the server, both isc-dhcp and systemd-networkd client implementations have mechanisms to deal with this situation. dhclient simply takes the first bytes of the aggregated option. systemd-networkd doesn't follow RFC 3396 and doesn't aggregate multiple options; it considers only the last occurrence of each option. Change the parsing code to accept options that are longer than necessary. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/324
* shared: remove nm_dbus_connection_signal_subscribe_object_manager() helperThomas Haller2020-01-162-111/+7
| | | | | | It seems to complicate things more than helping. Drop it. What we still have is a wrapper around plain g_dbus_connection_signal_subscribe(). That one is trivial and helpful. The previous wrapper seems to add more complexity.
* shared: add nm_source_func_unref_gobject() helperThomas Haller2020-01-161-0/+8
|
* shared/tests: add nmtst_file_set_contents_size() helperThomas Haller2020-01-161-2/+14
|
* license: relicense "shared/nm-std-aux/nm-dbus-compat.h" under LGPL-2.1+Thomas Haller2020-01-141-49/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | "nm-dbus-compat.h" was GPL licensed. That is a problem, because we use it from libnm (which is LGPL). The history of this file in NetworkManager source tree: $ git shortlog -n -s e055bdbbc3e7bb3ff3bc73860c4479f15bbfe7b2 -- shared/nm-std-aux/nm-dbus-compat.h include/nm-dbus-compat.h shared/nm-dbus-compat.h 5 Thomas Haller 1 Dan Winship 1 Lubomir Rintel Note that commit dd0e19895532 ('include: add nm-dbus-compat.h') introduced this file from dbus sources ([1]). Hence, originally the file is (like all of dbus sources) dual-licensed under GPL-2.0+ and Academic Free License 2.1 (AFL-2.1). That makes it problematic to change the license of this file to LGPL also because of the old history of the file. Instead, drop everything from the header except the bits that we actually use. I claim the remainder is trivial and only contains defines for documented D-Bus API. I don't think that the remainder is copyrightable and hence get rid of the copy-right notice and the GPL license. [1] https://gitlab.freedesktop.org/dbus/dbus/blob/39ea37b587c9fa4c5e8d0aff08b043617b22f50a/dbus/dbus-shared.h
* n-dhcp4: fix integer context in n_dhcp4_client_probe_transition_nak() on 32 bitThomas Haller2020-01-141-3/+3
| | | | | | Fixes: 218782a9a3c3 ('n-dhcp4: restart the transaction after a NAK') https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/339
* libnm-core,cli: add VRF settingBeniamino Galvani2020-01-142-0/+8
| | | | | Add new VRF setting and connection types to libnm-core and support them in nmcli.
* shared/udev: don't use GIOChannel to watch plain file descriptorThomas Haller2020-01-131-11/+9
|
* shared: add nm_g_unix_fd_source_new() helperThomas Haller2020-01-132-1/+28
|
* shared: use G_SOURCE_FUNC() macro in "shared/nm-test-utils-impl.c"Thomas Haller2020-01-131-1/+1
|
* shared: improve nm_free_secret() to clear entire memory bufferThomas Haller2020-01-092-8/+27
| | | | | | | | | | The purpose is to clear the entire available buffer, not only up to the first '\0'. This is done, because otherwise we might leak sensitive data that happens to be after the first '\0', or we might give away the length of the secrets. Of course, those are very (very) minor concerns. But avoiding them is easy enough.
* n-dhcp4: use C_CLAMP() macro instead of c_clamp()Beniamino Galvani2020-01-091-1/+1
| | | | | | | | | | | | | | | The latter requires __auto_type which is not available in GCC versions older than 4.9. Fix the following compile error on RHEL 7.8: CC src/src_libNetworkManagerBase_la-NetworkManagerUtils.lo shared/n-dhcp4/src/n-dhcp4-c-probe.c: In function 'n_dhcp4_client_probe_transition_nak': shared/n-dhcp4/src/n-dhcp4-c-probe.c:1008:17: error: unknown type name '__auto_type' probe->ns_nak_restart_delay = c_clamp(probe->ns_nak_restart_delay * 2, ^ shared/n-dhcp4/src/n-dhcp4-c-probe.c:1008:17: error: unknown type name '__auto_type' shared/n-dhcp4/src/n-dhcp4-c-probe.c:1008:17: error: unknown type name '__auto_type' Fixes: 218782a9a3c3 ('n-dhcp4: restart the transaction after a NAK')
* n-dhcp4: restart the transaction after a NAKBeniamino Galvani2020-01-092-4/+7
| | | | | | | | | | | | | | It is not enough to set the INIT state after a NAK; a timeout (ns_deferred) must be set so that it is added to the event fd. The client retries immediately the first time, so that in the successful case it gets an address quickly. To avoid flooding the network in case of servers always replying with NAKs, next attempts are done with intervals from 2 seconds to 5 minutes using exponential backoff. See also systemd commit [1]. [1] https://github.com/systemd/systemd/commit/1d1a3e0afb85478cda43670b8ed92a6db6c83f3e https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/325
* n-dhcp4: allow calling listen() on already listening connectionBeniamino Galvani2020-01-091-0/+3
| | | | | | | When the client enters the INIT state, it calls listen() on the connection connection to create the packet socket. However, if the client is coming from the REBOOTING state after a NAK, the connection is already in the listening state; do nothing in such case.
* libnm/keyfile: build keyfile code as separate GPL licensed internal libraryThomas Haller2020-01-075-0/+4995
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Keyfile support was initially added under GPL-2.0+ license as part of core. It was moved to "libnm-core" in commit 59eb5312a5d6 ('keyfile: merge branch 'th/libnm-keyfile-bgo744699''). "libnm-core" is statically linked with by core and "libnm". In the former case under terms of GPL-2.0+ (good) and in the latter case under terms of LGPL-2.1+ (bad). In fact, to this day, "libnm" doesn't actually use the code. The linker will probably remove all the GPL-2.0+ symbols when compiled with gc-sections or LTO. Still, linking them together in the first place makes "libnm" only available under GPL code (despite the code not actually being used). Instead, move the GPL code to a separate static library "shared/nm-keyfile/libnm-keyfile.la" and only link it to the part that actually uses the code (and which is GPL licensed too). This fixes the license violation. Eventually, it would be very useful to be able to expose keyfile handling via "libnm". However that is not straight forward due to the licensing conflict. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/merge_requests/381
* shared: don't allow NULL arguments with g_hash_table_steal_extended() compat ↵Thomas Haller2019-12-311-5/+14
| | | | | | | | implementation We cannot know the key/value free functions, hence, our compat implementation cannot free the values if they are not requested. The "solution" is to require the caller to fetch all values, always.
* shared: nm-auth-subject: add unix-session typeAntonio Cardace2019-12-242-45/+102
|
* shared: move nm-dbus-auth-subject to shared/nm-libnm-core-internAntonio Cardace2019-12-243-0/+447
| | | | | | | | Move it to shared as it's useful for clients as well. Move and rename nm_dbus_manager_new_auth_subject_from_context() and nm_dbus_manager_new_auth_subject_from_message() in nm-dbus-manager.c as they're needed there.
* shared: add io-util to read data from a fd into a GStringAntonio Cardace2019-12-242-0/+34
|
* n-dhcp4: handle invalid return codes gracefullyBeniamino Galvani2019-12-231-1/+6
| | | | | | | | Instead of terminating the program when the dispatch function returns an invalid return code, log an error message and convert the error code to a valid, generic one. https://bugs.archlinux.org/task/64880
* n-dhcp4: use packet socket in rebinding stateBeniamino Galvani2019-12-232-3/+30
| | | | | | | After t1, the client tries to renew the lease by contacting via the udp socket the server specified in the server-id option. If this fails, after t2 it tries to contact any server using broadcast. For this to work, the packet socket must be used.
* n-dhcp4: support init-reboot stateBeniamino Galvani2019-12-233-7/+80
| | | | | | | | | | | | | | | | Currently the client always starts from the INIT state (i.e. sending a discover message). If a requested-ip was specified by the caller, it is added as an option in the discover. It was reported that some DHCP servers don't respond to discover messages with the requested-ip option set [1][2]. The RFC allows to skip the discover by entering the INIT-REBOOT state and starting directly with a broadcast request message containing the requested IP address. Implement that. [1] https://bugzilla.redhat.com/show_bug.cgi?id=1781856 [2] https://gitlab.freedesktop.org/NetworkManager/NetworkManager/issues/310
* n-dhcp4: fix logging broadcast messagesBeniamino Galvani2019-12-231-0/+7
| | | | | Log the broadcast address instead of the server IP as destination when needed.
* shared/glib: add compat implementation for g_hash_table_steal_extended()Thomas Haller2019-12-211-0/+28
|
* core: add and indicate NM_CAPABILITY_OVS capability on D-BusThomas Haller2019-12-211-0/+4
| | | | https://bugzilla.redhat.com/show_bug.cgi?id=1785147
* shared: add missing va_end() to _nm_dbus_error_is()Beniamino Galvani2019-12-181-1/+3
| | | | | | | | | Found by covscan: NetworkManager-1.22.0/shared/nm-glib-aux/nm-dbus-aux.c:361: missing_va_end: va_end was not called for "ap". Fixes: ce36494c0a48 ('shared: add nm_dbus_error_is() helper')
* shared: implement _LOGx() macros using log levels that are themself definesThomas Haller2019-12-161-63/+69
| | | | | | | | | | | "nm-glib-aux/nm-logging-fwd.h" provides macros like _LOGD() to be reused by various parts which implement logging (by defining _NMLOG() accordingly). libnm also has logging, however it uses different logging levels aside LOGD_DEBUG. Instead, implement _LOGD() using a define _LOGL_DEBUG, so that libnm can redefine thos _LOGL_DEBUG defines and use the _LOGD() macro.