Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-dhcp-failover.c
blobd70105dd06718282d11ca2114316065a8b4fad0b
1 /* packet-dhcpfo.c
2 * Routines for ISC DHCP Server failover protocol dissection
3 * Copyright 2004, M. Ortega y Strupp <moys@loplof.de>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
13 * This implementation is loosely based on draft-ietf-dhc-failover-07.txt.
14 * As this document does not represent the actual implementation, the
15 * source code of ISC DHCPD 3.0 was used too.
17 * See also
19 * https://tools.ietf.org/html/draft-ietf-dhc-failover-10
21 * upon which the handling of the message-digest option is based.
23 * Updated to https://tools.ietf.org/html/draft-ietf-dhc-failover-12, July 2020
25 * Updated with Microsoft DHCP Failover Protocol Extension in August 2023:
26 * https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-dhcpf/380744f9-17ed-4aef-8810-ef08d1e70932
29 #include "config.h"
31 #include <epan/packet.h>
32 #include <epan/strutil.h>
33 #include <epan/prefs.h>
34 #include <epan/expert.h>
35 #include <epan/to_str.h>
36 #include <epan/tfs.h>
37 #include <epan/unit_strings.h>
39 #include "packet-arp.h"
40 #include "packet-tcp.h"
42 #define TCP_PORT_DHCPFO 647 /* Not IANA registered */
44 void proto_register_dhcpfo(void);
45 void proto_reg_handoff_dhcpfo(void);
47 static dissector_handle_t dhcpfo_handle;
49 /* desegmentation of DHCP failover over TCP */
50 static bool dhcpfo_desegment = true;
52 /* enum preference to interpret Microsoft-formatted fields correctly */
53 #define AUTODETECT_MS_DHCP 0
54 #define DISSECT_IEFT_DRAFT 1
55 #define DISSECT_MS_DHCP 2
56 static const enum_val_t microsoft_compatibility[] = {
57 { "autodetect_ms_dhcp", "Autodetect Microsoft Windows DHCP server", AUTODETECT_MS_DHCP },
58 { "dissect_ietf_draft", "Dissect using IETF draft 12 specifications", DISSECT_IEFT_DRAFT },
59 { "dissect_ms_dhcp", "Dissect using Microsoft-style formatting", DISSECT_MS_DHCP },
60 { NULL, NULL, 0 }
62 static int dhcpfo_microsoft_compatibility = AUTODETECT_MS_DHCP;
64 /* Initialize the protocol and registered fields */
65 static int proto_dhcpfo;
66 static int hf_dhcpfo_length;
67 static int hf_dhcpfo_type;
68 static int hf_dhcpfo_poffset;
69 static int hf_dhcpfo_time;
70 static int hf_dhcpfo_xid;
71 static int hf_dhcpfo_additional_HB;
72 static int hf_dhcpfo_payload_data;
73 static int hf_dhcpfo_option_code;
74 static int hf_dhcpfo_dhcp_style_option;
75 static int hf_dhcpfo_option_length;
76 static int hf_dhcpfo_binding_status;
77 static int hf_dhcpfo_server_state;
78 static int hf_dhcpfo_assigned_ip_address;
79 static int hf_dhcpfo_delayed_service_parameter;
80 static int hf_dhcpfo_addresses_transferred;
81 static int hf_dhcpfo_client_identifier;
82 static int hf_dhcpfo_client_hw_type;
83 static int hf_dhcpfo_client_hardware_address;
84 static int hf_dhcpfo_ftddns;
85 static int hf_dhcpfo_reject_reason;
86 static int hf_dhcpfo_relationship_name;
87 static int hf_dhcpfo_message;
88 static int hf_dhcpfo_mclt;
89 static int hf_dhcpfo_vendor_class;
90 static int hf_dhcpfo_lease_expiration_time;
91 static int hf_dhcpfo_potential_expiration_time;
92 static int hf_dhcpfo_client_last_transaction_time;
93 static int hf_dhcpfo_start_time_of_state;
94 static int hf_dhcpfo_vendor_option;
95 static int hf_dhcpfo_max_unacked_bndupd;
96 static int hf_dhcpfo_protocol_version;
97 static int hf_dhcpfo_receive_timer;
98 static int hf_dhcpfo_message_digest;
99 static int hf_dhcpfo_ipflags;
100 static int hf_dhcpfo_ipflags_reserved;
101 static int hf_dhcpfo_ipflags_bootp;
102 static int hf_dhcpfo_ipflags_mbz;
103 static int hf_dhcpfo_hash_bucket_assignment;
104 static int hf_dhcpfo_message_digest_type;
105 static int hf_dhcpfo_tls_request;
106 static int hf_dhcpfo_tls_reply;
107 static int hf_dhcpfo_serverflag;
108 static int hf_dhcpfo_options;
109 static int hf_dhcpfo_ms_client_name;
110 static int hf_dhcpfo_ms_client_description;
111 static int hf_dhcpfo_ms_client_type;
112 static int hf_dhcpfo_ms_client_nap_status;
113 static int hf_dhcpfo_ms_client_nap_capable;
114 static int hf_dhcpfo_ms_client_nap_probation;
115 static int hf_dhcpfo_ms_client_matched_policy;
116 static int hf_dhcpfo_ms_server_name;
117 static int hf_dhcpfo_ms_server_ip;
118 static int hf_dhcpfo_ms_client_scope;
119 static int hf_dhcpfo_ms_client_subnet_mask;
120 static int hf_dhcpfo_ms_scope_id;
121 static int hf_dhcpfo_ms_ipflags;
122 static int hf_dhcpfo_ms_extended_address_state;
123 static int hf_dhcpfo_infoblox_client_hostname;
124 static int hf_dhcpfo_unknown_data;
126 /* Initialize the subtree pointers */
127 static int ett_dhcpfo;
128 static int ett_fo_payload;
129 static int ett_fo_option;
130 static int ett_fo_payload_data;
132 static expert_field ei_dhcpfo_bad_length;
133 static expert_field ei_dhcpfo_message_digest_type_not_allowed;
136 /* Length of fixed-length portion of header */
137 #define DHCPFO_FL_HDR_LEN 12
139 /* message-types of failover */
141 static const value_string failover_vals[] =
143 {1, "Pool request"},
144 {2, "Pool response"},
145 {3, "Binding update"},
146 {4, "Binding acknowledge"},
147 {5, "Connect"},
148 {6, "Connect acknowledge"},
149 {7, "Update request"},
150 {8, "Update done"},
151 {9, "Update request all"},
152 {10, "State"},
153 {11, "Contact"},
154 {12, "Disconnect"},
155 {0, NULL}
158 /*options of payload-data*/
159 #define DHCP_FO_PD_ADDRESSES_TRANSFERRED 1
160 #define DHCP_FO_PD_ASSIGNED_IP_ADDRESS 2
161 #define DHCP_FO_PD_BINDING_STATUS 3
162 #define DHCP_FO_PD_CLIENT_IDENTIFIER 4
163 #define DHCP_FO_PD_CLIENT_HARDWARE_ADDRESS 5
164 #define DHCP_FO_PD_CLIENT_LAST_TRANSACTION_TIME 6
165 #define DHCP_FO_PD_REPLY_OPTION 7
166 #define DHCP_FO_PD_REQUEST_OPTION 8
167 #define DHCP_FO_PD_FTDDNS 9
168 #define DHCP_FO_PD_DELAYED_SERVICE_PARAMETER 10
169 #define DHCP_FO_PD_HASH_BUCKET_ASSIGNMENT 11
170 #define DHCP_FO_PD_IP_FLAGS 12
171 #define DHCP_FO_PD_LEASE_EXPIRATION_TIME 13
172 #define DHCP_FO_PD_MAX_UNACKED_BNDUPD 14
173 #define DHCP_FO_PD_MCLT 15
174 #define DHCP_FO_PD_MESSAGE 16
175 #define DHCP_FO_PD_MESSAGE_DIGEST 17
176 #define DHCP_FO_PD_POTENTIAL_EXPIRATION_TIME 18
177 #define DHCP_FO_PD_RECEIVE_TIMER 19
178 #define DHCP_FO_PD_PROTOCOL_VERSION 20
179 #define DHCP_FO_PD_REJECT_REASON 21
180 #define DHCP_FO_PD_RELATIONSHIP_NAME 22
181 #define DHCP_FO_PD_SERVERFLAG 23
182 #define DHCP_FO_PD_SERVERSTATE 24
183 #define DHCP_FO_PD_START_TIME_OF_STATE 25
184 #define DHCP_FO_PD_TLS_REPLY 26
185 #define DHCP_FO_PD_TLS_REQUEST 27
186 #define DHCP_FO_PD_VENDOR_CLASS 28
187 #define DHCP_FO_PD_VENDOR_OPTION 29
188 /* Options not defined in the draft */
189 #define DHCP_FO_PD_OPTION_30 30
190 #define DHCP_FO_PD_OPTION_31 31
191 #define DHCP_FO_PD_OPTION_32 32
192 #define DHCP_FO_PD_OPTION_33 33
193 #define DHCP_FO_PD_OPTION_34 34
194 #define DHCP_FO_PD_OPTION_35 35
195 #define DHCP_FO_PD_OPTION_36 36
196 #define DHCP_FO_PD_OPTION_37 37
197 #define DHCP_FO_PD_OPTION_38 38
198 #define DHCP_FO_PD_OPTION_39 39
199 #define DHCP_FO_PD_OPTION_40 40
200 #define DHCP_FO_PD_OPTION_41 41
203 static const char VENDOR_SPECIFIC[] = "(vendor-specific)";
204 static const char UNKNOWN_OPTION[] = "Unknown Option";
206 static const value_string option_code_vals[] =
208 {DHCP_FO_PD_ADDRESSES_TRANSFERRED, "addresses-transferred"},
209 {DHCP_FO_PD_ASSIGNED_IP_ADDRESS, "assigned-IP-address"},
210 {DHCP_FO_PD_BINDING_STATUS, "binding-status"},
211 {DHCP_FO_PD_CLIENT_IDENTIFIER, "client-identifier"},
212 {DHCP_FO_PD_CLIENT_HARDWARE_ADDRESS, "client-hardware-address"},
213 {DHCP_FO_PD_CLIENT_LAST_TRANSACTION_TIME, "client-last-transaction-time"},
214 {DHCP_FO_PD_REPLY_OPTION, "reply-option"},
215 {DHCP_FO_PD_REQUEST_OPTION, "request-option"},
216 {DHCP_FO_PD_FTDDNS, "FTDDNS"},
217 {DHCP_FO_PD_DELAYED_SERVICE_PARAMETER, "delayed-service-parameter"},
218 {DHCP_FO_PD_HASH_BUCKET_ASSIGNMENT, "hash-bucket-assignment"},
219 {DHCP_FO_PD_IP_FLAGS, "IP-flags"},
220 {DHCP_FO_PD_LEASE_EXPIRATION_TIME, "lease-expiration-time"},
221 {DHCP_FO_PD_MAX_UNACKED_BNDUPD, "max-unacked-BNDUPD"},
222 {DHCP_FO_PD_MCLT, "MCLT"},
223 {DHCP_FO_PD_MESSAGE, "message"},
224 {DHCP_FO_PD_MESSAGE_DIGEST, "message-digest"},
225 {DHCP_FO_PD_POTENTIAL_EXPIRATION_TIME, "potential-expiration-time"},
226 {DHCP_FO_PD_RECEIVE_TIMER, "receive-timer"},
227 {DHCP_FO_PD_PROTOCOL_VERSION, "protocol-version"},
228 {DHCP_FO_PD_REJECT_REASON, "reject-reason"},
229 {DHCP_FO_PD_RELATIONSHIP_NAME, "relationship-name"},
230 {DHCP_FO_PD_SERVERFLAG, "server-flag"},
231 {DHCP_FO_PD_SERVERSTATE, "server-state"},
232 {DHCP_FO_PD_START_TIME_OF_STATE, "start-time-of-state"},
233 {DHCP_FO_PD_TLS_REPLY, "TLS-reply"},
234 {DHCP_FO_PD_TLS_REQUEST, "TLS-request"},
235 {DHCP_FO_PD_VENDOR_CLASS, "vendor-class"},
236 {DHCP_FO_PD_VENDOR_OPTION, "vendor-option"},
237 /* Not specified in the draft, further defined in the following arrays: */
238 {DHCP_FO_PD_OPTION_30, VENDOR_SPECIFIC},
239 {DHCP_FO_PD_OPTION_31, VENDOR_SPECIFIC},
240 {DHCP_FO_PD_OPTION_32, VENDOR_SPECIFIC},
241 {DHCP_FO_PD_OPTION_33, VENDOR_SPECIFIC},
242 {DHCP_FO_PD_OPTION_34, VENDOR_SPECIFIC},
243 {DHCP_FO_PD_OPTION_35, VENDOR_SPECIFIC},
244 {DHCP_FO_PD_OPTION_36, VENDOR_SPECIFIC},
245 {DHCP_FO_PD_OPTION_37, VENDOR_SPECIFIC},
246 {DHCP_FO_PD_OPTION_38, VENDOR_SPECIFIC},
247 {DHCP_FO_PD_OPTION_39, VENDOR_SPECIFIC},
248 {DHCP_FO_PD_OPTION_40, VENDOR_SPECIFIC},
249 {DHCP_FO_PD_OPTION_41, VENDOR_SPECIFIC},
250 {0, NULL}
253 /* Used when Microsoft-compatibility is detected/enabled */
254 static const value_string microsoft_option_code_vals[] =
256 {DHCP_FO_PD_OPTION_30, "microsoft-scope-ID-list"},
257 {DHCP_FO_PD_OPTION_31, "microsoft-client-name"},
258 {DHCP_FO_PD_OPTION_32, "microsoft-client-description"},
259 {DHCP_FO_PD_OPTION_33, "microsoft-client-subnet-mask"},
260 {DHCP_FO_PD_OPTION_34, "microsoft-server-IP"},
261 {DHCP_FO_PD_OPTION_35, "microsoft-server-name"},
262 {DHCP_FO_PD_OPTION_36, "microsoft-client-type"},
263 {DHCP_FO_PD_OPTION_37, "microsoft-client-NAP-status"},
264 {DHCP_FO_PD_OPTION_38, "microsoft-client-NAP-probation"},
265 {DHCP_FO_PD_OPTION_39, "microsoft-client-NAP-capable"},
266 {DHCP_FO_PD_OPTION_40, "microsoft-client-matched-policy"},
267 {DHCP_FO_PD_OPTION_41, "microsoft-extended-address-state"},
268 {0, NULL}
271 /* Used when Microsoft-compatibility is NOT detected/enabled */
272 static const value_string others_option_code_vals[] =
274 {DHCP_FO_PD_OPTION_30, "infoblox-client-hostname"},
275 {0, NULL}
278 /* Microsoft client types (option 36) */
280 static const value_string ms_client_type_vals[] =
282 {0x00, "CLIENT_TYPE_UNSPECIFIED"},
283 {0x01, "CLIENT_TYPE_DHCP"},
284 {0x02, "CLIENT_TYPE_BOOTP"},
285 {0x03, "CLIENT_TYPE_BOTH"},
286 {0x04, "CLIENT_TYPE_RESERVATION_FLAG"},
287 {0x64, "CLIENT_TYPE_NONE"},
288 {0, NULL}
291 /* Microsoft client NAP status codes (option 37) */
293 static const value_string ms_client_nap_status_vals[] =
295 {0x00, "NOQUARANTINE"},
296 {0x01, "RESTRICTEDACCESS"},
297 {0x02, "DROPPACKET"},
298 {0x03, "PROBATION"},
299 {0, NULL}
302 /* Binding-status */
304 static const value_string binding_status_vals[] =
306 {1, "FREE"},
307 {2, "ACTIVE"},
308 {3, "EXPIRED"},
309 {4, "RELEASED"},
310 {5, "ABANDONED"},
311 {6, "RESET"},
312 {7, "BACKUP"},
313 {0, NULL}
317 /* Server-status */
319 static const value_string server_state_vals[] =
321 {1, "startup"},
322 {2, "normal"},
323 {3, "communication interrupted"},
324 {4, "partner down"},
325 {5, "potential conflict"},
326 {6, "recover"},
327 {7, "paused"},
328 {8, "shutdown"},
329 {9, "recover done"},
330 {10, "resolution interrupted"},
331 {11, "conflict done"},
332 {0, NULL}
335 /* reject reasons */
336 static const value_string reject_reason_vals[] =
338 {0, "Reserved"},
339 {1, "Illegal IP address (not part of any address pool)"},
340 {2, "Fatal conflict exists: address in use by other client"},
341 {3, "Missing binding information"},
342 {4, "Connection rejected, time mismatch too great"},
343 {5, "Connection rejected, invalid MCLT"},
344 {6, "Connection rejected, unknown reason"},
345 {7, "Connection rejected, duplicate connection"},
346 {8, "Connection rejected, invalid failover partner"},
347 {9, "TLS not supported"},
348 {10, "TLS supported but not configured"},
349 {11, "TLS required but not supported by partner"},
350 {12, "Message digest not supported"},
351 {13, "Message digest not configured"},
352 {14, "Protocol version mismatch"},
353 {15, "Outdated binding information"},
354 {16, "Less critical binding information"},
355 {17, "No traffic within sufficient time"},
356 {18, "Hash bucket assignment conflict"},
357 {19, "IP not reserved on this server"},
358 {20, "Message digest failed to compare"},
359 {21, "Missing message digest."},
360 {254, "Unknown: Error occurred but does not match any reason"},
361 {0, NULL}
364 static const value_string tls_request_vals[] =
366 {0, "No TLS operation"},
367 {1, "TLS operation desired but not required"},
368 {2, "TLS operation is required"},
369 {0, NULL}
372 static const value_string tls_reply_vals[] =
374 {0, "No TLS operation"},
375 {1, "TLS operation is required"},
376 {0, NULL}
379 static const value_string message_digest_type_vals[] =
381 {1, "HMAC-MD5"},
382 {2, "Microsoft-specific"},
383 {0, NULL}
386 static const value_string serverflag_vals[] =
388 {0, "NONE"},
389 {1, "STARTUP"},
390 {0, NULL}
393 /* Code to actually dissect the packets */
394 static unsigned
395 get_dhcpfo_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_)
398 * Return the length of the DHCP failover packet.
400 return tvb_get_ntohs(tvb, offset);
403 static int
404 dissect_dhcpfo_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
406 int offset = 0;
407 proto_item *ti, *pi, *oi;
408 proto_tree *dhcpfo_tree = NULL, *payload_tree, *option_tree;
409 uint8_t tls_request, tls_reply;
410 uint16_t length;
411 unsigned type, serverflag;
412 int poffset;
413 uint32_t xid;
414 nstime_t timex;
415 uint32_t lease_expiration_time,
416 potential_expiration_time, client_last_transaction_time,
417 start_time_of_state;
418 bool bogus_poffset, microsoft_style;
419 uint16_t opcode, option_length;
420 uint8_t htype, reject_reason, message_digest_type, binding_status;
421 const uint8_t *vendor_class_str, *relationship_name_str;
422 const char *htype_str, *option_name;
423 char *lease_expiration_time_str, *potential_expiration_time_str,
424 *client_last_transaction_time_str, *start_time_of_state_str;
425 uint32_t mclt;
426 uint8_t server_state, ms_client_type, ms_client_nap_status, ms_client_nap_capable;
427 uint32_t max_unacked_bndupd, receive_timer,
428 ms_client_nap_probation, ms_extended_address_state;
429 const uint8_t *client_hostname_str, *ms_server_name_str, *ms_client_description_str,
430 *ms_client_matched_policy_str;
432 /* Make entries in Protocol column and Info column on summary display */
433 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DHCPFO");
434 col_clear(pinfo->cinfo, COL_INFO);
436 length = tvb_get_ntohs(tvb, offset);
437 if (tree) {
438 /* create display subtree for the protocol */
439 ti = proto_tree_add_item(tree, proto_dhcpfo, tvb, 0, -1, ENC_NA);
441 dhcpfo_tree = proto_item_add_subtree(ti, ett_dhcpfo);
443 if (length >= DHCPFO_FL_HDR_LEN) {
444 proto_tree_add_uint(dhcpfo_tree,
445 hf_dhcpfo_length, tvb, offset, 2, length);
446 } else {
447 proto_tree_add_uint_format_value(dhcpfo_tree,
448 hf_dhcpfo_length, tvb, offset, 2, length,
449 "%u (bogus, must be >= %u)",
450 length, DHCPFO_FL_HDR_LEN);
453 offset += 2;
455 type = tvb_get_uint8(tvb, offset);
456 if (tree) {
457 proto_tree_add_uint(dhcpfo_tree,
458 hf_dhcpfo_type, tvb, offset, 1, type);
460 col_set_str(pinfo->cinfo, COL_INFO,
461 val_to_str_const(type, failover_vals, "Unknown Packet"));
462 offset += 1;
464 if (dhcpfo_microsoft_compatibility == DISSECT_MS_DHCP) {
465 microsoft_style = true;
466 } else {
467 /* Set to false, changed to true later if autodetected */
468 microsoft_style = false;
470 poffset = tvb_get_uint8(tvb, offset);
471 if (poffset == 8) {
472 if (dhcpfo_microsoft_compatibility == AUTODETECT_MS_DHCP) {
473 microsoft_style = true;
475 bogus_poffset = false;
476 proto_tree_add_uint_format_value(dhcpfo_tree,
477 hf_dhcpfo_poffset, tvb, offset, 1, poffset,
478 "%u (as per Draft, now treated as being %u)",
479 poffset, DHCPFO_FL_HDR_LEN);
480 poffset = DHCPFO_FL_HDR_LEN;
481 } else if (poffset < DHCPFO_FL_HDR_LEN) {
482 bogus_poffset = true;
483 if (tree) {
484 proto_tree_add_uint_format_value(dhcpfo_tree,
485 hf_dhcpfo_poffset, tvb, offset, 1, poffset,
486 "%u (bogus, must be >= %u)",
487 poffset, DHCPFO_FL_HDR_LEN);
489 } else if (poffset > length) {
490 bogus_poffset = true;
491 if (tree) {
492 proto_tree_add_uint_format_value(dhcpfo_tree,
493 hf_dhcpfo_poffset, tvb, offset, 1, poffset,
494 "%u (bogus, must be <= length of message)",
495 poffset);
497 } else {
498 bogus_poffset = false;
499 if (tree) {
500 proto_tree_add_uint(dhcpfo_tree,
501 hf_dhcpfo_poffset, tvb, offset, 1, poffset);
504 offset += 1;
506 if (tree) {
508 * XXX - this is *almost* like a time_t, but it's unsigned.
509 * Also, we need a way to keep from displaying nanoseconds,
510 * so as not to make it look as if it has higher
512 timex.secs = tvb_get_ntohl(tvb, offset);
513 timex.nsecs = 0;
514 proto_tree_add_time_format_value(dhcpfo_tree, hf_dhcpfo_time, tvb,
515 offset, 4, &timex, "%s",
516 abs_time_secs_to_str(pinfo->pool, timex.secs, ABSOLUTE_TIME_LOCAL, true));
518 offset += 4;
520 xid = tvb_get_ntohl(tvb, offset);
521 if (tree) {
522 proto_tree_add_item(dhcpfo_tree,
523 hf_dhcpfo_xid, tvb, offset, 4, ENC_BIG_ENDIAN);
525 col_append_fstr(pinfo->cinfo, COL_INFO," xid: %x", xid);
526 offset += 4;
528 if (bogus_poffset)
529 return offset; /* payload offset was bogus */
531 /* if there are any additional header bytes */
532 if (poffset != offset) {
533 proto_tree_add_item(dhcpfo_tree, hf_dhcpfo_additional_HB, tvb,
534 offset, poffset-offset, ENC_NA);
535 offset = poffset;
538 /* payload-data */
539 if (poffset == length)
540 return length; /* no payload */
541 /* create display subtree for the payload */
542 pi = proto_tree_add_item(dhcpfo_tree, hf_dhcpfo_payload_data,
543 tvb, poffset, length-poffset, ENC_NA);
544 payload_tree = proto_item_add_subtree(pi, ett_fo_payload);
545 while (offset < length) {
546 opcode = tvb_get_ntohs(tvb, offset);
547 option_length = tvb_get_ntohs(tvb, offset+2);
549 oi = proto_tree_add_item(payload_tree,
550 hf_dhcpfo_dhcp_style_option, tvb, offset,
551 option_length+4, ENC_NA);
552 option_tree = proto_item_add_subtree(oi, ett_fo_option);
554 /*** DHCP-Style-Options ****/
556 option_name = val_to_str_const(opcode, option_code_vals, UNKNOWN_OPTION);
557 if (strcmp(option_name, VENDOR_SPECIFIC) == 0) {
558 /* Get the option name based on current setting */
559 if (microsoft_style) {
560 option_name = val_to_str_const(opcode, microsoft_option_code_vals, UNKNOWN_OPTION);
561 } else {
562 option_name = val_to_str_const(opcode, others_option_code_vals, UNKNOWN_OPTION);
565 proto_item_append_text(oi, ", %s (%u)", option_name, opcode);
567 proto_tree_add_uint(option_tree, hf_dhcpfo_option_code, tvb,
568 offset, 2, opcode);
570 proto_tree_add_uint(option_tree, hf_dhcpfo_option_length, tvb,
571 offset+2, 2, option_length);
573 offset += 4;
575 /** opcode dependent format **/
577 switch (opcode) {
579 case DHCP_FO_PD_BINDING_STATUS:
580 binding_status = tvb_get_uint8(tvb, offset);
581 proto_item_append_text(oi, ", %s (%d)",
582 val_to_str_const(binding_status,
583 binding_status_vals,
584 "Unknown Packet"),
585 binding_status);
587 proto_tree_add_item(option_tree,
588 hf_dhcpfo_binding_status, tvb,
589 offset, 1, ENC_BIG_ENDIAN);
590 break;
592 case DHCP_FO_PD_ASSIGNED_IP_ADDRESS:
593 if (option_length != 4) {
594 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "assigned ip address is not 4 bytes long");
595 break;
597 proto_item_append_text(oi, ", %s ", tvb_ip_to_str(pinfo->pool, tvb, offset));
599 proto_tree_add_item(option_tree,
600 hf_dhcpfo_assigned_ip_address, tvb, offset,
601 option_length, ENC_BIG_ENDIAN);
602 break;
604 case DHCP_FO_PD_DELAYED_SERVICE_PARAMETER:
605 if (option_length != 1) {
606 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "delayed service parameter is not 1 bytes long");
607 break;
610 proto_item_append_text(oi, ", %d ", tvb_get_uint8(tvb, offset));
612 proto_tree_add_item(option_tree,
613 hf_dhcpfo_delayed_service_parameter, tvb,
614 offset, option_length, ENC_NA);
615 break;
617 case DHCP_FO_PD_ADDRESSES_TRANSFERRED:
618 if (option_length != 4) {
619 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "addresses transferred is not 4 bytes long");
620 break;
623 proto_item_append_text(oi,", %u", tvb_get_ntohl(tvb, offset));
625 proto_tree_add_item(option_tree,
626 hf_dhcpfo_addresses_transferred, tvb, offset,
627 option_length, ENC_BIG_ENDIAN);
628 break;
630 case DHCP_FO_PD_CLIENT_IDENTIFIER:
632 const uint8_t* identifier;
634 * XXX - if this is truly like DHCP option 81,
635 * we need to dissect it as such.
637 proto_tree_add_item_ret_string(option_tree,
638 hf_dhcpfo_client_identifier, tvb, offset,
639 option_length, ENC_ASCII|ENC_NA, pinfo->pool, &identifier);
641 proto_item_append_text(oi,", \"%s\"", identifier);
643 break;
645 case DHCP_FO_PD_CLIENT_HARDWARE_ADDRESS:
646 if (microsoft_style == false) {
647 /* As specified in the draft: hardware type + hardware address */
648 if (option_length < 2) {
649 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "hardware address is too short");
650 break;
652 htype = tvb_get_uint8(tvb, offset);
653 htype_str = tvb_arphrdaddr_to_str(pinfo->pool, tvb, offset+1, option_length-1,
654 htype);
655 proto_item_append_text(oi, ", %s", htype_str);
657 proto_tree_add_item(option_tree, hf_dhcpfo_client_hw_type, tvb,
658 offset, 1, ENC_BIG_ENDIAN);
659 proto_tree_add_string(option_tree, hf_dhcpfo_client_hardware_address, tvb,
660 offset+1, option_length-1, htype_str);
661 } else {
662 /* Microsoft-style: DHCP scope (reversed) + hardware type + hardware address */
663 if (option_length < 6) {
664 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "hardware address is too short");
665 break;
667 proto_tree_add_item(option_tree,
668 hf_dhcpfo_ms_client_scope, tvb, offset, 4, ENC_LITTLE_ENDIAN);
669 uint32_t scope = tvb_get_uint32(tvb, offset, ENC_LITTLE_ENDIAN);
670 htype = tvb_get_uint8(tvb, offset+4);
671 htype_str = tvb_arphrdaddr_to_str(pinfo->pool, tvb, offset+1+4, option_length-1-4,
672 htype);
673 proto_item_append_text(oi, ", %s, client DHCP scope: %s",
674 htype_str, ip_num_to_str(pinfo->pool, scope));
676 proto_tree_add_item(option_tree, hf_dhcpfo_client_hw_type, tvb,
677 offset+4, 1, ENC_BIG_ENDIAN);
678 proto_tree_add_string(option_tree, hf_dhcpfo_client_hardware_address, tvb,
679 offset+1+4, option_length-1-4, htype_str);
681 break;
683 case DHCP_FO_PD_FTDDNS:
684 proto_tree_add_item(option_tree, hf_dhcpfo_ftddns, tvb,
685 offset, option_length, ENC_ASCII);
686 break;
688 case DHCP_FO_PD_REJECT_REASON:
689 if (option_length != 1) {
690 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "Reject reason is not 1 byte long");
691 break;
693 reject_reason = tvb_get_uint8(tvb, offset);
695 proto_item_append_text(oi, ", %s (%d)",
696 val_to_str_const(reject_reason, reject_reason_vals,
697 "Unknown Packet"),
698 reject_reason);
700 proto_tree_add_uint(option_tree,
701 hf_dhcpfo_reject_reason, tvb, offset,
702 option_length, reject_reason);
703 break;
705 case DHCP_FO_PD_RELATIONSHIP_NAME:
706 if (microsoft_style == false) {
707 /* Parse as ASCII */
708 proto_tree_add_item_ret_string(option_tree,
709 hf_dhcpfo_relationship_name, tvb, offset,
710 option_length, ENC_ASCII, pinfo->pool, &relationship_name_str);
711 proto_item_append_text(oi,", \"%s\"",
712 format_text(pinfo->pool, relationship_name_str, option_length));
713 } else {
714 /* Microsoft-style: Parse as UTF-16-LE */
715 proto_tree_add_item_ret_string(option_tree,
716 hf_dhcpfo_relationship_name, tvb, offset,
717 option_length, ENC_UTF_16|ENC_LITTLE_ENDIAN, pinfo->pool, &relationship_name_str);
718 /* String length is half the data length */
719 proto_item_append_text(oi,", \"%s\"",
720 format_text(pinfo->pool, relationship_name_str, option_length/2));
722 break;
724 case DHCP_FO_PD_MESSAGE:
725 proto_tree_add_item(option_tree, hf_dhcpfo_message, tvb,
726 offset, option_length, ENC_ASCII);
727 break;
729 case DHCP_FO_PD_MCLT:
730 if (option_length != 4) {
731 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "MCLT is not 4 bytes long");
732 break;
734 mclt = tvb_get_ntohl(tvb, offset);
735 proto_item_append_text(oi,", %u seconds", mclt);
736 proto_tree_add_uint(option_tree, hf_dhcpfo_mclt, tvb,
737 offset, option_length, mclt);
738 break;
740 case DHCP_FO_PD_VENDOR_CLASS:
741 if (microsoft_style == false) {
742 /* Parse as ASCII */
743 proto_tree_add_item_ret_string(option_tree,
744 hf_dhcpfo_vendor_class, tvb, offset,
745 option_length, ENC_ASCII, pinfo->pool, &vendor_class_str);
746 proto_item_append_text(oi,", \"%s\"",
747 format_text(pinfo->pool, vendor_class_str, option_length));
748 } else {
749 /* Microsoft-style: Parse as UTF-16-LE */
750 proto_tree_add_item_ret_string(option_tree,
751 hf_dhcpfo_vendor_class, tvb, offset,
752 option_length, ENC_UTF_16|ENC_LITTLE_ENDIAN, pinfo->pool, &vendor_class_str);
753 /* String length is half the data length */
754 proto_item_append_text(oi,", \"%s\"",
755 format_text(pinfo->pool, vendor_class_str, option_length/2));
757 break;
759 case DHCP_FO_PD_LEASE_EXPIRATION_TIME:
760 if (option_length != 4) {
761 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "Lease expiration time is not 4 bytes long");
762 break;
764 lease_expiration_time =
765 tvb_get_ntohl(tvb, offset);
766 lease_expiration_time_str =
767 abs_time_secs_to_str(pinfo->pool, lease_expiration_time, ABSOLUTE_TIME_LOCAL, true);
769 proto_item_append_text(oi, ", %s",
770 lease_expiration_time_str);
772 proto_tree_add_uint_format_value(option_tree,
773 hf_dhcpfo_lease_expiration_time, tvb,
774 offset, option_length,
775 lease_expiration_time,
776 "%s",
777 lease_expiration_time_str);
778 break;
780 case DHCP_FO_PD_POTENTIAL_EXPIRATION_TIME:
781 if (option_length != 4) {
782 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "Potential expiration time is not 4 bytes long");
783 break;
785 potential_expiration_time =
786 tvb_get_ntohl(tvb, offset);
788 potential_expiration_time_str =
789 abs_time_secs_to_str(pinfo->pool, potential_expiration_time, ABSOLUTE_TIME_LOCAL, true);
791 proto_item_append_text(oi, ", %s",
792 potential_expiration_time_str);
794 proto_tree_add_uint_format_value(option_tree,
795 hf_dhcpfo_potential_expiration_time, tvb,
796 offset, option_length,
797 potential_expiration_time,
798 "%s",
799 potential_expiration_time_str);
800 break;
802 case DHCP_FO_PD_CLIENT_LAST_TRANSACTION_TIME:
803 if (option_length != 4) {
804 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "Last transaction time is not 4 bytes long");
805 break;
807 client_last_transaction_time =
808 tvb_get_ntohl(tvb, offset);
809 client_last_transaction_time_str =
810 abs_time_secs_to_str(pinfo->pool, client_last_transaction_time, ABSOLUTE_TIME_LOCAL, true);
812 proto_item_append_text(oi, ", %s",
813 client_last_transaction_time_str);
815 proto_tree_add_uint_format_value(option_tree,
816 hf_dhcpfo_client_last_transaction_time, tvb,
817 offset, option_length,
818 client_last_transaction_time,
819 "%s",
820 abs_time_secs_to_str(pinfo->pool, client_last_transaction_time, ABSOLUTE_TIME_LOCAL, true));
821 break;
823 case DHCP_FO_PD_START_TIME_OF_STATE:
824 if (option_length != 4) {
825 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "Start time of state is not 4 bytes long");
826 break;
828 start_time_of_state =
829 tvb_get_ntohl(tvb, offset);
830 start_time_of_state_str =
831 abs_time_secs_to_str(pinfo->pool, start_time_of_state, ABSOLUTE_TIME_LOCAL, true);
833 proto_item_append_text(oi, ", %s",
834 start_time_of_state_str);
836 proto_tree_add_uint_format_value(option_tree,
837 hf_dhcpfo_start_time_of_state, tvb,
838 offset, option_length,
839 start_time_of_state,
840 "%s",
841 abs_time_secs_to_str(pinfo->pool, start_time_of_state, ABSOLUTE_TIME_LOCAL, true));
842 break;
844 case DHCP_FO_PD_SERVERSTATE:
845 if (option_length != 1) {
846 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "server status is not 1 byte long");
847 break;
849 server_state = tvb_get_uint8(tvb, offset);
851 proto_item_append_text(oi, ", %s (%u)",
852 val_to_str_const(server_state, server_state_vals,
853 "Unknown"),
854 server_state);
856 proto_tree_add_uint(option_tree,
857 hf_dhcpfo_server_state, tvb, offset, 1,
858 server_state);
859 break;
861 case DHCP_FO_PD_SERVERFLAG:
862 if (option_length != 1) {
863 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "Serverflag is not 1 byte long");
864 break;
866 serverflag = tvb_get_uint8(tvb, offset);
867 proto_item_append_text(oi, ", %s (%d)",
868 val_to_str_const(serverflag, serverflag_vals, "UNKNOWN FLAGS"),
869 serverflag);
870 proto_tree_add_item(option_tree, hf_dhcpfo_serverflag, tvb, offset, option_length, ENC_BIG_ENDIAN);
871 break;
873 case DHCP_FO_PD_VENDOR_OPTION:
874 proto_tree_add_item(option_tree,
875 hf_dhcpfo_vendor_option, tvb, offset,
876 option_length, ENC_NA);
877 break;
879 case DHCP_FO_PD_MAX_UNACKED_BNDUPD:
880 if (option_length != 4) {
881 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "Max unacked BNDUPD is not 4 bytes long");
882 break;
884 max_unacked_bndupd = tvb_get_ntohl(tvb, offset);
885 proto_item_append_text(oi, ", %u", max_unacked_bndupd);
887 proto_tree_add_uint(option_tree,
888 hf_dhcpfo_max_unacked_bndupd, tvb, offset,
889 option_length, max_unacked_bndupd);
890 break;
892 case DHCP_FO_PD_RECEIVE_TIMER:
893 if (option_length != 4) {
894 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "Receive timer is not 4 bytes long");
895 break;
897 receive_timer = tvb_get_ntohl(tvb, offset);
898 proto_item_append_text(oi,", %u seconds",
899 receive_timer);
901 proto_tree_add_uint(option_tree,
902 hf_dhcpfo_receive_timer, tvb, offset,
903 option_length, receive_timer);
904 break;
906 case DHCP_FO_PD_HASH_BUCKET_ASSIGNMENT:
907 proto_tree_add_item(option_tree,
908 hf_dhcpfo_hash_bucket_assignment, tvb,
909 offset, option_length, ENC_NA);
910 break;
912 case DHCP_FO_PD_IP_FLAGS: {
913 if (microsoft_style == false) {
914 /* As specified in the draft: 16-bit flags */
915 static int * const ipflags[] = {
916 &hf_dhcpfo_ipflags_reserved,
917 &hf_dhcpfo_ipflags_bootp,
918 &hf_dhcpfo_ipflags_mbz,
919 NULL
921 if (option_length != 2) {
922 /* Draft-12 shows Len=1 with 16-bit field though */
923 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "IP flags is not 2 bytes long");
924 break;
926 proto_tree_add_bitmask(option_tree, tvb, offset, hf_dhcpfo_ipflags,
927 ett_fo_payload_data, ipflags, ENC_BIG_ENDIAN);
928 } else {
929 /* Microsoft-style: one byte only, usage unknown */
930 if (option_length != 1) {
931 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "IP flags is not 1 bytes long");
932 break;
934 proto_item_append_text(oi, ", flags (Microsoft-specific): 0x%02x", tvb_get_uint8(tvb, offset));
935 proto_tree_add_item(option_tree, hf_dhcpfo_ms_ipflags, tvb, offset, option_length, ENC_BIG_ENDIAN);
937 break;
940 case DHCP_FO_PD_MESSAGE_DIGEST:
941 if (option_length < 1) {
942 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "Message digest option is too short");
943 break;
946 message_digest_type = tvb_get_uint8(tvb, offset);
947 ti = proto_tree_add_item(option_tree, hf_dhcpfo_message_digest_type, tvb, offset, 1, ENC_BIG_ENDIAN);
949 if (message_digest_type >= 1 && message_digest_type <= 2) {
950 proto_item_append_text(oi, ", %s", val_to_str_const(message_digest_type, message_digest_type_vals, "Unknown value"));
951 } else {
952 proto_item_append_text(oi, ", type not allowed");
953 expert_add_info_format(pinfo, ti, &ei_dhcpfo_message_digest_type_not_allowed, "Message digest type: %u, not allowed", message_digest_type);
956 proto_tree_add_item(option_tree,
957 hf_dhcpfo_message_digest, tvb, offset+1,
958 option_length-1, ENC_ASCII);
959 break;
961 case DHCP_FO_PD_PROTOCOL_VERSION:
962 if (option_length != 1) {
963 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "Protocol version is not 1 byte long");
964 break;
966 proto_item_append_text(oi, ", version: %u", tvb_get_uint8(tvb, offset));
967 proto_tree_add_item(option_tree, hf_dhcpfo_protocol_version, tvb, offset, option_length, ENC_BIG_ENDIAN);
968 break;
970 case DHCP_FO_PD_TLS_REQUEST:
971 if (option_length != 1) {
972 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "TLS request is not 1 bytes long");
973 break;
975 tls_request = tvb_get_uint8(tvb, offset);
976 proto_item_append_text(oi, ", %s", val_to_str(tls_request, tls_request_vals, "Unknown (%u)"));
977 proto_tree_add_item(option_tree, hf_dhcpfo_tls_request, tvb, offset, 1, ENC_BIG_ENDIAN);
978 break;
980 case DHCP_FO_PD_TLS_REPLY:
981 if (option_length != 1) {
982 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "TLS reply is not 1 bytes long");
983 break;
985 tls_reply = tvb_get_uint8(tvb, offset);
986 proto_item_append_text(oi, ", %s", val_to_str(tls_reply, tls_reply_vals, "Unknown (%u)"));
987 proto_tree_add_item(option_tree, hf_dhcpfo_tls_reply, tvb, offset, 1, ENC_BIG_ENDIAN);
988 break;
990 case DHCP_FO_PD_REQUEST_OPTION:
991 case DHCP_FO_PD_REPLY_OPTION:
992 proto_tree_add_item(option_tree, hf_dhcpfo_options, tvb, offset, option_length, ENC_NA);
993 break;
995 case DHCP_FO_PD_OPTION_30:
996 if (microsoft_style) {
997 /* Microsoft: Scope ID List */
998 uint16_t local_offset = 0;
999 while (local_offset < option_length) {
1000 proto_tree_add_item(option_tree,
1001 hf_dhcpfo_ms_scope_id, tvb, offset+local_offset, 4, ENC_LITTLE_ENDIAN);
1002 local_offset += 4;
1004 } else {
1005 /* In Infoblox this is client hostname */
1006 proto_tree_add_item_ret_string(option_tree,
1007 hf_dhcpfo_infoblox_client_hostname, tvb, offset,
1008 option_length, ENC_UTF_8, pinfo->pool, &client_hostname_str);
1009 proto_item_append_text(oi,", \"%s\"",
1010 format_text(pinfo->pool, client_hostname_str, option_length));
1012 break;
1014 case DHCP_FO_PD_OPTION_31:
1015 /* Microsoft: Client Name */
1016 proto_tree_add_item_ret_string(option_tree,
1017 hf_dhcpfo_ms_client_name, tvb, offset,
1018 option_length, ENC_UTF_16|ENC_LITTLE_ENDIAN, pinfo->pool, &client_hostname_str);
1019 /* With UTF-16 the string length is half the data length, minus the zero-termination */
1020 proto_item_append_text(oi,", \"%s\"",
1021 format_text(pinfo->pool, client_hostname_str, option_length/2-1));
1022 break;
1024 case DHCP_FO_PD_OPTION_32:
1025 /* Microsoft: Client Description */
1026 proto_tree_add_item_ret_string(option_tree,
1027 hf_dhcpfo_ms_client_description, tvb, offset,
1028 option_length, ENC_UTF_16|ENC_LITTLE_ENDIAN, pinfo->pool, &ms_client_description_str);
1029 /* With UTF-16 the string length is half the data length, minus the zero-termination */
1030 proto_item_append_text(oi,", \"%s\"",
1031 format_text(pinfo->pool, ms_client_description_str, option_length/2-1));
1032 break;
1034 case DHCP_FO_PD_OPTION_33:
1035 /* Microsoft: Client Subnet Mask */
1036 if (option_length != 4) {
1037 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "netmask is not 4 bytes long");
1038 break;
1040 proto_item_append_text(oi, ", %s", tvb_ip_to_str(pinfo->pool, tvb, offset));
1041 proto_tree_add_item(option_tree,
1042 hf_dhcpfo_ms_client_subnet_mask, tvb, offset,
1043 option_length, ENC_BIG_ENDIAN);
1044 break;
1046 case DHCP_FO_PD_OPTION_34:
1047 /* Microsoft: Server IP */
1048 if (option_length != 4) {
1049 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "server IP address is not 4 bytes long");
1050 break;
1052 proto_item_append_text(oi, ", %s", tvb_ip_to_str(pinfo->pool, tvb, offset));
1053 proto_tree_add_item(option_tree,
1054 hf_dhcpfo_ms_server_ip, tvb, offset,
1055 option_length, ENC_BIG_ENDIAN);
1056 break;
1058 case DHCP_FO_PD_OPTION_35:
1059 /* Microsoft: Server Name */
1060 proto_tree_add_item_ret_string(option_tree,
1061 hf_dhcpfo_ms_server_name, tvb, offset,
1062 option_length, ENC_UTF_16|ENC_LITTLE_ENDIAN, pinfo->pool, &ms_server_name_str);
1063 /* With UTF-16 the string length is half the data length, minus the zero-termination */
1064 proto_item_append_text(oi,", \"%s\"",
1065 format_text(pinfo->pool, ms_server_name_str, option_length/2-1));
1066 break;
1068 case DHCP_FO_PD_OPTION_36:
1069 /* Microsoft: Client Type */
1070 if (option_length != 1) {
1071 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "client type is not 1 byte long");
1072 break;
1074 ms_client_type = tvb_get_uint8(tvb, offset);
1075 proto_item_append_text(oi, ", %s (%d)",
1076 val_to_str_const(ms_client_type, ms_client_type_vals, "(undefined)"),
1077 ms_client_type);
1078 proto_tree_add_item(option_tree, hf_dhcpfo_ms_client_type, tvb, offset, option_length, ENC_BIG_ENDIAN);
1079 break;
1081 case DHCP_FO_PD_OPTION_37:
1082 /* Microsoft: Client NAP Status */
1083 if (option_length != 1) {
1084 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "client NAP status is not 1 byte long");
1085 break;
1087 ms_client_nap_status = tvb_get_uint8(tvb, offset);
1088 proto_item_append_text(oi, ", %s (%d)",
1089 val_to_str_const(ms_client_nap_status, ms_client_nap_status_vals, "(undefined)"),
1090 ms_client_nap_status);
1091 proto_tree_add_item(option_tree, hf_dhcpfo_ms_client_nap_status, tvb, offset, option_length, ENC_BIG_ENDIAN);
1092 break;
1094 case DHCP_FO_PD_OPTION_38:
1095 /* Microsoft: Client NAP Probation */
1096 if (option_length != 4) {
1097 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "client NAP probation is not 4 bytes long");
1098 break;
1100 ms_client_nap_probation = tvb_get_ntohl(tvb, offset);
1101 /* The option value is specified:
1102 * "The value is specified as an absolute time and represents the
1103 * number of 100-nanosecond intervals since January 1, 1601 (UTC)"
1104 * But obviously that large values won't fit into a 4-byte variable.
1105 * So showing as uint32 for now.
1107 proto_item_append_text(oi,", %u", ms_client_nap_probation);
1108 proto_tree_add_uint(option_tree,
1109 hf_dhcpfo_ms_client_nap_probation, tvb, offset,
1110 option_length, ms_client_nap_probation);
1111 break;
1113 case DHCP_FO_PD_OPTION_39:
1114 /* Microsoft: Client NAP Capable */
1115 if (option_length != 1) {
1116 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "client NAP capable option is not 1 byte long");
1117 break;
1119 ms_client_nap_capable = tvb_get_uint8(tvb, offset);
1120 proto_item_append_text(oi, ", %s (%d)",
1121 tfs_get_true_false(ms_client_nap_capable),
1122 ms_client_nap_capable);
1123 proto_tree_add_item(option_tree, hf_dhcpfo_ms_client_nap_capable, tvb, offset, option_length, ENC_BIG_ENDIAN);
1124 break;
1126 case DHCP_FO_PD_OPTION_40:
1127 /* Microsoft: Client Matched Policy */
1128 proto_tree_add_item_ret_string(option_tree,
1129 hf_dhcpfo_ms_client_matched_policy, tvb, offset,
1130 option_length, ENC_UTF_16|ENC_LITTLE_ENDIAN, pinfo->pool, &ms_client_matched_policy_str);
1131 /* With UTF-16 the string length is half the data length, minus the zero-termination */
1132 proto_item_append_text(oi,", \"%s\"",
1133 format_text(pinfo->pool, ms_client_matched_policy_str, option_length/2-1));
1134 break;
1136 case DHCP_FO_PD_OPTION_41:
1137 /* Microsoft: Extended Address State */
1138 if (option_length != 4) {
1139 expert_add_info_format(pinfo, oi, &ei_dhcpfo_bad_length, "Extended address state is not 4 bytes long");
1140 break;
1142 ms_extended_address_state = tvb_get_ntohl(tvb, offset);
1143 proto_item_append_text(oi,", 0x%08x", ms_extended_address_state);
1145 proto_tree_add_uint(option_tree,
1146 hf_dhcpfo_ms_extended_address_state, tvb, offset,
1147 option_length, ms_extended_address_state);
1148 break;
1150 default:
1151 proto_tree_add_item(option_tree,
1152 hf_dhcpfo_unknown_data, tvb, offset,
1153 option_length, ENC_ASCII);
1154 break;
1157 offset += option_length;
1160 return tvb_reported_length(tvb);
1163 static int
1164 dissect_dhcpfo(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
1166 tcp_dissect_pdus(tvb, pinfo, tree, dhcpfo_desegment, 2,
1167 get_dhcpfo_pdu_len, dissect_dhcpfo_pdu, data);
1168 return tvb_reported_length(tvb);
1171 /* Register the protocol with Wireshark */
1173 void
1174 proto_register_dhcpfo(void)
1177 /* Setup list of header fields See Section 1.6.1 for details*/
1178 static hf_register_info hf[] = {
1179 { &hf_dhcpfo_length,
1180 { "Message length", "dhcpfo.length",
1181 FT_UINT16, BASE_DEC, NULL, 0,
1182 NULL, HFILL }
1184 { &hf_dhcpfo_type,
1185 { "Message Type", "dhcpfo.type",
1186 FT_UINT8, BASE_DEC, VALS(failover_vals), 0,
1187 NULL, HFILL }
1189 { &hf_dhcpfo_poffset,
1190 { "Payload Offset", "dhcpfo.poffset",
1191 FT_UINT8, BASE_DEC, NULL, 0,
1192 NULL, HFILL }
1194 { &hf_dhcpfo_time,
1195 { "Time", "dhcpfo.time",
1196 FT_ABSOLUTE_TIME, ABSOLUTE_TIME_LOCAL, NULL, 0,
1197 NULL, HFILL }
1199 { &hf_dhcpfo_xid,
1200 { "Xid", "dhcpfo.xid",
1201 FT_UINT32, BASE_HEX, NULL, 0,
1202 NULL, HFILL }
1204 { &hf_dhcpfo_additional_HB,
1205 {"Additional Header Bytes", "dhcpfo.additionalheaderbytes",
1206 FT_BYTES, BASE_NONE, NULL, 0x0,
1207 NULL, HFILL }
1209 { &hf_dhcpfo_payload_data,
1210 {"Payload Data", "dhcpfo.payloaddata",
1211 FT_NONE, BASE_NONE, NULL, 0,
1212 NULL, HFILL }
1214 { &hf_dhcpfo_dhcp_style_option,
1215 {"DHCP Style Option", "dhcpfo.dhcpstyleoption",
1216 FT_NONE, BASE_NONE, NULL, 0,
1217 NULL, HFILL }
1219 { &hf_dhcpfo_option_code,
1220 {"Option Code", "dhcpfo.optioncode",
1221 FT_UINT16, BASE_DEC, VALS(option_code_vals), 0,
1222 NULL, HFILL }
1224 {&hf_dhcpfo_option_length,
1225 {"Length", "dhcpfo.optionlength",
1226 FT_UINT16, BASE_DEC, NULL, 0,
1227 NULL, HFILL }
1229 {&hf_dhcpfo_binding_status,
1230 {"Status", "dhcpfo.bindingstatus",
1231 FT_UINT32, BASE_DEC, VALS(binding_status_vals), 0,
1232 NULL, HFILL }
1234 {&hf_dhcpfo_server_state,
1235 {"server status", "dhcpfo.serverstatus",
1236 FT_UINT8, BASE_DEC, VALS(server_state_vals), 0,
1237 NULL, HFILL }
1239 {&hf_dhcpfo_assigned_ip_address,
1240 {"assigned ip address", "dhcpfo.assignedipaddress",
1241 FT_IPv4, BASE_NONE, NULL, 0x0,
1242 NULL, HFILL }
1244 {&hf_dhcpfo_delayed_service_parameter,
1245 {"delayed service parameter", "dhcpfo.delayedserviceparameter",
1246 FT_UINT8, BASE_DEC, NULL, 0x0,
1247 NULL, HFILL }
1249 {&hf_dhcpfo_addresses_transferred,
1250 {"addresses transferred", "dhcpfo.addressestransferred",
1251 FT_UINT32, BASE_DEC, NULL, 0,
1252 NULL, HFILL }
1254 {&hf_dhcpfo_client_identifier,
1255 {"Client Identifier", "dhcpfo.clientidentifier",
1256 FT_STRING, BASE_NONE, NULL, 0,
1257 NULL, HFILL }
1259 {&hf_dhcpfo_client_hw_type,
1260 {"Client Hardware Type", "dhcpfo.clienthardwaretype",
1261 FT_UINT8, BASE_HEX, VALS(arp_hrd_vals), 0x0,
1262 NULL, HFILL }
1264 {&hf_dhcpfo_client_hardware_address,
1265 {"Client Hardware Address", "dhcpfo.clienthardwareaddress",
1266 FT_STRING, BASE_NONE, NULL, 0,
1267 NULL, HFILL }
1269 {&hf_dhcpfo_ftddns,
1270 {"FTDDNS", "dhcpfo.ftddns",
1271 FT_STRING, BASE_NONE, NULL, 0,
1272 NULL, HFILL }
1274 {&hf_dhcpfo_reject_reason,
1275 {"Reject reason", "dhcpfo.rejectreason",
1276 FT_UINT8, BASE_DEC, VALS(reject_reason_vals), 0,
1277 NULL, HFILL }
1279 {&hf_dhcpfo_relationship_name,
1280 {"Relationship name", "dhcpfo.relationshipname",
1281 FT_STRING, BASE_NONE, NULL, 0,
1282 NULL, HFILL }
1284 {&hf_dhcpfo_message,
1285 {"Message", "dhcpfo.message",
1286 FT_STRING, BASE_NONE, NULL, 0,
1287 NULL, HFILL }
1289 {&hf_dhcpfo_mclt,
1290 {"MCLT", "dhcpfo.mclt",
1291 FT_UINT32, BASE_DEC, NULL, 0,
1292 NULL, HFILL }
1294 {&hf_dhcpfo_vendor_class,
1295 {"Vendor class", "dhcpfo.vendorclass",
1296 FT_STRING, BASE_NONE, NULL, 0,
1297 NULL, HFILL }
1299 {&hf_dhcpfo_lease_expiration_time,
1300 {"Lease expiration time", "dhcpfo.leaseexpirationtime",
1301 FT_UINT32, BASE_DEC, NULL, 0,
1302 NULL, HFILL }
1304 {&hf_dhcpfo_potential_expiration_time,
1305 {"Potential expiration time", "dhcpfo.potentialexpirationtime",
1306 FT_UINT32, BASE_DEC, NULL, 0,
1307 NULL, HFILL }
1309 {&hf_dhcpfo_client_last_transaction_time,
1310 {"Client last transaction time", "dhcpfo.clientlasttransactiontime",
1311 FT_UINT32, BASE_DEC, NULL, 0,
1312 NULL, HFILL }
1314 {&hf_dhcpfo_start_time_of_state,
1315 {"Start time of state", "dhcpfo.starttimeofstate",
1316 FT_UINT32, BASE_DEC, NULL, 0,
1317 NULL, HFILL }
1319 {&hf_dhcpfo_vendor_option,
1320 {"Vendor option", "dhcpfo.vendoroption",
1321 FT_NONE, BASE_NONE, NULL, 0x0,
1322 NULL, HFILL }
1324 {&hf_dhcpfo_max_unacked_bndupd,
1325 {"Max unacked BNDUPD", "dhcpfo.maxunackedbndupd",
1326 FT_UINT32, BASE_DEC, NULL, 0,
1327 NULL, HFILL }
1329 {&hf_dhcpfo_protocol_version,
1330 {"Protocol version", "dhcpfo.protocolversion",
1331 FT_UINT8, BASE_DEC, NULL, 0,
1332 NULL, HFILL }
1334 {&hf_dhcpfo_receive_timer,
1335 {"Receive timer", "dhcpfo.receivetimer",
1336 FT_UINT32, BASE_DEC|BASE_UNIT_STRING, UNS(&units_second_seconds), 0,
1337 NULL, HFILL }
1339 {&hf_dhcpfo_message_digest,
1340 {"Message digest", "dhcpfo.messagedigest",
1341 FT_BYTES, BASE_NONE|BASE_ALLOW_ZERO, NULL, 0,
1342 NULL, HFILL }
1344 {&hf_dhcpfo_hash_bucket_assignment,
1345 {"Hash bucket assignment", "dhcpfo.hashbucketassignment",
1346 FT_BYTES, BASE_NONE, NULL, 0,
1347 NULL, HFILL }
1349 {&hf_dhcpfo_ipflags,
1350 {"IP Flags", "dhcpfo.ipflags",
1351 FT_UINT16, BASE_HEX, NULL, 0,
1352 NULL, HFILL }
1354 {&hf_dhcpfo_ipflags_reserved,
1355 {"Reserved", "dhcpfo.ipflags.reserved",
1356 FT_BOOLEAN, 8, NULL, 0x80,
1357 NULL, HFILL }
1359 {&hf_dhcpfo_ipflags_bootp,
1360 {"BOOTP", "dhcpfo.ipflags.bootp",
1361 FT_BOOLEAN, 8, NULL, 0x40,
1362 NULL, HFILL }
1364 {&hf_dhcpfo_ipflags_mbz,
1365 {"MBZ", "dhcpfo.ipflags.mbz",
1366 FT_UINT8, BASE_HEX, NULL, 0x3F,
1367 NULL, HFILL }
1369 {&hf_dhcpfo_message_digest_type,
1370 {"Message digest type", "dhcpfo.message_digest_type",
1371 FT_UINT8, BASE_DEC, VALS(message_digest_type_vals), 0,
1372 NULL, HFILL }
1374 {&hf_dhcpfo_tls_request,
1375 {"TLS Request", "dhcpfo.tls_request",
1376 FT_UINT8, BASE_DEC, VALS(tls_request_vals), 0,
1377 NULL, HFILL }
1379 {&hf_dhcpfo_tls_reply,
1380 {"TLS Reply", "dhcpfo.tls_reply",
1381 FT_UINT8, BASE_DEC, VALS(tls_reply_vals), 0,
1382 NULL, HFILL }
1384 {&hf_dhcpfo_serverflag,
1385 {"Serverflag", "dhcpfo.serverflag",
1386 FT_UINT8, BASE_DEC, VALS(serverflag_vals), 0,
1387 NULL, HFILL }
1389 {&hf_dhcpfo_options,
1390 {"Options", "dhcpfo.options",
1391 FT_BYTES, BASE_NONE, NULL, 0,
1392 NULL, HFILL }
1394 {&hf_dhcpfo_ms_client_name,
1395 {"Client name (Microsoft-specific)", "dhcpfo.microsoft.clientname",
1396 FT_STRING, BASE_NONE, NULL, 0,
1397 NULL, HFILL }
1399 {&hf_dhcpfo_ms_client_description,
1400 {"Client description (Microsoft-specific)", "dhcpfo.microsoft.clientdescription",
1401 FT_STRING, BASE_NONE, NULL, 0,
1402 NULL, HFILL }
1404 {&hf_dhcpfo_ms_client_type,
1405 {"Client type (Microsoft-specific)", "dhcpfo.microsoft.clienttype",
1406 FT_UINT8, BASE_NONE, VALS(ms_client_type_vals), 0,
1407 NULL, HFILL }
1409 {&hf_dhcpfo_ms_client_nap_status,
1410 {"Client NAP status (Microsoft-specific)", "dhcpfo.microsoft.clientnapstatus",
1411 FT_UINT8, BASE_NONE, VALS(ms_client_nap_status_vals), 0,
1412 NULL, HFILL }
1414 {&hf_dhcpfo_ms_client_nap_capable,
1415 {"Client NAP capable (Microsoft-specific)", "dhcpfo.microsoft.clientnapcapable",
1416 FT_BOOLEAN, BASE_NONE, NULL, 0,
1417 NULL, HFILL }
1419 {&hf_dhcpfo_ms_client_nap_probation,
1420 {"Client NAP probation (Microsoft-specific)", "dhcpfo.microsoft.clientnapprobation",
1421 FT_UINT32, BASE_DEC, NULL, 0,
1422 NULL, HFILL }
1424 {&hf_dhcpfo_ms_client_matched_policy,
1425 {"Client matched policy (Microsoft-specific)", "dhcpfo.microsoft.clientmatchedpolicy",
1426 FT_STRING, BASE_NONE, NULL, 0,
1427 NULL, HFILL }
1429 {&hf_dhcpfo_ms_server_name,
1430 {"Server name (Microsoft-specific)", "dhcpfo.microsoft.servername",
1431 FT_STRING, BASE_NONE, NULL, 0,
1432 NULL, HFILL }
1434 {&hf_dhcpfo_ms_client_scope,
1435 {"Client DHCP scope (Microsoft-specific)", "dhcpfo.microsoft.clientscope",
1436 FT_IPv4, BASE_NONE, NULL, 0x0,
1437 NULL, HFILL }
1439 {&hf_dhcpfo_ms_client_subnet_mask,
1440 {"Client subnet mask (Microsoft-specific)", "dhcpfo.microsoft.clientsubnetmask",
1441 FT_IPv4, BASE_NETMASK, NULL, 0x0,
1442 NULL, HFILL }
1444 {&hf_dhcpfo_ms_scope_id,
1445 {"Scope ID (Microsoft-specific)", "dhcpfo.microsoft.scopeid",
1446 FT_IPv4, BASE_NONE, NULL, 0x0,
1447 NULL, HFILL }
1449 {&hf_dhcpfo_ms_server_ip,
1450 {"Server IP (Microsoft-specific)", "dhcpfo.microsoft.serverip",
1451 FT_IPv4, BASE_NONE, NULL, 0x0,
1452 NULL, HFILL }
1454 {&hf_dhcpfo_ms_ipflags,
1455 {"IP flags (Microsoft-specific)", "dhcpfo.microsoft.ipflags",
1456 FT_UINT8, BASE_HEX, NULL, 0,
1457 NULL, HFILL }
1459 {&hf_dhcpfo_ms_extended_address_state,
1460 {"Extended address state (Microsoft-specific)", "dhcpfo.microsoft.extendedaddressstate",
1461 FT_UINT32, BASE_HEX, NULL, 0,
1462 NULL, HFILL }
1464 {&hf_dhcpfo_infoblox_client_hostname,
1465 {"Client hostname (Infoblox-specific)", "dhcpfo.infoblox.clienthostname",
1466 FT_STRING, BASE_NONE, NULL, 0,
1467 NULL, HFILL }
1469 {&hf_dhcpfo_unknown_data,
1470 {"Unknown data", "dhcpfo.unknowndata",
1471 FT_BYTES, BASE_NONE, NULL, 0,
1472 NULL, HFILL }
1476 /* Setup protocol subtree array */
1477 static int *ett[] = {
1478 &ett_dhcpfo,
1479 &ett_fo_payload,
1480 &ett_fo_option,
1481 &ett_fo_payload_data,
1484 static ei_register_info ei[] = {
1485 { &ei_dhcpfo_bad_length, { "dhcpfo.bad_length", PI_PROTOCOL, PI_WARN, "Bad length", EXPFILL }},
1486 { &ei_dhcpfo_message_digest_type_not_allowed, { "dhcpfo.message_digest_type_not_allowed", PI_PROTOCOL, PI_WARN, "Message digest type not allowed", EXPFILL }},
1489 module_t *dhcpfo_module;
1490 expert_module_t* expert_dhcpfo;
1492 /* Register the protocol name and description */
1493 proto_dhcpfo = proto_register_protocol("DHCP Failover", "DHCPFO", "dhcpfo");
1495 /* Required function calls to register the header fields and subtrees used */
1496 proto_register_field_array(proto_dhcpfo, hf, array_length(hf));
1497 proto_register_subtree_array(ett, array_length(ett));
1498 expert_dhcpfo = expert_register_protocol(proto_dhcpfo);
1499 expert_register_field_array(expert_dhcpfo, ei, array_length(ei));
1501 dhcpfo_module = prefs_register_protocol(proto_dhcpfo, NULL);
1503 prefs_register_bool_preference(dhcpfo_module, "desegment",
1504 "Reassemble DHCP failover messages spanning multiple TCP segments",
1505 "Whether the DHCP failover dissector should reassemble messages spanning multiple TCP segments."
1506 " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
1507 &dhcpfo_desegment);
1508 prefs_register_enum_preference(dhcpfo_module, "microsoft_compatibility",
1509 "Microsoft Windows DHCP server compatibility",
1510 "Enables the dissector to show Microsoft-formatted option fields correctly",
1511 &dhcpfo_microsoft_compatibility,
1512 microsoft_compatibility, false);
1514 dhcpfo_handle = register_dissector("dhcpfo", dissect_dhcpfo, proto_dhcpfo);
1517 void
1518 proto_reg_handoff_dhcpfo(void)
1520 dissector_add_uint_with_preference("tcp.port", TCP_PORT_DHCPFO, dhcpfo_handle);
1524 * Editor modelines - https://www.wireshark.org/tools/modelines.html
1526 * Local variables:
1527 * c-basic-offset: 8
1528 * tab-width: 8
1529 * indent-tabs-mode: t
1530 * End:
1532 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
1533 * :indentSize=8:tabSize=8:noTabs=false: