2 * Routines for Banyan VINES protocol packet disassembly
4 * $Id: packet-vines.c,v 1.36 2001/12/03 03:59:40 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>
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(const u_char *pd, int offset, int len, 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->fd, COL_PROTOCOL))
97 col_set_str(pinfo->fd, COL_PROTOCOL, "Vines FRP");
98 if (check_col(pinfo->fd, COL_INFO))
99 col_clear(pinfo->fd, 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->fd, COL_PROTOCOL))
192 col_set_str(pinfo->fd, COL_PROTOCOL, "Vines");
193 if (check_col(pinfo->fd, COL_INFO))
194 col_clear(pinfo->fd, 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->fd, COL_PROTOCOL))
211 col_set_str(pinfo->fd, COL_PROTOCOL, "Vines IPC");
212 if (check_col(pinfo->fd, COL_INFO))
213 col_add_fstr(pinfo->fd, COL_INFO, "IPC (%02x)", viph.vip_proto);
216 if (check_col(pinfo->fd, COL_PROTOCOL))
217 col_set_str(pinfo->fd, COL_PROTOCOL, "Vines SPP");
218 if (check_col(pinfo->fd, COL_INFO))
219 col_add_fstr(pinfo->fd, COL_INFO, "SPP (%02x)", viph.vip_proto);
222 if (check_col(pinfo->fd, COL_PROTOCOL))
223 col_set_str(pinfo->fd, COL_PROTOCOL, "Vines ARP");
224 if (check_col(pinfo->fd, COL_INFO))
225 col_add_fstr(pinfo->fd, COL_INFO, "ARP (%02x)", viph.vip_proto);
228 if (check_col(pinfo->fd, COL_PROTOCOL))
229 col_set_str(pinfo->fd, COL_PROTOCOL, "Vines RTP");
230 if (check_col(pinfo->fd, COL_INFO))
231 col_add_fstr(pinfo->fd, COL_INFO, "RTP (%02x)", viph.vip_proto);
234 if (check_col(pinfo->fd, COL_PROTOCOL))
235 col_set_str(pinfo->fd, COL_PROTOCOL, "Vines ICP");
236 if (check_col(pinfo->fd, COL_INFO))
237 col_add_fstr(pinfo->fd, COL_INFO, "ICP (%02x)", viph.vip_proto);
240 if (check_col(pinfo->fd, COL_PROTOCOL))
241 col_set_str(pinfo->fd, COL_PROTOCOL, "Vines IP");
242 if (check_col(pinfo->fd, COL_INFO))
243 col_add_fstr(pinfo->fd, 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");
341 register_dissector("vines", dissect_vines, proto_vines);
342 vines_handle = find_dissector("vines");
346 proto_reg_handoff_vines(void)
348 dissector_add("ethertype", ETHERTYPE_VINES, vines_handle);
349 dissector_add("ppp.protocol", PPP_VINES, vines_handle);
350 data_handle = find_dissector("data");
354 dissect_vines_spp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
358 proto_tree *vspp_tree;
361 if (check_col(pinfo->fd, COL_PROTOCOL))
362 col_set_str(pinfo->fd, COL_PROTOCOL, "VSPP");
363 if (check_col(pinfo->fd, COL_INFO))
364 col_clear(pinfo->fd, COL_INFO);
366 /* To do: check for runts, errs, etc. */
368 /* Avoids alignment problems on many architectures. */
369 tvb_memcpy(tvb, (guint8 *)&viph, offset, sizeof(e_vspp));
371 viph.vspp_sport = ntohs(viph.vspp_sport);
372 viph.vspp_dport = ntohs(viph.vspp_dport);
373 viph.vspp_lclid = ntohs(viph.vspp_lclid);
374 viph.vspp_rmtid = ntohs(viph.vspp_rmtid);
376 switch (viph.vspp_pkttype) {
377 case VSPP_PKTTYPE_DATA:
378 if (check_col(pinfo->fd, COL_PROTOCOL))
379 col_set_str(pinfo->fd, COL_PROTOCOL, "VSPP Data");
381 case VSPP_PKTTYPE_DISC:
382 if (check_col(pinfo->fd, COL_PROTOCOL))
383 col_set_str(pinfo->fd, COL_PROTOCOL, "VSPP Disconnect");
385 case VSPP_PKTTYPE_PROBE:
386 if (check_col(pinfo->fd, COL_PROTOCOL))
387 col_set_str(pinfo->fd, COL_PROTOCOL, "VSPP Probe");
389 case VSPP_PKTTYPE_ACK:
390 if (check_col(pinfo->fd, COL_PROTOCOL))
391 col_set_str(pinfo->fd, COL_PROTOCOL, "VSPP Ack");
394 if (check_col(pinfo->fd, COL_PROTOCOL))
395 col_set_str(pinfo->fd, COL_PROTOCOL, "VSPP Unknown");
398 if (check_col(pinfo->fd, COL_INFO))
399 col_add_fstr(pinfo->fd, COL_INFO,
400 "NS=%04x NR=%04x Window=%04x RID=%04x LID=%04x D=%04x S=%04x",
401 viph.vspp_seqno, viph.vspp_ack, viph.vspp_win,
402 viph.vspp_rmtid, viph.vspp_lclid, viph.vspp_dport,
406 iph.ip_tos = IPTOS_TOS(iph.ip_tos);
407 switch (iph.ip_tos) {
409 strcpy(tos_str, "None");
412 strcpy(tos_str, "Minimize delay");
414 case IPTOS_THROUGHPUT:
415 strcpy(tos_str, "Maximize throughput");
417 case IPTOS_RELIABILITY:
418 strcpy(tos_str, "Maximize reliability");
421 strcpy(tos_str, "Minimize cost");
424 strcpy(tos_str, "Unknon. Malformed?");
430 ti = proto_tree_add_item(tree, proto_vines_spp, tvb, offset,
431 sizeof(viph), FALSE);
432 vspp_tree = proto_item_add_subtree(ti, ett_vines_spp);
433 proto_tree_add_text(vspp_tree, tvb, offset, 2,
434 "Source port: 0x%04x", viph.vspp_sport);
435 proto_tree_add_text(vspp_tree, tvb, offset + 2, 2,
436 "Destination port: 0x%04x",
438 proto_tree_add_text(vspp_tree, tvb, offset + 4, 1,
439 "Packet type: 0x%02x", viph.vspp_pkttype);
440 proto_tree_add_text(vspp_tree, tvb, offset + 5, 1,
441 "Control: 0x%02x", viph.vspp_control);
442 proto_tree_add_text(vspp_tree, tvb, offset + 6, 2,
443 "Local Connection ID: 0x%04x",
445 proto_tree_add_text(vspp_tree, tvb, offset + 8, 2,
446 "Remote Connection ID: 0x%04x",
448 proto_tree_add_text(vspp_tree, tvb, offset + 10, 2,
449 "Sequence number: 0x%04x",
451 proto_tree_add_text(vspp_tree, tvb, offset + 12, 2,
452 "Ack number: 0x%04x", viph.vspp_ack);
453 proto_tree_add_text(vspp_tree, tvb, offset + 14, 2,
454 "Window: 0x%04x", viph.vspp_win);
456 offset += 16; /* sizeof SPP */
457 call_dissector(data_handle,tvb_new_subset(tvb, offset,-1,tvb_reported_length_remaining(tvb,offset)), pinfo, tree);
461 proto_register_vines_spp(void)
463 static gint *ett[] = {
467 proto_vines_spp = proto_register_protocol("Banyan Vines SPP",
468 "Vines SPP", "vines_spp");
469 proto_register_subtree_array(ett, array_length(ett));
473 proto_reg_handoff_vines_spp(void)
475 dissector_handle_t vines_spp_handle;
477 vines_spp_handle = create_dissector_handle(dissect_vines_spp,
479 dissector_add("vines.proto", VIP_PROTO_SPP, vines_spp_handle);