mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-04 22:20:27 +01:00
dhcp: client: use logging helpers
This commit is contained in:
parent
cc19352e11
commit
d6d9f47a32
6 changed files with 193 additions and 155 deletions
|
|
@ -287,6 +287,7 @@ libNetworkManager_la_SOURCES = \
|
|||
\
|
||||
dhcp-manager/nm-dhcp-client.c \
|
||||
dhcp-manager/nm-dhcp-client.h \
|
||||
dhcp-manager/nm-dhcp-client-logging.h \
|
||||
dhcp-manager/nm-dhcp-utils.c \
|
||||
dhcp-manager/nm-dhcp-utils.h \
|
||||
dhcp-manager/nm-dhcp-listener.c \
|
||||
|
|
@ -462,6 +463,8 @@ nm_enum_types_sources = $(filter-out \
|
|||
%/nm-device-private.h \
|
||||
%/nm-rdisc-private.h \
|
||||
%/wifi-utils-private.h \
|
||||
%/nm-dhcp-client-logging.h \
|
||||
%/nm-device-logging.h \
|
||||
, $(libNetworkManager_la_SOURCES))
|
||||
|
||||
BUILT_SOURCES = $(GLIB_GENERATED)
|
||||
|
|
@ -526,6 +529,7 @@ NetworkManager_LDFLAGS = -rdynamic
|
|||
libnm_iface_helper_la_SOURCES = \
|
||||
dhcp-manager/nm-dhcp-client.c \
|
||||
dhcp-manager/nm-dhcp-client.h \
|
||||
dhcp-manager/nm-dhcp-client-logging.h \
|
||||
dhcp-manager/nm-dhcp-utils.c \
|
||||
dhcp-manager/nm-dhcp-utils.h \
|
||||
dhcp-manager/nm-dhcp-manager.c \
|
||||
|
|
|
|||
48
src/dhcp-manager/nm-dhcp-client-logging.h
Normal file
48
src/dhcp-manager/nm-dhcp-client-logging.h
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
|
||||
/* NetworkManager -- Network link manager
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Copyright (C) 2016 Red Hat, Inc.
|
||||
*/
|
||||
|
||||
#ifndef __NETWORKMANAGER_DHCP_CLIENT_LOGGING_H__
|
||||
#define __NETWORKMANAGER_DHCP_CLIENT_LOGGING_H__
|
||||
|
||||
#include "nm-default.h"
|
||||
#include "nm-dhcp-client.h"
|
||||
|
||||
#define _NMLOG_PREFIX_NAME "dhcp"
|
||||
#define _NMLOG(level, ...) \
|
||||
G_STMT_START { \
|
||||
const NMLogLevel _level = (level); \
|
||||
\
|
||||
if (nm_logging_enabled (_level, LOGD_DHCP)) { \
|
||||
NMDhcpClient *_self = (NMDhcpClient *) (self); \
|
||||
const char *__ifname = _self ? nm_dhcp_client_get_iface (_self) : NULL; \
|
||||
const NMLogDomain _domain = !_self \
|
||||
? LOGD_DHCP \
|
||||
: (nm_dhcp_client_get_ipv6 (_self) ? LOGD_DHCP6 : LOGD_DHCP4); \
|
||||
\
|
||||
nm_log (_level, _domain, \
|
||||
"%s%s%s%s%s: " _NM_UTILS_MACRO_FIRST (__VA_ARGS__), \
|
||||
_NMLOG_PREFIX_NAME, \
|
||||
(_domain == LOGD_DHCP4 ? "4" : (_domain == LOGD_DHCP6 ? "6" : "")), \
|
||||
NM_PRINT_FMT_QUOTED (__ifname, " (", __ifname, ")", "") \
|
||||
_NM_UTILS_MACRO_REST (__VA_ARGS__)); \
|
||||
} \
|
||||
} G_STMT_END
|
||||
|
||||
#endif /* __NETWORKMANAGER_DHCP_CLIENT_LOGGING_H__ */
|
||||
|
|
@ -35,6 +35,8 @@
|
|||
#include "nm-dhcp-utils.h"
|
||||
#include "nm-platform.h"
|
||||
|
||||
#include "nm-dhcp-client-logging.h"
|
||||
|
||||
typedef struct {
|
||||
char * iface;
|
||||
int ifindex;
|
||||
|
|
@ -204,7 +206,7 @@ state_to_string (NMDhcpState state)
|
|||
}
|
||||
|
||||
static NMDhcpState
|
||||
reason_to_state (const char *iface, const char *reason)
|
||||
reason_to_state (NMDhcpClient *self, const char *iface, const char *reason)
|
||||
{
|
||||
if (g_ascii_strcasecmp (reason, "bound") == 0 ||
|
||||
g_ascii_strcasecmp (reason, "bound6") == 0 ||
|
||||
|
|
@ -226,7 +228,7 @@ reason_to_state (const char *iface, const char *reason)
|
|||
g_ascii_strcasecmp (reason, "abend") == 0)
|
||||
return NM_DHCP_STATE_FAIL;
|
||||
|
||||
nm_log_dbg (LOGD_DHCP, "(%s): unmapped DHCP state '%s'", iface, reason);
|
||||
_LOGD ("unmapped DHCP state '%s'", reason);
|
||||
return NM_DHCP_STATE_UNKNOWN;
|
||||
}
|
||||
|
||||
|
|
@ -319,13 +321,10 @@ nm_dhcp_client_set_state (NMDhcpClient *self,
|
|||
event_id = g_strdup_printf ("%s|%s", iaid, start);
|
||||
}
|
||||
|
||||
nm_log_info (priv->ipv6 ? LOGD_DHCP6 : LOGD_DHCP4,
|
||||
"(%s): DHCPv%c state changed %s -> %s%s%s%s",
|
||||
priv->iface,
|
||||
priv->ipv6 ? '6' : '4',
|
||||
state_to_string (priv->state),
|
||||
state_to_string (new_state),
|
||||
NM_PRINT_FMT_QUOTED (event_id, ", event ID=\"", event_id, "\"", ""));
|
||||
_LOGI ("state changed %s -> %s%s%s%s",
|
||||
state_to_string (priv->state),
|
||||
state_to_string (new_state),
|
||||
NM_PRINT_FMT_QUOTED (event_id, ", event ID=\"", event_id, "\"", ""));
|
||||
|
||||
priv->state = new_state;
|
||||
g_signal_emit (G_OBJECT (self),
|
||||
|
|
@ -343,10 +342,7 @@ transaction_timeout (gpointer user_data)
|
|||
NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE (self);
|
||||
|
||||
priv->timeout_id = 0;
|
||||
nm_log_warn (priv->ipv6 ? LOGD_DHCP6 : LOGD_DHCP4,
|
||||
"(%s): DHCPv%c request timed out.",
|
||||
priv->iface,
|
||||
priv->ipv6 ? '6' : '4');
|
||||
_LOGW ("request timed out");
|
||||
nm_dhcp_client_set_state (self, NM_DHCP_STATE_TIMEOUT, NULL, NULL);
|
||||
return G_SOURCE_REMOVE;
|
||||
}
|
||||
|
|
@ -357,29 +353,20 @@ daemon_watch_cb (GPid pid, gint status, gpointer user_data)
|
|||
NMDhcpClient *self = NM_DHCP_CLIENT (user_data);
|
||||
NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE (self);
|
||||
NMDhcpState new_state;
|
||||
guint64 log_domain;
|
||||
guint ip_ver;
|
||||
|
||||
g_return_if_fail (priv->watch_id);
|
||||
priv->watch_id = 0;
|
||||
|
||||
log_domain = priv->ipv6 ? LOGD_DHCP6 : LOGD_DHCP4;
|
||||
ip_ver = priv->ipv6 ? 6 : 4;
|
||||
|
||||
if (WIFEXITED (status))
|
||||
nm_log_info (log_domain, "(%s): DHCPv%d client pid %d exited with status %d",
|
||||
priv->iface, ip_ver, pid, WEXITSTATUS (status));
|
||||
_LOGI ("client pid %d exited with status %d", pid, WEXITSTATUS (status));
|
||||
else if (WIFSIGNALED (status))
|
||||
nm_log_info (log_domain, "(%s): DHCPv%d client pid %d killed by signal %d",
|
||||
priv->iface, ip_ver, pid, WTERMSIG (status));
|
||||
_LOGI ("client pid %d killed by signal %d", pid, WTERMSIG (status));
|
||||
else if (WIFSTOPPED(status))
|
||||
nm_log_info (log_domain, "(%s): DHCPv%d client pid %d stopped by signal %d",
|
||||
priv->iface, ip_ver, pid, WSTOPSIG (status));
|
||||
_LOGI ("client pid %d stopped by signal %d", pid, WSTOPSIG (status));
|
||||
else if (WIFCONTINUED (status))
|
||||
nm_log_info (log_domain, "(%s): DHCPv%d client pid %d resumed (by SIGCONT)",
|
||||
priv->iface, ip_ver, pid);
|
||||
_LOGI ("client pid %d resumed (by SIGCONT)", pid);
|
||||
else
|
||||
nm_log_warn (LOGD_DHCP, "DHCP client died abnormally");
|
||||
_LOGW ("client died abnormally");
|
||||
|
||||
if (!WIFEXITED (status))
|
||||
new_state = NM_DHCP_STATE_FAIL;
|
||||
|
|
@ -434,8 +421,7 @@ nm_dhcp_client_start_ip4 (NMDhcpClient *self,
|
|||
g_return_val_if_fail (priv->ipv6 == FALSE, FALSE);
|
||||
g_return_val_if_fail (priv->uuid != NULL, FALSE);
|
||||
|
||||
nm_log_info (LOGD_DHCP, "Activation (%s) Beginning DHCPv4 transaction (timeout in %d seconds)",
|
||||
priv->iface, priv->timeout);
|
||||
_LOGI ("activation: beginning transaction (timeout in %d seconds)", priv->timeout);
|
||||
|
||||
nm_dhcp_client_set_client_id (self, dhcp_client_id ? nm_dhcp_utils_client_id_string_to_bytes (dhcp_client_id) : NULL);
|
||||
|
||||
|
|
@ -506,7 +492,7 @@ generate_duid_from_machine_id (void)
|
|||
}
|
||||
|
||||
if (!success) {
|
||||
nm_log_warn (LOGD_DHCP6, "Failed to read " SYSCONFDIR "/machine-id "
|
||||
nm_log_warn (LOGD_DHCP6, "dhcp6: failed to read " SYSCONFDIR "/machine-id "
|
||||
"or " LOCALSTATEDIR "/lib/dbus/machine-id to generate "
|
||||
"DHCPv6 DUID; creating non-persistent random DUID.");
|
||||
|
||||
|
|
@ -546,7 +532,7 @@ get_duid (NMDhcpClient *self)
|
|||
|
||||
if (nm_logging_enabled (LOGL_DEBUG, LOGD_DHCP6)) {
|
||||
str = nm_dhcp_utils_duid_to_string (duid);
|
||||
nm_log_dbg (LOGD_DHCP6, "Generated DUID %s", str);
|
||||
_LOGD ("generated DUID %s", str);
|
||||
g_free (str);
|
||||
}
|
||||
}
|
||||
|
|
@ -583,9 +569,9 @@ nm_dhcp_client_start_ip6 (NMDhcpClient *self,
|
|||
if (!priv->duid)
|
||||
priv->duid = NM_DHCP_CLIENT_GET_CLASS (self)->get_duid (self);
|
||||
|
||||
if (nm_logging_enabled (LOGL_DEBUG, LOGD_DHCP)) {
|
||||
if (nm_logging_enabled (LOGL_DEBUG, LOGD_DHCP6)) {
|
||||
str = nm_dhcp_utils_duid_to_string (priv->duid);
|
||||
nm_log_dbg (LOGD_DHCP, "(%s): DHCPv6 DUID is '%s'", priv->iface, str);
|
||||
_LOGD ("DUID is '%s'", str);
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
|
|
@ -594,8 +580,8 @@ nm_dhcp_client_start_ip6 (NMDhcpClient *self,
|
|||
|
||||
priv->info_only = info_only;
|
||||
|
||||
nm_log_info (LOGD_DHCP, "Activation (%s) Beginning DHCPv6 transaction (timeout in %d seconds)",
|
||||
priv->iface, priv->timeout);
|
||||
_LOGI ("activation: beginning transaction (timeout in %d seconds)",
|
||||
priv->timeout);
|
||||
|
||||
return NM_DHCP_CLIENT_GET_CLASS (self)->ip6_start (self,
|
||||
dhcp_anycast_addr,
|
||||
|
|
@ -645,8 +631,10 @@ nm_dhcp_client_stop_existing (const char *pid_file, const char *binary_name)
|
|||
}
|
||||
}
|
||||
|
||||
if (remove (pid_file) == -1)
|
||||
nm_log_dbg (LOGD_DHCP, "Could not remove dhcp pid file \"%s\": %d (%s)", pid_file, errno, g_strerror (errno));
|
||||
if (remove (pid_file) == -1) {
|
||||
nm_log_dbg (LOGD_DHCP, "dhcp: could not remove pid file \"%s\": %d (%s)",
|
||||
pid_file, errno, g_strerror (errno));
|
||||
}
|
||||
|
||||
g_free (proc_path);
|
||||
g_free (pid_contents);
|
||||
|
|
@ -666,11 +654,10 @@ nm_dhcp_client_stop (NMDhcpClient *self, gboolean release)
|
|||
/* Kill the DHCP client */
|
||||
old_pid = priv->pid;
|
||||
NM_DHCP_CLIENT_GET_CLASS (self)->stop (self, release, priv->duid);
|
||||
if (old_pid > 0) {
|
||||
nm_log_info (LOGD_DHCP, "(%s): canceled DHCP transaction, DHCP client pid %d",
|
||||
priv->iface, old_pid);
|
||||
} else
|
||||
nm_log_info (LOGD_DHCP, "(%s): canceled DHCP transaction", priv->iface);
|
||||
if (old_pid > 0)
|
||||
_LOGI ("canceled DHCP transaction, DHCP client pid %d", old_pid);
|
||||
else
|
||||
_LOGI ("canceled DHCP transaction");
|
||||
g_assert (priv->pid == -1);
|
||||
|
||||
nm_dhcp_client_set_state (self, NM_DHCP_STATE_DONE, NULL, NULL);
|
||||
|
|
@ -710,7 +697,7 @@ bytearray_variant_to_string (GVariant *value, const char *key)
|
|||
|
||||
converted = str->str;
|
||||
if (!g_utf8_validate (converted, -1, NULL))
|
||||
nm_log_warn (LOGD_DHCP, "DHCP option '%s' couldn't be converted to UTF-8", key);
|
||||
nm_log_warn (LOGD_DHCP, "dhcp: option '%s' couldn't be converted to UTF-8", key);
|
||||
g_string_free (str, FALSE);
|
||||
return converted;
|
||||
}
|
||||
|
|
@ -782,9 +769,9 @@ nm_dhcp_client_handle_event (gpointer unused,
|
|||
return FALSE;
|
||||
|
||||
old_state = priv->state;
|
||||
new_state = reason_to_state (priv->iface, reason);
|
||||
nm_log_dbg (LOGD_DHCP, "(%s): DHCP reason '%s' -> state '%s'",
|
||||
iface, reason, state_to_string (new_state));
|
||||
new_state = reason_to_state (self, priv->iface, reason);
|
||||
_LOGD ("DHCP reason '%s' -> state '%s'",
|
||||
reason, state_to_string (new_state));
|
||||
|
||||
if (new_state == NM_DHCP_STATE_BOUND) {
|
||||
GVariantIter iter;
|
||||
|
|
@ -817,7 +804,7 @@ nm_dhcp_client_handle_event (gpointer unused,
|
|||
|
||||
/* Fail if no valid IP config was received */
|
||||
if (ip_config == NULL) {
|
||||
nm_log_warn (LOGD_DHCP, "(%s): DHCP client bound but IP config not received", iface);
|
||||
_LOGW ("client bound but IP config not received");
|
||||
new_state = NM_DHCP_STATE_FAIL;
|
||||
g_clear_pointer (&str_options, g_hash_table_unref);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@
|
|||
#include "nm-dhcp-manager.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-dhcp-listener.h"
|
||||
#include "nm-dhcp-client-logging.h"
|
||||
|
||||
G_DEFINE_TYPE (NMDhcpDhclient, nm_dhcp_dhclient, NM_TYPE_DHCP_CLIENT)
|
||||
|
||||
|
|
@ -148,7 +149,8 @@ nm_dhcp_dhclient_get_lease_ip_configs (const char *iface,
|
|||
}
|
||||
|
||||
static gboolean
|
||||
merge_dhclient_config (const char *iface,
|
||||
merge_dhclient_config (NMDhcpDhclient *self,
|
||||
const char *iface,
|
||||
const char *conf_file,
|
||||
gboolean is_ip6,
|
||||
GBytes *client_id,
|
||||
|
|
@ -169,8 +171,8 @@ merge_dhclient_config (const char *iface,
|
|||
GError *read_error = NULL;
|
||||
|
||||
if (!g_file_get_contents (orig_path, &orig, NULL, &read_error)) {
|
||||
nm_log_warn (LOGD_DHCP, "(%s): error reading dhclient%s configuration %s: %s",
|
||||
iface, is_ip6 ? "6" : "", orig_path, read_error->message);
|
||||
_LOGW ("error reading dhclient configuration %s: %s",
|
||||
orig_path, read_error->message);
|
||||
g_error_free (read_error);
|
||||
}
|
||||
}
|
||||
|
|
@ -185,7 +187,7 @@ merge_dhclient_config (const char *iface,
|
|||
}
|
||||
|
||||
static char *
|
||||
find_existing_config (const char *iface, const char *uuid, gboolean ipv6)
|
||||
find_existing_config (NMDhcpDhclient *self, const char *iface, const char *uuid, gboolean ipv6)
|
||||
{
|
||||
char *path;
|
||||
|
||||
|
|
@ -195,20 +197,20 @@ find_existing_config (const char *iface, const char *uuid, gboolean ipv6)
|
|||
*/
|
||||
if (uuid) {
|
||||
path = g_strdup_printf (NMCONFDIR "/dhclient%s-%s.conf", ipv6 ? "6" : "", uuid);
|
||||
nm_log_dbg (ipv6 ? LOGD_DHCP6 : LOGD_DHCP4, "(%s) looking for existing config %s", iface, path);
|
||||
_LOGD ("looking for existing config %s", path);
|
||||
if (g_file_test (path, G_FILE_TEST_EXISTS))
|
||||
return path;
|
||||
g_free (path);
|
||||
}
|
||||
|
||||
path = g_strdup_printf (NMCONFDIR "/dhclient%s-%s.conf", ipv6 ? "6" : "", iface);
|
||||
nm_log_dbg (ipv6 ? LOGD_DHCP6 : LOGD_DHCP4, "(%s) looking for existing config %s", iface, path);
|
||||
_LOGD ("looking for existing config %s", path);
|
||||
if (g_file_test (path, G_FILE_TEST_EXISTS))
|
||||
return path;
|
||||
g_free (path);
|
||||
|
||||
path = g_strdup_printf (NMCONFDIR "/dhclient%s.conf", ipv6 ? "6" : "");
|
||||
nm_log_dbg (ipv6 ? LOGD_DHCP6 : LOGD_DHCP4, "(%s) looking for existing config %s", iface, path);
|
||||
_LOGD ("looking for existing config %s", path);
|
||||
if (g_file_test (path, G_FILE_TEST_EXISTS))
|
||||
return path;
|
||||
g_free (path);
|
||||
|
|
@ -222,25 +224,25 @@ find_existing_config (const char *iface, const char *uuid, gboolean ipv6)
|
|||
* (including Fedora) don't even provide a default configuration file.
|
||||
*/
|
||||
path = g_strdup_printf (SYSCONFDIR "/dhcp/dhclient%s-%s.conf", ipv6 ? "6" : "", iface);
|
||||
nm_log_dbg (ipv6 ? LOGD_DHCP6 : LOGD_DHCP4, "(%s) looking for existing config %s", iface, path);
|
||||
_LOGD ("looking for existing config %s", path);
|
||||
if (g_file_test (path, G_FILE_TEST_EXISTS))
|
||||
return path;
|
||||
g_free (path);
|
||||
|
||||
path = g_strdup_printf (SYSCONFDIR "/dhclient%s-%s.conf", ipv6 ? "6" : "", iface);
|
||||
nm_log_dbg (ipv6 ? LOGD_DHCP6 : LOGD_DHCP4, "(%s) looking for existing config %s", iface, path);
|
||||
_LOGD ("looking for existing config %s", path);
|
||||
if (g_file_test (path, G_FILE_TEST_EXISTS))
|
||||
return path;
|
||||
g_free (path);
|
||||
|
||||
path = g_strdup_printf (SYSCONFDIR "/dhcp/dhclient%s.conf", ipv6 ? "6" : "");
|
||||
nm_log_dbg (ipv6 ? LOGD_DHCP6 : LOGD_DHCP4, "(%s) looking for existing config %s", iface, path);
|
||||
_LOGD ("looking for existing config %s", path);
|
||||
if (g_file_test (path, G_FILE_TEST_EXISTS))
|
||||
return path;
|
||||
g_free (path);
|
||||
|
||||
path = g_strdup_printf (SYSCONFDIR "/dhclient%s.conf", ipv6 ? "6" : "");
|
||||
nm_log_dbg (ipv6 ? LOGD_DHCP6 : LOGD_DHCP4, "(%s) looking for existing config %s", iface, path);
|
||||
_LOGD ("looking for existing config %s", path);
|
||||
if (g_file_test (path, G_FILE_TEST_EXISTS))
|
||||
return path;
|
||||
g_free (path);
|
||||
|
|
@ -256,7 +258,8 @@ find_existing_config (const char *iface, const char *uuid, gboolean ipv6)
|
|||
* config file along with the NM options.
|
||||
*/
|
||||
static char *
|
||||
create_dhclient_config (const char *iface,
|
||||
create_dhclient_config (NMDhcpDhclient *self,
|
||||
const char *iface,
|
||||
gboolean is_ip6,
|
||||
const char *uuid,
|
||||
GBytes *client_id,
|
||||
|
|
@ -272,26 +275,19 @@ create_dhclient_config (const char *iface,
|
|||
g_return_val_if_fail (iface != NULL, NULL);
|
||||
|
||||
new = g_strdup_printf (NMSTATEDIR "/dhclient%s-%s.conf", is_ip6 ? "6" : "", iface);
|
||||
nm_log_dbg (is_ip6 ? LOGD_DHCP6 : LOGD_DHCP4,
|
||||
"(%s): creating composite dhclient config %s",
|
||||
iface, new);
|
||||
_LOGD ("creating composite dhclient config %s", new);
|
||||
|
||||
orig = find_existing_config (iface, uuid, is_ip6);
|
||||
if (orig) {
|
||||
nm_log_dbg (is_ip6 ? LOGD_DHCP6 : LOGD_DHCP4,
|
||||
"(%s): merging existing dhclient config %s",
|
||||
iface, orig);
|
||||
} else {
|
||||
nm_log_dbg (is_ip6 ? LOGD_DHCP6 : LOGD_DHCP4,
|
||||
"(%s): no existing dhclient configuration to merge",
|
||||
iface);
|
||||
}
|
||||
orig = find_existing_config (self, iface, uuid, is_ip6);
|
||||
if (orig)
|
||||
_LOGD ("merging existing dhclient config %s", orig);
|
||||
else
|
||||
_LOGD ("no existing dhclient configuration to merge");
|
||||
|
||||
error = NULL;
|
||||
success = merge_dhclient_config (iface, new, is_ip6, client_id, dhcp_anycast_addr, hostname, fqdn, orig, out_new_client_id, &error);
|
||||
success = merge_dhclient_config (self, iface, new, is_ip6, client_id, dhcp_anycast_addr,
|
||||
hostname, fqdn, orig, out_new_client_id, &error);
|
||||
if (!success) {
|
||||
nm_log_warn (LOGD_DHCP, "(%s): error creating dhclient%s configuration: %s",
|
||||
iface, is_ip6 ? "6" : "", error->message);
|
||||
_LOGW ("error creating dhclient configuration: %s", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
|
|
@ -307,14 +303,14 @@ dhclient_start (NMDhcpClient *client,
|
|||
gboolean release,
|
||||
pid_t *out_pid)
|
||||
{
|
||||
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (client);
|
||||
NMDhcpDhclient *self = NM_DHCP_DHCLIENT (client);
|
||||
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (self);
|
||||
GPtrArray *argv = NULL;
|
||||
pid_t pid;
|
||||
GError *error = NULL;
|
||||
const char *iface, *uuid, *system_bus_address, *dhclient_path = NULL;
|
||||
char *binary_name, *cmd_str, *pid_file = NULL, *system_bus_address_env = NULL;
|
||||
gboolean ipv6, success;
|
||||
guint log_domain;
|
||||
char *escaped, *preferred_leasefile_path = NULL;
|
||||
|
||||
g_return_val_if_fail (priv->pid_file == NULL, FALSE);
|
||||
|
|
@ -323,11 +319,9 @@ dhclient_start (NMDhcpClient *client,
|
|||
uuid = nm_dhcp_client_get_uuid (client);
|
||||
ipv6 = nm_dhcp_client_get_ipv6 (client);
|
||||
|
||||
log_domain = ipv6 ? LOGD_DHCP6 : LOGD_DHCP4;
|
||||
|
||||
dhclient_path = nm_dhcp_dhclient_get_path ();
|
||||
if (!dhclient_path) {
|
||||
nm_log_warn (log_domain, "dhclient could not be found");
|
||||
_LOGW ("dhclient could not be found");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -362,9 +356,9 @@ dhclient_start (NMDhcpClient *client,
|
|||
priv->lease_file = g_strdup (g_file_get_path (dst));
|
||||
} else {
|
||||
/* Failure; just use the existing leasefile */
|
||||
nm_log_warn (log_domain, "Failed to copy leasefile %s to %s: %s",
|
||||
g_file_get_path (src), g_file_get_path (dst),
|
||||
error->message);
|
||||
_LOGW ("failed to copy leasefile %s to %s: %s",
|
||||
g_file_get_path (src), g_file_get_path (dst),
|
||||
error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
g_object_unref (src);
|
||||
|
|
@ -378,9 +372,7 @@ dhclient_start (NMDhcpClient *client,
|
|||
success = nm_dhcp_dhclient_save_duid (priv->lease_file, escaped, &error);
|
||||
g_free (escaped);
|
||||
if (!success) {
|
||||
nm_log_warn (log_domain, "(%s): failed to save DUID to %s: %s.",
|
||||
iface, priv->lease_file,
|
||||
error->message);
|
||||
_LOGW ("failed to save DUID to %s: %s", priv->lease_file, error->message);
|
||||
g_free (pid_file);
|
||||
return FALSE;
|
||||
}
|
||||
|
|
@ -436,19 +428,19 @@ dhclient_start (NMDhcpClient *client,
|
|||
g_ptr_array_add (argv, NULL);
|
||||
|
||||
cmd_str = g_strjoinv (" ", (gchar **) argv->pdata);
|
||||
nm_log_dbg (log_domain, "running: %s", cmd_str);
|
||||
_LOGD ("running: %s", cmd_str);
|
||||
g_free (cmd_str);
|
||||
|
||||
if (g_spawn_async (NULL, (char **) argv->pdata, NULL,
|
||||
G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
|
||||
nm_utils_setpgid, NULL, &pid, &error)) {
|
||||
g_assert (pid > 0);
|
||||
nm_log_info (log_domain, "dhclient started with pid %d", pid);
|
||||
_LOGI ("dhclient started with pid %d", pid);
|
||||
if (release == FALSE)
|
||||
nm_dhcp_client_watch_child (client, pid);
|
||||
priv->pid_file = pid_file;
|
||||
} else {
|
||||
nm_log_warn (log_domain, "dhclient failed to start: '%s'", error->message);
|
||||
_LOGW ("dhclient failed to start: '%s'", error->message);
|
||||
g_error_free (error);
|
||||
g_free (pid_file);
|
||||
}
|
||||
|
|
@ -464,7 +456,8 @@ dhclient_start (NMDhcpClient *client,
|
|||
static gboolean
|
||||
ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last_ip4_address)
|
||||
{
|
||||
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (client);
|
||||
NMDhcpDhclient *self = NM_DHCP_DHCLIENT (client);
|
||||
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (self);
|
||||
GBytes *client_id;
|
||||
gs_unref_bytes GBytes *new_client_id = NULL;
|
||||
const char *iface, *uuid, *hostname, *fqdn;
|
||||
|
|
@ -476,14 +469,14 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last
|
|||
hostname = nm_dhcp_client_get_hostname (client);
|
||||
fqdn = nm_dhcp_client_get_fqdn (client);
|
||||
|
||||
priv->conf_file = create_dhclient_config (iface, FALSE, uuid, client_id, dhcp_anycast_addr,
|
||||
priv->conf_file = create_dhclient_config (self, iface, FALSE, uuid, client_id, dhcp_anycast_addr,
|
||||
hostname, fqdn, &new_client_id);
|
||||
if (priv->conf_file) {
|
||||
if (new_client_id)
|
||||
nm_dhcp_client_set_client_id (client, new_client_id);
|
||||
success = dhclient_start (client, NULL, NULL, FALSE, NULL);
|
||||
} else
|
||||
nm_log_warn (LOGD_DHCP4, "(%s): error creating dhclient configuration file.", iface);
|
||||
_LOGW ("error creating dhclient configuration file");
|
||||
|
||||
return success;
|
||||
}
|
||||
|
|
@ -496,16 +489,17 @@ ip6_start (NMDhcpClient *client,
|
|||
NMSettingIP6ConfigPrivacy privacy,
|
||||
const GByteArray *duid)
|
||||
{
|
||||
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (client);
|
||||
NMDhcpDhclient *self = NM_DHCP_DHCLIENT (client);
|
||||
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (self);
|
||||
const char *iface, *uuid, *hostname;
|
||||
|
||||
iface = nm_dhcp_client_get_iface (client);
|
||||
uuid = nm_dhcp_client_get_uuid (client);
|
||||
hostname = nm_dhcp_client_get_hostname (client);
|
||||
|
||||
priv->conf_file = create_dhclient_config (iface, TRUE, uuid, NULL, dhcp_anycast_addr, hostname, NULL, NULL);
|
||||
priv->conf_file = create_dhclient_config (self, iface, TRUE, uuid, NULL, dhcp_anycast_addr, hostname, NULL, NULL);
|
||||
if (!priv->conf_file) {
|
||||
nm_log_warn (LOGD_DHCP6, "(%s): error creating dhclient6 configuration file.", iface);
|
||||
_LOGW ("error creating dhclient configuration file");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -515,17 +509,18 @@ ip6_start (NMDhcpClient *client,
|
|||
static void
|
||||
stop (NMDhcpClient *client, gboolean release, const GByteArray *duid)
|
||||
{
|
||||
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (client);
|
||||
NMDhcpDhclient *self = NM_DHCP_DHCLIENT (client);
|
||||
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (self);
|
||||
|
||||
/* Chain up to parent */
|
||||
NM_DHCP_CLIENT_CLASS (nm_dhcp_dhclient_parent_class)->stop (client, release, duid);
|
||||
|
||||
if (priv->conf_file)
|
||||
if (remove (priv->conf_file) == -1)
|
||||
nm_log_dbg (LOGD_DHCP, "Could not remove dhcp config file \"%s\": %d (%s)", priv->conf_file, errno, g_strerror (errno));
|
||||
_LOGD ("could not remove dhcp config file \"%s\": %d (%s)", priv->conf_file, errno, g_strerror (errno));
|
||||
if (priv->pid_file) {
|
||||
if (remove (priv->pid_file) == -1)
|
||||
nm_log_dbg (LOGD_DHCP, "Could not remove dhcp pid file \"%s\": %d (%s)", priv->pid_file, errno, g_strerror (errno));
|
||||
_LOGD ("could not remove dhcp pid file \"%s\": %d (%s)", priv->pid_file, errno, g_strerror (errno));
|
||||
g_free (priv->pid_file);
|
||||
priv->pid_file = NULL;
|
||||
}
|
||||
|
|
@ -561,7 +556,8 @@ state_changed (NMDhcpClient *client,
|
|||
static GByteArray *
|
||||
get_duid (NMDhcpClient *client)
|
||||
{
|
||||
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (client);
|
||||
NMDhcpDhclient *self = NM_DHCP_DHCLIENT (client);
|
||||
NMDhcpDhclientPrivate *priv = NM_DHCP_DHCLIENT_GET_PRIVATE (self);
|
||||
GByteArray *duid = NULL;
|
||||
char *leasefile;
|
||||
GError *error = NULL;
|
||||
|
|
@ -572,12 +568,12 @@ get_duid (NMDhcpClient *client)
|
|||
TRUE,
|
||||
NULL);
|
||||
if (leasefile) {
|
||||
nm_log_dbg (LOGD_DHCP, "Looking for DHCPv6 DUID in '%s'.", leasefile);
|
||||
_LOGD ("looking for DUID in '%s'", leasefile);
|
||||
duid = nm_dhcp_dhclient_read_duid (leasefile, &error);
|
||||
|
||||
if (error) {
|
||||
nm_log_warn (LOGD_DHCP, "Failed to read leasefile '%s': %s",
|
||||
leasefile, error->message);
|
||||
_LOGW ("failed to read leasefile '%s': %s",
|
||||
leasefile, error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
g_free (leasefile);
|
||||
|
|
@ -585,12 +581,12 @@ get_duid (NMDhcpClient *client)
|
|||
|
||||
if (!duid && priv->def_leasefile) {
|
||||
/* Otherwise read the default machine-wide DUID */
|
||||
nm_log_dbg (LOGD_DHCP, "Looking for default DHCPv6 DUID in '%s'.", priv->def_leasefile);
|
||||
_LOGD ("looking for default DUID in '%s'", priv->def_leasefile);
|
||||
duid = nm_dhcp_dhclient_read_duid (priv->def_leasefile, &error);
|
||||
if (error) {
|
||||
nm_log_warn (LOGD_DHCP, "Failed to read leasefile '%s': %s",
|
||||
priv->def_leasefile,
|
||||
error->message);
|
||||
_LOGW ("failed to read leasefile '%s': %s",
|
||||
priv->def_leasefile,
|
||||
error->message);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
#include "nm-utils.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-dhcp-listener.h"
|
||||
#include "nm-dhcp-client-logging.h"
|
||||
|
||||
G_DEFINE_TYPE (NMDhcpDhcpcd, nm_dhcp_dhcpcd, NM_TYPE_DHCP_CLIENT)
|
||||
|
||||
|
|
@ -58,7 +59,8 @@ nm_dhcp_dhcpcd_get_path (void)
|
|||
static gboolean
|
||||
ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last_ip4_address)
|
||||
{
|
||||
NMDhcpDhcpcdPrivate *priv = NM_DHCP_DHCPCD_GET_PRIVATE (client);
|
||||
NMDhcpDhcpcd *self = NM_DHCP_DHCPCD (client);
|
||||
NMDhcpDhcpcdPrivate *priv = NM_DHCP_DHCPCD_GET_PRIVATE (self);
|
||||
GPtrArray *argv = NULL;
|
||||
pid_t pid = -1;
|
||||
GError *error = NULL;
|
||||
|
|
@ -77,7 +79,7 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last
|
|||
|
||||
dhcpcd_path = nm_dhcp_dhcpcd_get_path ();
|
||||
if (!dhcpcd_path) {
|
||||
nm_log_warn (LOGD_DHCP4, "dhcpcd could not be found");
|
||||
_LOGW ("dhcpcd could not be found");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -134,17 +136,17 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last
|
|||
g_ptr_array_add (argv, NULL);
|
||||
|
||||
cmd_str = g_strjoinv (" ", (gchar **) argv->pdata);
|
||||
nm_log_dbg (LOGD_DHCP4, "running: %s", cmd_str);
|
||||
_LOGD ("running: %s", cmd_str);
|
||||
g_free (cmd_str);
|
||||
|
||||
if (g_spawn_async (NULL, (char **) argv->pdata, NULL,
|
||||
G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_STDOUT_TO_DEV_NULL | G_SPAWN_STDERR_TO_DEV_NULL,
|
||||
nm_utils_setpgid, NULL, &pid, &error)) {
|
||||
g_assert (pid > 0);
|
||||
nm_log_info (LOGD_DHCP4, "dhcpcd started with pid %d", pid);
|
||||
_LOGI ("dhcpcd started with pid %d", pid);
|
||||
nm_dhcp_client_watch_child (client, pid);
|
||||
} else {
|
||||
nm_log_warn (LOGD_DHCP4, "dhcpcd failed to start. error: '%s'", error->message);
|
||||
_LOGW ("dhcpcd failed to start, error: '%s'", error->message);
|
||||
g_error_free (error);
|
||||
}
|
||||
|
||||
|
|
@ -161,21 +163,24 @@ ip6_start (NMDhcpClient *client,
|
|||
NMSettingIP6ConfigPrivacy privacy,
|
||||
const GByteArray *duid)
|
||||
{
|
||||
nm_log_warn (LOGD_DHCP6, "the dhcpcd backend does not support IPv6.");
|
||||
NMDhcpDhcpcd *self = NM_DHCP_DHCPCD (client);
|
||||
|
||||
_LOGW ("the dhcpcd backend does not support IPv6");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
stop (NMDhcpClient *client, gboolean release, const GByteArray *duid)
|
||||
{
|
||||
NMDhcpDhcpcdPrivate *priv = NM_DHCP_DHCPCD_GET_PRIVATE (client);
|
||||
NMDhcpDhcpcd *self = NM_DHCP_DHCPCD (client);
|
||||
NMDhcpDhcpcdPrivate *priv = NM_DHCP_DHCPCD_GET_PRIVATE (self);
|
||||
|
||||
/* Chain up to parent */
|
||||
NM_DHCP_CLIENT_CLASS (nm_dhcp_dhcpcd_parent_class)->stop (client, release, duid);
|
||||
|
||||
if (priv->pid_file) {
|
||||
if (remove (priv->pid_file) == -1)
|
||||
nm_log_dbg (LOGD_DHCP, "Could not remove dhcp pid file \"%s\": %d (%s)", priv->pid_file, errno, g_strerror (errno));
|
||||
_LOGD ("could not remove dhcp pid file \"%s\": %d (%s)", priv->pid_file, errno, g_strerror (errno));
|
||||
}
|
||||
|
||||
/* FIXME: implement release... */
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#include "nm-dhcp-utils.h"
|
||||
#include "NetworkManagerUtils.h"
|
||||
#include "nm-platform.h"
|
||||
#include "nm-dhcp-client-logging.h"
|
||||
|
||||
#include "sd-dhcp-client.h"
|
||||
#include "sd-dhcp6-client.h"
|
||||
|
|
@ -465,15 +466,15 @@ bound4_handle (NMDhcpSystemd *self)
|
|||
GError *error = NULL;
|
||||
int r;
|
||||
|
||||
nm_log_dbg (LOGD_DHCP4, "(%s): lease available", iface);
|
||||
|
||||
r = sd_dhcp_client_get_lease (priv->client4, &lease);
|
||||
if (r < 0 || !lease) {
|
||||
nm_log_warn (LOGD_DHCP4, "(%s): no lease!", iface);
|
||||
_LOGW ("no lease!");
|
||||
nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_FAIL, NULL, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
_LOGD ("lease available");
|
||||
|
||||
options = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
|
||||
ip4_config = lease_to_ip4_config (iface,
|
||||
nm_dhcp_client_get_ifindex (NM_DHCP_CLIENT (self)),
|
||||
|
|
@ -499,7 +500,7 @@ bound4_handle (NMDhcpSystemd *self)
|
|||
G_OBJECT (ip4_config),
|
||||
options);
|
||||
} else {
|
||||
nm_log_warn (LOGD_DHCP4, "(%s): %s", iface, error->message);
|
||||
_LOGW ("%s", error->message);
|
||||
nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_FAIL, NULL, NULL);
|
||||
g_clear_error (&error);
|
||||
}
|
||||
|
|
@ -513,11 +514,10 @@ dhcp_event_cb (sd_dhcp_client *client, int event, gpointer user_data)
|
|||
{
|
||||
NMDhcpSystemd *self = NM_DHCP_SYSTEMD (user_data);
|
||||
NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self);
|
||||
const char *iface = nm_dhcp_client_get_iface (NM_DHCP_CLIENT (self));
|
||||
|
||||
g_assert (priv->client4 == client);
|
||||
|
||||
nm_log_dbg (LOGD_DHCP4, "(%s): DHCPv4 client event %d", iface, event);
|
||||
_LOGD ("client event %d", event);
|
||||
|
||||
switch (event) {
|
||||
case SD_DHCP_CLIENT_EVENT_EXPIRED:
|
||||
|
|
@ -532,7 +532,7 @@ dhcp_event_cb (sd_dhcp_client *client, int event, gpointer user_data)
|
|||
bound4_handle (self);
|
||||
break;
|
||||
default:
|
||||
nm_log_warn (LOGD_DHCP4, "(%s): unhandled DHCP event %d", iface, event);
|
||||
_LOGW ("unhandled DHCP event %d", event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -551,7 +551,8 @@ get_arp_type (const GByteArray *hwaddr)
|
|||
static gboolean
|
||||
ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last_ip4_address)
|
||||
{
|
||||
NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (client);
|
||||
NMDhcpSystemd *self = NM_DHCP_SYSTEMD (client);
|
||||
NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self);
|
||||
const char *iface = nm_dhcp_client_get_iface (client);
|
||||
const GByteArray *hwaddr;
|
||||
sd_dhcp_lease *lease = NULL;
|
||||
|
|
@ -572,13 +573,13 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last
|
|||
|
||||
r = sd_dhcp_client_new (&priv->client4);
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP4, "(%s): failed to create DHCPv4 client (%d)", iface, r);
|
||||
_LOGW ("failed to create client (%d)", r);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
r = sd_dhcp_client_attach_event (priv->client4, NULL, 0);
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP4, "(%s): failed to attach DHCP event (%d)", iface, r);
|
||||
_LOGW ("failed to attach event (%d)", r);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
@ -586,7 +587,7 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last
|
|||
if (hwaddr) {
|
||||
arp_type= get_arp_type (hwaddr);
|
||||
if (arp_type == ARPHRD_NONE) {
|
||||
nm_log_warn (LOGD_DHCP4, "(%s): failed to determine ARP type", iface);
|
||||
_LOGW ("failed to determine ARP type");
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
@ -595,26 +596,26 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last
|
|||
hwaddr->len,
|
||||
arp_type);
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP4, "(%s): failed to set DHCP MAC address (%d)", iface, r);
|
||||
_LOGW ("failed to set MAC address (%d)", r);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
r = sd_dhcp_client_set_index (priv->client4, nm_dhcp_client_get_ifindex (client));
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP4, "(%s): failed to set DHCP ifindex (%d)", iface, r);
|
||||
_LOGW ("failed to set ifindex (%d)", r);
|
||||
goto error;
|
||||
}
|
||||
|
||||
r = sd_dhcp_client_set_callback (priv->client4, dhcp_event_cb, client);
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP4, "(%s): failed to set DHCP callback (%d)", iface, r);
|
||||
_LOGW ("failed to set callback (%d)", r);
|
||||
goto error;
|
||||
}
|
||||
|
||||
r = sd_dhcp_client_set_request_broadcast (priv->client4, true);
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP4, "(%s): failed to set DHCP broadcast (%d)", iface, r);
|
||||
_LOGW ("failed to enable broadcast mode (%d)", r);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
@ -628,7 +629,7 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last
|
|||
if (last_addr.s_addr) {
|
||||
r = sd_dhcp_client_set_request_address (priv->client4, &last_addr);
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP4, "(%s): failed to set last IPv4 address (%d)", iface, r);
|
||||
_LOGW ("failed to set last IPv4 address (%d)", r);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
|
@ -676,7 +677,7 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last
|
|||
free (prefix);
|
||||
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP4, "(%s): failed to set DHCP hostname (%d)", iface, r);
|
||||
_LOGW ("failed to set DHCP hostname (%d)", r);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
|
@ -685,14 +686,14 @@ ip4_start (NMDhcpClient *client, const char *dhcp_anycast_addr, const char *last
|
|||
if (fqdn) {
|
||||
r = sd_dhcp_client_set_hostname (priv->client4, fqdn);
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP4, "(%s): failed to set DHCP FQDN (%d)", iface, r);
|
||||
_LOGW ("failed to set DHCP FQDN (%d)", r);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
r = sd_dhcp_client_start (priv->client4);
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP4, "(%s): failed to start DHCP (%d)", iface, r);
|
||||
_LOGW ("failed to start client (%d)", r);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
@ -810,12 +811,12 @@ bound6_handle (NMDhcpSystemd *self)
|
|||
|
||||
r = sd_dhcp6_client_get_lease (priv->client6, &lease);
|
||||
if (r < 0 || !lease) {
|
||||
nm_log_warn (LOGD_DHCP6, "(%s): no lease!", iface);
|
||||
_LOGW (" no lease!");
|
||||
nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_FAIL, NULL, NULL);
|
||||
return;
|
||||
}
|
||||
|
||||
nm_log_dbg (LOGD_DHCP6, "(%s): lease available", iface);
|
||||
_LOGD ("lease available");
|
||||
|
||||
options = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
|
||||
ip6_config = lease_to_ip6_config (iface,
|
||||
|
|
@ -832,7 +833,7 @@ bound6_handle (NMDhcpSystemd *self)
|
|||
G_OBJECT (ip6_config),
|
||||
options);
|
||||
} else {
|
||||
nm_log_warn (LOGD_DHCP6, "(%s): %s", iface, error->message);
|
||||
_LOGW ("%s", error->message);
|
||||
nm_dhcp_client_set_state (NM_DHCP_CLIENT (self), NM_DHCP_STATE_FAIL, NULL, NULL);
|
||||
}
|
||||
}
|
||||
|
|
@ -842,11 +843,10 @@ dhcp6_event_cb (sd_dhcp6_client *client, int event, gpointer user_data)
|
|||
{
|
||||
NMDhcpSystemd *self = NM_DHCP_SYSTEMD (user_data);
|
||||
NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self);
|
||||
const char *iface = nm_dhcp_client_get_iface (NM_DHCP_CLIENT (self));
|
||||
|
||||
g_assert (priv->client6 == client);
|
||||
|
||||
nm_log_dbg (LOGD_DHCP6, "(%s): DHCPv6 client event %d", iface, event);
|
||||
_LOGD ("client event %d", event);
|
||||
|
||||
switch (event) {
|
||||
case SD_DHCP6_CLIENT_EVENT_RETRANS_MAX:
|
||||
|
|
@ -860,7 +860,7 @@ dhcp6_event_cb (sd_dhcp6_client *client, int event, gpointer user_data)
|
|||
bound6_handle (self);
|
||||
break;
|
||||
default:
|
||||
nm_log_warn (LOGD_DHCP6, "(%s): unhandled DHCPv6 event %d", iface, event);
|
||||
_LOGW ("unhandled event %d", event);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -873,7 +873,8 @@ ip6_start (NMDhcpClient *client,
|
|||
NMSettingIP6ConfigPrivacy privacy,
|
||||
const GByteArray *duid)
|
||||
{
|
||||
NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (client);
|
||||
NMDhcpSystemd *self = NM_DHCP_SYSTEMD (client);
|
||||
NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self);
|
||||
const char *iface = nm_dhcp_client_get_iface (client);
|
||||
const GByteArray *hwaddr;
|
||||
int r, i;
|
||||
|
|
@ -888,7 +889,7 @@ ip6_start (NMDhcpClient *client,
|
|||
|
||||
r = sd_dhcp6_client_new (&priv->client6);
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP6, "(%s): failed to create DHCPv6 client (%d)", iface, r);
|
||||
_LOGW ("failed to create client (%d)", r);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
|
@ -900,13 +901,13 @@ ip6_start (NMDhcpClient *client,
|
|||
duid->data + 2,
|
||||
duid->len - 2);
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP6, "(%s): failed to create DHCPv6 client (%d)", iface, r);
|
||||
_LOGW ("failed to set DUID (%d)", r);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
r = sd_dhcp6_client_attach_event (priv->client6, NULL, 0);
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP6, "(%s): failed to attach DHCP event (%d)", iface, r);
|
||||
_LOGW ("failed to attach event (%d)", r);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
@ -917,20 +918,20 @@ ip6_start (NMDhcpClient *client,
|
|||
hwaddr->len,
|
||||
get_arp_type (hwaddr));
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP6, "(%s): failed to set DHCP MAC address (%d)", iface, r);
|
||||
_LOGW ("failed to set MAC address (%d)", r);
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
r = sd_dhcp6_client_set_index (priv->client6, nm_dhcp_client_get_ifindex (client));
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP6, "(%s): failed to set DHCP ifindex (%d)", iface, r);
|
||||
_LOGW ("failed to set ifindex (%d)", r);
|
||||
goto error;
|
||||
}
|
||||
|
||||
r = sd_dhcp6_client_set_callback (priv->client6, dhcp6_event_cb, client);
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP6, "(%s): failed to set DHCP callback (%d)", iface, r);
|
||||
_LOGW ("failed to set callback (%d)", r);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
@ -942,13 +943,13 @@ ip6_start (NMDhcpClient *client,
|
|||
|
||||
r = sd_dhcp6_client_set_local_address (priv->client6, ll_addr);
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP6, "(%s): failed to set local address (%d)", iface, r);
|
||||
_LOGW ("failed to set local address (%d)", r);
|
||||
goto error;
|
||||
}
|
||||
|
||||
r = sd_dhcp6_client_start (priv->client6);
|
||||
if (r < 0) {
|
||||
nm_log_warn (LOGD_DHCP6, "(%s): failed to start DHCP (%d)", iface, r);
|
||||
_LOGW ("failed to start client (%d)", r);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
@ -963,7 +964,8 @@ error:
|
|||
static void
|
||||
stop (NMDhcpClient *client, gboolean release, const GByteArray *duid)
|
||||
{
|
||||
NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (client);
|
||||
NMDhcpSystemd *self = NM_DHCP_SYSTEMD (client);
|
||||
NMDhcpSystemdPrivate *priv = NM_DHCP_SYSTEMD_GET_PRIVATE (self);
|
||||
int r = 0;
|
||||
|
||||
if (priv->client4) {
|
||||
|
|
@ -974,12 +976,8 @@ stop (NMDhcpClient *client, gboolean release, const GByteArray *duid)
|
|||
r = sd_dhcp6_client_stop (priv->client6);
|
||||
}
|
||||
|
||||
if (r) {
|
||||
nm_log_warn (priv->client6 ? LOGD_DHCP6 : LOGD_DHCP4,
|
||||
"(%s): failed to stop DHCP client (%d)",
|
||||
nm_dhcp_client_get_iface (client),
|
||||
r);
|
||||
}
|
||||
if (r)
|
||||
_LOGW ("failed to stop client (%d)", r);
|
||||
}
|
||||
|
||||
/***************************************************/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue