Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-mpls-y1711.c
blobc0af61cc53067e1b4e2c25c2a197ed55255e4390
1 /* packet-mpls-y1711.c
2 * Routines for (old) ITU-T MPLS OAM: it conforms to ITU-T Y.1711 and RFC 3429
4 * Copyright 2006, 2011 _FF_
6 * Francesco Fondelli <francesco dot fondelli, gmail dot com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * SPDX-License-Identifier: GPL-2.0-or-later
16 * FF: NOTES
18 * - this should dissect OAM pdus (identified by the MPLS_LABEL_OAM_ALERT = 14
19 * label) as described in ITU-T Y.1711 and RFC 3429.
21 * - this code used to be (since 2006) in packet-mpls.c ... nobody on this
22 * planet is using Y.1711 today (?), so thanks to the mpls subdissector
23 * table indexed by label value it has been moved here.
26 #include "config.h"
28 #include <epan/packet.h>
29 #include <epan/expert.h>
31 #include "packet-mpls.h"
33 void proto_register_mpls_y1711(void);
34 void proto_reg_handoff_mpls_y1711(void);
36 static int proto_mpls_y1711;
38 static int hf_mpls_y1711_function_type;
39 /* static int hf_mpls_y1711_ttsi; */
40 static int hf_mpls_y1711_frequency;
41 static int hf_mpls_y1711_defect_type;
42 static int hf_mpls_y1711_defect_location;
43 static int hf_mpls_y1711_bip16;
44 /* Generated from convert_proto_tree_add_text.pl */
45 static int hf_mpls_y1711_lsr_id;
46 static int hf_mpls_y1711_lsp_id;
48 static int ett_mpls_y1711;
50 /* Generated from convert_proto_tree_add_text.pl */
51 static expert_field ei_mpls_y1711_padding_not_ff;
52 static expert_field ei_mpls_y1711_reserved_not_zero;
53 static expert_field ei_mpls_y1711_ttsi_not_preset;
54 static expert_field ei_mpls_y1711_minimum_payload;
55 static expert_field ei_mpls_y1711_s_bit_not_one;
56 static expert_field ei_mpls_y1711_no_OAM_alert_label;
57 static expert_field ei_mpls_y1711_exp_bits_not_zero;
58 static expert_field ei_mpls_y1711_ttl_not_one;
59 static expert_field ei_mpls_y1711_padding_not_zero;
60 static expert_field ei_mpls_y1711_unknown_pdu;
62 static dissector_handle_t mpls_y1711_handle;
64 static const value_string y1711_function_type_vals[] = {
65 {0x00, "Reserved" },
66 {0x01, "CV (Connectivity Verification)" },
67 {0x02, "FDI (Forward Defect Indicator)" },
68 {0x03, "BDI (Backward Defect Indicator)" },
69 {0x04, "Reserved for Performance packets" },
70 {0x05, "Reserved for LB-Req (Loopback Request)" },
71 {0x06, "Reserved for LB-Rsp (Loopback Response)"},
72 {0x07, "FDD (Fast Failure Detection)" },
73 {0, NULL }
76 static const value_string y1711_frequency_vals[] = {
77 {0x00, "Reserved" },
78 {0x01, "10 ms" },
79 {0x02, "20 ms" },
80 {0x03, "50 ms (default value)"},
81 {0x04, "100 ms" },
82 {0x05, "200 ms" },
83 {0x06, "500 ms" },
84 /* 7-255 Reserved */
85 {0, NULL }
88 static const value_string y1711_defect_type_vals[] = {
89 {0x0000, "Reserved" },
90 {0x0101, "dServer" },
91 {0x0102, "dPeerME" },
92 {0x0201, "dLOCV" },
93 {0x0202, "dTTSI_Mismatch"},
94 {0x0203, "dTTSI_Mismerge"},
95 {0x0204, "dExcess" },
96 {0x02FF, "dUnknown" },
97 {0xFFFF, "Reserved" },
98 {0, NULL }
101 static int
102 dissect_mpls_y1711(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
104 struct mplsinfo *mplsinfo;
105 int offset = 0;
106 proto_tree *mpls_y1711_tree;
107 int functype;
108 tvbuff_t *data_tvb;
110 static const uint8_t allone[] = { 0xff, 0xff };
111 static const uint8_t allzero[] = { 0x00, 0x00, 0x00, 0x00, 0x00,
112 0x00, 0x00, 0x00, 0x00, 0x00,
113 0x00, 0x00, 0x00, 0x00, 0x00,
114 0x00, 0x00, 0x00, 0x00, 0x00 };
116 /* Reject the packet if data is NULL */
117 if (data == NULL)
118 return 0;
119 mplsinfo = (struct mplsinfo *)data;
121 functype = tvb_get_uint8(tvb, offset);
122 col_append_fstr(pinfo->cinfo, COL_INFO, " (Y.1711: %s)",
123 (functype == 0x01) ? "CV" :
124 (functype == 0x02) ? "FDI" :
125 (functype == 0x03) ? "BDI" :
126 (functype == 0x07) ? "FDD" :
127 "reserved/unknown");
129 /* sanity checks */
130 if (tvb_reported_length(tvb) < 44) {
132 * ITU-T Y.1711, 5.3: PDUs must have a minimum payload length of
133 * 44 bytes
135 proto_tree_add_expert(tree, pinfo, &ei_mpls_y1711_minimum_payload, tvb, offset, -1);
136 data_tvb = tvb_new_subset_remaining(tvb, offset);
137 call_data_dissector(data_tvb, pinfo, tree);
139 return tvb_reported_length(tvb);
142 mpls_y1711_tree = proto_tree_add_subtree(tree, tvb, offset, 44, ett_mpls_y1711, NULL, "Y.1711 OAM");
144 /* checks for exp, bos and ttl encoding */
145 if (mplsinfo->label != MPLS_LABEL_OAM_ALERT)
146 proto_tree_add_expert_format(mpls_y1711_tree, pinfo, &ei_mpls_y1711_no_OAM_alert_label, tvb, offset - 4, 3,
147 "Warning: Y.1711 but no OAM alert label (%d) ?!", MPLS_LABEL_OAM_ALERT);
149 if (mplsinfo->exp != 0)
150 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_exp_bits_not_zero, tvb, offset - 2, 1);
152 if (mplsinfo->bos != 1)
153 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_s_bit_not_one, tvb, offset - 2, 1);
155 if (mplsinfo->ttl != 1)
156 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_ttl_not_one, tvb, offset - 1, 1);
158 /* starting dissection */
159 functype = tvb_get_uint8(tvb, offset);
160 proto_tree_add_item(mpls_y1711_tree, hf_mpls_y1711_function_type, tvb,
161 offset, 1,
162 ENC_LITTLE_ENDIAN);
163 offset++;
165 switch (functype) {
166 case 0x01: /* CV */
168 /* 3 octets reserved (all 0x00) */
169 if (tvb_memeql(tvb, offset, allzero, 3) == -1) {
170 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_reserved_not_zero, tvb, offset, 3);
172 offset += 3;
174 /* ttsi (ipv4 flavor as in RFC 2373) */
175 if (tvb_memeql(tvb, offset, allzero, 10) == -1) {
176 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_padding_not_zero, tvb, offset, 10);
178 offset += 10;
180 if (tvb_memeql(tvb, offset, allone, 2) == -1) {
181 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_padding_not_ff, tvb, offset, 2);
183 offset += 2;
185 proto_tree_add_item(mpls_y1711_tree, hf_mpls_y1711_lsr_id, tvb, offset, 4, ENC_BIG_ENDIAN);
186 offset += 4;
188 proto_tree_add_item(mpls_y1711_tree, hf_mpls_y1711_lsp_id, tvb, offset, 4, ENC_BIG_ENDIAN);
189 offset += 4;
191 /* 18 octets of padding (all 0x00) */
192 if (tvb_memeql(tvb, offset, allzero, 18) == -1) {
193 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_padding_not_zero, tvb, offset, 18);
195 offset += 18;
197 break;
199 case 0x02: /* FDI */
200 case 0x03: /* BDI */
202 /* 1 octets reserved (all 0x00) */
203 if (tvb_memeql(tvb, offset, allzero, 1) == -1) {
204 proto_tree_add_expert_format(mpls_y1711_tree, pinfo, &ei_mpls_y1711_reserved_not_zero, tvb, offset, 3,
205 "Error: this byte is reserved and must be 0x00");
207 offset++;
209 proto_tree_add_item(mpls_y1711_tree, hf_mpls_y1711_defect_type, tvb,
210 offset, 2,
211 ENC_BIG_ENDIAN);
212 offset += 2;
215 * ttsi (ipv4 flavor as in RFC 2373) is optional if not used must
216 * be set to all 0x00
218 if (tvb_memeql(tvb, offset, allzero, 20) == 0) {
219 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_ttsi_not_preset, tvb, offset, 20);
220 offset += 20;
221 } else {
222 if (tvb_memeql(tvb, offset, allzero, 10) == -1) {
223 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_padding_not_zero, tvb, offset, 10);
225 offset += 10;
227 if (tvb_memeql(tvb, offset, allone, 2) == -1) {
228 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_padding_not_ff, tvb, offset, 2);
230 offset += 2;
232 proto_tree_add_item(mpls_y1711_tree, hf_mpls_y1711_lsr_id, tvb, offset, 4, ENC_BIG_ENDIAN);
233 offset += 4;
235 proto_tree_add_item(mpls_y1711_tree, hf_mpls_y1711_lsp_id, tvb, offset, 4, ENC_BIG_ENDIAN);
236 offset += 4;
239 /* defect location */
240 proto_tree_add_item(mpls_y1711_tree, hf_mpls_y1711_defect_location, tvb,
241 offset, 4,
242 ENC_BIG_ENDIAN);
243 offset += 4;
245 /* 14 octets of padding (all 0x00) */
246 if (tvb_memeql(tvb, offset, allzero, 14) == -1) {
247 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_padding_not_zero, tvb, offset, 14);
249 offset += 14;
251 break;
253 case 0x07: /* FDD */
255 /* 3 octets reserved (all 0x00) */
256 if (tvb_memeql(tvb, offset, allzero, 3) == -1) {
257 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_reserved_not_zero, tvb, offset, 3);
259 offset += 3;
261 /* ttsi (ipv4 flavor as in RFC 2373) */
262 if (tvb_memeql(tvb, offset, allzero, 10) == -1) {
263 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_padding_not_zero, tvb, offset, 10);
265 offset += 10;
267 if (tvb_memeql(tvb, offset, allone, 2) == -1) {
268 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_padding_not_ff, tvb, offset, 2);
270 offset += 2;
272 proto_tree_add_item(mpls_y1711_tree, hf_mpls_y1711_lsr_id, tvb, offset, 4, ENC_BIG_ENDIAN);
273 offset += 4;
275 proto_tree_add_item(mpls_y1711_tree, hf_mpls_y1711_lsp_id, tvb, offset, 4, ENC_BIG_ENDIAN);
276 offset += 4;
278 proto_tree_add_item(mpls_y1711_tree, hf_mpls_y1711_frequency, tvb,
279 offset, 1,
280 ENC_LITTLE_ENDIAN);
281 offset++;
283 /* 17 octets of padding (all 0x00) */
284 if (tvb_memeql(tvb, offset, allzero, 17) == -1) {
285 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_padding_not_zero, tvb, offset, 17);
287 offset += 17;
289 break;
291 default:
292 proto_tree_add_expert(mpls_y1711_tree, pinfo, &ei_mpls_y1711_unknown_pdu, tvb, offset - 1, -1);
293 return offset;
296 /* BIP16 */
297 proto_tree_add_item(mpls_y1711_tree, hf_mpls_y1711_bip16, tvb, offset, 2,
298 ENC_BIG_ENDIAN);
299 offset += 2;
301 return offset;
304 void
305 proto_register_mpls_y1711(void)
307 static hf_register_info hf[] = {
309 &hf_mpls_y1711_function_type,
311 "Function Type", "mpls_y1711.function_type", FT_UINT8,
312 BASE_HEX, VALS(y1711_function_type_vals),
313 0x0, "Function Type codepoint", HFILL
316 #if 0
318 &hf_mpls_y1711_ttsi,
320 "Trail Termination Source Identifier",
321 "mpls_y1711.ttsi",
322 FT_UINT32, BASE_HEX, NULL, 0x0, NULL, HFILL
325 #endif
327 &hf_mpls_y1711_frequency,
329 "Frequency", "mpls_y1711.frequency", FT_UINT8,
330 BASE_HEX, VALS(y1711_frequency_vals), 0x0,
331 "Frequency of probe injection", HFILL
335 &hf_mpls_y1711_defect_type,
337 "Defect Type", "mpls_y1711.defect_type", FT_UINT16,
338 BASE_HEX, VALS(y1711_defect_type_vals), 0x0, NULL, HFILL
342 &hf_mpls_y1711_defect_location,
344 "Defect Location (AS)", "mpls_y1711.defect_location",
345 FT_UINT32, BASE_DEC, NULL, 0x0, NULL, HFILL
349 &hf_mpls_y1711_bip16,
351 "BIP16", "mpls_y1711.bip16", FT_UINT16,
352 BASE_HEX, NULL, 0x0, NULL, HFILL
355 /* Generated from convert_proto_tree_add_text.pl */
356 { &hf_mpls_y1711_lsr_id, { "LSR ID", "mpls_y1711.lsr_id", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
357 { &hf_mpls_y1711_lsp_id, { "LSP ID", "mpls_y1711.lsp_id", FT_INT32, BASE_DEC, NULL, 0x0, NULL, HFILL }},
360 static int *ett[] = {
361 &ett_mpls_y1711
364 static ei_register_info ei[] = {
365 /* Generated from convert_proto_tree_add_text.pl */
366 { &ei_mpls_y1711_minimum_payload, { "mpls_y1711.minimum_payload", PI_MALFORMED, PI_ERROR, "Must have a minimum payload length of 44 bytes", EXPFILL }},
367 { &ei_mpls_y1711_no_OAM_alert_label, { "mpls_y1711.no_OAM_alert_label", PI_PROTOCOL, PI_WARN, "Y.1711 but no OAM alert label", EXPFILL }},
368 { &ei_mpls_y1711_exp_bits_not_zero, { "mpls_y1711.exp_bits_not_0", PI_PROTOCOL, PI_WARN, "Exp bits should be 0", EXPFILL }},
369 { &ei_mpls_y1711_s_bit_not_one, { "mpls_y1711.s_bit_not_1", PI_PROTOCOL, PI_WARN, "S bit should be 1", EXPFILL }},
370 { &ei_mpls_y1711_ttl_not_one, { "mpls_y1711.ttl_not_1", PI_PROTOCOL, PI_WARN, "TTL should be 1", EXPFILL }},
371 { &ei_mpls_y1711_reserved_not_zero, { "mpls_y1711.reserved_not_zero", PI_PROTOCOL, PI_WARN, "These bytes are reserved and must be 0x00", EXPFILL }},
372 { &ei_mpls_y1711_padding_not_zero, { "mpls_y1711.padding_not_zero", PI_PROTOCOL, PI_WARN, "These bytes are padding and must be 0x00", EXPFILL }},
373 { &ei_mpls_y1711_padding_not_ff, { "mpls_y1711.padding_not_ff", PI_PROTOCOL, PI_ERROR, "Error: these bytes are padding and must be 0xFF", EXPFILL }},
374 { &ei_mpls_y1711_ttsi_not_preset, { "mpls_y1711.ttsi_not_preset", PI_PROTOCOL, PI_NOTE, "TTSI not preset (optional for FDI/BDI)", EXPFILL }},
375 { &ei_mpls_y1711_unknown_pdu, { "mpls_y1711.unknown_pdu", PI_PROTOCOL, PI_WARN, "Unknown MPLS Y.1711 PDU", EXPFILL }},
378 expert_module_t* expert_mpls_y1711;
380 proto_mpls_y1711 =
381 proto_register_protocol("MPLS ITU-T Y.1711 OAM",
382 "MPLS ITU-T Y.1711 OAM",
383 "mpls_y1711");
384 proto_register_field_array(proto_mpls_y1711, hf, array_length(hf));
385 proto_register_subtree_array(ett, array_length(ett));
386 expert_mpls_y1711 = expert_register_protocol(proto_mpls_y1711);
387 expert_register_field_array(expert_mpls_y1711, ei, array_length(ei));
388 mpls_y1711_handle = register_dissector("mpls_y1711", dissect_mpls_y1711, proto_mpls_y1711);
391 void
392 proto_reg_handoff_mpls_y1711(void)
394 dissector_add_uint("mpls.label",
395 MPLS_LABEL_OAM_ALERT /* 14 */,
396 mpls_y1711_handle);
400 * Editor modelines - https://www.wireshark.org/tools/modelines.html
402 * Local variables:
403 * c-basic-offset: 4
404 * tab-width: 8
405 * indent-tabs-mode: nil
406 * End:
408 * vi: set shiftwidth=4 tabstop=8 expandtab:
409 * :indentSize=4:tabSize=8:noTabs=true: