dhcp: merge branch 'th/dhcp-cleanup'

https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/956
This commit is contained in:
Thomas Haller 2021-08-11 14:23:24 +02:00
commit e11b8b94e3
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
12 changed files with 218 additions and 257 deletions

View file

@ -10,7 +10,7 @@
/*****************************************************************************/
NM_UTILS_LOOKUP_STR_DEFINE(
nm_device_state_queued_state_to_str,
nm_device_state_queued_state_to_string,
NMDeviceState,
NM_UTILS_LOOKUP_DEFAULT(NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "???"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_UNKNOWN,
@ -41,14 +41,14 @@ NM_UTILS_LOOKUP_STR_DEFINE(
NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "failed"), );
const char *
nm_device_state_to_str(NMDeviceState state)
nm_device_state_to_string(NMDeviceState state)
{
return nm_device_state_queued_state_to_str(state)
return nm_device_state_queued_state_to_string(state)
+ NM_STRLEN(NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE);
}
NM_UTILS_LOOKUP_STR_DEFINE(
nm_device_state_reason_to_str,
nm_device_state_reason_to_string,
NMDeviceStateReason,
NM_UTILS_LOOKUP_DEFAULT(NULL),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_UNKNOWN, "unknown"),
@ -129,7 +129,7 @@ NM_UTILS_LOOKUP_STR_DEFINE(
"sriov-configuration-failed"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_STATE_REASON_PEER_NOT_FOUND, "peer-not-found"), );
NM_UTILS_LOOKUP_STR_DEFINE(nm_device_mtu_source_to_str,
NM_UTILS_LOOKUP_STR_DEFINE(nm_device_mtu_source_to_string,
NMDeviceMtuSource,
NM_UTILS_LOOKUP_DEFAULT_NM_ASSERT("unknown"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_MTU_SOURCE_NONE, "none"),
@ -138,7 +138,7 @@ NM_UTILS_LOOKUP_STR_DEFINE(nm_device_mtu_source_to_str,
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_MTU_SOURCE_CONNECTION,
"connection"), );
NM_UTILS_LOOKUP_STR_DEFINE(nm_device_sys_iface_state_to_str,
NM_UTILS_LOOKUP_STR_DEFINE(nm_device_sys_iface_state_to_string,
NMDeviceSysIfaceState,
NM_UTILS_LOOKUP_DEFAULT_NM_ASSERT("unknown"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_SYS_IFACE_STATE_EXTERNAL, "external"),
@ -147,7 +147,7 @@ NM_UTILS_LOOKUP_STR_DEFINE(nm_device_sys_iface_state_to_str,
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_SYS_IFACE_STATE_REMOVED,
"removed"), );
NM_UTILS_LOOKUP_STR_DEFINE(nm_device_ip_state_to_str,
NM_UTILS_LOOKUP_STR_DEFINE(nm_device_ip_state_to_string,
NMDeviceIPState,
NM_UTILS_LOOKUP_DEFAULT_WARN("unknown"),
NM_UTILS_LOOKUP_STR_ITEM(NM_DEVICE_IP_STATE_NONE, "none"),

View file

@ -5,11 +5,11 @@
/*****************************************************************************/
const char *nm_device_state_to_str(NMDeviceState state);
const char *nm_device_state_reason_to_str(NMDeviceStateReason reason);
const char *nm_device_state_to_string(NMDeviceState state);
const char *nm_device_state_reason_to_string(NMDeviceStateReason reason);
#define nm_device_state_reason_to_str_a(reason) \
NM_UTILS_LOOKUP_STR_A(nm_device_state_reason_to_str, reason)
#define nm_device_state_reason_to_string_a(reason) \
NM_UTILS_LOOKUP_STR_A(nm_device_state_reason_to_string, reason)
static inline NMDeviceStateReason
nm_device_state_reason_check(NMDeviceStateReason reason)
@ -41,7 +41,7 @@ nm_device_state_reason_check(NMDeviceStateReason reason)
#define NM_PENDING_ACTIONPREFIX_QUEUED_STATE_CHANGE "queued-state-change-"
#define NM_PENDING_ACTIONPREFIX_ACTIVATION "activation-"
const char *nm_device_state_queued_state_to_str(NMDeviceState state);
const char *nm_device_state_queued_state_to_string(NMDeviceState state);
/*****************************************************************************/
@ -52,7 +52,7 @@ typedef enum {
NM_DEVICE_MTU_SOURCE_CONNECTION,
} NMDeviceMtuSource;
const char *nm_device_mtu_source_to_str(NMDeviceMtuSource mtu_source);
const char *nm_device_mtu_source_to_string(NMDeviceMtuSource mtu_source);
/*****************************************************************************/
@ -69,7 +69,7 @@ typedef enum _nm_packed {
NM_DEVICE_SYS_IFACE_STATE_REMOVED,
} NMDeviceSysIfaceState;
const char *nm_device_sys_iface_state_to_str(NMDeviceSysIfaceState sys_iface_state);
const char *nm_device_sys_iface_state_to_string(NMDeviceSysIfaceState sys_iface_state);
/*****************************************************************************/
@ -81,7 +81,7 @@ typedef enum {
NM_DEVICE_IP_STATE_FAIL,
} NMDeviceIPState;
const char *nm_device_ip_state_to_str(NMDeviceIPState ip_state);
const char *nm_device_ip_state_to_string(NMDeviceIPState ip_state);
/*****************************************************************************/

View file

@ -185,7 +185,7 @@ typedef struct {
typedef struct {
NMDhcpClient *client;
NMDhcpConfig *config;
gulong state_sigid;
gulong notify_sigid;
guint grace_id;
bool grace_pending : 1;
bool was_active : 1;
@ -579,7 +579,6 @@ typedef struct _NMDevicePrivate {
AppliedConfig ip6_config;
/* Event ID of the current IP6 config from DHCP */
char * event_id;
gulong prefix_sigid;
NMNDiscDHCPLevel mode;
guint needed_prefixes;
} dhcp6;
@ -2559,8 +2558,8 @@ nm_device_sys_iface_state_set(NMDevice *self, NMDeviceSysIfaceState sys_iface_st
if (priv->sys_iface_state != sys_iface_state) {
_LOGT(LOGD_DEVICE,
"sys-iface-state: %s -> %s",
nm_device_sys_iface_state_to_str(priv->sys_iface_state),
nm_device_sys_iface_state_to_str(sys_iface_state));
nm_device_sys_iface_state_to_string(priv->sys_iface_state),
nm_device_sys_iface_state_to_string(sys_iface_state));
priv->sys_iface_state_ = sys_iface_state;
}
@ -2910,7 +2909,7 @@ _set_ip_state(NMDevice *self, int addr_family, NMDeviceIPState new_state)
"ip%c-state: set to %d (%s)",
nm_utils_addr_family_to_char(addr_family),
(int) new_state,
nm_device_ip_state_to_str(new_state));
nm_device_ip_state_to_string(new_state));
priv->ip_state_x_[IS_IPv4] = new_state;
@ -6449,9 +6448,9 @@ slave_state_changed(NMDevice * slave,
"slave %s state change %d (%s) -> %d (%s)",
nm_device_get_iface(slave),
slave_old_state,
nm_device_state_to_str(slave_old_state),
nm_device_state_to_string(slave_old_state),
slave_new_state,
nm_device_state_to_str(slave_new_state));
nm_device_state_to_string(slave_new_state));
/* Don't try to enslave slaves until the master is ready */
if (priv->state < NM_DEVICE_STATE_CONFIG)
@ -7763,7 +7762,8 @@ recheck_available(gpointer user_data)
now_available ? "" : "not ",
new_state == NM_DEVICE_STATE_UNAVAILABLE ? "no change required for"
: "will transition to",
nm_device_state_to_str(new_state == NM_DEVICE_STATE_UNAVAILABLE ? state : new_state));
nm_device_state_to_string(new_state == NM_DEVICE_STATE_UNAVAILABLE ? state
: new_state));
priv->recheck_available.available_reason = NM_DEVICE_STATE_REASON_NONE;
priv->recheck_available.unavailable_reason = NM_DEVICE_STATE_REASON_NONE;
@ -9035,7 +9035,7 @@ dhcp4_cleanup(NMDevice *self, CleanupType cleanup_type, gboolean release)
if (priv->dhcp_data_4.client) {
/* Stop any ongoing DHCP transaction on this device */
nm_clear_g_signal_handler(priv->dhcp_data_4.client, &priv->dhcp_data_4.state_sigid);
nm_clear_g_signal_handler(priv->dhcp_data_4.client, &priv->dhcp_data_4.notify_sigid);
if (cleanup_type == CLEANUP_TYPE_DECONFIGURE || cleanup_type == CLEANUP_TYPE_REMOVED)
nm_dhcp_client_stop(priv->dhcp_data_4.client, release);
@ -9380,7 +9380,7 @@ dhcp4_fail(NMDevice *self, NMDhcpState dhcp_state)
_LOGD(LOGD_DHCP4,
"DHCPv4 failed (ip_state %s, was_active %d)",
nm_device_ip_state_to_str(priv->ip_state_4),
nm_device_ip_state_to_string(priv->ip_state_4),
priv->dhcp_data_4.was_active);
/* The client is always left running after a failure. */
@ -9436,21 +9436,27 @@ dhcp4_dad_cb(NMDevice *self, NMIP4Config **configs, gboolean success)
}
static void
dhcp4_state_changed(NMDhcpClient *client,
NMDhcpState state,
NMIP4Config * ip4_config,
GHashTable * options,
gpointer user_data)
dhcp4_notify(NMDhcpClient *client, const NMDhcpClientNotifyData *notify_data, NMDevice *self)
{
NMDevice * self = NM_DEVICE(user_data);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
NMIP4Config * manual, **configs;
NMIP4Config * manual;
NMIP4Config ** configs;
NMConnection * connection;
NMDhcpState state;
NMIP4Config * ip4_config;
GHashTable * options;
g_return_if_fail(nm_dhcp_client_get_addr_family(client) == AF_INET);
g_return_if_fail(!ip4_config || NM_IS_IP4_CONFIG(ip4_config));
nm_assert(nm_dhcp_client_get_addr_family(client) == AF_INET);
nm_assert(notify_data);
nm_assert(notify_data->notify_type == NM_DHCP_CLIENT_NOTIFY_TYPE_STATE_CHANGED);
_LOGD(LOGD_DHCP4, "new DHCPv4 client state %d", state);
state = notify_data->state_changed.dhcp_state;
ip4_config = NM_IP4_CONFIG(notify_data->state_changed.ip_config);
options = notify_data->state_changed.options;
nm_assert(!ip4_config || NM_IS_IP4_CONFIG(ip4_config));
_LOGD(LOGD_DHCP4, "new DHCPv4 client state %d", (int) state);
switch (state) {
case NM_DHCP_STATE_BOUND:
@ -9601,10 +9607,10 @@ dhcp4_start(NMDevice *self)
return NM_ACT_STAGE_RETURN_FAILURE;
}
priv->dhcp_data_4.state_sigid = g_signal_connect(priv->dhcp_data_4.client,
NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED,
G_CALLBACK(dhcp4_state_changed),
self);
priv->dhcp_data_4.notify_sigid = g_signal_connect(priv->dhcp_data_4.client,
NM_DHCP_CLIENT_NOTIFY,
G_CALLBACK(dhcp4_notify),
self);
if (nm_device_sys_iface_state_is_external_or_assume(self))
priv->dhcp_data_4.was_active = TRUE;
@ -9775,8 +9781,7 @@ dhcp6_cleanup(NMDevice *self, CleanupType cleanup_type, gboolean release)
priv->dhcp_data_6.grace_pending = FALSE;
if (priv->dhcp_data_6.client) {
nm_clear_g_signal_handler(priv->dhcp_data_6.client, &priv->dhcp_data_6.state_sigid);
nm_clear_g_signal_handler(priv->dhcp_data_6.client, &priv->dhcp6.prefix_sigid);
nm_clear_g_signal_handler(priv->dhcp_data_6.client, &priv->dhcp_data_6.notify_sigid);
if (cleanup_type == CLEANUP_TYPE_DECONFIGURE || cleanup_type == CLEANUP_TYPE_REMOVED)
nm_dhcp_client_stop(priv->dhcp_data_6.client, release);
@ -9825,7 +9830,7 @@ dhcp6_fail(NMDevice *self, NMDhcpState dhcp_state)
_LOGD(LOGD_DHCP6,
"DHCPv6 failed (ip_state %s, was_active %d)",
nm_device_ip_state_to_str(priv->ip_state_6),
nm_device_ip_state_to_string(priv->ip_state_6),
priv->dhcp_data_6.was_active);
/* The client is always left running after a failure. */
@ -9876,20 +9881,34 @@ clear_config:
}
static void
dhcp6_state_changed(NMDhcpClient *client,
NMDhcpState state,
NMIP6Config * ip6_config,
GHashTable * options,
gpointer user_data)
dhcp6_notify(NMDhcpClient *client, const NMDhcpClientNotifyData *notify_data, NMDevice *self)
{
NMDevice * self = NM_DEVICE(user_data);
NMDevicePrivate *priv = NM_DEVICE_GET_PRIVATE(self);
gs_free char * event_id = NULL;
NMDhcpState state;
NMIP6Config * ip6_config;
GHashTable * options;
g_return_if_fail(nm_dhcp_client_get_addr_family(client) == AF_INET6);
g_return_if_fail(!ip6_config || NM_IS_IP6_CONFIG(ip6_config));
nm_assert(nm_dhcp_client_get_addr_family(client) == AF_INET6);
nm_assert(notify_data);
_LOGD(LOGD_DHCP6, "new DHCPv6 client state %d", state);
if (notify_data->notify_type == NM_DHCP_CLIENT_NOTIFY_TYPE_PREFIX_DELEGATED) {
/* Just re-emit. The device just contributes the prefix to the
* pool in NMPolicy, which decides about subnet allocation
* on the shared devices. */
g_signal_emit(self, signals[IP6_PREFIX_DELEGATED], 0, notify_data->prefix_delegated.prefix);
return;
}
nm_assert(notify_data->notify_type == NM_DHCP_CLIENT_NOTIFY_TYPE_STATE_CHANGED);
state = notify_data->state_changed.dhcp_state;
ip6_config = NM_IP6_CONFIG(notify_data->state_changed.ip_config);
options = notify_data->state_changed.options;
nm_assert(!ip6_config || NM_IS_IP6_CONFIG(ip6_config));
_LOGD(LOGD_DHCP6, "new DHCPv6 client state %d", (int) state);
switch (state) {
case NM_DHCP_STATE_BOUND:
@ -9969,17 +9988,6 @@ dhcp6_state_changed(NMDhcpClient *client,
}
}
static void
dhcp6_prefix_delegated(NMDhcpClient *client, const NMPlatformIP6Address *prefix, gpointer user_data)
{
NMDevice *self = NM_DEVICE(user_data);
/* Just re-emit. The device just contributes the prefix to the
* pool in NMPolicy, which decides about subnet allocation
* on the shared devices. */
g_signal_emit(self, signals[IP6_PREFIX_DELEGATED], 0, prefix);
}
/*****************************************************************************/
static gboolean
@ -10061,14 +10069,10 @@ dhcp6_start_with_link_ready(NMDevice *self, NMConnection *connection)
return FALSE;
}
priv->dhcp_data_6.state_sigid = g_signal_connect(priv->dhcp_data_6.client,
NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED,
G_CALLBACK(dhcp6_state_changed),
self);
priv->dhcp6.prefix_sigid = g_signal_connect(priv->dhcp_data_6.client,
NM_DHCP_CLIENT_SIGNAL_PREFIX_DELEGATED,
G_CALLBACK(dhcp6_prefix_delegated),
self);
priv->dhcp_data_6.notify_sigid = g_signal_connect(priv->dhcp_data_6.client,
NM_DHCP_CLIENT_NOTIFY,
G_CALLBACK(dhcp6_notify),
self);
if (nm_device_sys_iface_state_is_external_or_assume(self))
priv->dhcp_data_6.was_active = TRUE;
@ -10623,9 +10627,9 @@ _commit_mtu(NMDevice *self, const NMIP4Config *config)
_LOGT(LOGD_DEVICE,
"mtu: value %u from source '%s' (%u), current source '%s' (%u)%s",
(guint) mtu,
nm_device_mtu_source_to_str(source),
nm_device_mtu_source_to_string(source),
(guint) source,
nm_device_mtu_source_to_str(priv->mtu_source),
nm_device_mtu_source_to_string(priv->mtu_source),
(guint) priv->mtu_source,
force ? " (forced)" : "");
}
@ -10808,7 +10812,7 @@ nm_device_commit_mtu(NMDevice *self)
} else
_LOGT(LOGD_DEVICE,
"mtu: commit-mtu... skip due to state %s",
nm_device_state_to_str(state));
nm_device_state_to_string(state));
}
static void
@ -15016,7 +15020,7 @@ _set_unmanaged_flags(NMDevice * self,
flags,
NM_PRINT_FMT_QUOTED(allow_state_transition,
", reason ",
nm_device_state_reason_to_str_a(reason),
nm_device_state_reason_to_string_a(reason),
transition_state ? ", transition-state" : "",
""));
@ -16029,7 +16033,7 @@ nm_device_cleanup(NMDevice *self, NMDeviceStateReason reason, CleanupType cleanu
else
_LOGD(LOGD_DEVICE,
"deactivating device (reason '%s') [%d]",
nm_device_state_reason_to_str_a(reason),
nm_device_state_reason_to_string_a(reason),
reason);
/* Save whether or not we tried IPv6 for later */
@ -16523,20 +16527,20 @@ _set_state_full(NMDevice *self, NMDeviceState state, NMDeviceStateReason reason,
&& (state != NM_DEVICE_STATE_UNAVAILABLE || !priv->firmware_missing)) {
_LOGD(LOGD_DEVICE,
"state change: %s -> %s (reason '%s', sys-iface-state: '%s'%s)",
nm_device_state_to_str(old_state),
nm_device_state_to_str(state),
nm_device_state_reason_to_str_a(reason),
nm_device_sys_iface_state_to_str(priv->sys_iface_state),
nm_device_state_to_string(old_state),
nm_device_state_to_string(state),
nm_device_state_reason_to_string_a(reason),
nm_device_sys_iface_state_to_string(priv->sys_iface_state),
priv->firmware_missing ? ", missing firmware" : "");
return;
}
_LOGI(LOGD_DEVICE,
"state change: %s -> %s (reason '%s', sys-iface-state: '%s')",
nm_device_state_to_str(old_state),
nm_device_state_to_str(state),
nm_device_state_reason_to_str_a(reason),
nm_device_sys_iface_state_to_str(priv->sys_iface_state));
nm_device_state_to_string(old_state),
nm_device_state_to_string(state),
nm_device_state_reason_to_string_a(reason),
nm_device_sys_iface_state_to_string(priv->sys_iface_state));
/* in order to prevent triggering any callback caused
* by the device not having any pending action anymore
@ -16881,8 +16885,8 @@ queued_state_set(gpointer user_data)
_LOGD(LOGD_DEVICE,
"queue-state[%s, reason:%s, id:%u]: %s",
nm_device_state_to_str(priv->queued_state.state),
nm_device_state_reason_to_str_a(priv->queued_state.reason),
nm_device_state_to_string(priv->queued_state.state),
nm_device_state_reason_to_string_a(priv->queued_state.reason),
priv->queued_state.id,
"change state");
@ -16894,7 +16898,7 @@ queued_state_set(gpointer user_data)
new_reason = priv->queued_state.reason;
nm_device_state_changed(self, new_state, new_reason);
nm_device_remove_pending_action(self, nm_device_state_queued_state_to_str(new_state), TRUE);
nm_device_remove_pending_action(self, nm_device_state_queued_state_to_string(new_state), TRUE);
return G_SOURCE_REMOVE;
}
@ -16911,13 +16915,13 @@ nm_device_queue_state(NMDevice *self, NMDeviceState state, NMDeviceStateReason r
if (priv->queued_state.id && priv->queued_state.state == state) {
_LOGD(LOGD_DEVICE,
"queue-state[%s, reason:%s, id:%u]: %s%s%s%s",
nm_device_state_to_str(priv->queued_state.state),
nm_device_state_reason_to_str_a(priv->queued_state.reason),
nm_device_state_to_string(priv->queued_state.state),
nm_device_state_reason_to_string_a(priv->queued_state.reason),
priv->queued_state.id,
"ignore queuing same state change",
NM_PRINT_FMT_QUOTED(priv->queued_state.reason != reason,
" (reason differs: ",
nm_device_state_reason_to_str_a(reason),
nm_device_state_reason_to_string_a(reason),
")",
""));
return;
@ -16925,20 +16929,20 @@ nm_device_queue_state(NMDevice *self, NMDeviceState state, NMDeviceStateReason r
/* Add pending action for the new state before clearing the queued states, so
* that we don't accidentally pop all pending states and reach 'startup complete' */
nm_device_add_pending_action(self, nm_device_state_queued_state_to_str(state), TRUE);
nm_device_add_pending_action(self, nm_device_state_queued_state_to_string(state), TRUE);
/* We should only ever have one delayed state transition at a time */
if (priv->queued_state.id) {
_LOGW(LOGD_DEVICE,
"queue-state[%s, reason:%s, id:%u]: %s",
nm_device_state_to_str(priv->queued_state.state),
nm_device_state_reason_to_str_a(priv->queued_state.reason),
nm_device_state_to_string(priv->queued_state.state),
nm_device_state_reason_to_string_a(priv->queued_state.reason),
priv->queued_state.id,
"replace previously queued state change");
nm_clear_g_source(&priv->queued_state.id);
nm_device_remove_pending_action(
self,
nm_device_state_queued_state_to_str(priv->queued_state.state),
nm_device_state_queued_state_to_string(priv->queued_state.state),
TRUE);
}
@ -16948,8 +16952,8 @@ nm_device_queue_state(NMDevice *self, NMDeviceState state, NMDeviceStateReason r
_LOGD(LOGD_DEVICE,
"queue-state[%s, reason:%s, id:%u]: %s",
nm_device_state_to_str(state),
nm_device_state_reason_to_str_a(reason),
nm_device_state_to_string(state),
nm_device_state_reason_to_string_a(reason),
priv->queued_state.id,
"queue state change");
}
@ -16964,14 +16968,15 @@ queued_state_clear(NMDevice *self)
_LOGD(LOGD_DEVICE,
"queue-state[%s, reason:%s, id:%u]: %s",
nm_device_state_to_str(priv->queued_state.state),
nm_device_state_reason_to_str_a(priv->queued_state.reason),
nm_device_state_to_string(priv->queued_state.state),
nm_device_state_reason_to_string_a(priv->queued_state.reason),
priv->queued_state.id,
"clear queued state change");
nm_clear_g_source(&priv->queued_state.id);
nm_device_remove_pending_action(self,
nm_device_state_queued_state_to_str(priv->queued_state.state),
TRUE);
nm_device_remove_pending_action(
self,
nm_device_state_queued_state_to_string(priv->queued_state.state),
TRUE);
}
NMDeviceState

View file

@ -28,7 +28,7 @@
/*****************************************************************************/
enum { SIGNAL_STATE_CHANGED, SIGNAL_PREFIX_DELEGATED, LAST_SIGNAL };
enum { SIGNAL_NOTIFY, LAST_SIGNAL };
static guint signals[LAST_SIGNAL] = {0};
@ -78,6 +78,7 @@ typedef struct _NMDhcpClientPrivate {
NMDhcpHostnameFlags hostname_flags;
NMDhcpClientFlags client_flags;
bool iaid_explicit : 1;
bool is_stopped : 1;
} NMDhcpClientPrivate;
G_DEFINE_ABSTRACT_TYPE(NMDhcpClient, nm_dhcp_client, G_TYPE_OBJECT)
@ -91,6 +92,33 @@ G_STATIC_ASSERT(!(((pid_t) -1) > 0));
/*****************************************************************************/
static void
_emit_notify(NMDhcpClient *self, const NMDhcpClientNotifyData *notify_data)
{
g_signal_emit(G_OBJECT(self), signals[SIGNAL_NOTIFY], 0, notify_data);
}
static void
_emit_notify_state_changed(NMDhcpClient *self,
NMDhcpState dhcp_state,
NMIPConfig * ip_config,
GHashTable * options)
{
const NMDhcpClientNotifyData notify_data = {
.notify_type = NM_DHCP_CLIENT_NOTIFY_TYPE_STATE_CHANGED,
.state_changed =
{
.dhcp_state = dhcp_state,
.ip_config = ip_config,
.options = options,
},
};
_emit_notify(self, &notify_data);
}
/*****************************************************************************/
pid_t
nm_dhcp_client_get_pid(NMDhcpClient *self)
{
@ -496,12 +524,8 @@ nm_dhcp_client_set_state(NMDhcpClient *self,
}
priv->state = new_state;
g_signal_emit(G_OBJECT(self),
signals[SIGNAL_STATE_CHANGED],
0,
(guint) new_state,
ip_config,
options);
_emit_notify_state_changed(self, new_state, ip_config, options);
}
static gboolean
@ -751,6 +775,11 @@ nm_dhcp_client_stop(NMDhcpClient *self, gboolean release)
priv = NM_DHCP_CLIENT_GET_PRIVATE(self);
if (priv->is_stopped)
return;
priv->is_stopped = TRUE;
/* Kill the DHCP client */
old_pid = priv->pid;
NM_DHCP_CLIENT_GET_CLASS(self)->stop(self, release);
@ -873,7 +902,15 @@ maybe_add_option(NMDhcpClient *self, GHashTable *hash, const char *key, GVariant
void
nm_dhcp_client_emit_ipv6_prefix_delegated(NMDhcpClient *self, const NMPlatformIP6Address *prefix)
{
g_signal_emit(G_OBJECT(self), signals[SIGNAL_PREFIX_DELEGATED], 0, prefix);
const NMDhcpClientNotifyData notify_data = {
.notify_type = NM_DHCP_CLIENT_NOTIFY_TYPE_PREFIX_DELEGATED,
.prefix_delegated =
{
.prefix = prefix,
},
};
_emit_notify(self, &notify_data);
}
gboolean
@ -1160,8 +1197,6 @@ nm_dhcp_client_init(NMDhcpClient *self)
priv = G_TYPE_INSTANCE_GET_PRIVATE(self, NM_TYPE_DHCP_CLIENT, NMDhcpClientPrivate);
self->_priv = priv;
c_list_init(&self->dhcp_client_lst);
priv->pid = -1;
}
@ -1193,12 +1228,7 @@ dispose(GObject *object)
NMDhcpClient * self = NM_DHCP_CLIENT(object);
NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self);
/* Stopping the client is left up to the controlling device
* explicitly since we may want to quit NetworkManager but not terminate
* the DHCP client.
*/
nm_assert(c_list_is_empty(&self->dhcp_client_lst));
nm_dhcp_client_stop(self, FALSE);
watch_cleanup(self);
timeout_cleanup(self);
@ -1387,28 +1417,15 @@ nm_dhcp_client_class_init(NMDhcpClientClass *client_class)
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
signals[SIGNAL_STATE_CHANGED] = g_signal_new(NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED,
G_OBJECT_CLASS_TYPE(object_class),
G_SIGNAL_RUN_FIRST,
0,
NULL,
NULL,
NULL,
G_TYPE_NONE,
3,
G_TYPE_UINT,
G_TYPE_OBJECT,
G_TYPE_HASH_TABLE);
signals[SIGNAL_PREFIX_DELEGATED] =
g_signal_new(NM_DHCP_CLIENT_SIGNAL_PREFIX_DELEGATED,
signals[SIGNAL_NOTIFY] =
g_signal_new(NM_DHCP_CLIENT_NOTIFY,
G_OBJECT_CLASS_TYPE(object_class),
G_SIGNAL_RUN_FIRST,
0,
NULL,
NULL,
NULL,
g_cclosure_marshal_VOID__POINTER,
G_TYPE_NONE,
1,
G_TYPE_POINTER /* const NMPlatformIP6Address *prefix */);
G_TYPE_POINTER /* const NMDhcpClientNotifyData *notify_data */);
}

