2 * Routines for BOOTP/DHCP packet disassembly
3 * Gilbert Ramirez <gram@verdict.uthscsa.edu>
5 * $Id: packet-bootp.c,v 1.24 2000/01/07 22:05:30 guy Exp $
7 * The information used comes from:
8 * RFC 2132: DHCP Options and BOOTP Vendor Extensions
9 * RFC 1542: Clarifications and Extensions for the Bootstrap Protocol
10 * RFC 2131: Dynamic Host Configuration Protocol
12 * Ethereal - Network traffic analyzer
13 * By Gerald Combs <gerald@zing.org>
14 * Copyright 1998 Gerald Combs
17 * This program is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU General Public License
19 * as published by the Free Software Foundation; either version 2
20 * of the License, or (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #ifdef HAVE_SYS_TYPES_H
37 # include <sys/types.h>
42 #include "packet-arp.h"
44 static int proto_bootp = -1;
45 static int hf_bootp_type = -1;
46 static int hf_bootp_hw_type = -1;
47 static int hf_bootp_hw_len = -1;
48 static int hf_bootp_hops = -1;
49 static int hf_bootp_id = -1;
50 static int hf_bootp_secs = -1;
51 static int hf_bootp_flag = -1;
52 static int hf_bootp_ip_client = -1;
53 static int hf_bootp_ip_your = -1;
54 static int hf_bootp_ip_server = -1;
55 static int hf_bootp_ip_relay = -1;
56 static int hf_bootp_hw_addr = -1;
57 static int hf_bootp_server = -1;
58 static int hf_bootp_file = -1;
59 static int hf_bootp_cookie = -1;
61 static guint ett_bootp = -1;
62 static guint ett_bootp_option = -1;
64 enum field_type { none, ipv4, string, toggle, yes_no, special, opaque,
66 val_u_byte, val_u_short, val_u_long,
71 enum field_type ftype;
74 #define NUM_OPT_INFOS 77
76 /* returns the number of bytes consumed by this option */
78 bootp_option(const u_char *pd, proto_tree *bp_tree, int voff, int eoff)
81 enum field_type ftype;
82 u_char code = pd[voff];
83 int vlen = pd[voff+1];
85 int i, consumed = vlen + 2;
90 static const char *opt53_text[] = {
91 "Unknown Message Type",
101 static const value_string nbnt_vals[] = {
108 static struct opt_info opt[] = {
109 /* 0 */ { "Padding", none },
110 /* 1 */ { "Subnet Mask", ipv4 },
111 /* 2 */ { "Time Offset", val_s_long },
112 /* 3 */ { "Router", ipv4 },
113 /* 4 */ { "Time Server", ipv4 },
114 /* 5 */ { "Name Server", ipv4 },
115 /* 6 */ { "Domain Name Server", ipv4 },
116 /* 7 */ { "Log Server", ipv4 },
117 /* 8 */ { "Cookie Server", ipv4 },
118 /* 9 */ { "LPR Server", ipv4 },
119 /* 10 */ { "Impress Server", ipv4 },
120 /* 11 */ { "Resource Location Server", ipv4 },
121 /* 12 */ { "Host Name", string },
122 /* 13 */ { "Boot File Size", val_u_short },
123 /* 14 */ { "Merit Dump File", string },
124 /* 15 */ { "Domain Name", string },
125 /* 16 */ { "Swap Server", ipv4 },
126 /* 17 */ { "Root Path", string },
127 /* 18 */ { "Extensions Path", string },
128 /* 19 */ { "IP Forwarding", toggle },
129 /* 20 */ { "Non-Local Source Routing", toggle },
130 /* 21 */ { "Policy Filter", special },
131 /* 22 */ { "Maximum Datagram Reassembly Size", val_u_short },
132 /* 23 */ { "Default IP Time-to-Live", val_u_byte },
133 /* 24 */ { "Path MTU Aging Timeout", time_in_secs },
134 /* 25 */ { "Path MTU Plateau Table", val_u_short },
135 /* 26 */ { "Interface MTU", val_u_short },
136 /* 27 */ { "All Subnets are Local", yes_no },
137 /* 28 */ { "Broadcast Address", ipv4 },
138 /* 29 */ { "Perform Mask Discovery", toggle },
139 /* 30 */ { "Mask Supplier", yes_no },
140 /* 31 */ { "Perform Router Discover", toggle },
141 /* 32 */ { "Router Solicitation Address", ipv4 },
142 /* 33 */ { "Static Route", special },
143 /* 34 */ { "Trailer Encapsulation", toggle },
144 /* 35 */ { "ARP Cache Timeout", time_in_secs },
145 /* 36 */ { "Ethernet Encapsulation", toggle },
146 /* 37 */ { "TCP Default TTL", val_u_byte },
147 /* 38 */ { "TCP Keepalive Interval", time_in_secs },
148 /* 39 */ { "TCP Keepalive Garbage", toggle },
149 /* 40 */ { "Network Information Service Domain", string },
150 /* 41 */ { "Network Information Service Servers", ipv4 },
151 /* 42 */ { "Network Time Protocol Servers", ipv4 },
152 /* 43 */ { "Vendor-Specific Information", special },
153 /* 44 */ { "NetBIOS over TCP/IP Name Server", ipv4 },
154 /* 45 */ { "NetBIOS over TCP/IP Datagram Distribution Name Server", ipv4 },
155 /* 46 */ { "NetBIOS over TCP/IP Node Type", special },
156 /* 47 */ { "NetBIOS over TCP/IP Scope", string },
157 /* 48 */ { "X Window System Font Server", ipv4 },
158 /* 49 */ { "X Window System Display Manager", ipv4 },
159 /* 50 */ { "Requested IP Address", ipv4 },
160 /* 51 */ { "IP Address Lease Time", time_in_secs },
161 /* 52 */ { "Option Overload", special },
162 /* 53 */ { "DHCP Message Type", special },
163 /* 54 */ { "Server Identifier", ipv4 },
164 /* 55 */ { "Parameter Request List", special },
165 /* 56 */ { "Message", string },
166 /* 57 */ { "Maximum DHCP Message Size", val_u_short },
167 /* 58 */ { "Renewal Time Value", time_in_secs },
168 /* 59 */ { "Rebinding Time Value", time_in_secs },
169 /* 60 */ { "Vendor class identifier", opaque },
170 /* 61 */ { "Client identifier", special },
171 /* 64 */ { "Network Information Service+ Domain", string },
172 /* 65 */ { "Network Information Service+ Servers", ipv4 },
173 /* 66 */ { "TFTP Server Name", string },
174 /* 67 */ { "Bootfile name", string },
175 /* 68 */ { "Mobile IP Home Agent", ipv4 },
176 /* 69 */ { "SMTP Server", ipv4 },
177 /* 70 */ { "POP3 Server", ipv4 },
178 /* 71 */ { "NNTP Server", ipv4 },
179 /* 72 */ { "Default WWW Server", ipv4 },
180 /* 73 */ { "Default Finger Server", ipv4 },
181 /* 74 */ { "Default IRC Server", ipv4 },
182 /* 75 */ { "StreetTalk Server", ipv4 },
183 /* 76 */ { "StreetTalk Directory Assistance Server", ipv4 }
186 text = opt[code].text;
191 /* check how much padding we have */
192 for (i = voff + 1; i < eoff; i++ ) {
198 proto_tree_add_text(bp_tree, voff, i, "Padding");
204 /* one IP address pair */
206 proto_tree_add_text(bp_tree, voff, consumed,
207 "Option %d: %s = %s/%s", code, text,
208 ip_to_str((guint8*)&pd[voff+2]),
209 ip_to_str((guint8*)&pd[voff+6]));
211 /* > 1 IP address pair. Let's make a sub-tree */
214 vti = proto_tree_add_text(bp_tree, voff,
215 consumed, "Option %d: %s", code, text);
216 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
217 for (i = voff + 2; i < voff + consumed; i += 8) {
218 proto_tree_add_text(v_tree, i, 8, "IP Address/Mask: %s/%s",
219 ip_to_str((guint8*)&pd[i]),
220 ip_to_str((guint8*)&pd[i+4]));
227 /* one IP address pair */
229 proto_tree_add_text(bp_tree, voff, consumed,
230 "Option %d: %s = %s/%s", code, text,
231 ip_to_str((guint8*)&pd[voff+2]),
232 ip_to_str((guint8*)&pd[voff+6]));
234 /* > 1 IP address pair. Let's make a sub-tree */
237 vti = proto_tree_add_text(bp_tree, voff,
238 consumed, "Option %d: %s", code, text);
239 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
240 for (i = voff + 2; i < voff + consumed; i += 8) {
241 proto_tree_add_text(v_tree, i, 8,
242 "Destination IP Address/Router: %s/%s",
243 ip_to_str((guint8*)&pd[i]),
244 ip_to_str((guint8*)&pd[i+4]));
249 /* Vendor-Specific Info */
251 proto_tree_add_text(bp_tree, voff, consumed,
252 "Option %d: %s", code, text);
255 /* NetBIOS-over-TCP/IP Node Type */
258 proto_tree_add_text(bp_tree, voff, consumed,
259 "Option %d: %s = %s", code, text,
260 val_to_str(byte, nbnt_vals,
261 "Unknown (0x%02x)"));
264 /* DHCP Message Type */
267 if (byte > 0 && byte < 9) {
273 proto_tree_add_text(bp_tree, voff, 3, "Option %d: %s = DHCP %s",
274 code, text, opt53_text[i]);
277 /* Parameter Request List */
279 vti = proto_tree_add_text(bp_tree, voff,
280 vlen + 2, "Option %d: %s", code, text);
281 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
282 for (i = 0; i < vlen; i++) {
284 if (byte < NUM_OPT_INFOS) {
285 proto_tree_add_text(v_tree, voff+2+i, 1, "%d = %s",
286 byte, opt[byte].text);
289 proto_tree_add_text(vti, voff+2+i, 1,
290 "Unknown Option Code: %d", byte);
295 /* Client Identifier */
297 /* We *MAY* use hwtype/hwaddr. If we have 7 bytes, I'll
298 guess that the first is the hwtype, and the last 6 are
301 vti = proto_tree_add_text(bp_tree, voff,
302 consumed, "Option %d: %s", code, text);
303 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
304 proto_tree_add_text(v_tree, voff+2, 1,
306 arphrdtype_to_str(pd[voff+2],
307 "Unknown (0x%02x)"));
308 proto_tree_add_text(v_tree, voff+3, 6,
309 "Client hardware address: %s",
310 arphrdaddr_to_str((guint8*)&pd[voff+3],
313 /* otherwise, it's opaque data */
315 proto_tree_add_text(bp_tree, voff, consumed,
316 "Option %d: %s (%d bytes)", code, text, vlen);
322 proto_tree_add_text(bp_tree, voff, 1, "End Option");
332 if (code < NUM_OPT_INFOS) {
333 text = opt[code].text;
334 ftype = opt[code].ftype;
343 proto_tree_add_text(bp_tree, voff, consumed,
344 "Option %d: %s = %s", code, text,
345 ip_to_str((guint8*)&pd[voff+2]));
347 /* > 1 IP addresses. Let's make a sub-tree */
350 vti = proto_tree_add_text(bp_tree, voff,
351 consumed, "Option %d: %s", code, text);
352 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
353 for (i = voff + 2; i < voff + consumed; i += 4) {
354 proto_tree_add_text(v_tree, i, 4, "IP Address: %s",
355 ip_to_str((guint8*)&pd[i]));
361 /* Fix for non null-terminated string supplied by
362 * John Lines <John.Lines@aeat.co.uk>
364 proto_tree_add_text(bp_tree, voff, consumed,
365 "Option %d: %s = %.*s", code, text, vlen, &pd[voff+2]);
369 proto_tree_add_text(bp_tree, voff, consumed,
370 "Option %d: %s (%d bytes)",
377 proto_tree_add_text(bp_tree, voff, consumed,
378 "Option %d: %s = %d", code, text,
379 pntohs(&pd[voff+2]));
383 vti = proto_tree_add_text(bp_tree, voff,
384 consumed, "Option %d: %s", code, text);
385 v_tree = proto_item_add_subtree(vti, ett_bootp_option);
386 for (i = voff + 2; i < voff + consumed; i += 2) {
387 proto_tree_add_text(v_tree, i, 4, "Value: %d",
394 proto_tree_add_text(bp_tree, voff, consumed,
395 "Option %d: %s = %d", code, text,
396 pntohl(&pd[voff+2]));
400 proto_tree_add_text(bp_tree, voff, consumed,
401 "Option %d: %s = %d", code, text, pd[voff+2]);
406 if (i != 0 && i != 1) {
407 proto_tree_add_text(bp_tree, voff, consumed,
408 "Option %d: %s = Invalid Value %d", code, text,
412 proto_tree_add_text(bp_tree, voff, consumed,
413 "Option %d: %s = %s", code, text,
414 pd[voff+2] == 0 ? "Disabled" : "Enabled");
420 if (i != 0 && i != 1) {
421 proto_tree_add_text(bp_tree, voff, consumed,
422 "Option %d: %s = Invalid Value %d", code, text,
426 proto_tree_add_text(bp_tree, voff, consumed,
427 "Option %d: %s = %s", code, text,
428 pd[voff+2] == 0 ? "No" : "Yes");
433 time_secs = pntohl(&pd[voff+2]);
434 proto_tree_add_text(bp_tree, voff, consumed,
435 "Option %d: %s = %s", code, text,
436 ((time_secs == 0xffffffff) ?
438 time_secs_to_str(time_secs)));
442 proto_tree_add_text(bp_tree, voff, consumed,
443 "Option %d: %s (%d bytes)", code, text, vlen);
447 proto_tree_add_text(bp_tree, voff, consumed,
448 "Unknown Option Code: %d (%d bytes)", code, vlen);
455 dissect_bootp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
459 int voff, eoff; /* vender offset, end offset */
462 if (check_col(fd, COL_PROTOCOL))
463 col_add_str(fd, COL_PROTOCOL, "BOOTP");
465 if (check_col(fd, COL_INFO)) {
466 if (pd[offset] == 1) {
467 col_add_fstr(fd, COL_INFO, "Boot Request from %s",
468 arphrdaddr_to_str((guint8*)&pd[offset+28],
469 pd[offset+2], pd[offset+1]));
472 col_add_str(fd, COL_INFO, "Boot Reply");
477 ti = proto_tree_add_item(tree, proto_bootp, offset, END_OF_FRAME, NULL);
478 bp_tree = proto_item_add_subtree(ti, ett_bootp);
480 proto_tree_add_item_format(bp_tree, hf_bootp_type,
484 "Boot Request" : "Boot Reply");
485 proto_tree_add_item_format(bp_tree, hf_bootp_hw_type,
489 arphrdtype_to_str(pd[offset+1],
490 "Unknown (0x%02x)"));
491 proto_tree_add_item(bp_tree, hf_bootp_hw_len,
492 offset + 2, 1, pd[offset+2]);
493 proto_tree_add_item(bp_tree, hf_bootp_hops,
494 offset + 3, 1, pd[offset+3]);
495 proto_tree_add_item(bp_tree, hf_bootp_id,
496 offset + 4, 4, pntohl(&pd[offset+4]));
497 proto_tree_add_item(bp_tree, hf_bootp_secs,
498 offset + 8, 2, pntohs(&pd[offset+8]));
499 proto_tree_add_item(bp_tree, hf_bootp_flag,
500 offset + 10, 2, pd[offset+10] & 1);
502 memcpy(&ip_addr, &pd[offset+12], sizeof(ip_addr));
503 proto_tree_add_item(bp_tree, hf_bootp_ip_client,
504 offset + 12, 4, ip_addr);
505 memcpy(&ip_addr, &pd[offset+16], sizeof(ip_addr));
506 proto_tree_add_item(bp_tree, hf_bootp_ip_your,
507 offset + 16, 4, ip_addr);
508 memcpy(&ip_addr, &pd[offset+20], sizeof(ip_addr));
509 proto_tree_add_item(bp_tree, hf_bootp_ip_server,
510 offset + 20, 4, ip_addr);
511 memcpy(&ip_addr, &pd[offset+24], sizeof(ip_addr));
512 proto_tree_add_item(bp_tree, hf_bootp_ip_relay,
513 offset + 24, 4, ip_addr);
515 proto_tree_add_item_format(bp_tree, hf_bootp_hw_addr,
516 offset + 28, pd[offset+2],
518 "Client hardware address: %s",
519 arphrdaddr_to_str((guint8*)&pd[offset+28],
520 pd[offset+2], pd[offset+1]));
522 /* The server host name is optional */
524 proto_tree_add_item_format(bp_tree, hf_bootp_server,
527 "Server host name: %s",
531 proto_tree_add_item_format(bp_tree, hf_bootp_server,
534 "Server host name not given");
538 if (pd[offset+108]) {
539 proto_tree_add_item_format(bp_tree, hf_bootp_file,
542 "Boot file name: %s",
546 proto_tree_add_item_format(bp_tree, hf_bootp_file,
549 "Boot file name not given");
552 if (pntohl(&pd[offset+236]) == 0x63825363) {
553 proto_tree_add_item_format(bp_tree, hf_bootp_cookie,
556 "Magic cookie: (OK)");
559 memcpy(&ip_addr, &pd[offset + 236], sizeof(ip_addr));
560 proto_tree_add_item(bp_tree, hf_bootp_cookie,
561 offset + 236, 4, ip_addr);
565 eoff = pi.captured_len;
567 while (voff < eoff) {
568 voff += bootp_option(pd, bp_tree, voff, eoff);
574 proto_register_bootp(void)
576 static hf_register_info hf[] = {
578 { "Message type", "bootp.type", FT_UINT8, BASE_NONE, NULL, 0x0,
582 { "Hardware type", "bootp.hw.type", FT_UINT8, BASE_HEX, NULL, 0x0,
586 { "Hardware address length", "bootp.hw.len", FT_UINT8, BASE_DEC, NULL, 0x0,
590 { "Hops", "bootp.hops", FT_UINT8, BASE_DEC, NULL, 0x0,
594 { "Transaction ID", "bootp.id", FT_UINT32, BASE_HEX, NULL, 0x0,
598 { "Seconds elapsed", "bootp.secs", FT_UINT16, BASE_DEC, NULL, 0x0,
602 { "Broadcast flag", "bootp.flag", FT_UINT16, BASE_DEC, NULL, 0x0,
605 { &hf_bootp_ip_client,
606 { "Client IP address", "bootp.ip.client",FT_IPv4, BASE_NONE, NULL, 0x0,
610 { "Your (client) IP address", "bootp.ip.your", FT_IPv4, BASE_NONE, NULL, 0x0,
613 { &hf_bootp_ip_server,
614 { "Next server IP address", "bootp.ip.server",FT_IPv4, BASE_NONE, NULL, 0x0,
617 { &hf_bootp_ip_relay,
618 { "Relay agent IP address", "bootp.ip.relay", FT_IPv4, BASE_NONE, NULL, 0x0,
622 { "Client hardware address", "bootp.hw.addr", FT_BYTES, BASE_NONE, NULL, 0x0,
626 { "Server host name", "bootp.server", FT_STRING, BASE_NONE, NULL, 0x0,
630 { "Boot file name", "bootp.file", FT_STRING, BASE_NONE, NULL, 0x0,
634 { "Magic cookie", "bootp.cookie", FT_IPv4, BASE_NONE, NULL, 0x0,
637 static gint *ett[] = {
642 proto_bootp = proto_register_protocol("Bootstrap Protocol", "bootp");
643 proto_register_field_array(proto_bootp, hf, array_length(hf));
644 proto_register_subtree_array(ett, array_length(ett));