summaryrefslogtreecommitdiff
path: root/shared
Commit message (Collapse)AuthorAgeFilesLines
* libnm: rename nm_setting_gendata_*() API to nm_setting_option_*()Thomas Haller2020-05-221-3/+3
| | | | | | | | | | | We are going to expose some of this API in libnm. The name "gendata" (for "generic data") is not very suited. Instead, call the public API nm_setting_option_*(). This also brings no naming conflict, because currently no API exists with such naming. Rename the internal API, so that it matches the API that we are going to expose next.
* ethtool: add and use _NM_ETHTOOL_ID_FEATURE_AS_IDX() macroThomas Haller2020-05-221-0/+1
|
* platform: make states of NMEthtoolCoalesceState indexed by ethtool_idThomas Haller2020-05-221-0/+2
| | | | | | | | | | | | | | | | | | We already have NMEthtoolID to handle coalesce options in a way that is convenient programmatically. That is, we can iterate over all valid coalesce options (it's just an integer) and use that in a more generic way. If NMEthtoolCoalesceState names all fields explicitly, we need explicit code that names each coalesce option. Especially since NMEthtoolCoalesceState is an internal and intermediate data structure, this is cumbersome and unnecessary. Thereby it also fixes the issue that nm_platform_ethtool_init_coalesce() has a NMPlatform argument without actually needing it. nm_platform_ethtool_init_coalesce() does not operate on a NMPlatform instance, and should not have the appearance of being a method of NMPlatform.
* ifcfg-rh: add support for ethtool ring settingsAntonio Cardace2020-05-202-0/+23
| | | | | | Also update unit tests. https://bugzilla.redhat.com/show_bug.cgi?id=1614700
* ethtool: add ring settingsAntonio Cardace2020-05-202-1/+22
| | | | | | | | | This is the initial support for ring settings and only allows getting/setting, nothing is yet implemented in nm-device. Also add unit test. https://bugzilla.redhat.com/show_bug.cgi?id=1614700
* n-dhcp4: style fix in n_dhcp4_client_probe_transition_accept()Thomas Haller2020-05-181-1/+1
| | | | | | | The upstream fix also doesn't have this whitespace. Keep the sources in sync. https://github.com/nettools/n-dhcp4/commit/0be7033dd9403cf10a21333a4121934ca06c1cee
* shared: move _nm_utils_format_variant_attributes*() API to "shared/nm-glib-aux"Thomas Haller2020-05-142-0/+106
| | | | | This has no dependency on libnm, libnm-core, or src. Move it to the general purpose toolbox.
* build: fix redefinition of VALGRIND define in "nm-sd-adapt-shared.h"Thomas Haller2020-05-131-0/+2
| | | | | | | | | | | | | When configuring with sanitizers enabled, ./configure.ac sets -DVALGRIND=1 in the CFLAGS. This causes a compilation error later: $ /bin/sh ./libtool --tag=CC --mode=compile gcc ... -DVALGRIND=1 ... src/dhcp/nm-dhcp-nettools.c ... In file included from src/dhcp/nm-dhcp-nettools.c:16: ./shared/systemd/sd-adapt-shared/nm-sd-adapt-shared.h:73: error: "VALGRIND" redefined [-Werror] #define VALGRIND 0
* shared: add NM_UTILS_NAMED_VALUE_INIT() macroThomas Haller2020-05-132-0/+5
|
* shared: support stripping whitespace from nm_utils_buf_utf8safe_unescape()Thomas Haller2020-05-132-11/+40
| | | | | | | | | | | | | When parsing user input if is often convenient to allow stripping whitespace. Especially with escaped strings, the user could still escape the whitespace, if the space should be taken literally. Add support for that to nm_utils_buf_utf8safe_unescape(). Note that this is not the same as calling g_strstrip() before/after unescape. That is, because nm_utils_buf_utf8safe_unescape() correctly preserves escaped whitespace. If you call g_strstrip() before/after the unescape, you don't know whether the whitespace is escaped.
* shared: assert that nm_utils_buf_utf8safe_unescape() doesn't reallocate memoryThomas Haller2020-05-132-2/+23
| | | | | | | | | | We want to use the function to unescape (compress) secrets. As such, we want to be sure that no secrets are leaked in memory due to growing the buffer with realloc. In fact, reallocation should never happen. Assert for that. As reallocation cannot happen, we could directly fill a buffer with API like nm_utils_strbuf_*(). But NMStrBuf has low overhead even in this case.
* ethtool: add coalesce settingsAntonio Cardace2020-05-132-2/+78
| | | | | | | | | This is the initial support for coalesce settings and only allows getting/setting, nothing is yet implemented in nm-device. Also add unit test. https://bugzilla.redhat.com/show_bug.cgi?id=1614700
* keyfile: add support for uint32 variant types when using gendataAntonio Cardace2020-05-131-0/+21
| | | | https://bugzilla.redhat.com/show_bug.cgi?id=1614700
* ethtool: accept %NULL as argument for ↵Thomas Haller2020-05-111-1/+2
| | | | | | | | | nm_ethtool_data_get_by_optname()/nm_ethtool_id_get_by_name() Often it is useful to not accept %NULL as input argument, to catch bugs. For simple functions like nm_ethtool_id_get_by_name(), such limitations are more annoying than helpful. Gracefully accept %NULL and treat is like an invalid ethtool option.
* ethtool: use NM_MORE_ASSERT_ONCE() in _ASSERT_data() to assert immutable ↵Thomas Haller2020-05-111-2/+3
| | | | | | | | | | | data only once _ASSERT_data() checks static, immutable data. Even with more asserts enabled, there is no need to do that every time. Use NM_MORE_ASSERT_ONCE(). Note that NM_MORE_ASSERT_ONCE() will return constant FALSE, when build without a sufficiently high assertion level. That means, the compiler will just optimize the rest away.
* all: use "int/char" instead of "gint/gchar" typedefsThomas Haller2020-05-081-1/+1
| | | | This is also recommended by our checkpatch.pl script.
* shared: add nm_str_is_empty() helperThomas Haller2020-05-081-2/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | We have nm_str_not_empty() which is the inverse of that. The purpose of nm_str_not_empty() is to normalize a string to either return %NULL or a non-empty string, like const char * get_name (Object *obj) { return nm_str_not_empty (obj->name); } Sometimes, we however want to check whether a string is not empty. So, we previously had two choices: 1) use a temporary variable: const char *tmp; tmp = get_string (); if (tmp && tmp[0]) ... The problem with this variant is that it's more verbose (by requiring a temporary variable). Another downside is that there are multiple ways how to check for an empty string (!tmp[0], tmp[0] == '\0', !strlen (tmp), strlen (tmp) == 0), and sure enough they are all in use. 2) use !nm_str_not_empty(). But this double negation looks really odd and confusing. Add nm_str_is_empty() instead.
* shared: add NM_G_PARAM_SPEC_GET_DEFAULT_*() helper macrosThomas Haller2020-05-081-0/+19
|
* shared: add NM_ENSURE_NOT_NULL() macroThomas Haller2020-05-081-0/+8
|
* keyfile: use nm_g_error_matches() in g_error_matches()Thomas Haller2020-05-071-4/+4
| | | | | | nm_g_error_matches() can be inlined and first checks whether the error argument is not NULL. At least from the keyfile accessor functions, use this macro, as they are called many times.
* keyfile,config: use nm_keyfile_error_is_not_found() helperThomas Haller2020-05-071-6/+2
|
* shared: add nm_keyfile_error_is_not_found() helperThomas Haller2020-05-071-0/+12
|
* shared: add nm_g_error_matches() helperThomas Haller2020-05-071-0/+15
|
* shared: add NM_STR_HAS_PREFIX_WITH_MORE() helperThomas Haller2020-05-071-0/+10
|
* shared: fix accessing "str" argument to NM_STR_HAS_PREFIX() macro twiceThomas Haller2020-05-071-6/+11
| | | | | | | | | | | | Macros preferably behave function-like, for example in that they evaluate arguments exactly ones. Sometimes, we want to evaluate arguments lazily, like in NM_IN_SET() or nm_g_set_error_take_lazy(). But it is almost always undesirable to evaluate an argument more than once. Fix NM_STR_HAS_PREFIX() for that. Also, rename the local variable to not use the name "_str", which may be a common name that the caller would like to use.
* tests: add include guard to "nm-test-libnm-utils.h" headerThomas Haller2020-05-071-0/+5
| | | | It causes a warning on lgtm.com.
* shared: add nm_strvarray_*() helper APIThomas Haller2020-05-061-0/+48
| | | | | | GPtrArray does not support NULL terminating the pointer array. That makes it cumbersome to use it for tracking a strv array. Add a few helper functions nm_strvarray_*() that help using a GArray instead.
* shared: add nm_indirect_g_free() helperThomas Haller2020-05-062-0/+22
|
* shared: add nm_g_array_len() helperThomas Haller2020-05-061-0/+8
|
* shared: add nm_g_ptr_array_len() helperThomas Haller2020-05-061-0/+8
|
* keyfile: implement nm_keyfile_plugin_kf_get_string_list() directly without macroThomas Haller2020-05-041-29/+26
| | | | There is only one user of the macro left. Drop it.
* keyfile: add nm_keyfile_plugin_kf_get_integer_list_uint() to parse a list of ↵Thomas Haller2020-05-043-26/+65
| | | | | | | | | | | | | | | | | | | | | integers We had three callers of nm_keyfile_plugin_kf_get_integer_list(). Two only wanted to read values in range of guint8. One, wanted to read unsigned integers (for which nm_keyfile_plugin_kf_get_integer_list() was not suitable). Instead, implement a integer list reader ourself. One change is that g_key_file_get_integer_list() would accept list elements with a number followed by a white space and garbage ([1]). We don't do that, so there is a change in behavior here. That seems preferable, we don't want to accept garbage. The error reason text from the reader now also changes, and obviously we no longer fail for integer values larger than G_MAXINT. [1] https://gitlab.gnome.org/GNOME/glib/-/blob/c9bf247eb90805cc7a0020db20b8808ed42fe61c/glib/gkeyfile.c#L4445
* keyfile: implement nm_keyfile_plugin_kf_set_string_list() directly without macroThomas Haller2020-05-041-14/+11
| | | | There is only one user of the macro left. Drop it.
* keyfile: refactor writing of G_TYPE_ARRAY list of unsigned integersThomas Haller2020-05-043-17/+31
| | | | | | | | | | | | | | | | | | Keyfile handles GObject properties of type G_TYPE_ARRAY as a GArray of unsigned ints. That is correct, because all our properties of this GType happen to be of this kind. However, then the function was using nm_keyfile_plugin_kf_set_integer_list(), which only can handle signed integers. There was thus an assertion that all integers were non-negative. Which, probably was also correct, because NMSettingDcb would validate that all values of such kind are in fact positive. Anyway, that is an unexpected limitation (if not a bug). Fix that by handling the array as unsigned list of integers. Also, since glib doesn't provide an API for storing lists of unsigend integers, we have to implement our own. but that is no loss. We probably do it better anyway.
* keyfile: use NMStrBuf in nm_keyfile_plugin_kf_set_integer_list_uint8()Thomas Haller2020-05-042-15/+9
| | | | | | | | | | | Previously, we were preallocating a string buffer of fixed size. For guint8 we reserved 3 characters per number, which is sufficient. However, it is not obviously sufficient. NMStrBuf would grow as needed. Next, I will add nm_keyfile_plugin_kf_set_integer_list_uint(), where it is more unclear how large the string can be at most. To avoid that question from the start, it will use NMStrBuf. To keep the implementations similar, use NMStrBuf also in this case.
* keyfile: refactor defining keyfile list getter/setter functionsThomas Haller2020-05-041-21/+24
|
* keyfile: refactor defining keyfile getter/setter functionsThomas Haller2020-05-041-20/+24
| | | | | | | | | | | | | | Split the macros to define the setter and getter so that setters and getters are defined by separate macros. This will be used to define the boolean getter differently, but still using the macro to define the setter. Also, don't construct function names in the macro. Instead, pass the full names as argument to the macro. This helps with the problem where ctags/cscope is unable to locate the implementation of the function. Since we define the function with macro, the tools still don't recognize this as the location of the definition. But at least when showing all occurrences of the name, it can be found.
* n-dhcp4: don't fail dispatch in case of receive errorsBeniamino Galvani2020-04-302-8/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Currently any error encountered in n_dhcp4_c_connection_dispatch_io() causes a dispatch failure and interrupts the library state machine. The recvmsg() on the socket can fail for different reasons; one of these is for example that the UDP request previously sent got a ICMP port-unreachable response. This can be reproduced in the following way: ip netns add ns1 ip link add veth0 type veth peer name veth1 ip link set veth1 netns ns1 ip link set veth0 up cat > dhcpd.conf <<EOF server-identifier 172.25.0.1; max-lease-time 120; default-lease-time 120; subnet 172.25.0.0 netmask 255.255.255.0 { range 172.25.0.100 172.25.0.200; } EOF ip -n ns1 link set veth1 up ip -n ns1 address add dev veth1 172.25.0.1/24 ip netns exec ns1 iptables -A INPUT -p udp --dport 67 -j REJECT ip netns exec ns1 dhcpd -4 -cf dhcpd.conf -pf /tmp/dhcp-server.pid If a client is started on veth0, it is able to obtain a lease despite the firewall rule blocking DHCP, because dhcpd uses a packet socket. Then it fails during the renewal because the recvmsg() fails: dhcp4 (veth0): send REQUEST of 172.25.0.178 to 172.25.0.1 dhcp4 (veth0): error -111 dispatching events dhcp4 (veth0): state changed bound -> fail The client should consider such errors non fatal and keep running. https://bugzilla.redhat.com/show_bug.cgi?id=1829178 https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/486
* keyfile: don't declare keyfile getters/setter functions with macroThomas Haller2020-04-301-40/+21
| | | | | | In general, I like macros. But in this case it seems the make the code harder to understand than it needs to be. There are repeated patterns in these declarations, but I feel they are better recognizible by aligning the lines nicely.
* shared/glib: prevent users to use g_cancellable_reset()Thomas Haller2020-04-281-0/+8
| | | | | | | | | | | | | | When handling a GCancellable, you make decisions based on when the cancelled property of a GCancellable changes. Correctly handling a cancellable becoming uncancelled again is really complicated, nor is it clear what it even means: should the flipping be treated as cancellation or not? Probably if the cancelled property gets reset, you already start aborting and there is no way back. So, you would want that a cancellation is always handled. But it's hard to implement that correctly, and it's odd to claim something was cancelled, if g_cancellable_is_cancelled() doesn't agree (anymore). Avoid such problems by preventing users to call g_cancellable_reset().
* shared: add nm_gbytes_get_empty() singleton getterThomas Haller2020-04-282-0/+20
|
* shared: add nm_gbytes_hash() and nm_gbytes_equal()Thomas Haller2020-04-282-0/+14
|
* dhcp: make connection.mud-url configurable as global connection defaultThomas Haller2020-04-281-0/+2
| | | | | | | | | | | | | | | | | | Conceptionally, the MUD URL really depends on the device, and not so much the connection profile. That is, when you have a specific IoT device, then this device probably should use the same MUD URL for all profiles (at least by default). We already have a mechanism for that: global connection defaults. Use that. This allows a vendor drop pre-install a file "/usr/lib/NetworkManager/conf.d/10-mud-url.conf" with [connection-10-mud-url] connection.mud-url=https://example.com Note that we introduce the special "connection.mud-url" value "none", to indicate not to use a MUD URL (but also not to consult the global connection default).
* dhcp: enforce MUD URL to use "https://" schemeThomas Haller2020-04-242-13/+18
| | | | | | | | | | | | nm_sd_http_url_is_valid_https() is rather clunky, but it is this way, because we must not disagree with systemd code about what makes a valid URL. RFC 8520 says "MUD URLs MUST use the "https" scheme". See-also: https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/463#note_476190 Fixes: cedcea5ee812 ('libnm: fix verification of connection:mud-url property')
* shared: add nm_utils_invoke_on_timeout()Thomas Haller2020-04-242-32/+84
| | | | | | | | | | | | | | | | | | Add nm_utils_invoke_on_timeout() beside nm_utils_invoke_on_idle(). They are fundamentally similar, except one schedules an idle handler and the other a timeout. Also, use the current g_main_context_get_thread_default() as context instead of the singleton instance. That is a change in behavior, but the only caller of nm_utils_invoke_on_idle() is the daemon, which doesn't use different main contexts. Anyway, to avoid anybody being tripped up by this also change the order of arguments. It anyway seems nicer to first pass the cancellable, and the callback and user data as last arguments. It's more in line with glib's asynchronous methods. Also, in the unlikely case that the cancellable is already cancelled from the start, always schedule an idle action to complete fast.
* systemd: add nm_sd_http_url_is_valid() to access internal http_url_is_valid()Thomas Haller2020-04-243-15/+61
|
* shared: add NM_CMP_DIRECT_PTR() macroThomas Haller2020-04-221-0/+8
|
* keyfile: minor cleanup handling error in read_array_of_uint()Thomas Haller2020-04-151-2/+3
| | | | | | Why "if (length > G_MAXUINT)"? This is never going to hit. Also, we probably should actual missing keys handle differently from empty lists. If @error is set, return without setting the property.
* keyfile: avoid assertion failure in ↵Thomas Haller2020-04-151-1/+0
| | | | | | | | | | | | | | nm_keyfile_plugin_kf_get_{string,integer}_list() g_key_file_get_integer_list() can return %NULL without setting an error. That is the case if the key is set to an empty value. For X sake, this API. Read the documentation and figure out whether the function can return %NULL without reporting an error. Anyway, avoid the assertion failure. https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/issues/412
* keyfile: cleanup mac_address_parser()Thomas Haller2020-04-151-52/+29
|