Commit Graph

419 Commits

Author SHA1 Message Date
Patrick Talbert
f44c793f6c team: add support for 'vlanid' link-watchers property
Add support for the teaming arp_ping link watcher 'vlanid' property.

Signed-off-by: Patrick Talbert <ptalbert@redhat.com>

[thaller@redhat.com: minor fixes to original patch]

https://bugzilla.redhat.com/show_bug.cgi?id=1652931
2018-12-12 14:07:30 +01:00
Thomas Haller
140a5e3316 all: make use of NM_MAKE_STRV() macro 2018-12-01 15:16:48 +01:00
Thomas Haller
eb9f950a33 all: cleanup GChecksum handling
- prefer nm_auto_free_checksum over explicit free.
- use nm_utils_checksum_get_digest*().
- prefer defines for digest length.
- assume g_checksum_new() cannot fail.
2018-11-13 18:30:03 +01:00
Thomas Haller
01239e99d7 libnm: add nm_utils_uuid_is_null() helper 2018-10-31 11:34:31 +01:00
Thomas Haller
4db431191c libnm: add nm_utils_uuid_generate_from_string_bin() function 2018-10-31 11:34:31 +01:00
Thomas Haller
070a4d9355 libnm: add support for SHA1 based version 5 UUIDs
The entire point of using version 3/5 UUIDs is to generate
stable UUIDs based on a string. It's usually important that
we don't change the UUID generation algorithm later on.

Since we didn't have a version 5 implementation, we would always
resort to the MD5 based version 3. Version 5 is recommended by RFC 4122:

   o  Choose either MD5 [4] or SHA-1 [8] as the hash algorithm; If
      backward compatibility is not an issue, SHA-1 is preferred.

Add a version 5 implementation so we can use it in the future.

All test values are generated with python's uuid module or OSSP uuid.
2018-10-31 11:34:31 +01:00
Thomas Haller
c150b0fa29 libnm/trivial: rename uuid type VARIANT3 to VERSION3
In RFC 4122, this is called "version 3", not "variant 3". While for
UUIDs there is also a concept of "variants", that is something else.

Fix naming.
2018-10-31 09:41:12 +01:00
Thomas Haller
88b081fce4 libnm: expose UUID utils as internal API
We link against libuuid.so, but it was entirely internal to
libnm-core. We only exposed UUIDs in string form.

Add API to also handle UUIDs in binary form.

Note that libuuid already defines a type "uuid_t". However,
don't use it and instead use our own typedef NMUuid.
Reasons:

  - uuid.h should be internal to libnm-core (nm-utils.c specifically),
    and not be used by or exposed it other parts of the code.

  - uuid_t is a typedef for a guchar[16] array. Typedefs
    for arrays are confusing, because depending on whether
    it's an automatic variable or a pointer in a function argument,
    they behave differently regarding whether to take their address
    or not and usage of "sizeof()".
2018-10-31 09:41:12 +01:00
Beniamino Galvani
9b04b871a0 libnm-core: fix coverity warning
3. NetworkManager-1.14.0/libnm-core/nm-utils.c:4944: var_compare_op: Comparing "str" to null implies that "str" might be null.
 4. NetworkManager-1.14.0/libnm-core/nm-utils.c:4958: var_deref_op: Dereferencing null pointer "str".
 #  4956|
 #  4957|   	/* do some very basic validation to see if this might be a JSON object. */
 #  4958|-> 	if (str[0] == '{') {
 #  4959|   		gsize l;
 #  4960|
2018-10-06 10:03:48 +02:00
Thomas Haller
be6c7fa5f6 libnm: cleanup _nm_utils_hexstr2bin*() helper
Add 3 variants of _nm_utils_hexstr2bin*():

  - _nm_utils_hexstr2bin_full(), which takes a preallocated
    buffer and fills it.
  - _nm_utils_hexstr2bin_alloc() which returns a malloc'ed
    buffer
  - _nm_utils_hexstr2bin_buf(), which fills a preallocated
    buffer of a specific size.
2018-09-30 16:13:42 +02:00
Thomas Haller
b537c0388a all: drop _nm_utils_bin2hexstr()
We already have nm_utils_bin2hexstr() and _nm_utils_bin2hexstr_full().
This is confusing.

  - nm_utils_bin2hexstr() is public API of libnm. Also, it has
    a last argument @final_len to truncate the string at that
    length.
    It uses no delimiter and lower-case characters.

  - _nm_utils_bin2hexstr_full() does not do any truncation, but
    it has options to specify a delimiter, the character case,
    and to update a given buffer in-place. Also, like
    nm_utils_bin2hexstr() and _nm_utils_bin2hexstr() it can
    allocate a new buffer on demand.

  - _nm_utils_bin2hexstr() would use ':' as delimiter and make
    the case configurable. Also, it would always allocate the returned
    buffer.

It's too much and confusing. Drop _nm_utils_bin2hexstr() which is internal
API and just a wrapper around _nm_utils_bin2hexstr_full().
2018-09-30 13:36:57 +02:00
Thomas Haller
21df8d38ef libnm: return output buffer from _nm_utils_bin2hexstr_full()
It's just more convenient, as it allows better chaining.

Also, allow passing %NULL as @out buffer. It's clear how
large the output buffer must be, so for convenience let the
function (optionally) allocate a new buffer.

This behavior of whether to
  - take @out, fill it, and return @out
  - take no @out, allocate new buffer, fill and and return it
is slightly error prone. But it was already error prone before, when
it would accept an input buffer without explicit buffer length. I think
this makes it more safe, because in the common case the caller can avoid
pre-allocating a buffer of the right size and the function gets it
right.
2018-09-30 13:36:57 +02:00
Thomas Haller
6714440669 all/trivial: rename hexstr<>bin conversion functions
"bin2str" and "str2bin" are not very clear. These strings are
hex-strings. Rename.
2018-09-30 13:33:46 +02:00
luz.paz
58510ed566 docs: misc. typos pt2
Remainder of typos found using `codespell -q 3 --skip="./shared,./src/systemd,*.po" -I ../NetworkManager-word-whitelist.txt` whereby whitelist consists of:
 ```
ans
busses
cace
cna
conexant
crasher
iff
liftime
creat
nd
sav
technik
uint
```

https://github.com/NetworkManager/NetworkManager/pull/205
2018-09-17 11:26:13 +02:00
Thomas Haller
ff8777cdde libnm/trivial: whitespace
(cherry picked from commit 3b5912f08d)
2018-09-14 17:29:05 +02:00
Thomas Haller
74a3d184b0 libnm: document nm_utils_parse_variant_attributes() returning floating references
See-also: https://bugzilla.redhat.com/show_bug.cgi?id=1594887
(cherry picked from commit e645aeb12c)
2018-09-14 17:29:05 +02:00
Thomas Haller
d01b37c46f libnm: fix memleak in _nm_utils_ssid_to_string_arr()
Fixes: 5cd4e6f3e6
(cherry picked from commit 54e1f73e0c)
2018-09-13 16:18:34 +02:00
Thomas Haller
986ca94a36 libnm: assert in nm_utils_is_uuid() for valid argument
nm_utils_is_uuid() is public API. Commonly we check input arguments for such
functions with g_return_*() assertions.
2018-09-06 07:41:22 +02:00
Thomas Haller
a9406ca4a7 libnm-core: expose _nm_utils_str2bin_full() as internal API
We only exposed wrappers around this function, but all of them have
different behavior, and none exposes all possible features. For example,
nm_utils_hexstr2bin() strips leading "0x", but it does not clear
the data on failure (nm_explicit_bzero()). Instead of adding more
wrappers, expose the underlying implementation, so that callers may
use the function the way they want it.
2018-09-04 07:38:30 +02:00
Thomas Haller
f961dcb806 libnm/crypto: move and mark nm_utils_rsa_key_encrypt() as test code
nm_utils_rsa_key_encrypt() is internal API which is only uesd for testing.
Move it to nm-crypto.h (where it fits better) and rename it to make the
testing-aspect obvious.
2018-09-04 07:38:30 +02:00
Thomas Haller
896a47da53 libnm/crypto: refactor nm_crypto_load_and_verify_certificate() and return GBytes
The GBytes has a suitable cleanup function, which zeros the certificate
from memory.

Also, all callers that require the certificate, actually later converted
it into a GBytes anyway. This way, they can re-used the same instance
(avoiding an additionaly copying of the data), and they will properly
clear the memory when freed.
2018-09-04 07:38:30 +02:00
Thomas Haller
c172675c13 libnm/crypto: rename libnm crypto API to have consistent NM prefix
Follow our convention, that items in headers are all named with
an "NM" prefix.

Also, "nm-crypto-impl.h" contains internal functions that are to be implemented
by the corresponding crypto backends. Distinguish their names as well.
2018-09-04 07:38:30 +02:00
Thomas Haller
4106f2968d libnm/crypto: rename libnm's crypto files
"crypto.h" did not follow our common NM style naming. Rename
the files.
2018-09-04 07:38:30 +02:00
Thomas Haller
9ca12145a3 libnm/crypto: adjust argument types for crypto_md5_hash()
There should be a clear distinction between whether an array
is a NUL terminated string or binary with a length.

