mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-02 21:20:37 +01:00
merge: branch 'bg/dhcp6-dad' into nm-1-38
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1284
This commit is contained in:
commit
4fac7c4a42
9 changed files with 642 additions and 433 deletions
File diff suppressed because it is too large
Load diff
|
|
@ -27,16 +27,16 @@
|
|||
#define NM_DHCP_CLIENT_NOTIFY "dhcp-notify"
|
||||
|
||||
typedef enum {
|
||||
NM_DHCP_STATE_UNKNOWN = 0,
|
||||
NM_DHCP_STATE_BOUND, /* new lease */
|
||||
NM_DHCP_STATE_EXTENDED, /* lease extended */
|
||||
NM_DHCP_STATE_TIMEOUT, /* timed out contacting server */
|
||||
NM_DHCP_STATE_DONE, /* client reported it's stopping */
|
||||
NM_DHCP_STATE_EXPIRE, /* lease expired or NAKed */
|
||||
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 */
|
||||
} NMDhcpState;
|
||||
NM_DHCP_CLIENT_EVENT_TYPE_UNSPECIFIED,
|
||||
|
||||
NM_DHCP_CLIENT_EVENT_TYPE_BOUND,
|
||||
NM_DHCP_CLIENT_EVENT_TYPE_EXTENDED,
|
||||
|
||||
NM_DHCP_CLIENT_EVENT_TYPE_TIMEOUT,
|
||||
NM_DHCP_CLIENT_EVENT_TYPE_EXPIRE,
|
||||
NM_DHCP_CLIENT_EVENT_TYPE_FAIL,
|
||||
NM_DHCP_CLIENT_EVENT_TYPE_TERMINATED,
|
||||
} NMDhcpClientEventType;
|
||||
|
||||
typedef enum _nm_packed {
|
||||
NM_DHCP_CLIENT_NOTIFY_TYPE_LEASE_UPDATE,
|
||||
|
|
@ -82,17 +82,8 @@ typedef struct {
|
|||
};
|
||||
} NMDhcpClientNotifyData;
|
||||
|
||||
const char *nm_dhcp_state_to_string(NMDhcpState state);
|
||||
const char *nm_dhcp_client_event_type_to_string(NMDhcpClientEventType client_event_type);
|
||||
|
||||
/* FIXME(l3cfg:dhcp:config): nm_dhcp_manager_start_ip[46]() has a gazillion of parameters,
|
||||
* those get passed on as CONSTRUCT_ONLY properties to the NMDhcpClient. Drop
|
||||
* all these parameters, and let the caller provide one NMDhcpClientConfig
|
||||
* instance. There will be only one GObject property (NM_DHCP_CLIENT_CONFIG),
|
||||
* which is CONSTRUCT_ONLY and takes a (mandatory) G_TYPE_POINTER for the
|
||||
* configuration.
|
||||
*
|
||||
* Since NMDhcpClientConfig has an addr_family, we also don't need separate
|
||||
* nm_dhcp_manager_start_ip[46]() methods. */
|
||||
typedef struct {
|
||||
int addr_family;
|
||||
|
||||
|
|
@ -156,12 +147,13 @@ typedef struct {
|
|||
|
||||
union {
|
||||
struct {
|
||||
/* The address from the previous lease */
|
||||
const char *last_address;
|
||||
|
||||
/* Set BOOTP broadcast flag in request packets, so that servers
|
||||
* will always broadcast replies. */
|
||||
bool request_broadcast : 1;
|
||||
|
||||
/* The address from the previous lease */
|
||||
const char *last_address;
|
||||
} v4;
|
||||
struct {
|
||||
/* If set, the DUID from the connection is used; otherwise
|
||||
|
|
@ -208,9 +200,12 @@ typedef struct {
|
|||
|
||||
gboolean (*ip4_start)(NMDhcpClient *self, GError **error);
|
||||
|
||||
gboolean (*accept)(NMDhcpClient *self, GError **error);
|
||||
gboolean (*accept)(NMDhcpClient *self, const NML3ConfigData *l3cd, GError **error);
|
||||
|
||||
gboolean (*decline)(NMDhcpClient *self, const char *error_message, GError **error);
|
||||
gboolean (*decline)(NMDhcpClient *self,
|
||||
const NML3ConfigData *l3cd,
|
||||
const char *error_message,
|
||||
GError **error);
|
||||
|
||||
gboolean (*ip6_start)(NMDhcpClient *self, const struct in6_addr *ll_addr, GError **error);
|
||||
|
||||
|
|
@ -230,8 +225,7 @@ typedef struct {
|
|||
|
||||
GType nm_dhcp_client_get_type(void);
|
||||
|
||||
gboolean nm_dhcp_client_start_ip4(NMDhcpClient *self, GError **error);
|
||||
gboolean nm_dhcp_client_start_ip6(NMDhcpClient *self, GError **error);
|
||||
gboolean nm_dhcp_client_start(NMDhcpClient *self, GError **error);
|
||||
|
||||
const NMDhcpClientConfig *nm_dhcp_client_get_config(NMDhcpClient *self);
|
||||
|
||||
|
|
@ -250,11 +244,6 @@ nm_dhcp_client_get_lease(NMDhcpClient *self)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
void nm_dhcp_client_stop(NMDhcpClient *self, gboolean release);
|
||||
|
||||
/* Backend helpers for subclasses */
|
||||
|
|
@ -268,15 +257,17 @@ void nm_dhcp_client_watch_child(NMDhcpClient *self, pid_t pid);
|
|||
|
||||
void nm_dhcp_client_stop_watch_child(NMDhcpClient *self, pid_t pid);
|
||||
|
||||
void
|
||||
nm_dhcp_client_set_state(NMDhcpClient *self, NMDhcpState new_state, const NML3ConfigData *l3cd);
|
||||
void _nm_dhcp_client_notify(NMDhcpClient *self,
|
||||
NMDhcpClientEventType client_event_type,
|
||||
const NML3ConfigData *l3cd);
|
||||
|
||||
gboolean nm_dhcp_client_handle_event(gpointer unused,
|
||||
const char *iface,
|
||||
int pid,
|
||||
GVariant *options,
|
||||
const char *reason,
|
||||
NMDhcpClient *self);
|
||||
gboolean nm_dhcp_client_handle_event(gpointer unused,
|
||||
const char *iface,
|
||||
int pid,
|
||||
GVariant *options,
|
||||
const char *reason,
|
||||
GDBusMethodInvocation *invocation,
|
||||
NMDhcpClient *self);
|
||||
|
||||
void nm_dhcp_client_emit_ipv6_prefix_delegated(NMDhcpClient *self,
|
||||
const NMPlatformIP6Address *prefix);
|
||||
|
|
|
|||
|
|
@ -100,21 +100,6 @@ next:;
|
|||
return g_variant_ref_sink(g_variant_new("(a{sv})", &builder));
|
||||
}
|
||||
|
||||
static void
|
||||
kill_pid(void)
|
||||
{
|
||||
const char *pid_str;
|
||||
pid_t pid = 0;
|
||||
|
||||
pid_str = getenv("pid");
|
||||
if (pid_str)
|
||||
pid = strtol(pid_str, NULL, 10);
|
||||
if (pid) {
|
||||
_LOGI("a fatal error occurred, kill dhclient instance with pid %d", pid);
|
||||
kill(pid, SIGTERM);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
|
@ -180,7 +165,7 @@ do_notify:
|
|||
parameters,
|
||||
NULL,
|
||||
G_DBUS_CALL_FLAGS_NONE,
|
||||
1000,
|
||||
60000,
|
||||
NULL,
|
||||
&error);
|
||||
|
||||
|
|
@ -236,7 +221,5 @@ do_notify:
|
|||
}
|
||||
|
||||
out:
|
||||
if (!success)
|
||||
kill_pid();
|
||||
return success ? EXIT_SUCCESS : EXIT_FAILURE;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -128,7 +128,7 @@ get_option(GVariant *options, const char *key)
|
|||
}
|
||||
|
||||
static void
|
||||
_method_call_handle(NMDhcpListener *self, GVariant *parameters)
|
||||
_method_call_handle(NMDhcpListener *self, GDBusMethodInvocation *invocation, GVariant *parameters)
|
||||
{
|
||||
gs_free char *iface = NULL;
|
||||
gs_free char *pid_str = NULL;
|
||||
|
|
@ -142,23 +142,23 @@ _method_call_handle(NMDhcpListener *self, GVariant *parameters)
|
|||
iface = get_option(options, "interface");
|
||||
if (iface == NULL) {
|
||||
_LOGW("dhcp-event: didn't have associated interface.");
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
|
||||
pid_str = get_option(options, "pid");
|
||||
pid = _nm_utils_ascii_str_to_int64(pid_str, 10, 0, G_MAXINT32, -1);
|
||||
if (pid == -1) {
|
||||
_LOGW("dhcp-event: couldn't convert PID '%s' to an integer", pid_str ?: "(null)");
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
|
||||
reason = get_option(options, "reason");
|
||||
if (reason == NULL) {
|
||||
_LOGW("dhcp-event: (pid %d) DHCP event didn't have a reason", pid);
|
||||
return;
|
||||
goto out;
|
||||
}
|
||||
|
||||
g_signal_emit(self, signals[EVENT], 0, iface, pid, options, reason, &handled);
|
||||
g_signal_emit(self, signals[EVENT], 0, iface, pid, options, reason, invocation, &handled);
|
||||
if (!handled) {
|
||||
if (g_ascii_strcasecmp(reason, "RELEASE") == 0) {
|
||||
/* Ignore event when the dhcp client gets killed and we receive its last message */
|
||||
|
|
@ -166,6 +166,10 @@ _method_call_handle(NMDhcpListener *self, GVariant *parameters)
|
|||
} else
|
||||
_LOGW("dhcp-event: (pid %d) unhandled DHCP event for interface %s", pid, iface);
|
||||
}
|
||||
|
||||
out:
|
||||
if (!handled)
|
||||
g_dbus_method_invocation_return_value(invocation, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -190,8 +194,7 @@ _method_call(GDBusConnection *connection,
|
|||
return;
|
||||
}
|
||||
|
||||
_method_call_handle(self, parameters);
|
||||
g_dbus_method_invocation_return_value(invocation, NULL);
|
||||
_method_call_handle(self, invocation, parameters);
|
||||
}
|
||||
|
||||
static GDBusInterfaceInfo *const interface_info = NM_DEFINE_GDBUS_INTERFACE_INFO(
|
||||
|
|
@ -311,9 +314,10 @@ nm_dhcp_listener_class_init(NMDhcpListenerClass *listener_class)
|
|||
NULL,
|
||||
NULL,
|
||||
G_TYPE_BOOLEAN, /* listeners return TRUE if handled */
|
||||
4,
|
||||
5,
|
||||
G_TYPE_STRING, /* iface */
|
||||
G_TYPE_INT, /* pid */
|
||||
G_TYPE_VARIANT, /* options */
|
||||
G_TYPE_STRING); /* reason */
|
||||
G_TYPE_STRING, /* reason */
|
||||
G_TYPE_DBUS_METHOD_INVOCATION /* invocation*/);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -131,8 +131,7 @@ NMDhcpClient *
|
|||
nm_dhcp_manager_start_client(NMDhcpManager *self, NMDhcpClientConfig *config, GError **error)
|
||||
{
|
||||
NMDhcpManagerPrivate *priv;
|
||||
gs_unref_object NMDhcpClient *client = NULL;
|
||||
gboolean success = FALSE;
|
||||
gs_unref_object NMDhcpClient *client = NULL;
|
||||
gsize hwaddr_len;
|
||||
GType gtype;
|
||||
|
||||
|
|
@ -202,13 +201,7 @@ nm_dhcp_manager_start_client(NMDhcpManager *self, NMDhcpClientConfig *config, GE
|
|||
* default outside of NetworkManager API.
|
||||
*/
|
||||
|
||||
if (config->addr_family == AF_INET) {
|
||||
success = nm_dhcp_client_start_ip4(client, error);
|
||||
} else {
|
||||
success = nm_dhcp_client_start_ip6(client, error);
|
||||
}
|
||||
|
||||
if (!success)
|
||||
if (!nm_dhcp_client_start(client, error))
|
||||
return NULL;
|
||||
|
||||
return g_steal_pointer(&client);
|
||||
|
|
|
|||
|
|
@ -50,9 +50,14 @@ typedef struct _NMDhcpNettoolsClass NMDhcpNettoolsClass;
|
|||
typedef struct {
|
||||
NDhcp4Client *client;
|
||||
NDhcp4ClientProbe *probe;
|
||||
NDhcp4ClientLease *lease;
|
||||
GSource *event_source;
|
||||
char *lease_file;
|
||||
|
||||
struct {
|
||||
NDhcp4ClientLease *lease;
|
||||
const NML3ConfigData *lease_l3cd;
|
||||
} granted;
|
||||
|
||||
GSource *event_source;
|
||||
char *lease_file;
|
||||
} NMDhcpNettoolsPrivate;
|
||||
|
||||
struct _NMDhcpNettools {
|
||||
|
|
@ -778,15 +783,19 @@ lease_save(NMDhcpNettools *self, NDhcp4ClientLease *lease, const char *lease_fil
|
|||
}
|
||||
|
||||
static void
|
||||
bound4_handle(NMDhcpNettools *self, NDhcp4ClientLease *lease, gboolean extended)
|
||||
bound4_handle(NMDhcpNettools *self, guint event, NDhcp4ClientLease *lease)
|
||||
{
|
||||
NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self);
|
||||
NMDhcpClient *client = NM_DHCP_CLIENT(self);
|
||||
const NMDhcpClientConfig *client_config;
|
||||
nm_auto_unref_l3cd_init NML3ConfigData *l3cd = NULL;
|
||||
GError *error = NULL;
|
||||
gs_free_error GError *error = NULL;
|
||||
|
||||
nm_assert(NM_IN_SET(event, N_DHCP4_CLIENT_EVENT_GRANTED, N_DHCP4_CLIENT_EVENT_EXTENDED));
|
||||
nm_assert(lease);
|
||||
|
||||
_LOGT("lease available (%s)", (event == N_DHCP4_CLIENT_EVENT_GRANTED) ? "granted" : "extended");
|
||||
|
||||
_LOGT("lease available (%s)", extended ? "extended" : "new");
|
||||
client_config = nm_dhcp_client_get_config(client);
|
||||
l3cd = lease_to_ip4_config(nm_dhcp_client_get_multi_idx(client),
|
||||
client_config->iface,
|
||||
|
|
@ -795,29 +804,51 @@ bound4_handle(NMDhcpNettools *self, NDhcp4ClientLease *lease, gboolean extended)
|
|||
&error);
|
||||
if (!l3cd) {
|
||||
_LOGW("failure to parse lease: %s", error->message);
|
||||
g_clear_error(&error);
|
||||
nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL);
|
||||
|
||||
if (event == N_DHCP4_CLIENT_EVENT_GRANTED)
|
||||
n_dhcp4_client_lease_decline(lease, "invalid lease");
|
||||
|
||||
_nm_dhcp_client_notify(NM_DHCP_CLIENT(self), NM_DHCP_CLIENT_EVENT_TYPE_FAIL, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
lease_save(self, lease, priv->lease_file);
|
||||
if (event == N_DHCP4_CLIENT_EVENT_GRANTED) {
|
||||
priv->granted.lease = n_dhcp4_client_lease_ref(lease);
|
||||
priv->granted.lease_l3cd = nm_l3_config_data_ref(l3cd);
|
||||
} else
|
||||
lease_save(self, lease, priv->lease_file);
|
||||
|
||||
nm_dhcp_client_set_state(NM_DHCP_CLIENT(self),
|
||||
extended ? NM_DHCP_STATE_EXTENDED : NM_DHCP_STATE_BOUND,
|
||||
l3cd);
|
||||
_nm_dhcp_client_notify(NM_DHCP_CLIENT(self),
|
||||
event == N_DHCP4_CLIENT_EVENT_GRANTED
|
||||
? NM_DHCP_CLIENT_EVENT_TYPE_BOUND
|
||||
: NM_DHCP_CLIENT_EVENT_TYPE_EXTENDED,
|
||||
l3cd);
|
||||
}
|
||||
|
||||
static void
|
||||
dhcp4_event_handle(NMDhcpNettools *self, NDhcp4ClientEvent *event)
|
||||
{
|
||||
NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self);
|
||||
const NMDhcpClientConfig *client_config;
|
||||
struct in_addr server_id;
|
||||
char addr_str[INET_ADDRSTRLEN];
|
||||
int r;
|
||||
NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self);
|
||||
struct in_addr server_id;
|
||||
struct in_addr yiaddr;
|
||||
char addr_str[INET_ADDRSTRLEN];
|
||||
char addr_str2[INET_ADDRSTRLEN];
|
||||
int r;
|
||||
|
||||
_LOGT("client event %d", event->event);
|
||||
client_config = nm_dhcp_client_get_config(NM_DHCP_CLIENT(self));
|
||||
if (event->event == N_DHCP4_CLIENT_EVENT_LOG) {
|
||||
_NMLOG(nm_log_level_from_syslog(event->log.level), "event: %s", event->log.message);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!NM_IN_SET(event->event, N_DHCP4_CLIENT_EVENT_LOG)) {
|
||||
/* In almost all events (even those that we don't expect below), we clear
|
||||
* the currently granted lease. That is, because in GRANTED state we
|
||||
* expect to follow up with accept/decline, and that only works while
|
||||
* we are still in the same state. Transitioning away to another state
|
||||
* (on most events) will invalidate that. */
|
||||
nm_clear_pointer(&priv->granted.lease, n_dhcp4_client_lease_unref);
|
||||
nm_clear_l3cd(&priv->granted.lease_l3cd);
|
||||
}
|
||||
|
||||
switch (event->event) {
|
||||
case N_DHCP4_CLIENT_EVENT_OFFER:
|
||||
|
|
@ -827,53 +858,51 @@ dhcp4_event_handle(NMDhcpNettools *self, NDhcp4ClientEvent *event)
|
|||
return;
|
||||
}
|
||||
|
||||
n_dhcp4_client_lease_get_yiaddr(event->offer.lease, &yiaddr);
|
||||
if (yiaddr.s_addr == INADDR_ANY) {
|
||||
_LOGD("selecting lease failed: no yiaddr address");
|
||||
return;
|
||||
}
|
||||
|
||||
if (nm_dhcp_client_server_id_is_rejected(NM_DHCP_CLIENT(self), &server_id)) {
|
||||
_LOGD("server-id %s is in the reject-list, ignoring",
|
||||
nm_utils_inet_ntop(AF_INET, &server_id, addr_str));
|
||||
return;
|
||||
}
|
||||
|
||||
_LOGT("selecting offered lease from %s for %s",
|
||||
_nm_utils_inet4_ntop(server_id.s_addr, addr_str),
|
||||
_nm_utils_inet4_ntop(yiaddr.s_addr, addr_str2));
|
||||
|
||||
r = n_dhcp4_client_lease_select(event->offer.lease);
|
||||
if (r) {
|
||||
_LOGW("selecting lease failed: %d", r);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
|
||||
return;
|
||||
case N_DHCP4_CLIENT_EVENT_RETRACTED:
|
||||
case N_DHCP4_CLIENT_EVENT_EXPIRED:
|
||||
nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_EXPIRE, NULL);
|
||||
break;
|
||||
_nm_dhcp_client_notify(NM_DHCP_CLIENT(self), NM_DHCP_CLIENT_EVENT_TYPE_EXPIRE, NULL);
|
||||
return;
|
||||
case N_DHCP4_CLIENT_EVENT_CANCELLED:
|
||||
nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL);
|
||||
break;
|
||||
_nm_dhcp_client_notify(NM_DHCP_CLIENT(self), NM_DHCP_CLIENT_EVENT_TYPE_FAIL, NULL);
|
||||
return;
|
||||
case N_DHCP4_CLIENT_EVENT_GRANTED:
|
||||
priv->lease = n_dhcp4_client_lease_ref(event->granted.lease);
|
||||
bound4_handle(self, event->granted.lease, FALSE);
|
||||
break;
|
||||
bound4_handle(self, event->event, event->granted.lease);
|
||||
return;
|
||||
case N_DHCP4_CLIENT_EVENT_EXTENDED:
|
||||
bound4_handle(self, event->extended.lease, TRUE);
|
||||
break;
|
||||
bound4_handle(self, event->event, event->extended.lease);
|
||||
return;
|
||||
case N_DHCP4_CLIENT_EVENT_DOWN:
|
||||
/* ignore down events, they are purely informational */
|
||||
break;
|
||||
case N_DHCP4_CLIENT_EVENT_LOG:
|
||||
{
|
||||
NMLogLevel nm_level;
|
||||
|
||||
nm_level = nm_log_level_from_syslog(event->log.level);
|
||||
if (nm_logging_enabled(nm_level, LOGD_DHCP4)) {
|
||||
nm_log(nm_level,
|
||||
LOGD_DHCP4,
|
||||
NULL,
|
||||
NULL,
|
||||
"dhcp4 (%s): %s",
|
||||
client_config->iface,
|
||||
event->log.message);
|
||||
}
|
||||
} break;
|
||||
_LOGT("event: down (ignore)");
|
||||
return;
|
||||
default:
|
||||
_LOGW("unhandled DHCP event %d", event->event);
|
||||
break;
|
||||
_LOGE("unhandled DHCP event %d", event->event);
|
||||
nm_assert(event->event != N_DHCP4_CLIENT_EVENT_LOG);
|
||||
nm_assert_not_reached();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -896,7 +925,7 @@ dhcp4_event_cb(int fd, GIOCondition condition, gpointer user_data)
|
|||
*/
|
||||
_LOGE("error %d dispatching events", r);
|
||||
nm_clear_g_source_inst(&priv->event_source);
|
||||
nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL);
|
||||
_nm_dhcp_client_notify(NM_DHCP_CLIENT(self), NM_DHCP_CLIENT_EVENT_TYPE_FAIL, NULL);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
||||
|
|
@ -1008,46 +1037,65 @@ nettools_create(NMDhcpNettools *self, GError **error)
|
|||
}
|
||||
|
||||
static gboolean
|
||||
_accept(NMDhcpClient *client, GError **error)
|
||||
_accept(NMDhcpClient *client, const NML3ConfigData *l3cd, GError **error)
|
||||
{
|
||||
NMDhcpNettools *self = NM_DHCP_NETTOOLS(client);
|
||||
NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self);
|
||||
int r;
|
||||
|
||||
g_return_val_if_fail(priv->lease, FALSE);
|
||||
|
||||
_LOGT("accept");
|
||||
|
||||
r = n_dhcp4_client_lease_accept(priv->lease);
|
||||
g_return_val_if_fail(l3cd, FALSE);
|
||||
|
||||
if (priv->granted.lease_l3cd != l3cd) {
|
||||
nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, "calling accept in unexpected state");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
nm_assert(priv->granted.lease);
|
||||
|
||||
r = n_dhcp4_client_lease_accept(priv->granted.lease);
|
||||
|
||||
nm_clear_pointer(&priv->granted.lease, n_dhcp4_client_lease_unref);
|
||||
nm_clear_l3cd(&priv->granted.lease_l3cd);
|
||||
|
||||
if (r) {
|
||||
set_error_nettools(error, r, "failed to accept lease");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
priv->lease = n_dhcp4_client_lease_unref(priv->lease);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
decline(NMDhcpClient *client, const char *error_message, GError **error)
|
||||
decline(NMDhcpClient *client, const NML3ConfigData *l3cd, const char *error_message, GError **error)
|
||||
{
|
||||
NMDhcpNettools *self = NM_DHCP_NETTOOLS(client);
|
||||
NMDhcpNettoolsPrivate *priv = NM_DHCP_NETTOOLS_GET_PRIVATE(self);
|
||||
int r;
|
||||
nm_auto(n_dhcp4_client_lease_unrefp) NDhcp4ClientLease *lease = NULL;
|
||||
|
||||
g_return_val_if_fail(priv->lease, FALSE);
|
||||
_LOGT("decline (%s)", error_message);
|
||||
|
||||
_LOGT("dhcp4-client: decline (%s)", error_message);
|
||||
g_return_val_if_fail(l3cd, FALSE);
|
||||
|
||||
if (priv->granted.lease_l3cd != l3cd) {
|
||||
nm_utils_error_set(error, NM_UTILS_ERROR_UNKNOWN, "calling decline in unexpected state");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
nm_assert(priv->granted.lease);
|
||||
|
||||
lease = g_steal_pointer(&priv->granted.lease);
|
||||
nm_clear_l3cd(&priv->granted.lease_l3cd);
|
||||
|
||||
r = n_dhcp4_client_lease_decline(lease, error_message);
|
||||
|
||||
r = n_dhcp4_client_lease_decline(priv->lease, error_message);
|
||||
if (r) {
|
||||
set_error_nettools(error, r, "failed to decline lease");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
priv->lease = n_dhcp4_client_lease_unref(priv->lease);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
|
@ -1256,7 +1304,8 @@ dispose(GObject *object)
|
|||
|
||||
nm_clear_g_free(&priv->lease_file);
|
||||
nm_clear_g_source_inst(&priv->event_source);
|
||||
nm_clear_pointer(&priv->lease, n_dhcp4_client_lease_unref);
|
||||
nm_clear_pointer(&priv->granted.lease, n_dhcp4_client_lease_unref);
|
||||
nm_clear_l3cd(&priv->granted.lease_l3cd);
|
||||
nm_clear_pointer(&priv->probe, n_dhcp4_client_probe_free);
|
||||
nm_clear_pointer(&priv->client, n_dhcp4_client_unref);
|
||||
|
||||
|
|
|
|||
|
|
@ -459,7 +459,7 @@ bound4_handle(NMDhcpSystemd *self, gboolean extended)
|
|||
|
||||
if (sd_dhcp_client_get_lease(priv->client4, &lease) < 0 || !lease) {
|
||||
_LOGW("no lease!");
|
||||
nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL);
|
||||
_nm_dhcp_client_notify(NM_DHCP_CLIENT(self), NM_DHCP_CLIENT_EVENT_TYPE_FAIL, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -473,15 +473,16 @@ bound4_handle(NMDhcpSystemd *self, gboolean extended)
|
|||
if (!l3cd) {
|
||||
_LOGW("%s", error->message);
|
||||
g_clear_error(&error);
|
||||
nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL);
|
||||
_nm_dhcp_client_notify(NM_DHCP_CLIENT(self), NM_DHCP_CLIENT_EVENT_TYPE_FAIL, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
dhcp_lease_save(lease, priv->lease_file);
|
||||
|
||||
nm_dhcp_client_set_state(NM_DHCP_CLIENT(self),
|
||||
extended ? NM_DHCP_STATE_EXTENDED : NM_DHCP_STATE_BOUND,
|
||||
l3cd);
|
||||
_nm_dhcp_client_notify(NM_DHCP_CLIENT(self),
|
||||
extended ? NM_DHCP_CLIENT_EVENT_TYPE_EXTENDED
|
||||
: NM_DHCP_CLIENT_EVENT_TYPE_BOUND,
|
||||
l3cd);
|
||||
}
|
||||
|
||||
static int
|
||||
|
|
@ -500,10 +501,10 @@ dhcp_event_cb(sd_dhcp_client *client, int event, gpointer user_data)
|
|||
|
||||
switch (event) {
|
||||
case SD_DHCP_CLIENT_EVENT_EXPIRED:
|
||||
nm_dhcp_client_set_state(NM_DHCP_CLIENT(user_data), NM_DHCP_STATE_EXPIRE, NULL);
|
||||
_nm_dhcp_client_notify(NM_DHCP_CLIENT(user_data), NM_DHCP_CLIENT_EVENT_TYPE_EXPIRE, NULL);
|
||||
break;
|
||||
case SD_DHCP_CLIENT_EVENT_STOP:
|
||||
nm_dhcp_client_set_state(NM_DHCP_CLIENT(user_data), NM_DHCP_STATE_FAIL, NULL);
|
||||
_nm_dhcp_client_notify(NM_DHCP_CLIENT(user_data), NM_DHCP_CLIENT_EVENT_TYPE_FAIL, NULL);
|
||||
break;
|
||||
case SD_DHCP_CLIENT_EVENT_RENEW:
|
||||
case SD_DHCP_CLIENT_EVENT_IP_CHANGE:
|
||||
|
|
@ -876,7 +877,7 @@ bound6_handle(NMDhcpSystemd *self)
|
|||
|
||||
if (sd_dhcp6_client_get_lease(priv->client6, &lease) < 0 || !lease) {
|
||||
_LOGW(" no lease!");
|
||||
nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL);
|
||||
_nm_dhcp_client_notify(NM_DHCP_CLIENT(self), NM_DHCP_CLIENT_EVENT_TYPE_FAIL, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -892,11 +893,11 @@ bound6_handle(NMDhcpSystemd *self)
|
|||
|
||||
if (!l3cd) {
|
||||
_LOGW("%s", error->message);
|
||||
nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_FAIL, NULL);
|
||||
_nm_dhcp_client_notify(NM_DHCP_CLIENT(self), NM_DHCP_CLIENT_EVENT_TYPE_FAIL, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
nm_dhcp_client_set_state(NM_DHCP_CLIENT(self), NM_DHCP_STATE_BOUND, l3cd);
|
||||
_nm_dhcp_client_notify(NM_DHCP_CLIENT(self), NM_DHCP_CLIENT_EVENT_TYPE_BOUND, l3cd);
|
||||
|
||||
sd_dhcp6_lease_reset_pd_prefix_iter(lease);
|
||||
while (!sd_dhcp6_lease_get_pd(lease,
|
||||
|
|
@ -921,11 +922,11 @@ dhcp6_event_cb(sd_dhcp6_client *client, int event, gpointer user_data)
|
|||
|
||||
switch (event) {
|
||||
case SD_DHCP6_CLIENT_EVENT_RETRANS_MAX:
|
||||
nm_dhcp_client_set_state(NM_DHCP_CLIENT(user_data), NM_DHCP_STATE_TIMEOUT, NULL);
|
||||
_nm_dhcp_client_notify(NM_DHCP_CLIENT(user_data), NM_DHCP_CLIENT_EVENT_TYPE_TIMEOUT, NULL);
|
||||
break;
|
||||
case SD_DHCP6_CLIENT_EVENT_RESEND_EXPIRE:
|
||||
case SD_DHCP6_CLIENT_EVENT_STOP:
|
||||
nm_dhcp_client_set_state(NM_DHCP_CLIENT(user_data), NM_DHCP_STATE_FAIL, NULL);
|
||||
_nm_dhcp_client_notify(NM_DHCP_CLIENT(user_data), NM_DHCP_CLIENT_EVENT_TYPE_FAIL, NULL);
|
||||
break;
|
||||
case SD_DHCP6_CLIENT_EVENT_IP_ACQUIRE:
|
||||
case SD_DHCP6_CLIENT_EVENT_INFORMATION_REQUEST:
|
||||
|
|
|
|||
|
|
@ -855,8 +855,7 @@ nm_dhcp_utils_merge_new_dhcp6_lease(const NML3ConfigData *l3cd_old,
|
|||
const char *start;
|
||||
const char *iaid;
|
||||
|
||||
nm_assert(out_l3cd_merged);
|
||||
nm_assert(!*out_l3cd_merged);
|
||||
nm_assert(out_l3cd_merged && !*out_l3cd_merged);
|
||||
|
||||
if (!l3cd_old)
|
||||
return FALSE;
|
||||
|
|
|
|||
|
|
@ -623,6 +623,16 @@ nm_utils_is_separator(const char c)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline GBytes *
|
||||
nm_g_bytes_ref(GBytes *b)
|
||||
{
|
||||
if (b)
|
||||
g_bytes_ref(b);
|
||||
return b;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
GBytes *nm_g_bytes_get_empty(void);
|
||||
|
||||
GBytes *nm_g_bytes_new_from_str(const char *str);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue