Commit graph

1228 commits

Author SHA1 Message Date
Thomas Haller
6efd4e2efa
tests: use in_addr_t type for IPv4 addresses in test helpers 2020-09-24 09:43:58 +02:00
Thomas Haller
adb78bd471
tests: mark static variables in test helpers as thread local
We should avoid static variables in general, but for test helpers they
are often convenient.

Mark them as thread local to make them safer to use. The only downsides
may only be some runtime overhead, which is negligible for unit tests.
2020-09-24 09:43:57 +02:00
Thomas Haller
1b79b33206
shared: add NM_PRINT_FMT_QUOTED2() helper macro 2020-09-24 09:43:53 +02:00
Thomas Haller
dea59122e7
shared: move nm_utils_hwaddr_ntoa_buf() to shared/ as _nm_utils_hwaddr_ntoa()
The name is better as it mirrors nm_utils_hwaddr_aton(). Also, move
it to shared/ so it can be reused (and inlined).
2020-09-23 13:57:37 +02:00
Thomas Haller
74c03da086
shared: move _nm_utils_hwaddr_aton() to shared/
_nm_utils_hwaddr_aton() is only a wrapper around nm_utils_hexstr2bin_full().
But it abstracts the "right" parameters for what we consider a valid MAC
address and what not. As such, this function is useful.

Move it to "shared/" and replace the dupicate macro hwaddr_aton() with
it.
2020-09-23 13:57:04 +02:00
Thomas Haller
dc3a477884
all/style: remove duplicate semicolon (";;") in sources 2020-09-23 12:43:47 +02:00
Thomas Haller
b8811d97a4
all: require a semicolon after NM_CACHED_QUARK_FCN() 2020-09-23 10:55:17 +02:00
Thomas Haller
e8dd19bb01
shared: extend nm_utils_hexstr2bin_full() to require hexdigits in pairs
nm_utils_hexstr2bin_full() is our general hexstr to binary parsing
method. It uses (either mandatory or optional) delimiters. Before,
if delimiters are in use, it would accept individual hexdigits.
E.g. "a:b" would be accepted as "0a:0b:.

Add an argument that prevents accepting such single digits.
2020-09-22 17:40:41 +02:00
Thomas Haller
479de883b3
shared: add m_g_variant_singleton_u_0()
We anyway cache our variants for the properties of NMDBusObject instances.
If such a variant is well known to be always the same, there is no need
to allocate a new instance every time. In particular, because GVariant
is an immutable and ref counted type.

Add a singleton getter for a "u" variant with numeric value 0.
2020-09-18 15:26:37 +02:00
Thomas Haller
348ab39f6d
shared: add nm_utils_hashtable_{equal,cmp}() helper function 2020-09-11 10:45:40 +02:00
Thomas Haller
ff37c961ff
shared: fix out of bounds for nm_g_array_append_new() macro
Fixes: fb6e9795b7 ('shared: add nm_g_array_append_new() helper')
2020-09-11 10:45:40 +02:00
Thomas Haller
0f4221da42
shared: extend NM_IN_SET()/NM_IN_STRSET() macros to support up to 30 arguments 2020-09-10 22:09:50 +02:00
Thomas Haller
aed61588fd
shared: add nm_utils_bin2hexstr_a() macro 2020-09-03 11:39:39 +02:00
Thomas Haller
265a5879ae
shared: add nm_g_timeout_source_new_seconds() 2020-09-03 11:39:39 +02:00
Thomas Haller
fc66ad70d5
shared: add nm_g_hash_table_contains() helper 2020-09-03 11:39:39 +02:00
Thomas Haller
15be2bb3fd
shared: redefine "gs_*" cleanup macros to their "nm_auto*" counterparts 2020-09-02 17:46:44 +02:00
Thomas Haller
c7a724fd53
all: replace cleanup macro "gs_free_slist" by "nm_auto_free_slist" 2020-09-02 17:46:43 +02:00
Thomas Haller
426a4c9d50
all: replace cleanup macro "gs_unref_keyfile" by "nm_auto_unref_keyfile" 2020-09-02 17:46:43 +02:00
Thomas Haller
63f304ad58
shared: add "nm_auto*" macros as future replacements for "gs_*" cleanup macros
We still use the "gs_*" macros that we originally got from libgsystem.
libgsystem no longer exists, we only still use the names of these
macros.

Our own cleanup macros all follow the "nm_auto*" naming pattern.
Eventually, we want to replace all uses of "gs_*" with cleanup macros
that follow our naming scheme.

Add the macros that will be used to replace the "gs_*" macros.
2020-09-02 17:46:43 +02:00
Thomas Haller
4a084a2bcb
shared: rename "gs_local_option_context" to "nm_auto_free_option_context"
The "gs_*" macros originate from the (no longer existing) libgsystem library.
We still have them, because so far we didn't go through the effort of
renaming the API.

Aside that oddity, our cleanup API is called "nm_auto*". There is no need
to add new API with the old name.
2020-09-02 10:36:58 +02:00
Antonio Cardace
d5c05d07c7
initrd: fix memory leak
Signed-off-by: Antonio Cardace <acardace@redhat.com>
Fixes: 9f9609555d ('initrd: add configuration generator')
2020-09-01 19:05:10 +02:00
Thomas Haller
d619de7727
shared/trivial: add code comment about the purpose of "nm-default.h" header 2020-09-01 17:27:17 +02:00
Beniamino Galvani
c25aed5051 n-dhcp4: add n_dhcp4_client_lease_get_server_identifier()
Add new API to query the server identifier of a lease.
2020-08-26 17:08:15 +02:00
Beniamino Galvani
418d20acc9 shared: add nm_strvarray_remove_first()
Co-authored-by: Thomas Haller <thaller@redhat.com>
2020-08-26 17:08:00 +02:00
Thomas Haller
9b54d175bf
shared: avoid multiple strlen() calls in _nm_utils_strv_dup_packed()
Instead of calling strlen() for all strings twice, remember the length
in a temporary buffer.

Yes, this is measurably faster.
2020-08-25 12:45:26 +02:00
Thomas Haller
2e0cd52474
shared: add nm_utils_strv_dup_packed() util 2020-08-25 09:54:11 +02:00
Thomas Haller
c25f4d947a
shared: enforce compatible C-type argument for nm_utils_strv_dup()
Use a macro that uses NM_CAST_STRV_CC() to cast the strv argument. Note that
NM_CAST_STRV_CC() uses C11's _Generic() to check whether the argument is
of a valid type.
2020-08-25 08:54:36 +02:00
Beniamino Galvani
8113069062 shared: add nm_is_ascii()
glib's is{alnum,alpha,ascii,...}() functions perform the check based
on the current locale. Probably using isascii() would be fine anyway,
but add a NM version that just checks that the upper bit is zero.
2020-08-24 16:51:53 +02:00
Thomas Haller
7fbfe4381e
shared/trivial: add gtk-doc for nm_utils_buf_utf8safe_unescape() 2020-08-24 15:19:12 +02:00
Sayed Shah
f5db085cd3 shared: add a struct and definition for MAC address
This is a shared util which adds an array of 6 bytes and also add define statements
for how to format the MAC address
2020-08-20 13:27:32 -04:00
Thomas Haller
70971d1141
all: avoid wrong compiler warning about uninitalized variables with LTO
Seems with LTO the compiler can sometimes think that thes variables are
uninitialized. Usually those code paths are only after an assertion was
hit (g_return*()), but we still need to workaround the warning.
2020-08-17 15:18:02 +02:00
Thomas Haller
4e0e002092
n-dhcp4/connection: avoid compiler warning in n_dhcp4_c_connection_connect() about fd_udp uninitialized
With LTO and optimizations enabled, we get a compiler warning about fd_udp
not initialized:

  ../src/n-dhcp4-c-connection.c: In function ‘n_dhcp4_c_connection_connect’:
  ../src/n-dhcp4-c-connection.c:196:13: error: ‘fd_udp’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    196 |         r = epoll_ctl(connection->fd_epoll,
        |             ^
  ../src/n-dhcp4-c-connection.c:185:16: note: ‘fd_udp’ was declared here
    185 |         int r, fd_udp;
        |                ^

6c6e936898
2020-08-17 15:15:17 +02:00
Thomas Haller
08318a0bac
n-dhcp4/packet: avoid compiler warning in n_dhcp4_c_socket_packet_recv()
gcc-10.2.1-1.fc32 with optimizations and LTO enabled can think that "len"
is uninitialized. Let packet_recv_udp() always set the length.

  ../src/n-dhcp4-socket.c: In function ‘n_dhcp4_c_socket_packet_recv.constprop’:
  ../src/n-dhcp4-incoming.c:210:29: error: ‘len’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    210 |         incoming->n_message = n_raw;
        |                             ^
  ../src/n-dhcp4-socket.c:558:16: note: ‘len’ was declared here
    558 |         size_t len;
        |                ^

142eedcfc3
2020-08-17 15:14:11 +02:00
Thomas Haller
717b0f71e1
systemd: merge branch systemd into master 2020-08-13 09:54:41 +02:00
Thomas Haller
7e747c950e
systemd: update code from upstream (2020-08-11)
This is a direct dump from systemd git.

======

SYSTEMD_DIR=../systemd
COMMIT=c53da7ed02a5d732c9449f79c19675b90a6032e3

(
  cd "$SYSTEMD_DIR"
  git checkout "$COMMIT"
  git reset --hard
  git clean -fdx
)

git ls-files -z :/src/systemd/src/ \
                :/shared/systemd/src/ \
                :/shared/nm-std-aux/unaligned.h | \
  xargs -0 rm -f

nm_copy_sd_shared() {
    mkdir -p "./shared/systemd/$(dirname "$1")"
    cp "$SYSTEMD_DIR/$1" "./shared/systemd/$1"
}

nm_copy_sd_core() {
    mkdir -p "./src/systemd/$(dirname "$1")"
    cp "$SYSTEMD_DIR/$1" "./src/systemd/$1"
}

nm_copy_sd_stdaux() {
    mkdir -p "./shared/nm-std-aux/"
    cp "$SYSTEMD_DIR/$1" "./shared/nm-std-aux/${1##*/}"
}

nm_copy_sd_core "src/libsystemd-network/arp-util.c"
nm_copy_sd_core "src/libsystemd-network/arp-util.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-identifier.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-identifier.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-lease-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp-network.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-option.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-packet.c"
nm_copy_sd_core "src/libsystemd-network/dhcp-protocol.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-lease-internal.h"
nm_copy_sd_core "src/libsystemd-network/dhcp6-network.c"
nm_copy_sd_core "src/libsystemd-network/dhcp6-option.c"
nm_copy_sd_core "src/libsystemd-network/dhcp6-protocol.h"
nm_copy_sd_core "src/libsystemd-network/lldp-internal.h"
nm_copy_sd_core "src/libsystemd-network/lldp-neighbor.c"
nm_copy_sd_core "src/libsystemd-network/lldp-neighbor.h"
nm_copy_sd_core "src/libsystemd-network/lldp-network.c"
nm_copy_sd_core "src/libsystemd-network/lldp-network.h"
nm_copy_sd_core "src/libsystemd-network/network-internal.c"
nm_copy_sd_core "src/libsystemd-network/network-internal.h"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp-client.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp-lease.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp6-client.c"
nm_copy_sd_core "src/libsystemd-network/sd-dhcp6-lease.c"
nm_copy_sd_core "src/libsystemd-network/sd-ipv4acd.c"
nm_copy_sd_core "src/libsystemd-network/sd-ipv4ll.c"
nm_copy_sd_core "src/libsystemd-network/sd-lldp.c"
nm_copy_sd_core "src/libsystemd/sd-event/event-source.h"
nm_copy_sd_core "src/libsystemd/sd-event/event-util.c"
nm_copy_sd_core "src/libsystemd/sd-event/event-util.h"
nm_copy_sd_core "src/libsystemd/sd-event/sd-event.c"
nm_copy_sd_core "src/libsystemd/sd-id128/id128-util.c"
nm_copy_sd_core "src/libsystemd/sd-id128/id128-util.h"
nm_copy_sd_core "src/libsystemd/sd-id128/sd-id128.c"
nm_copy_sd_core "src/systemd/_sd-common.h"
nm_copy_sd_core "src/systemd/sd-dhcp-client.h"
nm_copy_sd_core "src/systemd/sd-dhcp-lease.h"
nm_copy_sd_core "src/systemd/sd-dhcp-option.h"
nm_copy_sd_core "src/systemd/sd-dhcp6-client.h"
nm_copy_sd_core "src/systemd/sd-dhcp6-lease.h"
nm_copy_sd_core "src/systemd/sd-dhcp6-option.h"
nm_copy_sd_core "src/systemd/sd-event.h"
nm_copy_sd_core "src/systemd/sd-id128.h"
nm_copy_sd_core "src/systemd/sd-ipv4acd.h"
nm_copy_sd_core "src/systemd/sd-ipv4ll.h"
nm_copy_sd_core "src/systemd/sd-lldp.h"
nm_copy_sd_core "src/systemd/sd-ndisc.h"
nm_copy_sd_shared "src/basic/alloc-util.c"
nm_copy_sd_shared "src/basic/alloc-util.h"
nm_copy_sd_shared "src/basic/async.h"
nm_copy_sd_shared "src/basic/cgroup-util.h"
nm_copy_sd_shared "src/basic/env-file.c"
nm_copy_sd_shared "src/basic/env-file.h"
nm_copy_sd_shared "src/basic/env-util.c"
nm_copy_sd_shared "src/basic/env-util.h"
nm_copy_sd_shared "src/basic/errno-util.h"
nm_copy_sd_shared "src/basic/escape.c"
nm_copy_sd_shared "src/basic/escape.h"
nm_copy_sd_shared "src/basic/ether-addr-util.c"
nm_copy_sd_shared "src/basic/ether-addr-util.h"
nm_copy_sd_shared "src/basic/extract-word.c"
nm_copy_sd_shared "src/basic/extract-word.h"
nm_copy_sd_shared "src/basic/fd-util.c"
nm_copy_sd_shared "src/basic/fd-util.h"
nm_copy_sd_shared "src/basic/fileio.c"
nm_copy_sd_shared "src/basic/fileio.h"
nm_copy_sd_shared "src/basic/format-util.c"
nm_copy_sd_shared "src/basic/format-util.h"
nm_copy_sd_shared "src/basic/fs-util.c"
nm_copy_sd_shared "src/basic/fs-util.h"
nm_copy_sd_shared "src/basic/hash-funcs.c"
nm_copy_sd_shared "src/basic/hash-funcs.h"
nm_copy_sd_shared "src/basic/hashmap.c"
nm_copy_sd_shared "src/basic/hashmap.h"
nm_copy_sd_shared "src/basic/hexdecoct.c"
nm_copy_sd_shared "src/basic/hexdecoct.h"
nm_copy_sd_shared "src/basic/hostname-util.c"
nm_copy_sd_shared "src/basic/hostname-util.h"
nm_copy_sd_shared "src/basic/in-addr-util.c"
nm_copy_sd_shared "src/basic/in-addr-util.h"
nm_copy_sd_shared "src/basic/io-util.c"
nm_copy_sd_shared "src/basic/io-util.h"
nm_copy_sd_shared "src/basic/list.h"
nm_copy_sd_shared "src/basic/log.h"
nm_copy_sd_shared "src/basic/macro.h"
nm_copy_sd_shared "src/basic/memory-util.c"
nm_copy_sd_shared "src/basic/memory-util.h"
nm_copy_sd_shared "src/basic/mempool.c"
nm_copy_sd_shared "src/basic/mempool.h"
nm_copy_sd_shared "src/basic/missing_fcntl.h"
nm_copy_sd_shared "src/basic/missing_random.h"
nm_copy_sd_shared "src/basic/missing_socket.h"
nm_copy_sd_shared "src/basic/missing_stat.h"
nm_copy_sd_shared "src/basic/missing_syscall.h"
nm_copy_sd_shared "src/basic/missing_type.h"
nm_copy_sd_shared "src/basic/parse-util.c"
nm_copy_sd_shared "src/basic/parse-util.h"
nm_copy_sd_shared "src/basic/path-util.c"
nm_copy_sd_shared "src/basic/path-util.h"
nm_copy_sd_shared "src/basic/prioq.c"
nm_copy_sd_shared "src/basic/prioq.h"
nm_copy_sd_shared "src/basic/process-util.c"
nm_copy_sd_shared "src/basic/process-util.h"
nm_copy_sd_shared "src/basic/random-util.c"
nm_copy_sd_shared "src/basic/random-util.h"
nm_copy_sd_shared "src/basic/set.h"
nm_copy_sd_shared "src/basic/signal-util.c"
nm_copy_sd_shared "src/basic/signal-util.h"
nm_copy_sd_shared "src/basic/siphash24.h"
nm_copy_sd_shared "src/basic/socket-util.c"
nm_copy_sd_shared "src/basic/socket-util.h"
nm_copy_sd_shared "src/basic/sort-util.h"
nm_copy_sd_shared "src/basic/sparse-endian.h"
nm_copy_sd_shared "src/basic/stat-util.c"
nm_copy_sd_shared "src/basic/stat-util.h"
nm_copy_sd_shared "src/basic/stdio-util.h"
nm_copy_sd_shared "src/basic/string-table.c"
nm_copy_sd_shared "src/basic/string-table.h"
nm_copy_sd_shared "src/basic/string-util.c"
nm_copy_sd_shared "src/basic/string-util.h"
nm_copy_sd_shared "src/basic/strv.c"
nm_copy_sd_shared "src/basic/strv.h"
nm_copy_sd_shared "src/basic/strxcpyx.c"
nm_copy_sd_shared "src/basic/strxcpyx.h"
nm_copy_sd_shared "src/basic/time-util.c"
nm_copy_sd_shared "src/basic/time-util.h"
nm_copy_sd_shared "src/basic/tmpfile-util.c"
nm_copy_sd_shared "src/basic/tmpfile-util.h"
nm_copy_sd_shared "src/basic/umask-util.h"
nm_copy_sd_shared "src/basic/user-util.h"
nm_copy_sd_shared "src/basic/utf8.c"
nm_copy_sd_shared "src/basic/utf8.h"
nm_copy_sd_shared "src/basic/util.c"
nm_copy_sd_shared "src/basic/util.h"
nm_copy_sd_shared "src/shared/dns-domain.c"
nm_copy_sd_shared "src/shared/dns-domain.h"
nm_copy_sd_shared "src/shared/web-util.c"
nm_copy_sd_shared "src/shared/web-util.h"
nm_copy_sd_stdaux "src/basic/unaligned.h"
2020-08-13 09:51:05 +02:00
Thomas Haller
cc8da77637
shared: add NM_STR_HAS_SUFFIX_WITH_MORE()/NM_STR_HAS_SUFFIX_ASCII_CASE_WITH_MORE() macros
They are like NM_STR_HAS_SUFFIX()/NM_STR_HAS_SUFFIX_ASCII_CASE(), but require that
the checked string is not identical to the suffix. They require some non-empty word
preceding the suffix.
2020-08-07 11:43:32 +02:00
Thomas Haller
07264a5dc1
shared: avoid "-Wmaybe-uninitialized" in _char_lookup_has()
shared/nm-glib-aux/nm-shared-utils.c: In function ‘nm_utils_escaped_tokens_escape_full’:
   shared/nm-glib-aux/nm-shared-utils.c:1569:26: error: ‘ch_lookup_as_needed.<U7d10>.table[0]’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
    1569 |  nm_assert (lookup->table[(guint8) 0] == 0);
         |                          ^
   shared/nm-glib-aux/nm-shared-utils.c:1569:26: error: ‘ch_lookup_as_needed.<U7d10>.table[0]’ may be used uninitialized in this function [-Werror=maybe-uninitialized]

Fixes: ae55b98e02 ('shared: add CharLookupTable type for nm_utils_strsplit_set_full()')
2020-08-07 11:38:50 +02:00
Thomas Haller
6bf5f014c8
shared: change NM_SWAP() macro to take pointer arguments
This makes the macro more function like. Also, taking a pointer
makes it a bit clearer that this possibly changes the value.

Of course, it's not a big difference to before, but this
form seems slightly preferable to me.
2020-08-06 18:12:01 +02:00
Thomas Haller
ae55b98e02
shared: add CharLookupTable type for nm_utils_strsplit_set_full()
It's not a large difference, whether we use a 256 array directly or a
struct. I guess, theoretically this gives the compiler some more
information about the type, like the alignment. Also, it seems nicer
to use a dedicated struct instead of a pointer array.
2020-08-06 18:12:01 +02:00
Thomas Haller
2222af9a91
shared: add nm_puint32_hash/nm_puint32_equals helpers
They are in practice idential to nm_pint_hash/nm_pint_equals. So, just
#define them.
2020-08-06 18:12:01 +02:00
Antonio Cardace
2e70391033
shared: extend NM_IN_STRSET and NM_IN_SET to support up to 20 args
https://bugzilla.redhat.com/show_bug.cgi?id=1847814
2020-08-06 11:21:45 +02:00
Thomas Haller
5da502a1e1
shared,core: extend nm_utils_is_specific_hostname() and move to shared
nm_utils_is_specific_hostname() is basically to check whether the
hostname is localhost (and also handle "(null)").

In that sense, it's similar to systemd's is_localhost(). Extend or
variant to

  - be case insensitive (like is_localhost()).

  - accept more variants of localhost/localdomain names as special.
2020-08-05 12:47:55 +02:00
Thomas Haller
00c6823ecc
shared: add nm_strcmp_ascii_case_with_data() helper 2020-08-05 10:22:11 +02:00
Thomas Haller
a46940d0d7
shared: add NM_STR_HAS_SUFFIX_ASCII_CASE() macro 2020-08-05 10:22:11 +02:00
Thomas Haller
3b64d88a93
shared: add NM_IN_STRSET_ASCII_CASE() macro 2020-08-05 10:22:10 +02:00
Thomas Haller
b16b42266d
shared: make implementation for NM_IN_STRSET() more reusable 2020-08-05 10:22:10 +02:00
Thomas Haller
3c846baa83
shared: add nm_strv_ptrarray_get_unsafe() helper
It's called "unsafe" because the returned pointer array is not
NULL terminated. This is due to a limitation of GPtrArray which
doesn't support that. If you want a NULL terminated strv array,
use a GArray based API, like nm_strvarray_*().
2020-08-05 10:22:10 +02:00
Thomas Haller
77c000aa0b
shared/tests: add nmtst_assert_ip_address() 2020-08-05 10:22:10 +02:00
Thomas Haller
5150e45fcc
shared/tests: add static assert to ensure proper alignment of NMIPAddr struct 2020-08-05 10:22:10 +02:00
Beniamino Galvani
dee5ce0a52 systemd: merge branch systemd into master 2020-08-04 17:20:21 +02:00