2 * Routines for Banyan VINES protocol packet disassembly
4 * $Id: packet-vines.c,v 1.40 2002/04/24 06:03:34 guy Exp $
6 * Don Lafontaine <lafont02@cn.ca>
8 * Ethereal - Network traffic analyzer
9 * By Gerald Combs <gerald@ethereal.com>
10 * Copyright 1998 Gerald Combs
11 * Joerg Mayer <jmayer@loplof.de>
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #ifdef HAVE_SYS_TYPES_H
33 #include <sys/types.h>
36 #ifdef HAVE_NETINET_IN_H
37 #include <netinet/in.h>
42 #include <epan/packet.h>
43 #include "packet-vines.h"
48 #define UDP_PORT_VINES 573
50 static int proto_vines = -1;
51 static int hf_vines_protocol = -1;
53 static gint ett_vines = -1;
55 static int proto_vines_frp = -1;
57 static gint ett_vines_frp = -1;
59 static int proto_vines_spp = -1;
61 static gint ett_vines_spp = -1;
63 static void dissect_vines_frp(tvbuff_t *, packet_info *, proto_tree *);
65 static void dissect_vines_arp(tvbuff_t *, packet_info *, proto_tree *);
66 static void dissect_vines_icp(tvbuff_t *, packet_info *, proto_tree *);
67 static void dissect_vines_ipc(tvbuff_t *, packet_info *, proto_tree *);
68 static void dissect_vines_rtp(tvbuff_t *, packet_info *, proto_tree *);
70 static void dissect_vines_spp(tvbuff_t *, packet_info *, proto_tree *);
71 static void dissect_vines(tvbuff_t *, packet_info *, proto_tree *);
74 capture_vines(packet_counts *ld)
79 static dissector_handle_t vines_handle;
80 static dissector_handle_t data_handle;
82 /* AFAIK Vines FRP (Fragmentation Protocol) is used on all media except
83 * Ethernet and TR (and probably FDDI) - Fragmentation on these media types
85 * FIXME: Do we need to use this header with PPP too?
88 dissect_vines_frp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
90 guint8 vines_frp_ctrl;
91 proto_tree *vines_frp_tree;
93 gchar frp_flags_str[32];
96 if (check_col(pinfo->cinfo, COL_PROTOCOL))
97 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines FRP");
98 if (check_col(pinfo->cinfo, COL_INFO))
99 col_clear(pinfo->cinfo, COL_INFO);
102 ti = proto_tree_add_item(tree, proto_vines_frp, tvb, 0, 2,
104 vines_frp_tree = proto_item_add_subtree(ti, ett_vines_frp);
106 vines_frp_ctrl = tvb_get_guint8(tvb, 0);
109 * 1: first fragment of vines packet
110 * 2: last fragment of vines packet
113 switch (vines_frp_ctrl) {
116 strcpy(frp_flags_str, "middle");
120 strcpy(frp_flags_str, "first");
124 strcpy(frp_flags_str, "last");
128 strcpy(frp_flags_str, "only");
132 strcpy(frp_flags_str, "please report: unknown");
136 proto_tree_add_text(vines_frp_tree, tvb, 0, 1,
137 "Control Flags: 0x%02x = %s fragment",
138 vines_frp_ctrl, frp_flags_str);
140 proto_tree_add_text(vines_frp_tree, tvb, 1, 1,
141 "Sequence Number: 0x%02x",
142 tvb_get_guint8(tvb, 1));
145 /* Decode the "real" Vines now */
146 next_tvb = tvb_new_subset(tvb, 2, -1, -1);
147 call_dissector(vines_handle, next_tvb, pinfo, tree);
151 proto_register_vines_frp(void)
153 static gint *ett[] = {
157 proto_vines_frp = proto_register_protocol(
158 "Banyan Vines Fragmentation Protocol", "Vines FRP", "vines_frp");
159 proto_register_subtree_array(ett, array_length(ett));
163 proto_reg_handoff_vines_frp(void)
165 dissector_handle_t vines_frp_handle;
167 vines_frp_handle = create_dissector_handle(dissect_vines_frp,
169 dissector_add("ip.proto", IP_PROTO_VINES, vines_frp_handle);
171 /* XXX: AFAIK, src and dst port must be the same; should
172 the dissector check for that? */
173 dissector_add("udp.port", UDP_PORT_VINES, vines_frp_handle);
176 static dissector_table_t vines_dissector_table;
179 dissect_vines(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
183 proto_tree *vip_tree;
185 /* gchar tos_str[32]; */
186 const guint8 *dst_addr, *src_addr;
187 int is_broadcast = 0;
191 if (check_col(pinfo->cinfo, COL_PROTOCOL))
192 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines");
193 if (check_col(pinfo->cinfo, COL_INFO))
194 col_clear(pinfo->cinfo, COL_INFO);
196 /* To do: check for runts, errs, etc. */
198 /* Avoids alignment problems on many architectures. */
199 tvb_memcpy(tvb, (guint8 *)&viph, offset, sizeof(e_vip));
201 viph.vip_chksum = ntohs(viph.vip_chksum);
202 viph.vip_pktlen = ntohs(viph.vip_pktlen);
203 viph.vip_dnet = ntohl(viph.vip_dnet);
204 viph.vip_dsub = ntohs(viph.vip_dsub);
205 viph.vip_snet = ntohl(viph.vip_snet);
206 viph.vip_ssub = ntohs(viph.vip_ssub);
208 switch (viph.vip_proto) {
210 if (check_col(pinfo->cinfo, COL_PROTOCOL))
211 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines IPC");
212 if (check_col(pinfo->cinfo, COL_INFO))
213 col_add_fstr(pinfo->cinfo, COL_INFO, "IPC (%02x)", viph.vip_proto);
216 if (check_col(pinfo->cinfo, COL_PROTOCOL))
217 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines SPP");
218 if (check_col(pinfo->cinfo, COL_INFO))
219 col_add_fstr(pinfo->cinfo, COL_INFO, "SPP (%02x)", viph.vip_proto);
222 if (check_col(pinfo->cinfo, COL_PROTOCOL))
223 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines ARP");
224 if (check_col(pinfo->cinfo, COL_INFO))
225 col_add_fstr(pinfo->cinfo, COL_INFO, "ARP (%02x)", viph.vip_proto);
228 if (check_col(pinfo->cinfo, COL_PROTOCOL))
229 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines RTP");
230 if (check_col(pinfo->cinfo, COL_INFO))
231 col_add_fstr(pinfo->cinfo, COL_INFO, "RTP (%02x)", viph.vip_proto);
234 if (check_col(pinfo->cinfo, COL_PROTOCOL))
235 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines ICP");
236 if (check_col(pinfo->cinfo, COL_INFO))
237 col_add_fstr(pinfo->cinfo, COL_INFO, "ICP (%02x)", viph.vip_proto);
240 if (check_col(pinfo->cinfo, COL_PROTOCOL))
241 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Vines IP");
242 if (check_col(pinfo->cinfo, COL_INFO))
243 col_add_fstr(pinfo->cinfo, COL_INFO, "Unknown VIP protocol (%02x)",
247 src_addr = tvb_get_ptr(tvb, offset+12, VINES_ADDR_LEN);
248 SET_ADDRESS(&pinfo->net_src, AT_VINES, VINES_ADDR_LEN, src_addr);
249 SET_ADDRESS(&pinfo->src, AT_VINES, VINES_ADDR_LEN, src_addr);
250 dst_addr = tvb_get_ptr(tvb, offset+6, VINES_ADDR_LEN);
251 SET_ADDRESS(&pinfo->net_dst, AT_VINES, VINES_ADDR_LEN,dst_addr);
252 SET_ADDRESS(&pinfo->dst, AT_VINES, VINES_ADDR_LEN, dst_addr);
254 /* helpers to decode flags */
255 /* FIXME: Not used yet */
256 if ((viph.vip_dnet == 0xffffffff) && (viph.vip_dsub == 0xffff)) {
259 hops = viph.vip_tctl & 0xf;
262 viph.ip_tos = IPTOS_TOS(viph.ip_tos);
263 switch (viph.ip_tos) {
265 strcpy(tos_str, "None");
268 strcpy(tos_str, "Minimize delay");
270 case IPTOS_THROUGHPUT:
271 strcpy(tos_str, "Maximize throughput");
273 case IPTOS_RELIABILITY:
274 strcpy(tos_str, "Maximize reliability");
277 strcpy(tos_str, "Minimize cost");
280 strcpy(tos_str, "Unknon. Malformed?");
286 ti = proto_tree_add_protocol_format(tree, proto_vines, tvb,
287 offset, (viph.vip_pktlen),
289 vip_tree = proto_item_add_subtree(ti, ett_vines);
290 proto_tree_add_text(vip_tree, tvb, offset, 2,
291 "Packet checksum: 0x%04x",
293 proto_tree_add_text(vip_tree, tvb, offset + 2, 2,
294 "Packet length: 0x%04x (%d)",
295 viph.vip_pktlen, viph.vip_pktlen);
296 proto_tree_add_text(vip_tree, tvb, offset + 4, 1,
297 "Transport control: 0x%02x",
299 proto_tree_add_uint(vip_tree, hf_vines_protocol, tvb,
302 proto_tree_add_text(vip_tree, tvb, offset + 6,
305 vines_addr_to_str(dst_addr));
306 proto_tree_add_text(vip_tree, tvb, offset + 12,
309 vines_addr_to_str(src_addr));
314 next_tvb = tvb_new_subset(tvb, offset, -1, -1);
315 if (!dissector_try_port(vines_dissector_table, viph.vip_proto,
316 next_tvb, pinfo, tree))
317 call_dissector(data_handle,next_tvb, pinfo, tree);
321 proto_register_vines(void)
323 static gint *ett[] = {
327 static hf_register_info hf[] = {
328 { &hf_vines_protocol,
329 { "Protocol", "vines.protocol",
330 FT_UINT8, BASE_HEX, NULL, 0x0,
331 "Vines protocol", HFILL }}
334 proto_vines = proto_register_protocol("Banyan Vines", "Vines", "vines");
335 proto_register_field_array(proto_vines, hf, array_length(hf));
336 proto_register_subtree_array(ett, array_length(ett));
338 /* subdissector code */
339 vines_dissector_table = register_dissector_table("vines.proto",
340 "Vines protocol", FT_UINT8, BASE_HEX);
342 register_dissector("vines", dissect_vines, proto_vines);
343 vines_handle = find_dissector("vines");
347 proto_reg_handoff_vines(void)
349 dissector_add("ethertype", ETHERTYPE_VINES, vines_handle);
350 dissector_add("ppp.protocol", PPP_VINES, vines_handle);
351 data_handle = find_dissector("data");
355 dissect_vines_spp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
359 proto_tree *vspp_tree;
362 if (check_col(pinfo->cinfo, COL_PROTOCOL))
363 col_set_str(pinfo->cinfo, COL_PROTOCOL, "VSPP");
364 if (check_col(pinfo->cinfo, COL_INFO))
365 col_clear(pinfo->cinfo, COL_INFO);
367 /* To do: check for runts, errs, etc. */
369 /* Avoids alignment problems on many architectures. */
370 tvb_memcpy(tvb, (guint8 *)&viph, offset, sizeof(e_vspp));
372 viph.vspp_sport = ntohs(viph.vspp_sport);
373 viph.vspp_dport = ntohs(viph.vspp_dport);
374 viph.vspp_lclid = ntohs(viph.vspp_lclid);
375 viph.vspp_rmtid = ntohs(viph.vspp_rmtid);
377 switch (viph.vspp_pkttype) {
378 case VSPP_PKTTYPE_DATA:
379 if (check_col(pinfo->cinfo, COL_PROTOCOL))
380 col_set_str(pinfo->cinfo, COL_PROTOCOL, "VSPP Data");
382 case VSPP_PKTTYPE_DISC:
383 if (check_col(pinfo->cinfo, COL_PROTOCOL))
384 col_set_str(pinfo->cinfo, COL_PROTOCOL, "VSPP Disconnect");
386 case VSPP_PKTTYPE_PROBE:
387 if (check_col(pinfo->cinfo, COL_PROTOCOL))
388 col_set_str(pinfo->cinfo, COL_PROTOCOL, "VSPP Probe");
390 case VSPP_PKTTYPE_ACK:
391 if (check_col(pinfo->cinfo, COL_PROTOCOL))
392 col_set_str(pinfo->cinfo, COL_PROTOCOL, "VSPP Ack");
395 if (check_col(pinfo->cinfo, COL_PROTOCOL))
396 col_set_str(pinfo->cinfo, COL_PROTOCOL, "VSPP Unknown");
399 if (check_col(pinfo->cinfo, COL_INFO))
400 col_add_fstr(pinfo->cinfo, COL_INFO,
401 "NS=%04x NR=%04x Window=%04x RID=%04x LID=%04x D=%04x S=%04x",
402 viph.vspp_seqno, viph.vspp_ack, viph.vspp_win,
403 viph.vspp_rmtid, viph.vspp_lclid, viph.vspp_dport,
407 iph.ip_tos = IPTOS_TOS(iph.ip_tos);
408 switch (iph.ip_tos) {
410 strcpy(tos_str, "None");
413 strcpy(tos_str, "Minimize delay");
415 case IPTOS_THROUGHPUT:
416 strcpy(tos_str, "Maximize throughput");
418 case IPTOS_RELIABILITY:
419 strcpy(tos_str, "Maximize reliability");
422 strcpy(tos_str, "Minimize cost");
425 strcpy(tos_str, "Unknon. Malformed?");
431 ti = proto_tree_add_item(tree, proto_vines_spp, tvb, offset,
432 sizeof(viph), FALSE);
433 vspp_tree = proto_item_add_subtree(ti, ett_vines_spp);
434 proto_tree_add_text(vspp_tree, tvb, offset, 2,
435 "Source port: 0x%04x", viph.vspp_sport);
436 proto_tree_add_text(vspp_tree, tvb, offset + 2, 2,
437 "Destination port: 0x%04x",
439 proto_tree_add_text(vspp_tree, tvb, offset + 4, 1,
440 "Packet type: 0x%02x", viph.vspp_pkttype);
441 proto_tree_add_text(vspp_tree, tvb, offset + 5, 1,
442 "Control: 0x%02x", viph.vspp_control);
443 proto_tree_add_text(vspp_tree, tvb, offset + 6, 2,
444 "Local Connection ID: 0x%04x",
446 proto_tree_add_text(vspp_tree, tvb, offset + 8, 2,
447 "Remote Connection ID: 0x%04x",
449 proto_tree_add_text(vspp_tree, tvb, offset + 10, 2,
450 "Sequence number: 0x%04x",
452 proto_tree_add_text(vspp_tree, tvb, offset + 12, 2,
453 "Ack number: 0x%04x", viph.vspp_ack);
454 proto_tree_add_text(vspp_tree, tvb, offset + 14, 2,
455 "Window: 0x%04x", viph.vspp_win);
457 offset += 16; /* sizeof SPP */
458 call_dissector(data_handle,tvb_new_subset(tvb, offset,-1,tvb_reported_length_remaining(tvb,offset)), pinfo, tree);
462 proto_register_vines_spp(void)
464 static gint *ett[] = {
468 proto_vines_spp = proto_register_protocol("Banyan Vines SPP",
469 "Vines SPP", "vines_spp");
470 proto_register_subtree_array(ett, array_length(ett));
474 proto_reg_handoff_vines_spp(void)
476 dissector_handle_t vines_spp_handle;
478 vines_spp_handle = create_dissector_handle(dissect_vines_spp,
480 dissector_add("vines.proto", VIP_PROTO_SPP, vines_spp_handle);