2 * Routines for Appletalk packet disassembly (DDP, currently).
4 * $Id: packet-atalk.c,v 1.55 2001/06/18 02:17:44 guy Exp $
6 * Simon Wilkinson <sxw@dcs.ed.ac.uk>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version 2
11 * of the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 #ifdef HAVE_SYS_TYPES_H
28 # include <sys/types.h>
31 #ifdef HAVE_NETINET_IN_H
32 # include <netinet/in.h>
40 #include "atalk-utils.h"
42 static int proto_ddp = -1;
43 static int hf_ddp_hopcount = -1;
44 static int hf_ddp_len = -1;
45 static int hf_ddp_checksum = -1;
46 static int hf_ddp_dst_net = -1;
47 static int hf_ddp_src_net = -1;
48 static int hf_ddp_dst_node = -1;
49 static int hf_ddp_src_node = -1;
50 static int hf_ddp_dst_socket = -1;
51 static int hf_ddp_src_socket = -1;
52 static int hf_ddp_type = -1;
54 static int proto_nbp = -1;
55 static int hf_nbp_op = -1;
56 static int hf_nbp_info = -1;
57 static int hf_nbp_count = -1;
58 static int hf_nbp_tid = -1;
60 static int hf_nbp_node_net = -1;
61 static int hf_nbp_node_port = -1;
62 static int hf_nbp_node_node = -1;
63 static int hf_nbp_node_enum = -1;
64 static int hf_nbp_node_object = -1;
65 static int hf_nbp_node_type = -1;
66 static int hf_nbp_node_zone = -1;
68 static int proto_rtmp = -1;
69 static int hf_rtmp_net = -1;
70 static int hf_rtmp_node_len = -1;
71 static int hf_rtmp_node = -1;
72 static int hf_rtmp_tuple_net = -1;
73 static int hf_rtmp_tuple_range_start = -1;
74 static int hf_rtmp_tuple_range_end = -1;
75 static int hf_rtmp_tuple_dist = -1;
76 static int hf_rtmp_function = -1;
78 static gint ett_nbp = -1;
79 static gint ett_nbp_info = -1;
80 static gint ett_nbp_node = -1;
81 static gint ett_rtmp = -1;
82 static gint ett_rtmp_tuple = -1;
83 static gint ett_ddp = -1;
84 static gint ett_pstring = -1;
86 static dissector_table_t ddp_dissector_table;
89 * P = Padding, H = Hops, L = Len
93 * Assumes the argument is in host byte order.
95 #define ddp_hops(x) ( ( x >> 10) & 0x3C )
96 #define ddp_len(x) ( x & 0x03ff )
97 typedef struct _e_ddp {
98 guint16 hops_len; /* combines pad, hops, and len */
99 guint16 sum,dnet,snet;
105 #define DDP_HEADER_SIZE 13
108 static const value_string op_vals[] = {
109 {DDP_RTMPDATA, "AppleTalk Routing Table response or data" },
110 {DDP_NBP, "AppleTalk Name Binding Protocol packet"},
111 {DDP_ATP, "AppleTalk Transaction Protocol packet"},
112 {DDP_AEP, "AppleTalk Echo Protocol packet"},
113 {DDP_RTMPREQ, "AppleTalk Routing Table request"},
114 {DDP_ZIP, "AppleTalk Zone Information Protocol packet"},
115 {DDP_ADSP, "AppleTalk Data Stream Protocol"},
116 {DDP_EIGRP, "Cisco EIGRP for AppleTalk"},
120 static const value_string rtmp_function_vals[] = {
122 {2, "Route Data Request (split horizon processed)"},
123 {3, "Route Data Request (no split horizon processing)"},
128 #define NBP_FORWARD 4
131 static const value_string nbp_op_vals[] = {
132 {NBP_LOOKUP, "lookup"},
133 {NBP_FORWARD, "forward request"},
134 {NBP_REPLY, "reply"},
139 * XXX - do this with an FT_UINT_STRING?
140 * Unfortunately, you can't extract from an FT_UINT_STRING the string,
141 * which we'd want to do in order to put it into the "Data:" portion.
143 int dissect_pascal_string(tvbuff_t *tvb, int offset, proto_tree *tree,
148 len = tvb_get_guint8(tvb, offset);
158 * XXX - if we could do this inside the protocol tree
159 * code, we could perhaps avoid allocating and freeing
160 * this string buffer.
162 tmp = g_malloc( len+1 );
163 tvb_memcpy(tvb, tmp, offset, len);
165 item = proto_tree_add_string(tree, hf_index, tvb, offset-1, len+1, tmp);
167 subtree = proto_item_add_subtree(item, ett_pstring);
168 proto_tree_add_text(subtree, tvb, offset-1, 1, "Length: %d", len);
169 proto_tree_add_text(subtree, tvb, offset, len, "Data: %s", tmp);
179 dissect_rtmp_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
180 proto_tree *rtmp_tree;
184 if (check_col(pinfo->fd, COL_PROTOCOL))
185 col_set_str(pinfo->fd, COL_PROTOCOL, "RTMP");
186 if (check_col(pinfo->fd, COL_INFO))
187 col_clear(pinfo->fd, COL_INFO);
189 function = tvb_get_guint8(tvb, 0);
191 if (check_col(pinfo->fd, COL_INFO))
192 col_add_fstr(pinfo->fd, COL_INFO, "%s",
193 val_to_str(function, rtmp_function_vals, "Unknown function (%02)"));
196 ti = proto_tree_add_item(tree, proto_rtmp, tvb, 0, 1, FALSE);
197 rtmp_tree = proto_item_add_subtree(ti, ett_rtmp);
199 proto_tree_add_uint(rtmp_tree, hf_rtmp_function, tvb, 0, 1, function);
204 dissect_rtmp_data(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
205 proto_tree *rtmp_tree;
209 guint8 nodelen,nodelen_bits;
210 guint16 node; /* might be more than 8 bits */
213 if (check_col(pinfo->fd, COL_PROTOCOL))
214 col_set_str(pinfo->fd, COL_PROTOCOL, "RTMP");
215 if (check_col(pinfo->fd, COL_INFO))
216 col_clear(pinfo->fd, COL_INFO);
218 net = tvb_get_ntohs(tvb, offset);
219 nodelen_bits = tvb_get_guint8(tvb, offset+2);
220 if ( nodelen_bits <= 8 ) {
221 node = tvb_get_guint8(tvb, offset)+1;
224 node = tvb_get_ntohs(tvb, offset);
228 if (check_col(pinfo->fd, COL_INFO))
229 col_add_fstr(pinfo->fd, COL_INFO, "Net: %u Node Len: %u Node: %u",
230 net, nodelen_bits, node);
233 ti = proto_tree_add_item(tree, proto_rtmp, tvb, offset,
234 tvb_length_remaining(tvb, offset), FALSE);
235 rtmp_tree = proto_item_add_subtree(ti, ett_rtmp);
237 proto_tree_add_uint(rtmp_tree, hf_rtmp_net, tvb, offset, 2, net);
238 proto_tree_add_uint(rtmp_tree, hf_rtmp_node_len, tvb, offset+2, 1,
240 proto_tree_add_uint(rtmp_tree, hf_rtmp_node, tvb, offset+3, nodelen,
242 offset += 3 + nodelen;
245 while (tvb_offset_exists(tvb, offset)) {
246 proto_tree *tuple_item, *tuple_tree;
249 guint16 tuple_range_end;
251 tuple_net = tvb_get_ntohs(tvb, offset);
252 tuple_dist = tvb_get_guint8(tvb, offset+2);
254 if (tuple_dist & 0x80) {
255 tuple_range_end = tvb_get_ntohs(tvb, offset+3);
256 tuple_item = proto_tree_add_text(rtmp_tree, tvb, offset, 6,
257 "Tuple %d: Range Start: %u Dist: %u Range End: %u",
258 i, tuple_net, tuple_dist&0x7F, tuple_range_end);
260 tuple_item = proto_tree_add_text(rtmp_tree, tvb, offset, 3,
261 "Tuple %d: Net: %u Dist: %u",
262 i, tuple_net, tuple_dist);
264 tuple_tree = proto_item_add_subtree(tuple_item, ett_rtmp_tuple);
266 if (tuple_dist & 0x80) {
267 proto_tree_add_uint(tuple_tree, hf_rtmp_tuple_range_start, tvb, offset, 2,
270 proto_tree_add_uint(tuple_tree, hf_rtmp_tuple_net, tvb, offset, 2,
273 proto_tree_add_uint(tuple_tree, hf_rtmp_tuple_dist, tvb, offset+2, 1,
276 if (tuple_dist & 0x80) {
278 * Extended network tuple.
280 proto_tree_add_item(tuple_tree, hf_rtmp_tuple_range_end, tvb, offset+3, 2,
292 dissect_nbp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
293 proto_tree *nbp_tree;
294 proto_tree *nbp_info_tree;
295 proto_item *ti, *info_item;
301 if (check_col(pinfo->fd, COL_PROTOCOL))
302 col_set_str(pinfo->fd, COL_PROTOCOL, "NBP");
303 if (check_col(pinfo->fd, COL_INFO))
304 col_clear(pinfo->fd, COL_INFO);
306 info = tvb_get_guint8(tvb, offset);
310 if (check_col(pinfo->fd, COL_INFO))
311 col_add_fstr(pinfo->fd, COL_INFO, "Op: %s Count: %u",
312 val_to_str(op, nbp_op_vals, "Unknown (0x%01x)"), count);
315 ti = proto_tree_add_item(tree, proto_nbp, tvb, offset,
316 tvb_length_remaining(tvb, offset), FALSE);
317 nbp_tree = proto_item_add_subtree(ti, ett_nbp);
319 info_item = proto_tree_add_uint_format(nbp_tree, hf_nbp_info, tvb, offset, 1,
321 "Info: 0x%01X Operation: %s Count: %u", info,
322 val_to_str(op, nbp_op_vals, "Unknown (0x%01X)"),
324 nbp_info_tree = proto_item_add_subtree(info_item, ett_nbp_info);
325 proto_tree_add_uint(nbp_info_tree, hf_nbp_op, tvb, offset, 1, info);
326 proto_tree_add_uint(nbp_info_tree, hf_nbp_count, tvb, offset, 1, info);
327 proto_tree_add_item(nbp_tree, hf_nbp_tid, tvb, offset+1, 1, FALSE);
330 for (i=0; i<count; i++) {
331 proto_tree *node_item,*node_tree;
332 int soffset = offset;
334 node_item = proto_tree_add_text(nbp_tree, tvb, offset, 4,
336 node_tree = proto_item_add_subtree(node_item, ett_nbp_node);
338 proto_tree_add_item(node_tree, hf_nbp_node_net, tvb, offset, 2, FALSE);
340 proto_tree_add_item(node_tree, hf_nbp_node_node, tvb, offset, 1, FALSE);
342 proto_tree_add_item(node_tree, hf_nbp_node_port, tvb, offset, 1, FALSE);
344 proto_tree_add_item(node_tree, hf_nbp_node_enum, tvb, offset, 1, FALSE);
347 offset = dissect_pascal_string(tvb, offset, node_tree, hf_nbp_node_object);
348 offset = dissect_pascal_string(tvb, offset, node_tree, hf_nbp_node_type);
349 offset = dissect_pascal_string(tvb, offset, node_tree, hf_nbp_node_zone);
351 proto_item_set_len(node_item, offset-soffset);
359 dissect_ddp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
361 proto_tree *ddp_tree;
363 static struct atalk_ddp_addr src, dst;
366 if (check_col(pinfo->fd, COL_PROTOCOL))
367 col_set_str(pinfo->fd, COL_PROTOCOL, "DDP");
368 if (check_col(pinfo->fd, COL_INFO))
369 col_clear(pinfo->fd, COL_INFO);
371 tvb_memcpy(tvb, (guint8 *)&ddp, 0, sizeof(e_ddp));
372 ddp.dnet=ntohs(ddp.dnet);
373 ddp.snet=ntohs(ddp.snet);
374 ddp.sum=ntohs(ddp.sum);
375 ddp.hops_len=ntohs(ddp.hops_len);
378 src.node = ddp.snode;
379 src.port = ddp.sport;
381 dst.node = ddp.dnode;
382 dst.port = ddp.dport;
383 SET_ADDRESS(&pinfo->net_src, AT_ATALK, sizeof src, (guint8 *)&src);
384 SET_ADDRESS(&pinfo->src, AT_ATALK, sizeof src, (guint8 *)&src);
385 SET_ADDRESS(&pinfo->net_dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
386 SET_ADDRESS(&pinfo->dst, AT_ATALK, sizeof dst, (guint8 *)&dst);
388 if (check_col(pinfo->fd, COL_INFO))
389 col_add_str(pinfo->fd, COL_INFO,
390 val_to_str(ddp.type, op_vals, "Unknown DDP protocol (%02x)"));
393 ti = proto_tree_add_item(tree, proto_ddp, tvb, 0, DDP_HEADER_SIZE,
395 ddp_tree = proto_item_add_subtree(ti, ett_ddp);
396 proto_tree_add_uint(ddp_tree, hf_ddp_hopcount, tvb, 0, 1,
397 ddp_hops(ddp.hops_len));
398 proto_tree_add_uint(ddp_tree, hf_ddp_len, tvb, 0, 2,
399 ddp_len(ddp.hops_len));
400 proto_tree_add_uint(ddp_tree, hf_ddp_checksum, tvb, 2, 2,
402 proto_tree_add_uint(ddp_tree, hf_ddp_dst_net, tvb, 4, 2,
404 proto_tree_add_uint(ddp_tree, hf_ddp_src_net, tvb, 6, 2,
406 proto_tree_add_uint(ddp_tree, hf_ddp_dst_node, tvb, 8, 1,
408 proto_tree_add_uint(ddp_tree, hf_ddp_src_node, tvb, 9, 1,
410 proto_tree_add_uint(ddp_tree, hf_ddp_dst_socket, tvb, 10, 1,
412 proto_tree_add_uint(ddp_tree, hf_ddp_src_socket, tvb, 11, 1,
414 proto_tree_add_uint(ddp_tree, hf_ddp_type, tvb, 12, 1,
418 new_tvb = tvb_new_subset(tvb, DDP_HEADER_SIZE, -1, -1);
420 if (!dissector_try_port(ddp_dissector_table, ddp.type, new_tvb, pinfo, tree))
421 dissect_data(new_tvb, 0, pinfo, tree);
425 proto_register_atalk(void)
427 static hf_register_info hf_ddp[] = {
429 { "Hop count", "ddp.hopcount", FT_UINT8, BASE_DEC, NULL, 0x0,
433 { "Datagram length", "ddp.len", FT_UINT16, BASE_DEC, NULL, 0x0,
437 { "Checksum", "ddp.checksum", FT_UINT16, BASE_DEC, NULL, 0x0,
441 { "Destination Net", "ddp.dst.net", FT_UINT16, BASE_DEC, NULL, 0x0,
445 { "Source Net", "ddp.src.net", FT_UINT16, BASE_DEC, NULL, 0x0,
449 { "Destination Node", "ddp.dst.node", FT_UINT8, BASE_DEC, NULL, 0x0,
453 { "Source Node", "ddp.src.node", FT_UINT8, BASE_DEC, NULL, 0x0,
456 { &hf_ddp_dst_socket,
457 { "Destination Socket", "ddp.dst.socket", FT_UINT8, BASE_DEC, NULL, 0x0,
460 { &hf_ddp_src_socket,
461 { "Source Socket", "ddp.src.socket", FT_UINT8, BASE_DEC, NULL, 0x0,
465 { "Protocol type", "ddp.type", FT_UINT8, BASE_DEC, VALS(op_vals), 0x0,
469 static hf_register_info hf_nbp[] = {
471 { "Operation", "nbp.op", FT_UINT8, BASE_DEC,
472 VALS(nbp_op_vals), 0xF0, "Operation", HFILL }},
474 { "Info", "nbp.info", FT_UINT8, BASE_HEX,
475 NULL, 0x0, "Info", HFILL }},
477 { "Count", "nbp.count", FT_UINT8, BASE_DEC,
478 NULL, 0x0F, "Count", HFILL }},
480 { "Network", "nbp.net", FT_UINT16, BASE_DEC,
481 NULL, 0x0, "Network", HFILL }},
483 { "Node", "nbp.node", FT_UINT8, BASE_DEC,
484 NULL, 0x0, "Node", HFILL }},
486 { "Port", "nbp.port", FT_UINT8, BASE_DEC,
487 NULL, 0x0, "Port", HFILL }},
489 { "Enumerator", "nbp.enum", FT_UINT8, BASE_DEC,
490 NULL, 0x0, "Enumerator", HFILL }},
491 { &hf_nbp_node_object,
492 { "Object", "nbp.object", FT_STRING, BASE_DEC,
493 NULL, 0x0, "Object", HFILL }},
495 { "Type", "nbp.type", FT_STRING, BASE_DEC,
496 NULL, 0x0, "Type", HFILL }},
498 { "Zone", "nbp.zone", FT_STRING, BASE_DEC,
499 NULL, 0x0, "Zone", HFILL }},
501 { "Transaction ID", "nbp.tid", FT_UINT8, BASE_DEC,
502 NULL, 0x0, "Transaction ID", HFILL }}
505 static hf_register_info hf_rtmp[] = {
507 { "Net", "rtmp.net", FT_UINT16, BASE_DEC,
508 NULL, 0x0, "Net", HFILL }},
510 { "Node", "nbp.nodeid", FT_UINT8, BASE_DEC,
511 NULL, 0x0, "Node", HFILL }},
513 { "Node Length", "nbp.nodeid.length", FT_UINT8, BASE_DEC,
514 NULL, 0x0, "Node Length", HFILL }},
515 { &hf_rtmp_tuple_net,
516 { "Net", "rtmp.tuple.net", FT_UINT16, BASE_DEC,
517 NULL, 0x0, "Net", HFILL }},
518 { &hf_rtmp_tuple_range_start,
519 { "Range Start", "rtmp.tuple.range_start", FT_UINT16, BASE_DEC,
520 NULL, 0x0, "Range Start", HFILL }},
521 { &hf_rtmp_tuple_range_end,
522 { "Range End", "rtmp.tuple.range_end", FT_UINT16, BASE_DEC,
523 NULL, 0x0, "Range End", HFILL }},
524 { &hf_rtmp_tuple_dist,
525 { "Distance", "rtmp.tuple.dist", FT_UINT16, BASE_DEC,
526 NULL, 0x0, "Distance", HFILL }},
528 { "Function", "rtmp.function", FT_UINT8, BASE_DEC,
529 VALS(rtmp_function_vals), 0x0, "Request Function", HFILL }}
533 static gint *ett[] = {
543 proto_ddp = proto_register_protocol("Datagram Delivery Protocol", "DDP", "ddp");
544 proto_register_field_array(proto_ddp, hf_ddp, array_length(hf_ddp));
546 proto_nbp = proto_register_protocol("Name Binding Protocol", "NBP", "nbp");
547 proto_register_field_array(proto_nbp, hf_nbp, array_length(hf_nbp));
549 proto_rtmp = proto_register_protocol("Routing Table Maintenance Protocol",
551 proto_register_field_array(proto_rtmp, hf_rtmp, array_length(hf_rtmp));
553 proto_register_subtree_array(ett, array_length(ett));
555 /* subdissector code */
556 ddp_dissector_table = register_dissector_table("ddp.type");
560 proto_reg_handoff_atalk(void)
562 dissector_add("ethertype", ETHERTYPE_ATALK, dissect_ddp, proto_ddp);
563 dissector_add("chdlctype", ETHERTYPE_ATALK, dissect_ddp, proto_ddp);
564 dissector_add("ppp.protocol", PPP_AT, dissect_ddp, proto_ddp);
565 dissector_add("null.type", BSD_AF_APPLETALK, dissect_ddp, proto_ddp);
566 dissector_add("ddp.type", DDP_NBP, dissect_nbp, proto_nbp);
567 dissector_add("ddp.type", DDP_RTMPREQ, dissect_rtmp_request, proto_rtmp);
568 dissector_add("ddp.type", DDP_RTMPDATA, dissect_rtmp_data, proto_rtmp);