2014-01-21 13:07:06 +01:00
|
|
|
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
|
|
|
|
/*
|
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
|
* the Free Software Foundation; either version 2, or (at your option)
|
|
|
|
|
* any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2014 Red Hat, Inc.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-19 14:57:48 +01:00
|
|
|
#include "nm-default.h"
|
2014-11-13 10:07:02 -05:00
|
|
|
|
2014-01-21 13:07:06 +01:00
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
dhcp: test systemd's default DHCP client identifier generation
Internal DHCP client generates a default client ID. For one,
we should ensure that this algorithm does not change without
us noticing, for example, when upgrading systemd code. Add
a test, that the generation algorithm works as we expect.
Also note, that the generation algorithm uses siphash24().
That means, siphash24() implementation also must not change
in the future, to ensure the client ID doesn't change. As we
patch systemd sources to use shared/c-siphash, this is not
obviously the case. Luckily c-siphash and systemd's siphash24 do
agree, so all is good. The test is here to ensure that.
Also, previously the generation algorithm is not exposed as a
function, sd_dhcp_client will just generate a client-id when
it needs it. However, later we want to know (and set) the client
id before starting DHCP and not leave it unspecified to an
implementation detail.
This patch only adds a unit-test for the existing DHCP client
ID generation to have something for comparison. In the next
commit this will change further.
2018-10-26 17:32:59 +02:00
|
|
|
#include <net/if.h>
|
|
|
|
|
#include <byteswap.h>
|
2014-01-21 13:07:06 +01:00
|
|
|
|
2017-03-23 16:01:07 +01:00
|
|
|
/* need math.h for isinf() and INFINITY. No need to link with -lm */
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
2014-01-21 13:07:06 +01:00
|
|
|
#include "NetworkManagerUtils.h"
|
2014-10-21 22:09:52 -04:00
|
|
|
#include "nm-core-internal.h"
|
core: refactor loading machine-id and cache it
Previously, whenever we needed /etc/machine-id we would re-load it
from file. The are 3 downsides of that:
- the smallest downside is the runtime overhead of repeatedly
reading the file and parse it.
- as we read it multiple times, it may change anytime. Most
code in NetworkManager does not expect or handle a change of
the machine-id.
Generally, the admin should make sure that the machine-id is properly
initialized before NetworkManager starts, and not change it. As such,
a change of the machine-id should never happen in practice.
But if it would change, we would get odd behaviors. Note for example
how generate_duid_from_machine_id() already cached the generated DUID
and only read it once.
It's better to pick the machine-id once, and rely to use the same
one for the remainder of the program.
If the admin wants to change the machine-id, NetworkManager must be
restarted as well (in case the admin cares).
Also, as we now only load it once, it makes sense to log an error
(once) when we fail to read the machine-id.
- previously, loading the machine-id could fail each time. And we
have to somehow handle that error. It seems, the best thing what we
anyway can do, is to log an error once and continue with a fake
machine-id. Here we add a fake machine-id based on the secret-key
or the boot-id. Now obtaining a machine-id can no longer fail
and error handling is no longer necessary.
Also, ensure that a machine-id of all zeros is not valid.
Technically, a machine-id is not an RFC 4122 UUID. But it's
the same size, so we also use NMUuid data structure for it.
While at it, also refactor caching of the boot-id and the secret
key. In particular, fix the thread-safety of the double-checked
locking implementations.
2018-10-30 14:07:11 +01:00
|
|
|
#include "nm-core-utils.h"
|
|
|
|
|
#include "systemd/nm-sd-utils.h"
|
2014-01-21 13:07:06 +01:00
|
|
|
|
2018-11-12 10:44:19 +01:00
|
|
|
#include "dns/nm-dns-manager.h"
|
|
|
|
|
|
2016-05-17 14:04:28 +02:00
|
|
|
#include "nm-test-utils-core.h"
|
2014-01-21 13:07:06 +01:00
|
|
|
|
2014-02-13 18:12:41 +01:00
|
|
|
/* Reference implementation for nm_utils_ip6_address_clear_host_address.
|
2016-10-13 11:06:25 +00:00
|
|
|
* Taken originally from set_address_masked(), src/ndisc/nm-lndp-ndisc.c
|
2014-02-13 18:12:41 +01:00
|
|
|
**/
|
|
|
|
|
static void
|
|
|
|
|
ip6_address_clear_host_address_reference (struct in6_addr *dst, struct in6_addr *src, guint8 plen)
|
|
|
|
|
{
|
|
|
|
|
guint nbytes = plen / 8;
|
|
|
|
|
guint nbits = plen % 8;
|
|
|
|
|
|
|
|
|
|
g_return_if_fail (plen <= 128);
|
|
|
|
|
g_assert (src);
|
|
|
|
|
g_assert (dst);
|
|
|
|
|
|
|
|
|
|
if (plen >= 128)
|
|
|
|
|
*dst = *src;
|
|
|
|
|
else {
|
|
|
|
|
memset (dst, 0, sizeof (*dst));
|
|
|
|
|
memcpy (dst, src, nbytes);
|
|
|
|
|
dst->s6_addr[nbytes] = (src->s6_addr[nbytes] & (0xFF << (8 - nbits)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2014-08-20 13:59:07 -05:00
|
|
|
_randomize_in6_addr (struct in6_addr *addr, GRand *r)
|
2014-02-13 18:12:41 +01:00
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
|
|
for (i=0; i < 4; i++)
|
2014-08-20 13:59:07 -05:00
|
|
|
((guint32 *)addr)[i] = g_rand_int (r);
|
2014-02-13 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_nm_utils_ip6_address_clear_host_address (void)
|
|
|
|
|
{
|
2014-08-20 13:59:07 -05:00
|
|
|
GRand *r = g_rand_new ();
|
2014-02-13 18:12:41 +01:00
|
|
|
int plen, i;
|
|
|
|
|
|
2014-08-20 13:59:07 -05:00
|
|
|
g_rand_set_seed (r, 0);
|
2014-02-13 18:12:41 +01:00
|
|
|
|
|
|
|
|
for (plen = 0; plen <= 128; plen++) {
|
|
|
|
|
for (i =0; i<50; i++) {
|
|
|
|
|
struct in6_addr addr_src, addr_ref;
|
|
|
|
|
struct in6_addr addr1, addr2;
|
|
|
|
|
|
2014-08-20 13:59:07 -05:00
|
|
|
_randomize_in6_addr (&addr_src, r);
|
|
|
|
|
_randomize_in6_addr (&addr_ref, r);
|
|
|
|
|
_randomize_in6_addr (&addr1, r);
|
|
|
|
|
_randomize_in6_addr (&addr2, r);
|
2014-02-13 18:12:41 +01:00
|
|
|
|
|
|
|
|
addr1 = addr_src;
|
|
|
|
|
ip6_address_clear_host_address_reference (&addr_ref, &addr1, plen);
|
|
|
|
|
|
2014-08-20 13:59:07 -05:00
|
|
|
_randomize_in6_addr (&addr1, r);
|
|
|
|
|
_randomize_in6_addr (&addr2, r);
|
2014-02-13 18:12:41 +01:00
|
|
|
addr1 = addr_src;
|
|
|
|
|
nm_utils_ip6_address_clear_host_address (&addr2, &addr1, plen);
|
|
|
|
|
g_assert_cmpint (memcmp (&addr1, &addr_src, sizeof (struct in6_addr)), ==, 0);
|
|
|
|
|
g_assert_cmpint (memcmp (&addr2, &addr_ref, sizeof (struct in6_addr)), ==, 0);
|
|
|
|
|
|
|
|
|
|
/* test for self assignment/inplace update. */
|
2014-08-20 13:59:07 -05:00
|
|
|
_randomize_in6_addr (&addr1, r);
|
2014-02-13 18:12:41 +01:00
|
|
|
addr1 = addr_src;
|
|
|
|
|
nm_utils_ip6_address_clear_host_address (&addr1, &addr1, plen);
|
|
|
|
|
g_assert_cmpint (memcmp (&addr1, &addr_ref, sizeof (struct in6_addr)), ==, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-20 13:59:07 -05:00
|
|
|
g_rand_free (r);
|
2014-02-13 18:12:41 +01:00
|
|
|
}
|
|
|
|
|
|
2016-04-06 17:33:19 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_test_same_prefix (const char *a1, const char *a2, guint8 plen)
|
|
|
|
|
{
|
|
|
|
|
struct in6_addr a = *nmtst_inet6_from_string (a1);
|
|
|
|
|
struct in6_addr b = *nmtst_inet6_from_string (a2);
|
|
|
|
|
|
|
|
|
|
g_assert (nm_utils_ip6_address_same_prefix (&a, &b, plen));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_nm_utils_ip6_address_same_prefix (void)
|
|
|
|
|
{
|
|
|
|
|
guint n, i;
|
|
|
|
|
const guint N = 100;
|
|
|
|
|
union {
|
|
|
|
|
guint8 ptr[sizeof (struct in6_addr)];
|
|
|
|
|
struct in6_addr val;
|
|
|
|
|
} a, b, addrmask, addrmask_bit;
|
|
|
|
|
guint8 plen;
|
|
|
|
|
|
|
|
|
|
/* test#1 */
|
|
|
|
|
for (n = 0; n < N; n++) {
|
|
|
|
|
gboolean is_same = n < N / 2;
|
|
|
|
|
gboolean result;
|
|
|
|
|
|
|
|
|
|
nmtst_rand_buf (NULL, a.ptr, sizeof (a));
|
|
|
|
|
nmtst_rand_buf (NULL, b.ptr, sizeof (b));
|
|
|
|
|
again_plen:
|
|
|
|
|
plen = nmtst_get_rand_int () % 129;
|
|
|
|
|
if (!is_same && NM_IN_SET (plen, 0, 128))
|
|
|
|
|
goto again_plen;
|
|
|
|
|
|
|
|
|
|
if (plen < 128) {
|
|
|
|
|
for (i = 0; (i + 1) * 8 <= plen; i++)
|
|
|
|
|
b.ptr[i] = a.ptr[i];
|
|
|
|
|
if (plen % 8) {
|
|
|
|
|
guint8 mask;
|
|
|
|
|
|
|
|
|
|
g_assert (i < sizeof (a));
|
|
|
|
|
mask = ~((1 << (8 - (plen % 8))) - 1);
|
|
|
|
|
b.ptr[i] = (a.ptr[i] & mask) | (b.ptr[i] & ~mask);
|
|
|
|
|
if (!is_same) {
|
|
|
|
|
mask = (1 << (8 - (plen % 8)));
|
|
|
|
|
b.ptr[i] = (b.ptr[i] & ~mask) | ~(b.ptr[i] & mask);
|
|
|
|
|
}
|
|
|
|
|
} else if (!is_same) {
|
|
|
|
|
g_assert (i > 0);
|
|
|
|
|
|
|
|
|
|
b.ptr[i - 1] = (b.ptr[i - 1] & ~0x1) | ~(b.ptr[i - 1] & 0x1);
|
|
|
|
|
}
|
|
|
|
|
} else
|
|
|
|
|
b = a;
|
|
|
|
|
|
|
|
|
|
result = nm_utils_ip6_address_same_prefix (&a.val, &b.val, plen);
|
|
|
|
|
g_assert (result == is_same);
|
|
|
|
|
g_assert (NM_IN_SET (result, TRUE, FALSE));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* test#2 */
|
|
|
|
|
for (n = 0; n < N; n++) {
|
|
|
|
|
nmtst_rand_buf (NULL, a.ptr, sizeof (a));
|
|
|
|
|
nmtst_rand_buf (NULL, b.ptr, sizeof (b));
|
|
|
|
|
plen = nmtst_get_rand_int () % 129;
|
|
|
|
|
|
|
|
|
|
memset (addrmask.ptr, 0xFF, sizeof (addrmask));
|
|
|
|
|
nm_utils_ip6_address_clear_host_address (&addrmask.val, &addrmask.val, plen);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof (a); i++)
|
|
|
|
|
b.ptr[i] = (a.ptr[i] & addrmask.ptr[i]) | (b.ptr[i] & ~addrmask.ptr[i]);
|
|
|
|
|
|
|
|
|
|
g_assert (nm_utils_ip6_address_same_prefix (&a.val, &b.val, plen) == TRUE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* test#3 */
|
|
|
|
|
for (n = 0; n < N; n++) {
|
|
|
|
|
gboolean reached = FALSE;
|
|
|
|
|
|
|
|
|
|
nmtst_rand_buf (NULL, a.ptr, sizeof (a));
|
|
|
|
|
nmtst_rand_buf (NULL, b.ptr, sizeof (b));
|
|
|
|
|
plen = nmtst_get_rand_int () % 129;
|
|
|
|
|
|
|
|
|
|
if (!plen)
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
memset (addrmask.ptr, 0xFF, sizeof (addrmask));
|
|
|
|
|
nm_utils_ip6_address_clear_host_address (&addrmask.val, &addrmask.val, plen);
|
|
|
|
|
|
|
|
|
|
memset (addrmask_bit.ptr, 0xFF, sizeof (addrmask_bit));
|
|
|
|
|
nm_utils_ip6_address_clear_host_address (&addrmask_bit.val, &addrmask_bit.val, plen - 1);
|
|
|
|
|
|
|
|
|
|
for (i = 0; i < sizeof (a); i++)
|
|
|
|
|
b.ptr[i] = (a.ptr[i] & addrmask.ptr[i]) | (b.ptr[i] & ~addrmask.ptr[i]);
|
|
|
|
|
|
|
|
|
|
/* flip the last bit. */
|
|
|
|
|
for (i = 0; i < sizeof (a); i++) {
|
|
|
|
|
guint8 mask = addrmask.ptr[i] ^ addrmask_bit.ptr[i];
|
|
|
|
|
if (mask) {
|
|
|
|
|
g_assert (!reached);
|
|
|
|
|
g_assert (nm_utils_is_power_of_two (mask));
|
|
|
|
|
reached = TRUE;
|
|
|
|
|
b.ptr[i] = (b.ptr[i] & ~mask) | ~(b.ptr[i] & mask);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
g_assert (reached);
|
|
|
|
|
|
|
|
|
|
g_assert (nm_utils_ip6_address_same_prefix (&a.val, &b.val, plen) == FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* test#4 */
|
|
|
|
|
_test_same_prefix ("::", "::1", 10);
|
|
|
|
|
_test_same_prefix ("abcd::", "abcd::1", 10);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2014-02-26 09:51:09 +01:00
|
|
|
|
|
|
|
|
static void
|
2014-10-29 10:44:31 +01:00
|
|
|
test_nm_utils_log_connection_diff (void)
|
2014-02-26 09:51:09 +01:00
|
|
|
{
|
|
|
|
|
NMConnection *connection;
|
|
|
|
|
NMConnection *connection2;
|
|
|
|
|
|
|
|
|
|
/* if logging is disabled (the default), nm_utils_log_connection_diff() returns
|
|
|
|
|
* early without doing anything. Hence, in the normal testing, this test does nothing.
|
|
|
|
|
* It only gets interesting, when run verbosely with NMTST_DEBUG=debug ... */
|
|
|
|
|
|
2017-03-01 10:20:01 +00:00
|
|
|
nm_log (LOGL_DEBUG, LOGD_CORE, NULL, NULL, "START TEST test_nm_utils_log_connection_diff...");
|
2014-02-26 09:51:09 +01:00
|
|
|
|
|
|
|
|
connection = nm_simple_connection_new ();
|
|
|
|
|
nm_connection_add_setting (connection, nm_setting_connection_new ());
|
2018-03-29 11:47:52 +02:00
|
|
|
nm_utils_log_connection_diff (connection, NULL, LOGL_DEBUG, LOGD_CORE, "test1", ">>> ", NULL);
|
2014-02-26 09:51:09 +01:00
|
|
|
|
|
|
|
|
nm_connection_add_setting (connection, nm_setting_wired_new ());
|
2018-03-29 11:47:52 +02:00
|
|
|
nm_utils_log_connection_diff (connection, NULL, LOGL_DEBUG, LOGD_CORE, "test2", ">>> ", NULL);
|
2014-02-26 09:51:09 +01:00
|
|
|
|
|
|
|
|
connection2 = nm_simple_connection_new_clone (connection);
|
2018-03-29 11:47:52 +02:00
|
|
|
nm_utils_log_connection_diff (connection, connection2, LOGL_DEBUG, LOGD_CORE, "test3", ">>> ", NULL);
|
2014-02-26 09:51:09 +01:00
|
|
|
|
|
|
|
|
g_object_set (nm_connection_get_setting_connection (connection),
|
|
|
|
|
NM_SETTING_CONNECTION_ID, "id",
|
|
|
|
|
NM_SETTING_CONNECTION_UUID, "uuid",
|
|
|
|
|
NULL);
|
|
|
|
|
g_object_set (nm_connection_get_setting_connection (connection2),
|
|
|
|
|
NM_SETTING_CONNECTION_ID, "id2",
|
|
|
|
|
NM_SETTING_CONNECTION_MASTER, "master2",
|
|
|
|
|
NULL);
|
2018-03-29 11:47:52 +02:00
|
|
|
nm_utils_log_connection_diff (connection, connection2, LOGL_DEBUG, LOGD_CORE, "test4", ">>> ", NULL);
|
2014-02-26 09:51:09 +01:00
|
|
|
|
|
|
|
|
nm_connection_add_setting (connection, nm_setting_802_1x_new ());
|
2018-03-29 11:47:52 +02:00
|
|
|
nm_utils_log_connection_diff (connection, connection2, LOGL_DEBUG, LOGD_CORE, "test5", ">>> ", NULL);
|
2014-02-26 09:51:09 +01:00
|
|
|
|
|
|
|
|
g_object_set (nm_connection_get_setting_802_1x (connection),
|
|
|
|
|
NM_SETTING_802_1X_PASSWORD, "id2",
|
|
|
|
|
NM_SETTING_802_1X_PASSWORD_FLAGS, NM_SETTING_SECRET_FLAG_NOT_SAVED,
|
|
|
|
|
NULL);
|
2018-03-29 11:47:52 +02:00
|
|
|
nm_utils_log_connection_diff (connection, NULL, LOGL_DEBUG, LOGD_CORE, "test6", ">>> ", NULL);
|
|
|
|
|
nm_utils_log_connection_diff (connection, connection2, LOGL_DEBUG, LOGD_CORE, "test7", ">>> ", NULL);
|
|
|
|
|
nm_utils_log_connection_diff (connection2, connection, LOGL_DEBUG, LOGD_CORE, "test8", ">>> ", NULL);
|
2014-02-26 09:51:09 +01:00
|
|
|
|
|
|
|
|
g_clear_object (&connection);
|
|
|
|
|
g_clear_object (&connection2);
|
|
|
|
|
|
|
|
|
|
connection = nmtst_create_minimal_connection ("id-vpn-1", NULL, NM_SETTING_VPN_SETTING_NAME, NULL);
|
2018-03-29 11:47:52 +02:00
|
|
|
nm_utils_log_connection_diff (connection, NULL, LOGL_DEBUG, LOGD_CORE, "test-vpn-1", ">>> ", NULL);
|
2014-02-26 09:51:09 +01:00
|
|
|
|
|
|
|
|
g_clear_object (&connection);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2014-01-21 13:07:06 +01:00
|
|
|
|
2017-10-23 14:24:28 +02:00
|
|
|
static void
|
|
|
|
|
do_test_sysctl_ip_conf (int addr_family,
|
|
|
|
|
const char *iface,
|
|
|
|
|
const char *property)
|
|
|
|
|
{
|
|
|
|
|
char path[NM_UTILS_SYSCTL_IP_CONF_PATH_BUFSIZE];
|
|
|
|
|
const char *pp;
|
|
|
|
|
|
|
|
|
|
pp = nm_utils_sysctl_ip_conf_path (addr_family, path, iface, property);
|
|
|
|
|
g_assert (pp == path);
|
|
|
|
|
g_assert (path[0] == '/');
|
|
|
|
|
|
|
|
|
|
g_assert (nm_utils_sysctl_ip_conf_is_path (addr_family, path, iface, property));
|
|
|
|
|
g_assert (nm_utils_sysctl_ip_conf_is_path (addr_family, path, NULL, property));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_nm_utils_sysctl_ip_conf_path (void)
|
|
|
|
|
{
|
|
|
|
|
do_test_sysctl_ip_conf (AF_INET6, "a", "mtu");
|
|
|
|
|
do_test_sysctl_ip_conf (AF_INET6, "eth0", "mtu");
|
|
|
|
|
do_test_sysctl_ip_conf (AF_INET6, "e23456789012345", "mtu");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2014-02-25 17:44:07 -06:00
|
|
|
static NMConnection *
|
|
|
|
|
_match_connection_new (void)
|
|
|
|
|
{
|
|
|
|
|
NMConnection *connection;
|
|
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
NMSettingWired *s_wired;
|
2014-10-19 17:30:10 -04:00
|
|
|
NMSettingIPConfig *s_ip4, *s_ip6;
|
2014-02-25 17:44:07 -06:00
|
|
|
char *uuid;
|
|
|
|
|
|
2014-08-13 14:34:29 -04:00
|
|
|
connection = nm_simple_connection_new ();
|
2014-02-25 17:44:07 -06:00
|
|
|
|
|
|
|
|
s_con = (NMSettingConnection *) nm_setting_connection_new ();
|
|
|
|
|
nm_connection_add_setting (connection, (NMSetting *) s_con);
|
|
|
|
|
uuid = nm_utils_uuid_generate ();
|
|
|
|
|
g_object_set (G_OBJECT (s_con),
|
|
|
|
|
NM_SETTING_CONNECTION_ID, "blahblah",
|
|
|
|
|
NM_SETTING_CONNECTION_UUID, uuid,
|
|
|
|
|
NM_SETTING_CONNECTION_TYPE, NM_SETTING_WIRED_SETTING_NAME,
|
|
|
|
|
NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
|
|
|
|
|
NULL);
|
|
|
|
|
g_free (uuid);
|
|
|
|
|
|
|
|
|
|
s_wired = (NMSettingWired *) nm_setting_wired_new ();
|
|
|
|
|
nm_connection_add_setting (connection, (NMSetting *) s_wired);
|
|
|
|
|
|
2014-10-19 17:30:10 -04:00
|
|
|
s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new ();
|
2014-02-25 17:44:07 -06:00
|
|
|
nm_connection_add_setting (connection, (NMSetting *) s_ip4);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip4),
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
2014-02-25 17:44:07 -06:00
|
|
|
NULL);
|
|
|
|
|
|
2014-10-19 17:30:10 -04:00
|
|
|
s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new ();
|
2014-02-25 17:44:07 -06:00
|
|
|
nm_connection_add_setting (connection, (NMSetting *) s_ip6);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip6),
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
|
2014-02-25 17:44:07 -06:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
return connection;
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-13 14:48:06 +01:00
|
|
|
static NMConnection *
|
|
|
|
|
_match_connection (GSList *connections,
|
|
|
|
|
NMConnection *original,
|
|
|
|
|
gboolean device_has_carrier,
|
|
|
|
|
gint64 default_v4_metric,
|
|
|
|
|
gint64 default_v6_metric)
|
|
|
|
|
{
|
|
|
|
|
NMConnection **list;
|
|
|
|
|
guint i, len;
|
|
|
|
|
|
|
|
|
|
len = g_slist_length (connections);
|
|
|
|
|
g_assert (len < 10);
|
|
|
|
|
|
|
|
|
|
list = g_alloca ((len + 1) * sizeof (NMConnection *));
|
|
|
|
|
for (i = 0; i < len; i++, connections = connections->next) {
|
|
|
|
|
g_assert (connections);
|
|
|
|
|
g_assert (connections->data);
|
|
|
|
|
list[i] = connections->data;
|
|
|
|
|
}
|
|
|
|
|
list[i] = NULL;
|
|
|
|
|
|
Revert "core: merge branch 'bg/restart-assume-rh1551958'"
This reverts commit cc1920d71470042c4e0837848da9183526b663d0, reversing
changes made to eb8257dea5802a004af9cccacb30af98440e2172.
This breaks restart, at least for Wi-Fi devices:
#0 0x00007ffff5ee8771 in _g_log_abort (breakpoint=breakpoint@entry=1) at gmessages.c:554
#1 0x00007ffff5ee9a5b in g_logv (log_domain=0x7ffff671a738 "GLib-GIO", log_level=G_LOG_LEVEL_CRITICAL, format=<optimized out>, args=args@entry=0x7fffffffd720) at gmessages.c:1362
#2 0x00007ffff5ee9baf in g_log (log_domain=log_domain@entry=0x7ffff671a738 "GLib-GIO", log_level=log_level@entry=G_LOG_LEVEL_CRITICAL, format=format@entry=0x7ffff5f347ea "%s: assertion '%s' failed") at gmessages.c:1403
#3 0x00007ffff5eea0f9 in g_return_if_fail_warning (log_domain=log_domain@entry=0x7ffff671a738 "GLib-GIO", pretty_function=pretty_function@entry=0x7ffff673fc10 <__func__.25628> "g_dbus_proxy_call_internal", expression=expression@entry=0x7ffff673fb1c "G_IS_DBUS_PROXY (proxy)") at gmessages.c:2702
#4 0x00007ffff66cdc5f in g_dbus_proxy_call_internal (proxy=0x0, method_name=method_name@entry=0x555555810510 "Scan", parameters=0x555555c7a530, flags=flags@entry=G_DBUS_CALL_FLAGS_NONE, timeout_msec=timeout_msec@entry=-1, fd_list=fd_list@entry=0x0, cancellable=0x0, callback=0x55555574cb96 <scan_request_cb>, user_data=0x555555ac2220) at gdbusproxy.c:2664
#5 0x00007ffff66cf686 in g_dbus_proxy_call (proxy=<optimized out>, method_name=method_name@entry=0x555555810510 "Scan", parameters=<optimized out>, flags=flags@entry=G_DBUS_CALL_FLAGS_NONE, timeout_msec=timeout_msec@entry=-1, cancellable=cancellable@entry=0x0, callback=0x55555574cb96 <scan_request_cb>, user_data=0x555555ac2220) at gdbusproxy.c:2970
#6 0x000055555574e026 in nm_supplicant_interface_request_scan (self=0x555555ac2220 [NMSupplicantInterface], ssids=ssids@entry=0x0) at src/supplicant/nm-supplicant-interface.c:1821
#7 0x00007fffe1038276 in request_wireless_scan (self=self@entry=0x555555c6ee60 [NMDeviceWifi], periodic=periodic@entry=0, force_if_scanning=force_if_scanning@entry=0, ssids=<optimized out>, ssids@entry=0x0) at src/devices/wifi/nm-device-wifi.c:1347
#8 0x00007fffe1039011 in device_state_changed (device=0x555555c6ee60 [NMDeviceWifi], new_state=NM_DEVICE_STATE_DISCONNECTED, old_state=<optimized out>, reason=<optimized out>)
at src/devices/wifi/nm-device-wifi.c:2998
#9 0x00007ffff432ed1e in ffi_call_unix64 () at ../src/x86/unix64.S:76
#10 0x00007ffff432e68f in ffi_call (cif=cif@entry=0x7fffffffdc70, fn=fn@entry=0x7fffe1038e1e <device_state_changed>, rvalue=<optimized out>, avalue=avalue@entry=0x7fffffffdb60)
at ../src/x86/ffi64.c:525
#15 0x00007ffff63db66f in <emit signal ??? on instance 0x555555c6ee60 [NMDeviceWifi]> (instance=instance@entry=0x555555c6ee60, signal_id=<optimized out>, detail=detail@entry=0)
at gsignal.c:3447
#11 0x00007ffff63bff39 in g_cclosure_marshal_generic (closure=0x555555c22ea0, return_gvalue=0x0, n_param_values=<optimized out>, param_values=<optimized out>, invocation_hint=<optimized out>, marshal_data=<optimized out>) at gclosure.c:1490
#12 0x00007ffff63bf73d in g_closure_invoke (closure=0x555555c22ea0, return_value=0x0, n_param_values=4, param_values=0x7fffffffdea0, invocation_hint=0x7fffffffde20) at gclosure.c:804
#13 0x00007ffff63d1f30 in signal_emit_unlocked_R (node=node@entry=0x555555c22750, detail=detail@entry=0, instance=instance@entry=0x555555c6ee60, emission_return=emission_return@entry=0x0, instance_and_params=instance_and_params@entry=0x7fffffffdea0) at gsignal.c:3673
#14 0x00007ffff63dad05 in g_signal_emit_valist (instance=0x555555c6ee60, signal_id=<optimized out>, detail=0, var_args=var_args@entry=0x7fffffffe0b0) at gsignal.c:3391
#16 0x00005555556f0f18 in _set_state_full (self=self@entry=0x555555c6ee60 [NMDeviceWifi], state=state@entry=NM_DEVICE_STATE_DISCONNECTED, reason=reason@entry=NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED, quitting=quitting@entry=0) at src/devices/nm-device.c:13268
#17 0x00005555556f1774 in nm_device_state_changed (self=self@entry=0x555555c6ee60 [NMDeviceWifi], state=state@entry=NM_DEVICE_STATE_DISCONNECTED, reason=reason@entry=NM_DEVICE_STATE_REASON_CONNECTION_ASSUMED) at src/devices/nm-device.c:13435
#18 0x00005555555bcf95 in recheck_assume_connection (self=self@entry=0x555555b09140 [NMManager], device=device@entry=0x555555c6ee60 [NMDeviceWifi]) at src/nm-manager.c:2297
#19 0x00005555555bd53e in _device_realize_finish (self=self@entry=0x555555b09140 [NMManager], device=device@entry=0x555555c6ee60 [NMDeviceWifi], plink=plink@entry=0x555555ae43d8)
at src/nm-manager.c:2473
#20 0x00005555555c01d0 in platform_link_added (self=self@entry=0x555555b09140 [NMManager], ifindex=<optimized out>, plink=plink@entry=0x555555ae43d8, guess_assume=<optimized out>, dev_state=<optimized out>) at src/nm-manager.c:2789
#21 0x00005555555c0cec in platform_query_devices (self=self@entry=0x555555b09140 [NMManager]) at src/nm-manager.c:2901
#22 0x00005555555c439e in nm_manager_start (self=0x555555b09140 [NMManager], error=<optimized out>) at src/nm-manager.c:5632
#23 0x000055555558498e in main (argc=<optimized out>, argv=<optimized out>) at src/main.c:413
2018-04-04 14:48:52 +02:00
|
|
|
return nm_utils_match_connection (list, original, FALSE, device_has_carrier, default_v4_metric, default_v6_metric, NULL, NULL);
|
2017-03-13 14:48:06 +01:00
|
|
|
}
|
|
|
|
|
|
2014-02-25 17:44:07 -06:00
|
|
|
static void
|
|
|
|
|
test_connection_match_basic (void)
|
|
|
|
|
{
|
|
|
|
|
NMConnection *orig, *copy, *matched;
|
|
|
|
|
GSList *connections = NULL;
|
2014-10-19 17:30:10 -04:00
|
|
|
NMSettingIPConfig *s_ip4;
|
2014-02-25 17:44:07 -06:00
|
|
|
|
|
|
|
|
orig = _match_connection_new ();
|
2014-08-13 14:34:29 -04:00
|
|
|
copy = nm_simple_connection_new_clone (orig);
|
2014-02-25 17:44:07 -06:00
|
|
|
connections = g_slist_append (connections, copy);
|
|
|
|
|
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
2014-02-25 17:44:07 -06:00
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
/* Now change a material property like IPv4 method and ensure matching fails */
|
|
|
|
|
s_ip4 = nm_connection_get_setting_ip4_config (orig);
|
|
|
|
|
g_assert (s_ip4);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip4),
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_LINK_LOCAL,
|
2014-02-25 17:44:07 -06:00
|
|
|
NULL);
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
2014-02-25 17:44:07 -06:00
|
|
|
g_assert (matched == NULL);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
|
g_object_unref (orig);
|
|
|
|
|
g_object_unref (copy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_connection_match_ip6_method (void)
|
|
|
|
|
{
|
|
|
|
|
NMConnection *orig, *copy, *matched;
|
|
|
|
|
GSList *connections = NULL;
|
2014-10-19 17:30:10 -04:00
|
|
|
NMSettingIPConfig *s_ip6;
|
2014-02-25 17:44:07 -06:00
|
|
|
|
|
|
|
|
orig = _match_connection_new ();
|
2014-08-13 14:34:29 -04:00
|
|
|
copy = nm_simple_connection_new_clone (orig);
|
2014-02-25 17:44:07 -06:00
|
|
|
connections = g_slist_append (connections, copy);
|
|
|
|
|
|
2014-05-30 09:06:24 +02:00
|
|
|
/* Check that if the generated connection is IPv6 method=link-local, and the
|
2014-02-25 17:44:07 -06:00
|
|
|
* candidate is both method=auto and may-faily=true, that the candidate is
|
|
|
|
|
* matched.
|
|
|
|
|
*/
|
|
|
|
|
s_ip6 = nm_connection_get_setting_ip6_config (orig);
|
|
|
|
|
g_assert (s_ip6);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip6),
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL,
|
2014-02-25 17:44:07 -06:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
s_ip6 = nm_connection_get_setting_ip6_config (copy);
|
|
|
|
|
g_assert (s_ip6);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip6),
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
|
|
|
|
|
NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
|
2014-02-25 17:44:07 -06:00
|
|
|
NULL);
|
|
|
|
|
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
2014-02-25 17:44:07 -06:00
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
|
g_object_unref (orig);
|
|
|
|
|
g_object_unref (copy);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-07 10:33:12 +01:00
|
|
|
static void
|
|
|
|
|
test_connection_match_ip6_method_ignore (void)
|
|
|
|
|
{
|
|
|
|
|
NMConnection *orig, *copy, *matched;
|
|
|
|
|
GSList *connections = NULL;
|
2014-10-19 17:30:10 -04:00
|
|
|
NMSettingIPConfig *s_ip6;
|
2014-03-07 10:33:12 +01:00
|
|
|
|
|
|
|
|
orig = _match_connection_new ();
|
2014-08-13 14:34:29 -04:00
|
|
|
copy = nm_simple_connection_new_clone (orig);
|
2014-03-07 10:33:12 +01:00
|
|
|
connections = g_slist_append (connections, copy);
|
|
|
|
|
|
2014-05-30 09:06:24 +02:00
|
|
|
/* Check that if the generated connection is IPv6 method=link-local, and the
|
2014-03-07 10:33:12 +01:00
|
|
|
* candidate is method=ignore, that the candidate is matched.
|
|
|
|
|
*/
|
|
|
|
|
s_ip6 = nm_connection_get_setting_ip6_config (orig);
|
|
|
|
|
g_assert (s_ip6);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip6),
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL,
|
2014-03-07 10:33:12 +01:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
s_ip6 = nm_connection_get_setting_ip6_config (copy);
|
|
|
|
|
g_assert (s_ip6);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip6),
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
|
2014-03-07 10:33:12 +01:00
|
|
|
NULL);
|
|
|
|
|
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
2014-03-07 10:33:12 +01:00
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
|
g_object_unref (orig);
|
|
|
|
|
g_object_unref (copy);
|
|
|
|
|
}
|
|
|
|
|
|
2014-05-29 16:36:24 +02:00
|
|
|
static void
|
|
|
|
|
test_connection_match_ip6_method_ignore_auto (void)
|
|
|
|
|
{
|
|
|
|
|
NMConnection *orig, *copy, *matched;
|
|
|
|
|
GSList *connections = NULL;
|
2014-10-19 17:30:10 -04:00
|
|
|
NMSettingIPConfig *s_ip6;
|
2014-05-29 16:36:24 +02:00
|
|
|
|
|
|
|
|
orig = _match_connection_new ();
|
2014-08-13 14:34:29 -04:00
|
|
|
copy = nm_simple_connection_new_clone (orig);
|
2014-05-29 16:36:24 +02:00
|
|
|
connections = g_slist_append (connections, copy);
|
|
|
|
|
|
|
|
|
|
/* Check that if the generated connection is IPv6 method=auto, and the
|
|
|
|
|
* candidate is method=ignore, that the candidate is matched.
|
|
|
|
|
*/
|
|
|
|
|
s_ip6 = nm_connection_get_setting_ip6_config (orig);
|
|
|
|
|
g_assert (s_ip6);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip6),
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_AUTO,
|
2014-05-29 16:36:24 +02:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
s_ip6 = nm_connection_get_setting_ip6_config (copy);
|
|
|
|
|
g_assert (s_ip6);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip6),
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
|
2014-05-29 16:36:24 +02:00
|
|
|
NULL);
|
|
|
|
|
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
2014-05-29 16:36:24 +02:00
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
|
g_object_unref (orig);
|
|
|
|
|
g_object_unref (copy);
|
|
|
|
|
}
|
|
|
|
|
|
2014-02-25 17:56:06 -06:00
|
|
|
static void
|
|
|
|
|
test_connection_match_ip4_method (void)
|
|
|
|
|
{
|
|
|
|
|
NMConnection *orig, *copy, *matched;
|
|
|
|
|
GSList *connections = NULL;
|
2014-10-19 17:30:10 -04:00
|
|
|
NMSettingIPConfig *s_ip4;
|
2014-02-25 17:56:06 -06:00
|
|
|
|
|
|
|
|
orig = _match_connection_new ();
|
2014-08-13 14:34:29 -04:00
|
|
|
copy = nm_simple_connection_new_clone (orig);
|
2014-02-25 17:56:06 -06:00
|
|
|
connections = g_slist_append (connections, copy);
|
|
|
|
|
|
2014-05-30 09:06:24 +02:00
|
|
|
/* Check that if the generated connection is IPv4 method=disabled, and the
|
2014-02-25 17:56:06 -06:00
|
|
|
* candidate is both method=auto and may-faily=true, and the device has no
|
|
|
|
|
* carrier that the candidate is matched.
|
|
|
|
|
*/
|
|
|
|
|
s_ip4 = nm_connection_get_setting_ip4_config (orig);
|
|
|
|
|
g_assert (s_ip4);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip4),
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_DISABLED,
|
2014-02-25 17:56:06 -06:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
s_ip4 = nm_connection_get_setting_ip4_config (copy);
|
|
|
|
|
g_assert (s_ip4);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip4),
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_AUTO,
|
|
|
|
|
NM_SETTING_IP_CONFIG_MAY_FAIL, TRUE,
|
2014-02-25 17:56:06 -06:00
|
|
|
NULL);
|
|
|
|
|
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, FALSE, 0, 0);
|
2014-02-25 17:56:06 -06:00
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
/* Ensure when carrier=true matching fails */
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
2014-02-25 17:56:06 -06:00
|
|
|
g_assert (matched == NULL);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
|
g_object_unref (orig);
|
|
|
|
|
g_object_unref (copy);
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-18 14:21:59 +01:00
|
|
|
static void
|
|
|
|
|
test_connection_match_interface_name (void)
|
|
|
|
|
{
|
|
|
|
|
NMConnection *orig, *copy, *matched;
|
|
|
|
|
GSList *connections = NULL;
|
|
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
|
|
|
|
|
orig = _match_connection_new ();
|
2014-08-13 14:34:29 -04:00
|
|
|
copy = nm_simple_connection_new_clone (orig);
|
2014-03-18 14:21:59 +01:00
|
|
|
connections = g_slist_append (connections, copy);
|
|
|
|
|
|
2014-05-30 09:06:24 +02:00
|
|
|
/* Check that if the generated connection has an interface name and the
|
|
|
|
|
* candidate's interface name is NULL, that the candidate is matched.
|
2014-03-18 14:21:59 +01:00
|
|
|
*/
|
|
|
|
|
s_con = nm_connection_get_setting_connection (orig);
|
|
|
|
|
g_assert (s_con);
|
|
|
|
|
g_object_set (G_OBJECT (s_con),
|
|
|
|
|
NM_SETTING_CONNECTION_INTERFACE_NAME, "em1",
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
s_con = nm_connection_get_setting_connection (copy);
|
|
|
|
|
g_assert (s_con);
|
|
|
|
|
g_object_set (G_OBJECT (s_con),
|
|
|
|
|
NM_SETTING_CONNECTION_INTERFACE_NAME, NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
2014-03-18 14:21:59 +01:00
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
|
g_object_unref (orig);
|
|
|
|
|
g_object_unref (copy);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 10:39:31 +02:00
|
|
|
static void
|
|
|
|
|
test_connection_match_wired (void)
|
|
|
|
|
{
|
|
|
|
|
NMConnection *orig, *copy, *matched;
|
|
|
|
|
GSList *connections = NULL;
|
|
|
|
|
NMSettingWired *s_wired;
|
2014-08-21 13:19:53 -04:00
|
|
|
char *subchan_arr[] = { "0.0.8000", "0.0.8001", "0.0.8002", NULL };
|
2014-12-11 11:29:19 +01:00
|
|
|
const char *mac = "52:54:00:ab:db:23";
|
2014-04-08 10:39:31 +02:00
|
|
|
|
|
|
|
|
orig = _match_connection_new ();
|
2014-08-13 14:34:29 -04:00
|
|
|
copy = nm_simple_connection_new_clone (orig);
|
2014-04-08 10:39:31 +02:00
|
|
|
connections = g_slist_append (connections, copy);
|
|
|
|
|
|
|
|
|
|
s_wired = nm_connection_get_setting_wired (orig);
|
|
|
|
|
g_assert (s_wired);
|
|
|
|
|
g_object_set (G_OBJECT (s_wired),
|
|
|
|
|
NM_SETTING_WIRED_PORT, "tp", /* port is not compared */
|
|
|
|
|
NM_SETTING_WIRED_MAC_ADDRESS, mac, /* we allow MAC address just in one connection */
|
|
|
|
|
NM_SETTING_WIRED_S390_SUBCHANNELS, subchan_arr,
|
|
|
|
|
NM_SETTING_WIRED_S390_NETTYPE, "qeth",
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
s_wired = nm_connection_get_setting_wired (copy);
|
|
|
|
|
g_assert (s_wired);
|
|
|
|
|
g_object_set (G_OBJECT (s_wired),
|
|
|
|
|
NM_SETTING_WIRED_S390_SUBCHANNELS, subchan_arr,
|
|
|
|
|
NM_SETTING_WIRED_S390_NETTYPE, "qeth",
|
|
|
|
|
NULL);
|
|
|
|
|
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
2014-04-08 10:39:31 +02:00
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
|
g_object_unref (orig);
|
|
|
|
|
g_object_unref (copy);
|
|
|
|
|
}
|
|
|
|
|
|
2015-10-29 18:57:52 +01:00
|
|
|
static void
|
|
|
|
|
test_connection_match_wired2 (void)
|
|
|
|
|
{
|
|
|
|
|
NMConnection *orig, *copy, *matched;
|
|
|
|
|
GSList *connections = NULL;
|
|
|
|
|
NMSettingWired *s_wired;
|
|
|
|
|
const char *mac = "52:54:00:ab:db:23";
|
|
|
|
|
|
|
|
|
|
orig = _match_connection_new ();
|
|
|
|
|
s_wired = nm_connection_get_setting_wired (orig);
|
|
|
|
|
g_assert (s_wired);
|
|
|
|
|
g_object_set (G_OBJECT (s_wired),
|
|
|
|
|
NM_SETTING_WIRED_PORT, "tp", /* port is not compared */
|
|
|
|
|
NM_SETTING_WIRED_MAC_ADDRESS, mac, /* we allow MAC address just in one connection */
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
copy = nm_simple_connection_new_clone (orig);
|
|
|
|
|
connections = g_slist_append (connections, copy);
|
|
|
|
|
|
|
|
|
|
/* Check that if the generated connection do not have wired setting
|
|
|
|
|
* and s390 properties in the existing connection's setting are default,
|
|
|
|
|
* the connections match. It can happen if assuming VLAN devices. */
|
|
|
|
|
nm_connection_remove_setting (orig, NM_TYPE_SETTING_WIRED);
|
|
|
|
|
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
2015-10-29 18:57:52 +01:00
|
|
|
g_assert (matched == copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
|
g_object_unref (orig);
|
|
|
|
|
g_object_unref (copy);
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-19 17:53:43 +01:00
|
|
|
static void
|
|
|
|
|
test_connection_match_cloned_mac (void)
|
|
|
|
|
{
|
|
|
|
|
NMConnection *orig, *exact, *fuzzy, *matched;
|
|
|
|
|
GSList *connections = NULL;
|
|
|
|
|
NMSettingWired *s_wired;
|
|
|
|
|
|
|
|
|
|
orig = _match_connection_new ();
|
|
|
|
|
|
|
|
|
|
fuzzy = nm_simple_connection_new_clone (orig);
|
|
|
|
|
connections = g_slist_append (connections, fuzzy);
|
|
|
|
|
s_wired = nm_connection_get_setting_wired (orig);
|
|
|
|
|
g_assert (s_wired);
|
|
|
|
|
g_object_set (G_OBJECT (s_wired),
|
|
|
|
|
NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:23",
|
|
|
|
|
NULL);
|
|
|
|
|
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
2015-02-19 17:53:43 +01:00
|
|
|
g_assert (matched == fuzzy);
|
|
|
|
|
|
|
|
|
|
exact = nm_simple_connection_new_clone (orig);
|
|
|
|
|
connections = g_slist_append (connections, exact);
|
|
|
|
|
s_wired = nm_connection_get_setting_wired (exact);
|
|
|
|
|
g_assert (s_wired);
|
|
|
|
|
g_object_set (G_OBJECT (s_wired),
|
|
|
|
|
NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:23",
|
|
|
|
|
NULL);
|
|
|
|
|
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
2015-02-19 17:53:43 +01:00
|
|
|
g_assert (matched == exact);
|
|
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (s_wired),
|
|
|
|
|
NM_SETTING_WIRED_CLONED_MAC_ADDRESS, "52:54:00:ab:db:24",
|
|
|
|
|
NULL);
|
|
|
|
|
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
2015-02-19 17:53:43 +01:00
|
|
|
g_assert (matched == fuzzy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
|
g_object_unref (orig);
|
|
|
|
|
g_object_unref (fuzzy);
|
|
|
|
|
g_object_unref (exact);
|
|
|
|
|
}
|
|
|
|
|
|
2014-04-08 10:39:31 +02:00
|
|
|
static void
|
|
|
|
|
test_connection_no_match_ip4_addr (void)
|
|
|
|
|
{
|
|
|
|
|
NMConnection *orig, *copy, *matched;
|
|
|
|
|
GSList *connections = NULL;
|
2014-10-19 17:30:10 -04:00
|
|
|
NMSettingIPConfig *s_ip4, *s_ip6;
|
2014-09-16 16:42:46 -04:00
|
|
|
NMIPAddress *nm_addr;
|
|
|
|
|
GError *error = NULL;
|
2014-04-08 10:39:31 +02:00
|
|
|
|
|
|
|
|
orig = _match_connection_new ();
|
2014-08-13 14:34:29 -04:00
|
|
|
copy = nm_simple_connection_new_clone (orig);
|
2014-04-08 10:39:31 +02:00
|
|
|
connections = g_slist_append (connections, copy);
|
|
|
|
|
|
|
|
|
|
/* Check that if we have two differences, ipv6.method (exception we allow) and
|
|
|
|
|
* ipv4.addresses (which is fatal), we don't match the connections.
|
|
|
|
|
*/
|
|
|
|
|
s_ip6 = nm_connection_get_setting_ip6_config (orig);
|
|
|
|
|
g_assert (s_ip6);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip6),
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_LINK_LOCAL,
|
2014-04-08 10:39:31 +02:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
s_ip6 = nm_connection_get_setting_ip6_config (copy);
|
|
|
|
|
g_assert (s_ip6);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip6),
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_IGNORE,
|
2014-04-08 10:39:31 +02:00
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
s_ip4 = nm_connection_get_setting_ip4_config (orig);
|
|
|
|
|
g_assert (s_ip4);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip4),
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
|
2014-10-20 21:30:56 -04:00
|
|
|
NM_SETTING_IP_CONFIG_GATEWAY, "1.1.1.254",
|
2014-04-08 10:39:31 +02:00
|
|
|
NULL);
|
2014-10-20 21:30:56 -04:00
|
|
|
nm_addr = nm_ip_address_new (AF_INET, "1.1.1.4", 24, &error);
|
2014-09-16 16:42:46 -04:00
|
|
|
g_assert_no_error (error);
|
2014-10-19 17:30:10 -04:00
|
|
|
nm_setting_ip_config_add_address (s_ip4, nm_addr);
|
2014-09-16 16:42:46 -04:00
|
|
|
nm_ip_address_unref (nm_addr);
|
2014-04-08 10:39:31 +02:00
|
|
|
|
|
|
|
|
s_ip4 = nm_connection_get_setting_ip4_config (copy);
|
|
|
|
|
g_assert (s_ip4);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip4),
|
2014-10-19 17:30:10 -04:00
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
|
2014-10-20 21:30:56 -04:00
|
|
|
NM_SETTING_IP_CONFIG_GATEWAY, "2.2.2.254",
|
2014-04-08 10:39:31 +02:00
|
|
|
NULL);
|
2014-10-20 21:30:56 -04:00
|
|
|
nm_addr = nm_ip_address_new (AF_INET, "2.2.2.4", 24, &error);
|
2014-09-16 16:42:46 -04:00
|
|
|
g_assert_no_error (error);
|
2014-10-19 17:30:10 -04:00
|
|
|
nm_setting_ip_config_add_address (s_ip4, nm_addr);
|
2014-09-16 16:42:46 -04:00
|
|
|
nm_ip_address_unref (nm_addr);
|
2014-04-08 10:39:31 +02:00
|
|
|
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
2014-04-08 10:39:31 +02:00
|
|
|
g_assert (matched != copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
|
g_object_unref (orig);
|
|
|
|
|
g_object_unref (copy);
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-02 09:30:50 +02:00
|
|
|
static void
|
|
|
|
|
test_connection_no_match_vlan (void)
|
|
|
|
|
{
|
|
|
|
|
NMConnection *orig, *copy, *matched;
|
|
|
|
|
GSList *connections = NULL;
|
|
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
NMSettingVlan *s_vlan_orig, *s_vlan_copy;
|
|
|
|
|
char *uuid;
|
|
|
|
|
|
|
|
|
|
orig = nm_simple_connection_new ();
|
|
|
|
|
s_con = (NMSettingConnection *) nm_setting_connection_new ();
|
|
|
|
|
nm_connection_add_setting (orig, (NMSetting *) s_con);
|
|
|
|
|
uuid = nm_utils_uuid_generate ();
|
|
|
|
|
g_object_set (G_OBJECT (s_con),
|
|
|
|
|
NM_SETTING_CONNECTION_ID, "vlan-test",
|
|
|
|
|
NM_SETTING_CONNECTION_UUID, uuid,
|
|
|
|
|
NM_SETTING_CONNECTION_TYPE, NM_SETTING_VLAN_SETTING_NAME,
|
|
|
|
|
NM_SETTING_CONNECTION_AUTOCONNECT, FALSE,
|
|
|
|
|
NULL);
|
|
|
|
|
g_free (uuid);
|
|
|
|
|
nm_connection_add_setting (orig, nm_setting_vlan_new ());
|
|
|
|
|
|
|
|
|
|
copy = nm_simple_connection_new_clone (orig);
|
|
|
|
|
connections = g_slist_append (connections, copy);
|
|
|
|
|
|
|
|
|
|
/* Check that the connections do not match if VLAN flags differ */
|
|
|
|
|
s_vlan_orig = nm_connection_get_setting_vlan (orig);
|
|
|
|
|
g_assert (s_vlan_orig);
|
|
|
|
|
g_object_set (G_OBJECT (s_vlan_orig),
|
|
|
|
|
NM_SETTING_VLAN_FLAGS, NM_VLAN_FLAG_REORDER_HEADERS,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
s_vlan_copy = nm_connection_get_setting_vlan (copy);
|
|
|
|
|
g_assert (s_vlan_copy);
|
|
|
|
|
g_object_set (G_OBJECT (s_vlan_copy),
|
|
|
|
|
NM_SETTING_VLAN_FLAGS, 0,
|
|
|
|
|
NULL);
|
|
|
|
|
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
2015-09-02 09:30:50 +02:00
|
|
|
g_assert (matched != copy);
|
|
|
|
|
|
|
|
|
|
/* Check that the connections do not match if VLAN priorities differ */
|
|
|
|
|
g_object_set (G_OBJECT (s_vlan_orig), NM_SETTING_VLAN_FLAGS, 0, NULL);
|
|
|
|
|
nm_setting_vlan_add_priority_str (s_vlan_orig, NM_VLAN_INGRESS_MAP, "1:3");
|
|
|
|
|
|
|
|
|
|
g_object_set (G_OBJECT (s_vlan_copy), NM_SETTING_VLAN_FLAGS, 0, NULL);
|
|
|
|
|
nm_setting_vlan_add_priority_str (s_vlan_copy, NM_VLAN_INGRESS_MAP, "4:2");
|
|
|
|
|
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, TRUE, 0, 0);
|
2015-09-02 09:30:50 +02:00
|
|
|
g_assert (matched != copy);
|
|
|
|
|
|
|
|
|
|
g_slist_free (connections);
|
|
|
|
|
g_object_unref (orig);
|
|
|
|
|
g_object_unref (copy);
|
|
|
|
|
}
|
|
|
|
|
|
2016-02-01 14:16:30 +01:00
|
|
|
static void
|
|
|
|
|
test_connection_match_ip4_routes1 (void)
|
|
|
|
|
{
|
|
|
|
|
gs_unref_object NMConnection *orig = NULL, *copy = NULL;
|
|
|
|
|
NMConnection *matched;
|
|
|
|
|
gs_free_slist GSList *connections = NULL;
|
|
|
|
|
NMSettingIPConfig *s_ip4;
|
|
|
|
|
|
|
|
|
|
orig = _match_connection_new ();
|
|
|
|
|
|
|
|
|
|
s_ip4 = nm_connection_get_setting_ip4_config (orig);
|
|
|
|
|
g_assert (s_ip4);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip4),
|
|
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
nmtst_setting_ip_config_add_address (s_ip4, "10.0.0.1", 8);
|
|
|
|
|
|
|
|
|
|
/* Clone connection */
|
|
|
|
|
copy = nm_simple_connection_new_clone (orig);
|
|
|
|
|
connections = g_slist_append (connections, copy);
|
|
|
|
|
|
|
|
|
|
/* Set routes on original connection */
|
|
|
|
|
nmtst_setting_ip_config_add_route (s_ip4, "172.25.16.0", 24, "10.0.0.2", -1);
|
|
|
|
|
nmtst_setting_ip_config_add_route (s_ip4, "172.25.17.0", 24, "10.0.0.3", 20);
|
|
|
|
|
|
|
|
|
|
/* Set single route on cloned connection */
|
|
|
|
|
s_ip4 = nm_connection_get_setting_ip4_config (copy);
|
|
|
|
|
g_assert (s_ip4);
|
|
|
|
|
nmtst_setting_ip_config_add_route (s_ip4, "172.25.17.0", 24, "10.0.0.3", 20);
|
|
|
|
|
|
|
|
|
|
/* Try to match the connections */
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, FALSE, 100, 0);
|
2016-02-01 14:16:30 +01:00
|
|
|
g_assert (matched == NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_connection_match_ip4_routes2 (void)
|
|
|
|
|
{
|
|
|
|
|
gs_unref_object NMConnection *orig = NULL, *copy = NULL;
|
|
|
|
|
NMConnection *matched;
|
|
|
|
|
gs_free_slist GSList *connections = NULL;
|
|
|
|
|
NMSettingIPConfig *s_ip4;
|
|
|
|
|
|
|
|
|
|
orig = _match_connection_new ();
|
|
|
|
|
|
|
|
|
|
s_ip4 = nm_connection_get_setting_ip4_config (orig);
|
|
|
|
|
g_assert (s_ip4);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip4),
|
|
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP4_CONFIG_METHOD_MANUAL,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
nmtst_setting_ip_config_add_address (s_ip4, "10.0.0.1", 8);
|
|
|
|
|
|
|
|
|
|
/* Clone connection */
|
|
|
|
|
copy = nm_simple_connection_new_clone (orig);
|
|
|
|
|
connections = g_slist_append (connections, copy);
|
|
|
|
|
|
|
|
|
|
/* Set routes on original connection */
|
|
|
|
|
nmtst_setting_ip_config_add_route (s_ip4, "172.25.16.0", 24, "10.0.0.2", -1);
|
|
|
|
|
nmtst_setting_ip_config_add_route (s_ip4, "172.25.17.0", 24, "10.0.0.3", 20);
|
|
|
|
|
|
|
|
|
|
/* Set routes on cloned connection, changing order and using explicit metrics */
|
|
|
|
|
s_ip4 = nm_connection_get_setting_ip4_config (copy);
|
|
|
|
|
g_assert (s_ip4);
|
|
|
|
|
nmtst_setting_ip_config_add_route (s_ip4, "172.25.17.0", 24, "10.0.0.3", 20);
|
|
|
|
|
nmtst_setting_ip_config_add_route (s_ip4, "172.25.16.0", 24, "10.0.0.2", 100);
|
|
|
|
|
|
|
|
|
|
/* Try to match the connections using different default metrics */
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, FALSE, 100, 0);
|
2016-02-01 14:16:30 +01:00
|
|
|
g_assert (matched == copy);
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, FALSE, 500, 0);
|
2016-02-01 14:16:30 +01:00
|
|
|
g_assert (matched == NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_connection_match_ip6_routes (void)
|
|
|
|
|
{
|
|
|
|
|
gs_unref_object NMConnection *orig = NULL, *copy = NULL;
|
|
|
|
|
NMConnection *matched;
|
|
|
|
|
gs_free_slist GSList *connections = NULL;
|
|
|
|
|
NMSettingIPConfig *s_ip6;
|
|
|
|
|
|
|
|
|
|
orig = _match_connection_new ();
|
|
|
|
|
|
|
|
|
|
s_ip6 = nm_connection_get_setting_ip6_config (orig);
|
|
|
|
|
g_assert (s_ip6);
|
|
|
|
|
g_object_set (G_OBJECT (s_ip6),
|
|
|
|
|
NM_SETTING_IP_CONFIG_METHOD, NM_SETTING_IP6_CONFIG_METHOD_MANUAL,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
nmtst_setting_ip_config_add_address (s_ip6, "fd01::15", 64);
|
|
|
|
|
|
|
|
|
|
/* Clone connection */
|
|
|
|
|
copy = nm_simple_connection_new_clone (orig);
|
|
|
|
|
connections = g_slist_append (connections, copy);
|
|
|
|
|
|
|
|
|
|
/* Set routes on original connection */
|
|
|
|
|
nmtst_setting_ip_config_add_route (s_ip6, "2001:db8:a:b:0:0:0:0", 64, "fd01::16", -1);
|
|
|
|
|
|
|
|
|
|
/* Set routes on cloned connection */
|
|
|
|
|
s_ip6 = nm_connection_get_setting_ip6_config (copy);
|
|
|
|
|
g_assert (s_ip6);
|
|
|
|
|
nmtst_setting_ip_config_add_route (s_ip6, "2001:db8:a:b:0:0:0:0", 64, "fd01::16", 50);
|
|
|
|
|
|
|
|
|
|
/* Try to match the connections */
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, FALSE, 0, 100);
|
2016-02-01 14:16:30 +01:00
|
|
|
g_assert (matched == NULL);
|
2017-03-13 14:48:06 +01:00
|
|
|
matched = _match_connection (connections, orig, FALSE, 0, 50);
|
2016-02-01 14:16:30 +01:00
|
|
|
g_assert (matched == copy);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-29 16:32:03 +02:00
|
|
|
#define do_test_wildcard_match(str, result, ...) \
|
|
|
|
|
g_assert (nm_wildcard_match_check (str, \
|
|
|
|
|
(const char *const[]) { __VA_ARGS__ }, \
|
|
|
|
|
NM_NARG (__VA_ARGS__)) \
|
|
|
|
|
== result);
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_wildcard_match (void)
|
|
|
|
|
{
|
|
|
|
|
do_test_wildcard_match ("foobar", TRUE);
|
|
|
|
|
|
|
|
|
|
do_test_wildcard_match ("foo", TRUE, "foo", "bar", "baz");
|
|
|
|
|
do_test_wildcard_match ("bar", TRUE, "foo", "bar", "baz");
|
|
|
|
|
do_test_wildcard_match ("baz", TRUE, "foo", "bar", "baz");
|
|
|
|
|
do_test_wildcard_match ("aaa", FALSE, "foo", "bar", "baz");
|
|
|
|
|
do_test_wildcard_match ("", FALSE, "foo", "bar", "baz");
|
|
|
|
|
|
|
|
|
|
do_test_wildcard_match ("ens1", TRUE, "ens1*");
|
|
|
|
|
do_test_wildcard_match ("ens10", TRUE, "ens1*");
|
|
|
|
|
do_test_wildcard_match ("ens11", TRUE, "ens1*");
|
|
|
|
|
do_test_wildcard_match ("ens12", TRUE, "ens1*");
|
|
|
|
|
do_test_wildcard_match ("eth0", FALSE, "ens1*");
|
|
|
|
|
do_test_wildcard_match ("ens", FALSE, "ens1*");
|
|
|
|
|
|
|
|
|
|
do_test_wildcard_match ("ens1*", TRUE, "ens1\\*");
|
|
|
|
|
do_test_wildcard_match ("ens1" , FALSE, "ens1\\*");
|
|
|
|
|
do_test_wildcard_match ("ens10", FALSE, "ens1\\*");
|
|
|
|
|
|
|
|
|
|
do_test_wildcard_match ("abcd", TRUE, "ab??");
|
|
|
|
|
do_test_wildcard_match ("ab", FALSE, "ab??");
|
|
|
|
|
|
|
|
|
|
do_test_wildcard_match ("ab??", TRUE, "ab\\?\\?");
|
|
|
|
|
do_test_wildcard_match ("abcd", FALSE, "ab\\?\\?");
|
|
|
|
|
|
|
|
|
|
do_test_wildcard_match ("ens10", TRUE, "ens1*", "!ens11");
|
|
|
|
|
do_test_wildcard_match ("ens11", FALSE, "ens1*", "!ens11");
|
|
|
|
|
do_test_wildcard_match ("ens12", TRUE, "ens1*", "!ens11");
|
|
|
|
|
|
|
|
|
|
do_test_wildcard_match ("a", FALSE, "!a", "!b");
|
|
|
|
|
do_test_wildcard_match ("b", FALSE, "!a", "!b");
|
|
|
|
|
do_test_wildcard_match ("c", TRUE, "!a", "!b");
|
|
|
|
|
do_test_wildcard_match ("!a", TRUE, "!a", "!b");
|
|
|
|
|
|
|
|
|
|
do_test_wildcard_match ("!net", TRUE, "\\!net");
|
|
|
|
|
do_test_wildcard_match ("net", FALSE, "\\!net");
|
|
|
|
|
do_test_wildcard_match ("ens10", FALSE, "\\!net");
|
|
|
|
|
do_test_wildcard_match ("\\!net", FALSE, "\\!net");
|
|
|
|
|
|
|
|
|
|
do_test_wildcard_match ("eth0", FALSE, "*eth?", "!veth*", "!*0");
|
|
|
|
|
do_test_wildcard_match ("eth1", TRUE, "*eth?", "!veth*", "!*0");
|
|
|
|
|
do_test_wildcard_match ("myeth0", FALSE, "*eth?", "!veth*", "!*0");
|
|
|
|
|
do_test_wildcard_match ("myeth2", TRUE, "*eth?", "!veth*", "!*0");
|
|
|
|
|
do_test_wildcard_match ("veth0", FALSE, "*eth?", "!veth*", "!*0");
|
|
|
|
|
do_test_wildcard_match ("veth1", FALSE, "*eth?", "!veth*", "!*0");
|
|
|
|
|
do_test_wildcard_match ("dummy1", FALSE, "*eth?", "!veth*", "!*0");
|
|
|
|
|
|
|
|
|
|
do_test_wildcard_match ("a", TRUE, "!!a");
|
|
|
|
|
do_test_wildcard_match ("b", TRUE, "!!a");
|
|
|
|
|
do_test_wildcard_match ("!a", FALSE, "!!a");
|
|
|
|
|
|
|
|
|
|
do_test_wildcard_match ("\\", TRUE, "\\\\");
|
|
|
|
|
do_test_wildcard_match ("\\\\", FALSE, "\\\\");
|
|
|
|
|
do_test_wildcard_match ("", FALSE, "\\\\");
|
|
|
|
|
|
|
|
|
|
do_test_wildcard_match ("name", FALSE, "name[123]");
|
|
|
|
|
do_test_wildcard_match ("name1", TRUE, "name[123]");
|
|
|
|
|
do_test_wildcard_match ("name2", TRUE, "name[123]");
|
|
|
|
|
do_test_wildcard_match ("name3", TRUE, "name[123]");
|
|
|
|
|
do_test_wildcard_match ("name4", FALSE, "name[123]");
|
|
|
|
|
|
|
|
|
|
do_test_wildcard_match ("[a]", TRUE, "\\[a\\]");
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 16:06:39 +02:00
|
|
|
static NMConnection *
|
|
|
|
|
_create_connection_autoconnect (const char *id, gboolean autoconnect, int autoconnect_priority)
|
|
|
|
|
{
|
|
|
|
|
NMConnection *c;
|
|
|
|
|
NMSettingConnection *s_con;
|
|
|
|
|
|
|
|
|
|
c = nmtst_create_minimal_connection (id, NULL, NM_SETTING_WIRED_SETTING_NAME, &s_con);
|
|
|
|
|
g_object_set (s_con,
|
|
|
|
|
NM_SETTING_CONNECTION_AUTOCONNECT, autoconnect,
|
|
|
|
|
NM_SETTING_CONNECTION_AUTOCONNECT_PRIORITY, autoconnect_priority,
|
|
|
|
|
NULL);
|
|
|
|
|
nmtst_connection_normalize (c);
|
|
|
|
|
return c;
|
|
|
|
|
}
|
|
|
|
|
|
2017-02-05 16:24:27 +01:00
|
|
|
static int
|
|
|
|
|
_cmp_autoconnect_priority_p_with_data (gconstpointer pa, gconstpointer pb, gpointer user_data)
|
|
|
|
|
{
|
|
|
|
|
return nm_utils_cmp_connection_by_autoconnect_priority (*((NMConnection **) pa), *((NMConnection **) pb));
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-26 16:06:39 +02:00
|
|
|
static void
|
|
|
|
|
_test_connection_sort_autoconnect_priority_one (NMConnection **list, gboolean shuffle)
|
|
|
|
|
{
|
|
|
|
|
int i, j;
|
|
|
|
|
int count = 0;
|
|
|
|
|
gs_unref_ptrarray GPtrArray *connections = g_ptr_array_new ();
|
|
|
|
|
|
|
|
|
|
while (list[count])
|
|
|
|
|
count++;
|
|
|
|
|
g_assert (count > 1);
|
|
|
|
|
|
|
|
|
|
/* copy the list of connections over to @connections and shuffle. */
|
|
|
|
|
for (i = 0; i < count; i++)
|
|
|
|
|
g_ptr_array_add (connections, list[i]);
|
|
|
|
|
if (shuffle) {
|
|
|
|
|
for (i = count - 1; i > 0; i--) {
|
|
|
|
|
j = g_rand_int (nmtst_get_rand ()) % (i + 1);
|
|
|
|
|
NMTST_SWAP (connections->pdata[i], connections->pdata[j]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* sort it... */
|
2017-02-05 16:24:27 +01:00
|
|
|
g_ptr_array_sort_with_data (connections, _cmp_autoconnect_priority_p_with_data, NULL);
|
2014-08-26 16:06:39 +02:00
|
|
|
|
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
|
if (list[i] == connections->pdata[i])
|
|
|
|
|
continue;
|
2017-02-03 15:38:58 +01:00
|
|
|
if (shuffle && nm_utils_cmp_connection_by_autoconnect_priority (list[i], connections->pdata[i]) == 0)
|
2014-08-26 16:06:39 +02:00
|
|
|
continue;
|
|
|
|
|
g_message ("After sorting, the order of connections is not as expected!! Offending index: %d", i);
|
|
|
|
|
for (j = 0; j < count; j++)
|
|
|
|
|
g_message (" %3d: %p/%-20s - %p/%-20s", j, list[j], nm_connection_get_id (list[j]), connections->pdata[j], nm_connection_get_id (connections->pdata[j]));
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
_test_connection_sort_autoconnect_priority_free (NMConnection **list)
|
|
|
|
|
{
|
|
|
|
|
while (*list) {
|
|
|
|
|
g_object_unref (*list);
|
|
|
|
|
*list = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_connection_sort_autoconnect_priority (void)
|
|
|
|
|
{
|
|
|
|
|
NMConnection *c1[] = {
|
|
|
|
|
_create_connection_autoconnect ("AC/100", TRUE, 100),
|
|
|
|
|
_create_connection_autoconnect ("AC/100", TRUE, 100),
|
|
|
|
|
_create_connection_autoconnect ("AC/99", TRUE, 99),
|
|
|
|
|
_create_connection_autoconnect ("AC/0", TRUE, 0),
|
|
|
|
|
_create_connection_autoconnect ("AC/0", TRUE, 0),
|
|
|
|
|
_create_connection_autoconnect ("AC/-1", TRUE, -1),
|
|
|
|
|
_create_connection_autoconnect ("AC/-3", TRUE, -3),
|
|
|
|
|
_create_connection_autoconnect ("ac/0", FALSE, 0),
|
|
|
|
|
_create_connection_autoconnect ("ac/0", FALSE, 0),
|
|
|
|
|
_create_connection_autoconnect ("ac/1", FALSE, 1),
|
|
|
|
|
_create_connection_autoconnect ("ac/-1", FALSE, -1),
|
|
|
|
|
_create_connection_autoconnect ("ac/1", FALSE, 1),
|
|
|
|
|
_create_connection_autoconnect ("ac/0", FALSE, 0),
|
|
|
|
|
NULL,
|
|
|
|
|
};
|
|
|
|
|
NMConnection *c2[] = {
|
|
|
|
|
_create_connection_autoconnect ("AC/100", TRUE, 100),
|
|
|
|
|
_create_connection_autoconnect ("AC/99", TRUE, 99),
|
|
|
|
|
_create_connection_autoconnect ("AC/0", TRUE, 0),
|
|
|
|
|
_create_connection_autoconnect ("AC/-1", TRUE, -1),
|
|
|
|
|
_create_connection_autoconnect ("AC/-3", TRUE, -3),
|
|
|
|
|
_create_connection_autoconnect ("ac/0", FALSE, 0),
|
|
|
|
|
NULL,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
_test_connection_sort_autoconnect_priority_one (c1, FALSE);
|
|
|
|
|
_test_connection_sort_autoconnect_priority_one (c2, FALSE);
|
|
|
|
|
_test_connection_sort_autoconnect_priority_one (c1, TRUE);
|
|
|
|
|
_test_connection_sort_autoconnect_priority_one (c2, TRUE);
|
|
|
|
|
|
|
|
|
|
_test_connection_sort_autoconnect_priority_free (c1);
|
|
|
|
|
_test_connection_sort_autoconnect_priority_free (c2);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2014-02-25 17:44:07 -06:00
|
|
|
|
2017-01-25 16:05:39 +01:00
|
|
|
#define MATCH_S390 "S390:"
|
2017-03-17 16:18:48 +01:00
|
|
|
#define MATCH_DRIVER "DRIVER:"
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
|
2017-01-25 16:05:39 +01:00
|
|
|
static NMMatchSpecMatchType
|
|
|
|
|
_test_match_spec_device (const GSList *specs, const char *match_str)
|
2015-01-26 18:58:20 +01:00
|
|
|
{
|
2017-01-25 16:05:39 +01:00
|
|
|
if (match_str && g_str_has_prefix (match_str, MATCH_S390))
|
device: add "dhcp-plugin" match spec for device
The need for this is the following:
"ipv4.dhcp-client-id" can be specified via global connection defaults.
In absence of any configuration in NetworkManager, the default depends
on the DHCP client plugin. In case of "dhclient", the default further
depends on /etc/dhcp.
For "internal" plugin, we may very well want to change the default
client-id to "mac" by universally installing a configuration
snippet
[connection-use-mac-client-id]
ipv4.dhcp-client-id=mac
However, if we the user happens to enable "dhclient" plugin, this also
forces the client-id and overrules configuration from /etc/dhcp. The real
problem is, that dhclient can be configured via means outside of NetworkManager,
so our defaults shall not overwrite defaults from /etc/dhcp.
With the new device spec, we can avoid this issue:
[connection-dhcp-client-id]
match-device=except:dhcp-plugin:dhclient
ipv4.dhcp-client-id=mac
This will be part of the solution for rh#1640494. Note that merely
dropping a configuration snippet is not yet enough. More fixes for
DHCP will follow. Also, bug rh#1640494 may have alternative solutions
as well. The nice part of this new feature is that it is generally
useful for configuring connection defaults and not specifically for
the client-id issue.
Note that this match spec is per-device, although the plugin is selected
globally. That makes some sense, because in the future we may or may not
configure the DHCP plugin per-device or per address family.
https://bugzilla.redhat.com/show_bug.cgi?id=1640494
2018-10-24 08:43:45 +02:00
|
|
|
return nm_match_spec_device (specs, NULL, NULL, NULL, NULL, NULL, &match_str[NM_STRLEN (MATCH_S390)], NULL);
|
2017-03-17 16:18:48 +01:00
|
|
|
if (match_str && g_str_has_prefix (match_str, MATCH_DRIVER)) {
|
|
|
|
|
gs_free char *s = g_strdup (&match_str[NM_STRLEN (MATCH_DRIVER)]);
|
|
|
|
|
char *t;
|
|
|
|
|
|
|
|
|
|
t = strchr (s, '|');
|
|
|
|
|
if (t) {
|
|
|
|
|
t[0] = '\0';
|
|
|
|
|
t++;
|
|
|
|
|
}
|
device: add "dhcp-plugin" match spec for device
The need for this is the following:
"ipv4.dhcp-client-id" can be specified via global connection defaults.
In absence of any configuration in NetworkManager, the default depends
on the DHCP client plugin. In case of "dhclient", the default further
depends on /etc/dhcp.
For "internal" plugin, we may very well want to change the default
client-id to "mac" by universally installing a configuration
snippet
[connection-use-mac-client-id]
ipv4.dhcp-client-id=mac
However, if we the user happens to enable "dhclient" plugin, this also
forces the client-id and overrules configuration from /etc/dhcp. The real
problem is, that dhclient can be configured via means outside of NetworkManager,
so our defaults shall not overwrite defaults from /etc/dhcp.
With the new device spec, we can avoid this issue:
[connection-dhcp-client-id]
match-device=except:dhcp-plugin:dhclient
ipv4.dhcp-client-id=mac
This will be part of the solution for rh#1640494. Note that merely
dropping a configuration snippet is not yet enough. More fixes for
DHCP will follow. Also, bug rh#1640494 may have alternative solutions
as well. The nice part of this new feature is that it is generally
useful for configuring connection defaults and not specifically for
the client-id issue.
Note that this match spec is per-device, although the plugin is selected
globally. That makes some sense, because in the future we may or may not
configure the DHCP plugin per-device or per address family.
https://bugzilla.redhat.com/show_bug.cgi?id=1640494
2018-10-24 08:43:45 +02:00
|
|
|
return nm_match_spec_device (specs, NULL, NULL, s, t, NULL, NULL, NULL);
|
2017-03-17 16:18:48 +01:00
|
|
|
}
|
device: add "dhcp-plugin" match spec for device
The need for this is the following:
"ipv4.dhcp-client-id" can be specified via global connection defaults.
In absence of any configuration in NetworkManager, the default depends
on the DHCP client plugin. In case of "dhclient", the default further
depends on /etc/dhcp.
For "internal" plugin, we may very well want to change the default
client-id to "mac" by universally installing a configuration
snippet
[connection-use-mac-client-id]
ipv4.dhcp-client-id=mac
However, if we the user happens to enable "dhclient" plugin, this also
forces the client-id and overrules configuration from /etc/dhcp. The real
problem is, that dhclient can be configured via means outside of NetworkManager,
so our defaults shall not overwrite defaults from /etc/dhcp.
With the new device spec, we can avoid this issue:
[connection-dhcp-client-id]
match-device=except:dhcp-plugin:dhclient
ipv4.dhcp-client-id=mac
This will be part of the solution for rh#1640494. Note that merely
dropping a configuration snippet is not yet enough. More fixes for
DHCP will follow. Also, bug rh#1640494 may have alternative solutions
as well. The nice part of this new feature is that it is generally
useful for configuring connection defaults and not specifically for
the client-id issue.
Note that this match spec is per-device, although the plugin is selected
globally. That makes some sense, because in the future we may or may not
configure the DHCP plugin per-device or per address family.
https://bugzilla.redhat.com/show_bug.cgi?id=1640494
2018-10-24 08:43:45 +02:00
|
|
|
return nm_match_spec_device (specs, match_str, NULL, NULL, NULL, NULL, NULL, NULL);
|
2015-01-26 18:58:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
2017-01-25 16:05:39 +01:00
|
|
|
_do_test_match_spec_device (const char *spec_str, const char **matches, const char **no_matches, const char **neg_matches)
|
2015-01-26 18:58:20 +01:00
|
|
|
{
|
2017-01-20 20:52:14 +01:00
|
|
|
GSList *specs, *specs_randperm = NULL, *specs_resplit, *specs_i, *specs_j;
|
2015-01-26 18:58:20 +01:00
|
|
|
guint i;
|
2015-07-01 17:01:44 +02:00
|
|
|
gs_free char *specs_joined = NULL;
|
2017-01-25 16:05:39 +01:00
|
|
|
const char *s;
|
|
|
|
|
static const char *no_matches_default[] = {
|
|
|
|
|
"e",
|
|
|
|
|
"em",
|
|
|
|
|
"em*",
|
|
|
|
|
"em\\",
|
|
|
|
|
"em\\*",
|
|
|
|
|
"em\\1",
|
|
|
|
|
"em\\11",
|
|
|
|
|
"em\\2",
|
|
|
|
|
"em1",
|
|
|
|
|
"em11",
|
|
|
|
|
"em2",
|
|
|
|
|
"=em*",
|
|
|
|
|
NULL
|
|
|
|
|
};
|
2015-01-26 18:58:20 +01:00
|
|
|
|
|
|
|
|
g_assert (spec_str);
|
core: add nm_match_spec_split() function
There are currently three device spec properties: 'main.ignore-carrier',
'main.no-auto-default' and 'keyfile.unmanaged-devices'.
The first two, called g_key_file_parse_value_as_string() to split
the string into individual device specs. This uses ',' as separator
and supports escaping using '\\'.
'keyfile.unmanaged-devices' is split using ',' or ';' as separator
without supporting escaping.
Add a new function nm_match_spec_split(), to unify these two behaviors
and support both formats. That is, both previous formats are mostly
supported, but obviously there are some behavioral changes if the string
contains one of '\\', ',', or ';'.
nm_match_spec_split() is copied from glibs g_key_file_parse_value_as_string()
and adjusted.
2015-02-09 16:57:14 +01:00
|
|
|
|
|
|
|
|
specs = nm_match_spec_split (spec_str);
|
2015-06-16 14:06:48 +02:00
|
|
|
|
2015-07-01 17:01:44 +02:00
|
|
|
/* assert that split(join(specs)) == specs */
|
|
|
|
|
specs_joined = nm_match_spec_join (specs);
|
|
|
|
|
specs_resplit = nm_match_spec_split (specs_joined);
|
|
|
|
|
specs_i = specs;
|
|
|
|
|
specs_j = specs_resplit;
|
|
|
|
|
while (specs_i && specs_j && g_strcmp0 (specs_i->data, specs_j->data) == 0) {
|
|
|
|
|
specs_i = specs_i->next;
|
|
|
|
|
specs_j = specs_j->next;
|
|
|
|
|
}
|
|
|
|
|
g_assert (!specs_i);
|
|
|
|
|
g_assert (!specs_j);
|
|
|
|
|
g_slist_free_full (specs_resplit, g_free);
|
|
|
|
|
|
2017-01-20 20:52:14 +01:00
|
|
|
/* also check the matches in the random order. They must yield the same result because
|
2015-06-16 14:06:48 +02:00
|
|
|
* matches are inclusive -- except "except:" which always wins. */
|
2017-01-20 20:52:14 +01:00
|
|
|
specs_randperm = nmtst_rand_perm_gslist (NULL, g_slist_copy (specs));
|
2015-01-26 18:58:20 +01:00
|
|
|
|
|
|
|
|
for (i = 0; matches && matches[i]; i++) {
|
2017-01-25 16:05:39 +01:00
|
|
|
g_assert (_test_match_spec_device (specs, matches[i]) == NM_MATCH_SPEC_MATCH);
|
|
|
|
|
g_assert (_test_match_spec_device (specs_randperm, matches[i]) == NM_MATCH_SPEC_MATCH);
|
2015-01-23 17:02:16 +01:00
|
|
|
}
|
|
|
|
|
for (i = 0; neg_matches && neg_matches[i]; i++) {
|
2017-01-25 16:05:39 +01:00
|
|
|
g_assert (_test_match_spec_device (specs, neg_matches[i]) == NM_MATCH_SPEC_NEG_MATCH);
|
|
|
|
|
g_assert (_test_match_spec_device (specs_randperm, neg_matches[i]) == NM_MATCH_SPEC_NEG_MATCH);
|
2015-01-26 18:58:20 +01:00
|
|
|
}
|
2017-01-25 16:05:39 +01:00
|
|
|
for (i = 0; no_matches && no_matches[i]; i++) {
|
|
|
|
|
g_assert (_test_match_spec_device (specs, no_matches[i]) == NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
g_assert (_test_match_spec_device (specs_randperm, no_matches[i]) == NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
}
|
|
|
|
|
if (!no_matches) {
|
|
|
|
|
for (i = 0; (s = no_matches_default[i]); i++) {
|
|
|
|
|
if ( (matches && g_strv_contains (matches, s))
|
|
|
|
|
|| (neg_matches && g_strv_contains (neg_matches, s)))
|
|
|
|
|
continue;
|
|
|
|
|
g_assert (_test_match_spec_device (specs, s) == NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
g_assert (_test_match_spec_device (specs_randperm, s) == NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
}
|
2015-01-26 18:58:20 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-20 20:52:14 +01:00
|
|
|
g_slist_free (specs_randperm);
|
core: add nm_match_spec_split() function
There are currently three device spec properties: 'main.ignore-carrier',
'main.no-auto-default' and 'keyfile.unmanaged-devices'.
The first two, called g_key_file_parse_value_as_string() to split
the string into individual device specs. This uses ',' as separator
and supports escaping using '\\'.
'keyfile.unmanaged-devices' is split using ',' or ';' as separator
without supporting escaping.
Add a new function nm_match_spec_split(), to unify these two behaviors
and support both formats. That is, both previous formats are mostly
supported, but obviously there are some behavioral changes if the string
contains one of '\\', ',', or ';'.
nm_match_spec_split() is copied from glibs g_key_file_parse_value_as_string()
and adjusted.
2015-02-09 16:57:14 +01:00
|
|
|
g_slist_free_full (specs, g_free);
|
2015-01-26 18:58:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
test_match_spec_device (void)
|
2015-01-26 18:58:20 +01:00
|
|
|
{
|
|
|
|
|
#define S(...) ((const char *[]) { __VA_ARGS__, NULL } )
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
_do_test_match_spec_device ("em1",
|
|
|
|
|
S ("em1"),
|
2017-01-25 16:05:39 +01:00
|
|
|
NULL,
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
NULL);
|
|
|
|
|
_do_test_match_spec_device ("em1,em2",
|
|
|
|
|
S ("em1", "em2"),
|
2017-01-25 16:05:39 +01:00
|
|
|
NULL,
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
NULL);
|
|
|
|
|
_do_test_match_spec_device ("em1,em2,interface-name:em2",
|
|
|
|
|
S ("em1", "em2"),
|
2017-01-25 16:05:39 +01:00
|
|
|
NULL,
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
NULL);
|
|
|
|
|
_do_test_match_spec_device ("interface-name:em1",
|
|
|
|
|
S ("em1"),
|
2017-01-25 16:05:39 +01:00
|
|
|
NULL,
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
NULL);
|
|
|
|
|
_do_test_match_spec_device ("interface-name:em*",
|
|
|
|
|
S ("em", "em*", "em\\", "em\\*", "em\\1", "em\\11", "em\\2", "em1", "em11", "em2", "em3"),
|
2017-01-25 16:05:39 +01:00
|
|
|
NULL,
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
NULL);
|
|
|
|
|
_do_test_match_spec_device ("interface-name:em\\*",
|
|
|
|
|
S ("em\\", "em\\*", "em\\1", "em\\11", "em\\2"),
|
2017-01-25 16:05:39 +01:00
|
|
|
NULL,
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
NULL);
|
|
|
|
|
_do_test_match_spec_device ("interface-name:~em\\*",
|
|
|
|
|
S ("em\\", "em\\*", "em\\1", "em\\11", "em\\2"),
|
2017-01-25 16:05:39 +01:00
|
|
|
NULL,
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
NULL);
|
2017-03-08 16:13:18 +01:00
|
|
|
_do_test_match_spec_device ("except:*",
|
|
|
|
|
NULL,
|
|
|
|
|
S (NULL),
|
|
|
|
|
S ("a"));
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
_do_test_match_spec_device ("interface-name:=em*",
|
|
|
|
|
S ("em*"),
|
2017-01-25 16:05:39 +01:00
|
|
|
NULL,
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
NULL);
|
|
|
|
|
_do_test_match_spec_device ("interface-name:em*,except:interface-name:em1*",
|
|
|
|
|
S ("em", "em*", "em\\", "em\\*", "em\\1", "em\\11", "em\\2", "em2", "em3"),
|
2017-01-25 16:05:39 +01:00
|
|
|
NULL,
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
S ("em1", "em11"));
|
|
|
|
|
_do_test_match_spec_device ("interface-name:em*,except:interface-name:=em*",
|
|
|
|
|
S ("em", "em\\", "em\\*", "em\\1", "em\\11", "em\\2", "em1", "em11", "em2", "em3"),
|
2017-01-25 16:05:39 +01:00
|
|
|
NULL,
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
S ("em*"));
|
|
|
|
|
_do_test_match_spec_device ("aa,bb,cc\\,dd,e,,",
|
|
|
|
|
S ("aa", "bb", "cc,dd", "e"),
|
2017-01-25 16:05:39 +01:00
|
|
|
NULL,
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
NULL);
|
|
|
|
|
_do_test_match_spec_device ("aa;bb;cc\\;dd;e,;",
|
|
|
|
|
S ("aa", "bb", "cc;dd", "e"),
|
2017-01-25 16:05:39 +01:00
|
|
|
NULL,
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
NULL);
|
|
|
|
|
_do_test_match_spec_device ("interface-name:em\\;1,em\\,2,\\,,\\\\,,em\\\\x",
|
|
|
|
|
S ("em;1", "em,2", ",", "\\", "em\\x"),
|
2017-01-25 16:05:39 +01:00
|
|
|
NULL,
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
NULL);
|
|
|
|
|
_do_test_match_spec_device ("\\s\\s,\\sinterface-name:a,\\s,",
|
|
|
|
|
S (" ", " ", " interface-name:a"),
|
2017-01-25 16:05:39 +01:00
|
|
|
NULL,
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
NULL);
|
|
|
|
|
_do_test_match_spec_device (" aa ; bb ; cc\\;dd ;e , ; \t\\t , ",
|
|
|
|
|
S ("aa", "bb", "cc;dd", "e", "\t"),
|
2017-01-25 16:05:39 +01:00
|
|
|
NULL,
|
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
|
|
_do_test_match_spec_device ("s390-subchannels:0.0.1000\\,0.0.1001",
|
|
|
|
|
S (MATCH_S390"0.0.1000", MATCH_S390"0.0.1000,deadbeef", MATCH_S390"0.0.1000,0.0.1001", MATCH_S390"0.0.1000,0.0.1002"),
|
|
|
|
|
S (MATCH_S390"0.0.1001"),
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
NULL);
|
2017-01-25 16:05:39 +01:00
|
|
|
_do_test_match_spec_device ("*,except:s390-subchannels:0.0.1000\\,0.0.1001",
|
|
|
|
|
NULL,
|
|
|
|
|
S (NULL),
|
|
|
|
|
S (MATCH_S390"0.0.1000", MATCH_S390"0.0.1000,deadbeef", MATCH_S390"0.0.1000,0.0.1001", MATCH_S390"0.0.1000,0.0.1002"));
|
2017-03-17 16:18:48 +01:00
|
|
|
|
|
|
|
|
_do_test_match_spec_device ("driver:DRV",
|
|
|
|
|
S (MATCH_DRIVER"DRV", MATCH_DRIVER"DRV|1.6"),
|
|
|
|
|
S (MATCH_DRIVER"DR", MATCH_DRIVER"DR*"),
|
|
|
|
|
NULL);
|
|
|
|
|
_do_test_match_spec_device ("driver:DRV//",
|
|
|
|
|
S (MATCH_DRIVER"DRV/"),
|
|
|
|
|
S (MATCH_DRIVER"DRV/|1.6", MATCH_DRIVER"DR", MATCH_DRIVER"DR*"),
|
|
|
|
|
NULL);
|
|
|
|
|
_do_test_match_spec_device ("driver:DRV//*",
|
|
|
|
|
S (MATCH_DRIVER"DRV/", MATCH_DRIVER"DRV/|1.6"),
|
|
|
|
|
S (MATCH_DRIVER"DR", MATCH_DRIVER"DR*"),
|
|
|
|
|
NULL);
|
|
|
|
|
_do_test_match_spec_device ("driver:DRV//1.5*",
|
|
|
|
|
S (MATCH_DRIVER"DRV/|1.5", MATCH_DRIVER"DRV/|1.5.2"),
|
|
|
|
|
S (MATCH_DRIVER"DRV/", MATCH_DRIVER"DRV/|1.6", MATCH_DRIVER"DR", MATCH_DRIVER"DR*"),
|
|
|
|
|
NULL);
|
2015-01-26 18:58:20 +01:00
|
|
|
#undef S
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
2015-01-26 18:58:20 +01:00
|
|
|
|
config: allow to enable/disable configuration snippets
Support a new configuration option
[.config]
enable=<ENABLED>
for configuration snippets.
This new [.config] section is only relevant within the snippet itself
and it is not merged into the combined configuration.
Currently only the "enable" key is supported. If the "enable" key is
missing, it obviously defaults to being enabled. It allows snippets
to be skipped from loading. The main configuration "NetworkManager.conf"
cannot be skipped.
<ENABLED> can be a boolean value (false), to skip a configuration
snippet from loading.
It can also be a string to match against the NetworkManager version,
like "enable=nm-version-min:1.1,nm-version-min:1.0.6"
There are several motivations for this:
- the user can disable an entire configuration snippet by toggeling
one entry.
This generalizes the functionality of the global-dns.enable
setting, but in a way that applies to configuration on a per-file
basis.
- for developing, we often switch between different versions of
NetworkManager. Thus, we might want to use different configuration.
E.g. before global-dns options, I want to use "dns=none" and manage
resolv.conf myself. Now, I can use global-dns setting to do that.
That can be achieved with something like the following (not exactly,
it's an example only):
[.config]
enable=nm-version-min:1.1
[main]
dns=default
[global-dns-domain-*]
nameserver=127.0.0.1
Arguably, this would be more awesome, if we would bump our micro devel
version (1.1.0) more often while developing 1.2.0 (*hint*).
- in principle, packages could drop configuration snippets and enable
them based on the NetworkManager version.
- with the "env:" spec, you can enable/disable snippets by configuring
an environment variable. Again, useful for testing and developing.
2015-10-01 10:43:33 +02:00
|
|
|
static void
|
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 07:40:19 +02:00
|
|
|
_do_test_match_spec_config (const char *file, int line, const char *spec_str, guint version, guint v_maj, guint v_min, guint v_mic, NMMatchSpecMatchType expected)
|
config: allow to enable/disable configuration snippets
Support a new configuration option
[.config]
enable=<ENABLED>
for configuration snippets.
This new [.config] section is only relevant within the snippet itself
and it is not merged into the combined configuration.
Currently only the "enable" key is supported. If the "enable" key is
missing, it obviously defaults to being enabled. It allows snippets
to be skipped from loading. The main configuration "NetworkManager.conf"
cannot be skipped.
<ENABLED> can be a boolean value (false), to skip a configuration
snippet from loading.
It can also be a string to match against the NetworkManager version,
like "enable=nm-version-min:1.1,nm-version-min:1.0.6"
There are several motivations for this:
- the user can disable an entire configuration snippet by toggeling
one entry.
This generalizes the functionality of the global-dns.enable
setting, but in a way that applies to configuration on a per-file
basis.
- for developing, we often switch between different versions of
NetworkManager. Thus, we might want to use different configuration.
E.g. before global-dns options, I want to use "dns=none" and manage
resolv.conf myself. Now, I can use global-dns setting to do that.
That can be achieved with something like the following (not exactly,
it's an example only):
[.config]
enable=nm-version-min:1.1
[main]
dns=default
[global-dns-domain-*]
nameserver=127.0.0.1
Arguably, this would be more awesome, if we would bump our micro devel
version (1.1.0) more often while developing 1.2.0 (*hint*).
- in principle, packages could drop configuration snippets and enable
them based on the NetworkManager version.
- with the "env:" spec, you can enable/disable snippets by configuring
an environment variable. Again, useful for testing and developing.
2015-10-01 10:43:33 +02:00
|
|
|
{
|
|
|
|
|
GSList *specs;
|
|
|
|
|
NMMatchSpecMatchType match_result;
|
|
|
|
|
guint c_maj, c_min, c_mic;
|
|
|
|
|
|
|
|
|
|
g_assert_cmpint (version, ==, nm_encode_version (v_maj, v_min, v_mic));
|
|
|
|
|
|
|
|
|
|
nm_decode_version (version, &c_maj, &c_min, &c_mic);
|
|
|
|
|
g_assert_cmpint (c_maj, ==, c_maj);
|
|
|
|
|
g_assert_cmpint (c_min, ==, c_min);
|
|
|
|
|
g_assert_cmpint (c_mic, ==, c_mic);
|
|
|
|
|
|
|
|
|
|
specs = nm_match_spec_split (spec_str);
|
|
|
|
|
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
match_result = nm_match_spec_config (specs, version, NULL);
|
config: allow to enable/disable configuration snippets
Support a new configuration option
[.config]
enable=<ENABLED>
for configuration snippets.
This new [.config] section is only relevant within the snippet itself
and it is not merged into the combined configuration.
Currently only the "enable" key is supported. If the "enable" key is
missing, it obviously defaults to being enabled. It allows snippets
to be skipped from loading. The main configuration "NetworkManager.conf"
cannot be skipped.
<ENABLED> can be a boolean value (false), to skip a configuration
snippet from loading.
It can also be a string to match against the NetworkManager version,
like "enable=nm-version-min:1.1,nm-version-min:1.0.6"
There are several motivations for this:
- the user can disable an entire configuration snippet by toggeling
one entry.
This generalizes the functionality of the global-dns.enable
setting, but in a way that applies to configuration on a per-file
basis.
- for developing, we often switch between different versions of
NetworkManager. Thus, we might want to use different configuration.
E.g. before global-dns options, I want to use "dns=none" and manage
resolv.conf myself. Now, I can use global-dns setting to do that.
That can be achieved with something like the following (not exactly,
it's an example only):
[.config]
enable=nm-version-min:1.1
[main]
dns=default
[global-dns-domain-*]
nameserver=127.0.0.1
Arguably, this would be more awesome, if we would bump our micro devel
version (1.1.0) more often while developing 1.2.0 (*hint*).
- in principle, packages could drop configuration snippets and enable
them based on the NetworkManager version.
- with the "env:" spec, you can enable/disable snippets by configuring
an environment variable. Again, useful for testing and developing.
2015-10-01 10:43:33 +02:00
|
|
|
|
|
|
|
|
if (expected != match_result)
|
2018-09-14 23:49:20 -04:00
|
|
|
g_error ("%s:%d: failed comparing \"%s\" with %u.%u.%u. Expected %d, but got %d", file, line, spec_str, v_maj, v_min, v_mic, (int) expected, (int) match_result);
|
config: allow to enable/disable configuration snippets
Support a new configuration option
[.config]
enable=<ENABLED>
for configuration snippets.
This new [.config] section is only relevant within the snippet itself
and it is not merged into the combined configuration.
Currently only the "enable" key is supported. If the "enable" key is
missing, it obviously defaults to being enabled. It allows snippets
to be skipped from loading. The main configuration "NetworkManager.conf"
cannot be skipped.
<ENABLED> can be a boolean value (false), to skip a configuration
snippet from loading.
It can also be a string to match against the NetworkManager version,
like "enable=nm-version-min:1.1,nm-version-min:1.0.6"
There are several motivations for this:
- the user can disable an entire configuration snippet by toggeling
one entry.
This generalizes the functionality of the global-dns.enable
setting, but in a way that applies to configuration on a per-file
basis.
- for developing, we often switch between different versions of
NetworkManager. Thus, we might want to use different configuration.
E.g. before global-dns options, I want to use "dns=none" and manage
resolv.conf myself. Now, I can use global-dns setting to do that.
That can be achieved with something like the following (not exactly,
it's an example only):
[.config]
enable=nm-version-min:1.1
[main]
dns=default
[global-dns-domain-*]
nameserver=127.0.0.1
Arguably, this would be more awesome, if we would bump our micro devel
version (1.1.0) more often while developing 1.2.0 (*hint*).
- in principle, packages could drop configuration snippets and enable
them based on the NetworkManager version.
- with the "env:" spec, you can enable/disable snippets by configuring
an environment variable. Again, useful for testing and developing.
2015-10-01 10:43:33 +02:00
|
|
|
|
|
|
|
|
if (g_slist_length (specs) == 1 && match_result != NM_MATCH_SPEC_NEG_MATCH) {
|
|
|
|
|
/* there is only one spec in the list... test that we match except: */
|
|
|
|
|
char *sss = g_strdup_printf ("except:%s", (char *) specs->data);
|
|
|
|
|
GSList *specs2 = g_slist_append (NULL, sss);
|
|
|
|
|
NMMatchSpecMatchType match_result2;
|
|
|
|
|
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
match_result2 = nm_match_spec_config (specs2, version, NULL);
|
config: allow to enable/disable configuration snippets
Support a new configuration option
[.config]
enable=<ENABLED>
for configuration snippets.
This new [.config] section is only relevant within the snippet itself
and it is not merged into the combined configuration.
Currently only the "enable" key is supported. If the "enable" key is
missing, it obviously defaults to being enabled. It allows snippets
to be skipped from loading. The main configuration "NetworkManager.conf"
cannot be skipped.
<ENABLED> can be a boolean value (false), to skip a configuration
snippet from loading.
It can also be a string to match against the NetworkManager version,
like "enable=nm-version-min:1.1,nm-version-min:1.0.6"
There are several motivations for this:
- the user can disable an entire configuration snippet by toggeling
one entry.
This generalizes the functionality of the global-dns.enable
setting, but in a way that applies to configuration on a per-file
basis.
- for developing, we often switch between different versions of
NetworkManager. Thus, we might want to use different configuration.
E.g. before global-dns options, I want to use "dns=none" and manage
resolv.conf myself. Now, I can use global-dns setting to do that.
That can be achieved with something like the following (not exactly,
it's an example only):
[.config]
enable=nm-version-min:1.1
[main]
dns=default
[global-dns-domain-*]
nameserver=127.0.0.1
Arguably, this would be more awesome, if we would bump our micro devel
version (1.1.0) more often while developing 1.2.0 (*hint*).
- in principle, packages could drop configuration snippets and enable
them based on the NetworkManager version.
- with the "env:" spec, you can enable/disable snippets by configuring
an environment variable. Again, useful for testing and developing.
2015-10-01 10:43:33 +02:00
|
|
|
if (match_result == NM_MATCH_SPEC_NO_MATCH)
|
|
|
|
|
g_assert_cmpint (match_result2, ==, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
else
|
|
|
|
|
g_assert_cmpint (match_result2, ==, NM_MATCH_SPEC_NEG_MATCH);
|
|
|
|
|
|
|
|
|
|
g_slist_free_full (specs2, g_free);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_slist_free_full (specs, g_free);
|
|
|
|
|
}
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
#define do_test_match_spec_config(spec, v_maj, v_min, v_mic, expected) \
|
|
|
|
|
_do_test_match_spec_config (__FILE__, __LINE__, (""spec), NM_ENCODE_VERSION ((v_maj), (v_min), (v_mic)), (v_maj), (v_min), (v_mic), (expected))
|
config: allow to enable/disable configuration snippets
Support a new configuration option
[.config]
enable=<ENABLED>
for configuration snippets.
This new [.config] section is only relevant within the snippet itself
and it is not merged into the combined configuration.
Currently only the "enable" key is supported. If the "enable" key is
missing, it obviously defaults to being enabled. It allows snippets
to be skipped from loading. The main configuration "NetworkManager.conf"
cannot be skipped.
<ENABLED> can be a boolean value (false), to skip a configuration
snippet from loading.
It can also be a string to match against the NetworkManager version,
like "enable=nm-version-min:1.1,nm-version-min:1.0.6"
There are several motivations for this:
- the user can disable an entire configuration snippet by toggeling
one entry.
This generalizes the functionality of the global-dns.enable
setting, but in a way that applies to configuration on a per-file
basis.
- for developing, we often switch between different versions of
NetworkManager. Thus, we might want to use different configuration.
E.g. before global-dns options, I want to use "dns=none" and manage
resolv.conf myself. Now, I can use global-dns setting to do that.
That can be achieved with something like the following (not exactly,
it's an example only):
[.config]
enable=nm-version-min:1.1
[main]
dns=default
[global-dns-domain-*]
nameserver=127.0.0.1
Arguably, this would be more awesome, if we would bump our micro devel
version (1.1.0) more often while developing 1.2.0 (*hint*).
- in principle, packages could drop configuration snippets and enable
them based on the NetworkManager version.
- with the "env:" spec, you can enable/disable snippets by configuring
an environment variable. Again, useful for testing and developing.
2015-10-01 10:43:33 +02:00
|
|
|
|
|
|
|
|
static void
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
test_match_spec_config (void)
|
config: allow to enable/disable configuration snippets
Support a new configuration option
[.config]
enable=<ENABLED>
for configuration snippets.
This new [.config] section is only relevant within the snippet itself
and it is not merged into the combined configuration.
Currently only the "enable" key is supported. If the "enable" key is
missing, it obviously defaults to being enabled. It allows snippets
to be skipped from loading. The main configuration "NetworkManager.conf"
cannot be skipped.
<ENABLED> can be a boolean value (false), to skip a configuration
snippet from loading.
It can also be a string to match against the NetworkManager version,
like "enable=nm-version-min:1.1,nm-version-min:1.0.6"
There are several motivations for this:
- the user can disable an entire configuration snippet by toggeling
one entry.
This generalizes the functionality of the global-dns.enable
setting, but in a way that applies to configuration on a per-file
basis.
- for developing, we often switch between different versions of
NetworkManager. Thus, we might want to use different configuration.
E.g. before global-dns options, I want to use "dns=none" and manage
resolv.conf myself. Now, I can use global-dns setting to do that.
That can be achieved with something like the following (not exactly,
it's an example only):
[.config]
enable=nm-version-min:1.1
[main]
dns=default
[global-dns-domain-*]
nameserver=127.0.0.1
Arguably, this would be more awesome, if we would bump our micro devel
version (1.1.0) more often while developing 1.2.0 (*hint*).
- in principle, packages could drop configuration snippets and enable
them based on the NetworkManager version.
- with the "env:" spec, you can enable/disable snippets by configuring
an environment variable. Again, useful for testing and developing.
2015-10-01 10:43:33 +02:00
|
|
|
{
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
do_test_match_spec_config ("", 1, 2, 3, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version:1.2.3", 1, 2, 2, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version:1.2.3", 1, 2, 3, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version:1.2.3", 1, 2, 4, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
|
|
|
|
|
do_test_match_spec_config ("nm-version:1.2", 1, 1, 2, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version:1.2", 1, 2, 0, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version:1.2", 1, 2, 2, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version:1.2", 1, 2, 3, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version:1.2", 1, 2, 4, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version:1.2", 1, 3, 0, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2.3", 0, 2, 30, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2.3", 1, 1, 1, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2.3", 1, 2, 2, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2.3", 1, 2, 3, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2.3", 1, 2, 5, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2.3", 1, 3, 0, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2.3", 1, 3, 30, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2.3", 1, 4, 30, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2", 0, 2, 30, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2", 1, 1, 1, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2", 1, 2, 0, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2", 1, 2, 3, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2", 1, 2, 5, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2", 1, 3, 0, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2", 1, 3, 30, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.2", 1, 4, 30, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1", 0, 2, 30, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1", 1, 1, 1, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1", 1, 2, 0, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1", 1, 2, 3, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1", 1, 2, 5, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1", 1, 3, 0, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1", 1, 3, 30, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1", 1, 4, 30, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2.3", 0, 2, 30, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2.3", 1, 1, 1, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2.3", 1, 2, 0, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2.3", 1, 2, 1, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2.3", 1, 2, 2, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2.3", 1, 2, 3, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2.3", 1, 2, 5, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2.3", 1, 3, 0, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2.3", 1, 3, 30, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2.3", 1, 4, 30, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2", 0, 2, 30, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2", 1, 1, 1, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2", 1, 2, 0, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2", 1, 2, 3, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2", 1, 2, 5, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2", 1, 3, 0, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2", 1, 3, 30, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1.2", 1, 4, 30, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1", 0, 2, 30, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1", 1, 1, 1, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1", 1, 2, 0, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1", 1, 2, 3, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1", 1, 2, 5, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1", 1, 3, 0, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1", 1, 3, 30, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1", 1, 4, 30, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-max:1", 2, 4, 30, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
|
|
|
|
|
do_test_match_spec_config ("except:nm-version:1.4.8", 1, 6, 0, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,except:nm-version:1.4.8", 1, 6, 0, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 2, 0, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 2, 0, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 2, 15, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 2, 16, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 2, 17, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 2, 20, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 3, 0, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 4, 0, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 4, 5, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 4, 6, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 4, 7, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 4, 8, NM_MATCH_SPEC_NEG_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 4, 9, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 5, 0, NM_MATCH_SPEC_NO_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 6, 0, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 6, 5, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 7, 7, NM_MATCH_SPEC_MATCH);
|
|
|
|
|
do_test_match_spec_config ("nm-version-min:1.6,nm-version-min:1.4.6,nm-version-min:1.2.16,except:nm-version:1.4.8", 1, 8, 8, NM_MATCH_SPEC_MATCH);
|
config: allow to enable/disable configuration snippets
Support a new configuration option
[.config]
enable=<ENABLED>
for configuration snippets.
This new [.config] section is only relevant within the snippet itself
and it is not merged into the combined configuration.
Currently only the "enable" key is supported. If the "enable" key is
missing, it obviously defaults to being enabled. It allows snippets
to be skipped from loading. The main configuration "NetworkManager.conf"
cannot be skipped.
<ENABLED> can be a boolean value (false), to skip a configuration
snippet from loading.
It can also be a string to match against the NetworkManager version,
like "enable=nm-version-min:1.1,nm-version-min:1.0.6"
There are several motivations for this:
- the user can disable an entire configuration snippet by toggeling
one entry.
This generalizes the functionality of the global-dns.enable
setting, but in a way that applies to configuration on a per-file
basis.
- for developing, we often switch between different versions of
NetworkManager. Thus, we might want to use different configuration.
E.g. before global-dns options, I want to use "dns=none" and manage
resolv.conf myself. Now, I can use global-dns setting to do that.
That can be achieved with something like the following (not exactly,
it's an example only):
[.config]
enable=nm-version-min:1.1
[main]
dns=default
[global-dns-domain-*]
nameserver=127.0.0.1
Arguably, this would be more awesome, if we would bump our micro devel
version (1.1.0) more often while developing 1.2.0 (*hint*).
- in principle, packages could drop configuration snippets and enable
them based on the NetworkManager version.
- with the "env:" spec, you can enable/disable snippets by configuring
an environment variable. Again, useful for testing and developing.
2015-10-01 10:43:33 +02:00
|
|
|
}
|
|
|
|
|
|
2016-10-02 18:22:50 +02:00
|
|
|
/*****************************************************************************/
|
config: allow to enable/disable configuration snippets
Support a new configuration option
[.config]
enable=<ENABLED>
for configuration snippets.
This new [.config] section is only relevant within the snippet itself
and it is not merged into the combined configuration.
Currently only the "enable" key is supported. If the "enable" key is
missing, it obviously defaults to being enabled. It allows snippets
to be skipped from loading. The main configuration "NetworkManager.conf"
cannot be skipped.
<ENABLED> can be a boolean value (false), to skip a configuration
snippet from loading.
It can also be a string to match against the NetworkManager version,
like "enable=nm-version-min:1.1,nm-version-min:1.0.6"
There are several motivations for this:
- the user can disable an entire configuration snippet by toggeling
one entry.
This generalizes the functionality of the global-dns.enable
setting, but in a way that applies to configuration on a per-file
basis.
- for developing, we often switch between different versions of
NetworkManager. Thus, we might want to use different configuration.
E.g. before global-dns options, I want to use "dns=none" and manage
resolv.conf myself. Now, I can use global-dns setting to do that.
That can be achieved with something like the following (not exactly,
it's an example only):
[.config]
enable=nm-version-min:1.1
[main]
dns=default
[global-dns-domain-*]
nameserver=127.0.0.1
Arguably, this would be more awesome, if we would bump our micro devel
version (1.1.0) more often while developing 1.2.0 (*hint*).
- in principle, packages could drop configuration snippets and enable
them based on the NetworkManager version.
- with the "env:" spec, you can enable/disable snippets by configuring
an environment variable. Again, useful for testing and developing.
2015-10-01 10:43:33 +02:00
|
|
|
|
2015-10-27 10:56:53 +01:00
|
|
|
static void
|
|
|
|
|
test_nm_utils_strbuf_append (void)
|
|
|
|
|
{
|
|
|
|
|
#define BUF_ORIG "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
|
|
|
|
#define STR_ORIG "abcdefghijklmnopqrstuvwxyz"
|
|
|
|
|
int buf_len;
|
|
|
|
|
int rep;
|
2016-02-12 12:34:43 +01:00
|
|
|
char buf[NM_STRLEN (BUF_ORIG) + 1];
|
|
|
|
|
char str[NM_STRLEN (BUF_ORIG) + 1];
|
2015-10-27 10:56:53 +01:00
|
|
|
|
|
|
|
|
for (buf_len = 0; buf_len < 10; buf_len++) {
|
|
|
|
|
for (rep = 0; rep < 50; rep++) {
|
|
|
|
|
const int s_len = nmtst_get_rand_int () % (sizeof (str) - 5);
|
|
|
|
|
char *t_buf;
|
|
|
|
|
gsize t_len;
|
|
|
|
|
int test_mode;
|
|
|
|
|
|
|
|
|
|
strcpy (str, STR_ORIG);
|
|
|
|
|
str[s_len] = '\0';
|
|
|
|
|
|
|
|
|
|
g_assert_cmpint (str[sizeof (str) - 1], ==, '\0');
|
|
|
|
|
g_assert_cmpint (strlen (str), ==, s_len);
|
|
|
|
|
|
|
|
|
|
strcpy (buf, BUF_ORIG);
|
|
|
|
|
|
|
|
|
|
t_buf = buf;
|
|
|
|
|
t_len = buf_len;
|
|
|
|
|
|
2018-09-06 15:20:21 +02:00
|
|
|
test_mode = nmtst_get_rand_int () % 5;
|
2015-10-27 10:56:53 +01:00
|
|
|
|
|
|
|
|
switch (test_mode) {
|
|
|
|
|
case 0:
|
|
|
|
|
if (s_len == 1) {
|
|
|
|
|
nm_utils_strbuf_append_c (&t_buf, &t_len, str[0]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-02-06 14:42:47 +01:00
|
|
|
/* fall through */
|
2015-10-27 10:56:53 +01:00
|
|
|
case 1:
|
|
|
|
|
nm_utils_strbuf_append_str (&t_buf, &t_len, str);
|
|
|
|
|
break;
|
|
|
|
|
case 2:
|
|
|
|
|
if (s_len == 1) {
|
|
|
|
|
nm_utils_strbuf_append (&t_buf, &t_len, "%c", str[0]);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2017-02-06 14:42:47 +01:00
|
|
|
/* fall through */
|
2015-10-27 10:56:53 +01:00
|
|
|
case 3:
|
|
|
|
|
nm_utils_strbuf_append (&t_buf, &t_len, "%s", str);
|
|
|
|
|
break;
|
2018-09-06 15:20:21 +02:00
|
|
|
case 4:
|
|
|
|
|
g_snprintf (t_buf, t_len, "%s", str);
|
|
|
|
|
if ( t_len > 0
|
|
|
|
|
&& strlen (str) >= buf_len
|
|
|
|
|
&& (nmtst_get_rand_int () % 2)) {
|
|
|
|
|
/* the string was truncated by g_snprintf(). That means, at the last position in the
|
|
|
|
|
* buffer is now NUL.
|
|
|
|
|
* Replace the NUL by the actual character, and check that nm_utils_strbuf_seek_end()
|
|
|
|
|
* does the right thing: NUL terminate the buffer and seek past the end of the buffer. */
|
|
|
|
|
g_assert_cmpmem (t_buf, t_len - 1, str, t_len - 1);
|
|
|
|
|
g_assert (t_buf[t_len - 1] == '\0');
|
|
|
|
|
g_assert (str[t_len - 1] != '\0');
|
|
|
|
|
t_buf[t_len - 1] = str[t_len - 1];
|
|
|
|
|
nm_utils_strbuf_seek_end (&t_buf, &t_len);
|
|
|
|
|
g_assert (t_len == 0);
|
|
|
|
|
g_assert (t_buf == &buf[buf_len]);
|
|
|
|
|
g_assert (t_buf[-1] == '\0');
|
|
|
|
|
} else {
|
|
|
|
|
nm_utils_strbuf_seek_end (&t_buf, &t_len);
|
2018-09-07 18:05:10 +02:00
|
|
|
if ( buf_len > 0
|
|
|
|
|
&& strlen (str) + 1 > buf_len) {
|
|
|
|
|
/* the buffer was truncated by g_snprintf() above.
|
2018-09-06 15:20:21 +02:00
|
|
|
*
|
2018-09-07 18:05:10 +02:00
|
|
|
* But nm_utils_strbuf_seek_end() does not recognize that and returns
|
|
|
|
|
* a remaining length of 1.
|
2018-09-06 15:20:21 +02:00
|
|
|
*
|
2018-09-07 18:05:10 +02:00
|
|
|
* Note that other nm_utils_strbuf_append*() functions recognize
|
|
|
|
|
* truncation, and properly set the remaining length to zero.
|
|
|
|
|
* As the assertions below check for the behavior of nm_utils_strbuf_append*(),
|
|
|
|
|
* we assert here that nm_utils_strbuf_seek_end() behaved as expected, and then
|
|
|
|
|
* adjust t_buf/t_len according to the "is-truncated" case. */
|
|
|
|
|
g_assert (t_len == 1);
|
|
|
|
|
g_assert (t_buf == &buf[buf_len - 1]);
|
|
|
|
|
g_assert (t_buf[0] == '\0');
|
|
|
|
|
t_len = 0;
|
|
|
|
|
t_buf++;
|
2018-09-06 15:20:21 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
2015-10-27 10:56:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Assert that the source-buffer is unmodified. */
|
|
|
|
|
g_assert_cmpint (str[s_len], ==, '\0');
|
|
|
|
|
str[s_len] = STR_ORIG[s_len];
|
|
|
|
|
g_assert (!memcmp (str, STR_ORIG, sizeof (str)));
|
|
|
|
|
str[s_len] = '\0';
|
|
|
|
|
|
|
|
|
|
g_assert_cmpint (t_len, >=, 0);
|
|
|
|
|
g_assert_cmpint (t_len, <=, buf_len);
|
|
|
|
|
g_assert (t_buf >= buf);
|
|
|
|
|
|
|
|
|
|
/* Assert what was written to the destination buffer. */
|
|
|
|
|
switch (buf_len) {
|
|
|
|
|
case 0:
|
|
|
|
|
g_assert_cmpint (t_len, ==, 0);
|
|
|
|
|
g_assert (t_buf == buf);
|
|
|
|
|
g_assert (!memcmp (buf, BUF_ORIG, sizeof (buf)));
|
|
|
|
|
break;
|
|
|
|
|
case 1:
|
|
|
|
|
if (s_len == 0) {
|
|
|
|
|
g_assert_cmpint (t_len, ==, 1);
|
|
|
|
|
g_assert (t_buf == buf);
|
|
|
|
|
g_assert (buf[0] == '\0');
|
|
|
|
|
g_assert (!memcmp (&buf[1], &BUF_ORIG[1], sizeof (buf) - 1));
|
|
|
|
|
} else {
|
|
|
|
|
g_assert_cmpint (t_len, ==, 0);
|
|
|
|
|
g_assert (t_buf == &buf[1]);
|
|
|
|
|
g_assert (buf[0] == '\0');
|
|
|
|
|
g_assert (!memcmp (&buf[1], &BUF_ORIG[1], sizeof (buf) - 1));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
if (s_len == 0) {
|
|
|
|
|
g_assert_cmpint (t_len, ==, buf_len);
|
|
|
|
|
g_assert (t_buf == buf);
|
|
|
|
|
g_assert (buf[0] == '\0');
|
|
|
|
|
g_assert (!memcmp (&buf[1], &BUF_ORIG[1], sizeof (buf) - 1));
|
|
|
|
|
} else if (buf_len <= s_len) {
|
|
|
|
|
g_assert_cmpint (t_len, ==, 0);
|
|
|
|
|
g_assert (t_buf == &buf[buf_len]);
|
|
|
|
|
g_assert (!memcmp (buf, STR_ORIG, buf_len - 1));
|
|
|
|
|
g_assert (buf[buf_len - 1] == '\0');
|
|
|
|
|
g_assert (!memcmp (&buf[buf_len], &BUF_ORIG[buf_len], sizeof (buf) - buf_len));
|
|
|
|
|
} else {
|
|
|
|
|
g_assert_cmpint (t_len, >, 0);
|
|
|
|
|
g_assert_cmpint (buf_len - t_len, ==, s_len);
|
|
|
|
|
g_assert_cmpint (strlen (buf), ==, s_len);
|
|
|
|
|
g_assert (t_buf == &buf[s_len]);
|
|
|
|
|
g_assert (!memcmp (buf, STR_ORIG, s_len));
|
|
|
|
|
g_assert (buf[s_len] == '\0');
|
|
|
|
|
g_assert (!memcmp (&buf[s_len + 1], &BUF_ORIG[s_len + 1], sizeof (buf) - s_len - 1));
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-09 11:17:36 +01:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_duplicate_decl_specifier (void)
|
|
|
|
|
{
|
2017-12-18 08:36:51 +01:00
|
|
|
/* We're intentionally assigning values to static arrays v_const
|
|
|
|
|
* and v_result without using it afterwards just so that valgrind
|
|
|
|
|
* doesn't complain about the leak. */
|
|
|
|
|
NM_PRAGMA_WARNING_DISABLE("-Wunused-but-set-variable")
|
|
|
|
|
|
2016-03-09 11:17:36 +01:00
|
|
|
/* have some static variables, so that the result is certainly not optimized out. */
|
|
|
|
|
static const int v_const[1] = { 1 };
|
|
|
|
|
static int v_result[1] = { };
|
|
|
|
|
const const int v2 = 3;
|
|
|
|
|
|
|
|
|
|
/* Test that we don't get a compiler warning about duplicate const specifier.
|
|
|
|
|
* C99 allows that and it can easily happen in macros. */
|
|
|
|
|
|
|
|
|
|
#define TEST_MAX(a, b) \
|
|
|
|
|
({ \
|
|
|
|
|
const typeof(a) _a = (a); \
|
|
|
|
|
const typeof(b) _b = (b); \
|
|
|
|
|
\
|
|
|
|
|
(_a > _b ? _a : _b); \
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
v_result[0] = TEST_MAX (v_const[0], nmtst_get_rand_int () % 5) + v2;
|
2017-12-18 08:36:51 +01:00
|
|
|
|
|
|
|
|
NM_PRAGMA_WARNING_REENABLE
|
2016-03-09 11:17:36 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-03 22:07:38 +02:00
|
|
|
static void
|
|
|
|
|
test_reverse_dns_ip4 (void)
|
|
|
|
|
{
|
|
|
|
|
guint32 addr;
|
|
|
|
|
GPtrArray *domains = g_ptr_array_new_full (8, g_free);
|
|
|
|
|
|
|
|
|
|
inet_pton (AF_INET, "7.2.3.0", &addr);
|
|
|
|
|
nm_utils_get_reverse_dns_domains_ip4 (addr, 27, domains);
|
|
|
|
|
g_assert_cmpuint (domains->len, ==, 32);
|
|
|
|
|
g_assert_cmpstr (domains->pdata[0], ==, "0.3.2.7.in-addr.arpa");
|
|
|
|
|
g_assert_cmpstr (domains->pdata[31], ==, "31.3.2.7.in-addr.arpa");
|
|
|
|
|
|
|
|
|
|
g_ptr_array_set_size (domains, 0);
|
|
|
|
|
|
|
|
|
|
inet_pton (AF_INET, "10.155.16.0", &addr);
|
|
|
|
|
nm_utils_get_reverse_dns_domains_ip4 (addr, 22, domains);
|
|
|
|
|
g_assert_cmpuint (domains->len, ==, 4);
|
|
|
|
|
g_assert_cmpstr (domains->pdata[0], ==, "16.155.10.in-addr.arpa");
|
|
|
|
|
g_assert_cmpstr (domains->pdata[1], ==, "17.155.10.in-addr.arpa");
|
|
|
|
|
g_assert_cmpstr (domains->pdata[2], ==, "18.155.10.in-addr.arpa");
|
|
|
|
|
g_assert_cmpstr (domains->pdata[3], ==, "19.155.10.in-addr.arpa");
|
|
|
|
|
|
|
|
|
|
g_ptr_array_set_size (domains, 0);
|
|
|
|
|
|
|
|
|
|
inet_pton (AF_INET, "4.5.6.7", &addr);
|
|
|
|
|
nm_utils_get_reverse_dns_domains_ip4 (addr, 32, domains);
|
|
|
|
|
g_assert_cmpuint (domains->len, ==, 1);
|
|
|
|
|
g_assert_cmpstr (domains->pdata[0], ==, "7.6.5.4.in-addr.arpa");
|
|
|
|
|
|
|
|
|
|
g_ptr_array_set_size (domains, 0);
|
|
|
|
|
|
|
|
|
|
inet_pton (AF_INET, "4.5.6.7", &addr);
|
|
|
|
|
nm_utils_get_reverse_dns_domains_ip4 (addr, 8, domains);
|
|
|
|
|
g_assert_cmpuint (domains->len, ==, 1);
|
|
|
|
|
g_assert_cmpstr (domains->pdata[0], ==, "4.in-addr.arpa");
|
|
|
|
|
|
|
|
|
|
g_ptr_array_set_size (domains, 0);
|
|
|
|
|
|
|
|
|
|
inet_pton (AF_INET, "4.180.6.7", &addr);
|
|
|
|
|
nm_utils_get_reverse_dns_domains_ip4 (addr, 9, domains);
|
|
|
|
|
g_assert_cmpuint (domains->len, ==, 128);
|
|
|
|
|
g_assert_cmpstr (domains->pdata[0], ==, "128.4.in-addr.arpa");
|
|
|
|
|
g_assert_cmpstr (domains->pdata[1], ==, "129.4.in-addr.arpa");
|
|
|
|
|
g_assert_cmpstr (domains->pdata[127], ==, "255.4.in-addr.arpa");
|
|
|
|
|
|
|
|
|
|
g_ptr_array_set_size (domains, 0);
|
|
|
|
|
|
|
|
|
|
inet_pton (AF_INET, "172.16.0.0", &addr);
|
|
|
|
|
nm_utils_get_reverse_dns_domains_ip4 (addr, 12, domains);
|
|
|
|
|
g_assert_cmpuint (domains->len, ==, 16);
|
|
|
|
|
g_assert_cmpstr (domains->pdata[0], ==, "16.172.in-addr.arpa");
|
|
|
|
|
g_assert_cmpstr (domains->pdata[1], ==, "17.172.in-addr.arpa");
|
|
|
|
|
g_assert_cmpstr (domains->pdata[14], ==, "30.172.in-addr.arpa");
|
|
|
|
|
g_assert_cmpstr (domains->pdata[15], ==, "31.172.in-addr.arpa");
|
|
|
|
|
|
|
|
|
|
g_ptr_array_set_size (domains, 0);
|
|
|
|
|
|
|
|
|
|
inet_pton (AF_INET, "1.2.3.4", &addr);
|
|
|
|
|
nm_utils_get_reverse_dns_domains_ip4 (addr, 0, domains);
|
|
|
|
|
g_assert_cmpuint (domains->len, ==, 0);
|
|
|
|
|
|
|
|
|
|
g_ptr_array_unref (domains);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-03 22:07:42 +02:00
|
|
|
static void
|
|
|
|
|
test_reverse_dns_ip6 (void)
|
|
|
|
|
{
|
|
|
|
|
struct in6_addr addr;
|
|
|
|
|
GPtrArray *domains = g_ptr_array_new_full (8, g_free);
|
|
|
|
|
|
|
|
|
|
inet_pton (AF_INET6, "1234::56", &addr);
|
|
|
|
|
nm_utils_get_reverse_dns_domains_ip6 (&addr, 16, domains);
|
|
|
|
|
g_assert_cmpuint (domains->len, ==, 1);
|
|
|
|
|
g_assert_cmpstr (domains->pdata[0], ==, "4.3.2.1.ip6.arpa");
|
|
|
|
|
|
|
|
|
|
g_ptr_array_set_size (domains, 0);
|
|
|
|
|
|
|
|
|
|
inet_pton (AF_INET6, "1234::56", &addr);
|
|
|
|
|
nm_utils_get_reverse_dns_domains_ip6 (&addr, 17, domains);
|
|
|
|
|
g_assert_cmpuint (domains->len, ==, 8);
|
|
|
|
|
g_assert_cmpstr (domains->pdata[0], ==, "0.4.3.2.1.ip6.arpa");
|
|
|
|
|
g_assert_cmpstr (domains->pdata[1], ==, "1.4.3.2.1.ip6.arpa");
|
|
|
|
|
g_assert_cmpstr (domains->pdata[7], ==, "7.4.3.2.1.ip6.arpa");
|
|
|
|
|
|
|
|
|
|
g_ptr_array_set_size (domains, 0);
|
|
|
|
|
|
|
|
|
|
inet_pton (AF_INET6, "2001:db8::", &addr);
|
|
|
|
|
nm_utils_get_reverse_dns_domains_ip6 (&addr, 29, domains);
|
|
|
|
|
g_assert_cmpuint (domains->len, ==, 8);
|
|
|
|
|
g_assert_cmpstr (domains->pdata[0], ==, "8.b.d.0.1.0.0.2.ip6.arpa");
|
|
|
|
|
g_assert_cmpstr (domains->pdata[1], ==, "9.b.d.0.1.0.0.2.ip6.arpa");
|
|
|
|
|
g_assert_cmpstr (domains->pdata[7], ==, "f.b.d.0.1.0.0.2.ip6.arpa");
|
|
|
|
|
|
|
|
|
|
g_ptr_array_set_size (domains, 0);
|
|
|
|
|
|
|
|
|
|
inet_pton (AF_INET6, "0123:4567:89ab:cdef::", &addr);
|
|
|
|
|
nm_utils_get_reverse_dns_domains_ip6 (&addr, 63, domains);
|
|
|
|
|
g_assert_cmpuint (domains->len, ==, 2);
|
|
|
|
|
g_assert_cmpstr (domains->pdata[0], ==, "e.e.d.c.b.a.9.8.7.6.5.4.3.2.1.0.ip6.arpa");
|
|
|
|
|
g_assert_cmpstr (domains->pdata[1], ==, "f.e.d.c.b.a.9.8.7.6.5.4.3.2.1.0.ip6.arpa");
|
|
|
|
|
|
|
|
|
|
g_ptr_array_set_size (domains, 0);
|
|
|
|
|
|
|
|
|
|
inet_pton (AF_INET6, "fec0:1234:5678:9ab0::", &addr);
|
|
|
|
|
nm_utils_get_reverse_dns_domains_ip6 (&addr, 61, domains);
|
|
|
|
|
g_assert_cmpuint (domains->len, ==, 8);
|
|
|
|
|
g_assert_cmpstr (domains->pdata[0], ==, "0.b.a.9.8.7.6.5.4.3.2.1.0.c.e.f.ip6.arpa");
|
|
|
|
|
g_assert_cmpstr (domains->pdata[7], ==, "7.b.a.9.8.7.6.5.4.3.2.1.0.c.e.f.ip6.arpa");
|
|
|
|
|
|
|
|
|
|
g_ptr_array_set_size (domains, 0);
|
|
|
|
|
|
|
|
|
|
inet_pton (AF_INET6, "0123:4567:89ab:cdee::", &addr);
|
|
|
|
|
nm_utils_get_reverse_dns_domains_ip6 (&addr, 0, domains);
|
|
|
|
|
g_assert_cmpuint (domains->len, ==, 0);
|
|
|
|
|
|
|
|
|
|
g_ptr_array_unref (domains);
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-03 22:07:38 +02:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2016-12-18 13:54:26 +01:00
|
|
|
static void
|
|
|
|
|
do_test_stable_id_parse (const char *stable_id,
|
|
|
|
|
NMUtilsStableType expected_stable_type,
|
|
|
|
|
const char *expected_generated)
|
|
|
|
|
{
|
|
|
|
|
gs_free char *generated = NULL;
|
|
|
|
|
NMUtilsStableType stable_type;
|
|
|
|
|
|
|
|
|
|
if (expected_stable_type == NM_UTILS_STABLE_TYPE_GENERATED)
|
|
|
|
|
g_assert (expected_generated);
|
|
|
|
|
else
|
|
|
|
|
g_assert (!expected_generated);
|
|
|
|
|
|
|
|
|
|
if (expected_stable_type == NM_UTILS_STABLE_TYPE_UUID)
|
|
|
|
|
g_assert (!stable_id);
|
|
|
|
|
else
|
|
|
|
|
g_assert (stable_id);
|
|
|
|
|
|
2018-05-22 18:35:43 +02:00
|
|
|
stable_type = nm_utils_stable_id_parse (stable_id, "_DEVICE", "_BOOT", "_CONNECTION", &generated);
|
2016-12-18 13:54:26 +01:00
|
|
|
|
|
|
|
|
g_assert_cmpint (expected_stable_type, ==, stable_type);
|
|
|
|
|
|
|
|
|
|
if (stable_type == NM_UTILS_STABLE_TYPE_GENERATED) {
|
|
|
|
|
g_assert_cmpstr (expected_generated, ==, generated);
|
|
|
|
|
g_assert (generated);
|
|
|
|
|
} else
|
|
|
|
|
g_assert (!generated);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_stable_id_parse (void)
|
|
|
|
|
{
|
|
|
|
|
#define _parse_stable_id(stable_id) do_test_stable_id_parse (""stable_id"", NM_UTILS_STABLE_TYPE_STABLE_ID, NULL)
|
|
|
|
|
#define _parse_generated(stable_id, expected_generated) do_test_stable_id_parse (""stable_id"", NM_UTILS_STABLE_TYPE_GENERATED, ""expected_generated"")
|
|
|
|
|
#define _parse_random(stable_id) do_test_stable_id_parse (""stable_id"", NM_UTILS_STABLE_TYPE_RANDOM, NULL)
|
|
|
|
|
do_test_stable_id_parse (NULL, NM_UTILS_STABLE_TYPE_UUID, NULL);
|
|
|
|
|
_parse_stable_id ("");
|
|
|
|
|
_parse_stable_id ("a");
|
|
|
|
|
_parse_stable_id ("a$");
|
|
|
|
|
_parse_stable_id ("a$x");
|
|
|
|
|
_parse_stable_id (" ${a$x");
|
|
|
|
|
_parse_stable_id ("${");
|
|
|
|
|
_parse_stable_id ("${=");
|
|
|
|
|
_parse_stable_id ("${a");
|
|
|
|
|
_parse_stable_id ("${a$x");
|
|
|
|
|
_parse_stable_id ("a$$");
|
|
|
|
|
_parse_stable_id ("a$$x");
|
|
|
|
|
_parse_stable_id ("a$${CONNECTION}");
|
|
|
|
|
_parse_stable_id ("a$${CONNECTION}x");
|
|
|
|
|
_parse_generated ("${CONNECTION}", "${CONNECTION}=11{_CONNECTION}");
|
|
|
|
|
_parse_generated ("${${CONNECTION}", "${${CONNECTION}=11{_CONNECTION}");
|
|
|
|
|
_parse_generated ("${CONNECTION}x", "${CONNECTION}=11{_CONNECTION}x");
|
|
|
|
|
_parse_generated ("x${CONNECTION}", "x${CONNECTION}=11{_CONNECTION}");
|
|
|
|
|
_parse_generated ("${BOOT}x", "${BOOT}=5{_BOOT}x");
|
|
|
|
|
_parse_generated ("x${BOOT}", "x${BOOT}=5{_BOOT}");
|
|
|
|
|
_parse_generated ("x${BOOT}${CONNECTION}", "x${BOOT}=5{_BOOT}${CONNECTION}=11{_CONNECTION}");
|
|
|
|
|
_parse_generated ("xX${BOOT}yY${CONNECTION}zZ", "xX${BOOT}=5{_BOOT}yY${CONNECTION}=11{_CONNECTION}zZ");
|
|
|
|
|
_parse_random ("${RANDOM}");
|
|
|
|
|
_parse_random (" ${RANDOM}");
|
|
|
|
|
_parse_random ("${BOOT}${RANDOM}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_stable_id_generated_complete (void)
|
|
|
|
|
{
|
|
|
|
|
#define ASSERT(str, expected) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
gs_free char *_s = NULL; \
|
|
|
|
|
\
|
|
|
|
|
_s = nm_utils_stable_id_generated_complete ((str)); \
|
|
|
|
|
g_assert_cmpstr ((expected), ==, _s); \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
|
|
ASSERT ("", "2jmj7l5rSw0yVb/vlWAYkK/YBwk");
|
|
|
|
|
ASSERT ("a", "hvfkN/qlp/zhXR3cuerq6jd2Z7g");
|
|
|
|
|
ASSERT ("password", "W6ph5Mm5Pz8GgiULbPgzG37mj9g");
|
|
|
|
|
#undef ASSERT
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2017-03-23 16:01:07 +01:00
|
|
|
static void
|
2017-03-24 11:27:41 +01:00
|
|
|
test_nm_utils_exp10 (void)
|
2017-03-23 16:01:07 +01:00
|
|
|
{
|
|
|
|
|
#define FLOAT_CMP(a, b) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
double _a = (a); \
|
|
|
|
|
double _b = (b); \
|
|
|
|
|
\
|
|
|
|
|
if (isinf (_b)) \
|
|
|
|
|
g_assert (isinf (_a)); \
|
|
|
|
|
else if (_b >= 0.0 && _b <= 0.0) \
|
2017-03-28 13:33:27 +02:00
|
|
|
g_assert (_a - _b < G_MINFLOAT); \
|
2017-03-23 16:01:07 +01:00
|
|
|
else { \
|
|
|
|
|
double _x = (_a) - (_b); \
|
|
|
|
|
g_assert (_b > 0.0); \
|
|
|
|
|
if (_x < 0.0) \
|
|
|
|
|
_x = -_x; \
|
|
|
|
|
g_assert (_x / _b < 1E-10); \
|
|
|
|
|
} \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
2017-03-24 11:27:41 +01:00
|
|
|
FLOAT_CMP (nm_utils_exp10 (G_MININT16), 0.0);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (-310), 0.0);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (-309), 0.0);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (-308), 1e-308);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (-307), 1e-307);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (-1), 1e-1);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (-2), 1e-2);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (0), 1e0);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (1), 1e1);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (2), 1e2);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (3), 1e3);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (4), 1e4);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (5), 1e5);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (6), 1e6);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (7), 1e7);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (122), 1e122);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (200), 1e200);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (307), 1e307);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (308), 1e308);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (309), INFINITY);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (310), INFINITY);
|
|
|
|
|
FLOAT_CMP (nm_utils_exp10 (G_MAXINT16), INFINITY);
|
2017-03-23 16:01:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2018-10-19 10:21:53 +02:00
|
|
|
static void
|
|
|
|
|
test_utils_file_is_in_path (void)
|
|
|
|
|
{
|
|
|
|
|
g_assert (!nm_utils_file_is_in_path ("/", "/"));
|
|
|
|
|
g_assert (!nm_utils_file_is_in_path ("//", "/"));
|
|
|
|
|
g_assert (!nm_utils_file_is_in_path ("/a/", "/"));
|
|
|
|
|
g_assert ( nm_utils_file_is_in_path ("/a", "/"));
|
|
|
|
|
g_assert ( nm_utils_file_is_in_path ("///a", "/"));
|
|
|
|
|
g_assert ( nm_utils_file_is_in_path ("//b/a", "/b//"));
|
|
|
|
|
g_assert ( nm_utils_file_is_in_path ("//b///a", "/b//"));
|
|
|
|
|
g_assert (!nm_utils_file_is_in_path ("//b///a/", "/b//"));
|
|
|
|
|
g_assert (!nm_utils_file_is_in_path ("//b///a/", "/b/a/"));
|
|
|
|
|
g_assert (!nm_utils_file_is_in_path ("//b///a", "/b/a/"));
|
|
|
|
|
g_assert ( nm_utils_file_is_in_path ("//b///a/.", "/b/a/"));
|
|
|
|
|
g_assert ( nm_utils_file_is_in_path ("//b///a/..", "/b/a/"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2018-11-12 10:44:19 +01:00
|
|
|
#define _TEST_RC(searches, nameservers, options, expected) \
|
|
|
|
|
G_STMT_START { \
|
|
|
|
|
const char *const*const _searches = (searches); \
|
|
|
|
|
const char *const*const _nameservers = (nameservers); \
|
|
|
|
|
const char *const*const _options = (options); \
|
|
|
|
|
gs_free char *_content = NULL; \
|
|
|
|
|
\
|
|
|
|
|
_content = nmtst_dns_create_resolv_conf (_searches, _nameservers, _options); \
|
|
|
|
|
g_assert_cmpstr (_content, ==, expected); \
|
|
|
|
|
} G_STMT_END
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
|
test_dns_create_resolv_conf (void)
|
|
|
|
|
{
|
|
|
|
|
_TEST_RC (NM_MAKE_STRV ("a"),
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
"# Generated by NetworkManager\n"
|
|
|
|
|
"search a\n"
|
|
|
|
|
"");
|
|
|
|
|
|
|
|
|
|
_TEST_RC (NM_MAKE_STRV ("a", "b.com"),
|
|
|
|
|
NM_MAKE_STRV ("192.168.55.1", "192.168.56.1"),
|
|
|
|
|
NM_MAKE_STRV ("opt1", "opt2"),
|
|
|
|
|
"# Generated by NetworkManager\n"
|
|
|
|
|
"search a b.com\n"
|
|
|
|
|
"nameserver 192.168.55.1\n"
|
|
|
|
|
"nameserver 192.168.56.1\n"
|
|
|
|
|
"options opt1 opt2\n"
|
|
|
|
|
"");
|
|
|
|
|
|
|
|
|
|
_TEST_RC (NM_MAKE_STRV ("a2x456789.b2x456789.c2x456789.d2x456789.e2x456789.f2x456789.g2x456789.h2x456789.i2x456789.j2x4567890",
|
|
|
|
|
"a2y456789.b2y456789.c2y456789.d2y456789.e2y456789.f2y456789.g2y456789.h2y456789.i2y456789.j2y4567890",
|
|
|
|
|
"a2z456789.b2z456789.c2z456789.d2z456789.e2z456789.f2z456789.g2z456789.h2z456789.i2z456789.j2z4567890"),
|
|
|
|
|
NULL,
|
|
|
|
|
NULL,
|
|
|
|
|
"# Generated by NetworkManager\n"
|
2018-11-12 10:34:54 +01:00
|
|
|
"search a2x456789.b2x456789.c2x456789.d2x456789.e2x456789.f2x456789.g2x456789.h2x456789.i2x456789.j2x4567890 a2y456789.b2y456789.c2y456789.d2y456789.e2y456789.f2y456789.g2y456789.h2y456789.i2y456789.j2y4567890 a2z456789.b2z456789.c2z456789.d2z456789.e2z456789.f2z456789.g2z456789.h2z456789.i2z456789.j2z4567890\n"
|
2018-11-12 10:44:19 +01:00
|
|
|
"");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
core: refactor loading machine-id and cache it
Previously, whenever we needed /etc/machine-id we would re-load it
from file. The are 3 downsides of that:
- the smallest downside is the runtime overhead of repeatedly
reading the file and parse it.
- as we read it multiple times, it may change anytime. Most
code in NetworkManager does not expect or handle a change of
the machine-id.
Generally, the admin should make sure that the machine-id is properly
initialized before NetworkManager starts, and not change it. As such,
a change of the machine-id should never happen in practice.
But if it would change, we would get odd behaviors. Note for example
how generate_duid_from_machine_id() already cached the generated DUID
and only read it once.
It's better to pick the machine-id once, and rely to use the same
one for the remainder of the program.
If the admin wants to change the machine-id, NetworkManager must be
restarted as well (in case the admin cares).
Also, as we now only load it once, it makes sense to log an error
(once) when we fail to read the machine-id.
- previously, loading the machine-id could fail each time. And we
have to somehow handle that error. It seems, the best thing what we
anyway can do, is to log an error once and continue with a fake
machine-id. Here we add a fake machine-id based on the secret-key
or the boot-id. Now obtaining a machine-id can no longer fail
and error handling is no longer necessary.
Also, ensure that a machine-id of all zeros is not valid.
Technically, a machine-id is not an RFC 4122 UUID. But it's
the same size, so we also use NMUuid data structure for it.
While at it, also refactor caching of the boot-id and the secret
key. In particular, fix the thread-safety of the double-checked
locking implementations.
2018-10-30 14:07:11 +01:00
|
|
|
static void
|
|
|
|
|
test_machine_id_read (void)
|
|
|
|
|
{
|
|
|
|
|
NMUuid machine_id_sd;
|
|
|
|
|
const NMUuid *machine_id;
|
|
|
|
|
char machine_id_str[33];
|
|
|
|
|
gpointer logstate;
|
|
|
|
|
|
|
|
|
|
logstate = nmtst_logging_disable (FALSE);
|
|
|
|
|
/* If you run this test as root, without a valid /etc/machine-id,
|
2018-11-13 18:50:01 +01:00
|
|
|
* the code will try to get the secret-key. That is a bit ugly,
|
|
|
|
|
* but no real problem. */
|
core: refactor loading machine-id and cache it
Previously, whenever we needed /etc/machine-id we would re-load it
from file. The are 3 downsides of that:
- the smallest downside is the runtime overhead of repeatedly
reading the file and parse it.
- as we read it multiple times, it may change anytime. Most
code in NetworkManager does not expect or handle a change of
the machine-id.
Generally, the admin should make sure that the machine-id is properly
initialized before NetworkManager starts, and not change it. As such,
a change of the machine-id should never happen in practice.
But if it would change, we would get odd behaviors. Note for example
how generate_duid_from_machine_id() already cached the generated DUID
and only read it once.
It's better to pick the machine-id once, and rely to use the same
one for the remainder of the program.
If the admin wants to change the machine-id, NetworkManager must be
restarted as well (in case the admin cares).
Also, as we now only load it once, it makes sense to log an error
(once) when we fail to read the machine-id.
- previously, loading the machine-id could fail each time. And we
have to somehow handle that error. It seems, the best thing what we
anyway can do, is to log an error once and continue with a fake
machine-id. Here we add a fake machine-id based on the secret-key
or the boot-id. Now obtaining a machine-id can no longer fail
and error handling is no longer necessary.
Also, ensure that a machine-id of all zeros is not valid.
Technically, a machine-id is not an RFC 4122 UUID. But it's
the same size, so we also use NMUuid data structure for it.
While at it, also refactor caching of the boot-id and the secret
key. In particular, fix the thread-safety of the double-checked
locking implementations.
2018-10-30 14:07:11 +01:00
|
|
|
machine_id = nm_utils_machine_id_bin ();
|
|
|
|
|
nmtst_logging_reenable (logstate);
|
|
|
|
|
|
|
|
|
|
g_assert (machine_id);
|
|
|
|
|
g_assert (_nm_utils_bin2hexstr_full (machine_id,
|
|
|
|
|
sizeof (NMUuid),
|
|
|
|
|
'\0',
|
|
|
|
|
FALSE,
|
|
|
|
|
machine_id_str) == machine_id_str);
|
|
|
|
|
g_assert (strlen (machine_id_str) == 32);
|
|
|
|
|
g_assert_cmpstr (machine_id_str, ==, nm_utils_machine_id_str ());
|
|
|
|
|
|
|
|
|
|
/* double check with systemd's implementation... */
|
|
|
|
|
if (!nm_sd_utils_id128_get_machine (&machine_id_sd)) {
|
|
|
|
|
/* if systemd failed to read /etc/machine-id, the file likely
|
|
|
|
|
* is invalid. Our machine-id is fake, and we have nothing to
|
|
|
|
|
* compare against. */
|
|
|
|
|
|
|
|
|
|
/* NOTE: this test will fail, if you don't have /etc/machine-id,
|
|
|
|
|
* but a valid "LOCALSTATEDIR/lib/dbus/machine-id" file.
|
|
|
|
|
* Just don't do that. */
|
|
|
|
|
g_assert (nm_utils_machine_id_is_fake ());
|
|
|
|
|
} else {
|
|
|
|
|
g_assert (!nm_utils_machine_id_is_fake ());
|
|
|
|
|
g_assert_cmpmem (&machine_id_sd, sizeof (NMUuid), machine_id, 16);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
dhcp: test systemd's default DHCP client identifier generation
Internal DHCP client generates a default client ID. For one,
we should ensure that this algorithm does not change without
us noticing, for example, when upgrading systemd code. Add
a test, that the generation algorithm works as we expect.
Also note, that the generation algorithm uses siphash24().
That means, siphash24() implementation also must not change
in the future, to ensure the client ID doesn't change. As we
patch systemd sources to use shared/c-siphash, this is not
obviously the case. Luckily c-siphash and systemd's siphash24 do
agree, so all is good. The test is here to ensure that.
Also, previously the generation algorithm is not exposed as a
function, sd_dhcp_client will just generate a client-id when
it needs it. However, later we want to know (and set) the client
id before starting DHCP and not leave it unspecified to an
implementation detail.
This patch only adds a unit-test for the existing DHCP client
ID generation to have something for comparison. In the next
commit this will change further.
2018-10-26 17:32:59 +02:00
|
|
|
static void
|
|
|
|
|
test_nm_sd_utils_generate_default_dhcp_client_id (gconstpointer test_data)
|
|
|
|
|
{
|
|
|
|
|
const guint8 HASH_KEY[16] = { 0x80, 0x11, 0x8c, 0xc2, 0xfe, 0x4a, 0x03, 0xee, 0x3e, 0xd6, 0x0c, 0x6f, 0x36, 0x39, 0x14, 0x09 };
|
|
|
|
|
/* We run the test twice with two ifindexes.
|
|
|
|
|
*
|
|
|
|
|
* One is "1", which we expect to exist and having a name "lo".
|
|
|
|
|
* The other is a random number, which we expect not to exist.
|
|
|
|
|
*
|
|
|
|
|
* Regardless of whether the ifindex actually exists, the tests are
|
|
|
|
|
* supposed to pass. However, when our expectations are not met, we
|
|
|
|
|
* silently miss test cases. */
|
|
|
|
|
const int IFINDEX = GPOINTER_TO_INT (test_data)
|
|
|
|
|
? 1
|
|
|
|
|
: (int) (nmtst_get_rand_int () % 10000);
|
|
|
|
|
const guint8 mac_addr[ETH_ALEN] = { 0x20, 0xaf, 0x51, 0x42, 0x29, 0x05 };
|
|
|
|
|
const guint16 duid_type_en = htons (2);
|
|
|
|
|
const guint32 systemd_pen = htonl (43793);
|
|
|
|
|
guint32 iaid_mac;
|
|
|
|
|
guint32 iaid_ifname;
|
|
|
|
|
gs_unref_bytes GBytes *client_id = NULL;
|
|
|
|
|
char ifname_buf[IFNAMSIZ];
|
|
|
|
|
const char *ifname;
|
|
|
|
|
gboolean has_ifindex;
|
|
|
|
|
gint64 u64;
|
|
|
|
|
const guint8 *cid;
|
|
|
|
|
const NMUuid *machine_id;
|
|
|
|
|
|
|
|
|
|
/* see whether IFINDEX exists. */
|
|
|
|
|
if (if_indextoname (IFINDEX, ifname_buf)) {
|
|
|
|
|
ifname = ifname_buf;
|
|
|
|
|
has_ifindex = TRUE;
|
|
|
|
|
} else {
|
|
|
|
|
ifname = "lo";
|
|
|
|
|
has_ifindex = FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* generate the iaid based on the ifname and assert for expected
|
|
|
|
|
* values.
|
|
|
|
|
*
|
|
|
|
|
* We often expect that the interface name is "lo". Hence, assert
|
|
|
|
|
* for the expected hash values explicitly.
|
|
|
|
|
*
|
|
|
|
|
* Note that the iaid generated by dhcp_identifier_set_iaid() is
|
|
|
|
|
* in native endianness (https://github.com/systemd/systemd/pull/10614). */
|
|
|
|
|
u64 = c_siphash_hash (HASH_KEY, (const guint8 *) ifname, strlen (ifname));
|
|
|
|
|
if (nm_streq (ifname, "lo"))
|
|
|
|
|
g_assert_cmpint (u64, ==, 0x7297085c2b12c911llu);
|
|
|
|
|
iaid_ifname = bswap_32 ((u64 & 0xffffffffu) ^ (u64 >> 32));
|
|
|
|
|
if (nm_streq (ifname, "lo"))
|
|
|
|
|
g_assert_cmpint (iaid_ifname, ==, 0x4dc18559u);
|
|
|
|
|
|
|
|
|
|
/* generate the iaid based on the hard-coded MAC address */
|
|
|
|
|
u64 = c_siphash_hash (HASH_KEY, mac_addr, sizeof (mac_addr));
|
|
|
|
|
g_assert_cmpint (u64, ==, 0x1f3d1d8d15de49dcllu);
|
|
|
|
|
iaid_mac = bswap_32 ((u64 & 0xffffffffu) ^ (u64 >> 32));
|
|
|
|
|
g_assert_cmpint (iaid_mac, ==, 0x5154e30au);
|
|
|
|
|
|
|
|
|
|
/* as it is, nm_sd_utils_generate_default_dhcp_client_id() resolves the ifname (based on the
|
|
|
|
|
* ifindex) and loads /etc/machine-id. Maybe the code should be refactored, to accept
|
|
|
|
|
* such external input as arguments (to ease testing).
|
|
|
|
|
*
|
|
|
|
|
* Instead, we just duplicate the steps here, which are don't internally by the
|
|
|
|
|
* function. Hey, it's a test. Let's re-implement what the code does here. */
|
|
|
|
|
client_id = nm_sd_utils_generate_default_dhcp_client_id (IFINDEX, mac_addr, sizeof (mac_addr));
|
|
|
|
|
|
|
|
|
|
if (!client_id) {
|
|
|
|
|
/* the only reason why this can fail, is because /etc/machine-id is invalid. */
|
|
|
|
|
if (!g_file_test ("/etc/machine-id", G_FILE_TEST_EXISTS)) {
|
|
|
|
|
g_test_skip ("no /etc/machine-id");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
g_assert_not_reached ();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
g_assert_cmpint (g_bytes_get_size (client_id), ==, 19);
|
|
|
|
|
cid = g_bytes_get_data (client_id, NULL);
|
|
|
|
|
|
|
|
|
|
g_assert_cmpint (cid[0], ==, 255);
|
|
|
|
|
if (has_ifindex)
|
|
|
|
|
g_assert_cmpmem (&cid[1], 4, &iaid_ifname, sizeof (iaid_ifname));
|
|
|
|
|
else
|
|
|
|
|
g_assert_cmpmem (&cid[1], 4, &iaid_mac, sizeof (iaid_mac));
|
|
|
|
|
g_assert_cmpmem (&cid[5], 2, &duid_type_en, sizeof (duid_type_en));
|
|
|
|
|
g_assert_cmpmem (&cid[7], 4, &systemd_pen, sizeof (systemd_pen));
|
|
|
|
|
|
|
|
|
|
machine_id = nm_utils_machine_id_bin ();
|
|
|
|
|
u64 = htole64 (c_siphash_hash (HASH_KEY, (const guint8 *) machine_id, sizeof (*machine_id)));
|
|
|
|
|
g_assert_cmpmem (&cid[11], 8, &u64, sizeof (u64));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
2014-07-10 10:40:47 +02:00
|
|
|
NMTST_DEFINE ();
|
|
|
|
|
|
2014-01-21 13:07:06 +01:00
|
|
|
int
|
|
|
|
|
main (int argc, char **argv)
|
|
|
|
|
{
|
2014-07-10 10:40:47 +02:00
|
|
|
nmtst_init_with_logging (&argc, &argv, NULL, "ALL");
|
2014-01-21 13:07:06 +01:00
|
|
|
|
2015-10-27 10:56:53 +01:00
|
|
|
g_test_add_func ("/general/nm_utils_strbuf_append", test_nm_utils_strbuf_append);
|
|
|
|
|
|
2014-02-13 18:12:41 +01:00
|
|
|
g_test_add_func ("/general/nm_utils_ip6_address_clear_host_address", test_nm_utils_ip6_address_clear_host_address);
|
2016-04-06 17:33:19 +02:00
|
|
|
g_test_add_func ("/general/nm_utils_ip6_address_same_prefix", test_nm_utils_ip6_address_same_prefix);
|
2014-02-26 09:51:09 +01:00
|
|
|
g_test_add_func ("/general/nm_utils_log_connection_diff", test_nm_utils_log_connection_diff);
|
2014-01-21 13:07:06 +01:00
|
|
|
|
2017-10-23 14:24:28 +02:00
|
|
|
g_test_add_func ("/general/nm_utils_sysctl_ip_conf_path", test_nm_utils_sysctl_ip_conf_path);
|
|
|
|
|
|
2017-03-24 11:27:41 +01:00
|
|
|
g_test_add_func ("/general/exp10", test_nm_utils_exp10);
|
2017-03-23 16:01:07 +01:00
|
|
|
|
2014-02-25 17:44:07 -06:00
|
|
|
g_test_add_func ("/general/connection-match/basic", test_connection_match_basic);
|
|
|
|
|
g_test_add_func ("/general/connection-match/ip6-method", test_connection_match_ip6_method);
|
2014-03-07 10:33:12 +01:00
|
|
|
g_test_add_func ("/general/connection-match/ip6-method-ignore", test_connection_match_ip6_method_ignore);
|
2014-05-29 16:36:24 +02:00
|
|
|
g_test_add_func ("/general/connection-match/ip6-method-ignore-auto", test_connection_match_ip6_method_ignore_auto);
|
2014-02-25 17:56:06 -06:00
|
|
|
g_test_add_func ("/general/connection-match/ip4-method", test_connection_match_ip4_method);
|
2014-03-18 14:21:59 +01:00
|
|
|
g_test_add_func ("/general/connection-match/con-interface-name", test_connection_match_interface_name);
|
2014-04-08 10:39:31 +02:00
|
|
|
g_test_add_func ("/general/connection-match/wired", test_connection_match_wired);
|
2015-10-29 18:57:52 +01:00
|
|
|
g_test_add_func ("/general/connection-match/wired2", test_connection_match_wired2);
|
2015-02-19 17:53:43 +01:00
|
|
|
g_test_add_func ("/general/connection-match/cloned_mac", test_connection_match_cloned_mac);
|
2014-04-08 10:39:31 +02:00
|
|
|
g_test_add_func ("/general/connection-match/no-match-ip4-addr", test_connection_no_match_ip4_addr);
|
2015-09-02 09:30:50 +02:00
|
|
|
g_test_add_func ("/general/connection-match/no-match-vlan", test_connection_no_match_vlan);
|
2016-02-01 14:16:30 +01:00
|
|
|
g_test_add_func ("/general/connection-match/routes/ip4/1", test_connection_match_ip4_routes1);
|
|
|
|
|
g_test_add_func ("/general/connection-match/routes/ip4/2", test_connection_match_ip4_routes2);
|
|
|
|
|
g_test_add_func ("/general/connection-match/routes/ip6", test_connection_match_ip6_routes);
|
2014-02-25 17:44:07 -06:00
|
|
|
|
2018-08-29 16:32:03 +02:00
|
|
|
g_test_add_func ("/general/wildcard-match", test_wildcard_match);
|
|
|
|
|
|
2014-08-26 16:06:39 +02:00
|
|
|
g_test_add_func ("/general/connection-sort/autoconnect-priority", test_connection_sort_autoconnect_priority);
|
|
|
|
|
|
core: refactor evaluation of device's match-spec
Previously, we would have different functions like
- nm_match_spec_device_type()
- nm_match_spec_hwaddr()
- nm_match_spec_s390_subchannels()
- nm_match_spec_interface_name()
which all would handle one type of match-spec.
So, to get the overall result whether the arguments
match or not, nm_device_spec_match_list() had to stich
them together and iterate the list multiple times.
Refactor the code to have one nm_match_spec_device()
function that gets all relevant paramters.
The upside is:
- the logic how to evaluate the match-spec is all at one place
(match_device_eval()) instead of spread over multiple
functions.
- It requires iterating the list at most twice. Twice, because
we do a fast pre-search for "*".
One downside could be, that we have to pass all 4 arguments
for the evaluation, even if the might no be needed. That is,
because "nm-core-utils.c" shall be independend from NMDevice, it
cannot receive a device instance to get the parameters as needed.
As we would add new match-types, the argument list would grow.
However, all arguments are cached and fetching them from the
device's private data is very cheap.
(cherry picked from commit b957403efd53ff7d826ac7a4f80487032c03824b)
2017-01-20 19:50:25 +01:00
|
|
|
g_test_add_func ("/general/match-spec/device", test_match_spec_device);
|
|
|
|
|
g_test_add_func ("/general/match-spec/config", test_match_spec_config);
|
2016-03-09 11:17:36 +01:00
|
|
|
g_test_add_func ("/general/duplicate_decl_specifier", test_duplicate_decl_specifier);
|
2014-11-27 14:09:03 +01:00
|
|
|
|
2016-06-03 22:07:38 +02:00
|
|
|
g_test_add_func ("/general/reverse_dns/ip4", test_reverse_dns_ip4);
|
2016-06-03 22:07:42 +02:00
|
|
|
g_test_add_func ("/general/reverse_dns/ip6", test_reverse_dns_ip6);
|
2016-06-03 22:07:38 +02:00
|
|
|
|
2016-12-18 13:54:26 +01:00
|
|
|
g_test_add_func ("/general/stable-id/parse", test_stable_id_parse);
|
|
|
|
|
g_test_add_func ("/general/stable-id/generated-complete", test_stable_id_generated_complete);
|
|
|
|
|
|
core: refactor loading machine-id and cache it
Previously, whenever we needed /etc/machine-id we would re-load it
from file. The are 3 downsides of that:
- the smallest downside is the runtime overhead of repeatedly
reading the file and parse it.
- as we read it multiple times, it may change anytime. Most
code in NetworkManager does not expect or handle a change of
the machine-id.
Generally, the admin should make sure that the machine-id is properly
initialized before NetworkManager starts, and not change it. As such,
a change of the machine-id should never happen in practice.
But if it would change, we would get odd behaviors. Note for example
how generate_duid_from_machine_id() already cached the generated DUID
and only read it once.
It's better to pick the machine-id once, and rely to use the same
one for the remainder of the program.
If the admin wants to change the machine-id, NetworkManager must be
restarted as well (in case the admin cares).
Also, as we now only load it once, it makes sense to log an error
(once) when we fail to read the machine-id.
- previously, loading the machine-id could fail each time. And we
have to somehow handle that error. It seems, the best thing what we
anyway can do, is to log an error once and continue with a fake
machine-id. Here we add a fake machine-id based on the secret-key
or the boot-id. Now obtaining a machine-id can no longer fail
and error handling is no longer necessary.
Also, ensure that a machine-id of all zeros is not valid.
Technically, a machine-id is not an RFC 4122 UUID. But it's
the same size, so we also use NMUuid data structure for it.
While at it, also refactor caching of the boot-id and the secret
key. In particular, fix the thread-safety of the double-checked
locking implementations.
2018-10-30 14:07:11 +01:00
|
|
|
g_test_add_func ("/general/machine-id/read", test_machine_id_read);
|
|
|
|
|
|
2018-10-19 10:21:53 +02:00
|
|
|
g_test_add_func ("/general/test_utils_file_is_in_path", test_utils_file_is_in_path);
|
|
|
|
|
|
2018-11-12 10:44:19 +01:00
|
|
|
g_test_add_func ("/general/test_dns_create_resolv_conf", test_dns_create_resolv_conf);
|
|
|
|
|
|
dhcp: test systemd's default DHCP client identifier generation
Internal DHCP client generates a default client ID. For one,
we should ensure that this algorithm does not change without
us noticing, for example, when upgrading systemd code. Add
a test, that the generation algorithm works as we expect.
Also note, that the generation algorithm uses siphash24().
That means, siphash24() implementation also must not change
in the future, to ensure the client ID doesn't change. As we
patch systemd sources to use shared/c-siphash, this is not
obviously the case. Luckily c-siphash and systemd's siphash24 do
agree, so all is good. The test is here to ensure that.
Also, previously the generation algorithm is not exposed as a
function, sd_dhcp_client will just generate a client-id when
it needs it. However, later we want to know (and set) the client
id before starting DHCP and not leave it unspecified to an
implementation detail.
This patch only adds a unit-test for the existing DHCP client
ID generation to have something for comparison. In the next
commit this will change further.
2018-10-26 17:32:59 +02:00
|
|
|
g_test_add_data_func ("/general/nm_sd_utils_generate_default_dhcp_client_id/lo", GINT_TO_POINTER (TRUE), test_nm_sd_utils_generate_default_dhcp_client_id);
|
|
|
|
|
g_test_add_data_func ("/general/nm_sd_utils_generate_default_dhcp_client_id/rnd", GINT_TO_POINTER (FALSE), test_nm_sd_utils_generate_default_dhcp_client_id);
|
|
|
|
|
|
2014-01-21 13:07:06 +01:00
|
|
|
return g_test_run ();
|
|
|
|
|
}
|
|
|
|
|
|