epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-msnip.c
blob14f7cc1d91893869388e832ee76b5494bf735a9a
1 /* packet-msnip.c 2001 Ronnie Sahlberg <See AUTHORS for email>
2 * Routines for IGMP/MSNIP packet disassembly
4 * Wireshark - Network traffic analyzer
5 * By Gerald Combs <gerald@wireshark.org>
6 * Copyright 1998 Gerald Combs
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
13 MSNIP
14 code
16 0x23 x
17 0x24 x
18 0x25 x
20 MSNIP " Multicast Source Notification of Interest Protocol
21 Defined in draft-ietf-idmr-igmp-msnip-00.txt
24 #include "config.h"
26 #include <epan/packet.h>
27 #include <epan/expert.h>
28 #include <epan/to_str.h>
29 #include "packet-igmp.h"
31 void proto_register_msnip(void);
32 void proto_reg_handoff_msnip(void);
34 static dissector_handle_t msnip_handle;
36 static int proto_msnip;
37 static int hf_checksum;
38 static int hf_checksum_status;
39 static int hf_type;
40 static int hf_count;
41 static int hf_holdtime;
42 static int hf_groups;
43 static int hf_maddr;
44 static int hf_mask;
45 static int hf_holdtime16;
46 static int hf_genid;
47 static int hf_rec_type;
49 static int ett_msnip;
50 static int ett_groups;
52 static expert_field ei_checksum;
54 #define MC_ALL_IGMPV3_ROUTERS 0xe0000016
56 #define MSNIP_GM 0x23
57 #define MSNIP_IS 0x24
58 #define MSNIP_RMR 0x25
59 static const value_string msnip_types[] = {
60 {MSNIP_GM, "Multicast Group Map"},
61 {MSNIP_IS, "Multicast Interest Solicitation"},
62 {MSNIP_RMR, "Multicast Receiver Membership Report"},
63 {0, NULL}
66 #define MSNIP_RECTYPE_TRANSMIT 1
67 #define MSNIP_RECTYPE_HOLD 2
68 static const value_string msnip_rec_types[] = {
69 {MSNIP_RECTYPE_TRANSMIT, "Request to start transmitting group"},
70 {MSNIP_RECTYPE_HOLD, "Request to hold transmitting group"},
71 {0, NULL}
74 static int
75 dissect_msnip_rmr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
77 uint8_t count;
79 /* group count */
80 count = tvb_get_uint8(tvb, offset);
81 proto_tree_add_uint(parent_tree, hf_count, tvb, offset, 1, count);
82 offset += 1;
84 /* checksum */
85 igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_status, &ei_checksum, pinfo, 0);
86 offset += 2;
88 while (count--) {
89 proto_tree *tree;
90 proto_item *item;
91 uint8_t rec_type;
92 int old_offset = offset;
94 item = proto_tree_add_item(parent_tree, hf_groups,
95 tvb, offset, -1, ENC_NA);
96 tree = proto_item_add_subtree(item, ett_groups);
98 /* record type */
99 rec_type = tvb_get_uint8(tvb, offset);
100 proto_tree_add_uint(tree, hf_rec_type, tvb, offset, 1, rec_type);
101 offset += 1;
103 /* skip 3 unused bytes */
104 offset += 3;
106 /* multicast group */
107 proto_tree_add_item(tree, hf_maddr, tvb, offset, 4, ENC_BIG_ENDIAN);
108 offset += 4;
110 if (item) {
111 proto_item_set_text(item,"Group: %s %s",
112 tvb_ip_to_str(pinfo->pool, tvb, offset-4),
113 val_to_str(rec_type, msnip_rec_types,
114 "Unknown Type:0x%02x"));
116 proto_item_set_len(item, offset-old_offset);
120 return offset;
123 static int
124 dissect_msnip_is(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
127 /* skip reserved byte */
128 offset += 1;
130 /* checksum */
131 igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_status, &ei_checksum, pinfo, 0);
132 offset += 2;
134 /* 16 bit holdtime */
135 proto_tree_add_item(parent_tree, hf_holdtime16, tvb, offset, 2, ENC_BIG_ENDIAN);
136 offset += 2;
138 /* Generation ID */
139 proto_tree_add_item(parent_tree, hf_genid, tvb, offset, 2, ENC_BIG_ENDIAN);
140 offset += 2;
142 return offset;
146 static int
147 dissect_msnip_gm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
149 uint8_t count;
151 /* group count */
152 count = tvb_get_uint8(tvb, offset);
153 proto_tree_add_uint(parent_tree, hf_count, tvb, offset, 1, count);
154 offset += 1;
156 /* checksum */
157 igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_status, &ei_checksum, pinfo, 0);
158 offset += 2;
160 /* holdtime */
161 proto_tree_add_uint(parent_tree, hf_holdtime, tvb, offset, 4, count);
162 offset += 4;
164 while (count--) {
165 proto_tree *tree;
166 proto_item *item;
167 uint8_t masklen;
168 int old_offset = offset;
170 item = proto_tree_add_item(parent_tree, hf_groups,
171 tvb, offset, -1, ENC_NA);
172 tree = proto_item_add_subtree(item, ett_groups);
174 /* multicast group */
175 proto_tree_add_item(tree, hf_maddr, tvb, offset, 4, ENC_BIG_ENDIAN);
176 offset += 4;
178 /* mask length */
179 masklen = tvb_get_uint8(tvb, offset);
180 proto_tree_add_uint(tree, hf_mask, tvb,
181 offset, 1, masklen);
182 offset += 1;
184 /* skip 3 unused bytes */
185 offset += 3;
187 if (item) {
188 proto_item_set_text(item,"Group: %s/%d",
189 tvb_ip_to_str(pinfo->pool, tvb, offset - 8), masklen);
191 proto_item_set_len(item, offset-old_offset);
195 return offset;
199 /* This function is only called from the IGMP dissector */
200 static int
201 dissect_msnip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data _U_)
203 proto_tree *tree;
204 proto_item *item;
205 uint8_t type;
206 int offset = 0;
207 uint32_t dst = g_htonl(MC_ALL_IGMPV3_ROUTERS);
209 /* Shouldn't be destined for us */
210 if ((pinfo->dst.type != AT_IPv4) || memcmp(pinfo->dst.data, &dst, 4))
211 return 0;
213 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MSNIP");
214 col_clear(pinfo->cinfo, COL_INFO);
216 item = proto_tree_add_item(parent_tree, proto_msnip, tvb, offset, -1, ENC_NA);
217 tree = proto_item_add_subtree(item, ett_msnip);
219 type = tvb_get_uint8(tvb, offset);
220 col_add_str(pinfo->cinfo, COL_INFO,
221 val_to_str(type, msnip_types,
222 "Unknown Type:0x%02x"));
224 /* type of command */
225 proto_tree_add_uint(tree, hf_type, tvb, offset, 1, type);
226 offset += 1;
228 switch (type) {
229 case MSNIP_GM:
230 offset = dissect_msnip_gm(tvb, pinfo, tree, offset);
231 break;
232 case MSNIP_IS:
233 offset = dissect_msnip_is(tvb, pinfo, tree, offset);
234 break;
235 case MSNIP_RMR:
236 offset = dissect_msnip_rmr(tvb, pinfo, tree, offset);
237 break;
240 if (item) {
241 proto_item_set_len(item, offset);
244 return offset;
248 void
249 proto_register_msnip(void)
251 static hf_register_info hf[] = {
252 { &hf_type,
253 { "Type", "msnip.type", FT_UINT8, BASE_HEX,
254 VALS(msnip_types), 0, "MSNIP Packet Type", HFILL }},
256 { &hf_checksum,
257 { "Checksum", "msnip.checksum", FT_UINT16, BASE_HEX,
258 NULL, 0, "MSNIP Checksum", HFILL }},
260 { &hf_checksum_status,
261 { "Checksum Status", "msnip.checksum.status", FT_UINT8, BASE_NONE,
262 VALS(proto_checksum_vals), 0x0, NULL, HFILL }},
264 { &hf_count,
265 { "Count", "msnip.count", FT_UINT8, BASE_DEC,
266 NULL, 0, "MSNIP Number of groups", HFILL }},
268 { &hf_holdtime,
269 { "Holdtime", "msnip.holdtime", FT_UINT32, BASE_DEC,
270 NULL, 0, "MSNIP Holdtime in seconds", HFILL }},
272 { &hf_groups,
273 { "Groups", "msnip.groups", FT_NONE, BASE_NONE,
274 NULL, 0, "MSNIP Groups", HFILL }},
276 { &hf_maddr,
277 { "Multicast group", "msnip.maddr", FT_IPv4, BASE_NONE,
278 NULL, 0, "MSNIP Multicast Group", HFILL }},
280 { &hf_mask,
281 { "Netmask", "msnip.netmask", FT_UINT8, BASE_DEC,
282 NULL, 0, "MSNIP Netmask", HFILL }},
284 { &hf_holdtime16,
285 { "Holdtime", "msnip.holdtime16", FT_UINT16, BASE_DEC,
286 NULL, 0, "MSNIP Holdtime in seconds", HFILL }},
288 { &hf_genid,
289 { "Generation ID", "msnip.genid", FT_UINT16, BASE_DEC,
290 NULL, 0, "MSNIP Generation ID", HFILL }},
292 { &hf_rec_type,
293 { "Record Type", "msnip.rec_type", FT_UINT8, BASE_DEC,
294 VALS(msnip_rec_types), 0, "MSNIP Record Type", HFILL }},
297 static int *ett[] = {
298 &ett_msnip,
299 &ett_groups,
302 static ei_register_info ei[] = {
303 { &ei_checksum, { "msnip.bad_checksum", PI_CHECKSUM, PI_ERROR, "Bad checksum", EXPFILL }},
306 expert_module_t* expert_msnip;
308 proto_msnip = proto_register_protocol("MSNIP: Multicast Source Notification of Interest Protocol", "MSNIP", "msnip");
309 proto_register_field_array(proto_msnip, hf, array_length(hf));
310 proto_register_subtree_array(ett, array_length(ett));
311 expert_msnip = expert_register_protocol(proto_msnip);
312 expert_register_field_array(expert_msnip, ei, array_length(ei));
314 msnip_handle = register_dissector("msnip", dissect_msnip, proto_msnip);
317 void
318 proto_reg_handoff_msnip(void)
320 dissector_add_uint("igmp.type", IGMP_TYPE_0x23, msnip_handle);
321 dissector_add_uint("igmp.type", IGMP_TYPE_0x24, msnip_handle);
322 dissector_add_uint("igmp.type", IGMP_TYPE_0x25, msnip_handle);
326 * Editor modelines - https://www.wireshark.org/tools/modelines.html
328 * Local variables:
329 * c-basic-offset: 8
330 * tab-width: 8
331 * indent-tabs-mode: t
332 * End:
334 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
335 * :indentSize=8:tabSize=8:noTabs=false: