Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-mplstp-oam.c
blob22139cbe4ef8f40971a18eb2dbd0a5209269fe2f
1 /* packet-mplstp-oam.c
3 * Routines for MPLS-TP Lock Instruct Protocol : RFC 6435
4 * MPLS-TP Fault-Management Protocol : RFC 6427
6 * Authors:
7 * Krishnamurthy Mayya <krishnamurthymayya@gmail.com>
8 * Nikitha Malgi <nikitha01@gmail.com>
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include "config.h"
18 #include <epan/packet.h>
19 #include "packet-bfd.h"
20 #include "packet-mpls.h"
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);
27 static dissector_handle_t mplstp_lock_handle;
28 static dissector_handle_t mplstp_fm_handle;
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;
36 static int hf_mplstp_fm_version;
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;
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}
59 /* MPLS-TP Lock protocol specific variables */
60 static int proto_mplstp_lock;
61 static int ett_mplstp_lock;
63 static int hf_mplstp_lock_version;
64 static int hf_mplstp_lock_reserved;
65 static int hf_mplstp_lock_refresh_timer;
67 static void
68 dissect_mplstp_fm_tlv (tvbuff_t *tvb, proto_tree *tree)
70 proto_item *ti;
71 proto_tree *fm_tlv_tree;
73 unsigned offset = 0;
75 if (!tree)
76 return;
78 ti = proto_tree_add_protocol_format (tree, proto_mplstp_fm, tvb, offset, 16,
79 "Fault-Management TLVs");
81 fm_tlv_tree = proto_item_add_subtree (ti, ett_mplstp_fm_tlv_tree);
83 proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_if_tlv_type , tvb, offset,
84 1, ENC_BIG_ENDIAN);
85 offset = offset + 1;
86 proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_tlv_len, tvb, offset,
87 1, ENC_BIG_ENDIAN);
88 offset = offset + 1;
89 proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_node_id, tvb, offset,
90 4, ENC_BIG_ENDIAN);
91 offset = offset + 4;
92 proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_if_num, tvb, offset,
93 4, ENC_BIG_ENDIAN);
94 offset = offset + 4;
95 proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_global_tlv_type , tvb, offset,
96 1, ENC_BIG_ENDIAN);
97 offset = offset + 1;
98 proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_tlv_len, tvb, offset,
99 1, ENC_BIG_ENDIAN);
100 offset = offset + 1;
101 proto_tree_add_item (fm_tlv_tree, hf_mplstp_fm_global_id, tvb, offset,
102 4, ENC_BIG_ENDIAN);
103 /* offset = offset + 4; */
105 return;
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_)
112 proto_item *ti;
113 proto_tree *lock_tree;
114 tvbuff_t *next_tvb;
116 uint8_t offset = 0;
118 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPLS-TP LI");
119 col_clear(pinfo->cinfo, COL_INFO);
121 if (!tree)
122 return tvb_captured_length(tvb);
124 ti = proto_tree_add_item(tree, proto_mplstp_lock, tvb, 0, -1, ENC_NA);
126 lock_tree = proto_item_add_subtree (ti, ett_mplstp_lock);
128 /* Version field */
129 proto_tree_add_item (lock_tree, hf_mplstp_lock_version , tvb, offset,
130 1, ENC_BIG_ENDIAN);
132 /* Reserved field */
133 proto_tree_add_item (lock_tree, hf_mplstp_lock_reserved, tvb, offset,
134 3, ENC_BIG_ENDIAN);
135 offset = offset + 3;
137 /* Refresh-Timer field */
138 proto_tree_add_item (lock_tree, hf_mplstp_lock_refresh_timer, tvb, offset,
139 1, ENC_BIG_ENDIAN);
140 offset = offset + 1;
142 /* Source-MEP TLVs */
143 next_tvb = tvb_new_subset_remaining (tvb, offset);
144 dissect_bfd_mep (next_tvb, tree, proto_mplstp_lock);
146 return tvb_captured_length(tvb);
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_)
154 proto_item *ti, *ti_flags;
155 proto_tree *fm_tree, *fm_flags;
157 int offset = 0;
158 uint8_t tlv_len;
160 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPLS-TP FM");
161 col_clear(pinfo->cinfo, COL_INFO);
163 tlv_len = tvb_get_uint8 (tvb, (offset + 4));
165 if (!tree)
166 return tvb_captured_length(tvb);
168 ti = proto_tree_add_item(tree, proto_mplstp_fm, tvb, 0, (tlv_len + 5), ENC_NA);
169 fm_tree = proto_item_add_subtree (ti, ett_mplstp_fm);
171 /* Version and Reserved fields */
172 proto_tree_add_item (fm_tree, hf_mplstp_fm_version , tvb, offset,
173 1, ENC_BIG_ENDIAN);
174 proto_tree_add_item (fm_tree, hf_mplstp_fm_reserved, tvb, offset,
175 1, ENC_BIG_ENDIAN);
176 offset++;
178 /* FM-Message type field */
179 proto_tree_add_item (fm_tree, hf_mplstp_fm_msg_type, tvb, offset,
180 1,ENC_BIG_ENDIAN);
181 offset++;
183 /* Flags field */
184 ti_flags = proto_tree_add_item (fm_tree, hf_mplstp_fm_flags, tvb,
185 offset, 1, ENC_BIG_ENDIAN);
186 fm_flags = proto_item_add_subtree(ti_flags, ett_mplstp_fm_flags);
188 proto_tree_add_item (fm_flags, hf_mplstp_fm_flags_l, tvb, offset, 1, ENC_BIG_ENDIAN);
189 proto_tree_add_item (fm_flags, hf_mplstp_fm_flags_r, tvb, offset, 1, ENC_BIG_ENDIAN);
190 offset++;
192 /* Refresh-Timer field */
193 proto_tree_add_item (fm_tree, hf_mplstp_fm_refresh_timer, tvb, offset,
194 1, ENC_BIG_ENDIAN);
195 offset++;
197 /* FM-TLV Length field*/
198 proto_tree_add_item (fm_tree, hf_mplstp_fm_total_tlv_len, tvb, offset,
199 1, ENC_BIG_ENDIAN);
200 offset = offset + 1;
202 if (tlv_len != 0) {
203 tvbuff_t *next_tvb;
205 /* FM TLVs*/
206 next_tvb = tvb_new_subset_remaining (tvb, offset);
207 dissect_mplstp_fm_tlv (next_tvb, tree);
209 return tvb_captured_length(tvb);
212 void
213 proto_register_mplstp_lock(void)
215 static hf_register_info hf[] = {
217 {&hf_mplstp_lock_version,
218 {"Version", "mplstp_lock.version", FT_UINT8,
219 BASE_HEX, NULL, 0x0, NULL, HFILL }},
221 {&hf_mplstp_lock_reserved,
222 {"Reserved", "mplstp_lock.reserved", FT_UINT24,
223 BASE_HEX, NULL, 0x0, NULL, HFILL }},
225 {&hf_mplstp_lock_refresh_timer,
226 {"Refresh-timer value", "mplstp_lock.refresh-timer", FT_UINT8,
227 BASE_DEC, NULL, 0x0, NULL, HFILL }},
230 static int *ett[] = {
231 &ett_mplstp_lock,
234 proto_mplstp_lock =
235 proto_register_protocol("MPLS-TP Lock-Instruct", "MPLS[-TP] Lock-Instruct "
236 "Lock-Instruct (LI) Protocol",
237 "mplstp_lock");
239 proto_register_field_array(proto_mplstp_lock, hf, array_length(hf));
240 proto_register_subtree_array(ett, array_length(ett));
242 mplstp_lock_handle = register_dissector("mplstp_lock", dissect_mplstp_lock, proto_mplstp_lock);
245 void
246 proto_reg_handoff_mplstp_lock(void)
248 dissector_add_uint("pwach.channel_type", 0x0026, mplstp_lock_handle); /* KM: MPLSTP LOCK, RFC 6435 */
251 void
252 proto_register_mplstp_fm(void)
254 static hf_register_info hf[] = {
256 {&hf_mplstp_fm_version,
257 {"Version", "mplstp_oam.version", FT_UINT8,
258 BASE_HEX, NULL, 0x0, NULL, HFILL }},
260 {&hf_mplstp_fm_reserved,
261 {"Reserved", "mplstp_oam.reserved", FT_UINT8,
262 BASE_HEX, NULL, 0x0, NULL, HFILL }},
264 {&hf_mplstp_fm_refresh_timer,
265 {"Refresh-timer value", "mplstp_oam.refresh.timer", FT_UINT8,
266 BASE_DEC, NULL, 0x0, NULL, HFILL }},
268 {&hf_mplstp_fm_total_tlv_len,
269 {"FM TLV Length", "mplstp_oam.total.tlv.len", FT_UINT8,
270 BASE_DEC, NULL, 0x0, NULL, HFILL }},
272 {&hf_mplstp_fm_if_tlv_type,
273 {"Type : IF-ID TLV", "mplstp_oam.if_id_tlv_type", FT_UINT8,
274 BASE_DEC, NULL, 0x0, NULL, HFILL }},
276 {&hf_mplstp_fm_global_tlv_type,
277 {"Type : GLOBAL-ID TLV", "mplstp_oam.global_id_tlv_type", FT_UINT8,
278 BASE_DEC, NULL, 0x0, NULL, HFILL }},
280 {&hf_mplstp_fm_tlv_len,
281 {"Length", "mplstp_oam.tlv_len", FT_UINT8,
282 BASE_DEC, NULL, 0x0, NULL, HFILL }},
284 {&hf_mplstp_fm_node_id,
285 {"Node id", "mplstp_oam.node_id", FT_IPv4,
286 BASE_NONE, NULL, 0x0, NULL, HFILL }},
288 {&hf_mplstp_fm_if_num,
289 {"Interface Number", "mplstp_oam.if_num", FT_UINT32,
290 BASE_DEC, NULL, 0x0, NULL, HFILL }},
292 {&hf_mplstp_fm_global_id,
293 {"Global id", "mplstp_oam.global_id", FT_UINT32,
294 BASE_DEC, NULL, 0x0, NULL, HFILL }},
296 {&hf_mplstp_fm_msg_type,
297 {"Message Type", "mplstp_oam.message.type", FT_UINT8,
298 BASE_DEC, VALS(fm_msg_type), 0x0, "MPLS-TP FM Message Type", HFILL }},
300 { &hf_mplstp_fm_flags,
301 { "FM Flags", "mplstp_oam.flags",
302 FT_UINT8, BASE_HEX, NULL, 0x0, "MPLS-TP FM Flags", HFILL}
305 { &hf_mplstp_fm_flags_l,
306 { "Link Down Indication", "mplstp_oam.flag_l",
307 FT_BOOLEAN, 8, NULL, 0x02, NULL, HFILL}
310 { &hf_mplstp_fm_flags_r,
311 { "FM Condition Cleared", "mplstp_oam.flag_r",
312 FT_BOOLEAN, 8, NULL, 0x01, "Fault Condition Cleared", HFILL}
316 static int *ett[] = {
317 &ett_mplstp_fm,
318 &ett_mplstp_fm_tlv_tree,
319 &ett_mplstp_fm_flags,
322 proto_mplstp_fm =
323 proto_register_protocol("MPLS-TP Fault-Management", "MPLS[-TP] Fault-Management "
324 "Fault-Management (FM) Protocol",
325 "mplstp_fm");
327 proto_register_field_array(proto_mplstp_fm, hf, array_length(hf));
328 proto_register_subtree_array(ett, array_length(ett));
330 mplstp_fm_handle = register_dissector("mplstp_fm", dissect_mplstp_fm, proto_mplstp_fm );
333 void
334 proto_reg_handoff_mplstp_fm(void)
336 dissector_add_uint("pwach.channel_type", PW_ACH_TYPE_MPLSTP_FM, mplstp_fm_handle);
340 * Editor modelines - https://www.wireshark.org/tools/modelines.html
342 * Local Variables:
343 * c-basic-offset: 2
344 * tab-width: 8
345 * indent-tabs-mode: nil
346 * End:
348 * ex: set shiftwidth=2 tabstop=8 expandtab:
349 * :indentSize=2:tabSize=8:noTabs=true: