/src/wireshark/epan/dissectors/packet-mplstp-oam.c
Line | Count | Source |
1 | | /* packet-mplstp-oam.c |
2 | | * |
3 | | * Routines for MPLS-TP Lock Instruct Protocol : RFC 6435 |
4 | | * MPLS-TP Fault-Management Protocol : RFC 6427 |
5 | | * |
6 | | * Authors: |
7 | | * Krishnamurthy Mayya <krishnamurthymayya@gmail.com> |
8 | | * Nikitha Malgi <nikitha01@gmail.com> |
9 | | * |
10 | | * Wireshark - Network traffic analyzer |
11 | | * By Gerald Combs <gerald@wireshark.org> |
12 | | * Copyright 1998 Gerald Combs |
13 | | * |
14 | | * SPDX-License-Identifier: GPL-2.0-or-later |
15 | | */ |
16 | | |
17 | | #include "config.h" |
18 | | #include <epan/packet.h> |
19 | | #include "packet-bfd.h" |
20 | | #include "packet-mpls.h" |
21 | | |
22 | | void proto_register_mplstp_lock(void); |
23 | | void proto_register_mplstp_fm(void); |
24 | | void proto_reg_handoff_mplstp_lock(void); |
25 | | void proto_reg_handoff_mplstp_fm(void); |
26 | | |
27 | | static dissector_handle_t mplstp_lock_handle; |
28 | | static dissector_handle_t mplstp_fm_handle; |
29 | | |
30 | | /* MPLS-TP FM protocol specific variables */ |
31 | | static int proto_mplstp_fm; |
32 | | static int ett_mplstp_fm; |
33 | | static int ett_mplstp_fm_flags; |
34 | | static int ett_mplstp_fm_tlv_tree; |
35 | | |
36 | | static int hf_mplstp_fm_version; |
37 | | |
38 | | static int hf_mplstp_fm_reserved; |
39 | | static int hf_mplstp_fm_msg_type; |
40 | | static int hf_mplstp_fm_flags; |
41 | | static int hf_mplstp_fm_flags_l; |
42 | | static int hf_mplstp_fm_flags_r; |
43 | | static int hf_mplstp_fm_refresh_timer; |
44 | | static int hf_mplstp_fm_total_tlv_len; |
45 | | static int hf_mplstp_fm_if_tlv_type; |
46 | | static int hf_mplstp_fm_global_tlv_type; |
47 | | static int hf_mplstp_fm_tlv_len; |
48 | | static int hf_mplstp_fm_node_id; |
49 | | static int hf_mplstp_fm_if_num; |
50 | | static int hf_mplstp_fm_global_id; |
51 | | |
52 | | static const value_string fm_msg_type[] = { |
53 | | {0, "No Return Code"}, |
54 | | {1, "Alarm-Indication Signal(A)"}, |
55 | | {2, "Lock-Report(L)"}, |
56 | | {0, NULL} |
57 | | }; |
58 | | |
59 | | /* MPLS-TP Lock protocol specific variables */ |
60 | | static int proto_mplstp_lock; |
61 | | static int ett_mplstp_lock; |
62 | | |
63 | | static int hf_mplstp_lock_version; |
64 | | static int hf_mplstp_lock_reserved; |
65 | | static int hf_mplstp_lock_refresh_timer; |
66 | | |
67 | | static void |
68 | | dissect_mplstp_fm_tlv (tvbuff_t *tvb, proto_tree *tree) |
69 | 0 | { |
70 | 0 | proto_item *ti; |
71 | 0 | proto_tree *fm_tlv_tree; |
72 | |
|
73 | 0 | unsigned offset = 0; |
74 | |
|
75 | 0 | if (!tree) |
76 | 0 | return; |
77 | | |
78 | 0 | ti = proto_tree_add_protocol_format (tree, proto_mplstp_fm, tvb, offset, 16, |
79 | 0 | "Fault-Management TLVs"); |
80 | |
|
81 | 0 | fm_tlv_tree = proto_item_add_subtree (ti, ett_mplstp_fm_tlv_tree); |
82 | |
|
83 | 0 | proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_if_tlv_type , tvb, offset, |
84 | 0 | 1, ENC_BIG_ENDIAN); |
85 | 0 | offset = offset + 1; |
86 | 0 | proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_tlv_len, tvb, offset, |
87 | 0 | 1, ENC_BIG_ENDIAN); |
88 | 0 | offset = offset + 1; |
89 | 0 | proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_node_id, tvb, offset, |
90 | 0 | 4, ENC_BIG_ENDIAN); |
91 | 0 | offset = offset + 4; |
92 | 0 | proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_if_num, tvb, offset, |
93 | 0 | 4, ENC_BIG_ENDIAN); |
94 | 0 | offset = offset + 4; |
95 | 0 | proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_global_tlv_type , tvb, offset, |
96 | 0 | 1, ENC_BIG_ENDIAN); |
97 | 0 | offset = offset + 1; |
98 | 0 | proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_tlv_len, tvb, offset, |
99 | 0 | 1, ENC_BIG_ENDIAN); |
100 | 0 | offset = offset + 1; |
101 | 0 | proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_global_id, tvb, offset, |
102 | 0 | 4, ENC_BIG_ENDIAN); |
103 | | /* offset = offset + 4; */ |
104 | |
|
105 | 0 | return; |
106 | 0 | } |
107 | | |
108 | | /* Dissector for MPLS-TP LI protocol: RFC 6435 */ |
109 | | static int |
110 | | dissect_mplstp_lock(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) |
111 | 1 | { |
112 | 1 | proto_item *ti; |
113 | 1 | proto_tree *lock_tree; |
114 | 1 | tvbuff_t *next_tvb; |
115 | | |
116 | 1 | uint8_t offset = 0; |
117 | | |
118 | 1 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPLS-TP LI"); |
119 | 1 | col_clear(pinfo->cinfo, COL_INFO); |
120 | | |
121 | 1 | if (!tree) |
122 | 0 | return tvb_captured_length(tvb); |
123 | | |
124 | 1 | ti = proto_tree_add_item(tree, proto_mplstp_lock, tvb, 0, -1, ENC_NA); |
125 | | |
126 | 1 | lock_tree = proto_item_add_subtree (ti, ett_mplstp_lock); |
127 | | |
128 | | /* Version field */ |
129 | 1 | proto_tree_add_item (lock_tree, hf_mplstp_lock_version , tvb, offset, |
130 | 1 | 1, ENC_BIG_ENDIAN); |
131 | | |
132 | | /* Reserved field */ |
133 | 1 | proto_tree_add_item (lock_tree, hf_mplstp_lock_reserved, tvb, offset, |
134 | 1 | 3, ENC_BIG_ENDIAN); |
135 | 1 | offset = offset + 3; |
136 | | |
137 | | /* Refresh-Timer field */ |
138 | 1 | proto_tree_add_item (lock_tree, hf_mplstp_lock_refresh_timer, tvb, offset, |
139 | 1 | 1, ENC_BIG_ENDIAN); |
140 | 1 | offset = offset + 1; |
141 | | |
142 | | /* Source-MEP TLVs */ |
143 | 1 | next_tvb = tvb_new_subset_remaining (tvb, offset); |
144 | 1 | dissect_bfd_mep (next_tvb, tree, proto_mplstp_lock); |
145 | | |
146 | 1 | return tvb_captured_length(tvb); |
147 | 1 | } |
148 | | |
149 | | |
150 | | /* Dissector for MPLS-TP FM protocol: RFC 6427 */ |
151 | | static int |
152 | | dissect_mplstp_fm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) |
153 | 0 | { |
154 | 0 | proto_item *ti, *ti_flags; |
155 | 0 | proto_tree *fm_tree, *fm_flags; |
156 | |
|
157 | 0 | int offset = 0; |
158 | 0 | uint8_t tlv_len; |
159 | |
|
160 | 0 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPLS-TP FM"); |
161 | 0 | col_clear(pinfo->cinfo, COL_INFO); |
162 | |
|
163 | 0 | tlv_len = tvb_get_uint8 (tvb, (offset + 4)); |
164 | |
|
165 | 0 | if (!tree) |
166 | 0 | return tvb_captured_length(tvb); |
167 | | |
168 | 0 | ti = proto_tree_add_item(tree, proto_mplstp_fm, tvb, 0, (tlv_len + 5), ENC_NA); |
169 | 0 | fm_tree = proto_item_add_subtree (ti, ett_mplstp_fm); |
170 | | |
171 | | /* Version and Reserved fields */ |
172 | 0 | proto_tree_add_item (fm_tree, hf_mplstp_fm_version , tvb, offset, |
173 | 0 | 1, ENC_BIG_ENDIAN); |
174 | 0 | proto_tree_add_item (fm_tree, hf_mplstp_fm_reserved, tvb, offset, |
175 | 0 | 1, ENC_BIG_ENDIAN); |
176 | 0 | offset++; |
177 | | |
178 | | /* FM-Message type field */ |
179 | 0 | proto_tree_add_item (fm_tree, hf_mplstp_fm_msg_type, tvb, offset, |
180 | 0 | 1,ENC_BIG_ENDIAN); |
181 | 0 | offset++; |
182 | | |
183 | | /* Flags field */ |
184 | 0 | ti_flags = proto_tree_add_item (fm_tree, hf_mplstp_fm_flags, tvb, |
185 | 0 | offset, 1, ENC_BIG_ENDIAN); |
186 | 0 | fm_flags = proto_item_add_subtree(ti_flags, ett_mplstp_fm_flags); |
187 | |
|
188 | 0 | proto_tree_add_item (fm_flags, hf_mplstp_fm_flags_l, tvb, offset, 1, ENC_BIG_ENDIAN); |
189 | 0 | proto_tree_add_item (fm_flags, hf_mplstp_fm_flags_r, tvb, offset, 1, ENC_BIG_ENDIAN); |
190 | 0 | offset++; |
191 | | |
192 | | /* Refresh-Timer field */ |
193 | 0 | proto_tree_add_item (fm_tree, hf_mplstp_fm_refresh_timer, tvb, offset, |
194 | 0 | 1, ENC_BIG_ENDIAN); |
195 | 0 | offset++; |
196 | | |
197 | | /* FM-TLV Length field*/ |
198 | 0 | proto_tree_add_item (fm_tree, hf_mplstp_fm_total_tlv_len, tvb, offset, |
199 | 0 | 1, ENC_BIG_ENDIAN); |
200 | 0 | offset = offset + 1; |
201 | |
|
202 | 0 | if (tlv_len != 0) { |
203 | 0 | tvbuff_t *next_tvb; |
204 | | |
205 | | /* FM TLVs*/ |
206 | 0 | next_tvb = tvb_new_subset_remaining (tvb, offset); |
207 | 0 | dissect_mplstp_fm_tlv (next_tvb, tree); |
208 | 0 | } |
209 | 0 | return tvb_captured_length(tvb); |
210 | 0 | } |
211 | | |
212 | | void |
213 | | proto_register_mplstp_lock(void) |
214 | 15 | { |
215 | 15 | static hf_register_info hf[] = { |
216 | | |
217 | 15 | {&hf_mplstp_lock_version, |
218 | 15 | {"Version", "mplstp_lock.version", FT_UINT8, |
219 | 15 | BASE_HEX, NULL, 0x0, NULL, HFILL }}, |
220 | | |
221 | 15 | {&hf_mplstp_lock_reserved, |
222 | 15 | {"Reserved", "mplstp_lock.reserved", FT_UINT24, |
223 | 15 | BASE_HEX, NULL, 0x0, NULL, HFILL }}, |
224 | | |
225 | 15 | {&hf_mplstp_lock_refresh_timer, |
226 | 15 | {"Refresh-timer value", "mplstp_lock.refresh-timer", FT_UINT8, |
227 | 15 | BASE_DEC, NULL, 0x0, NULL, HFILL }}, |
228 | 15 | }; |
229 | | |
230 | 15 | static int *ett[] = { |
231 | 15 | &ett_mplstp_lock, |
232 | 15 | }; |
233 | | |
234 | 15 | proto_mplstp_lock = |
235 | 15 | proto_register_protocol("MPLS-TP Lock-Instruct", "MPLS[-TP] Lock-Instruct " |
236 | 15 | "Lock-Instruct (LI) Protocol", |
237 | 15 | "mplstp_lock"); |
238 | | |
239 | 15 | proto_register_field_array(proto_mplstp_lock, hf, array_length(hf)); |
240 | 15 | proto_register_subtree_array(ett, array_length(ett)); |
241 | | |
242 | 15 | mplstp_lock_handle = register_dissector("mplstp_lock", dissect_mplstp_lock, proto_mplstp_lock); |
243 | 15 | } |
244 | | |
245 | | void |
246 | | proto_reg_handoff_mplstp_lock(void) |
247 | 15 | { |
248 | 15 | dissector_add_uint("pwach.channel_type", 0x0026, mplstp_lock_handle); /* KM: MPLSTP LOCK, RFC 6435 */ |
249 | 15 | } |
250 | | |
251 | | void |
252 | | proto_register_mplstp_fm(void) |
253 | 15 | { |
254 | 15 | static hf_register_info hf[] = { |
255 | | |
256 | 15 | {&hf_mplstp_fm_version, |
257 | 15 | {"Version", "mplstp_oam.version", FT_UINT8, |
258 | 15 | BASE_HEX, NULL, 0x0, NULL, HFILL }}, |
259 | | |
260 | 15 | {&hf_mplstp_fm_reserved, |
261 | 15 | {"Reserved", "mplstp_oam.reserved", FT_UINT8, |
262 | 15 | BASE_HEX, NULL, 0x0, NULL, HFILL }}, |
263 | | |
264 | 15 | {&hf_mplstp_fm_refresh_timer, |
265 | 15 | {"Refresh-timer value", "mplstp_oam.refresh.timer", FT_UINT8, |
266 | 15 | BASE_DEC, NULL, 0x0, NULL, HFILL }}, |
267 | | |
268 | 15 | {&hf_mplstp_fm_total_tlv_len, |
269 | 15 | {"FM TLV Length", "mplstp_oam.total.tlv.len", FT_UINT8, |
270 | 15 | BASE_DEC, NULL, 0x0, NULL, HFILL }}, |
271 | | |
272 | 15 | {&hf_mplstp_fm_if_tlv_type, |
273 | 15 | {"Type : IF-ID TLV", "mplstp_oam.if_id_tlv_type", FT_UINT8, |
274 | 15 | BASE_DEC, NULL, 0x0, NULL, HFILL }}, |
275 | | |
276 | 15 | {&hf_mplstp_fm_global_tlv_type, |
277 | 15 | {"Type : GLOBAL-ID TLV", "mplstp_oam.global_id_tlv_type", FT_UINT8, |
278 | 15 | BASE_DEC, NULL, 0x0, NULL, HFILL }}, |
279 | | |
280 | 15 | {&hf_mplstp_fm_tlv_len, |
281 | 15 | {"Length", "mplstp_oam.tlv_len", FT_UINT8, |
282 | 15 | BASE_DEC, NULL, 0x0, NULL, HFILL }}, |
283 | | |
284 | 15 | {&hf_mplstp_fm_node_id, |
285 | 15 | {"Node id", "mplstp_oam.node_id", FT_IPv4, |
286 | 15 | BASE_NONE, NULL, 0x0, NULL, HFILL }}, |
287 | | |
288 | 15 | {&hf_mplstp_fm_if_num, |
289 | 15 | {"Interface Number", "mplstp_oam.if_num", FT_UINT32, |
290 | 15 | BASE_DEC, NULL, 0x0, NULL, HFILL }}, |
291 | | |
292 | 15 | {&hf_mplstp_fm_global_id, |
293 | 15 | {"Global id", "mplstp_oam.global_id", FT_UINT32, |
294 | 15 | BASE_DEC, NULL, 0x0, NULL, HFILL }}, |
295 | | |
296 | 15 | {&hf_mplstp_fm_msg_type, |
297 | 15 | {"Message Type", "mplstp_oam.message.type", FT_UINT8, |
298 | 15 | BASE_DEC, VALS(fm_msg_type), 0x0, "MPLS-TP FM Message Type", HFILL }}, |
299 | | |
300 | 15 | { &hf_mplstp_fm_flags, |
301 | 15 | { "FM Flags", "mplstp_oam.flags", |
302 | 15 | FT_UINT8, BASE_HEX, NULL, 0x0, "MPLS-TP FM Flags", HFILL} |
303 | 15 | }, |
304 | | |
305 | 15 | { &hf_mplstp_fm_flags_l, |
306 | 15 | { "Link Down Indication", "mplstp_oam.flag_l", |
307 | 15 | FT_BOOLEAN, 8, NULL, 0x02, NULL, HFILL} |
308 | 15 | }, |
309 | | |
310 | 15 | { &hf_mplstp_fm_flags_r, |
311 | 15 | { "FM Condition Cleared", "mplstp_oam.flag_r", |
312 | 15 | FT_BOOLEAN, 8, NULL, 0x01, "Fault Condition Cleared", HFILL} |
313 | 15 | }, |
314 | 15 | }; |
315 | | |
316 | 15 | static int *ett[] = { |
317 | 15 | &ett_mplstp_fm, |
318 | 15 | &ett_mplstp_fm_tlv_tree, |
319 | 15 | &ett_mplstp_fm_flags, |
320 | 15 | }; |
321 | | |
322 | 15 | proto_mplstp_fm = |
323 | 15 | proto_register_protocol("MPLS-TP Fault-Management", "MPLS[-TP] Fault-Management " |
324 | 15 | "Fault-Management (FM) Protocol", |
325 | 15 | "mplstp_fm"); |
326 | | |
327 | 15 | proto_register_field_array(proto_mplstp_fm, hf, array_length(hf)); |
328 | 15 | proto_register_subtree_array(ett, array_length(ett)); |
329 | | |
330 | 15 | mplstp_fm_handle = register_dissector("mplstp_fm", dissect_mplstp_fm, proto_mplstp_fm ); |
331 | 15 | } |
332 | | |
333 | | void |
334 | | proto_reg_handoff_mplstp_fm(void) |
335 | 15 | { |
336 | 15 | dissector_add_uint("pwach.channel_type", PW_ACH_TYPE_MPLSTP_FM, mplstp_fm_handle); |
337 | 15 | } |
338 | | |
339 | | /* |
340 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
341 | | * |
342 | | * Local Variables: |
343 | | * c-basic-offset: 2 |
344 | | * tab-width: 8 |
345 | | * indent-tabs-mode: nil |
346 | | * End: |
347 | | * |
348 | | * ex: set shiftwidth=2 tabstop=8 expandtab: |
349 | | * :indentSize=2:tabSize=8:noTabs=true: |
350 | | */ |