2 * Routines for BOOTP/DHCP packet disassembly
3 * Gilbert Ramirez <gram@alumni.rice.edu>
5 * $Id: packet-bootp.c,v 1.58 2001/12/03 03:59:33 guy Exp $
7 * The information used comes from:
8 * RFC 951: Bootstrap Protocol
9 * RFC 1542: Clarifications and Extensions for the Bootstrap Protocol
10 * RFC 2131: Dynamic Host Configuration Protocol
11 * RFC 2132: DHCP Options and BOOTP Vendor Extensions
12 * RFC 2489: Procedure for Defining New DHCP Options
13 * RFC 3046: DHCP Relay Agent Information Option
14 * RFC 3118: Authentication for DHCP Messages
15 * BOOTP and DHCP Parameters
16 * http://www.iana.org/assignments/bootp-dhcp-parameters
18 * Ethereal - Network traffic analyzer
19 * By Gerald Combs <gerald@ethereal.com>
20 * Copyright 1998 Gerald Combs
22 * This program is free software; you can redistribute it and/or
23 * modify it under the terms of the GNU General Public License
24 * as published by the Free Software Foundation; either version 2
25 * of the License, or (at your option) any later version.
27 * This program is distributed in the hope that it will be useful,
28 * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 * GNU General Public License for more details.
32 * You should have received a copy of the GNU General Public License
33 * along with this program; if not, write to the Free Software
34 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
41 #ifdef HAVE_SYS_TYPES_H
42 # include <sys/types.h>
47 #include "int-64bit.h"
49 #include "packet-arp.h"
51 static int proto_bootp = -1;
52 static int hf_bootp_type = -1;
53 static int hf_bootp_hw_type = -1;
54 static int hf_bootp_hw_len = -1;
55 static int hf_bootp_hops = -1;
56 static int hf_bootp_id = -1;
57 static int hf_bootp_secs = -1;
58 static int hf_bootp_flag = -1;
59 static int hf_bootp_ip_client = -1;
60 static int hf_bootp_ip_your = -1;
61 static int hf_bootp_ip_server = -1;
62 static int hf_bootp_ip_relay = -1;
63 static int hf_bootp_hw_addr = -1;
64 static int hf_bootp_server = -1;
65 static int hf_bootp_file = -1;
66 static int hf_bootp_cookie = -1;
67 static int hf_bootp_dhcp = -1;
69 static guint ett_bootp = -1;
70 static guint ett_bootp_option = -1;
72 #define UDP_PORT_BOOTPS 67
74 enum field_type { none, ipv4, string, toggle, yes_no, special, opaque,
76 val_u_byte, val_u_short, val_u_le_short, val_u_long,
81 enum field_type ftype;
84 #define NUM_OPT_INFOS 211
85 #define NUM_O63_SUBOPTS 11
87 static int dissect_vendor_pxeclient_suboption(proto_tree *v_tree, tvbuff_t *tvb,
89 static int dissect_netware_ip_suboption(proto_tree *v_tree, tvbuff_t *tvb,
91 static int bootp_dhcp_decode_agent_info(proto_tree *v_tree, tvbuff_t *tvb,
95 get_dhcp_type(guint8 byte)
97 static const char *opt53_text[] = {
98 "Unknown Message Type",
110 if (byte > 0 && byte < (sizeof opt53_text / sizeof opt53_text[0]))
114 return opt53_text[i];
117 /* DHCP Authentication protocols */
118 #define AUTHEN_PROTO_CONFIG_TOKEN 0
119 #define AUTHEN_PROTO_DELAYED_AUTHEN 1
121 /* DHCP Authentication algorithms for delayed authentication */
122 #define AUTHEN_DELAYED_ALGO_HMAC_MD5 1
124 /* DHCP Authentication Replay Detection Methods */
125 #define AUTHEN_RDM_MONOTONIC_COUNTER 0x00
127 /* Returns the number of bytes consumed by this option. */
129 bootp_option(tvbuff_t *tvb, proto_tree *bp_tree, int voff, int eoff,
130 gboolean first_pass, const char **dhcp_type_p,
131 const guint8 **vendor_class_id_p)
134 enum field_type ftype;
135 u_char code = tvb_get_guint8(tvb, voff);
138 int i,optp, consumed;
146 static const value_string nbnt_vals[] = {
153 static const value_string authen_protocol_vals[] = {
154 {AUTHEN_PROTO_CONFIG_TOKEN, "configuration token" },
155 {AUTHEN_PROTO_DELAYED_AUTHEN, "delayed authentication" },
158 static const value_string authen_da_algo_vals[] = {
159 {AUTHEN_DELAYED_ALGO_HMAC_MD5, "HMAC_MD5" },
162 static const value_string authen_rdm_vals[] = {
163 {AUTHEN_RDM_MONOTONIC_COUNTER, "Monotonically-increasing counter" },
166 static struct opt_info opt[] = {
167 /* 0 */ { "Padding", none },
168 /* 1 */ { "Subnet Mask", ipv4 },
169 /* 2 */ { "Time Offset", val_s_long },
170 /* 3 */ { "Router", ipv4 },
171 /* 4 */ { "Time Server", ipv4 },
172 /* 5 */ { "Name Server", ipv4 },
173 /* 6 */ { "Domain Name Server", ipv4 },
174 /* 7 */ { "Log Server", ipv4 },
175 /* 8 */ { "Cookie Server", ipv4 },
176 /* 9 */ { "LPR Server", ipv4 },
177 /* 10 */ { "Impress Server", ipv4 },
178 /* 11 */ { "Resource Location Server", ipv4 },
179 /* 12 */ { "Host Name", string },
180 /* 13 */ { "Boot File Size", val_u_short },
181 /* 14 */ { "Merit Dump File", string },
182 /* 15 */ { "Domain Name", string },
183 /* 16 */ { "Swap Server", ipv4 },
184 /* 17 */ { "Root Path", string },
185 /* 18 */ { "Extensions Path", string },
186 /* 19 */ { "IP Forwarding", toggle },
187 /* 20 */ { "Non-Local Source Routing", toggle },
188 /* 21 */ { "Policy Filter", special },
189 /* 22 */ { "Maximum Datagram Reassembly Size", val_u_short },
190 /* 23 */ { "Default IP Time-to-Live", val_u_byte },
191 /* 24 */ { "Path MTU Aging Timeout", time_in_secs },
192 /* 25 */ { "Path MTU Plateau Table", val_u_short },
193 /* 26 */ { "Interface MTU", val_u_short },
194 /* 27 */ { "All Subnets are Local", yes_no },
195 /* 28 */ { "Broadcast Address", ipv4 },
196 /* 29 */ { "Perform Mask Discovery", toggle },
197 /* 30 */ { "Mask Supplier", yes_no },
198 /* 31 */ { "Perform Router Discover", toggle },
199 /* 32 */ { "Router Solicitation Address", ipv4 },
200 /* 33 */ { "Static Route", special },
201 /* 34 */ { "Trailer Encapsulation", toggle },
202 /* 35 */ { "ARP Cache Timeout", time_in_secs },
203 /* 36 */ { "Ethernet Encapsulation", toggle },
204 /* 37 */ { "TCP Default TTL", val_u_byte },
205 /* 38 */ { "TCP Keepalive Interval", time_in_secs },
206 /* 39 */ { "TCP Keepalive Garbage", toggle },
207 /* 40 */ { "Network Information Service Domain", string },
208 /* 41 */ { "Network Information Service Servers", ipv4 },
209 /* 42 */ { "Network Time Protocol Servers", ipv4 },
210 /* 43 */ { "Vendor-Specific Information", special },
211 /* 44 */ { "NetBIOS over TCP/IP Name Server", ipv4 },
212 /* 45 */ { "NetBIOS over TCP/IP Datagram Distribution Name Server", ipv4 },
213 /* 46 */ { "NetBIOS over TCP/IP Node Type", special },
214 /* 47 */ { "NetBIOS over TCP/IP Scope", string },
215 /* 48 */ { "X Window System Font Server", ipv4 },
216 /* 49 */ { "X Window System Display Manager", ipv4 },
217 /* 50 */ { "Requested IP Address", ipv4 },
218 /* 51 */ { "IP Address Lease Time", time_in_secs },
219 /* 52 */ { "Option Overload", special },
220 /* 53 */ { "DHCP Message Type", special },
221 /* 54 */ { "Server Identifier", ipv4 },
222 /* 55 */ { "Parameter Request List", special },
223 /* 56 */ { "Message", string },
224 /* 57 */ { "Maximum DHCP Message Size", val_u_short },
225 /* 58 */ { "Renewal Time Value", time_in_secs },
226 /* 59 */ { "Rebinding Time Value", time_in_secs },
227 /* 60 */ { "Vendor class identifier", special },
228 /* 61 */ { "Client identifier", special },
229 /* 62 */ { "Novell/Netware IP domain", string },
230 /* 63 */ { "Novell Options", special },
231 /* 64 */ { "Network Information Service+ Domain", string },
232 /* 65 */ { "Network Information Service+ Servers", ipv4 },
233 /* 66 */ { "TFTP Server Name", string },
234 /* 67 */ { "Bootfile name", string },
235 /* 68 */ { "Mobile IP Home Agent", ipv4 },
236 /* 69 */ { "SMTP Server", ipv4 },
237 /* 70 */ { "POP3 Server", ipv4 },
238 /* 71 */ { "NNTP Server", ipv4 },
239 /* 72 */ { "Default WWW Server", ipv4 },
240 /* 73 */ { "Default Finger Server", ipv4 },
241 /* 74 */ { "Default IRC Server", ipv4 },
242 /* 75 */ { "StreetTalk Server", ipv4 },
243 /* 76 */ { "StreetTalk Directory Assistance Server", ipv4 },
244 /* 77 */ { "User Class Information", opaque },
245 /* 78 */ { "Directory Agent Information", opaque },
246 /* 79 */ { "Service Location Agent Scope", opaque },
247 /* 80 */ { "Naming Authority", opaque },
248 /* 81 */ { "Client Fully Qualified Domain Name", opaque },
249 /* 82 */ { "Agent Information Option", special },
250 /* 83 */ { "Unassigned", opaque },
251 /* 84 */ { "Unassigned", opaque },
252 /* 85 */ { "Novell Directory Services Servers", opaque },
253 /* 86 */ { "Novell Directory Services Tree Name", opaque },
254 /* 87 */ { "Novell Directory Services Context", opaque },
255 /* 88 */ { "IEEE 1003.1 POSIX Timezone", opaque },
256 /* 89 */ { "Fully Qualified Domain Name", opaque },
257 /* 90 */ { "Authentication", special },
258 /* 91 */ { "Vines TCP/IP Server Option", opaque },
259 /* 92 */ { "Server Selection Option", opaque },
260 /* 93 */ { "Client System Architecture", opaque },
261 /* 94 */ { "Client Network Device Interface", opaque },
262 /* 95 */ { "Lightweight Directory Access Protocol", opaque },
263 /* 96 */ { "IPv6 Transitions", opaque },
264 /* 97 */ { "UUID/GUID-based Client Identifier", opaque },
265 /* 98 */ { "Open Group's User Authentication", opaque },
266 /* 99 */ { "Unassigned", opaque },
267 /* 100 */ { "Printer Name", opaque },
268 /* 101 */ { "MDHCP multicast address", opaque },
269 /* 102 */ { "Removed/unassigned", opaque },
270 /* 103 */ { "Removed/unassigned", opaque },
271 /* 104 */ { "Removed/unassigned", opaque },
272 /* 105 */ { "Removed/unassigned", opaque },
273 /* 106 */ { "Removed/unassigned", opaque },
274 /* 107 */ { "Removed/unassigned", opaque },
275 /* 108 */ { "Swap Path Option", opaque },
276 /* 109 */ { "Unassigned", opaque },
277 /* 110 */ { "IPX Compability", opaque },
278 /* 111 */ { "Unassigned", opaque },
279 /* 112 */ { "Netinfo Parent Server Address", opaque },
280 /* 113 */ { "Netinfo Parent Server Tag", opaque },
281 /* 114 */ { "URL", opaque },
282 /* 115 */ { "DHCP Failover Protocol", opaque },
283 /* 116 */ { "DHCP Auto-Configuration", opaque },
284 /* 117 */ { "Unassigned", opaque },
285 /* 118 */ { "Unassigned", opaque },
286 /* 119 */ { "Unassigned", opaque },
287 /* 120 */ { "Unassigned", opaque },
288 /* 121 */ { "Unassigned", opaque },
289 /* 122 */ { "Unassigned", opaque },
290 /* 123 */ { "Unassigned", opaque },
291 /* 124 */ { "Unassigned", opaque },
292 /* 125 */ { "Unassigned", opaque },
293 /* 126 */ { "Extension", opaque },
294 /* 127 */ { "Extension", opaque },
295 /* 128 */ { "Private", opaque },
296 /* 129 */ { "Private", opaque },
297 /* 130 */ { "Private", opaque },
298 /* 131 */ { "Private", opaque },
299 /* 132 */ { "Private", opaque },
300 /* 133 */ { "Private", opaque },
301 /* 134 */ { "Private", opaque },
302 /* 135 */ { "Private", opaque },
303 /* 136 */ { "Private", opaque },
304 /* 137 */ { "Private", opaque },
305 /* 138 */ { "Private", opaque },
306 /* 139 */ { "Private", opaque },
307 /* 140 */ { "Private", opaque },
308 /* 141 */ { "Private", opaque },
309 /* 142 */ { "Private", opaque },
310 /* 143 */ { "Private", opaque },
311 /* 144 */ { "Private", opaque },
312 /* 145 */ { "Private", opaque },
313 /* 146 */ { "Private", opaque },
314 /* 147 */ { "Private", opaque },
315 /* 148 */ { "Private", opaque },
316 /* 149 */ { "Private", opaque },
317 /* 150 */ { "Private", opaque },
318 /* 151 */ { "Private", opaque },
319 /* 152 */ { "Private", opaque },
320 /* 153 */ { "Private", opaque },
321 /* 154 */ { "Private", opaque },
322 /* 155 */ { "Private", opaque },
323 /* 156 */ { "Private", opaque },
324 /* 157 */ { "Private", opaque },
325 /* 158 */ { "Private", opaque },
326 /* 159 */ { "Private", opaque },
327 /* 160 */ { "Private", opaque },
328 /* 161 */ { "Private", opaque },
329 /* 162 */ { "Private", opaque },
330 /* 163 */ { "Private", opaque },
331 /* 164 */ { "Private", opaque },
332 /* 165 */ { "Private", opaque },
333 /* 166 */ { "Private", opaque },
334 /* 167 */ { "Private", opaque },
335 /* 168 */ { "Private", opaque },
336 /* 169 */ { "Private", opaque },
337 /* 170 */ { "Private", opaque },
338 /* 171 */ { "Private", opaque },
339 /* 172 */ { "Private", opaque },
340 /* 173 */ { "Private", opaque },
341 /* 174 */ { "Private", opaque },
342 /* 175 */ { "Private", opaque },
343 /* 176 */ { "Private", opaque },
344 /* 177 */ { "Private", opaque },
345 /* 178 */ { "Private", opaque },
346 /* 179 */ { "Private", opaque },
347 /* 180 */ { "Private", opaque },
348 /* 181 */ { "Private", opaque },
349 /* 182 */ { "Private", opaque },
350 /* 183 */ { "Private", opaque },
351 /* 184 */ { "Private", opaque },
352 /* 185 */ { "Private", opaque },
353 /* 186 */ { "Private", opaque },
354 /* 187 */ { "Private", opaque },
355 /* 188 */ { "Private", opaque },
356 /* 189 */ { "Private", opaque },
357 /* 190 */ { "Private", opaque },
358 /* 191 */ { "Private", opaque },
359 /* 192 */ { "Private", opaque },
360 /* 193 */ { "Private", opaque },
361 /* 194 */ { "Private", opaque },
362 /* 195 */ { "Private", opaque },
363 /* 196 */ { "Private", opaque },
364 /* 197 */ { "Private", opaque },
365 /* 198 */ { "Private", opaque },
366 /* 199 */ { "Private", opaque },
367 /* 200 */ { "Private", opaque },
368 /* 201 */ { "Private", opaque },
369 /* 202 */ { "Private", opaque },
370 /* 203 */ { "Private", opaque },
371 /* 204 */ { "Private", opaque },
372 /* 205 */ { "Private", opaque },
373 /* 206 */ { "Private", opaque },
374 /* 207 */ { "Private", opaque },
375 /* 208 */ { "Private", opaque },
376 /* 209 */ { "Private", opaque },
377 /* 210 */ { "Authentication", special }
380 /* Options whose length isn't "vlen + 2". */
383 case 0: /* Padding */
384 /* check how much padding we have */
385 for (i = voff + 1; i < eoff; i++ ) {
386 if (tvb_get_guint8(tvb, i) != 0) {
392 if (bp_tree != NULL) {
393 proto_tree_add_text(bp_tree, tvb, voff, i,
401 case 255: /* End Option */
403 if (bp_tree != NULL) {
404 proto_tree_add_text(bp_tree, tvb, voff, 1,
413 * Get the length of the option, and the number of bytes it
414 * consumes (the length doesn't include the option code or
417 vlen = tvb_get_guint8(tvb, voff+1);
421 * In the first pass, we don't put anything into the protocol
422 * tree; we just check for some options we have to look at
423 * in order to properly process the packet:
425 * 53 (DHCP message type) - if this is present, this is DHCP
427 * 60 (Vendor class identifier) - we need this in order to
428 * interpret the vendor-specific info
435 get_dhcp_type(tvb_get_guint8(tvb, voff+2));
440 tvb_get_ptr(tvb, voff+2, consumed-2);
445 * We don't do anything else here.
451 * This is the second pass - if there's a protocol tree to be
452 * built, we put stuff into it, otherwise we just return.
454 if (bp_tree == NULL) {
455 /* Don't put anything in the protocol tree. */
459 text = opt[code].text;
463 case 21: /* Policy Filter */
465 /* one IP address pair */
466 proto_tree_add_text(bp_tree, tvb, voff, consumed,
467 "Option %d: %s = %s/%s", code, text,
468 ip_to_str(tvb_get_ptr(tvb, voff+2, 4)),
469 ip_to_str(tvb_get_ptr(tvb, voff+6, 4)));
471 /* > 1 IP address pair. Let's make a sub-tree */
472 vti = proto_tree_add_text(bp_tree, tvb, voff,
473 consumed, "Option %d: %s", code, text);
474 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
475 for (i = voff + 2; i < voff + consumed; i += 8) {
476 proto_tree_add_text(v_tree, tvb, i, 8, "IP Address/Mask: %s/%s",
477 ip_to_str(tvb_get_ptr(tvb, i, 4)),
478 ip_to_str(tvb_get_ptr(tvb, i+4, 4)));
483 case 33: /* Static Route */
485 /* one IP address pair */
486 proto_tree_add_text(bp_tree, tvb, voff, consumed,
487 "Option %d: %s = %s/%s", code, text,
488 ip_to_str(tvb_get_ptr(tvb, voff+2, 4)),
489 ip_to_str(tvb_get_ptr(tvb, voff+6, 4)));
491 /* > 1 IP address pair. Let's make a sub-tree */
492 vti = proto_tree_add_text(bp_tree, tvb, voff,
493 consumed, "Option %d: %s", code, text);
494 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
495 for (i = voff + 2; i < voff + consumed; i += 8) {
496 proto_tree_add_text(v_tree, tvb, i, 8,
497 "Destination IP Address/Router: %s/%s",
498 ip_to_str(tvb_get_ptr(tvb, i, 4)),
499 ip_to_str(tvb_get_ptr(tvb, i+4, 4)));
504 case 43: /* Vendor-Specific Info */
505 /* PXE protocol 2.1 as described in the intel specs */
506 if (*vendor_class_id_p != NULL &&
507 strncmp(*vendor_class_id_p, "PXEClient", strlen("PXEClient")) == 0) {
508 vti = proto_tree_add_text(bp_tree, tvb, voff,
509 consumed, "Option %d: %s (PXEClient)", code, text);
510 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
513 while (optp < voff+consumed) {
514 optp = dissect_vendor_pxeclient_suboption(v_tree,
518 proto_tree_add_text(bp_tree, tvb, voff, consumed,
519 "Option %d: %s (%d bytes)", code, text, vlen);
523 case 46: /* NetBIOS-over-TCP/IP Node Type */
524 byte = tvb_get_guint8(tvb, voff+2);
525 proto_tree_add_text(bp_tree, tvb, voff, consumed,
526 "Option %d: %s = %s", code, text,
527 val_to_str(byte, nbnt_vals,
528 "Unknown (0x%02x)"));
531 case 53: /* DHCP Message Type */
532 proto_tree_add_text(bp_tree, tvb, voff, 3, "Option %d: %s = DHCP %s",
533 code, text, get_dhcp_type(tvb_get_guint8(tvb, voff+2)));
536 case 55: /* Parameter Request List */
537 vti = proto_tree_add_text(bp_tree, tvb, voff,
538 vlen + 2, "Option %d: %s", code, text);
539 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
540 for (i = 0; i < vlen; i++) {
541 byte = tvb_get_guint8(tvb, voff+2+i);
542 if (byte < NUM_OPT_INFOS) {
543 proto_tree_add_text(v_tree, tvb, voff+2+i, 1, "%d = %s",
544 byte, opt[byte].text);
546 proto_tree_add_text(vti, tvb, voff+2+i, 1,
547 "Unknown Option Code: %d", byte);
552 case 60: /* Vendor class identifier */
553 proto_tree_add_text(bp_tree, tvb, voff, consumed,
554 "Option %d: %s = \"%.*s\"", code, text, vlen,
555 tvb_get_ptr(tvb, voff+2, consumed-2));
558 case 61: /* Client Identifier */
559 /* We *MAY* use hwtype/hwaddr. If we have 7 bytes, I'll
560 guess that the first is the hwtype, and the last 6
565 vti = proto_tree_add_text(bp_tree, tvb, voff,
566 consumed, "Option %d: %s", code, text);
567 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
568 htype = tvb_get_guint8(tvb, voff+2);
569 proto_tree_add_text(v_tree, tvb, voff+2, 1,
571 arphrdtype_to_str(htype,
572 "Unknown (0x%02x)"));
573 proto_tree_add_text(v_tree, tvb, voff+3, 6,
574 "Client hardware address: %s",
575 arphrdaddr_to_str(tvb_get_ptr(tvb, voff+3, 6),
578 /* otherwise, it's opaque data */
579 proto_tree_add_text(bp_tree, tvb, voff, consumed,
580 "Option %d: %s (%d bytes)", code, text, vlen);
584 case 63: /* NetWare/IP options */
585 vti = proto_tree_add_text(bp_tree, tvb, voff,
586 consumed, "Option %d: %s", code, text);
587 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
590 while (optp < voff+consumed)
591 optp = dissect_netware_ip_suboption(v_tree, tvb, optp);
594 case 82: /* Relay Agent Information Option */
595 vti = proto_tree_add_text(bp_tree, tvb, voff, consumed,
596 "Option %d: %s (%d bytes)",
598 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
600 while (optp < voff+consumed) {
601 optp = bootp_dhcp_decode_agent_info(v_tree, tvb, optp);
605 case 90: /* DHCP Authentication */
606 case 210: /* Was this used for authentication at one time? */
607 vti = proto_tree_add_text(bp_tree, tvb, voff,
608 vlen + 2, "Option %d: %s", code, text);
609 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
611 protocol = tvb_get_guint8(tvb, voff+2);
612 proto_tree_add_text(v_tree, tvb, voff+2, 1, "Protocol: %s (%u)",
613 val_to_str(protocol, authen_protocol_vals, "Unknown"),
616 algorithm = tvb_get_guint8(tvb, voff+3);
619 case AUTHEN_PROTO_DELAYED_AUTHEN:
620 proto_tree_add_text(v_tree, tvb, voff+3, 1,
621 "Algorithm: %s (%u)",
622 val_to_str(algorithm, authen_da_algo_vals, "Unknown"),
627 proto_tree_add_text(v_tree, tvb, voff+3, 1,
628 "Algorithm: %u", algorithm);
632 rdm = tvb_get_guint8(tvb, voff+4);
633 proto_tree_add_text(v_tree, tvb, voff+4, 1,
634 "Replay Detection Method: %s (%u)",
635 val_to_str(rdm, authen_rdm_vals, "Unknown"),
640 case AUTHEN_RDM_MONOTONIC_COUNTER:
641 proto_tree_add_text(v_tree, tvb, voff+5, 8,
642 "Replay Detection Value: %s",
643 u64toh(tvb_get_ptr(tvb, voff+5, 8)));
647 proto_tree_add_text(v_tree, tvb, voff+5, 8,
648 "Replay Detection Value: %s",
649 tvb_bytes_to_str(tvb, voff+5, 8));
655 case AUTHEN_PROTO_DELAYED_AUTHEN:
658 case AUTHEN_DELAYED_ALGO_HMAC_MD5:
659 proto_tree_add_text(v_tree, tvb, voff+13, 4,
661 tvb_get_ntohl(tvb, voff+13));
662 proto_tree_add_text(v_tree, tvb, voff+17, 16,
664 tvb_bytes_to_str(tvb, voff+17, 16));
668 proto_tree_add_text(v_tree, tvb, voff+13, vlen-11,
669 "Authentication Information: %s",
670 tvb_bytes_to_str(tvb, voff+17, vlen-11));
676 proto_tree_add_text(v_tree, tvb, voff+13, vlen-11,
677 "Authentication Information: %s",
678 tvb_bytes_to_str(tvb, voff+17, vlen-11));
683 default: /* not special */
688 if (code < NUM_OPT_INFOS) {
689 text = opt[code].text;
690 ftype = opt[code].ftype;
700 proto_tree_add_text(bp_tree, tvb, voff, consumed,
701 "Option %d: %s = %s", code, text,
702 ip_to_str(tvb_get_ptr(tvb, voff+2, 4)));
704 /* > 1 IP addresses. Let's make a sub-tree */
705 vti = proto_tree_add_text(bp_tree, tvb, voff,
706 consumed, "Option %d: %s", code, text);
707 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
708 for (i = voff + 2; i < voff + consumed; i += 4) {
709 proto_tree_add_text(v_tree, tvb, i, 4, "IP Address: %s",
710 ip_to_str(tvb_get_ptr(tvb, i, 4)));
716 /* Fix for non null-terminated string supplied by
717 * John Lines <John.Lines@aeat.co.uk>
719 proto_tree_add_text(bp_tree, tvb, voff, consumed,
720 "Option %d: %s = \"%.*s\"", code, text, vlen,
721 tvb_get_ptr(tvb, voff+2, consumed-2));
725 proto_tree_add_text(bp_tree, tvb, voff, consumed,
726 "Option %d: %s (%d bytes)",
733 proto_tree_add_text(bp_tree, tvb, voff, consumed,
734 "Option %d: %s = %d", code, text,
735 tvb_get_ntohs(tvb, voff+2));
738 vti = proto_tree_add_text(bp_tree, tvb, voff,
739 consumed, "Option %d: %s", code, text);
740 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
741 for (i = voff + 2; i < voff + consumed; i += 2) {
742 proto_tree_add_text(v_tree, tvb, i, 4, "Value: %d",
743 tvb_get_ntohs(tvb, i));
749 proto_tree_add_text(bp_tree, tvb, voff, consumed,
750 "Option %d: %s = %d", code, text,
751 tvb_get_ntohl(tvb, voff+2));
755 proto_tree_add_text(bp_tree, tvb, voff, consumed,
756 "Option %d: %s = %d", code, text,
757 tvb_get_guint8(tvb, voff+2));
761 i = tvb_get_guint8(tvb, voff+2);
762 if (i != 0 && i != 1) {
763 proto_tree_add_text(bp_tree, tvb, voff, consumed,
764 "Option %d: %s = Invalid Value %d", code, text,
767 proto_tree_add_text(bp_tree, tvb, voff, consumed,
768 "Option %d: %s = %s", code, text,
769 i == 0 ? "Disabled" : "Enabled");
774 i = tvb_get_guint8(tvb, voff+2);
775 if (i != 0 && i != 1) {
776 proto_tree_add_text(bp_tree, tvb, voff, consumed,
777 "Option %d: %s = Invalid Value %d", code, text,
780 proto_tree_add_text(bp_tree, tvb, voff, consumed,
781 "Option %d: %s = %s", code, text,
782 i == 0 ? "No" : "Yes");
787 time_secs = tvb_get_ntohl(tvb, voff+2);
788 proto_tree_add_text(bp_tree, tvb, voff, consumed,
789 "Option %d: %s = %s", code, text,
790 ((time_secs == 0xffffffff) ?
792 time_secs_to_str(time_secs)));
796 proto_tree_add_text(bp_tree, tvb, voff, consumed,
797 "Option %d: %s (%d bytes)", code, text, vlen);
800 proto_tree_add_text(bp_tree, tvb, voff, consumed,
801 "Unknown Option Code: %d (%d bytes)", code, vlen);
808 bootp_dhcp_decode_agent_info(proto_tree *v_tree, tvbuff_t *tvb, int optp)
813 subopt = tvb_get_guint8(tvb, optp);
814 subopt_len = tvb_get_guint8(tvb, optp+1);
817 proto_tree_add_text(v_tree, tvb, optp, subopt_len + 2,
818 "Agent Circuit ID (%d bytes)", subopt_len);
821 proto_tree_add_text(v_tree, tvb, optp, subopt_len + 2,
822 "Agent Remote ID (%d bytes)", subopt_len);
825 proto_tree_add_text(v_tree, tvb, optp, subopt_len + 2,
826 "Unknown agent option: %d", subopt);
829 optp += (subopt_len + 2);
834 dissect_vendor_pxeclient_suboption(proto_tree *v_tree, tvbuff_t *tvb, int optp)
839 proto_tree *o43pxeclient_v_tree;
842 struct o43pxeclient_opt_info {
847 static struct o43pxeclient_opt_info o43pxeclient_opt[]= {
848 /* 0 */ {"nop", special}, /* dummy */
849 /* 1 */ {"PXE mtftp IP", ipv4},
850 /* 2 */ {"PXE mtftp client port", val_u_le_short},
851 /* 3 */ {"PXE mtftp server port",val_u_le_short},
852 /* 4 */ {"PXE mtftp timeout", val_u_byte},
853 /* 5 */ {"PXE mtftp delay", val_u_byte},
854 /* 6 */ {"PXE discovery control", val_u_byte},
856 * Correct: b0 (lsb): disable broadcast discovery
857 * b1: disable multicast discovery
858 * b2: only use/accept servers in boot servers
859 * b3: download bootfile without prompt/menu/disc
861 /* 7 */ {"PXE multicast address", ipv4},
862 /* 8 */ {"PXE boot servers", special},
863 /* 9 */ {"PXE boot menu", special},
864 /* 10 */ {"PXE menu prompt", special},
865 /* 11 */ {"PXE multicast address alloc", special},
866 /* 12 */ {"PXE credential types", special},
867 /* 71 {"PXE boot item", special} */
868 /* 255 {"PXE end options", special} */
870 #define NUM_O43PXECLIENT_SUBOPTS (12)
872 subopt = tvb_get_guint8(tvb, optp);
875 proto_tree_add_text(v_tree, tvb, optp, 1, "Padding");
877 } else if (subopt == 255) { /* End Option */
878 proto_tree_add_text(v_tree, tvb, optp, 1, "End PXEClient option");
879 /* Make sure we skip any junk left this option */
883 subopt_len = tvb_get_guint8(tvb, optp+1);
885 if ( subopt == 71 ) { /* 71 {"PXE boot item", special} */
887 /* I may need to decode that properly one day */
888 proto_tree_add_text(v_tree, tvb, optp, subopt_len+2,
889 "Suboption %d: %s (%d byte%s)" ,
890 subopt, "PXE boot item",
891 subopt_len, (subopt_len != 1)?"s":"");
892 } else if ( (subopt < 1 ) || (subopt > NUM_O43PXECLIENT_SUBOPTS) ) {
893 proto_tree_add_text(v_tree, tvb, optp, subopt_len+2,
894 "Unknown suboption %d (%d byte%s)", subopt, subopt_len,
895 (subopt_len != 1)?"s":"");
897 switch (o43pxeclient_opt[subopt].ft) {
900 proto_tree_add_text(v_tree, tvb, optp, subopt_len+2,
901 "Suboption %d: %s", subopt, o43pxeclient_opt[subopt].text);
905 /* I may need to decode that properly one day */
906 proto_tree_add_text(v_tree, tvb, optp, subopt_len+2,
907 "Suboption %d: %s (%d byte%s)" ,
908 subopt, o43pxeclient_opt[subopt].text,
909 subopt_len, (subopt_len != 1)?"s":"");
913 proto_tree_add_text(v_tree, tvb, optp, 4, "Suboption %d: %s = %u",
914 subopt, o43pxeclient_opt[subopt].text,
915 tvb_get_letohs(tvb, optp+2));
919 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s = %u",
920 subopt, o43pxeclient_opt[subopt].text,
921 tvb_get_guint8(tvb, optp+2));
925 if (subopt_len == 4) {
927 proto_tree_add_text(v_tree, tvb, optp, 6,
928 "Suboption %d : %s = %s",
929 subopt, o43pxeclient_opt[subopt].text,
930 ip_to_str(tvb_get_ptr(tvb, optp+2, 4)));
932 /* > 1 IP addresses. Let's make a sub-tree */
933 vti = proto_tree_add_text(v_tree, tvb, optp,
934 subopt_len+2, "Suboption %d: %s",
935 subopt, o43pxeclient_opt[subopt].text);
936 o43pxeclient_v_tree = proto_item_add_subtree(vti, ett_bootp_option);
937 for (slask = optp + 2 ; slask < optp+subopt_len; slask += 4) {
938 proto_tree_add_text(o43pxeclient_v_tree, tvb, slask, 4, "IP Address: %s",
939 ip_to_str(tvb_get_ptr(tvb, slask, 4)));
944 proto_tree_add_text(v_tree, tvb, optp, subopt_len+2,"ERROR, please report: Unknown subopt type handler %d", subopt);
948 optp += (subopt_len + 2);
953 dissect_netware_ip_suboption(proto_tree *v_tree, tvbuff_t *tvb, int optp)
958 proto_tree *o63_v_tree;
961 struct o63_opt_info {
967 static struct o63_opt_info o63_opt[]= {
968 /* 0 */ {"","",none},
969 /* 1 */ {"NWIP does not exist on subnet","",string},
970 /* 2 */ {"NWIP exist in options area","",string},
971 /* 3 */ {"NWIP exists in sname/file","",string},
972 /* 4 */ {"NWIP exists, but too big","",string},
973 /* 5 */ {"Broadcast for nearest Netware server","Do NOT Broadcast for nearest Netware server",yes_no},
974 /* 6 */ {"Preferred DSS server","",ipv4},
975 /* 7 */ {"Nearest NWIP server","",ipv4},
976 /* 8 */ {"Autoretries","",val_u_short},
977 /* 9 */ {"Autoretry delay, secs ","",val_u_short},
978 /* 10*/ {"Support NetWare/IP v1.1","Do NOT support NetWare/IP v1.1",yes_no},
979 /* 11*/ {"Primary DSS ", "" , special}
982 subopt = tvb_get_guint8(tvb, optp);
983 if (subopt > NUM_O63_SUBOPTS) {
984 proto_tree_add_text(v_tree, tvb,optp,1,"Unknown suboption %d", subopt);
987 switch (o63_opt[subopt].ft) {
990 proto_tree_add_text(v_tree, tvb, optp, 2, "Suboption %d: %s", subopt, o63_opt[subopt].truet);
995 if (tvb_get_guint8(tvb, optp+2)==1) {
996 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s", subopt, o63_opt[subopt].truet);
998 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s" , subopt, o63_opt[subopt].falset);
1004 proto_tree_add_text(v_tree, tvb, optp, 6,
1005 "Suboption %d: %s = %s" ,
1006 subopt, o63_opt[subopt].truet,
1007 ip_to_str(tvb_get_ptr(tvb, optp+2, 4)));
1012 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s = %u",
1013 subopt, o63_opt[subopt].truet,
1014 tvb_get_guint8(tvb, optp+2)); /* XXX - 1 byte? */
1019 subopt_len = tvb_get_guint8(tvb, optp+1);
1020 if (subopt_len == 4) {
1021 /* one IP address */
1022 proto_tree_add_text(v_tree, tvb, optp, 6,
1023 "Suboption %d : %s = %s",
1024 subopt, o63_opt[subopt].truet,
1025 ip_to_str(tvb_get_ptr(tvb, optp+2, 4)));
1028 /* > 1 IP addresses. Let's make a sub-tree */
1029 vti = proto_tree_add_text(v_tree, tvb, optp,
1030 subopt_len+2, "Suboption %d: %s",
1031 subopt, o63_opt[subopt].truet);
1032 o63_v_tree = proto_item_add_subtree(vti, ett_bootp_option);
1033 for (slask = optp + 2 ; slask < optp+subopt_len; slask += 4) {
1034 proto_tree_add_text(o63_v_tree, tvb, slask, 4, "IP Address: %s",
1035 ip_to_str(tvb_get_ptr(tvb, slask, 4)));
1041 proto_tree_add_text(v_tree, tvb,optp,1,"Unknown suboption %d", subopt);
1049 #define BOOTREQUEST 1
1052 static const value_string op_vals[] = {
1053 { BOOTREQUEST, "Boot Request" },
1054 { BOOTREPLY, "Boot Reply" },
1059 dissect_bootp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
1061 proto_tree *bp_tree = NULL;
1065 const guint8 *haddr;
1066 int voff, eoff, tmpvoff; /* vendor offset, end offset */
1068 const char *dhcp_type = NULL;
1069 const guint8 *vendor_class_id = NULL;
1071 if (check_col(pinfo->fd, COL_PROTOCOL))
1072 col_set_str(pinfo->fd, COL_PROTOCOL, "BOOTP");
1073 if (check_col(pinfo->fd, COL_INFO)) {
1075 * In case we throw an exception fetching the opcode, etc.
1077 col_clear(pinfo->fd, COL_INFO);
1080 op = tvb_get_guint8(tvb, 0);
1081 htype = tvb_get_guint8(tvb, 1);
1082 hlen = tvb_get_guint8(tvb, 2);
1083 if (check_col(pinfo->fd, COL_INFO)) {
1087 col_add_fstr(pinfo->fd, COL_INFO, "Boot Request from %s",
1088 arphrdaddr_to_str(tvb_get_ptr(tvb, 28, hlen),
1093 col_set_str(pinfo->fd, COL_INFO, "Boot Reply");
1097 col_add_fstr(pinfo->fd, COL_INFO, "Unknown BOOTP message type (%u)",
1104 ti = proto_tree_add_item(tree, proto_bootp, tvb, 0,
1105 tvb_length(tvb), FALSE);
1106 bp_tree = proto_item_add_subtree(ti, ett_bootp);
1108 proto_tree_add_uint(bp_tree, hf_bootp_type, tvb,
1111 proto_tree_add_uint_format(bp_tree, hf_bootp_hw_type, tvb,
1114 "Hardware type: %s",
1115 arphrdtype_to_str(htype,
1116 "Unknown (0x%02x)"));
1117 proto_tree_add_uint(bp_tree, hf_bootp_hw_len, tvb,
1119 proto_tree_add_item(bp_tree, hf_bootp_hops, tvb,
1121 proto_tree_add_item(bp_tree, hf_bootp_id, tvb,
1123 proto_tree_add_item(bp_tree, hf_bootp_secs, tvb,
1125 proto_tree_add_uint(bp_tree, hf_bootp_flag, tvb,
1126 10, 2, tvb_get_ntohs(tvb, 10) & 0x8000);
1128 proto_tree_add_item(bp_tree, hf_bootp_ip_client, tvb,
1130 proto_tree_add_item(bp_tree, hf_bootp_ip_your, tvb,
1132 proto_tree_add_item(bp_tree, hf_bootp_ip_server, tvb,
1134 proto_tree_add_item(bp_tree, hf_bootp_ip_relay, tvb,
1138 haddr = tvb_get_ptr(tvb, 28, hlen);
1139 proto_tree_add_bytes_format(bp_tree, hf_bootp_hw_addr, tvb,
1142 "Client hardware address: %s",
1143 arphrdaddr_to_str(haddr,
1148 proto_tree_add_text(bp_tree, tvb,
1149 28, 0, "Client address not given");
1152 /* The server host name is optional */
1153 if (tvb_get_guint8(tvb, 44) != '\0') {
1154 proto_tree_add_item(bp_tree, hf_bootp_server, tvb,
1158 proto_tree_add_string_format(bp_tree, hf_bootp_server, tvb,
1160 tvb_get_ptr(tvb, 44, 1),
1161 "Server host name not given");
1165 if (tvb_get_guint8(tvb, 108) != '\0') {
1166 proto_tree_add_item(bp_tree, hf_bootp_file, tvb,
1170 proto_tree_add_string_format(bp_tree, hf_bootp_file, tvb,
1172 tvb_get_ptr(tvb, 108, 1),
1173 "Boot file name not given");
1176 tvb_memcpy(tvb, (void *)&ip_addr, 236, sizeof(ip_addr));
1177 if (tvb_get_ntohl(tvb, 236) == 0x63825363) {
1178 proto_tree_add_ipv4_format(bp_tree, hf_bootp_cookie, tvb,
1180 "Magic cookie: (OK)");
1183 proto_tree_add_ipv4(bp_tree, hf_bootp_cookie, tvb,
1189 eoff = tvb_reported_length(tvb);
1192 * In the first pass, we just look for the DHCP message type
1193 * and Vendor class identifier options.
1196 while (tmpvoff < eoff) {
1197 tmpvoff += bootp_option(tvb, 0, tmpvoff, eoff, TRUE,
1198 &dhcp_type, &vendor_class_id);
1202 * If there was a DHCP message type option, flag this packet
1205 if (dhcp_type != NULL) {
1207 * Yes, this is a DHCP packet, and "dhcp_type" is the
1210 if (check_col(pinfo->fd, COL_PROTOCOL))
1211 col_set_str(pinfo->fd, COL_PROTOCOL, "DHCP");
1212 if (check_col(pinfo->fd, COL_INFO))
1213 col_add_fstr(pinfo->fd, COL_INFO, "DHCP %-8s - Transaction ID 0x%x",
1214 dhcp_type, tvb_get_ntohl(tvb, 4));
1216 proto_tree_add_boolean_hidden(bp_tree, hf_bootp_dhcp,
1221 * If we're not building the protocol tree, we don't need to
1222 * make a second pass.
1228 * OK, now build the protocol tree.
1230 while (voff < eoff) {
1231 voff += bootp_option(tvb, bp_tree, voff, eoff, FALSE,
1232 &dhcp_type, &vendor_class_id);
1237 proto_register_bootp(void)
1239 static hf_register_info hf[] = {
1241 { "Frame is DHCP", "bootp.dhcp", FT_BOOLEAN,
1242 BASE_NONE, NULL, 0x0,
1246 { "Message type", "bootp.type", FT_UINT8,
1247 BASE_DEC, VALS(op_vals), 0x0,
1250 { &hf_bootp_hw_type,
1251 { "Hardware type", "bootp.hw.type", FT_UINT8,
1252 BASE_HEX, NULL, 0x0,
1256 { "Hardware address length", "bootp.hw.len", FT_UINT8,
1257 BASE_DEC, NULL, 0x0,
1261 { "Hops", "bootp.hops", FT_UINT8,
1262 BASE_DEC, NULL, 0x0,
1266 { "Transaction ID", "bootp.id", FT_UINT32,
1267 BASE_HEX, NULL, 0x0,
1271 { "Seconds elapsed", "bootp.secs", FT_UINT16,
1272 BASE_DEC, NULL, 0x0,
1276 { "Broadcast flag", "bootp.flag", FT_UINT16,
1277 BASE_HEX, NULL, 0x0,
1280 { &hf_bootp_ip_client,
1281 { "Client IP address", "bootp.ip.client",FT_IPv4,
1282 BASE_NONE, NULL, 0x0,
1285 { &hf_bootp_ip_your,
1286 { "Your (client) IP address", "bootp.ip.your", FT_IPv4,
1287 BASE_NONE, NULL, 0x0,
1290 { &hf_bootp_ip_server,
1291 { "Next server IP address", "bootp.ip.server",FT_IPv4,
1292 BASE_NONE, NULL, 0x0,
1295 { &hf_bootp_ip_relay,
1296 { "Relay agent IP address", "bootp.ip.relay", FT_IPv4,
1297 BASE_NONE, NULL, 0x0,
1300 { &hf_bootp_hw_addr,
1301 { "Client hardware address", "bootp.hw.addr", FT_BYTES,
1302 BASE_NONE, NULL, 0x0,
1306 { "Server host name", "bootp.server", FT_STRING,
1307 BASE_NONE, NULL, 0x0,
1311 { "Boot file name", "bootp.file", FT_STRING,
1312 BASE_NONE, NULL, 0x0,
1316 { "Magic cookie", "bootp.cookie", FT_IPv4,
1317 BASE_NONE, NULL, 0x0,
1320 static gint *ett[] = {
1325 proto_bootp = proto_register_protocol("Bootstrap Protocol", "BOOTP/DHCP",
1327 proto_register_field_array(proto_bootp, hf, array_length(hf));
1328 proto_register_subtree_array(ett, array_length(ett));
1332 proto_reg_handoff_bootp(void)
1334 dissector_handle_t bootp_handle;
1336 bootp_handle = create_dissector_handle(dissect_bootp, proto_bootp);
1337 dissector_add("udp.port", UDP_PORT_BOOTPS, bootp_handle);