2 * Routines for BOOTP/DHCP packet disassembly
3 * Gilbert Ramirez <gram@xiexie.org>
5 * $Id: packet-bootp.c,v 1.54 2001/06/18 02:17:45 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 * BOOTP and DHCP Parameters
15 * http://www.isi.edu/in-notes/iana/assignments/bootp-dhcp-parameters
17 * Ethereal - Network traffic analyzer
18 * By Gerald Combs <gerald@zing.org>
19 * 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>
48 #include "packet-arp.h"
50 static int proto_bootp = -1;
51 static int hf_bootp_type = -1;
52 static int hf_bootp_hw_type = -1;
53 static int hf_bootp_hw_len = -1;
54 static int hf_bootp_hops = -1;
55 static int hf_bootp_id = -1;
56 static int hf_bootp_secs = -1;
57 static int hf_bootp_flag = -1;
58 static int hf_bootp_ip_client = -1;
59 static int hf_bootp_ip_your = -1;
60 static int hf_bootp_ip_server = -1;
61 static int hf_bootp_ip_relay = -1;
62 static int hf_bootp_hw_addr = -1;
63 static int hf_bootp_server = -1;
64 static int hf_bootp_file = -1;
65 static int hf_bootp_cookie = -1;
66 static int hf_bootp_dhcp = -1;
68 static guint ett_bootp = -1;
69 static guint ett_bootp_option = -1;
71 #define UDP_PORT_BOOTPS 67
73 enum field_type { none, ipv4, string, toggle, yes_no, special, opaque,
75 val_u_byte, val_u_short, val_u_le_short, val_u_long,
80 enum field_type ftype;
83 #define NUM_OPT_INFOS 211
84 #define NUM_O63_SUBOPTS 11
86 static int dissect_vendor_pxeclient_suboption(proto_tree *v_tree, tvbuff_t *tvb,
88 static int dissect_netware_ip_suboption(proto_tree *v_tree, tvbuff_t *tvb,
90 static int bootp_dhcp_decode_agent_info(proto_tree *v_tree, tvbuff_t *tvb,
94 get_dhcp_type(guint8 byte)
96 static const char *opt53_text[] = {
97 "Unknown Message Type",
109 if (byte > 0 && byte < (sizeof opt53_text / sizeof opt53_text[0]))
113 return opt53_text[i];
116 /* Returns the number of bytes consumed by this option. */
118 bootp_option(tvbuff_t *tvb, proto_tree *bp_tree, int voff, int eoff,
119 gboolean first_pass, const char **dhcp_type_p,
120 const guint8 **vendor_class_id_p)
123 enum field_type ftype;
124 u_char code = tvb_get_guint8(tvb, voff);
127 int i,optp, consumed;
134 static const value_string nbnt_vals[] = {
141 static struct opt_info opt[] = {
142 /* 0 */ { "Padding", none },
143 /* 1 */ { "Subnet Mask", ipv4 },
144 /* 2 */ { "Time Offset", val_s_long },
145 /* 3 */ { "Router", ipv4 },
146 /* 4 */ { "Time Server", ipv4 },
147 /* 5 */ { "Name Server", ipv4 },
148 /* 6 */ { "Domain Name Server", ipv4 },
149 /* 7 */ { "Log Server", ipv4 },
150 /* 8 */ { "Cookie Server", ipv4 },
151 /* 9 */ { "LPR Server", ipv4 },
152 /* 10 */ { "Impress Server", ipv4 },
153 /* 11 */ { "Resource Location Server", ipv4 },
154 /* 12 */ { "Host Name", string },
155 /* 13 */ { "Boot File Size", val_u_short },
156 /* 14 */ { "Merit Dump File", string },
157 /* 15 */ { "Domain Name", string },
158 /* 16 */ { "Swap Server", ipv4 },
159 /* 17 */ { "Root Path", string },
160 /* 18 */ { "Extensions Path", string },
161 /* 19 */ { "IP Forwarding", toggle },
162 /* 20 */ { "Non-Local Source Routing", toggle },
163 /* 21 */ { "Policy Filter", special },
164 /* 22 */ { "Maximum Datagram Reassembly Size", val_u_short },
165 /* 23 */ { "Default IP Time-to-Live", val_u_byte },
166 /* 24 */ { "Path MTU Aging Timeout", time_in_secs },
167 /* 25 */ { "Path MTU Plateau Table", val_u_short },
168 /* 26 */ { "Interface MTU", val_u_short },
169 /* 27 */ { "All Subnets are Local", yes_no },
170 /* 28 */ { "Broadcast Address", ipv4 },
171 /* 29 */ { "Perform Mask Discovery", toggle },
172 /* 30 */ { "Mask Supplier", yes_no },
173 /* 31 */ { "Perform Router Discover", toggle },
174 /* 32 */ { "Router Solicitation Address", ipv4 },
175 /* 33 */ { "Static Route", special },
176 /* 34 */ { "Trailer Encapsulation", toggle },
177 /* 35 */ { "ARP Cache Timeout", time_in_secs },
178 /* 36 */ { "Ethernet Encapsulation", toggle },
179 /* 37 */ { "TCP Default TTL", val_u_byte },
180 /* 38 */ { "TCP Keepalive Interval", time_in_secs },
181 /* 39 */ { "TCP Keepalive Garbage", toggle },
182 /* 40 */ { "Network Information Service Domain", string },
183 /* 41 */ { "Network Information Service Servers", ipv4 },
184 /* 42 */ { "Network Time Protocol Servers", ipv4 },
185 /* 43 */ { "Vendor-Specific Information", special },
186 /* 44 */ { "NetBIOS over TCP/IP Name Server", ipv4 },
187 /* 45 */ { "NetBIOS over TCP/IP Datagram Distribution Name Server", ipv4 },
188 /* 46 */ { "NetBIOS over TCP/IP Node Type", special },
189 /* 47 */ { "NetBIOS over TCP/IP Scope", string },
190 /* 48 */ { "X Window System Font Server", ipv4 },
191 /* 49 */ { "X Window System Display Manager", ipv4 },
192 /* 50 */ { "Requested IP Address", ipv4 },
193 /* 51 */ { "IP Address Lease Time", time_in_secs },
194 /* 52 */ { "Option Overload", special },
195 /* 53 */ { "DHCP Message Type", special },
196 /* 54 */ { "Server Identifier", ipv4 },
197 /* 55 */ { "Parameter Request List", special },
198 /* 56 */ { "Message", string },
199 /* 57 */ { "Maximum DHCP Message Size", val_u_short },
200 /* 58 */ { "Renewal Time Value", time_in_secs },
201 /* 59 */ { "Rebinding Time Value", time_in_secs },
202 /* 60 */ { "Vendor class identifier", special },
203 /* 61 */ { "Client identifier", special },
204 /* 62 */ { "Novell/Netware IP domain", string },
205 /* 63 */ { "Novell Options", special },
206 /* 64 */ { "Network Information Service+ Domain", string },
207 /* 65 */ { "Network Information Service+ Servers", ipv4 },
208 /* 66 */ { "TFTP Server Name", string },
209 /* 67 */ { "Bootfile name", string },
210 /* 68 */ { "Mobile IP Home Agent", ipv4 },
211 /* 69 */ { "SMTP Server", ipv4 },
212 /* 70 */ { "POP3 Server", ipv4 },
213 /* 71 */ { "NNTP Server", ipv4 },
214 /* 72 */ { "Default WWW Server", ipv4 },
215 /* 73 */ { "Default Finger Server", ipv4 },
216 /* 74 */ { "Default IRC Server", ipv4 },
217 /* 75 */ { "StreetTalk Server", ipv4 },
218 /* 76 */ { "StreetTalk Directory Assistance Server", ipv4 },
219 /* 77 */ { "User Class Information", opaque },
220 /* 78 */ { "Directory Agent Information", opaque },
221 /* 79 */ { "Service Location Agent Scope", opaque },
222 /* 80 */ { "Naming Authority", opaque },
223 /* 81 */ { "Client Fully Qualified Domain Name", opaque },
224 /* 82 */ { "Agent Information Option", special },
225 /* 83 */ { "Unassigned", opaque },
226 /* 84 */ { "Unassigned", opaque },
227 /* 85 */ { "Novell Directory Services Servers", opaque },
228 /* 86 */ { "Novell Directory Services Tree Name", opaque },
229 /* 87 */ { "Novell Directory Services Context", opaque },
230 /* 88 */ { "IEEE 1003.1 POSIX Timezone", opaque },
231 /* 89 */ { "Fully Qualified Domain Name", opaque },
232 /* 90 */ { "Authentication", opaque },
233 /* 91 */ { "Vines TCP/IP Server Option", opaque },
234 /* 92 */ { "Server Selection Option", opaque },
235 /* 93 */ { "Client System Architecture", opaque },
236 /* 94 */ { "Client Network Device Interface", opaque },
237 /* 95 */ { "Lightweight Directory Access Protocol", opaque },
238 /* 96 */ { "IPv6 Transitions", opaque },
239 /* 97 */ { "UUID/GUID-based Client Identifier", opaque },
240 /* 98 */ { "Open Group's User Authentication", opaque },
241 /* 99 */ { "Unassigned", opaque },
242 /* 100 */ { "Printer Name", opaque },
243 /* 101 */ { "MDHCP multicast address", opaque },
244 /* 102 */ { "Removed/unassigned", opaque },
245 /* 103 */ { "Removed/unassigned", opaque },
246 /* 104 */ { "Removed/unassigned", opaque },
247 /* 105 */ { "Removed/unassigned", opaque },
248 /* 106 */ { "Removed/unassigned", opaque },
249 /* 107 */ { "Removed/unassigned", opaque },
250 /* 108 */ { "Swap Path Option", opaque },
251 /* 109 */ { "Unassigned", opaque },
252 /* 110 */ { "IPX Compability", opaque },
253 /* 111 */ { "Unassigned", opaque },
254 /* 112 */ { "Netinfo Parent Server Address", opaque },
255 /* 113 */ { "Netinfo Parent Server Tag", opaque },
256 /* 114 */ { "URL", opaque },
257 /* 115 */ { "DHCP Failover Protocol", opaque },
258 /* 116 */ { "DHCP Auto-Configuration", opaque },
259 /* 117 */ { "Unassigned", opaque },
260 /* 118 */ { "Unassigned", opaque },
261 /* 119 */ { "Unassigned", opaque },
262 /* 120 */ { "Unassigned", opaque },
263 /* 121 */ { "Unassigned", opaque },
264 /* 122 */ { "Unassigned", opaque },
265 /* 123 */ { "Unassigned", opaque },
266 /* 124 */ { "Unassigned", opaque },
267 /* 125 */ { "Unassigned", opaque },
268 /* 126 */ { "Extension", opaque },
269 /* 127 */ { "Extension", opaque },
270 /* 128 */ { "Private", opaque },
271 /* 129 */ { "Private", opaque },
272 /* 130 */ { "Private", opaque },
273 /* 131 */ { "Private", opaque },
274 /* 132 */ { "Private", opaque },
275 /* 133 */ { "Private", opaque },
276 /* 134 */ { "Private", opaque },
277 /* 135 */ { "Private", opaque },
278 /* 136 */ { "Private", opaque },
279 /* 137 */ { "Private", opaque },
280 /* 138 */ { "Private", opaque },
281 /* 139 */ { "Private", opaque },
282 /* 140 */ { "Private", opaque },
283 /* 141 */ { "Private", opaque },
284 /* 142 */ { "Private", opaque },
285 /* 143 */ { "Private", opaque },
286 /* 144 */ { "Private", opaque },
287 /* 145 */ { "Private", opaque },
288 /* 146 */ { "Private", opaque },
289 /* 147 */ { "Private", opaque },
290 /* 148 */ { "Private", opaque },
291 /* 149 */ { "Private", opaque },
292 /* 150 */ { "Private", opaque },
293 /* 151 */ { "Private", opaque },
294 /* 152 */ { "Private", opaque },
295 /* 153 */ { "Private", opaque },
296 /* 154 */ { "Private", opaque },
297 /* 155 */ { "Private", opaque },
298 /* 156 */ { "Private", opaque },
299 /* 157 */ { "Private", opaque },
300 /* 158 */ { "Private", opaque },
301 /* 159 */ { "Private", opaque },
302 /* 160 */ { "Private", opaque },
303 /* 161 */ { "Private", opaque },
304 /* 162 */ { "Private", opaque },
305 /* 163 */ { "Private", opaque },
306 /* 164 */ { "Private", opaque },
307 /* 165 */ { "Private", opaque },
308 /* 166 */ { "Private", opaque },
309 /* 167 */ { "Private", opaque },
310 /* 168 */ { "Private", opaque },
311 /* 169 */ { "Private", opaque },
312 /* 170 */ { "Private", opaque },
313 /* 171 */ { "Private", opaque },
314 /* 172 */ { "Private", opaque },
315 /* 173 */ { "Private", opaque },
316 /* 174 */ { "Private", opaque },
317 /* 175 */ { "Private", opaque },
318 /* 176 */ { "Private", opaque },
319 /* 177 */ { "Private", opaque },
320 /* 178 */ { "Private", opaque },
321 /* 179 */ { "Private", opaque },
322 /* 180 */ { "Private", opaque },
323 /* 181 */ { "Private", opaque },
324 /* 182 */ { "Private", opaque },
325 /* 183 */ { "Private", opaque },
326 /* 184 */ { "Private", opaque },
327 /* 185 */ { "Private", opaque },
328 /* 186 */ { "Private", opaque },
329 /* 187 */ { "Private", opaque },
330 /* 188 */ { "Private", opaque },
331 /* 189 */ { "Private", opaque },
332 /* 190 */ { "Private", opaque },
333 /* 191 */ { "Private", opaque },
334 /* 192 */ { "Private", opaque },
335 /* 193 */ { "Private", opaque },
336 /* 194 */ { "Private", opaque },
337 /* 195 */ { "Private", opaque },
338 /* 196 */ { "Private", opaque },
339 /* 197 */ { "Private", opaque },
340 /* 198 */ { "Private", opaque },
341 /* 199 */ { "Private", opaque },
342 /* 200 */ { "Private", opaque },
343 /* 201 */ { "Private", opaque },
344 /* 202 */ { "Private", opaque },
345 /* 203 */ { "Private", opaque },
346 /* 204 */ { "Private", opaque },
347 /* 205 */ { "Private", opaque },
348 /* 206 */ { "Private", opaque },
349 /* 207 */ { "Private", opaque },
350 /* 208 */ { "Private", opaque },
351 /* 209 */ { "Private", opaque },
352 /* 210 */ { "Authentication", special }
355 /* Options whose length isn't "vlen + 2". */
358 case 0: /* Padding */
359 /* check how much padding we have */
360 for (i = voff + 1; i < eoff; i++ ) {
361 if (tvb_get_guint8(tvb, i) != 0) {
367 if (bp_tree != NULL) {
368 proto_tree_add_text(bp_tree, tvb, voff, i,
376 case 255: /* End Option */
378 if (bp_tree != NULL) {
379 proto_tree_add_text(bp_tree, tvb, voff, 1,
388 * Get the length of the option, and the number of bytes it
389 * consumes (the length doesn't include the option code or
392 vlen = tvb_get_guint8(tvb, voff+1);
396 * In the first pass, we don't put anything into the protocol
397 * tree; we just check for some options we have to look at
398 * in order to properly process the packet:
400 * 53 (DHCP message type) - if this is present, this is DHCP
402 * 60 (Vendor class identifier) - we need this in order to
403 * interpret the vendor-specific info
410 get_dhcp_type(tvb_get_guint8(tvb, voff+2));
415 tvb_get_ptr(tvb, voff+2, consumed-2);
420 * We don't do anything else here.
426 * This is the second pass - if there's a protocol tree to be
427 * built, we put stuff into it, otherwise we just return.
429 if (bp_tree == NULL) {
430 /* Don't put anything in the protocol tree. */
434 text = opt[code].text;
438 case 21: /* Policy Filter */
440 /* one IP address pair */
441 proto_tree_add_text(bp_tree, tvb, voff, consumed,
442 "Option %d: %s = %s/%s", code, text,
443 ip_to_str(tvb_get_ptr(tvb, voff+2, 4)),
444 ip_to_str(tvb_get_ptr(tvb, voff+6, 4)));
446 /* > 1 IP address pair. Let's make a sub-tree */
447 vti = proto_tree_add_text(bp_tree, tvb, voff,
448 consumed, "Option %d: %s", code, text);
449 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
450 for (i = voff + 2; i < voff + consumed; i += 8) {
451 proto_tree_add_text(v_tree, tvb, i, 8, "IP Address/Mask: %s/%s",
452 ip_to_str(tvb_get_ptr(tvb, i, 4)),
453 ip_to_str(tvb_get_ptr(tvb, i+4, 4)));
458 case 33: /* Static Route */
460 /* one IP address pair */
461 proto_tree_add_text(bp_tree, tvb, voff, consumed,
462 "Option %d: %s = %s/%s", code, text,
463 ip_to_str(tvb_get_ptr(tvb, voff+2, 4)),
464 ip_to_str(tvb_get_ptr(tvb, voff+6, 4)));
466 /* > 1 IP address pair. Let's make a sub-tree */
467 vti = proto_tree_add_text(bp_tree, tvb, voff,
468 consumed, "Option %d: %s", code, text);
469 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
470 for (i = voff + 2; i < voff + consumed; i += 8) {
471 proto_tree_add_text(v_tree, tvb, i, 8,
472 "Destination IP Address/Router: %s/%s",
473 ip_to_str(tvb_get_ptr(tvb, i, 4)),
474 ip_to_str(tvb_get_ptr(tvb, i+4, 4)));
479 case 43: /* Vendor-Specific Info */
480 /* PXE protocol 2.1 as described in the intel specs */
481 if (*vendor_class_id_p != NULL &&
482 strncmp(*vendor_class_id_p, "PXEClient", strlen("PXEClient")) == 0) {
483 vti = proto_tree_add_text(bp_tree, tvb, voff,
484 consumed, "Option %d: %s (PXEClient)", code, text);
485 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
488 while (optp < voff+consumed) {
489 optp = dissect_vendor_pxeclient_suboption(v_tree,
493 proto_tree_add_text(bp_tree, tvb, voff, consumed,
494 "Option %d: %s (%d bytes)", code, text, vlen);
498 case 46: /* NetBIOS-over-TCP/IP Node Type */
499 byte = tvb_get_guint8(tvb, voff+2);
500 proto_tree_add_text(bp_tree, tvb, voff, consumed,
501 "Option %d: %s = %s", code, text,
502 val_to_str(byte, nbnt_vals,
503 "Unknown (0x%02x)"));
506 case 53: /* DHCP Message Type */
507 proto_tree_add_text(bp_tree, tvb, voff, 3, "Option %d: %s = DHCP %s",
508 code, text, get_dhcp_type(tvb_get_guint8(tvb, voff+2)));
511 case 55: /* Parameter Request List */
512 vti = proto_tree_add_text(bp_tree, tvb, voff,
513 vlen + 2, "Option %d: %s", code, text);
514 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
515 for (i = 0; i < vlen; i++) {
516 byte = tvb_get_guint8(tvb, voff+2+i);
517 if (byte < NUM_OPT_INFOS) {
518 proto_tree_add_text(v_tree, tvb, voff+2+i, 1, "%d = %s",
519 byte, opt[byte].text);
521 proto_tree_add_text(vti, tvb, voff+2+i, 1,
522 "Unknown Option Code: %d", byte);
527 case 60: /* Vendor class identifier */
528 proto_tree_add_text(bp_tree, tvb, voff, consumed,
529 "Option %d: %s = \"%.*s\"", code, text, vlen,
530 tvb_get_ptr(tvb, voff+2, consumed-2));
533 case 61: /* Client Identifier */
534 /* We *MAY* use hwtype/hwaddr. If we have 7 bytes, I'll
535 guess that the first is the hwtype, and the last 6
540 vti = proto_tree_add_text(bp_tree, tvb, voff,
541 consumed, "Option %d: %s", code, text);
542 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
543 htype = tvb_get_guint8(tvb, voff+2);
544 proto_tree_add_text(v_tree, tvb, voff+2, 1,
546 arphrdtype_to_str(htype,
547 "Unknown (0x%02x)"));
548 proto_tree_add_text(v_tree, tvb, voff+3, 6,
549 "Client hardware address: %s",
550 arphrdaddr_to_str(tvb_get_ptr(tvb, voff+3, 6),
553 /* otherwise, it's opaque data */
554 proto_tree_add_text(bp_tree, tvb, voff, consumed,
555 "Option %d: %s (%d bytes)", code, text, vlen);
559 case 63: /* NetWare/IP options */
560 vti = proto_tree_add_text(bp_tree, tvb, voff,
561 consumed, "Option %d: %s", code, text);
562 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
565 while (optp < voff+consumed)
566 optp = dissect_netware_ip_suboption(v_tree, tvb, optp);
569 case 82: /* Relay Agent Information Option */
570 vti = proto_tree_add_text(bp_tree, tvb, voff, consumed,
571 "Option %d: %s (%d bytes)",
573 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
575 while (optp < voff+consumed) {
576 optp = bootp_dhcp_decode_agent_info(v_tree, tvb, optp);
580 case 210: /* DHCP Authentication */
581 vti = proto_tree_add_text(bp_tree, tvb, voff,
582 vlen + 2, "Option %d: %s", code, text);
583 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
584 proto_tree_add_text(v_tree, tvb, voff+2, 1, "Protocol: %d",
585 tvb_get_guint8(tvb, voff+2));
586 proto_tree_add_text(v_tree, tvb, voff+3, 1, "Algorithm: %d",
587 tvb_get_guint8(tvb, voff+3));
588 proto_tree_add_text(v_tree, tvb, voff+4, 1, "Replay Detection Method: %d",
589 tvb_get_guint8(tvb, voff+4));
593 * 1) this won't compile if you have a compiler that
594 * doesn't support 64-bit integral quantities;
596 * 2) there is no standard for the printf format to
597 * be used for 64-bit integral quantities, so
598 * this may not display correctly.
600 * We need to figure out how to handle 64-bit integral
601 * quantities portably, with some form of fallback if
602 * the compiler doesn't support it, and some way of
603 * handling "%ll{d,o,x}" (most platforms) vs. "%q{d,o.x}"
604 * (FreeBSD, perhaps some versions of other BSDs) vs.
605 * "sorry, we're an LP64 platform, %l{d,o,x} is good enough
606 * for you" (Digital UNIX).
608 proto_tree_add_text(v_tree, tvb, voff+5, 8, "Replay Detection Value: %0llX",
609 tvb_get_ntohll(tvb, voff+5));
611 proto_tree_add_text(v_tree, tvb, voff+13, 4, "Secret ID: %0X",
612 tvb_get_ntohl(tvb, voff+13));
613 md5_ptr = tvb_get_ptr(tvb, voff+17, 16);
615 sprintf(&(md5_str[i*3]), "%02X ", (guint8) md5_ptr[i]);
617 proto_tree_add_text(v_tree, tvb, voff+17, 16, "HMAC MD5 Hash: %s", md5_str);
621 default: /* not special */
626 if (code < NUM_OPT_INFOS) {
627 text = opt[code].text;
628 ftype = opt[code].ftype;
638 proto_tree_add_text(bp_tree, tvb, voff, consumed,
639 "Option %d: %s = %s", code, text,
640 ip_to_str(tvb_get_ptr(tvb, voff+2, 4)));
642 /* > 1 IP addresses. Let's make a sub-tree */
643 vti = proto_tree_add_text(bp_tree, tvb, voff,
644 consumed, "Option %d: %s", code, text);
645 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
646 for (i = voff + 2; i < voff + consumed; i += 4) {
647 proto_tree_add_text(v_tree, tvb, i, 4, "IP Address: %s",
648 ip_to_str(tvb_get_ptr(tvb, i, 4)));
654 /* Fix for non null-terminated string supplied by
655 * John Lines <John.Lines@aeat.co.uk>
657 proto_tree_add_text(bp_tree, tvb, voff, consumed,
658 "Option %d: %s = \"%.*s\"", code, text, vlen,
659 tvb_get_ptr(tvb, voff+2, consumed-2));
663 proto_tree_add_text(bp_tree, tvb, voff, consumed,
664 "Option %d: %s (%d bytes)",
671 proto_tree_add_text(bp_tree, tvb, voff, consumed,
672 "Option %d: %s = %d", code, text,
673 tvb_get_ntohs(tvb, voff+2));
676 vti = proto_tree_add_text(bp_tree, tvb, voff,
677 consumed, "Option %d: %s", code, text);
678 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
679 for (i = voff + 2; i < voff + consumed; i += 2) {
680 proto_tree_add_text(v_tree, tvb, i, 4, "Value: %d",
681 tvb_get_ntohs(tvb, i));
687 proto_tree_add_text(bp_tree, tvb, voff, consumed,
688 "Option %d: %s = %d", code, text,
689 tvb_get_ntohl(tvb, voff+2));
693 proto_tree_add_text(bp_tree, tvb, voff, consumed,
694 "Option %d: %s = %d", code, text,
695 tvb_get_guint8(tvb, voff+2));
699 i = tvb_get_guint8(tvb, voff+2);
700 if (i != 0 && i != 1) {
701 proto_tree_add_text(bp_tree, tvb, voff, consumed,
702 "Option %d: %s = Invalid Value %d", code, text,
705 proto_tree_add_text(bp_tree, tvb, voff, consumed,
706 "Option %d: %s = %s", code, text,
707 i == 0 ? "Disabled" : "Enabled");
712 i = tvb_get_guint8(tvb, voff+2);
713 if (i != 0 && i != 1) {
714 proto_tree_add_text(bp_tree, tvb, voff, consumed,
715 "Option %d: %s = Invalid Value %d", code, text,
718 proto_tree_add_text(bp_tree, tvb, voff, consumed,
719 "Option %d: %s = %s", code, text,
720 i == 0 ? "No" : "Yes");
725 time_secs = tvb_get_ntohl(tvb, voff+2);
726 proto_tree_add_text(bp_tree, tvb, voff, consumed,
727 "Option %d: %s = %s", code, text,
728 ((time_secs == 0xffffffff) ?
730 time_secs_to_str(time_secs)));
734 proto_tree_add_text(bp_tree, tvb, voff, consumed,
735 "Option %d: %s (%d bytes)", code, text, vlen);
738 proto_tree_add_text(bp_tree, tvb, voff, consumed,
739 "Unknown Option Code: %d (%d bytes)", code, vlen);
746 bootp_dhcp_decode_agent_info(proto_tree *v_tree, tvbuff_t *tvb, int optp)
751 subopt = tvb_get_guint8(tvb, optp);
752 subopt_len = tvb_get_guint8(tvb, optp+1);
755 proto_tree_add_text(v_tree, tvb, optp, subopt_len + 2,
756 "Agent Circuit ID (%d bytes)", subopt_len);
759 proto_tree_add_text(v_tree, tvb, optp, subopt_len + 2,
760 "Agent Remote ID (%d bytes)", subopt_len);
763 proto_tree_add_text(v_tree, tvb, optp, subopt_len + 2,
764 "Unknown agent option: %d", subopt);
767 optp += (subopt_len + 2);
772 dissect_vendor_pxeclient_suboption(proto_tree *v_tree, tvbuff_t *tvb, int optp)
777 proto_tree *o43pxeclient_v_tree;
780 struct o43pxeclient_opt_info {
785 static struct o43pxeclient_opt_info o43pxeclient_opt[]= {
786 /* 0 */ {"nop", special}, /* dummy */
787 /* 1 */ {"PXE mtftp IP", ipv4},
788 /* 2 */ {"PXE mtftp client port", val_u_le_short},
789 /* 3 */ {"PXE mtftp server port",val_u_le_short},
790 /* 4 */ {"PXE mtftp timeout", val_u_byte},
791 /* 5 */ {"PXE mtftp delay", val_u_byte},
792 /* 6 */ {"PXE discovery control", val_u_byte},
794 * Correct: b0 (lsb): disable broadcast discovery
795 * b1: disable multicast discovery
796 * b2: only use/accept servers in boot servers
797 * b3: download bootfile without prompt/menu/disc
799 /* 7 */ {"PXE multicast address", ipv4},
800 /* 8 */ {"PXE boot servers", special},
801 /* 9 */ {"PXE boot menu", special},
802 /* 10 */ {"PXE menu prompt", special},
803 /* 11 */ {"PXE multicast address alloc", special},
804 /* 12 */ {"PXE credential types", special},
805 /* 71 {"PXE boot item", special} */
806 /* 255 {"PXE end options", special} */
808 #define NUM_O43PXECLIENT_SUBOPTS (12)
810 subopt = tvb_get_guint8(tvb, optp);
813 proto_tree_add_text(v_tree, tvb, optp, 1, "Padding");
815 } else if (subopt == 255) { /* End Option */
816 proto_tree_add_text(v_tree, tvb, optp, 1, "End PXEClient option");
817 /* Make sure we skip any junk left this option */
821 subopt_len = tvb_get_guint8(tvb, optp+1);
823 if ( subopt == 71 ) { /* 71 {"PXE boot item", special} */
825 /* I may need to decode that properly one day */
826 proto_tree_add_text(v_tree, tvb, optp, subopt_len+2,
827 "Suboption %d: %s (%d byte%s)" ,
828 subopt, "PXE boot item",
829 subopt_len, (subopt_len != 1)?"s":"");
830 } else if ( (subopt < 1 ) || (subopt > NUM_O43PXECLIENT_SUBOPTS) ) {
831 proto_tree_add_text(v_tree, tvb, optp, subopt_len+2,
832 "Unknown suboption %d (%d byte%s)", subopt, subopt_len,
833 (subopt_len != 1)?"s":"");
835 switch (o43pxeclient_opt[subopt].ft) {
838 proto_tree_add_text(v_tree, tvb, optp, subopt_len+2,
839 "Suboption %d: %s", subopt, o43pxeclient_opt[subopt].text);
843 /* I may need to decode that properly one day */
844 proto_tree_add_text(v_tree, tvb, optp, subopt_len+2,
845 "Suboption %d: %s (%d byte%s)" ,
846 subopt, o43pxeclient_opt[subopt].text,
847 subopt_len, (subopt_len != 1)?"s":"");
851 proto_tree_add_text(v_tree, tvb, optp, 4, "Suboption %d: %s = %u",
852 subopt, o43pxeclient_opt[subopt].text,
853 tvb_get_letohs(tvb, optp+2));
857 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s = %u",
858 subopt, o43pxeclient_opt[subopt].text,
859 tvb_get_guint8(tvb, optp+2));
863 if (subopt_len == 4) {
865 proto_tree_add_text(v_tree, tvb, optp, 6,
866 "Suboption %d : %s = %s",
867 subopt, o43pxeclient_opt[subopt].text,
868 ip_to_str(tvb_get_ptr(tvb, optp+2, 4)));
870 /* > 1 IP addresses. Let's make a sub-tree */
871 vti = proto_tree_add_text(v_tree, tvb, optp,
872 subopt_len+2, "Suboption %d: %s",
873 subopt, o43pxeclient_opt[subopt].text);
874 o43pxeclient_v_tree = proto_item_add_subtree(vti, ett_bootp_option);
875 for (slask = optp + 2 ; slask < optp+subopt_len; slask += 4) {
876 proto_tree_add_text(o43pxeclient_v_tree, tvb, slask, 4, "IP Address: %s",
877 ip_to_str(tvb_get_ptr(tvb, slask, 4)));
882 proto_tree_add_text(v_tree, tvb, optp, subopt_len+2,"ERROR, please report: Unknown subopt type handler %d", subopt);
886 optp += (subopt_len + 2);
891 dissect_netware_ip_suboption(proto_tree *v_tree, tvbuff_t *tvb, int optp)
896 proto_tree *o63_v_tree;
899 struct o63_opt_info {
905 static struct o63_opt_info o63_opt[]= {
906 /* 0 */ {"","",none},
907 /* 1 */ {"NWIP does not exist on subnet","",string},
908 /* 2 */ {"NWIP exist in options area","",string},
909 /* 3 */ {"NWIP exists in sname/file","",string},
910 /* 4 */ {"NWIP exists, but too big","",string},
911 /* 5 */ {"Broadcast for nearest Netware server","Do NOT Broadcast for nearest Netware server",yes_no},
912 /* 6 */ {"Preferred DSS server","",ipv4},
913 /* 7 */ {"Nearest NWIP server","",ipv4},
914 /* 8 */ {"Autoretries","",val_u_short},
915 /* 9 */ {"Autoretry delay, secs ","",val_u_short},
916 /* 10*/ {"Support NetWare/IP v1.1","Do NOT support NetWare/IP v1.1",yes_no},
917 /* 11*/ {"Primary DSS ", "" , special}
920 subopt = tvb_get_guint8(tvb, optp);
921 if (subopt > NUM_O63_SUBOPTS) {
922 proto_tree_add_text(v_tree, tvb,optp,1,"Unknown suboption %d", subopt);
925 switch (o63_opt[subopt].ft) {
928 proto_tree_add_text(v_tree, tvb, optp, 2, "Suboption %d: %s", subopt, o63_opt[subopt].truet);
933 if (tvb_get_guint8(tvb, optp+2)==1) {
934 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s", subopt, o63_opt[subopt].truet);
936 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s" , subopt, o63_opt[subopt].falset);
942 proto_tree_add_text(v_tree, tvb, optp, 6,
943 "Suboption %d: %s = %s" ,
944 subopt, o63_opt[subopt].truet,
945 ip_to_str(tvb_get_ptr(tvb, optp+2, 4)));
950 proto_tree_add_text(v_tree, tvb, optp, 3, "Suboption %d: %s = %u",
951 subopt, o63_opt[subopt].truet,
952 tvb_get_guint8(tvb, optp+2)); /* XXX - 1 byte? */
957 subopt_len = tvb_get_guint8(tvb, optp+1);
958 if (subopt_len == 4) {
960 proto_tree_add_text(v_tree, tvb, optp, 6,
961 "Suboption %d : %s = %s",
962 subopt, o63_opt[subopt].truet,
963 ip_to_str(tvb_get_ptr(tvb, optp+2, 4)));
966 /* > 1 IP addresses. Let's make a sub-tree */
967 vti = proto_tree_add_text(v_tree, tvb, optp,
968 subopt_len+2, "Suboption %d: %s",
969 subopt, o63_opt[subopt].truet);
970 o63_v_tree = proto_item_add_subtree(vti, ett_bootp_option);
971 for (slask = optp + 2 ; slask < optp+subopt_len; slask += 4) {
972 proto_tree_add_text(o63_v_tree, tvb, slask, 4, "IP Address: %s",
973 ip_to_str(tvb_get_ptr(tvb, slask, 4)));
979 proto_tree_add_text(v_tree, tvb,optp,1,"Unknown suboption %d", subopt);
987 #define BOOTREQUEST 1
990 static const value_string op_vals[] = {
991 { BOOTREQUEST, "Boot Request" },
992 { BOOTREPLY, "Boot Reply" },
997 dissect_bootp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
999 proto_tree *bp_tree = NULL;
1003 const guint8 *haddr;
1004 int voff, eoff, tmpvoff; /* vendor offset, end offset */
1006 const char *dhcp_type = NULL;
1007 const guint8 *vendor_class_id = NULL;
1009 if (check_col(pinfo->fd, COL_PROTOCOL))
1010 col_set_str(pinfo->fd, COL_PROTOCOL, "BOOTP");
1011 if (check_col(pinfo->fd, COL_INFO)) {
1013 * In case we throw an exception fetching the opcode, etc.
1015 col_clear(pinfo->fd, COL_INFO);
1018 op = tvb_get_guint8(tvb, 0);
1019 htype = tvb_get_guint8(tvb, 1);
1020 hlen = tvb_get_guint8(tvb, 2);
1021 if (check_col(pinfo->fd, COL_INFO)) {
1025 col_add_fstr(pinfo->fd, COL_INFO, "Boot Request from %s",
1026 arphrdaddr_to_str(tvb_get_ptr(tvb, 28, hlen),
1031 col_set_str(pinfo->fd, COL_INFO, "Boot Reply");
1035 col_add_fstr(pinfo->fd, COL_INFO, "Unknown BOOTP message type (%u)",
1042 ti = proto_tree_add_item(tree, proto_bootp, tvb, 0,
1043 tvb_length(tvb), FALSE);
1044 bp_tree = proto_item_add_subtree(ti, ett_bootp);
1046 proto_tree_add_uint(bp_tree, hf_bootp_type, tvb,
1049 proto_tree_add_uint_format(bp_tree, hf_bootp_hw_type, tvb,
1052 "Hardware type: %s",
1053 arphrdtype_to_str(htype,
1054 "Unknown (0x%02x)"));
1055 proto_tree_add_uint(bp_tree, hf_bootp_hw_len, tvb,
1057 proto_tree_add_item(bp_tree, hf_bootp_hops, tvb,
1059 proto_tree_add_item(bp_tree, hf_bootp_id, tvb,
1061 proto_tree_add_item(bp_tree, hf_bootp_secs, tvb,
1063 proto_tree_add_uint(bp_tree, hf_bootp_flag, tvb,
1064 10, 2, tvb_get_ntohs(tvb, 10) & 0x8000);
1066 proto_tree_add_item(bp_tree, hf_bootp_ip_client, tvb,
1068 proto_tree_add_item(bp_tree, hf_bootp_ip_your, tvb,
1070 proto_tree_add_item(bp_tree, hf_bootp_ip_server, tvb,
1072 proto_tree_add_item(bp_tree, hf_bootp_ip_relay, tvb,
1076 haddr = tvb_get_ptr(tvb, 28, hlen);
1077 proto_tree_add_bytes_format(bp_tree, hf_bootp_hw_addr, tvb,
1080 "Client hardware address: %s",
1081 arphrdaddr_to_str(haddr,
1086 proto_tree_add_text(bp_tree, tvb,
1087 28, 0, "Client address not given");
1090 /* The server host name is optional */
1091 if (tvb_get_guint8(tvb, 44) != '\0') {
1092 proto_tree_add_item(bp_tree, hf_bootp_server, tvb,
1096 proto_tree_add_string_format(bp_tree, hf_bootp_server, tvb,
1098 tvb_get_ptr(tvb, 44, 1),
1099 "Server host name not given");
1103 if (tvb_get_guint8(tvb, 108) != '\0') {
1104 proto_tree_add_item(bp_tree, hf_bootp_file, tvb,
1108 proto_tree_add_string_format(bp_tree, hf_bootp_file, tvb,
1110 tvb_get_ptr(tvb, 108, 1),
1111 "Boot file name not given");
1114 tvb_memcpy(tvb, (void *)&ip_addr, 236, sizeof(ip_addr));
1115 if (tvb_get_ntohl(tvb, 236) == 0x63825363) {
1116 proto_tree_add_ipv4_format(bp_tree, hf_bootp_cookie, tvb,
1118 "Magic cookie: (OK)");
1121 proto_tree_add_ipv4(bp_tree, hf_bootp_cookie, tvb,
1127 eoff = tvb_reported_length(tvb);
1130 * In the first pass, we just look for the DHCP message type
1131 * and Vendor class identifier options.
1134 while (tmpvoff < eoff) {
1135 tmpvoff += bootp_option(tvb, 0, tmpvoff, eoff, TRUE,
1136 &dhcp_type, &vendor_class_id);
1140 * If there was a DHCP message type option, flag this packet
1143 if (dhcp_type != NULL) {
1145 * Yes, this is a DHCP packet, and "dhcp_type" is the
1148 if (check_col(pinfo->fd, COL_PROTOCOL))
1149 col_set_str(pinfo->fd, COL_PROTOCOL, "DHCP");
1150 if (check_col(pinfo->fd, COL_INFO))
1151 col_add_fstr(pinfo->fd, COL_INFO, "DHCP %-8s - Transaction ID 0x%x",
1152 dhcp_type, tvb_get_ntohl(tvb, 4));
1154 proto_tree_add_boolean_hidden(bp_tree, hf_bootp_dhcp,
1159 * If we're not building the protocol tree, we don't need to
1160 * make a second pass.
1166 * OK, now build the protocol tree.
1168 while (voff < eoff) {
1169 voff += bootp_option(tvb, bp_tree, voff, eoff, FALSE,
1170 &dhcp_type, &vendor_class_id);
1175 proto_register_bootp(void)
1177 static hf_register_info hf[] = {
1179 { "Frame is DHCP", "bootp.dhcp", FT_BOOLEAN,
1180 BASE_NONE, NULL, 0x0,
1184 { "Message type", "bootp.type", FT_UINT8,
1185 BASE_DEC, VALS(op_vals), 0x0,
1188 { &hf_bootp_hw_type,
1189 { "Hardware type", "bootp.hw.type", FT_UINT8,
1190 BASE_HEX, NULL, 0x0,
1194 { "Hardware address length", "bootp.hw.len", FT_UINT8,
1195 BASE_DEC, NULL, 0x0,
1199 { "Hops", "bootp.hops", FT_UINT8,
1200 BASE_DEC, NULL, 0x0,
1204 { "Transaction ID", "bootp.id", FT_UINT32,
1205 BASE_HEX, NULL, 0x0,
1209 { "Seconds elapsed", "bootp.secs", FT_UINT16,
1210 BASE_DEC, NULL, 0x0,
1214 { "Broadcast flag", "bootp.flag", FT_UINT16,
1215 BASE_HEX, NULL, 0x0,
1218 { &hf_bootp_ip_client,
1219 { "Client IP address", "bootp.ip.client",FT_IPv4,
1220 BASE_NONE, NULL, 0x0,
1223 { &hf_bootp_ip_your,
1224 { "Your (client) IP address", "bootp.ip.your", FT_IPv4,
1225 BASE_NONE, NULL, 0x0,
1228 { &hf_bootp_ip_server,
1229 { "Next server IP address", "bootp.ip.server",FT_IPv4,
1230 BASE_NONE, NULL, 0x0,
1233 { &hf_bootp_ip_relay,
1234 { "Relay agent IP address", "bootp.ip.relay", FT_IPv4,
1235 BASE_NONE, NULL, 0x0,
1238 { &hf_bootp_hw_addr,
1239 { "Client hardware address", "bootp.hw.addr", FT_BYTES,
1240 BASE_NONE, NULL, 0x0,
1244 { "Server host name", "bootp.server", FT_STRING,
1245 BASE_NONE, NULL, 0x0,
1249 { "Boot file name", "bootp.file", FT_STRING,
1250 BASE_NONE, NULL, 0x0,
1254 { "Magic cookie", "bootp.cookie", FT_IPv4,
1255 BASE_NONE, NULL, 0x0,
1258 static gint *ett[] = {
1263 proto_bootp = proto_register_protocol("Bootstrap Protocol", "BOOTP/DHCP",
1265 proto_register_field_array(proto_bootp, hf, array_length(hf));
1266 proto_register_subtree_array(ett, array_length(ett));
1270 proto_reg_handoff_bootp(void)
1272 dissector_add("udp.port", UDP_PORT_BOOTPS, dissect_bootp, proto_bootp);