]> git.ipfire.org Git - ipfire-3.x.git/blame - dhcp/patches/0015-Add-GUID-DUID-to-dhcpd-logs-1064416.patch
kernel: Update to 5.3.7
[ipfire-3.x.git] / dhcp / patches / 0015-Add-GUID-DUID-to-dhcpd-logs-1064416.patch
CommitLineData
530cba5e
SS
1From 7ac7d0b00874ee996c7ee75a595c029759368aad Mon Sep 17 00:00:00 2001
2From: Pavel Zhukov <pzhukov@redhat.com>
3Date: Thu, 21 Feb 2019 10:35:47 +0100
4Subject: [PATCH 15/21] Add GUID/DUID to dhcpd logs (#1064416)
5Cc: pzhukov@redhat.com
6
7---
8 client/dhclient.c | 75 ++++++++++++++++++++++++++++++++++++++++++----------
9 server/dhcp.c | 78 +++++++++++++++++++++++++++++++++----------------------
10 2 files changed, 108 insertions(+), 45 deletions(-)
11
12diff --git a/client/dhclient.c b/client/dhclient.c
13index dc9080e..8e57da9 100644
14--- a/client/dhclient.c
15+++ b/client/dhclient.c
16@@ -1170,6 +1170,26 @@ main(int argc, char **argv) {
17 }
18 }
19
20+ /* We create a backup seed before rediscovering interfaces in order to
21+ have a seed built using all of the available interfaces
22+ It's interesting if required interfaces doesn't let us defined
23+ a really unique seed due to a lack of valid HW addr later
24+ (this is the case with DHCP over IB)
25+ We only use the last device as using a sum could broke the
26+ uniqueness of the seed among multiple nodes
27+ */
28+ unsigned backup_seed = 0;
29+ for (ip = interfaces; ip; ip = ip -> next) {
30+ int junk;
31+ if ( ip -> hw_address.hlen <= sizeof seed )
32+ continue;
33+ memcpy (&junk,
34+ &ip -> hw_address.hbuf [ip -> hw_address.hlen -
35+ sizeof seed], sizeof seed);
36+ backup_seed = junk;
37+ }
38+
39+
40 /* At this point, all the interfaces that the script thinks
41 are relevant should be running, so now we once again call
42 discover_interfaces(), and this time ask it to actually set
43@@ -1184,14 +1204,36 @@ main(int argc, char **argv) {
44 Not much entropy, but we're booting, so we're not likely to
45 find anything better. */
46 seed = 0;
47+ int seed_flag = 0;
48 for (ip = interfaces; ip; ip = ip->next) {
49 int junk;
50+ if ( ip -> hw_address.hlen <= sizeof seed )
51+ continue;
52 memcpy(&junk,
53 &ip->hw_address.hbuf[ip->hw_address.hlen -
54 sizeof seed], sizeof seed);
55 seed += junk;
56+ seed_flag = 1;
57 }
58- srandom(seed + cur_time + (unsigned)getpid());
59+ if ( seed_flag == 0 ) {
60+ if ( backup_seed != 0 ) {
61+ seed = backup_seed;
62+ log_info ("xid: rand init seed (0x%x) built using all"
63+ " available interfaces",seed);
64+ }
65+ else {
66+ seed = cur_time^((unsigned) gethostid()) ;
67+ log_info ("xid: warning: no netdev with useable HWADDR found"
68+ " for seed's uniqueness enforcement");
69+ log_info ("xid: rand init seed (0x%x) built using gethostid",
70+ seed);
71+ }
72+ /* we only use seed and no current time as a broadcast reply */
73+ /* will certainly be used by the hwaddrless interface */
74+ srandom(seed + ((unsigned)(cur_tv.tv_usec * 1000000)) + (unsigned)getpid());
75+ }
76+ else
77+ srandom(seed + ((unsigned)(cur_tv.tv_usec * 1000000)) + (unsigned)getpid());
78
79 /* Setup specific Infiniband options */
80 for (ip = interfaces; ip; ip = ip->next) {
81@@ -1746,10 +1788,10 @@ void dhcpack (packet)
82 #endif
83 return;
84 }
85-
86- log_info ("DHCPACK of %s from %s",
87- inet_ntoa(packet->raw->yiaddr),
88- piaddr (packet->client_addr));
89+ log_info ("DHCPACK of %s from %s (xid=0x%x)",
90+ inet_ntoa(packet->raw->yiaddr),
91+ piaddr (packet -> client_addr),
92+ ntohl(client -> xid));
93
94 lease = packet_to_lease (packet, client);
95 if (!lease) {
96@@ -2669,7 +2711,7 @@ void dhcpnak (packet)
97 return;
98 }
99
100- log_info ("DHCPNAK from %s", piaddr (packet -> client_addr));
101+ log_info ("DHCPNAK from %s (xid=0x%x)", piaddr (packet -> client_addr), ntohl(client -> xid));
102
103 if (!client -> active) {
104 #if defined (DEBUG)
105@@ -2802,10 +2844,10 @@ void send_discover (cpp)
106 (long)(client -> interval));
107 } else
108 #endif
109- log_info ("DHCPDISCOVER on %s to %s port %d interval %ld",
110+ log_info ("DHCPDISCOVER on %s to %s port %d interval %ld (xid=0x%x)",
111 client -> name ? client -> name : client -> interface -> name,
112 inet_ntoa (sockaddr_broadcast.sin_addr),
113- ntohs (sockaddr_broadcast.sin_port), (long)(client -> interval));
114+ ntohs (sockaddr_broadcast.sin_port), (long)(client -> interval), ntohl(client -> xid));
115
116 /* Send out a packet. */
117 #if defined(DHCPv6) && defined(DHCP4o6)
118@@ -3108,10 +3150,12 @@ void send_request (cpp)
119 }
120
121 strncpy(rip_buf, rip_str, sizeof(rip_buf)-1);
122- log_info ("DHCPREQUEST for %s on %s to %s port %d", rip_buf,
123+ log_info ("DHCPREQUEST for %s on %s to %s port %d (xid=0x%x)",
124+ rip_buf,
125 client->name ? client->name : client->interface->name,
126 inet_ntoa(destination.sin_addr),
127- ntohs (destination.sin_port));
128+ ntohs (destination.sin_port),
129+ ntohl(client -> xid));
130
131 #if defined(DHCPv6) && defined(DHCP4o6)
132 if (dhcpv4_over_dhcpv6) {
133@@ -3168,11 +3212,13 @@ void send_decline (cpp)
134 log_info ("DHCPDECLINE");
135 } else
136 #endif
137- log_info ("DHCPDECLINE of %s on %s to %s port %d",
138+ log_info ("DHCPDECLINE of %s on %s to %s port %d (xid=0x%x)",
139 piaddr(client->requested_address),
140 (client->name ? client->name : client->interface->name),
141 inet_ntoa(sockaddr_broadcast.sin_addr),
142- ntohs(sockaddr_broadcast.sin_port));
143+ ntohs(sockaddr_broadcast.sin_port),
144+ ntohl(client -> xid));
145+
146
147 /* Send out a packet. */
148 #if defined(DHCPv6) && defined(DHCP4o6)
149@@ -3231,11 +3277,12 @@ void send_release (cpp)
150 log_info ("DHCPRELEASE");
151 } else
152 #endif
153- log_info ("DHCPRELEASE of %s on %s to %s port %d",
154+ log_info ("DHCPRELEASE of %s on %s to %s port %d (xid=0x%x)",
155 piaddr(client->active->address),
156 client->name ? client->name : client->interface->name,
157 inet_ntoa (destination.sin_addr),
158- ntohs (destination.sin_port));
159+ ntohs (destination.sin_port),
160+ ntohl(client -> xid));
161
162 #if defined(DHCPv6) && defined(DHCP4o6)
163 if (dhcpv4_over_dhcpv6) {
164diff --git a/server/dhcp.c b/server/dhcp.c
165index 20f2a62..0582c4c 100644
166--- a/server/dhcp.c
167+++ b/server/dhcp.c
168@@ -87,6 +87,42 @@ const int dhcp_type_name_max = ((sizeof dhcp_type_names) / sizeof (char *));
169
170 static TIME leaseTimeCheck(TIME calculated, TIME alternate);
171
172+char *print_client_identifier_from_packet (packet)
173+ struct packet *packet;
174+{
175+ struct option_cache *oc;
176+ struct data_string client_identifier;
177+ char *ci;
178+
179+ memset (&client_identifier, 0, sizeof client_identifier);
180+
181+ oc = lookup_option (&dhcp_universe, packet -> options,
182+ DHO_DHCP_CLIENT_IDENTIFIER);
183+ if (oc &&
184+ evaluate_option_cache (&client_identifier,
185+ packet, (struct lease *)0,
186+ (struct client_state *)0,
187+ packet -> options,
188+ (struct option_state *)0,
189+ &global_scope, oc, MDL)) {
190+ ci = print_hw_addr (HTYPE_INFINIBAND, client_identifier.len, client_identifier.data);
191+ data_string_forget (&client_identifier, MDL);
192+ return ci;
193+ } else
194+ return "\"no client id\"";
195+}
196+
197+char *print_hw_addr_or_client_id (packet)
198+ struct packet *packet;
199+{
200+ if (packet -> raw -> htype == HTYPE_INFINIBAND)
201+ return print_client_identifier_from_packet (packet);
202+ else
203+ return print_hw_addr (packet -> raw -> htype,
204+ packet -> raw -> hlen,
205+ packet -> raw -> chaddr);
206+}
207+
208 void
209 dhcp (struct packet *packet) {
210 int ms_nulltp = 0;
211@@ -129,9 +165,7 @@ dhcp (struct packet *packet) {
212
213 log_info("%s from %s via %s: %s", s,
214 (packet->raw->htype
215- ? print_hw_addr(packet->raw->htype,
216- packet->raw->hlen,
217- packet->raw->chaddr)
218+ ? print_hw_addr_or_client_id(packet)
219 : "<no identifier>"),
220 packet->raw->giaddr.s_addr
221 ? inet_ntoa(packet->raw->giaddr)
222@@ -328,9 +362,7 @@ void dhcpdiscover (packet, ms_nulltp)
223 #endif
224 snprintf (msgbuf, sizeof msgbuf, "DHCPDISCOVER from %s %s%s%svia %s",
225 (packet -> raw -> htype
226- ? print_hw_addr (packet -> raw -> htype,
227- packet -> raw -> hlen,
228- packet -> raw -> chaddr)
229+ ? print_hw_addr_or_client_id (packet)
230 : (lease
231 ? print_hex_1(lease->uid_len, lease->uid, 60)
232 : "<no identifier>")),
233@@ -542,9 +574,7 @@ void dhcprequest (packet, ms_nulltp, ip_lease)
234 "DHCPREQUEST for %s%s from %s %s%s%svia %s",
235 piaddr (cip), smbuf,
236 (packet -> raw -> htype
237- ? print_hw_addr (packet -> raw -> htype,
238- packet -> raw -> hlen,
239- packet -> raw -> chaddr)
240+ ? print_hw_addr_or_client_id(packet)
241 : (lease
242 ? print_hex_1(lease->uid_len, lease->uid, 60)
243 : "<no identifier>")),
244@@ -785,9 +815,7 @@ void dhcprelease (packet, ms_nulltp)
245 if ((oc = lookup_option (&dhcp_universe, packet -> options,
246 DHO_DHCP_REQUESTED_ADDRESS))) {
247 log_info ("DHCPRELEASE from %s specified requested-address.",
248- print_hw_addr (packet -> raw -> htype,
249- packet -> raw -> hlen,
250- packet -> raw -> chaddr));
251+ print_hw_addr_or_client_id(packet));
252 }
253
254 oc = lookup_option (&dhcp_universe, packet -> options,
255@@ -879,9 +907,7 @@ void dhcprelease (packet, ms_nulltp)
256 "DHCPRELEASE of %s from %s %s%s%svia %s (%sfound)",
257 cstr,
258 (packet -> raw -> htype
259- ? print_hw_addr (packet -> raw -> htype,
260- packet -> raw -> hlen,
261- packet -> raw -> chaddr)
262+ ? print_hw_addr_or_client_id(packet)
263 : (lease
264 ? print_hex_1(lease->uid_len, lease->uid, 60)
265 : "<no identifier>")),
266@@ -986,9 +1012,7 @@ void dhcpdecline (packet, ms_nulltp)
267 "DHCPDECLINE of %s from %s %s%s%svia %s",
268 piaddr (cip),
269 (packet -> raw -> htype
270- ? print_hw_addr (packet -> raw -> htype,
271- packet -> raw -> hlen,
272- packet -> raw -> chaddr)
273+ ? print_hw_addr_or_client_id(packet)
274 : (lease
275 ? print_hex_1(lease->uid_len, lease->uid, 60)
276 : "<no identifier>")),
277@@ -1732,8 +1756,7 @@ void dhcpinform (packet, ms_nulltp)
278 /* Report what we're sending. */
279 snprintf(msgbuf, sizeof msgbuf, "DHCPACK to %s (%s) via", piaddr(cip),
280 (packet->raw->htype && packet->raw->hlen) ?
281- print_hw_addr(packet->raw->htype, packet->raw->hlen,
282- packet->raw->chaddr) :
283+ print_hw_addr_or_client_id(packet) :
284 "<no client hardware address>");
285 log_info("%s %s", msgbuf, gip.len ? piaddr(gip) :
286 packet->interface->name);
287@@ -1918,9 +1941,7 @@ void nak_lease (packet, cip, network_group)
288 #endif
289 log_info ("DHCPNAK on %s to %s via %s",
290 piaddr (*cip),
291- print_hw_addr (packet -> raw -> htype,
292- packet -> raw -> hlen,
293- packet -> raw -> chaddr),
294+ print_hw_addr_or_client_id(packet),
295 packet -> raw -> giaddr.s_addr
296 ? inet_ntoa (packet -> raw -> giaddr)
297 : packet -> interface -> name);
298@@ -3936,7 +3957,7 @@ void dhcp_reply (lease)
299 ? (state -> offer == DHCPACK ? "DHCPACK" : "DHCPOFFER")
300 : "BOOTREPLY"),
301 piaddr (lease -> ip_addr),
302- (lease -> hardware_addr.hlen
303+ (lease -> hardware_addr.hlen > 1
304 ? print_hw_addr (lease -> hardware_addr.hbuf [0],
305 lease -> hardware_addr.hlen - 1,
306 &lease -> hardware_addr.hbuf [1])
307@@ -4497,10 +4518,7 @@ int find_lease (struct lease **lp,
308 if (uid_lease) {
309 if (uid_lease->binding_state == FTS_ACTIVE) {
310 log_error ("client %s has duplicate%s on %s",
311- (print_hw_addr
312- (packet -> raw -> htype,
313- packet -> raw -> hlen,
314- packet -> raw -> chaddr)),
315+ (print_hw_addr_or_client_id(packet)),
316 " leases",
317 (ip_lease -> subnet ->
318 shared_network -> name));
319@@ -4667,9 +4685,7 @@ int find_lease (struct lease **lp,
320 log_error("uid lease %s for client %s is duplicate "
321 "on %s",
322 piaddr(uid_lease->ip_addr),
323- print_hw_addr(packet->raw->htype,
324- packet->raw->hlen,
325- packet->raw->chaddr),
326+ print_hw_addr_or_client_id(packet),
327 uid_lease->subnet->shared_network->name);
328
329 if (!packet -> raw -> ciaddr.s_addr &&
330--
3312.14.5