1 From 3baf35269555e2223dbd1733cb1c475cb7f2ed7a Mon Sep 17 00:00:00 2001
2 From: Pavel Zhukov <pzhukov@redhat.com>
3 Date: Thu, 21 Feb 2019 10:35:47 +0100
4 Subject: [PATCH 15/28] Add GUID/DUID to dhcpd logs (#1064416)
7 client/dhclient.c | 70 ++++++++++++++++++++++++++++++++++--------
8 server/dhcp.c | 78 ++++++++++++++++++++++++++++-------------------
9 2 files changed, 105 insertions(+), 43 deletions(-)
11 diff --git a/client/dhclient.c b/client/dhclient.c
12 index 48edddf..181f6e1 100644
13 --- a/client/dhclient.c
14 +++ b/client/dhclient.c
15 @@ -1176,6 +1176,26 @@ main(int argc, char **argv) {
19 + /* We create a backup seed before rediscovering interfaces in order to
20 + have a seed built using all of the available interfaces
21 + It's interesting if required interfaces doesn't let us defined
22 + a really unique seed due to a lack of valid HW addr later
23 + (this is the case with DHCP over IB)
24 + We only use the last device as using a sum could broke the
25 + uniqueness of the seed among multiple nodes
27 + unsigned backup_seed = 0;
28 + for (ip = interfaces; ip; ip = ip -> next) {
30 + if ( ip -> hw_address.hlen <= sizeof seed )
33 + &ip -> hw_address.hbuf [ip -> hw_address.hlen -
34 + sizeof seed], sizeof seed);
39 /* At this point, all the interfaces that the script thinks
40 are relevant should be running, so now we once again call
41 discover_interfaces(), and this time ask it to actually set
42 @@ -1204,14 +1224,34 @@ main(int argc, char **argv) {
43 Not much entropy, but we're booting, so we're not likely to
44 find anything better. */
47 for (ip = interfaces; ip; ip = ip->next) {
49 + if ( ip -> hw_address.hlen <= sizeof seed )
52 &ip->hw_address.hbuf[ip->hw_address.hlen -
53 sizeof seed], sizeof seed);
57 - seed += cur_time + (unsigned)getpid();
58 + if ( seed_flag == 0 ) {
59 + if ( backup_seed != 0 ) {
61 + log_info ("xid: rand init seed (0x%x) built using all"
62 + " available interfaces",seed);
65 + seed = cur_time^((unsigned) gethostid()) ;
66 + log_info ("xid: warning: no netdev with useable HWADDR found"
67 + " for seed's uniqueness enforcement");
68 + log_info ("xid: rand init seed (0x%x) built using gethostid",
71 + /* we only use seed and no current time as a broadcast reply */
72 + /* will certainly be used by the hwaddrless interface */
74 + seed += ((unsigned)(cur_tv.tv_usec * 1000000)) + (unsigned)getpid();
78 @@ -1869,9 +1909,10 @@ void dhcpack (packet)
82 - log_info ("DHCPACK of %s from %s",
83 + log_info ("DHCPACK of %s from %s (xid=0x%x)",
84 inet_ntoa(packet->raw->yiaddr),
85 - piaddr (packet->client_addr));
86 + piaddr (packet -> client_addr),
87 + ntohl(client -> xid));
89 /* Check v6only first. */
90 v6only_wait = check_v6only(packet, client);
91 @@ -2825,7 +2866,7 @@ void dhcpnak (packet)
95 - log_info ("DHCPNAK from %s", piaddr (packet -> client_addr));
96 + log_info ("DHCPNAK from %s (xid=0x%x)", piaddr (packet -> client_addr), ntohl(client -> xid));
98 if (!client -> active) {
100 @@ -2958,10 +2999,10 @@ void send_discover (cpp)
101 (long)(client -> interval));
104 - log_info ("DHCPDISCOVER on %s to %s port %d interval %ld",
105 + log_info ("DHCPDISCOVER on %s to %s port %d interval %ld (xid=0x%x)",
106 client -> name ? client -> name : client -> interface -> name,
107 inet_ntoa (sockaddr_broadcast.sin_addr),
108 - ntohs (sockaddr_broadcast.sin_port), (long)(client -> interval));
109 + ntohs (sockaddr_broadcast.sin_port), (long)(client -> interval), ntohl(client -> xid));
111 /* Send out a packet. */
112 #if defined(DHCPv6) && defined(DHCP4o6)
113 @@ -3355,10 +3396,12 @@ void send_request (cpp)
116 strncpy(rip_buf, rip_str, sizeof(rip_buf)-1);
117 - log_info ("DHCPREQUEST for %s on %s to %s port %d", rip_buf,
118 + log_info ("DHCPREQUEST for %s on %s to %s port %d (xid=0x%x)",
120 client->name ? client->name : client->interface->name,
121 inet_ntoa(destination.sin_addr),
122 - ntohs (destination.sin_port));
123 + ntohs (destination.sin_port),
124 + ntohl(client -> xid));
126 #if defined(DHCPv6) && defined(DHCP4o6)
127 if (dhcpv4_over_dhcpv6) {
128 @@ -3415,11 +3458,13 @@ void send_decline (cpp)
129 log_info ("DHCPDECLINE");
132 - log_info ("DHCPDECLINE of %s on %s to %s port %d",
133 + log_info ("DHCPDECLINE of %s on %s to %s port %d (xid=0x%x)",
134 piaddr(client->requested_address),
135 (client->name ? client->name : client->interface->name),
136 inet_ntoa(sockaddr_broadcast.sin_addr),
137 - ntohs(sockaddr_broadcast.sin_port));
138 + ntohs(sockaddr_broadcast.sin_port),
139 + ntohl(client -> xid));
142 /* Send out a packet. */
143 #if defined(DHCPv6) && defined(DHCP4o6)
144 @@ -3478,11 +3523,12 @@ void send_release (cpp)
145 log_info ("DHCPRELEASE");
148 - log_info ("DHCPRELEASE of %s on %s to %s port %d",
149 + log_info ("DHCPRELEASE of %s on %s to %s port %d (xid=0x%x)",
150 piaddr(client->active->address),
151 client->name ? client->name : client->interface->name,
152 inet_ntoa (destination.sin_addr),
153 - ntohs (destination.sin_port));
154 + ntohs (destination.sin_port),
155 + ntohl(client -> xid));
157 #if defined(DHCPv6) && defined(DHCP4o6)
158 if (dhcpv4_over_dhcpv6) {
159 diff --git a/server/dhcp.c b/server/dhcp.c
160 index ae805a6..8363840 100644
163 @@ -93,6 +93,42 @@ const int dhcp_type_name_max = ((sizeof dhcp_type_names) / sizeof (char *));
165 static TIME leaseTimeCheck(TIME calculated, TIME alternate);
167 +char *print_client_identifier_from_packet (packet)
168 + struct packet *packet;
170 + struct option_cache *oc;
171 + struct data_string client_identifier;
174 + memset (&client_identifier, 0, sizeof client_identifier);
176 + oc = lookup_option (&dhcp_universe, packet -> options,
177 + DHO_DHCP_CLIENT_IDENTIFIER);
179 + evaluate_option_cache (&client_identifier,
180 + packet, (struct lease *)0,
181 + (struct client_state *)0,
183 + (struct option_state *)0,
184 + &global_scope, oc, MDL)) {
185 + ci = print_hw_addr (HTYPE_INFINIBAND, client_identifier.len, client_identifier.data);
186 + data_string_forget (&client_identifier, MDL);
189 + return "\"no client id\"";
192 +char *print_hw_addr_or_client_id (packet)
193 + struct packet *packet;
195 + if (packet -> raw -> htype == HTYPE_INFINIBAND)
196 + return print_client_identifier_from_packet (packet);
198 + return print_hw_addr (packet -> raw -> htype,
199 + packet -> raw -> hlen,
200 + packet -> raw -> chaddr);
204 dhcp (struct packet *packet) {
206 @@ -135,9 +171,7 @@ dhcp (struct packet *packet) {
208 log_info("%s from %s via %s: %s", s,
210 - ? print_hw_addr(packet->raw->htype,
212 - packet->raw->chaddr)
213 + ? print_hw_addr_or_client_id(packet)
214 : "<no identifier>"),
215 packet->raw->giaddr.s_addr
216 ? inet_ntoa(packet->raw->giaddr)
217 @@ -334,9 +368,7 @@ void dhcpdiscover (packet, ms_nulltp)
219 snprintf (msgbuf, sizeof msgbuf, "DHCPDISCOVER from %s %s%s%svia %s",
220 (packet -> raw -> htype
221 - ? print_hw_addr (packet -> raw -> htype,
222 - packet -> raw -> hlen,
223 - packet -> raw -> chaddr)
224 + ? print_hw_addr_or_client_id (packet)
226 ? print_hex_1(lease->uid_len, lease->uid, 60)
227 : "<no identifier>")),
228 @@ -548,9 +580,7 @@ void dhcprequest (packet, ms_nulltp, ip_lease)
229 "DHCPREQUEST for %s%s from %s %s%s%svia %s",
231 (packet -> raw -> htype
232 - ? print_hw_addr (packet -> raw -> htype,
233 - packet -> raw -> hlen,
234 - packet -> raw -> chaddr)
235 + ? print_hw_addr_or_client_id(packet)
237 ? print_hex_1(lease->uid_len, lease->uid, 60)
238 : "<no identifier>")),
239 @@ -791,9 +821,7 @@ void dhcprelease (packet, ms_nulltp)
240 if ((oc = lookup_option (&dhcp_universe, packet -> options,
241 DHO_DHCP_REQUESTED_ADDRESS))) {
242 log_info ("DHCPRELEASE from %s specified requested-address.",
243 - print_hw_addr (packet -> raw -> htype,
244 - packet -> raw -> hlen,
245 - packet -> raw -> chaddr));
246 + print_hw_addr_or_client_id(packet));
249 oc = lookup_option (&dhcp_universe, packet -> options,
250 @@ -885,9 +913,7 @@ void dhcprelease (packet, ms_nulltp)
251 "DHCPRELEASE of %s from %s %s%s%svia %s (%sfound)",
253 (packet -> raw -> htype
254 - ? print_hw_addr (packet -> raw -> htype,
255 - packet -> raw -> hlen,
256 - packet -> raw -> chaddr)
257 + ? print_hw_addr_or_client_id(packet)
259 ? print_hex_1(lease->uid_len, lease->uid, 60)
260 : "<no identifier>")),
261 @@ -992,9 +1018,7 @@ void dhcpdecline (packet, ms_nulltp)
262 "DHCPDECLINE of %s from %s %s%s%svia %s",
264 (packet -> raw -> htype
265 - ? print_hw_addr (packet -> raw -> htype,
266 - packet -> raw -> hlen,
267 - packet -> raw -> chaddr)
268 + ? print_hw_addr_or_client_id(packet)
270 ? print_hex_1(lease->uid_len, lease->uid, 60)
271 : "<no identifier>")),
272 @@ -1740,8 +1764,7 @@ void dhcpinform (packet, ms_nulltp)
273 /* Report what we're sending. */
274 snprintf(msgbuf, sizeof msgbuf, "DHCPACK to %s (%s) via", piaddr(cip),
275 (packet->raw->htype && packet->raw->hlen) ?
276 - print_hw_addr(packet->raw->htype, packet->raw->hlen,
277 - packet->raw->chaddr) :
278 + print_hw_addr_or_client_id(packet) :
279 "<no client hardware address>");
280 log_info("%s %s", msgbuf, gip.len ? piaddr(gip) :
281 packet->interface->name);
282 @@ -1926,9 +1949,7 @@ void nak_lease (packet, cip, network_group)
284 log_info ("DHCPNAK on %s to %s via %s",
286 - print_hw_addr (packet -> raw -> htype,
287 - packet -> raw -> hlen,
288 - packet -> raw -> chaddr),
289 + print_hw_addr_or_client_id(packet),
290 packet -> raw -> giaddr.s_addr
291 ? inet_ntoa (packet -> raw -> giaddr)
292 : packet -> interface -> name);
293 @@ -4044,7 +4065,7 @@ void dhcp_reply (lease)
294 ? (state -> offer == DHCPACK ? "DHCPACK" : "DHCPOFFER")
296 piaddr (lease -> ip_addr),
297 - (lease -> hardware_addr.hlen
298 + (lease -> hardware_addr.hlen > 1
299 ? print_hw_addr (lease -> hardware_addr.hbuf [0],
300 lease -> hardware_addr.hlen - 1,
301 &lease -> hardware_addr.hbuf [1])
302 @@ -4605,10 +4626,7 @@ int find_lease (struct lease **lp,
304 if (uid_lease->binding_state == FTS_ACTIVE) {
305 log_error ("client %s has duplicate%s on %s",
307 - (packet -> raw -> htype,
308 - packet -> raw -> hlen,
309 - packet -> raw -> chaddr)),
310 + (print_hw_addr_or_client_id(packet)),
312 (ip_lease -> subnet ->
313 shared_network -> name));
314 @@ -4775,9 +4793,7 @@ int find_lease (struct lease **lp,
315 log_error("uid lease %s for client %s is duplicate "
317 piaddr(uid_lease->ip_addr),
318 - print_hw_addr(packet->raw->htype,
320 - packet->raw->chaddr),
321 + print_hw_addr_or_client_id(packet),
322 uid_lease->subnet->shared_network->name);
324 if (!packet -> raw -> ciaddr.s_addr &&