View file

@ -44,8 +44,7 @@
#define NM_DHCP_CLIENT_VENDOR_CLASS_IDENTIFIER "vendor-class-identifier"
#define NM_DHCP_CLIENT_REJECT_SERVERS "reject-servers"
#define NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED "state-changed"
#define NM_DHCP_CLIENT_SIGNAL_PREFIX_DELEGATED "prefix-delegated"
#define NM_DHCP_CLIENT_NOTIFY "dhcp-notify"
typedef enum {
NM_DHCP_STATE_UNKNOWN = 0,
@ -59,6 +58,25 @@ typedef enum {
NM_DHCP_STATE_NOOP, /* state is a non operation for NetworkManager */
} NMDhcpState;
typedef enum _nm_packed {
NM_DHCP_CLIENT_NOTIFY_TYPE_STATE_CHANGED,
NM_DHCP_CLIENT_NOTIFY_TYPE_PREFIX_DELEGATED,
} NMDhcpClientNotifyType;
typedef struct {
NMDhcpClientNotifyType notify_type;
union {
struct {
NMIPConfig *ip_config;
GHashTable *options;
NMDhcpState dhcp_state;
} state_changed;
struct {
const NMPlatformIP6Address *prefix;
} prefix_delegated;
};
} NMDhcpClientNotifyData;
const char *nm_dhcp_state_to_string(NMDhcpState state);
struct _NMDhcpClientPrivate;
@ -66,7 +84,6 @@ struct _NMDhcpClientPrivate;
typedef struct {
GObject parent;
struct _NMDhcpClientPrivate *_priv;
CList dhcp_client_lst;
} NMDhcpClient;
typedef enum _nm_packed {

View file

@ -27,7 +27,6 @@
typedef struct {
const NMDhcpClientFactory *client_factory;
char * default_hostname;
CList dhcp_client_lst_head;
} NMDhcpManagerPrivate;
struct _NMDhcpManager {
@ -45,14 +44,6 @@ G_DEFINE_TYPE(NMDhcpManager, nm_dhcp_manager, G_TYPE_OBJECT)
/*****************************************************************************/
static void client_state_changed(NMDhcpClient * client,
NMDhcpState state,
GObject * ip_config,
GVariant * options,
NMDhcpManager *self);
/*****************************************************************************/
/* default to installed helper, but can be modified for testing */
const char *nm_dhcp_helper_path = LIBEXECDIR "/nm-dhcp-helper";
@ -138,56 +129,6 @@ _client_factory_get_gtype(const NMDhcpClientFactory *client_factory, int addr_fa
/*****************************************************************************/
static NMDhcpClient *
get_client_for_ifindex(NMDhcpManager *manager, int addr_family, int ifindex)
{
NMDhcpManagerPrivate *priv;
NMDhcpClient * client;
g_return_val_if_fail(NM_IS_DHCP_MANAGER(manager), NULL);
g_return_val_if_fail(ifindex > 0, NULL);
priv = NM_DHCP_MANAGER_GET_PRIVATE(manager);
c_list_for_each_entry (client, &priv->dhcp_client_lst_head, dhcp_client_lst) {
if (nm_dhcp_client_get_ifindex(client) == ifindex
&& nm_dhcp_client_get_addr_family(client) == addr_family)
return client;
}
return NULL;
}
static void
remove_client(NMDhcpManager *self, NMDhcpClient *client)
{
g_signal_handlers_disconnect_by_func(client, client_state_changed, self);
c_list_unlink(&client->dhcp_client_lst);
/* Stopping the client is left up to the controlling device
* explicitly since we may want to quit NetworkManager but not terminate
* the DHCP client.
*/
}
static void
remove_client_unref(NMDhcpManager *self, NMDhcpClient *client)
{
remove_client(self, client);
g_object_unref(client);
}
static void
client_state_changed(NMDhcpClient * client,
NMDhcpState state,
GObject * ip_config,
GVariant * options,
NMDhcpManager *self)
{
if (state >= NM_DHCP_STATE_TIMEOUT)
remove_client_unref(self, client);
}
static NMDhcpClient *
client_start(NMDhcpManager * self,
int addr_family,
@ -218,10 +159,10 @@ client_start(NMDhcpManager * self,
GError ** error)
{
NMDhcpManagerPrivate *priv;
NMDhcpClient * client;
gboolean success = FALSE;
gsize hwaddr_len;
GType gtype;
gs_unref_object NMDhcpClient *client = NULL;
gboolean success = FALSE;
gsize hwaddr_len;
GType gtype;
g_return_val_if_fail(NM_IS_DHCP_MANAGER(self), NULL);
g_return_val_if_fail(iface, NULL);
@ -270,20 +211,6 @@ client_start(NMDhcpManager * self,
priv = NM_DHCP_MANAGER_GET_PRIVATE(self);
/* Kill any old client instance */
client = get_client_for_ifindex(self, addr_family, ifindex);
if (client) {
/* FIXME: we cannot just call synchronously "stop()" and forget about the client.
* We need to wait for the client to be fully stopped because most/all clients
* cannot quit right away.
*
* FIXME(shutdown): also fix this during shutdown, to wait for all DHCP clients
* to be fully stopped. */
remove_client(self, client);
nm_dhcp_client_stop(client, FALSE);
g_object_unref(client);
}
gtype = _client_factory_get_gtype(priv->client_factory, addr_family);
nm_log_trace(LOGD_DHCP,
@ -332,12 +259,6 @@ client_start(NMDhcpManager * self,
NM_DHCP_CLIENT_ANYCAST_ADDRESS,
anycast_address,
NULL);
nm_assert(client && c_list_is_empty(&client->dhcp_client_lst));
c_list_link_tail(&priv->dhcp_client_lst_head, &client->dhcp_client_lst);
g_signal_connect(client,
NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED,
G_CALLBACK(client_state_changed),
self);
/* unfortunately, our implementations work differently per address-family regarding client-id/DUID.
*
@ -377,12 +298,10 @@ client_start(NMDhcpManager * self,
error);
}
if (!success) {
remove_client_unref(self, client);
if (!success)
return NULL;
}
return g_object_ref(client);
return g_steal_pointer(&client);
}
/* Caller owns a reference to the NMDhcpClient on return */
@ -588,8 +507,6 @@ nm_dhcp_manager_init(NMDhcpManager *self)
int i;
const NMDhcpClientFactory *client_factory = NULL;
c_list_init(&priv->dhcp_client_lst_head);
for (i = 0; i < (int) G_N_ELEMENTS(_nm_dhcp_manager_factories); i++) {
const NMDhcpClientFactory *f = _nm_dhcp_manager_factories[i];
@ -660,10 +577,6 @@ dispose(GObject *object)
{
NMDhcpManager * self = NM_DHCP_MANAGER(object);
NMDhcpManagerPrivate *priv = NM_DHCP_MANAGER_GET_PRIVATE(self);
NMDhcpClient * client, *client_safe;
c_list_for_each_entry_safe (client, client_safe, &priv->dhcp_client_lst_head, dhcp_client_lst)
remove_client_unref(self, client);
G_OBJECT_CLASS(nm_dhcp_manager_parent_class)->dispose(object);

View file

@ -96,6 +96,16 @@ static gboolean timeout_expire_cb(gpointer user_data);
/*****************************************************************************/
NM_UTILS_LOOKUP_STR_DEFINE(nm_ndisc_dhcp_level_to_string,
NMNDiscDHCPLevel,
NM_UTILS_LOOKUP_DEFAULT("INVALID"),
NM_UTILS_LOOKUP_STR_ITEM(NM_NDISC_DHCP_LEVEL_UNKNOWN, "unknown"),
NM_UTILS_LOOKUP_STR_ITEM(NM_NDISC_DHCP_LEVEL_NONE, "none"),
NM_UTILS_LOOKUP_STR_ITEM(NM_NDISC_DHCP_LEVEL_OTHERCONF, "otherconf"),
NM_UTILS_LOOKUP_STR_ITEM(NM_NDISC_DHCP_LEVEL_MANAGED, "managed"), );
/*****************************************************************************/
NML3ConfigData *
nm_ndisc_data_to_l3cd(NMDedupMultiIndex * multi_idx,
int ifindex,
@ -1211,21 +1221,6 @@ config_map_to_string(NMNDiscConfigMap map, char *p)
*p = '\0';
}
static const char *
dhcp_level_to_string(NMNDiscDHCPLevel dhcp_level)
{
switch (dhcp_level) {
case NM_NDISC_DHCP_LEVEL_NONE:
return "none";
case NM_NDISC_DHCP_LEVEL_OTHERCONF:
return "otherconf";
case NM_NDISC_DHCP_LEVEL_MANAGED:
return "managed";
default:
return "INVALID";
}
}
static void
_config_changed_log(NMNDisc *ndisc, NMNDiscConfigMap changed)
{
@ -1248,7 +1243,7 @@ _config_changed_log(NMNDisc *ndisc, NMNDiscConfigMap changed)
config_map_to_string(changed, changedstr);
_LOGD("neighbor discovery configuration changed [%s]:", changedstr);
_LOGD(" dhcp-level %s", dhcp_level_to_string(priv->rdata.public.dhcp_level));
_LOGD(" dhcp-level %s", nm_ndisc_dhcp_level_to_string(priv->rdata.public.dhcp_level));
if (rdata->public.hop_limit)
_LOGD(" hop limit : %d", rdata->public.hop_limit);

View file

@ -48,6 +48,8 @@ typedef enum {
NM_NDISC_DHCP_LEVEL_MANAGED
} NMNDiscDHCPLevel;
const char *nm_ndisc_dhcp_level_to_string(NMNDiscDHCPLevel level);
#define NM_NDISC_INFINITY_U32 ((uint32_t) -1)
/* It's important that this is G_MAXINT64, so that we can meaningfully do

View file

@ -92,24 +92,29 @@ static struct {
/*****************************************************************************/
static void
dhcp4_state_changed(NMDhcpClient *client,
NMDhcpState state,
NMIP4Config * ip4_config,
GHashTable * options,
gpointer user_data)
_dhcp_client_notify_cb(NMDhcpClient * client,
const NMDhcpClientNotifyData *notify_data,
gpointer user_data)
{
static NMIP4Config *last_config = NULL;
NMIP4Config * existing;
gs_unref_ptrarray GPtrArray *ip4_dev_route_blacklist = NULL;
gs_free_error GError *error = NULL;
NMIP4Config * ip4_config;
g_return_if_fail(!ip4_config || NM_IS_IP4_CONFIG(ip4_config));
if (!notify_data || notify_data->notify_type != NM_DHCP_CLIENT_NOTIFY_TYPE_STATE_CHANGED)
g_return_if_reached();
_LOGD(LOGD_DHCP4, "new DHCPv4 client state %d", state);
nm_assert(!notify_data->state_changed.ip_config
|| NM_IS_IP4_CONFIG(notify_data->state_changed.ip_config));
switch (state) {
_LOGD(LOGD_DHCP4, "new DHCPv4 client state %d", (int) notify_data->state_changed.dhcp_state);
switch (notify_data->state_changed.dhcp_state) {
case NM_DHCP_STATE_BOUND:
case NM_DHCP_STATE_EXTENDED:
ip4_config = NM_IP4_CONFIG(notify_data->state_changed.ip_config);
g_assert(ip4_config);
g_assert(nm_ip4_config_get_ifindex(ip4_config) == gl.ifindex);
@ -684,8 +689,8 @@ main(int argc, char *argv[])
g_error("failure to start DHCP: %s", error->message);
g_signal_connect(dhcp4_client,
NM_DHCP_CLIENT_SIGNAL_STATE_CHANGED,
G_CALLBACK(dhcp4_state_changed),
NM_DHCP_CLIENT_NOTIFY,
G_CALLBACK(_dhcp_client_notify_cb),
NULL);
}

View file

@ -2867,7 +2867,7 @@ recheck_assume_connection(NMManager *self, NMDevice *device)
_LOG2D(LOGD_DEVICE,
device,
"assume: don't assume due to device state %s",
nm_device_state_to_str(state));
nm_device_state_to_string(state));
return FALSE;
}

View file

@ -2059,7 +2059,7 @@ device_state_changed(NMDevice * device,
_LOGD(LOGD_DEVICE,
"blocking autoconnect of connection '%s': %s",
nm_settings_connection_get_id(sett_conn),
NM_UTILS_LOOKUP_STR_A(nm_device_state_reason_to_str,
NM_UTILS_LOOKUP_STR_A(nm_device_state_reason_to_string,
nm_device_state_reason_check(reason)));
nm_settings_connection_autoconnect_blocked_reason_set(sett_conn,
blocked_reason,

View file

@ -209,6 +209,13 @@ typedef uint64_t _nm_bitwise nm_be64_t;
} while (0)
#endif
/* This is similar nm_assert_not_reached(), but it's supposed to be used only during
* development. Like _XXX_ comments, they can be used as a marker that something still
* needs to be done. */
#define XXX(msg) \
nm_assert(!"X" \
"XX error: " msg "")
#define nm_assert_unreachable_val(val) \
({ \
nm_assert_not_reached(); \