create_dissector_handle -> new_create_dissector_handle
[metze/wireshark/wip.git] / epan / dissectors / packet-ipoib.c
1 /* packet-ipoib.c
2  * Routines for decoding IP over InfiniBand (IPoIB) packet disassembly
3  * See: http://tools.ietf.org/html/rfc4391#section-6
4  *
5  * Wireshark - Network traffic analyzer
6  * By Gerald Combs <gerald@wireshark.org>
7  * Copyright 1998 Gerald Combs
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22  */
23
24 #include "config.h"
25
26 #include <epan/packet.h>
27 #include <epan/etypes.h>
28 #include <wiretap/wtap.h>
29
30 void proto_register_ipoib(void);
31 void proto_reg_handoff_ipoib(void);
32
33 static int proto_ipoib = -1;
34 static int hf_type     = -1;
35 static int hf_reserved = -1;
36
37 static gint ett_raw = -1;
38
39 static dissector_handle_t arp_handle;
40 static dissector_handle_t ip_handle;
41 static dissector_handle_t ipv6_handle;
42
43 static int
44 dissect_ipoib(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
45 {
46   proto_tree *fh_tree;
47   proto_item *ti;
48   tvbuff_t   *next_tvb;
49   guint16     type;
50
51   /* load the top pane info. This should be overwritten by
52      the next protocol in the stack */
53   col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPoIB");
54   col_set_str(pinfo->cinfo, COL_INFO, "IP over Infiniband");
55
56   /* populate a tree in the second pane with the IPoIB header data */
57   if (tree) {
58     ti = proto_tree_add_item (tree, proto_ipoib, tvb, 0, 4, ENC_NA);
59     fh_tree = proto_item_add_subtree(ti, ett_raw);
60
61     proto_tree_add_item(fh_tree, hf_type, tvb, 0, 2, ENC_BIG_ENDIAN);
62     proto_tree_add_item(fh_tree, hf_reserved, tvb, 2, 2, ENC_BIG_ENDIAN);
63   }
64
65   next_tvb = tvb_new_subset_remaining(tvb, 4);
66
67   type = tvb_get_ntohs(tvb, 0);
68   switch (type) {
69   case ETHERTYPE_IP:
70     call_dissector(ip_handle, next_tvb, pinfo, tree);
71     break;
72   case ETHERTYPE_IPv6:
73     call_dissector(ipv6_handle, next_tvb, pinfo, tree);
74     break;
75   case ETHERTYPE_ARP:
76   case ETHERTYPE_REVARP:
77     call_dissector(arp_handle, next_tvb, pinfo, tree);
78     break;
79   default:
80     break;
81   }
82   return tvb_captured_length(tvb);
83 }
84
85 void
86 proto_register_ipoib(void)
87 {
88   static hf_register_info hf[] = {
89     { &hf_type,
90       { "Type", "ipoib.type",
91         FT_UINT16, BASE_HEX, VALS(etype_vals), 0x0,
92         NULL, HFILL }},
93     { &hf_reserved,
94       { "Reserved",  "ipoib.reserved",
95         FT_UINT16, BASE_HEX, NULL, 0x0,
96         NULL, HFILL }}
97   };
98
99   static gint *ett[] = {
100     &ett_raw
101   };
102
103   proto_ipoib = proto_register_protocol("IP over Infiniband", "IPoIB", "ipoib");
104   proto_register_field_array(proto_ipoib, hf, array_length(hf));
105   proto_register_subtree_array(ett, array_length(ett));
106 }
107
108 void
109 proto_reg_handoff_ipoib(void)
110 {
111   dissector_handle_t ipoib_handle;
112
113   /*
114    * Get handles for the ARP, IP and IPv6 dissectors.
115    */
116   arp_handle  = find_dissector("arp");
117   ip_handle   = find_dissector("ip");
118   ipv6_handle = find_dissector("ipv6");
119
120   ipoib_handle = new_create_dissector_handle(dissect_ipoib, proto_ipoib);
121   dissector_add_uint("wtap_encap", WTAP_ENCAP_IP_OVER_IB, ipoib_handle);
122 }
123
124 /*
125  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
126  *
127  * Local Variables:
128  * c-basic-offset: 2
129  * tab-width: 8
130  * indent-tabs-mode: nil
131  * End:
132  *
133  * ex: set shiftwidth=2 tabstop=8 expandtab:
134  * :indentSize=2:tabSize=8:noTabs=true:
135  */