2022-03-10 17:06:31 +00:00
|
|
|
From 3baf35269555e2223dbd1733cb1c475cb7f2ed7a Mon Sep 17 00:00:00 2001
|
2019-03-01 11:50:13 +00:00
|
|
|
From: Pavel Zhukov <pzhukov@redhat.com>
|
|
|
|
Date: Thu, 21 Feb 2019 10:35:47 +0100
|
2022-03-10 17:06:31 +00:00
|
|
|
Subject: [PATCH 15/28] Add GUID/DUID to dhcpd logs (#1064416)
|
2019-03-01 11:50:13 +00:00
|
|
|
|
|
|
|
---
|
2022-03-10 17:06:31 +00:00
|
|
|
client/dhclient.c | 70 ++++++++++++++++++++++++++++++++++--------
|
|
|
|
server/dhcp.c | 78 ++++++++++++++++++++++++++++-------------------
|
|
|
|
2 files changed, 105 insertions(+), 43 deletions(-)
|
2019-03-01 11:50:13 +00:00
|
|
|
|
|
|
|
diff --git a/client/dhclient.c b/client/dhclient.c
|
2022-03-10 17:06:31 +00:00
|
|
|
index 48edddf..181f6e1 100644
|
2019-03-01 11:50:13 +00:00
|
|
|
--- a/client/dhclient.c
|
|
|
|
+++ b/client/dhclient.c
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -1176,6 +1176,26 @@ main(int argc, char **argv) {
|
2019-03-01 11:50:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ /* We create a backup seed before rediscovering interfaces in order to
|
|
|
|
+ have a seed built using all of the available interfaces
|
|
|
|
+ It's interesting if required interfaces doesn't let us defined
|
|
|
|
+ a really unique seed due to a lack of valid HW addr later
|
|
|
|
+ (this is the case with DHCP over IB)
|
|
|
|
+ We only use the last device as using a sum could broke the
|
|
|
|
+ uniqueness of the seed among multiple nodes
|
|
|
|
+ */
|
|
|
|
+ unsigned backup_seed = 0;
|
|
|
|
+ for (ip = interfaces; ip; ip = ip -> next) {
|
|
|
|
+ int junk;
|
|
|
|
+ if ( ip -> hw_address.hlen <= sizeof seed )
|
|
|
|
+ continue;
|
|
|
|
+ memcpy (&junk,
|
|
|
|
+ &ip -> hw_address.hbuf [ip -> hw_address.hlen -
|
|
|
|
+ sizeof seed], sizeof seed);
|
|
|
|
+ backup_seed = junk;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
/* At this point, all the interfaces that the script thinks
|
|
|
|
are relevant should be running, so now we once again call
|
|
|
|
discover_interfaces(), and this time ask it to actually set
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -1204,14 +1224,34 @@ main(int argc, char **argv) {
|
|
|
|
Not much entropy, but we're booting, so we're not likely to
|
|
|
|
find anything better. */
|
|
|
|
|
|
|
|
+ int seed_flag = 0;
|
|
|
|
for (ip = interfaces; ip; ip = ip->next) {
|
|
|
|
int junk;
|
|
|
|
+ if ( ip -> hw_address.hlen <= sizeof seed )
|
|
|
|
+ continue;
|
|
|
|
memcpy(&junk,
|
|
|
|
&ip->hw_address.hbuf[ip->hw_address.hlen -
|
|
|
|
sizeof seed], sizeof seed);
|
|
|
|
seed += junk;
|
|
|
|
+ seed_flag = 1;
|
|
|
|
}
|
|
|
|
- seed += cur_time + (unsigned)getpid();
|
|
|
|
+ if ( seed_flag == 0 ) {
|
|
|
|
+ if ( backup_seed != 0 ) {
|
|
|
|
+ seed = backup_seed;
|
|
|
|
+ log_info ("xid: rand init seed (0x%x) built using all"
|
|
|
|
+ " available interfaces",seed);
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ seed = cur_time^((unsigned) gethostid()) ;
|
|
|
|
+ log_info ("xid: warning: no netdev with useable HWADDR found"
|
|
|
|
+ " for seed's uniqueness enforcement");
|
|
|
|
+ log_info ("xid: rand init seed (0x%x) built using gethostid",
|
|
|
|
+ seed);
|
|
|
|
+ }
|
|
|
|
+ /* we only use seed and no current time as a broadcast reply */
|
|
|
|
+ /* will certainly be used by the hwaddrless interface */
|
2019-03-01 11:50:13 +00:00
|
|
|
+ }
|
2022-03-10 17:06:31 +00:00
|
|
|
+ seed += ((unsigned)(cur_tv.tv_usec * 1000000)) + (unsigned)getpid();
|
|
|
|
}
|
|
|
|
srandom(seed);
|
2019-03-01 11:50:13 +00:00
|
|
|
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -1869,9 +1909,10 @@ void dhcpack (packet)
|
2019-03-01 11:50:13 +00:00
|
|
|
return;
|
|
|
|
}
|
2022-03-10 17:06:31 +00:00
|
|
|
|
2019-03-01 11:50:13 +00:00
|
|
|
- log_info ("DHCPACK of %s from %s",
|
|
|
|
+ log_info ("DHCPACK of %s from %s (xid=0x%x)",
|
2022-03-10 17:06:31 +00:00
|
|
|
inet_ntoa(packet->raw->yiaddr),
|
|
|
|
- piaddr (packet->client_addr));
|
|
|
|
+ piaddr (packet -> client_addr),
|
|
|
|
+ ntohl(client -> xid));
|
2019-03-01 11:50:13 +00:00
|
|
|
|
2022-03-10 17:06:31 +00:00
|
|
|
/* Check v6only first. */
|
|
|
|
v6only_wait = check_v6only(packet, client);
|
|
|
|
@@ -2825,7 +2866,7 @@ void dhcpnak (packet)
|
2019-03-01 11:50:13 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
- log_info ("DHCPNAK from %s", piaddr (packet -> client_addr));
|
|
|
|
+ log_info ("DHCPNAK from %s (xid=0x%x)", piaddr (packet -> client_addr), ntohl(client -> xid));
|
|
|
|
|
|
|
|
if (!client -> active) {
|
|
|
|
#if defined (DEBUG)
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -2958,10 +2999,10 @@ void send_discover (cpp)
|
2019-03-01 11:50:13 +00:00
|
|
|
(long)(client -> interval));
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
- log_info ("DHCPDISCOVER on %s to %s port %d interval %ld",
|
|
|
|
+ log_info ("DHCPDISCOVER on %s to %s port %d interval %ld (xid=0x%x)",
|
|
|
|
client -> name ? client -> name : client -> interface -> name,
|
|
|
|
inet_ntoa (sockaddr_broadcast.sin_addr),
|
|
|
|
- ntohs (sockaddr_broadcast.sin_port), (long)(client -> interval));
|
|
|
|
+ ntohs (sockaddr_broadcast.sin_port), (long)(client -> interval), ntohl(client -> xid));
|
|
|
|
|
|
|
|
/* Send out a packet. */
|
|
|
|
#if defined(DHCPv6) && defined(DHCP4o6)
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -3355,10 +3396,12 @@ void send_request (cpp)
|
2019-03-01 11:50:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
strncpy(rip_buf, rip_str, sizeof(rip_buf)-1);
|
|
|
|
- log_info ("DHCPREQUEST for %s on %s to %s port %d", rip_buf,
|
|
|
|
+ log_info ("DHCPREQUEST for %s on %s to %s port %d (xid=0x%x)",
|
|
|
|
+ rip_buf,
|
|
|
|
client->name ? client->name : client->interface->name,
|
|
|
|
inet_ntoa(destination.sin_addr),
|
|
|
|
- ntohs (destination.sin_port));
|
|
|
|
+ ntohs (destination.sin_port),
|
|
|
|
+ ntohl(client -> xid));
|
|
|
|
|
|
|
|
#if defined(DHCPv6) && defined(DHCP4o6)
|
|
|
|
if (dhcpv4_over_dhcpv6) {
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -3415,11 +3458,13 @@ void send_decline (cpp)
|
2019-03-01 11:50:13 +00:00
|
|
|
log_info ("DHCPDECLINE");
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
- log_info ("DHCPDECLINE of %s on %s to %s port %d",
|
|
|
|
+ log_info ("DHCPDECLINE of %s on %s to %s port %d (xid=0x%x)",
|
|
|
|
piaddr(client->requested_address),
|
|
|
|
(client->name ? client->name : client->interface->name),
|
|
|
|
inet_ntoa(sockaddr_broadcast.sin_addr),
|
|
|
|
- ntohs(sockaddr_broadcast.sin_port));
|
|
|
|
+ ntohs(sockaddr_broadcast.sin_port),
|
|
|
|
+ ntohl(client -> xid));
|
|
|
|
+
|
|
|
|
|
|
|
|
/* Send out a packet. */
|
|
|
|
#if defined(DHCPv6) && defined(DHCP4o6)
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -3478,11 +3523,12 @@ void send_release (cpp)
|
2019-03-01 11:50:13 +00:00
|
|
|
log_info ("DHCPRELEASE");
|
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
- log_info ("DHCPRELEASE of %s on %s to %s port %d",
|
|
|
|
+ log_info ("DHCPRELEASE of %s on %s to %s port %d (xid=0x%x)",
|
|
|
|
piaddr(client->active->address),
|
|
|
|
client->name ? client->name : client->interface->name,
|
|
|
|
inet_ntoa (destination.sin_addr),
|
|
|
|
- ntohs (destination.sin_port));
|
|
|
|
+ ntohs (destination.sin_port),
|
|
|
|
+ ntohl(client -> xid));
|
|
|
|
|
|
|
|
#if defined(DHCPv6) && defined(DHCP4o6)
|
|
|
|
if (dhcpv4_over_dhcpv6) {
|
|
|
|
diff --git a/server/dhcp.c b/server/dhcp.c
|
2022-03-10 17:06:31 +00:00
|
|
|
index ae805a6..8363840 100644
|
2019-03-01 11:50:13 +00:00
|
|
|
--- a/server/dhcp.c
|
|
|
|
+++ b/server/dhcp.c
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -93,6 +93,42 @@ const int dhcp_type_name_max = ((sizeof dhcp_type_names) / sizeof (char *));
|
2019-03-01 11:50:13 +00:00
|
|
|
|
|
|
|
static TIME leaseTimeCheck(TIME calculated, TIME alternate);
|
|
|
|
|
|
|
|
+char *print_client_identifier_from_packet (packet)
|
|
|
|
+ struct packet *packet;
|
|
|
|
+{
|
|
|
|
+ struct option_cache *oc;
|
|
|
|
+ struct data_string client_identifier;
|
|
|
|
+ char *ci;
|
|
|
|
+
|
|
|
|
+ memset (&client_identifier, 0, sizeof client_identifier);
|
|
|
|
+
|
|
|
|
+ oc = lookup_option (&dhcp_universe, packet -> options,
|
|
|
|
+ DHO_DHCP_CLIENT_IDENTIFIER);
|
|
|
|
+ if (oc &&
|
|
|
|
+ evaluate_option_cache (&client_identifier,
|
|
|
|
+ packet, (struct lease *)0,
|
|
|
|
+ (struct client_state *)0,
|
|
|
|
+ packet -> options,
|
|
|
|
+ (struct option_state *)0,
|
|
|
|
+ &global_scope, oc, MDL)) {
|
|
|
|
+ ci = print_hw_addr (HTYPE_INFINIBAND, client_identifier.len, client_identifier.data);
|
|
|
|
+ data_string_forget (&client_identifier, MDL);
|
|
|
|
+ return ci;
|
|
|
|
+ } else
|
|
|
|
+ return "\"no client id\"";
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+char *print_hw_addr_or_client_id (packet)
|
|
|
|
+ struct packet *packet;
|
|
|
|
+{
|
|
|
|
+ if (packet -> raw -> htype == HTYPE_INFINIBAND)
|
|
|
|
+ return print_client_identifier_from_packet (packet);
|
|
|
|
+ else
|
|
|
|
+ return print_hw_addr (packet -> raw -> htype,
|
|
|
|
+ packet -> raw -> hlen,
|
|
|
|
+ packet -> raw -> chaddr);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
void
|
|
|
|
dhcp (struct packet *packet) {
|
|
|
|
int ms_nulltp = 0;
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -135,9 +171,7 @@ dhcp (struct packet *packet) {
|
2019-03-01 11:50:13 +00:00
|
|
|
|
|
|
|
log_info("%s from %s via %s: %s", s,
|
|
|
|
(packet->raw->htype
|
|
|
|
- ? print_hw_addr(packet->raw->htype,
|
|
|
|
- packet->raw->hlen,
|
|
|
|
- packet->raw->chaddr)
|
|
|
|
+ ? print_hw_addr_or_client_id(packet)
|
|
|
|
: "<no identifier>"),
|
|
|
|
packet->raw->giaddr.s_addr
|
|
|
|
? inet_ntoa(packet->raw->giaddr)
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -334,9 +368,7 @@ void dhcpdiscover (packet, ms_nulltp)
|
2019-03-01 11:50:13 +00:00
|
|
|
#endif
|
|
|
|
snprintf (msgbuf, sizeof msgbuf, "DHCPDISCOVER from %s %s%s%svia %s",
|
|
|
|
(packet -> raw -> htype
|
|
|
|
- ? print_hw_addr (packet -> raw -> htype,
|
|
|
|
- packet -> raw -> hlen,
|
|
|
|
- packet -> raw -> chaddr)
|
|
|
|
+ ? print_hw_addr_or_client_id (packet)
|
|
|
|
: (lease
|
|
|
|
? print_hex_1(lease->uid_len, lease->uid, 60)
|
|
|
|
: "<no identifier>")),
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -548,9 +580,7 @@ void dhcprequest (packet, ms_nulltp, ip_lease)
|
2019-03-01 11:50:13 +00:00
|
|
|
"DHCPREQUEST for %s%s from %s %s%s%svia %s",
|
|
|
|
piaddr (cip), smbuf,
|
|
|
|
(packet -> raw -> htype
|
|
|
|
- ? print_hw_addr (packet -> raw -> htype,
|
|
|
|
- packet -> raw -> hlen,
|
|
|
|
- packet -> raw -> chaddr)
|
|
|
|
+ ? print_hw_addr_or_client_id(packet)
|
|
|
|
: (lease
|
|
|
|
? print_hex_1(lease->uid_len, lease->uid, 60)
|
|
|
|
: "<no identifier>")),
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -791,9 +821,7 @@ void dhcprelease (packet, ms_nulltp)
|
2019-03-01 11:50:13 +00:00
|
|
|
if ((oc = lookup_option (&dhcp_universe, packet -> options,
|
|
|
|
DHO_DHCP_REQUESTED_ADDRESS))) {
|
|
|
|
log_info ("DHCPRELEASE from %s specified requested-address.",
|
|
|
|
- print_hw_addr (packet -> raw -> htype,
|
|
|
|
- packet -> raw -> hlen,
|
|
|
|
- packet -> raw -> chaddr));
|
|
|
|
+ print_hw_addr_or_client_id(packet));
|
|
|
|
}
|
|
|
|
|
|
|
|
oc = lookup_option (&dhcp_universe, packet -> options,
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -885,9 +913,7 @@ void dhcprelease (packet, ms_nulltp)
|
2019-03-01 11:50:13 +00:00
|
|
|
"DHCPRELEASE of %s from %s %s%s%svia %s (%sfound)",
|
|
|
|
cstr,
|
|
|
|
(packet -> raw -> htype
|
|
|
|
- ? print_hw_addr (packet -> raw -> htype,
|
|
|
|
- packet -> raw -> hlen,
|
|
|
|
- packet -> raw -> chaddr)
|
|
|
|
+ ? print_hw_addr_or_client_id(packet)
|
|
|
|
: (lease
|
|
|
|
? print_hex_1(lease->uid_len, lease->uid, 60)
|
|
|
|
: "<no identifier>")),
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -992,9 +1018,7 @@ void dhcpdecline (packet, ms_nulltp)
|
2019-03-01 11:50:13 +00:00
|
|
|
"DHCPDECLINE of %s from %s %s%s%svia %s",
|
|
|
|
piaddr (cip),
|
|
|
|
(packet -> raw -> htype
|
|
|
|
- ? print_hw_addr (packet -> raw -> htype,
|
|
|
|
- packet -> raw -> hlen,
|
|
|
|
- packet -> raw -> chaddr)
|
|
|
|
+ ? print_hw_addr_or_client_id(packet)
|
|
|
|
: (lease
|
|
|
|
? print_hex_1(lease->uid_len, lease->uid, 60)
|
|
|
|
: "<no identifier>")),
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -1740,8 +1764,7 @@ void dhcpinform (packet, ms_nulltp)
|
2019-03-01 11:50:13 +00:00
|
|
|
/* Report what we're sending. */
|
|
|
|
snprintf(msgbuf, sizeof msgbuf, "DHCPACK to %s (%s) via", piaddr(cip),
|
|
|
|
(packet->raw->htype && packet->raw->hlen) ?
|
|
|
|
- print_hw_addr(packet->raw->htype, packet->raw->hlen,
|
|
|
|
- packet->raw->chaddr) :
|
|
|
|
+ print_hw_addr_or_client_id(packet) :
|
|
|
|
"<no client hardware address>");
|
|
|
|
log_info("%s %s", msgbuf, gip.len ? piaddr(gip) :
|
|
|
|
packet->interface->name);
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -1926,9 +1949,7 @@ void nak_lease (packet, cip, network_group)
|
2019-03-01 11:50:13 +00:00
|
|
|
#endif
|
|
|
|
log_info ("DHCPNAK on %s to %s via %s",
|
|
|
|
piaddr (*cip),
|
|
|
|
- print_hw_addr (packet -> raw -> htype,
|
|
|
|
- packet -> raw -> hlen,
|
|
|
|
- packet -> raw -> chaddr),
|
|
|
|
+ print_hw_addr_or_client_id(packet),
|
|
|
|
packet -> raw -> giaddr.s_addr
|
|
|
|
? inet_ntoa (packet -> raw -> giaddr)
|
|
|
|
: packet -> interface -> name);
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -4044,7 +4065,7 @@ void dhcp_reply (lease)
|
2019-03-01 11:50:13 +00:00
|
|
|
? (state -> offer == DHCPACK ? "DHCPACK" : "DHCPOFFER")
|
|
|
|
: "BOOTREPLY"),
|
|
|
|
piaddr (lease -> ip_addr),
|
|
|
|
- (lease -> hardware_addr.hlen
|
|
|
|
+ (lease -> hardware_addr.hlen > 1
|
|
|
|
? print_hw_addr (lease -> hardware_addr.hbuf [0],
|
|
|
|
lease -> hardware_addr.hlen - 1,
|
|
|
|
&lease -> hardware_addr.hbuf [1])
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -4605,10 +4626,7 @@ int find_lease (struct lease **lp,
|
2019-03-01 11:50:13 +00:00
|
|
|
if (uid_lease) {
|
|
|
|
if (uid_lease->binding_state == FTS_ACTIVE) {
|
|
|
|
log_error ("client %s has duplicate%s on %s",
|
|
|
|
- (print_hw_addr
|
|
|
|
- (packet -> raw -> htype,
|
|
|
|
- packet -> raw -> hlen,
|
|
|
|
- packet -> raw -> chaddr)),
|
|
|
|
+ (print_hw_addr_or_client_id(packet)),
|
|
|
|
" leases",
|
|
|
|
(ip_lease -> subnet ->
|
|
|
|
shared_network -> name));
|
2022-03-10 17:06:31 +00:00
|
|
|
@@ -4775,9 +4793,7 @@ int find_lease (struct lease **lp,
|
2019-03-01 11:50:13 +00:00
|
|
|
log_error("uid lease %s for client %s is duplicate "
|
|
|
|
"on %s",
|
|
|
|
piaddr(uid_lease->ip_addr),
|
|
|
|
- print_hw_addr(packet->raw->htype,
|
|
|
|
- packet->raw->hlen,
|
|
|
|
- packet->raw->chaddr),
|
|
|
|
+ print_hw_addr_or_client_id(packet),
|
|
|
|
uid_lease->subnet->shared_network->name);
|
|
|
|
|
|
|
|
if (!packet -> raw -> ciaddr.s_addr &&
|
|
|
|
--
|
2022-03-10 17:06:31 +00:00
|
|
|
2.35.1
|
2019-03-01 11:50:13 +00:00
|
|
|
|