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