device: log ACD conflicts

l3cfg emits a log for ACD conflicts. However, l3cfg is not aware of
what are the related NMDevice or the currently active connection, and
so it can't log the proper metadata fields (NM_DEVICE and
NM_CONNECTION) to the journal.

Instead, let NMDevice log about ACD collisions; in this way, it is
possible to get the message when filtering by device and connection.
For example:

 $ journalctl -e NM_CONNECTION=d1df47be-721f-472d-a1bf-51815ac7ec3d + NM_DEVICE=veth0
 <info> device (veth0): IP address 172.25.42.1 cannot be configured because it is already in use in the network by host 00:99:88:77:66:55
 <info> device (veth0): state change: ip-config -> failed (reason 'ip-config-unavailable', sys-iface-state: 'managed')
 <warn> device (veth0): Activation: failed for connection 'veth0+'

(cherry picked from commit 9143c1b542)
This commit is contained in:
Beniamino Galvani 2023-08-10 17:36:49 +02:00
parent 287252414b
commit 8a91b7beb4

View file

@ -4247,6 +4247,20 @@ _dev_l3_cfg_notify_cb(NML3Cfg *l3cfg, const NML3ConfigNotifyData *notify_data, N
case NM_L3_CONFIG_NOTIFY_TYPE_ACD_EVENT:
{
const NML3AcdAddrInfo *addr_info = &notify_data->acd_event.info;
char buf_addr[NM_INET_ADDRSTRLEN];
if (addr_info->state == NM_L3_ACD_ADDR_STATE_USED) {
_LOGI(LOGD_DEVICE,
"IP address %s cannot be configured because it is already in use in the "
"network by host %s",
nm_inet4_ntop(addr_info->addr, buf_addr),
nm_ether_addr_to_string_a(&addr_info->last_conflict_addr));
} else if (addr_info->state == NM_L3_ACD_ADDR_STATE_CONFLICT) {
_LOGI(LOGD_DEVICE,
"conflict detected for IP address %s with host %s",
nm_inet4_ntop(addr_info->addr, buf_addr),
nm_ether_addr_to_string_a(&addr_info->last_conflict_addr));
}
if (addr_info->state > NM_L3_ACD_ADDR_STATE_PROBING)
_dev_ipmanual_check_ready(self);