summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2021-08-05 18:34:25 +0200
committerThomas Haller <thaller@redhat.com>2021-08-05 18:34:25 +0200
commit17dcef41bdf13f83dd7f5a617609c4e65c610ef5 (patch)
tree654f2987a41a2e85cf209c6bd9aad09ccf76c72a
parent4513d4db630377d7c11ea8a0eed3c99c081186e4 (diff)
parent8c7ab709155fda367ccc012a2a7213526138469a (diff)
downloadNetworkManager-17dcef41bdf13f83dd7f5a617609c4e65c610ef5.tar.gz
all: merge branch 'th/l3cfg-21'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/953
-rw-r--r--src/core/devices/nm-device.c139
-rw-r--r--src/core/dhcp/nm-dhcp-client.c45
-rw-r--r--src/core/dhcp/nm-dhcp-client.h3
-rw-r--r--src/core/dhcp/nm-dhcp-nettools.c4
-rw-r--r--src/core/dhcp/nm-dhcp-systemd.c2
-rw-r--r--src/core/dns/nm-dns-manager.c2
-rw-r--r--src/core/nm-active-connection.c14
-rw-r--r--src/core/nm-dispatcher.c22
-rw-r--r--src/core/nm-dispatcher.h7
-rw-r--r--src/core/nm-l3cfg.c10
-rw-r--r--src/core/nm-l3cfg.h3
-rw-r--r--src/core/nm-manager.c6
-rw-r--r--src/core/nm-policy.c42
-rw-r--r--src/core/platform/tests/test-common.h6
-rw-r--r--src/core/tests/test-l3cfg.c9
-rw-r--r--src/libnm-client-impl/tests/test-nm-client.c18
-rw-r--r--src/libnm-core-impl/tests/test-general.c22
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.c4
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.h53
-rw-r--r--src/libnm-glib-aux/nm-test-utils.h2
-rw-r--r--src/libnm-std-aux/nm-std-aux.h31
21 files changed, 275 insertions, 169 deletions
diff --git a/src/core/devices/nm-device.c b/src/core/devices/nm-device.c
index 3c1db20c42..eef31c39c2 100644
--- a/src/core/devices/nm-device.c
+++ b/src/core/devices/nm-device.c
@@ -316,7 +316,12 @@ typedef struct _NMDevicePrivate {
guint queued_ip_config_id_x[2];
};
- GSList *pending_actions;
+ struct {
+ const char **arr;
+ guint len;
+ guint alloc;
+ } pending_actions;
+
GSList *dad6_failed_addrs;
NMDBusTrackObjPath parent_device;
@@ -8261,7 +8266,7 @@ activate_stage1_device_prepare(NMDevice *self)
priv->master_ready_id =
g_signal_connect(active,
"notify::" NM_ACTIVE_CONNECTION_INT_MASTER_READY,
- (GCallback) master_ready_cb,
+ G_CALLBACK(master_ready_cb),
self);
}
return;
@@ -9293,7 +9298,7 @@ dhcp4_lease_change(NMDevice *self, NMIP4Config *config, gboolean bound)
return FALSE;
}
- nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP4_CHANGE, self, NULL, NULL, NULL, NULL);
+ nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP_CHANGE_4, self, NULL, NULL, NULL, NULL);
return TRUE;
}
@@ -9807,7 +9812,7 @@ dhcp6_lease_change(NMDevice *self)
return FALSE;
}
- nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP6_CHANGE, self, NULL, NULL, NULL, NULL);
+ nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP_CHANGE_6, self, NULL, NULL, NULL, NULL);
return TRUE;
}
@@ -9965,7 +9970,7 @@ dhcp6_state_changed(NMDhcpClient *client,
}
static void
-dhcp6_prefix_delegated(NMDhcpClient *client, NMPlatformIP6Address *prefix, gpointer user_data)
+dhcp6_prefix_delegated(NMDhcpClient *client, const NMPlatformIP6Address *prefix, gpointer user_data)
{
NMDevice *self = NM_DEVICE(user_data);
@@ -11987,7 +11992,7 @@ activate_stage5_ip_config_result_x(NMDevice *self, int addr_family)
/* If IPv6 wasn't the first IP to complete, and DHCP was used,
* then ensure dispatcher scripts get the DHCP lease information.
*/
- nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP6_CHANGE,
+ nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP_CHANGE_6,
self,
NULL,
NULL,
@@ -12053,7 +12058,7 @@ activate_stage5_ip_config_result_x(NMDevice *self, int addr_family)
*/
if (priv->dhcp_data_4.client && nm_device_activate_ip4_state_in_conf(self)
&& (nm_device_get_state(self) > NM_DEVICE_STATE_IP_CONFIG)) {
- nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP4_CHANGE,
+ nm_dispatcher_call_device(NM_DISPATCHER_ACTION_DHCP_CHANGE_4,
self,
NULL,
NULL,
@@ -14951,7 +14956,7 @@ _set_unmanaged_flags(NMDevice * self,
priv->queued_ip_config_id_4 = g_idle_add(queued_ip4_config_change, self);
priv->queued_ip_config_id_6 = g_idle_add(queued_ip6_config_change, self);
- if (!priv->pending_actions) {
+ if (priv->pending_actions.len == 0) {
do_notify_has_pending_actions = TRUE;
had_pending_actions = nm_device_has_pending_action(self);
}
@@ -15745,37 +15750,39 @@ gboolean
nm_device_add_pending_action(NMDevice *self, const char *action, gboolean assert_not_yet_pending)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
- GSList * iter;
- guint count = 0;
+ gssize idx;
g_return_val_if_fail(action, FALSE);
- /* Check if the action is already pending. Cannot add duplicate actions */
- for (iter = priv->pending_actions; iter; iter = iter->next) {
- if (nm_streq(action, iter->data)) {
- if (assert_not_yet_pending) {
- _LOGW(LOGD_DEVICE,
- "add_pending_action (%d): '%s' already pending",
- count + g_slist_length(iter),
- action);
- g_return_val_if_reached(FALSE);
- } else {
- _LOGT(LOGD_DEVICE,
- "add_pending_action (%d): '%s' already pending (expected)",
- count + g_slist_length(iter),
- action);
- }
- return FALSE;
+ idx = nm_strv_find_binary_search(priv->pending_actions.arr, priv->pending_actions.len, action);
+ if (idx >= 0) {
+ if (assert_not_yet_pending) {
+ _LOGW(LOGD_DEVICE,
+ "add_pending_action (%u): '%s' already pending",
+ priv->pending_actions.len,
+ action);
+ g_return_val_if_reached(FALSE);
+ } else {
+ _LOGT(LOGD_DEVICE,
+ "add_pending_action (%u): '%s' already pending (expected)",
+ priv->pending_actions.len,
+ action);
}
- count++;
+ return FALSE;
}
- priv->pending_actions = g_slist_prepend(priv->pending_actions, (char *) action);
- count++;
+ if (priv->pending_actions.len == priv->pending_actions.alloc) {
+ nm_assert(priv->pending_actions.alloc < G_MAXUINT / 2u);
+ priv->pending_actions.alloc = NM_MAX(priv->pending_actions.alloc * 2u, 4u);
+ priv->pending_actions.arr =
+ g_renew(const char *, priv->pending_actions.arr, priv->pending_actions.alloc);
+ }
+ nm_arr_insert_at(priv->pending_actions.arr, priv->pending_actions.len, ~idx, action);
+ priv->pending_actions.len++;
- _LOGD(LOGD_DEVICE, "add_pending_action (%d): '%s'", count, action);
+ _LOGD(LOGD_DEVICE, "add_pending_action (%u): '%s'", priv->pending_actions.len, action);
- if (count == 1)
+ if (priv->pending_actions.len == 1)
_notify(self, PROP_HAS_PENDING_ACTION);
return TRUE;
@@ -15797,37 +15804,38 @@ gboolean
nm_device_remove_pending_action(NMDevice *self, const char *action, gboolean assert_is_pending)
{
NMDevicePrivate *priv;
- GSList * iter, *next;
- guint count = 0;
+ gssize idx;
g_return_val_if_fail(self, FALSE);
g_return_val_if_fail(action, FALSE);
priv = NM_DEVICE_GET_PRIVATE(self);
- for (iter = priv->pending_actions; iter; iter = next) {
- next = iter->next;
- if (nm_streq(action, iter->data)) {
- _LOGD(LOGD_DEVICE,
- "remove_pending_action (%d): '%s'",
- count + g_slist_length(iter->next), /* length excluding 'iter' */
- action);
- priv->pending_actions = g_slist_delete_link(priv->pending_actions, iter);
- if (priv->pending_actions == NULL)
- _notify(self, PROP_HAS_PENDING_ACTION);
- return TRUE;
- }
- count++;
+ idx = nm_strv_find_binary_search(priv->pending_actions.arr, priv->pending_actions.len, action);
+ if (idx >= 0) {
+ _LOGD(LOGD_DEVICE,
+ "remove_pending_action (%u): '%s'",
+ priv->pending_actions.len - 1u,
+ action);
+ nm_arr_remove_at(priv->pending_actions.arr, priv->pending_actions.len, idx);
+ priv->pending_actions.len--;
+ if (priv->pending_actions.len == 0)
+ _notify(self, PROP_HAS_PENDING_ACTION);
+ return TRUE;
}
if (assert_is_pending) {
- _LOGW(LOGD_DEVICE, "remove_pending_action (%d): '%s' not pending", count, action);
+ _LOGW(LOGD_DEVICE,
+ "remove_pending_action (%u): '%s' not pending",
+ priv->pending_actions.len,
+ action);
g_return_val_if_reached(FALSE);
- } else
+ } else {
_LOGT(LOGD_DEVICE,
- "remove_pending_action (%d): '%s' not pending (expected)",
- count,
+ "remove_pending_action (%u): '%s' not pending (expected)",
+ priv->pending_actions.len,
action);
+ }
return FALSE;
}
@@ -15837,15 +15845,15 @@ nm_device_has_pending_action_reason(NMDevice *self)
{
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
- if (priv->pending_actions) {
- if (!priv->pending_actions->next && nm_device_get_state(self) == NM_DEVICE_STATE_ACTIVATED
- && nm_streq(priv->pending_actions->data, NM_PENDING_ACTION_CARRIER_WAIT)) {
+ if (priv->pending_actions.len > 0) {
+ if (priv->pending_actions.len == 1 && nm_device_get_state(self) == NM_DEVICE_STATE_ACTIVATED
+ && nm_streq(priv->pending_actions.arr[0], NM_PENDING_ACTION_CARRIER_WAIT)) {
/* if the device is already in activated state, and the only reason
* why it appears still busy is "carrier-wait", then we are already complete. */
return NULL;
}
- return priv->pending_actions->data;
+ return priv->pending_actions.arr[0];
}
if (nm_device_is_real(self)
@@ -18574,7 +18582,7 @@ finalize(GObject *object)
g_free(priv->hw_addr);
g_free(priv->hw_addr_perm);
g_free(priv->hw_addr_initial);
- g_slist_free(priv->pending_actions);
+ g_free(priv->pending_actions.arr);
g_slist_free_full(priv->dad6_failed_addrs, (GDestroyNotify) nmp_object_unref);
nm_clear_g_free(&priv->physical_port_id);
g_free(priv->udi);
@@ -19114,16 +19122,17 @@ nm_device_class_init(NMDeviceClass *klass)
G_TYPE_OBJECT,
G_TYPE_OBJECT);
- signals[IP6_PREFIX_DELEGATED] = g_signal_new(NM_DEVICE_IP6_PREFIX_DELEGATED,
- G_OBJECT_CLASS_TYPE(object_class),
- G_SIGNAL_RUN_FIRST,
- 0,
- NULL,
- NULL,
- NULL,
- G_TYPE_NONE,
- 1,
- G_TYPE_POINTER);
+ signals[IP6_PREFIX_DELEGATED] =
+ g_signal_new(NM_DEVICE_IP6_PREFIX_DELEGATED,
+ G_OBJECT_CLASS_TYPE(object_class),
+ G_SIGNAL_RUN_FIRST,
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER /* const NMPlatformIP6Address *prefix */);
signals[IP6_SUBNET_NEEDED] = g_signal_new(NM_DEVICE_IP6_SUBNET_NEEDED,
G_OBJECT_CLASS_TYPE(object_class),
diff --git a/src/core/dhcp/nm-dhcp-client.c b/src/core/dhcp/nm-dhcp-client.c
index 3ffa4c9a68..07db0da438 100644
--- a/src/core/dhcp/nm-dhcp-client.c
+++ b/src/core/dhcp/nm-dhcp-client.c
@@ -352,8 +352,7 @@ NM_UTILS_LOOKUP_STR_DEFINE(nm_dhcp_state_to_string,
NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_NOOP, "noop"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_TERMINATED, "terminated"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_TIMEOUT, "timeout"),
- NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_UNKNOWN, "unknown"),
- NM_UTILS_LOOKUP_ITEM_IGNORE(__NM_DHCP_STATE_MAX), );
+ NM_UTILS_LOOKUP_STR_ITEM(NM_DHCP_STATE_UNKNOWN, "unknown"), );
static NMDhcpState
reason_to_state(NMDhcpClient *self, const char *iface, const char *reason)
@@ -497,7 +496,12 @@ nm_dhcp_client_set_state(NMDhcpClient *self,
}
priv->state = new_state;
- g_signal_emit(G_OBJECT(self), signals[SIGNAL_STATE_CHANGED], 0, new_state, ip_config, options);
+ g_signal_emit(G_OBJECT(self),
+ signals[SIGNAL_STATE_CHANGED],
+ 0,
+ (guint) new_state,
+ ip_config,
+ options);
}
static gboolean
@@ -608,6 +612,20 @@ nm_dhcp_client_accept(NMDhcpClient *self, GError **error)
}
gboolean
+nm_dhcp_client_can_accept(NMDhcpClient *self)
+{
+ gboolean can_accept;
+
+ g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE);
+
+ can_accept = !!(NM_DHCP_CLIENT_GET_CLASS(self)->accept);
+
+ nm_assert(can_accept == (!!(NM_DHCP_CLIENT_GET_CLASS(self)->decline)));
+
+ return can_accept;
+}
+
+gboolean
nm_dhcp_client_decline(NMDhcpClient *self, const char *error_message, GError **error)
{
g_return_val_if_fail(NM_IS_DHCP_CLIENT(self), FALSE);
@@ -1382,14 +1400,15 @@ nm_dhcp_client_class_init(NMDhcpClientClass *client_class)
G_TYPE_OBJECT,
G_TYPE_HASH_TABLE);
- signals[SIGNAL_PREFIX_DELEGATED] = g_signal_new(NM_DHCP_CLIENT_SIGNAL_PREFIX_DELEGATED,
- G_OBJECT_CLASS_TYPE(object_class),
- G_SIGNAL_RUN_FIRST,
- 0,
- NULL,
- NULL,
- NULL,
- G_TYPE_NONE,
- 1,
- G_TYPE_POINTER);
+ signals[SIGNAL_PREFIX_DELEGATED] =
+ g_signal_new(NM_DHCP_CLIENT_SIGNAL_PREFIX_DELEGATED,
+ G_OBJECT_CLASS_TYPE(object_class),
+ G_SIGNAL_RUN_FIRST,
+ 0,
+ NULL,
+ NULL,
+ NULL,
+ G_TYPE_NONE,
+ 1,
+ G_TYPE_POINTER /* const NMPlatformIP6Address *prefix */);
}
diff --git a/src/core/dhcp/nm-dhcp-client.h b/src/core/dhcp/nm-dhcp-client.h
index 601225ecd6..2a4a56059b 100644
--- a/src/core/dhcp/nm-dhcp-client.h
+++ b/src/core/dhcp/nm-dhcp-client.h
@@ -57,8 +57,6 @@ typedef enum {
NM_DHCP_STATE_FAIL, /* failed for some reason */
NM_DHCP_STATE_TERMINATED, /* client is no longer running */
NM_DHCP_STATE_NOOP, /* state is a non operation for NetworkManager */
- __NM_DHCP_STATE_MAX,
- NM_DHCP_STATE_MAX = __NM_DHCP_STATE_MAX - 1,
} NMDhcpState;
const char *nm_dhcp_state_to_string(NMDhcpState state);
@@ -173,6 +171,7 @@ gboolean nm_dhcp_client_start_ip6(NMDhcpClient * self,
GError ** error);
gboolean nm_dhcp_client_accept(NMDhcpClient *self, GError **error);
+gboolean nm_dhcp_client_can_accept(NMDhcpClient *self);
gboolean nm_dhcp_client_decline(NMDhcpClient *self, const char *error_message, GError **error);
diff --git a/src/core/dhcp/nm-dhcp-nettools.c b/src/core/dhcp/nm-dhcp-nettools.c
index 6e8c69c71f..56b485dd25 100644
--- a/src/core/dhcp/nm-dhcp-nettools.c
+++ b/src/core/dhcp/nm-dhcp-nettools.c
@@ -1219,7 +1219,7 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error)
return FALSE;
}
- _LOGT("dhcp-client4: start %p", (gpointer) priv->client);
+ _LOGT("dhcp-client4: start " NM_HASH_OBFUSCATE_PTR_FMT, NM_HASH_OBFUSCATE_PTR(priv->client));
nm_dhcp_client_start_timeout(client);
return TRUE;
@@ -1233,7 +1233,7 @@ stop(NMDhcpClient *client, gboolean release)
NM_DHCP_CLIENT_CLASS(nm_dhcp_nettools_parent_class)->stop(client, release);
- _LOGT("dhcp-client4: stop %p", (gpointer) priv->client);
+ _LOGT("dhcp-client4: stop " NM_HASH_OBFUSCATE_PTR_FMT, NM_HASH_OBFUSCATE_PTR(priv->client));
priv->probe = n_dhcp4_client_probe_free(priv->probe);
}
diff --git a/src/core/dhcp/nm-dhcp-systemd.c b/src/core/dhcp/nm-dhcp-systemd.c
index 4bb58ee354..af1d2238b4 100644
--- a/src/core/dhcp/nm-dhcp-systemd.c
+++ b/src/core/dhcp/nm-dhcp-systemd.c
@@ -592,7 +592,7 @@ ip4_start(NMDhcpClient *client, const char *last_ip4_address, GError **error)
return FALSE;
}
- _LOGT("dhcp-client4: set %p", sd_client);
+ _LOGT("dhcp-client4: set " NM_HASH_OBFUSCATE_PTR_FMT, NM_HASH_OBFUSCATE_PTR(sd_client));
r = sd_dhcp_client_attach_event(sd_client, NULL, 0);
if (r < 0) {
diff --git a/src/core/dns/nm-dns-manager.c b/src/core/dns/nm-dns-manager.c
index 95bfaed98a..f0ec0c8921 100644
--- a/src/core/dns/nm-dns-manager.c
+++ b/src/core/dns/nm-dns-manager.c
@@ -272,7 +272,7 @@ _dns_config_ip_data_new(NMDnsConfigData * data,
g_signal_connect(ip_config,
NM_IS_IP4_CONFIG(ip_config) ? "notify::" NM_IP4_CONFIG_DNS_PRIORITY
: "notify::" NM_IP6_CONFIG_DNS_PRIORITY,
- (GCallback) _ip_config_dns_priority_changed,
+ G_CALLBACK(_ip_config_dns_priority_changed),
ip_data);
_ASSERT_dns_config_ip_data(ip_data);
diff --git a/src/core/nm-active-connection.c b/src/core/nm-active-connection.c
index bf2c4a39f1..b3a3796f5c 100644
--- a/src/core/nm-active-connection.c
+++ b/src/core/nm-active-connection.c
@@ -208,12 +208,12 @@ _set_settings_connection(NMActiveConnection *self, NMSettingsConnection *sett_co
if (sett_conn) {
g_signal_connect(sett_conn,
NM_SETTINGS_CONNECTION_UPDATED_INTERNAL,
- (GCallback) _settings_connection_updated,
+ G_CALLBACK(_settings_connection_updated),
self);
if (nm_active_connection_get_activation_type(self) == NM_ACTIVATION_TYPE_EXTERNAL)
g_signal_connect(sett_conn,
NM_SETTINGS_CONNECTION_FLAGS_CHANGED,
- (GCallback) _settings_connection_flags_changed,
+ G_CALLBACK(_settings_connection_flags_changed),
self);
}
@@ -851,7 +851,7 @@ nm_active_connection_set_master(NMActiveConnection *self, NMActiveConnection *ma
priv->master = g_object_ref(master);
g_signal_connect(priv->master,
"notify::" NM_ACTIVE_CONNECTION_STATE,
- (GCallback) master_state_cb,
+ G_CALLBACK(master_state_cb),
self);
check_master_ready(self);
@@ -883,7 +883,7 @@ _set_activation_type(NMActiveConnection *self, NMActivationType activation_type)
if (activation_type == NM_ACTIVATION_TYPE_EXTERNAL)
g_signal_connect(priv->settings_connection.obj,
NM_SETTINGS_CONNECTION_FLAGS_CHANGED,
- (GCallback) _settings_connection_flags_changed,
+ G_CALLBACK(_settings_connection_flags_changed),
self);
else
g_signal_handlers_disconnect_by_func(priv->settings_connection.obj,
@@ -1018,7 +1018,7 @@ unwatch_parent(NMActiveConnection *self, gboolean unref)
{
NMActiveConnectionPrivate *priv = NM_ACTIVE_CONNECTION_GET_PRIVATE(self);
- g_signal_handlers_disconnect_by_func(priv->parent, (GCallback) parent_state_cb, self);
+ g_signal_handlers_disconnect_by_func(priv->parent, G_CALLBACK(parent_state_cb), self);
if (unref)
g_object_weak_unref((GObject *) priv->parent, parent_destroyed, self);
priv->parent = NULL;
@@ -1042,7 +1042,7 @@ nm_active_connection_set_parent(NMActiveConnection *self, NMActiveConnection *pa
priv->parent = parent;
g_signal_connect(priv->parent,
"notify::" NM_ACTIVE_CONNECTION_STATE,
- (GCallback) parent_state_cb,
+ G_CALLBACK(parent_state_cb),
self);
g_object_weak_ref((GObject *) priv->parent, parent_destroyed, self);
}
@@ -1522,7 +1522,7 @@ dispose(GObject *object)
_device_cleanup(self);
if (priv->master) {
- g_signal_handlers_disconnect_by_func(priv->master, (GCallback) master_state_cb, self);
+ g_signal_handlers_disconnect_by_func(priv->master, G_CALLBACK(master_state_cb), self);
}
g_clear_object(&priv->master);
diff --git a/src/core/nm-dispatcher.c b/src/core/nm-dispatcher.c
index 32c9db627c..b77197863b 100644
--- a/src/core/nm-dispatcher.c
+++ b/src/core/nm-dispatcher.c
@@ -448,17 +448,17 @@ dispatcher_done_cb(GObject *source, GAsyncResult *result, gpointer user_data)
dispatcher_call_id_free(call_id);
}
-static const char *action_table[] = {[NM_DISPATCHER_ACTION_HOSTNAME] = NMD_ACTION_HOSTNAME,
- [NM_DISPATCHER_ACTION_PRE_UP] = NMD_ACTION_PRE_UP,
- [NM_DISPATCHER_ACTION_UP] = NMD_ACTION_UP,
- [NM_DISPATCHER_ACTION_PRE_DOWN] = NMD_ACTION_PRE_DOWN,
- [NM_DISPATCHER_ACTION_DOWN] = NMD_ACTION_DOWN,
- [NM_DISPATCHER_ACTION_VPN_PRE_UP] = NMD_ACTION_VPN_PRE_UP,
- [NM_DISPATCHER_ACTION_VPN_UP] = NMD_ACTION_VPN_UP,
- [NM_DISPATCHER_ACTION_VPN_PRE_DOWN] = NMD_ACTION_VPN_PRE_DOWN,
- [NM_DISPATCHER_ACTION_VPN_DOWN] = NMD_ACTION_VPN_DOWN,
- [NM_DISPATCHER_ACTION_DHCP4_CHANGE] = NMD_ACTION_DHCP4_CHANGE,
- [NM_DISPATCHER_ACTION_DHCP6_CHANGE] = NMD_ACTION_DHCP6_CHANGE,
+static const char *action_table[] = {[NM_DISPATCHER_ACTION_HOSTNAME] = NMD_ACTION_HOSTNAME,
+ [NM_DISPATCHER_ACTION_PRE_UP] = NMD_ACTION_PRE_UP,
+ [NM_DISPATCHER_ACTION_UP] = NMD_ACTION_UP,
+ [NM_DISPATCHER_ACTION_PRE_DOWN] = NMD_ACTION_PRE_DOWN,
+ [NM_DISPATCHER_ACTION_DOWN] = NMD_ACTION_DOWN,
+ [NM_DISPATCHER_ACTION_VPN_PRE_UP] = NMD_ACTION_VPN_PRE_UP,
+ [NM_DISPATCHER_ACTION_VPN_UP] = NMD_ACTION_VPN_UP,
+ [NM_DISPATCHER_ACTION_VPN_PRE_DOWN] = NMD_ACTION_VPN_PRE_DOWN,
+ [NM_DISPATCHER_ACTION_VPN_DOWN] = NMD_ACTION_VPN_DOWN,
+ [NM_DISPATCHER_ACTION_DHCP_CHANGE_4] = NMD_ACTION_DHCP4_CHANGE,
+ [NM_DISPATCHER_ACTION_DHCP_CHANGE_6] = NMD_ACTION_DHCP6_CHANGE,
[NM_DISPATCHER_ACTION_CONNECTIVITY_CHANGE] =
NMD_ACTION_CONNECTIVITY_CHANGE};
diff --git a/src/core/nm-dispatcher.h b/src/core/nm-dispatcher.h
index d588de4e8f..8e4f01cb62 100644
--- a/src/core/nm-dispatcher.h
+++ b/src/core/nm-dispatcher.h
@@ -19,11 +19,14 @@ typedef enum {
NM_DISPATCHER_ACTION_VPN_UP,
NM_DISPATCHER_ACTION_VPN_PRE_DOWN,
NM_DISPATCHER_ACTION_VPN_DOWN,
- NM_DISPATCHER_ACTION_DHCP4_CHANGE,
- NM_DISPATCHER_ACTION_DHCP6_CHANGE,
+ NM_DISPATCHER_ACTION_DHCP_CHANGE_4,
+ NM_DISPATCHER_ACTION_DHCP_CHANGE_6,
NM_DISPATCHER_ACTION_CONNECTIVITY_CHANGE
} NMDispatcherAction;
+#define NM_DISPATCHER_ACTION_DHCP_CHANGE_X(IS_IPv4) \
+ ((IS_IPv4) ? NM_DISPATCHER_ACTION_DHCP_CHANGE_4 : NM_DISPATCHER_ACTION_DHCP_CHANGE_6)
+
typedef struct NMDispatcherCallId NMDispatcherCallId;
typedef void (*NMDispatcherFunc)(NMDispatcherCallId *call_id, gpointer user_data);
diff --git a/src/core/nm-l3cfg.c b/src/core/nm-l3cfg.c
index 46bdac234b..2ea93677ea 100644
--- a/src/core/nm-l3cfg.c
+++ b/src/core/nm-l3cfg.c
@@ -2885,9 +2885,15 @@ nm_l3cfg_remove_config(NML3Cfg *self, gconstpointer tag, const NML3ConfigData *i
}
gboolean
-nm_l3cfg_remove_config_all(NML3Cfg *self, gconstpointer tag, gboolean only_dirty)
+nm_l3cfg_remove_config_all(NML3Cfg *self, gconstpointer tag)
{
- return _l3cfg_remove_config(self, tag, only_dirty, NULL);
+ return _l3cfg_remove_config(self, tag, FALSE, NULL);
+}
+
+gboolean
+nm_l3cfg_remove_config_all_dirty(NML3Cfg *self, gconstpointer tag)
+{
+ return _l3cfg_remove_config(self, tag, TRUE, NULL);
}
/*****************************************************************************/
diff --git a/src/core/nm-l3cfg.h b/src/core/nm-l3cfg.h
index 037f21784d..d4438cbe3a 100644
--- a/src/core/nm-l3cfg.h
+++ b/src/core/nm-l3cfg.h
@@ -295,7 +295,8 @@ gboolean nm_l3cfg_add_config(NML3Cfg * self,
gboolean nm_l3cfg_remove_config(NML3Cfg *self, gconstpointer tag, const NML3ConfigData *ifcfg);
-gboolean nm_l3cfg_remove_config_all(NML3Cfg *self, gconstpointer tag, gboolean only_dirty);
+gboolean nm_l3cfg_remove_config_all(NML3Cfg *self, gconstpointer tag);
+gboolean nm_l3cfg_remove_config_all_dirty(NML3Cfg *self, gconstpointer tag);
/*****************************************************************************/
diff --git a/src/core/nm-manager.c b/src/core/nm-manager.c
index 47c906df40..c0997761c1 100644
--- a/src/core/nm-manager.c
+++ b/src/core/nm-manager.c
@@ -4751,7 +4751,7 @@ active_connection_parent_active(NMActiveConnection *active,
NMSettingsConnection *sett_conn;
NMDevice * parent;
- g_signal_handlers_disconnect_by_func(active, (GCallback) active_connection_parent_active, self);
+ g_signal_handlers_disconnect_by_func(active, G_CALLBACK(active_connection_parent_active), self);
if (!parent_ac) {
_LOGW(LOGD_CORE,
@@ -4926,7 +4926,7 @@ _internal_activate_device(NMManager *self, NMActiveConnection *active, GError **
/* We can't realize now; defer until the parent device is ready. */
g_signal_connect(active,
NM_ACTIVE_CONNECTION_PARENT_ACTIVE,
- (GCallback) active_connection_parent_active,
+ G_CALLBACK(active_connection_parent_active),
self);
nm_active_connection_set_parent(active, parent_ac);
} else {
@@ -6164,7 +6164,7 @@ sleep_devices_add(NMManager *self, NMDevice *device, gboolean suspending)
g_hash_table_insert(priv->sleep_devices,
g_object_ref(device),
suspending ? nm_sleep_monitor_inhibit_take(priv->sleep_monitor) : NULL);
- g_signal_connect(device, "notify::" NM_DEVICE_STATE, (GCallback) device_sleep_cb, self);
+ g_signal_connect(device, "notify::" NM_DEVICE_STATE, G_CALLBACK(device_sleep_cb), self);
return TRUE;
}
diff --git a/src/core/nm-policy.c b/src/core/nm-policy.c
index e4914acfb5..bf7c4ef01a 100644
--- a/src/core/nm-policy.c
+++ b/src/core/nm-policy.c
@@ -322,7 +322,9 @@ ip6_remove_device_prefix_delegations(NMPolicy *self, NMDevice *device)
}
static void
-device_ip6_prefix_delegated(NMDevice *device, NMPlatformIP6Address *prefix, gpointer user_data)
+device_ip6_prefix_delegated(NMDevice * device,
+ const NMPlatformIP6Address *prefix,
+ gpointer user_data)
{
NMPolicyPrivate * priv = user_data;
NMPolicy * self = _PRIV_TO_SELF(priv);
@@ -913,7 +915,7 @@ update_system_hostname(NMPolicy *self, const char *msg)
if (wait) {
g_signal_connect(info->device,
NM_DEVICE_DNS_LOOKUP_DONE,
- (GCallback) device_dns_lookup_done,
+ G_CALLBACK(device_dns_lookup_done),
self);
return;
}
@@ -2222,30 +2224,30 @@ devices_list_register(NMPolicy *self, NMDevice *device)
NMPolicyPrivate *priv = NM_POLICY_GET_PRIVATE(self);
/* Connect state-changed with _after, so that the handler is invoked after other handlers. */
- g_signal_connect_after(device, NM_DEVICE_STATE_CHANGED, (GCallback) device_state_changed, priv);
+ g_signal_connect_after(device, NM_DEVICE_STATE_CHANGED, G_CALLBACK(device_state_changed), priv);
g_signal_connect(device,
NM_DEVICE_IP4_CONFIG_CHANGED,
- (GCallback) device_ip_config_changed,
+ G_CALLBACK(device_ip_config_changed),
priv);
g_signal_connect(device,
NM_DEVICE_IP6_CONFIG_CHANGED,
- (GCallback) device_ip_config_changed,
+ G_CALLBACK(device_ip_config_changed),
priv);
g_signal_connect(device,
NM_DEVICE_IP6_PREFIX_DELEGATED,
- (GCallback) device_ip6_prefix_delegated,
+ G_CALLBACK(device_ip6_prefix_delegated),
priv);
g_signal_connect(device,
NM_DEVICE_IP6_SUBNET_NEEDED,
- (GCallback) device_ip6_subnet_needed,
+ G_CALLBACK(device_ip6_subnet_needed),
priv);
g_signal_connect(device,
"notify::" NM_DEVICE_AUTOCONNECT,
- (GCallback) device_autoconnect_changed,
+ G_CALLBACK(device_autoconnect_changed),
priv);
g_signal_connect(device,
NM_DEVICE_RECHECK_AUTO_ACTIVATE,
- (GCallback) device_recheck_auto_activate,
+ G_CALLBACK(device_recheck_auto_activate),
priv);
}
@@ -2800,49 +2802,49 @@ constructed(GObject *object)
g_signal_connect(priv->hostname_manager,
"notify::" NM_HOSTNAME_MANAGER_HOSTNAME,
- (GCallback) hostname_changed,
+ G_CALLBACK(hostname_changed),
priv);
g_signal_connect(priv->manager,
"notify::" NM_MANAGER_SLEEPING,
- (GCallback) sleeping_changed,
+ G_CALLBACK(sleeping_changed),
priv);
g_signal_connect(priv->manager,
"notify::" NM_MANAGER_NETWORKING_ENABLED,
- (GCallback) sleeping_changed,
+ G_CALLBACK(sleeping_changed),
priv);
g_signal_connect(priv->manager,
NM_MANAGER_INTERNAL_DEVICE_ADDED,
- (GCallback) device_added,
+ G_CALLBACK(device_added),
priv);
g_signal_connect(priv->manager,
NM_MANAGER_INTERNAL_DEVICE_REMOVED,
- (GCallback) device_removed,
+ G_CALLBACK(device_removed),
priv);
g_signal_connect(priv->manager,
NM_MANAGER_ACTIVE_CONNECTION_ADDED,
- (GCallback) active_connection_added,
+ G_CALLBACK(active_connection_added),
priv);
g_signal_connect(priv->manager,
NM_MANAGER_ACTIVE_CONNECTION_REMOVED,
- (GCallback) active_connection_removed,
+ G_CALLBACK(active_connection_removed),
priv);
g_signal_connect(priv->settings,
NM_SETTINGS_SIGNAL_CONNECTION_ADDED,
- (GCallback) connection_added,
+ G_CALLBACK(connection_added),
priv);
g_signal_connect(priv->settings,
NM_SETTINGS_SIGNAL_CONNECTION_UPDATED,
- (GCallback) connection_updated,
+ G_CALLBACK(connection_updated),
priv);
g_signal_connect(priv->settings,
NM_SETTINGS_SIGNAL_CONNECTION_REMOVED,
- (GCallback) connection_removed,
+ G_CALLBACK(connection_removed),
priv);
g_signal_connect(priv->settings,
NM_SETTINGS_SIGNAL_CONNECTION_FLAGS_CHANGED,
- (GCallback) connection_flags_changed,
+ G_CALLBACK(connection_flags_changed),
priv);
g_signal_connect(priv->agent_mgr,
diff --git a/src/core/platform/tests/test-common.h b/src/core/platform/tests/test-common.h
index 1fb97d248d..fc4149f0ee 100644
--- a/src/core/platform/tests/test-common.h
+++ b/src/core/platform/tests/test-common.h
@@ -104,11 +104,11 @@ SignalData *add_signal_full(const char * name,
int ifindex,
const char * ifname);
#define add_signal(name, change_type, callback) \
- add_signal_full(name, change_type, (GCallback) callback, 0, NULL)
+ add_signal_full(name, change_type, G_CALLBACK(callback), 0, NULL)
#define add_signal_ifindex(name, change_type, callback, ifindex) \
- add_signal_full(name, change_type, (GCallback) callback, ifindex, NULL)
+ add_signal_full(name, change_type, G_CALLBACK(callback), ifindex, NULL)
#define add_signal_ifname(name, change_type, callback, ifname) \
- add_signal_full(name, change_type, (GCallback) callback, 0, ifname)
+ add_signal_full(name, change_type, G_CALLBACK(callback), 0, ifname)
void _accept_signal(const char *file, int line, const char *func, SignalData *data);
void
_accept_signals(const char *file, int line, const char *func, SignalData *data, int min, int max);
diff --git a/src/core/tests/test-l3cfg.c b/src/core/tests/test-l3cfg.c
index d877b5dc5a..2ef9f36eb8 100644
--- a/src/core/tests/test-l3cfg.c
+++ b/src/core/tests/test-l3cfg.c
@@ -490,7 +490,7 @@ test_l3cfg(gconstpointer test_data)
if (nmtst_get_rand_one_case_in(3))
_test_fixture_1_teardown(&test_fixture);
- nm_l3cfg_remove_config_all(l3cfg0, GINT_TO_POINTER('a'), FALSE);
+ nm_l3cfg_remove_config_all(l3cfg0, GINT_TO_POINTER('a'));
if (nmtst_get_rand_one_case_in(3))
_test_fixture_1_teardown(&test_fixture);
@@ -615,8 +615,7 @@ _test_l3_ipv4ll_signal_notify(NML3Cfg * l3cfg,
_LOGT("remove address %s that previously passed ACD",
_nm_utils_inet4_ntop(tdata->addr_commit_addr, sbuf_addr));
if (!nm_l3cfg_remove_config_all(nm_l3_ipv4ll_get_l3cfg(tdata->l3ipv4ll),
- TEST_L3_IPV4LL_TAG(tdata, 1),
- FALSE))
+ TEST_L3_IPV4LL_TAG(tdata, 1)))
g_assert_not_reached();
nm_l3cfg_commit_on_idle_schedule(nm_l3_ipv4ll_get_l3cfg(tdata->l3ipv4ll));
nm_l3cfg_commit_type_unregister(nm_l3_ipv4ll_get_l3cfg(tdata->l3ipv4ll),
@@ -766,9 +765,7 @@ test_l3_ipv4ll(gconstpointer test_data)
_LOGT("poll 1 end");
if (tdata->addr_commit || nmtst_get_rand_bool()) {
- nm_l3cfg_remove_config_all(nm_l3_ipv4ll_get_l3cfg(l3ipv4ll),
- TEST_L3_IPV4LL_TAG(tdata, 1),
- FALSE);
+ nm_l3cfg_remove_config_all(nm_l3_ipv4ll_get_l3cfg(l3ipv4ll), TEST_L3_IPV4LL_TAG(tdata, 1));
}
nmtstp_acd_defender_destroy(g_steal_pointer(&acd_defender_1));
diff --git a/src/libnm-client-impl/tests/test-nm-client.c b/src/libnm-client-impl/tests/test-nm-client.c
index 55b886a08c..c1e3793af9 100644
--- a/src/libnm-client-impl/tests/test-nm-client.c
+++ b/src/libnm-client-impl/tests/test-nm-client.c
@@ -62,7 +62,7 @@ test_device_added(void)
devices = nm_client_get_devices(client);
g_assert(devices->len == 0);
- g_signal_connect(client, "notify::devices", (GCallback) devices_notify_cb, &notified);
+ g_signal_connect(client, "notify::devices", G_CALLBACK(devices_notify_cb), &notified);
/* Tell the test service to add a new device */
nmtstc_service_add_device(sinfo, client, "AddWiredDevice", "eth0");
@@ -149,11 +149,11 @@ test_device_added_signal_after_init(void)
devices = nm_client_get_devices(client);
g_assert(devices->len == 0);
- g_signal_connect(client, NM_CLIENT_DEVICE_ADDED, (GCallback) device_sai_added_cb, &result);
+ g_signal_connect(client, NM_CLIENT_DEVICE_ADDED, G_CALLBACK(device_sai_added_cb), &result);
g_signal_connect(client,
"notify::" NM_CLIENT_DEVICES,
- (GCallback) devices_sai_notify_cb,
+ G_CALLBACK(devices_sai_notify_cb),
&result);
/* Tell the test service to add a new device */
@@ -307,10 +307,10 @@ test_wifi_ap_added_removed(void)
g_variant_get(ret, "(o)", &expected_path);
g_variant_unref(ret);
- g_signal_connect(wifi, "access-point-added", (GCallback) wifi_ap_added_cb, &info);
+ g_signal_connect(wifi, "access-point-added", G_CALLBACK(wifi_ap_added_cb), &info);
info.quit_count = 1;
- g_signal_connect(wifi, "notify::access-points", (GCallback) wifi_ap_add_notify_cb, &info);
+ g_signal_connect(wifi, "notify::access-points", G_CALLBACK(wifi_ap_add_notify_cb), &info);
info.quit_count++;
/* Wait for libnm to find the AP */
@@ -340,10 +340,10 @@ test_wifi_ap_added_removed(void)
g_assert_no_error(error);
nm_clear_pointer(&ret, g_variant_unref);
- g_signal_connect(wifi, "access-point-removed", (GCallback) wifi_ap_removed_cb, &info);
+ g_signal_connect(wifi, "access-point-removed", G_CALLBACK(wifi_ap_removed_cb), &info);
info.quit_count = 1;
- g_signal_connect(wifi, "notify::access-points", (GCallback) wifi_ap_remove_notify_cb, &info);
+ g_signal_connect(wifi, "notify::access-points", G_CALLBACK(wifi_ap_remove_notify_cb), &info);
info.quit_count++;
/* Wait for libnm to find the AP */
@@ -463,9 +463,9 @@ test_devices_array(void)
g_assert(ret);
g_variant_unref(ret);
- g_signal_connect(client, "device-removed", (GCallback) da_device_removed_cb, &info);
+ g_signal_connect(client, "device-removed", G_CALLBACK(da_device_removed_cb), &info);
- g_signal_connect(client, "notify::devices", (GCallback) da_devices_notify_cb, &info);
+ g_signal_connect(client, "notify::devices", G_CALLBACK(da_devices_notify_cb), &info);
info.quit_count = 2;
/* Wait for libnm to notice the changes */
diff --git a/src/libnm-core-impl/tests/test-general.c b/src/libnm-core-impl/tests/test-general.c
index ebc7243be7..c7848fe5bf 100644
--- a/src/libnm-core-impl/tests/test-general.c
+++ b/src/libnm-core-impl/tests/test-general.c
@@ -5013,7 +5013,7 @@ test_connection_changed_signal(void)
connection = new_test_connection();
g_signal_connect(connection,
NM_CONNECTION_CHANGED,
- (GCallback) test_connection_changed_cb,
+ G_CALLBACK(test_connection_changed_cb),
&changed);
/* Add new setting */
@@ -5039,7 +5039,7 @@ test_setting_connection_changed_signal(void)
connection = nm_simple_connection_new();
g_signal_connect(connection,
NM_CONNECTION_CHANGED,
- (GCallback) test_connection_changed_cb,
+ G_CALLBACK(test_connection_changed_cb),
&changed);
s_con = (NMSettingConnection *) nm_setting_connection_new();
@@ -5075,7 +5075,7 @@ test_setting_bond_changed_signal(void)
connection = nm_simple_connection_new();
g_signal_connect(connection,
NM_CONNECTION_CHANGED,
- (GCallback) test_connection_changed_cb,
+ G_CALLBACK(test_connection_changed_cb),
&changed);
s_bond = (NMSettingBond *) nm_setting_bond_new();
@@ -5101,7 +5101,7 @@ test_setting_ip4_changed_signal(void)
connection = nm_simple_connection_new();
g_signal_connect(connection,
NM_CONNECTION_CHANGED,
- (GCallback) test_connection_changed_cb,
+ G_CALLBACK(test_connection_changed_cb),
&changed);
s_ip4 = (NMSettingIPConfig *) nm_setting_ip4_config_new();
@@ -5177,7 +5177,7 @@ test_setting_ip6_changed_signal(void)
connection = nm_simple_connection_new();
g_signal_connect(connection,
NM_CONNECTION_CHANGED,
- (GCallback) test_connection_changed_cb,
+ G_CALLBACK(test_connection_changed_cb),
&changed);
s_ip6 = (NMSettingIPConfig *) nm_setting_ip6_config_new();
@@ -5244,7 +5244,7 @@ test_setting_vlan_changed_signal(void)
connection = nm_simple_connection_new();
g_signal_connect(connection,
NM_CONNECTION_CHANGED,
- (GCallback) test_connection_changed_cb,
+ G_CALLBACK(test_connection_changed_cb),
&changed);
s_vlan = (NMSettingVlan *) nm_setting_vlan_new();
@@ -5279,7 +5279,7 @@ test_setting_vpn_changed_signal(void)
connection = nm_simple_connection_new();
g_signal_connect(connection,
NM_CONNECTION_CHANGED,
- (GCallback) test_connection_changed_cb,
+ G_CALLBACK(test_connection_changed_cb),
&changed);
s_vpn = (NMSettingVpn *) nm_setting_vpn_new();
@@ -5306,7 +5306,7 @@ test_setting_wired_changed_signal(void)
connection = nm_simple_connection_new();
g_signal_connect(connection,
NM_CONNECTION_CHANGED,
- (GCallback) test_connection_changed_cb,
+ G_CALLBACK(test_connection_changed_cb),
&changed);
s_wired = (NMSettingWired *) nm_setting_wired_new();
@@ -5329,7 +5329,7 @@ test_setting_wireless_changed_signal(void)
connection = nm_simple_connection_new();
g_signal_connect(connection,
NM_CONNECTION_CHANGED,
- (GCallback) test_connection_changed_cb,
+ G_CALLBACK(test_connection_changed_cb),
&changed);
s_wifi = (NMSettingWireless *) nm_setting_wireless_new();
@@ -5350,7 +5350,7 @@ test_setting_wireless_security_changed_signal(void)
connection = nm_simple_connection_new();
g_signal_connect(connection,
NM_CONNECTION_CHANGED,
- (GCallback) test_connection_changed_cb,
+ G_CALLBACK(test_connection_changed_cb),
&changed);
s_wsec = (NMSettingWirelessSecurity *) nm_setting_wireless_security_new();
@@ -5417,7 +5417,7 @@ test_setting_802_1x_changed_signal(void)
connection = nm_simple_connection_new();
g_signal_connect(connection,
NM_CONNECTION_CHANGED,
- (GCallback) test_connection_changed_cb,
+ G_CALLBACK(test_connection_changed_cb),
&changed);
s_8021x = (NMSetting8021x *) nm_setting_802_1x_new();
diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c
index 3fa00570b4..f2483da1ad 100644
--- a/src/libnm-glib-aux/nm-shared-utils.c
+++ b/src/libnm-glib-aux/nm-shared-utils.c
@@ -5000,14 +5000,14 @@ _nm_g_source_sentinel_get_init(GSource **p_source)
};
GSource *source;
-again:
source = g_source_new((GSourceFuncs *) &source_funcs, sizeof(GSource));
g_source_set_priority(source, G_PRIORITY_DEFAULT_IDLE);
g_source_set_name(source, "nm_g_source_sentinel");
if (!g_atomic_pointer_compare_and_exchange(p_source, NULL, source)) {
g_source_unref(source);
- goto again;
+ source = g_atomic_pointer_get(p_source);
+ nm_assert(source);
}
return source;
diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h
index ef4d3937f1..fd7f7dc309 100644
--- a/src/libnm-glib-aux/nm-shared-utils.h
+++ b/src/libnm-glib-aux/nm-shared-utils.h
@@ -2304,6 +2304,59 @@ int _nm_strv_cmp_n(const char *const *strv1, gssize len1, const char *const *str
/*****************************************************************************/
+/* nm_arr_insert_at() does @arr[@idx] = @value, but first memmove's
+ * the elements @arr[@idx..@len-1] one element up. That means, @arr currently
+ * has @len valid elements, but it must have space for one more element,
+ * which will be overwritten.
+ *
+ * The use case is to have a sorted array (nm_strv_find_binary_search()) and
+ * to insert the element at he desired index. The caller must make sure that
+ * @len is large enough to contain one more element. */
+#define nm_arr_insert_at(arr, len, idx, value) \
+ G_STMT_START \
+ { \
+ typeof(*(arr)) *const _arr = (arr); \
+ typeof(len) _len = (len); \
+ typeof(idx) _idx = (idx); \
+ const gsize _len2 = (_len); \
+ const gsize _idx2 = (_idx); \
+ \
+ nm_assert(_arr); \
+ nm_assert(_NM_INT_NOT_NEGATIVE(_len)); \
+ nm_assert(_NM_INT_NOT_NEGATIVE(_idx)); \
+ nm_assert(_idx <= _len); \
+ \
+ if (_idx2 != _len2) \
+ memmove(&_arr[_idx2 + 1u], &_arr[_idx2], sizeof(_arr[0]) * (_len2 - _idx2)); \
+ \
+ _arr[_idx2] = (value); \
+ } \
+ G_STMT_END
+
+/* nm_arr_remove_at() removes the element at arr[idx], by memmove'ing
+ * the elements from arr[idx+1..len-1] down. All it does is one memmove(),
+ * if there is anything to move. */
+#define nm_arr_remove_at(arr, len, idx) \
+ G_STMT_START \
+ { \
+ typeof(*(arr)) *const _arr = (arr); \
+ typeof(len) _len = (len); \
+ typeof(idx) _idx = (idx); \
+ const gsize _len2 = (_len); \
+ const gsize _idx2 = (_idx); \
+ \
+ nm_assert(_arr); \
+ nm_assert(_len > 0); \
+ nm_assert(_NM_INT_NOT_NEGATIVE(_idx)); \
+ nm_assert(_idx < _len); \
+ \
+ if (_idx2 != _len2 - 1u) \
+ memmove(&_arr[_idx2], &_arr[_idx2 + 1u], sizeof(_arr[0]) * ((_len2 - 1u) - _idx2)); \
+ } \
+ G_STMT_END
+
+/*****************************************************************************/
+
#define NM_UTILS_NSEC_PER_SEC ((gint64) 1000000000)
#define NM_UTILS_USEC_PER_SEC ((gint64) 1000000)
#define NM_UTILS_MSEC_PER_SEC ((gint64) 1000)
diff --git a/src/libnm-glib-aux/nm-test-utils.h b/src/libnm-glib-aux/nm-test-utils.h
index cae6453087..b759151508 100644
--- a/src/libnm-glib-aux/nm-test-utils.h
+++ b/src/libnm-glib-aux/nm-test-utils.h
@@ -1238,7 +1238,7 @@ _nmtst_main_loop_quit_on_notify(GObject *object, GParamSpec *pspec, gpointer use
g_main_loop_quit(loop);
}
-#define nmtst_main_loop_quit_on_notify ((GCallback) _nmtst_main_loop_quit_on_notify)
+#define nmtst_main_loop_quit_on_notify (G_CALLBACK(_nmtst_main_loop_quit_on_notify))
#define nmtst_main_context_iterate_until_full(context, timeout_msec, poll_msec, condition) \
({ \
diff --git a/src/libnm-std-aux/nm-std-aux.h b/src/libnm-std-aux/nm-std-aux.h
index 4f18081cd8..2747338576 100644
--- a/src/libnm-std-aux/nm-std-aux.h
+++ b/src/libnm-std-aux/nm-std-aux.h
@@ -1134,6 +1134,21 @@ nm_ptr_to_uintptr(const void *p)
#define NM_AF_INET_SIZE 4 /* sizeof (in_addr_t) */
#define NM_AF_INET6_SIZE 16 /* sizeof (stuct in6_addr) */
+static inline const char *
+nm_utils_addr_family_to_str(int addr_family)
+{
+ switch (addr_family) {
+ case NM_AF_UNSPEC:
+ return "";
+ case NM_AF_INET:
+ return "4";
+ case NM_AF_INET6:
+ return "6";
+ }
+ nm_assert_not_reached();
+ return "?";
+}
+
static inline char
nm_utils_addr_family_to_char(int addr_family)
{
@@ -1152,15 +1167,17 @@ nm_utils_addr_family_to_char(int addr_family)
#define nm_assert_addr_family(addr_family) \
nm_assert(NM_IN_SET((addr_family), NM_AF_INET, NM_AF_INET6))
-#define NM_IS_IPv4(addr_family) \
- ({ \
- const int _addr_family = (addr_family); \
- \
- nm_assert_addr_family(_addr_family); \
- \
- (_addr_family == NM_AF_INET); \
+#define _NM_IS_IPv4(uniq, addr_family) \
+ ({ \
+ const int NM_UNIQ_T(_addr_family, uniq) = (addr_family); \
+ \
+ nm_assert_addr_family(NM_UNIQ_T(_addr_family, uniq)); \
+ \
+ (NM_UNIQ_T(_addr_family, uniq) == NM_AF_INET); \
})
+#define NM_IS_IPv4(addr_family) _NM_IS_IPv4(NM_UNIQ, addr_family)
+
static inline size_t
nm_utils_addr_family_to_size(int addr_family)
{