Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-auto_rp.c
blob7d4a47e651298e85a10dc85b7f37306035e39f26
1 /* packet-auto_rp.c
2 * Routines for the Cisco Auto-RP protocol
3 * ftp://ftpeng.cisco.com/ftp/ipmulticast/specs/pim-autorp-spec01.txt
5 * Heikki Vatiainen <hessu@cs.tut.fi>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include "config.h"
16 #include <epan/packet.h>
17 #include <epan/to_str.h>
19 #include <wsutil/str_util.h>
21 void proto_register_auto_rp(void);
22 void proto_reg_handoff_auto_rp(void);
24 static dissector_handle_t auto_rp_handle;
26 static int proto_auto_rp;
27 static int ett_auto_rp;
28 static int ett_auto_rp_ver_type;
29 static int ett_auto_rp_map;
30 static int ett_auto_rp_group;
32 static int hf_auto_rp_version;
33 static int hf_auto_rp_type;
34 static int hf_auto_rp_count;
35 static int hf_auto_rp_holdtime;
36 static int hf_auto_rp_pim_ver;
37 static int hf_auto_rp_rp_addr;
38 static int hf_auto_rp_prefix_sgn;
39 static int hf_auto_rp_mask_len;
40 static int hf_auto_rp_group_prefix;
41 static int hf_auto_rp_reserved;
42 static int hf_auto_rp_trailing_junk;
43 static int hf_auto_rp_group_num;
45 #define UDP_PORT_PIM_RP_DISC 496
47 struct auto_rp_fixed_hdr {
48 #define AUTO_RP_VERSION_MASK 0xf0
49 #define AUTO_RP_TYPE_MASK 0x0f
50 uint8_t ver_type; /* pim-autorp-spec01.txt defines version 1+ */
51 uint8_t rp_count; /* Number of struct auto_rp_maps that follow the this header */
52 uint16_t holdtime; /* Time in seconds this announcement is valid. 0 equals forever */
53 uint32_t reserved;
56 struct auto_rp_map_hdr {
57 uint32_t rp_address; /* The unicast IPv4 address of this RP */
58 #define AUTO_RP_PIM_VER_MASK 0x03
59 uint8_t pim_version; /* RP's highest PIM version. 2-bit field */
60 uint8_t group_count; /* Number of encoded group addresses that follow this header */
63 struct auto_rp_enc_grp_hdr { /* Encoded group address */
64 #define AUTO_RP_SIGN_MASK 0x01
65 uint8_t prefix_sgn; /* 0 positive, 1 negative group prefix */
66 uint8_t mask_len; /* Length of group prefix */
67 uint32_t addr; /* Group prefix */
70 #define AUTO_RP_VER_1PLUS 1
71 static const value_string auto_rp_ver_vals[] = {
72 {AUTO_RP_VER_1PLUS, "1 or 1+"},
73 {0, NULL}
76 #define AUTO_RP_TYPE_ANNOUNCEMENT 1
77 #define AUTO_RP_TYPE_MAPPING 2
78 static const value_string auto_rp_type_vals[] = {
79 {AUTO_RP_TYPE_ANNOUNCEMENT, "RP announcement"},
80 {AUTO_RP_TYPE_MAPPING, "RP mapping"},
81 {0, NULL}
84 #define AUTO_RP_PIM_VERSION_UNKNOWN 0x00
85 #define AUTO_RP_PIM_VERSION_1 0x01
86 #define AUTO_RP_PIM_VERSION_2 0x02
87 #define AUTO_RP_PIM_VERSION_DUAL 0x03
88 static const value_string auto_rp_pim_ver_vals[] = {
89 {AUTO_RP_PIM_VERSION_UNKNOWN, "Version unknown"},
90 {AUTO_RP_PIM_VERSION_1, "Version 1"},
91 {AUTO_RP_PIM_VERSION_2, "Version 2"},
92 {AUTO_RP_PIM_VERSION_DUAL, "Dual version 1 and 2"},
93 {0, NULL}
96 #define AUTO_RP_GROUP_MASK_SIGN_POS 0
97 #define AUTO_RP_GROUP_MASK_SIGN_NEG 1
98 static const value_string auto_rp_mask_sign_vals[] = {
99 {AUTO_RP_GROUP_MASK_SIGN_POS, "Positive group prefix"},
100 {AUTO_RP_GROUP_MASK_SIGN_NEG, "Negative group prefix"},
101 {0, NULL}
104 static int do_auto_rp_map(wmem_allocator_t *scope, tvbuff_t *tvb, int offset, proto_tree *auto_rp_tree);
106 static int dissect_auto_rp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
108 uint8_t ver_type, rp_count;
110 col_set_str(pinfo->cinfo, COL_PROTOCOL, "Auto-RP");
111 col_clear(pinfo->cinfo, COL_INFO);
113 ver_type = tvb_get_uint8(tvb, 0);
114 rp_count = tvb_get_uint8(tvb, 1);
115 col_add_fstr(pinfo->cinfo, COL_INFO, "%s (v%s) for %u RP%s",
116 val_to_str_const(lo_nibble(ver_type), auto_rp_type_vals, "Unknown"),
117 val_to_str_const(hi_nibble(ver_type), auto_rp_ver_vals, "Unknown"),
118 rp_count, plurality(rp_count, "", "s"));
120 if (tree) {
121 proto_item *ti;
122 proto_tree *auto_rp_tree, *ver_type_tree;
123 int i, offset;
124 uint16_t holdtime;
126 offset = 0;
127 ti = proto_tree_add_item(tree, proto_auto_rp, tvb, offset, -1, ENC_NA);
128 auto_rp_tree = proto_item_add_subtree(ti, ett_auto_rp);
130 ver_type_tree = proto_tree_add_subtree_format(auto_rp_tree, tvb, offset, 1,
131 ett_auto_rp_ver_type, NULL, "Version: %s, Packet type: %s",
132 val_to_str_const(hi_nibble(ver_type), auto_rp_ver_vals, "Unknown"),
133 val_to_str_const(lo_nibble(ver_type), auto_rp_type_vals, "Unknown"));
134 proto_tree_add_uint(ver_type_tree, hf_auto_rp_version, tvb, offset, 1, ver_type);
135 proto_tree_add_uint(ver_type_tree, hf_auto_rp_type, tvb, offset, 1, ver_type);
136 offset++;
138 proto_tree_add_uint(auto_rp_tree, hf_auto_rp_count, tvb, offset, 1, rp_count);
139 offset++;
141 holdtime = tvb_get_ntohs(tvb, offset);
142 proto_tree_add_uint_format_value(auto_rp_tree, hf_auto_rp_holdtime, tvb, offset, 2, holdtime,
143 "%u second%s", holdtime, plurality(holdtime, "", "s"));
144 offset+=2;
146 proto_tree_add_item(auto_rp_tree, hf_auto_rp_reserved, tvb, offset, 4, ENC_BIG_ENDIAN);
147 offset+=4;
149 for (i = 0; i < rp_count; i++)
150 offset = do_auto_rp_map(pinfo->pool, tvb, offset, auto_rp_tree);
152 if (tvb_reported_length_remaining(tvb, offset) > 0)
153 proto_tree_add_item(tree, hf_auto_rp_trailing_junk, tvb, offset, -1, ENC_NA);
156 return tvb_captured_length(tvb);
160 * Handles one Auto-RP map entry. Returns the new offset.
162 static int do_auto_rp_map(wmem_allocator_t *scope, tvbuff_t *tvb, int offset, proto_tree *auto_rp_tree)
164 proto_tree *map_tree;
165 uint8_t group_count;
166 int i;
168 group_count = tvb_get_uint8(tvb, offset + 5);
170 /* sizeof map header + n * sizeof encoded group addresses */
171 map_tree = proto_tree_add_subtree_format(auto_rp_tree, tvb, offset, 6 + group_count * 6,
172 ett_auto_rp_map, NULL,
173 "RP %s: %u group%s", tvb_ip_to_str(scope, tvb, offset),
174 group_count, plurality(group_count, "", "s"));
176 proto_tree_add_item(map_tree, hf_auto_rp_rp_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
177 offset += 4;
178 proto_tree_add_item(map_tree, hf_auto_rp_pim_ver, tvb, offset, 1, ENC_BIG_ENDIAN);
179 offset++;
180 proto_tree_add_uint(map_tree, hf_auto_rp_group_num, tvb, offset, 1, group_count);
181 offset++;
183 for (i = 0; i < group_count; i++) {
184 proto_tree *grp_tree;
185 uint8_t sign, mask_len;
187 sign = tvb_get_uint8(tvb, offset);
188 mask_len = tvb_get_uint8(tvb, offset + 1);
189 grp_tree = proto_tree_add_subtree_format(map_tree, tvb, offset, 6,
190 ett_auto_rp_group, NULL, "Group %s/%u (%s)",
191 tvb_ip_to_str(scope, tvb, offset + 2), mask_len,
192 val_to_str_const(sign&AUTO_RP_SIGN_MASK, auto_rp_mask_sign_vals, ""));
194 proto_tree_add_uint(grp_tree, hf_auto_rp_prefix_sgn, tvb, offset, 1, sign);
195 offset++;
196 proto_tree_add_uint(grp_tree, hf_auto_rp_mask_len, tvb, offset, 1, mask_len);
197 offset++;
198 proto_tree_add_item(grp_tree, hf_auto_rp_group_prefix, tvb, offset, 4, ENC_BIG_ENDIAN);
199 offset += 4;
203 return offset;
206 void proto_register_auto_rp(void)
208 static hf_register_info hf[] = {
209 { &hf_auto_rp_version,
210 {"Protocol version", "auto_rp.version",
211 FT_UINT8, BASE_DEC, VALS(auto_rp_ver_vals), AUTO_RP_VERSION_MASK,
212 "Auto-RP protocol version", HFILL }},
214 { &hf_auto_rp_type,
215 {"Packet type", "auto_rp.type",
216 FT_UINT8, BASE_DEC, VALS(auto_rp_type_vals), AUTO_RP_TYPE_MASK,
217 "Auto-RP packet type", HFILL }},
219 { &hf_auto_rp_count,
220 {"RP count", "auto_rp.rp_count",
221 FT_UINT8, BASE_DEC, NULL, 0,
222 "The number of RP addresses contained in this message", HFILL }},
224 { &hf_auto_rp_group_num,
225 {"Number of groups this RP maps to", "auto_rp.group_num",
226 FT_UINT8, BASE_DEC, NULL, 0,
227 NULL, HFILL }},
229 { &hf_auto_rp_holdtime,
230 {"Holdtime", "auto_rp.holdtime",
231 FT_UINT16, BASE_DEC, NULL, 0,
232 "The amount of time in seconds this announcement is valid", HFILL }},
234 { &hf_auto_rp_pim_ver,
235 {"Version", "auto_rp.pim_ver",
236 FT_UINT8, BASE_DEC, VALS(auto_rp_pim_ver_vals), AUTO_RP_PIM_VER_MASK,
237 "RP's highest PIM version", HFILL }},
239 { &hf_auto_rp_rp_addr,
240 {"RP address", "auto_rp.rp_addr",
241 FT_IPv4, BASE_NONE, NULL, 0,
242 "The unicast IP address of the RP", HFILL }},
244 { &hf_auto_rp_prefix_sgn,
245 {"Sign", "auto_rp.prefix_sign",
246 FT_UINT8, BASE_DEC, VALS(auto_rp_mask_sign_vals), AUTO_RP_SIGN_MASK,
247 "Group prefix sign", HFILL }},
249 { &hf_auto_rp_mask_len,
250 {"Mask length", "auto_rp.mask_len",
251 FT_UINT8, BASE_DEC, NULL, 0x0,
252 "Length of group prefix", HFILL }},
254 { &hf_auto_rp_group_prefix,
255 {"Prefix", "auto_rp.group_prefix",
256 FT_IPv4, BASE_NONE, NULL, 0,
257 "Group prefix", HFILL }},
259 { &hf_auto_rp_reserved,
260 {"Reserved", "auto_rp.reserved",
261 FT_UINT32, BASE_HEX, NULL, 0,
262 NULL, HFILL }},
264 { &hf_auto_rp_trailing_junk,
265 {"Trailing junk", "auto_rp.trailing_junk",
266 FT_BYTES, BASE_NONE, NULL, 0,
267 NULL, HFILL }},
270 static int *ett[] = {
271 &ett_auto_rp,
272 &ett_auto_rp_ver_type,
273 &ett_auto_rp_map,
274 &ett_auto_rp_group
277 proto_auto_rp = proto_register_protocol("Cisco Auto-RP", "Auto-RP", "auto_rp");
278 proto_register_field_array(proto_auto_rp, hf, array_length(hf));
279 proto_register_subtree_array(ett, array_length(ett));
281 auto_rp_handle = register_dissector("auto_rp", dissect_auto_rp, proto_auto_rp);
284 void
285 proto_reg_handoff_auto_rp(void)
287 dissector_add_uint_with_preference("udp.port", UDP_PORT_PIM_RP_DISC, auto_rp_handle);
291 * Editor modelines - https://www.wireshark.org/tools/modelines.html
293 * Local variables:
294 * c-basic-offset: 8
295 * tab-width: 8
296 * indent-tabs-mode: nil
297 * End:
299 * vi: set shiftwidth=8 tabstop=8 expandtab:
300 * :indentSize=8:tabSize=8:noTabs=true: