]> git.pld-linux.org Git - packages/dhcp.git/blob - dhcp-add-guid-duid-to-logs.patch
- updated to 4.4.3-P1
[packages/dhcp.git] / dhcp-add-guid-duid-to-logs.patch
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)
5
6 ---
7  client/dhclient.c | 70 ++++++++++++++++++++++++++++++++++--------
8  server/dhcp.c     | 78 ++++++++++++++++++++++++++++-------------------
9  2 files changed, 105 insertions(+), 43 deletions(-)
10
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) {
16                 }
17         }
18  
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
26 +        */
27 +       unsigned backup_seed = 0;
28 +       for (ip = interfaces; ip; ip = ip -> next) {
29 +               int junk;
30 +               if ( ip -> hw_address.hlen <= sizeof seed )
31 +                 continue;
32 +               memcpy (&junk,
33 +                       &ip -> hw_address.hbuf [ip -> hw_address.hlen -
34 +                                               sizeof seed], sizeof seed);
35 +               backup_seed = junk;
36 +       }
37 +
38 +
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. */
45  
46 +               int seed_flag = 0;
47                 for (ip = interfaces; ip; ip = ip->next) {
48                         int junk;
49 +                       if ( ip -> hw_address.hlen <= sizeof seed )
50 +                         continue;
51                         memcpy(&junk,
52                                &ip->hw_address.hbuf[ip->hw_address.hlen -
53                                                     sizeof seed], sizeof seed);
54                         seed += junk;
55 +                       seed_flag = 1;
56                 }
57 -               seed += cur_time + (unsigned)getpid();
58 +               if ( seed_flag == 0 ) {
59 +                       if ( backup_seed != 0 ) {
60 +                         seed = backup_seed;
61 +                         log_info ("xid: rand init seed (0x%x) built using all"
62 +                                   " available interfaces",seed);
63 +                       }
64 +                       else {
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",
69 +                                   seed);
70 +                       }
71 +                       /* we only use seed and no current time as a broadcast reply */
72 +                       /* will certainly be used by the hwaddrless interface */
73 +               }
74 +               seed += ((unsigned)(cur_tv.tv_usec * 1000000)) + (unsigned)getpid();
75         }
76         srandom(seed);
77  
78 @@ -1869,9 +1909,10 @@ void dhcpack (packet)
79                 return;
80         }
81  
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));
88  
89         /* Check v6only first. */
90         v6only_wait = check_v6only(packet, client);
91 @@ -2825,7 +2866,7 @@ void dhcpnak (packet)
92                 return;
93         }
94  
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));
97  
98         if (!client -> active) {
99  #if defined (DEBUG)
100 @@ -2958,10 +2999,10 @@ void send_discover (cpp)
101                           (long)(client -> interval));
102         } else
103  #endif
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));
110  
111         /* Send out a packet. */
112  #if defined(DHCPv6) && defined(DHCP4o6)
113 @@ -3355,10 +3396,12 @@ void send_request (cpp)
114         }
115  
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)",
119 +                  rip_buf,
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));
125  
126  #if defined(DHCPv6) && defined(DHCP4o6)
127         if (dhcpv4_over_dhcpv6) {
128 @@ -3415,11 +3458,13 @@ void send_decline (cpp)
129                 log_info ("DHCPDECLINE");
130         } else
131  #endif
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));
140 +
141  
142         /* Send out a packet. */
143  #if defined(DHCPv6) && defined(DHCP4o6)
144 @@ -3478,11 +3523,12 @@ void send_release (cpp)
145                 log_info ("DHCPRELEASE");
146         } else
147  #endif
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));
156  
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
161 --- a/server/dhcp.c
162 +++ b/server/dhcp.c
163 @@ -93,6 +93,42 @@ const int dhcp_type_name_max = ((sizeof dhcp_type_names) / sizeof (char *));
164  
165  static TIME leaseTimeCheck(TIME calculated, TIME alternate);
166  
167 +char *print_client_identifier_from_packet (packet)
168 +       struct packet *packet;
169 +{
170 +       struct option_cache *oc;
171 +       struct data_string client_identifier;
172 +       char *ci;
173 +
174 +       memset (&client_identifier, 0, sizeof client_identifier);
175 +
176 +       oc = lookup_option (&dhcp_universe, packet -> options,
177 +                       DHO_DHCP_CLIENT_IDENTIFIER);
178 +       if (oc &&
179 +           evaluate_option_cache (&client_identifier,
180 +                                   packet, (struct lease *)0,
181 +                                   (struct client_state *)0,
182 +                                   packet -> options,
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);
187 +               return ci;
188 +       } else
189 +               return "\"no client id\"";
190 +}
191 +
192 +char *print_hw_addr_or_client_id (packet)
193 +       struct packet *packet;
194 +{
195 +       if (packet -> raw -> htype == HTYPE_INFINIBAND)
196 +               return print_client_identifier_from_packet (packet);
197 +       else
198 +               return print_hw_addr (packet -> raw -> htype,
199 +                                     packet -> raw -> hlen,
200 +                                     packet -> raw -> chaddr);
201 +}
202 +
203  void
204  dhcp (struct packet *packet) {
205         int ms_nulltp = 0;
206 @@ -135,9 +171,7 @@ dhcp (struct packet *packet) {
207  
208                 log_info("%s from %s via %s: %s", s,
209                          (packet->raw->htype
210 -                         ? print_hw_addr(packet->raw->htype,
211 -                                         packet->raw->hlen,
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)
218  #endif
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)
225                   : (lease
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",
230                  piaddr (cip), smbuf,
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)
236                   : (lease
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));
247         }
248  
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)",
252                  cstr,
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)
258                   : (lease
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",
263                  piaddr (cip),
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)
269                   : (lease
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)
283  #endif
284         log_info ("DHCPNAK on %s to %s via %s",
285               piaddr (*cip),
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")
295                    : "BOOTREPLY"),
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,
303                         if (uid_lease) {
304                             if (uid_lease->binding_state == FTS_ACTIVE) {
305                                 log_error ("client %s has duplicate%s on %s",
306 -                                          (print_hw_addr
307 -                                           (packet -> raw -> htype,
308 -                                            packet -> raw -> hlen,
309 -                                            packet -> raw -> chaddr)),
310 +                                          (print_hw_addr_or_client_id(packet)),
311                                            " leases",
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 "
316                                   "on %s",
317                                   piaddr(uid_lease->ip_addr),
318 -                                 print_hw_addr(packet->raw->htype,
319 -                                               packet->raw->hlen,
320 -                                               packet->raw->chaddr),
321 +                                 print_hw_addr_or_client_id(packet),
322                                   uid_lease->subnet->shared_network->name);
323  
324                         if (!packet -> raw -> ciaddr.s_addr &&
325 -- 
326 2.35.1
327
This page took 0.673084 seconds and 3 git commands to generate.