Commit graph

1087 commits

Author SHA1 Message Date
Thomas Haller
e2f83d4e92
keyfile: add NMKeyfileHandlerFlags
nm_keyfile_read() and nm_keyfile_write() will be public API.
As such, it must be flexible and extendible for future needs.
There is already the handler callback that fully solves this
(e.g. a future handler event could request whether a certain
behavior is enabled or not).

As additional possibility for future extension, add a flags
argument. Currently no flags are implemented.
2020-06-05 09:17:21 +02:00
Thomas Haller
00b3a3505a
keyfile: add nm_keyfile_handler_data_warn_get() and construct message lazy
Add an accessor for the warning event.

Also, as we now have an accessor, we can construct the warning
message only if it actually needed.
2020-06-05 09:17:20 +02:00
Thomas Haller
4230a1d4fb
keyfile: add accessors for NMKeyfileHandlerData
For introspection/bindings it is cumbersome to access the
fields of the NMKeyfileHandlerData struct. Instead add accessor
functions.

Also, we wouldn't want to expose the struct in public API directly,
because it makes it harder to extend it without breaking ABI.
2020-06-05 09:17:20 +02:00
Thomas Haller
7d47a8fdbf
keyfile: add handler context for all parser callbacks
From inside a callback 4 properties are potentially interesting
to all callbacks: the currenty group, key, setting and property-name.

Refactor the code to track these properties in NMKeyfileHandlerData
and distinguish between the property name and the keyfile key.
2020-06-05 09:17:19 +02:00
Thomas Haller
5c67b72bb7
keyfile: use cleanup attribute for GBytes and GByteArray 2020-06-05 09:17:19 +02:00
Thomas Haller
021726e54e
keyfile: don't check for info->error before calling handle_warn()
When an error gets set, we should abort right away. We should
not come into a situation where we would try to emit another warning.

Don't check for a condition that should never happen and assert
against it.
2020-06-05 09:17:19 +02:00
Thomas Haller
8afb8ba819
keyfile: style cleanup calling handle_warn() 2020-06-05 09:17:18 +02:00
Thomas Haller
ab7d0c62f9
keyfile: rework error reporting from read/write handler
Setting the error on the callback does not work well from bindings.
Instead, let bindings call a (future) nm_keyfile_handler_data_fail_with_error()
function on the handler_data to indicate failure.
2020-06-05 09:17:18 +02:00
Thomas Haller
e3d7ba89e5
keyfile: rename handler variable in KeyfileReaderInfo and KeyfileWriterInfo 2020-06-05 09:17:18 +02:00
Thomas Haller
0bfdb26973
keyfile: add NMKeyfileHandlerData typedef for arguments of keyfile callbacks
As the keyfile handler callback will become public API, it needs to be
usable via bindings. A plain void pointer is not usable. Instead, add
a new type that can be used via introspection.
2020-06-05 09:17:18 +02:00
Thomas Haller
18c1fe6ed8
keyfile: merge NMKeyfile{Read,Write}Type as NMKeyfileHandlerType
This will become public API. The enum for read and write callback
serves very similar purposes. Merge them so that we have fewer
types in the public API.
2020-06-05 09:17:14 +02:00
Thomas Haller
65b6fc7871
nettools: reimport nettools' n-dhcp4 and rework logging
git subtree pull --prefix shared/n-dhcp4/ git@github.com:nettools/n-dhcp4.git master --squash
2020-06-03 22:34:22 +02:00
Thomas Haller
53f27cfd40
shared/n-acd: reimport
git subtree pull --prefix shared/n-acd git@github.com:nettools/n-acd.git master --squash
2020-06-03 22:14:39 +02:00
Thomas Haller
fc11843fdc
shared/c-siphash: reimport
git subtree pull --prefix shared/c-siphash git@github.com:c-util/c-siphash.git master --squash
2020-06-03 22:10:22 +02:00
Thomas Haller
f9641b6b47
shared/c-rbtree: reimport
git subtree pull --prefix shared/c-rbtree git@github.com:c-util/c-rbtree.git master --squash
2020-06-03 22:08:05 +02:00
Thomas Haller
a75d7de78b
shared/c-stdaux: reimport
git subtree pull --prefix shared/c-stdaux git@github.com:c-util/c-stdaux.git master --squash
2020-06-03 22:05:14 +02:00
Thomas Haller
70c71151c6
shared/c-list: reimport
git subtree pull --prefix shared/c-list git@github.com:c-util/c-list.git master --squash
2020-06-03 22:00:56 +02:00
Thomas Haller
82a468c9ad
keyfile: suppress bogus warning about [ethernet-s390-options] setting
S390 options are stored in a separate [ethernet-s390-options] section.
This group must not be interpreted as a NMSetting name, otherwise we
log a bogus warning:

  <warn>  [1590523563.7757] keyfile: ethernet-s390-options: invalid setting name 'ethernet-s390-options'

Fixes: cf9b8d3bad ('libnm/keyfile: implement ethernet.s390-options in keyfile')
2020-05-26 22:45:10 +02:00
Thomas Haller
618ae93b94
libnm: rename nm_setting_gendata_*() API to nm_setting_option_*()
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.
2020-05-22 15:58:08 +02:00
Thomas Haller
dcb4ed2cb1
ethtool: add and use _NM_ETHTOOL_ID_FEATURE_AS_IDX() macro 2020-05-22 15:58:08 +02:00
Thomas Haller
1f4b190934
platform: make states of NMEthtoolCoalesceState indexed by ethtool_id
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.
2020-05-22 15:58:08 +02:00
Antonio Cardace
e04e5a5c2a
ifcfg-rh: add support for ethtool ring settings
Also update unit tests.

https://bugzilla.redhat.com/show_bug.cgi?id=1614700
2020-05-20 10:55:01 +02:00
Antonio Cardace
7109ac667a
ethtool: add ring settings
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
2020-05-20 10:55:01 +02:00
Thomas Haller
0480448e66
n-dhcp4: style fix in n_dhcp4_client_probe_transition_accept()
The upstream fix also doesn't have this whitespace.
Keep the sources in sync.

0be7033dd9
2020-05-18 09:54:28 +02:00
Thomas Haller
ef9fe85096
shared: move _nm_utils_format_variant_attributes*() API to "shared/nm-glib-aux"
This has no dependency on libnm, libnm-core, or src. Move it to the
general purpose toolbox.
2020-05-14 17:21:12 +02:00
Thomas Haller
3c581cbb78
build: fix redefinition of VALGRIND define in "nm-sd-adapt-shared.h"
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
2020-05-13 17:21:01 +02:00
Thomas Haller
bb19f6e29c
shared: add NM_UTILS_NAMED_VALUE_INIT() macro 2020-05-13 10:28:04 +02:00
Thomas Haller
0f22f77b1c
shared: support stripping whitespace from nm_utils_buf_utf8safe_unescape()
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.
2020-05-13 10:28:04 +02:00
Thomas Haller
5fe447d4a6
shared: assert that nm_utils_buf_utf8safe_unescape() doesn't reallocate memory
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.
2020-05-13 10:28:04 +02:00
Antonio Cardace
b0240db068
ethtool: add coalesce settings
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
2020-05-13 10:15:23 +02:00
Antonio Cardace
858fb211ad
keyfile: add support for uint32 variant types when using gendata
https://bugzilla.redhat.com/show_bug.cgi?id=1614700
2020-05-13 10:15:23 +02:00
Thomas Haller
0d7d2425c4
ethtool: accept %NULL as argument for 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.
2020-05-11 16:18:22 +02:00
Thomas Haller
2027ff50af
ethtool: use NM_MORE_ASSERT_ONCE() in _ASSERT_data() to assert immutable 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.
2020-05-11 14:47:43 +02:00
Thomas Haller
2929392855
all: use "int/char" instead of "gint/gchar" typedefs
This is also recommended by our checkpatch.pl script.
2020-05-08 12:56:29 +02:00
Thomas Haller
dbf14dc38c
shared: add nm_str_is_empty() helper
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.
2020-05-08 11:10:51 +02:00
Thomas Haller
0b2ecf5e35
shared: add NM_G_PARAM_SPEC_GET_DEFAULT_*() helper macros 2020-05-08 08:02:48 +02:00
Thomas Haller
a0b2955907
shared: add NM_ENSURE_NOT_NULL() macro 2020-05-08 08:00:41 +02:00
Thomas Haller
5cdb636301
keyfile: use nm_g_error_matches() in g_error_matches()
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.
2020-05-07 14:08:32 +02:00
Thomas Haller
e08bb66b34
keyfile,config: use nm_keyfile_error_is_not_found() helper 2020-05-07 14:08:32 +02:00
Thomas Haller
df27164d5e
shared: add nm_keyfile_error_is_not_found() helper 2020-05-07 14:08:32 +02:00
Thomas Haller
e31b31e5e5
shared: add nm_g_error_matches() helper 2020-05-07 14:08:31 +02:00
Thomas Haller
a617177070
shared: add NM_STR_HAS_PREFIX_WITH_MORE() helper 2020-05-07 14:08:31 +02:00
Thomas Haller
5a09292f1f
shared: fix accessing "str" argument to NM_STR_HAS_PREFIX() macro twice
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.
2020-05-07 14:08:31 +02:00
Thomas Haller
9e6d6191d1
tests: add include guard to "nm-test-libnm-utils.h" header
It causes a warning on lgtm.com.
2020-05-07 13:58:10 +02:00
Thomas Haller
5056e0d3c8
shared: add nm_strvarray_*() helper API
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.
2020-05-06 15:19:27 +02:00
Thomas Haller
8dd74fe364
shared: add nm_indirect_g_free() helper 2020-05-06 15:19:25 +02:00
Thomas Haller
070535c6f6
shared: add nm_g_array_len() helper 2020-05-06 15:19:24 +02:00
Thomas Haller
46bee5298b
shared: add nm_g_ptr_array_len() helper 2020-05-06 15:19:23 +02:00
Thomas Haller
3ebfb67df4
keyfile: implement nm_keyfile_plugin_kf_get_string_list() directly without macro
There is only one user of the macro left. Drop it.
2020-05-04 13:12:43 +02:00
Thomas Haller
dade5055fb
keyfile: add nm_keyfile_plugin_kf_get_integer_list_uint() to parse a list of 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] c9bf247eb9/glib/gkeyfile.c (L4445)
2020-05-04 13:12:43 +02:00