mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-07-22 10:46:59 +00:00
merge: branch 'bg/log-device-type'
https://gitlab.freedesktop.org/NetworkManager/NetworkManager/-/merge_requests/1638
This commit is contained in:
commit
647fa98810
|
@ -16,7 +16,7 @@
|
|||
NM_GOBJECT_PROPERTIES_DEFINE_BASE(PROP_TYPE_DESCRIPTION, );
|
||||
|
||||
typedef struct {
|
||||
char *type_description;
|
||||
const char *type_description;
|
||||
} NMDeviceGenericPrivate;
|
||||
|
||||
struct _NMDeviceGeneric {
|
||||
|
@ -64,11 +64,11 @@ realize_start_notify(NMDevice *device, const NMPlatformLink *plink)
|
|||
|
||||
NM_DEVICE_CLASS(nm_device_generic_parent_class)->realize_start_notify(device, plink);
|
||||
|
||||
nm_clear_g_free(&priv->type_description);
|
||||
ifindex = nm_device_get_ip_ifindex(NM_DEVICE(self));
|
||||
if (ifindex > 0)
|
||||
if (ifindex > 0) {
|
||||
priv->type_description =
|
||||
g_strdup(nm_platform_link_get_type_name(nm_device_get_platform(device), ifindex));
|
||||
nm_platform_link_get_type_name(nm_device_get_platform(device), ifindex);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -128,22 +128,6 @@ get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec)
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
set_property(GObject *object, guint prop_id, const GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
NMDeviceGeneric *self = NM_DEVICE_GENERIC(object);
|
||||
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE(self);
|
||||
|
||||
switch (prop_id) {
|
||||
case PROP_TYPE_DESCRIPTION:
|
||||
priv->type_description = g_value_dup_string(value);
|
||||
break;
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static void
|
||||
|
@ -180,17 +164,6 @@ nm_device_generic_new(const NMPlatformLink *plink, gboolean nm_plugin_missing)
|
|||
NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
dispose(GObject *object)
|
||||
{
|
||||
NMDeviceGeneric *self = NM_DEVICE_GENERIC(object);
|
||||
NMDeviceGenericPrivate *priv = NM_DEVICE_GENERIC_GET_PRIVATE(self);
|
||||
|
||||
nm_clear_g_free(&priv->type_description);
|
||||
|
||||
G_OBJECT_CLASS(nm_device_generic_parent_class)->dispose(object);
|
||||
}
|
||||
|
||||
static const NMDBusInterfaceInfoExtended interface_info_device_generic = {
|
||||
.parent = NM_DEFINE_GDBUS_INTERFACE_INFO_INIT(
|
||||
NM_DBUS_INTERFACE_DEVICE_GENERIC,
|
||||
|
@ -210,9 +183,7 @@ nm_device_generic_class_init(NMDeviceGenericClass *klass)
|
|||
NMDeviceClass *device_class = NM_DEVICE_CLASS(klass);
|
||||
|
||||
object_class->constructor = constructor;
|
||||
object_class->dispose = dispose;
|
||||
object_class->get_property = get_property;
|
||||
object_class->set_property = set_property;
|
||||
|
||||
dbus_object_class->interface_infos = NM_DBUS_INTERFACE_INFOS(&interface_info_device_generic);
|
||||
|
||||
|
@ -231,7 +202,7 @@ nm_device_generic_class_init(NMDeviceGenericClass *klass)
|
|||
"",
|
||||
"",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
|
||||
G_PARAM_READABLE | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties(object_class, _PROPERTY_ENUMS_LAST, obj_properties);
|
||||
}
|
||||
|
|
|
@ -19,27 +19,29 @@
|
|||
|
||||
#undef _NMLOG_ENABLED
|
||||
#define _NMLOG_ENABLED(level, domain) (nm_logging_enabled((level), (domain)))
|
||||
#define _NMLOG(level, domain, ...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
const NMLogLevel _level = (level); \
|
||||
const NMLogDomain _domain = (domain); \
|
||||
\
|
||||
if (nm_logging_enabled(_level, _domain)) { \
|
||||
typeof(*self) *const _self = (self); \
|
||||
const char *const _ifname = _nm_device_get_iface(_NM_DEVICE_CAST(_self)); \
|
||||
\
|
||||
nm_log_obj(_level, \
|
||||
_domain, \
|
||||
_ifname, \
|
||||
NULL, \
|
||||
_self, \
|
||||
"device", \
|
||||
"%s%s%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
|
||||
NM_PRINT_FMT_QUOTED(_ifname, "(", _ifname, ")", "[null]") \
|
||||
_NM_UTILS_MACRO_REST(__VA_ARGS__)); \
|
||||
} \
|
||||
} \
|
||||
#define _NMLOG(level, domain, ...) \
|
||||
G_STMT_START \
|
||||
{ \
|
||||
const NMLogLevel _level = (level); \
|
||||
const NMLogDomain _domain = (domain); \
|
||||
\
|
||||
if (nm_logging_enabled(_level, _domain)) { \
|
||||
typeof(*self) *const _self = (self); \
|
||||
const char *const _ifname = _nm_device_get_iface(_NM_DEVICE_CAST(_self)); \
|
||||
const char *_type = nm_device_get_type_desc_for_log(_NM_DEVICE_CAST(_self)); \
|
||||
\
|
||||
nm_log_obj(_level, \
|
||||
_domain, \
|
||||
_ifname, \
|
||||
NULL, \
|
||||
_self, \
|
||||
"device", \
|
||||
"%s%s%s%s%s%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
|
||||
NM_PRINT_FMT_QUOTED(_ifname, "(", _ifname, ")", "[null]"), \
|
||||
NM_PRINT_FMT_QUOTED(_type, "[", _type, "]", "") \
|
||||
_NM_UTILS_MACRO_REST(__VA_ARGS__)); \
|
||||
} \
|
||||
} \
|
||||
G_STMT_END
|
||||
|
||||
#endif /* __NETWORKMANAGER_DEVICE_LOGGING_H__ */
|
||||
|
|
|
@ -5399,14 +5399,32 @@ nm_device_get_type_desc(NMDevice *self)
|
|||
return NM_DEVICE_GET_PRIVATE(self)->type_desc;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_device_get_type_desc_for_log(NMDevice *self)
|
||||
{
|
||||
const char *type;
|
||||
|
||||
type = nm_device_get_type_desc(self);
|
||||
|
||||
/* Some OVS device types (ports and bridges) are not backed by a kernel link, and
|
||||
* they can have the same name of another device of a different type. In fact, it's
|
||||
* quite common to assign the same name to the OVS bridge, the OVS port and the OVS
|
||||
* interface. For this reason, also log the type in case of OVS devices to make the
|
||||
* log message unambiguous. */
|
||||
if (NM_STR_HAS_PREFIX(type, "Open vSwitch"))
|
||||
return type;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_device_get_type_description(NMDevice *self)
|
||||
{
|
||||
g_return_val_if_fail(self != NULL, NULL);
|
||||
|
||||
/* Beware: this function should return the same
|
||||
* value as nm_device_get_type_description() in libnm. */
|
||||
|
||||
* value as nm_device_get_type_description() in libnm.
|
||||
* The returned string is static or interned */
|
||||
return NM_DEVICE_GET_CLASS(self)->get_type_description(self);
|
||||
}
|
||||
|
||||
|
@ -10658,6 +10676,7 @@ _dev_ipdhcpx_start(NMDevice *self, int addr_family)
|
|||
.addr_family = AF_INET,
|
||||
.l3cfg = nm_device_get_l3cfg(self),
|
||||
.iface = nm_device_get_ip_iface(self),
|
||||
.iface_type_log = nm_device_get_type_desc_for_log(self),
|
||||
.uuid = nm_connection_get_uuid(connection),
|
||||
.hwaddr = hwaddr,
|
||||
.bcast_hwaddr = bcast_hwaddr,
|
||||
|
@ -10695,6 +10714,7 @@ _dev_ipdhcpx_start(NMDevice *self, int addr_family)
|
|||
.addr_family = AF_INET6,
|
||||
.l3cfg = nm_device_get_l3cfg(self),
|
||||
.iface = nm_device_get_ip_iface(self),
|
||||
.iface_type_log = nm_device_get_type_desc_for_log(self),
|
||||
.uuid = nm_connection_get_uuid(connection),
|
||||
.send_hostname = nm_setting_ip_config_get_dhcp_send_hostname(s_ip),
|
||||
.hostname = nm_setting_ip_config_get_dhcp_hostname(s_ip),
|
||||
|
|
|
@ -463,6 +463,7 @@ int nm_device_get_ip_ifindex(const NMDevice *dev);
|
|||
const char *nm_device_get_driver(NMDevice *dev);
|
||||
const char *nm_device_get_driver_version(NMDevice *dev);
|
||||
const char *nm_device_get_type_desc(NMDevice *dev);
|
||||
const char *nm_device_get_type_desc_for_log(NMDevice *dev);
|
||||
const char *nm_device_get_type_description(NMDevice *dev);
|
||||
NMDeviceType nm_device_get_device_type(NMDevice *dev);
|
||||
NMLinkType nm_device_get_link_type(NMDevice *dev);
|
||||
|
|
|
@ -41,16 +41,19 @@ _nm_dhcp_client_get_domain(NMDhcpClient *self)
|
|||
if (nm_logging_enabled(_level, _NMLOG_DOMAIN)) { \
|
||||
NMDhcpClient *_self = (NMDhcpClient *) (self); \
|
||||
const char *__ifname = _self ? nm_dhcp_client_get_iface(_self) : NULL; \
|
||||
const char *_type = nm_dhcp_client_get_iface_type_for_log(_self); \
|
||||
const NMLogDomain _domain = _nm_dhcp_client_get_domain(_self); \
|
||||
\
|
||||
nm_log(_level, \
|
||||
_domain, \
|
||||
__ifname, \
|
||||
NULL, \
|
||||
"%s%s%s%s%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \
|
||||
"%s%s%s%s%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, ")", "") \
|
||||
(__ifname || _type) ? " " : "", \
|
||||
NM_PRINT_FMT_QUOTED(__ifname, "(", __ifname, ")", ""), \
|
||||
NM_PRINT_FMT_QUOTED(_type, "[", _type, "]", "") \
|
||||
_NM_UTILS_MACRO_REST(__VA_ARGS__)); \
|
||||
} \
|
||||
} \
|
||||
|
|
|
@ -196,6 +196,14 @@ nm_dhcp_client_get_iface(NMDhcpClient *self)
|
|||
return priv->config.iface;
|
||||
}
|
||||
|
||||
const char *
|
||||
nm_dhcp_client_get_iface_type_for_log(NMDhcpClient *self)
|
||||
{
|
||||
NMDhcpClientPrivate *priv = NM_DHCP_CLIENT_GET_PRIVATE(self);
|
||||
|
||||
return priv->config.iface_type_log;
|
||||
}
|
||||
|
||||
NMDedupMultiIndex *
|
||||
nm_dhcp_client_get_multi_idx(NMDhcpClient *self)
|
||||
{
|
||||
|
@ -1823,6 +1831,7 @@ config_init(NMDhcpClientConfig *config, const NMDhcpClientConfig *src)
|
|||
nm_g_bytes_ref(config->client_id);
|
||||
|
||||
config->iface = g_strdup(config->iface);
|
||||
config->iface_type_log = g_strdup(config->iface_type_log);
|
||||
config->uuid = g_strdup(config->uuid);
|
||||
config->anycast_address = g_strdup(config->anycast_address);
|
||||
config->hostname = g_strdup(config->hostname);
|
||||
|
@ -1885,6 +1894,7 @@ config_clear(NMDhcpClientConfig *config)
|
|||
nm_clear_pointer(&config->client_id, g_bytes_unref);
|
||||
|
||||
nm_clear_g_free((gpointer *) &config->iface);
|
||||
nm_clear_g_free((gpointer *) &config->iface_type_log);
|
||||
nm_clear_g_free((gpointer *) &config->uuid);
|
||||
nm_clear_g_free((gpointer *) &config->anycast_address);
|
||||
nm_clear_g_free((gpointer *) &config->hostname);
|
||||
|
|
|
@ -103,6 +103,10 @@ typedef struct {
|
|||
|
||||
const char *iface;
|
||||
|
||||
/* Interface type for logging; only set for some devices whose names can be
|
||||
* ambiguous. */
|
||||
const char *iface_type_log;
|
||||
|
||||
/* The hardware address */
|
||||
GBytes *hwaddr;
|
||||
|
||||
|
@ -264,6 +268,7 @@ gboolean nm_dhcp_client_server_id_is_rejected(NMDhcpClient *self, gconstpointer
|
|||
|
||||
int nm_dhcp_client_get_addr_family(NMDhcpClient *self);
|
||||
const char *nm_dhcp_client_get_iface(NMDhcpClient *self);
|
||||
const char *nm_dhcp_client_get_iface_type_for_log(NMDhcpClient *self);
|
||||
NMDedupMultiIndex *nm_dhcp_client_get_multi_idx(NMDhcpClient *self);
|
||||
int nm_dhcp_client_get_ifindex(NMDhcpClient *self);
|
||||
|
||||
|
|
Loading…
Reference in a new issue