2 * Routines for BOOTP/DHCP packet disassembly
3 * Gilbert Ramirez <gram@verdict.uthscsa.edu>
5 * $Id: packet-bootp.c,v 1.21 1999/10/12 06:20:02 gram 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@unicom.net>
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>
43 static int proto_bootp = -1;
44 static int hf_bootp_type = -1;
45 static int hf_bootp_hw_type = -1;
46 static int hf_bootp_hw_len = -1;
47 static int hf_bootp_hops = -1;
48 static int hf_bootp_id = -1;
49 static int hf_bootp_secs = -1;
50 static int hf_bootp_flag = -1;
51 static int hf_bootp_ip_client = -1;
52 static int hf_bootp_ip_your = -1;
53 static int hf_bootp_ip_server = -1;
54 static int hf_bootp_ip_relay = -1;
55 static int hf_bootp_hw_addr = -1;
56 static int hf_bootp_server = -1;
57 static int hf_bootp_file = -1;
58 static int hf_bootp_cookie = -1;
60 enum field_type { none, ipv4, string, toggle, yes_no, special, opaque,
62 val_u_byte, val_u_short, val_u_long,
67 enum field_type ftype;
70 #define NUM_OPT_INFOS 77
72 /* returns the number of bytes consumed by this option */
74 bootp_option(const u_char *pd, proto_tree *bp_tree, int voff, int eoff)
77 enum field_type ftype;
78 u_char code = pd[voff];
79 int vlen = pd[voff+1];
81 int i, consumed = vlen + 2;
86 static const char *opt53_text[] = {
87 "Unknown Message Type",
97 static const value_string nbnt_vals[] = {
104 static struct opt_info opt[] = {
105 /* 0 */ { "Padding", none },
106 /* 1 */ { "Subnet Mask", ipv4 },
107 /* 2 */ { "Time Offset", val_s_long },
108 /* 3 */ { "Router", ipv4 },
109 /* 4 */ { "Time Server", ipv4 },
110 /* 5 */ { "Name Server", ipv4 },
111 /* 6 */ { "Domain Name Server", ipv4 },
112 /* 7 */ { "Log Server", ipv4 },
113 /* 8 */ { "Cookie Server", ipv4 },
114 /* 9 */ { "LPR Server", ipv4 },
115 /* 10 */ { "Impress Server", ipv4 },
116 /* 11 */ { "Resource Location Server", ipv4 },
117 /* 12 */ { "Host Name", string },
118 /* 13 */ { "Boot File Size", val_u_short },
119 /* 14 */ { "Merit Dump File", string },
120 /* 15 */ { "Domain Name", string },
121 /* 16 */ { "Swap Server", ipv4 },
122 /* 17 */ { "Root Path", string },
123 /* 18 */ { "Extensions Path", string },
124 /* 19 */ { "IP Forwarding", toggle },
125 /* 20 */ { "Non-Local Source Routing", toggle },
126 /* 21 */ { "Policy Filter", special },
127 /* 22 */ { "Maximum Datagram Reassembly Size", val_u_short },
128 /* 23 */ { "Default IP Time-to-Live", val_u_byte },
129 /* 24 */ { "Path MTU Aging Timeout", time_in_secs },
130 /* 25 */ { "Path MTU Plateau Table", val_u_short },
131 /* 26 */ { "Interface MTU", val_u_short },
132 /* 27 */ { "All Subnets are Local", yes_no },
133 /* 28 */ { "Broadcast Address", ipv4 },
134 /* 29 */ { "Perform Mask Discovery", toggle },
135 /* 30 */ { "Mask Supplier", yes_no },
136 /* 31 */ { "Perform Router Discover", toggle },
137 /* 32 */ { "Router Solicitation Address", ipv4 },
138 /* 33 */ { "Static Route", special },
139 /* 34 */ { "Trailer Encapsulation", toggle },
140 /* 35 */ { "ARP Cache Timeout", time_in_secs },
141 /* 36 */ { "Ethernet Encapsulation", toggle },
142 /* 37 */ { "TCP Default TTL", val_u_byte },
143 /* 38 */ { "TCP Keepalive Interval", time_in_secs },
144 /* 39 */ { "TCP Keepalive Garbage", toggle },
145 /* 40 */ { "Network Information Service Domain", string },
146 /* 41 */ { "Network Information Service Servers", ipv4 },
147 /* 42 */ { "Network Time Protocol Servers", ipv4 },
148 /* 43 */ { "Vendor-Specific Information", special },
149 /* 44 */ { "NetBIOS over TCP/IP Name Server", ipv4 },
150 /* 45 */ { "NetBIOS over TCP/IP Datagram Distribution Name Server", ipv4 },
151 /* 46 */ { "NetBIOS over TCP/IP Node Type", special },
152 /* 47 */ { "NetBIOS over TCP/IP Scope", string },
153 /* 48 */ { "X Window System Font Server", ipv4 },
154 /* 49 */ { "X Window System Display Manager", ipv4 },
155 /* 50 */ { "Requested IP Address", ipv4 },
156 /* 51 */ { "IP Address Lease Time", time_in_secs },
157 /* 52 */ { "Option Overload", special },
158 /* 53 */ { "DHCP Message Type", special },
159 /* 54 */ { "Server Identifier", ipv4 },
160 /* 55 */ { "Parameter Request List", special },
161 /* 56 */ { "Message", string },
162 /* 57 */ { "Maximum DHCP Message Size", val_u_short },
163 /* 58 */ { "Renewal Time Value", time_in_secs },
164 /* 59 */ { "Rebinding Time Value", time_in_secs },
165 /* 60 */ { "Vendor class identifier", opaque },
166 /* 61 */ { "Client identifier", special },
167 /* 64 */ { "Network Information Service+ Domain", string },
168 /* 65 */ { "Network Information Service+ Servers", ipv4 },
169 /* 66 */ { "TFTP Server Name", string },
170 /* 67 */ { "Bootfile name", string },
171 /* 68 */ { "Mobile IP Home Agent", ipv4 },
172 /* 69 */ { "SMTP Server", ipv4 },
173 /* 70 */ { "POP3 Server", ipv4 },
174 /* 71 */ { "NNTP Server", ipv4 },
175 /* 72 */ { "Default WWW Server", ipv4 },
176 /* 73 */ { "Default Finger Server", ipv4 },
177 /* 74 */ { "Default IRC Server", ipv4 },
178 /* 75 */ { "StreetTalk Server", ipv4 },
179 /* 76 */ { "StreetTalk Directory Assistance Server", ipv4 }
182 text = opt[code].text;
187 /* check how much padding we have */
188 for (i = voff + 1; i < eoff; i++ ) {
194 proto_tree_add_text(bp_tree, voff, i, "Padding");
200 /* one IP address pair */
202 proto_tree_add_text(bp_tree, voff, consumed,
203 "Option %d: %s = %s/%s", code, text,
204 ip_to_str((guint8*)&pd[voff+2]),
205 ip_to_str((guint8*)&pd[voff+6]));
207 /* > 1 IP address pair. Let's make a sub-tree */
210 vti = proto_tree_add_text(bp_tree, voff,
211 consumed, "Option %d: %s", code, text);
212 v_tree = proto_item_add_subtree(vti, ETT_BOOTP_OPTION);
213 for (i = voff + 2; i < voff + consumed; i += 8) {
214 proto_tree_add_text(v_tree, i, 8, "IP Address/Mask: %s/%s",
215 ip_to_str((guint8*)&pd[i]),
216 ip_to_str((guint8*)&pd[i+4]));
223 /* one IP address pair */
225 proto_tree_add_text(bp_tree, voff, consumed,
226 "Option %d: %s = %s/%s", code, text,
227 ip_to_str((guint8*)&pd[voff+2]),
228 ip_to_str((guint8*)&pd[voff+6]));
230 /* > 1 IP address pair. Let's make a sub-tree */
233 vti = proto_tree_add_text(bp_tree, voff,
234 consumed, "Option %d: %s", code, text);
235 v_tree = proto_item_add_subtree(vti, ETT_BOOTP_OPTION);
236 for (i = voff + 2; i < voff + consumed; i += 8) {
237 proto_tree_add_text(v_tree, i, 8,
238 "Destination IP Address/Router: %s/%s",
239 ip_to_str((guint8*)&pd[i]),
240 ip_to_str((guint8*)&pd[i+4]));
245 /* Vendor-Specific Info */
247 proto_tree_add_text(bp_tree, voff, consumed,
248 "Option %d: %s", code, text);
251 /* NetBIOS-over-TCP/IP Node Type */
254 proto_tree_add_text(bp_tree, voff, consumed,
255 "Option %d: %s = %s", code, text,
256 val_to_str(byte, nbnt_vals,
257 "Unknown (0x%02x)"));
260 /* DHCP Message Type */
263 if (byte > 0 && byte < 9) {
269 proto_tree_add_text(bp_tree, voff, 3, "Option %d: %s = DHCP %s",
270 code, text, opt53_text[i]);
273 /* Parameter Request List */
275 vti = proto_tree_add_text(bp_tree, voff,
276 vlen + 2, "Option %d: %s", code, text);
277 v_tree = proto_item_add_subtree(vti, ETT_BOOTP_OPTION);
278 for (i = 0; i < vlen; i++) {
280 if (byte < NUM_OPT_INFOS) {
281 proto_tree_add_text(v_tree, voff+2+i, 1, "%d = %s",
282 byte, opt[byte].text);
285 proto_tree_add_text(vti, voff+2+i, 1,
286 "Unknown Option Code: %d", byte);
291 /* Client Identifier */
293 /* We *MAY* use hwtype/hwaddr. If we have 7 bytes, I'll
294 guess that the first is the hwtype, and the last 6 are
297 vti = proto_tree_add_text(bp_tree, voff,
298 consumed, "Option %d: %s", code, text);
299 v_tree = proto_item_add_subtree(vti, ETT_BOOTP_OPTION);
300 proto_tree_add_text(v_tree, voff+2, 1,
302 arphrdtype_to_str(pd[voff+2],
303 "Unknown (0x%02x)"));
304 proto_tree_add_text(v_tree, voff+3, 6,
305 "Client hardware address: %s",
306 arphrdaddr_to_str((guint8*)&pd[voff+3],
309 /* otherwise, it's opaque data */
311 proto_tree_add_text(bp_tree, voff, consumed,
312 "Option %d: %s (%d bytes)", code, text, vlen);
318 proto_tree_add_text(bp_tree, voff, 1, "End Option");
328 if (code < NUM_OPT_INFOS) {
329 text = opt[code].text;
330 ftype = opt[code].ftype;
339 proto_tree_add_text(bp_tree, voff, consumed,
340 "Option %d: %s = %s", code, text,
341 ip_to_str((guint8*)&pd[voff+2]));
343 /* > 1 IP addresses. Let's make a sub-tree */
346 vti = proto_tree_add_text(bp_tree, voff,
347 consumed, "Option %d: %s", code, text);
348 v_tree = proto_item_add_subtree(vti, ETT_BOOTP_OPTION);
349 for (i = voff + 2; i < voff + consumed; i += 4) {
350 proto_tree_add_text(v_tree, i, 4, "IP Address: %s",
351 ip_to_str((guint8*)&pd[i]));
357 /* Fix for non null-terminated string supplied by
358 * John Lines <John.Lines@aeat.co.uk>
360 proto_tree_add_text(bp_tree, voff, consumed,
361 "Option %d: %s = %.*s", code, text, vlen, &pd[voff+2]);
365 proto_tree_add_text(bp_tree, voff, consumed,
366 "Option %d: %s (%d bytes)",
373 proto_tree_add_text(bp_tree, voff, consumed,
374 "Option %d: %s = %d", code, text,
375 pntohs(&pd[voff+2]));
379 vti = proto_tree_add_text(bp_tree, voff,
380 consumed, "Option %d: %s", code, text);
381 v_tree = proto_item_add_subtree(vti, ETT_BOOTP_OPTION);
382 for (i = voff + 2; i < voff + consumed; i += 2) {
383 proto_tree_add_text(v_tree, i, 4, "Value: %d",
390 proto_tree_add_text(bp_tree, voff, consumed,
391 "Option %d: %s = %d", code, text,
392 pntohl(&pd[voff+2]));
396 proto_tree_add_text(bp_tree, voff, consumed,
397 "Option %d: %s = %d", code, text, pd[voff+2]);
402 if (i != 0 && i != 1) {
403 proto_tree_add_text(bp_tree, voff, consumed,
404 "Option %d: %s = Invalid Value %d", code, text,
408 proto_tree_add_text(bp_tree, voff, consumed,
409 "Option %d: %s = %s", code, text,
410 pd[voff+2] == 0 ? "Disabled" : "Enabled");
416 if (i != 0 && i != 1) {
417 proto_tree_add_text(bp_tree, voff, consumed,
418 "Option %d: %s = Invalid Value %d", code, text,
422 proto_tree_add_text(bp_tree, voff, consumed,
423 "Option %d: %s = %s", code, text,
424 pd[voff+2] == 0 ? "No" : "Yes");
429 time_secs = pntohl(&pd[voff+2]);
430 proto_tree_add_text(bp_tree, voff, consumed,
431 "Option %d: %s = %s", code, text,
432 ((time_secs == 0xffffffff) ?
434 time_secs_to_str(time_secs)));
438 proto_tree_add_text(bp_tree, voff, consumed,
439 "Option %d: %s (%d bytes)", code, text, vlen);
443 proto_tree_add_text(bp_tree, voff, consumed,
444 "Unknown Option Code: %d (%d bytes)", code, vlen);
451 dissect_bootp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
455 int voff, eoff; /* vender offset, end offset */
458 if (check_col(fd, COL_PROTOCOL))
459 col_add_str(fd, COL_PROTOCOL, "BOOTP");
461 if (check_col(fd, COL_INFO)) {
462 if (pd[offset] == 1) {
463 col_add_fstr(fd, COL_INFO, "Boot Request from %s",
464 arphrdaddr_to_str((guint8*)&pd[offset+28],
465 pd[offset+2], pd[offset+1]));
468 col_add_str(fd, COL_INFO, "Boot Reply");
473 ti = proto_tree_add_item(tree, proto_bootp, offset, END_OF_FRAME, NULL);
474 bp_tree = proto_item_add_subtree(ti, ETT_BOOTP);
476 proto_tree_add_item_format(bp_tree, hf_bootp_type,
480 "Boot Request" : "Boot Reply");
481 proto_tree_add_item_format(bp_tree, hf_bootp_hw_type,
485 arphrdtype_to_str(pd[offset+1],
486 "Unknown (0x%02x)"));
487 proto_tree_add_item(bp_tree, hf_bootp_hw_len,
488 offset + 2, 1, pd[offset+2]);
489 proto_tree_add_item(bp_tree, hf_bootp_hops,
490 offset + 3, 1, pd[offset+3]);
491 proto_tree_add_item(bp_tree, hf_bootp_id,
492 offset + 4, 4, pntohl(&pd[offset+4]));
493 proto_tree_add_item(bp_tree, hf_bootp_secs,
494 offset + 8, 2, pntohs(&pd[offset+8]));
495 proto_tree_add_item(bp_tree, hf_bootp_flag,
496 offset + 10, 2, pd[offset+10] & 1);
498 memcpy(&ip_addr, &pd[offset+12], sizeof(ip_addr));
499 proto_tree_add_item(bp_tree, hf_bootp_ip_client,
500 offset + 12, 4, ip_addr);
501 memcpy(&ip_addr, &pd[offset+16], sizeof(ip_addr));
502 proto_tree_add_item(bp_tree, hf_bootp_ip_your,
503 offset + 16, 4, ip_addr);
504 memcpy(&ip_addr, &pd[offset+20], sizeof(ip_addr));
505 proto_tree_add_item(bp_tree, hf_bootp_ip_server,
506 offset + 20, 4, ip_addr);
507 memcpy(&ip_addr, &pd[offset+24], sizeof(ip_addr));
508 proto_tree_add_item(bp_tree, hf_bootp_ip_relay,
509 offset + 24, 4, ip_addr);
511 proto_tree_add_item_format(bp_tree, hf_bootp_hw_addr,
512 offset + 28, pd[offset+2],
514 "Client hardware address: %s",
515 arphrdaddr_to_str((guint8*)&pd[offset+28],
516 pd[offset+2], pd[offset+1]));
518 /* The server host name is optional */
520 proto_tree_add_item_format(bp_tree, hf_bootp_server,
523 "Server host name: %s",
527 proto_tree_add_item_format(bp_tree, hf_bootp_server,
530 "Server host name not given");
534 if (pd[offset+108]) {
535 proto_tree_add_item_format(bp_tree, hf_bootp_file,
538 "Boot file name: %s",
542 proto_tree_add_item_format(bp_tree, hf_bootp_file,
545 "Boot file name not given");
548 if (pntohl(&pd[offset+236]) == 0x63825363) {
549 proto_tree_add_item_format(bp_tree, hf_bootp_cookie,
552 "Magic cookie: (OK)");
555 memcpy(&ip_addr, &pd[offset + 236], sizeof(ip_addr));
556 proto_tree_add_item(bp_tree, hf_bootp_cookie,
557 offset + 236, 4, ip_addr);
561 eoff = pi.captured_len;
563 while (voff < eoff) {
564 voff += bootp_option(pd, bp_tree, voff, eoff);
570 proto_register_bootp(void)
572 static hf_register_info hf[] = {
574 { "Message type", "bootp.type", FT_UINT8, BASE_NONE, NULL, 0x0,
578 { "Hardware type", "bootp.hw.type", FT_UINT8, BASE_HEX, NULL, 0x0,
582 { "Hardware address length", "bootp.hw.len", FT_UINT8, BASE_DEC, NULL, 0x0,
586 { "Hops", "bootp.hops", FT_UINT8, BASE_DEC, NULL, 0x0,
590 { "Transaction ID", "bootp.id", FT_UINT32, BASE_HEX, NULL, 0x0,
594 { "Seconds elapsed", "bootp.secs", FT_UINT16, BASE_DEC, NULL, 0x0,
598 { "Broadcast flag", "bootp.flag", FT_UINT16, BASE_DEC, NULL, 0x0,
601 { &hf_bootp_ip_client,
602 { "Client IP address", "bootp.ip.client",FT_IPv4, BASE_NONE, NULL, 0x0,
606 { "Your (client) IP address", "bootp.ip.your", FT_IPv4, BASE_NONE, NULL, 0x0,
609 { &hf_bootp_ip_server,
610 { "Next server IP address", "bootp.ip.server",FT_IPv4, BASE_NONE, NULL, 0x0,
613 { &hf_bootp_ip_relay,
614 { "Relay agent IP address", "bootp.ip.relay", FT_IPv4, BASE_NONE, NULL, 0x0,
618 { "Client hardware address", "bootp.hw.addr", FT_BYTES, BASE_NONE, NULL, 0x0,
622 { "Server host name", "bootp.server", FT_STRING, BASE_NONE, NULL, 0x0,
626 { "Boot file name", "bootp.file", FT_STRING, BASE_NONE, NULL, 0x0,
630 { "Magic cookie", "bootp.cookie", FT_IPv4, BASE_NONE, NULL, 0x0,
634 proto_bootp = proto_register_protocol("Bootstrap Protocol", "bootp");
635 proto_register_field_array(proto_bootp, hf, array_length(hf));