crypto_md5_hash() is already complicated enough. Adjust it's
API to only support binary arguments, and thus have "guint8 *" type.
2018-09-04 07:38:30 +02:00
Thomas Haller
b8a57fb272 libnm-core: remove unused utlity functions for GSList
I think GSList is not a great data type. Most of the time when we used
it, we better had choosen another data type.

These utility functions were unused, and I think we should use GSList
less.

Drop them.
2018-08-30 11:17:09 +02:00
Thomas Haller
5cd4e6f3e6 wifi: don't use GBytesArray for NMWifiAP's ssid
GBytes makes more sense, because it's immutable.

Also, since at other places we use GBytes, having
different types is combersome and requires needless
conversions.

Also:

- avoid nm_utils_escape_ssid() instead of _nm_utils_ssid_to_string().
  We use nm_utils_escape_ssid() when we want to log the SSID. However, it
  does not escape newlines, which is bad.

- also no longer use nm_utils_same_ssid(). Since it no longer
  treated trailing NUL special, it is not different from
  g_bytes_equal().

- also, don't use nm_utils_ssid_to_utf8() for logging anymore.
  For logging, _nm_utils_ssid_escape_utf8safe() is better because
  it is loss-less escaping which can be unambigously reverted.
2018-08-22 10:49:34 +02:00
Thomas Haller
dba19ebd7d all: avoid useless cast of g_free() to GDestroyNotify 2018-08-22 10:49:34 +02:00
Thomas Haller
e730f7429d libnm: replace _nm_utils_bytes_to_dbus() with nm_utils_gbytes_get_variant_ay() 2018-08-22 10:49:34 +02:00
Beniamino Galvani
6a51d393b2 shared: add @allow_escaping argument to @nm_utils_strsplit_set 2018-08-11 09:41:07 +02:00
Thomas Haller
a587d32467 shared: move nm_utils_ptrarray_find_binary_search() to shared utils 2018-08-10 10:38:19 +02:00
Thomas Haller
d32da2daaa shared: move nm_utils_array_find_binary_search() to shared utils 2018-08-10 10:38:19 +02:00
Thomas Haller
4444db6b6f libnm: avoid deadlock during g_module_open() in _nm_utils_init()
_nm_utils_init() is a __attribute__((constructor)) function,
that is, it runs during dlopen().

On the other head, g_module_open() itself calls dlopen().

It is prone to deadlock. Don't do it.

The check is only an aggressive assertion to crash the application
if it wrongly loads libnm and libnm-util/libnm-glib at the same time.
If that happens, all is lost already. We can just as well call the
assertion later. It's not supposed to fail anyway.

https://bugzilla.gnome.org/show_bug.cgi?id=796804
2018-08-01 16:06:11 +02:00
Beniamino Galvani
a9b4532fa7 libnm-core: add SR-IOV setting
Add a setting containing SR-IOV parameters.
2018-07-11 16:16:22 +02:00
Beniamino Galvani
d7382fbe93 nm-utils: add _nm_utils_format_variant_attributes_full() 2018-07-11 16:16:22 +02:00
Thomas Haller
e1c7a2b5d0 all: don't use gchar/gshort/gint/glong but C types
We commonly don't use the glib typedefs for char/short/int/long,
but their C types directly.

    $ git grep '\<g\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    587
    $ git grep '\<\(char\|short\|int\|long\|float\|double\)\>' | wc -l
    21114

One could argue that using the glib typedefs is preferable in
public API (of our glib based libnm library) or where it clearly
is related to glib, like during

  g_object_set (obj, PROPERTY, (gint) value, NULL);

However, that argument does not seem strong, because in practice we don't
follow that argument today, and seldomly use the glib typedefs.
Also, the style guide for this would be hard to formalize, because
"using them where clearly related to a glib" is a very loose suggestion.

Also note that glib typedefs will always just be typedefs of the
underlying C types. There is no danger of glib changing the meaning
of these typedefs (because that would be a major API break of glib).

A simple style guide is instead: don't use these typedefs.

No manual actions, I only ran the bash script:

  FILES=($(git ls-files '*.[hc]'))
  sed -i \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>\( [^ ]\)/\1\2/g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>  /\1   /g' \
      -e 's/\<g\(char\|short\|int\|long\|float\|double\)\>/\1/g' \
      "${FILES[@]}"
2018-07-11 12:02:06 +02:00
Thomas Haller
9d3f01a27c libnm: add code comment about thread-safty of _nm_utils_init() and use atomic
Although we don't really need protect for thread safety in _nm_utils_init(),
avoid using static variables without lock/atomic operations. libnm is not
thread-safe, but we still should try to avoid potential issues whenever it is
easy.
2018-07-01 18:17:31 +02:00
Lubomir Rintel
0132da1ddb libnm: add nm_utils_get_timestamp_msec() 2018-06-15 16:23:30 +02:00
Thomas Haller
92b8161578 libnm: avoid allocating GBytes in _nm_utils_dhcp_duid_valid()
In a lot of cases, we don't require the GBytes out-argument. This
is the case when called from NMSettingIP6Config's verify().
Avoid allocating the GBytes instance and also don't heap allocate
the temporary buffer in that case.

Also, being called from NMSettingIP6Config's verify(), at which
point the string value contains untrusted data. Of course, we
do very badly in general protecting against the user creating
huge settings, which could trick NetworkManage to allocate
large amounts of memory (and being killed by glib's out of memory
handling). We should handle such cases better in general, but
just avoid it here.

Since we know that the buffer must hold at most 128+2 bytes,
we can stack allocate it. Later, in case we really need to
return the value, we can create a GBytes instance of the right
size.
2018-06-12 14:45:40 +02:00
Francesco Giudici
7a0b6b17bb libnm-core: add ipv6.dhcp-duid property
allow to specify the DUID to be used int the DHCPv6 client identifier
option: the dhcp-duid property accepts either a hex string or the
special values "lease", "llt", "ll", "stable-llt", "stable-ll" and
"stable-uuid".

"lease": give priority to the DUID available in the lease file if any,
         otherwise fallback to a global default dependant on the dhcp
         client used. This is the default and reflects how the DUID
         was managed previously.
"ll": enforce generation and use of LL type DUID based on the current
      hardware address.
"llt": enforce generation and use of LLT type DUID based on the current
       hardware address and a stable time field.
"stable-ll": enforce generation and use of LL type DUID based on a
             link layer address derived from the stable id.
"stable-llt": enforce generation and use of LLT type DUID based on
              a link layer address and a timestamp both derived from the
              stable id.
"stable-uuid": enforce generation and use of a UUID type DUID based on a
               uuid generated from the stable id.
2018-06-08 18:23:31 +02:00
Thomas Haller
e5d1a71396 build: unifiy specifying locale directory define 2018-05-31 15:59:38 +02:00
Thomas Haller
5f5f75ce0e libnm: expose _bin2str() helper function as internal API 2018-05-28 14:58:24 +02:00
Thomas Haller
4e463df100 libnm: allow nm_utils_hwaddr_valid() of length zero
nm_utils_hwaddr_valid() is used for validating strings. It should
not assert against calling it with an empty string "". That is just
an invalid hwaddr.
2018-05-28 14:58:24 +02:00
Lubomir Rintel
e69d386975 all: use the elvis operator wherever possible
Coccinelle:

  @@
  expression a, b;
  @@
  -a ? a : b
  +a ?: b

Applied with:

  spatch --sp-file ternary.cocci --in-place --smpl-spacing --dir .

With some manual adjustments on spots that Cocci didn't catch for
reasons unknown.

Thanks to the marvelous effort of the GNU compiler developer we can now
spare a couple of bits that could be used for more important things,
like this commit message. Standards commitees yet have to catch up.
2018-05-10 14:36:58 +02:00
Beniamino Galvani
1b5925ce88 all: remove consecutive empty lines
Normalize coding style by removing consecutive empty lines from C
sources and headers.

https://github.com/NetworkManager/NetworkManager/pull/108
2018-04-30 16:24:52 +02:00
Beniamino Galvani
aca671fff0 all: replace "it's" with "its" where needed 2018-04-18 14:14:07 +02:00
Beniamino Galvani
919f6b6d75 shared: use value infos in _nm_utils_enum_to_str_full 2018-04-13 17:02:55 +02:00
Corentin Noël
468a019333 gobject-introspection: made several fixes to the annotations
https://bugzilla.gnome.org/show_bug.cgi?id=794658
2018-03-26 12:45:49 +02:00
Lubomir Rintel
8a46b25cfa all: require glib 2.40
RHEL 7.1 and Ubuntu 14.04 LTS both have this.

https://bugzilla.gnome.org/show_bug.cgi?id=792323
2018-01-18 11:45:36 +01:00
Thomas Haller
e5f3c0fc8a libnm: only include "nm-jansson.h" from "nm-json.h"
"nm-utils/nm-jansson.h" and thus <jansson.h> must be included only
after "nm-json.h". Enforce that by never including them directly,
except from "nm-json.h" itself.
2018-01-16 14:47:24 +01:00
Thomas Haller
b6b6baa773 libnm: rename "libnm-core/nm-jansson.h" to "libnm-core/nm-json.h"
We already have "shared/nm-utils/nm-jansson.h". Avoid reusing the same file name.
2018-01-16 14:47:24 +01:00