Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-mpls-psc.c
blobff060d7455d62d63487652aaa3d63c53eafaa34a
1 /* packet-mpls-psc.c
3 * Routines for MPLS[-TP] Protection State Coordination (PSC) Protocol: it
4 * should conform to RFC 6378.
6 * Copyright 2012 _FF_
8 * Francesco Fondelli <francesco dot fondelli, gmail dot 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"
19 #include <epan/packet.h>
20 #include "packet-mpls.h"
22 void proto_register_mpls_psc(void);
23 void proto_reg_handoff_mpls_psc(void);
25 static dissector_handle_t mpls_psc_handle;
27 static int proto_mpls_psc;
29 static int ett_mpls_psc;
31 static int hf_mpls_psc_ver;
32 static int hf_mpls_psc_req;
33 static int hf_mpls_psc_pt;
34 static int hf_mpls_psc_rev;
35 static int hf_mpls_psc_fpath;
36 static int hf_mpls_psc_dpath;
37 static int hf_mpls_psc_tlvlen;
40 * FF: please keep this list in sync with
41 * http://www.iana.org/assignments/mpls-oam-parameters/mpls-oam-parameters.xml
42 * Registry Name: 'MPLS PSC Request'
44 static const range_string mpls_psc_req_rvals[] = {
45 { 0, 0, "No Request" },
46 { 1, 1, "Do Not Revert" },
47 { 2, 3, "Unassigned" },
48 { 4, 4, "Wait to Restore" },
49 { 5, 5, "Manual Switch" },
50 { 6, 6, "Unassigned" },
51 { 7, 7, "Signal Degrade" },
52 { 8, 9, "Unassigned" },
53 { 10, 10, "Signal Fail" },
54 { 11, 11, "Unassigned" },
55 { 12, 12, "Forced Switch" },
56 { 13, 13, "Unassigned" },
57 { 14, 14, "Lockout of protection" },
58 { 15, 15, "Unassigned" },
59 { 0, 0, NULL }
62 static const value_string mpls_psc_req_short_vals[] = {
63 { 0, "NR" },
64 { 1, "DNR" },
65 { 4, "WTR" },
66 { 5, "MS" },
67 { 7, "SD" },
68 { 10, "SF" },
69 { 12, "FS" },
70 { 14, "LO" },
71 { 0, NULL }
74 static const range_string mpls_psc_pt_rvals[] = {
75 { 0, 0, "for future extensions" },
76 { 1, 1, "unidirectional switching using a permanent bridge" },
77 { 2, 2, "bidirectional switching using a selector bridge" },
78 { 3, 3, "bidirectional switching using a permanent bridge" },
79 { 0, 0, NULL }
82 static const range_string mpls_psc_rev_rvals[] = {
83 { 0, 0, "non-revertive mode" },
84 { 1, 1, "revertive mode" },
85 { 0, 0, NULL }
88 static const range_string mpls_psc_fpath_rvals[] = {
89 { 0, 0, "protection" },
90 { 1, 1, "working" },
91 { 2, 255, "for future extensions" },
92 { 0, 0, NULL }
95 static const range_string mpls_psc_dpath_rvals[] = {
96 { 0, 0, "protection is not in use" },
97 { 1, 1, "protection is in use" },
98 { 2, 255, "for future extensions" },
99 { 0, 0, NULL }
102 static int
103 dissect_mpls_psc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
105 proto_item *ti;
106 proto_tree *psc_tree;
107 uint32_t offset = 0;
108 uint8_t req;
109 uint8_t fpath;
110 uint8_t path;
112 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PSC");
113 col_clear(pinfo->cinfo, COL_INFO);
115 /* build cinfo */
116 req = (tvb_get_uint8(tvb, offset) & 0x3C) >> 2;
117 fpath = tvb_get_uint8(tvb, offset + 2);
118 path = tvb_get_uint8(tvb, offset + 3);
120 col_add_fstr(pinfo->cinfo, COL_INFO,
121 "%s(%u,%u)",
122 val_to_str_const(req, mpls_psc_req_short_vals, "Unknown-Request"),
123 fpath, path);
125 if (!tree) {
126 return tvb_captured_length(tvb);
129 /* create display subtree for the protocol */
130 ti = proto_tree_add_item(tree, proto_mpls_psc, tvb, 0, -1, ENC_NA);
131 psc_tree = proto_item_add_subtree(ti, ett_mpls_psc);
132 /* version */
133 proto_tree_add_item(psc_tree, hf_mpls_psc_ver, tvb, offset, 1, ENC_BIG_ENDIAN);
134 /* request */
135 proto_tree_add_item(psc_tree, hf_mpls_psc_req, tvb, offset, 1, ENC_BIG_ENDIAN);
136 /* prot type */
137 proto_tree_add_item(psc_tree, hf_mpls_psc_pt, tvb, offset, 1, ENC_BIG_ENDIAN);
138 offset += 1;
139 /* prot type */
140 proto_tree_add_item(psc_tree, hf_mpls_psc_rev, tvb, offset, 1, ENC_BIG_ENDIAN);
141 /* skip reserved1 */
142 offset += 1;
143 /* fpath */
144 proto_tree_add_item(psc_tree, hf_mpls_psc_fpath, tvb, offset, 1, ENC_BIG_ENDIAN);
145 offset += 1;
146 /* path */
147 proto_tree_add_item(psc_tree, hf_mpls_psc_dpath, tvb, offset, 1, ENC_BIG_ENDIAN);
148 offset += 1;
149 /* tlv len */
150 proto_tree_add_item(psc_tree, hf_mpls_psc_tlvlen, tvb, offset, 1, ENC_BIG_ENDIAN);
151 return tvb_captured_length(tvb);
154 void
155 proto_register_mpls_psc(void)
157 static hf_register_info hf[] = {
159 &hf_mpls_psc_ver,
161 "Version", "mpls_psc.ver",
162 FT_UINT8, BASE_DEC, NULL, 0xC0,
163 NULL, HFILL
167 &hf_mpls_psc_req,
169 "Request", "mpls_psc.req",
170 FT_UINT8, BASE_RANGE_STRING | BASE_DEC, RVALS(mpls_psc_req_rvals), 0x3C,
171 NULL, HFILL
175 &hf_mpls_psc_pt,
177 "Protection Type", "mpls_psc.pt",
178 FT_UINT8, BASE_RANGE_STRING | BASE_DEC, RVALS(mpls_psc_pt_rvals), 0x03,
179 NULL, HFILL
183 &hf_mpls_psc_rev,
185 "R", "mpls_psc.rev",
186 FT_UINT8, BASE_RANGE_STRING | BASE_DEC, RVALS(mpls_psc_rev_rvals), 0x80,
187 NULL, HFILL
191 &hf_mpls_psc_fpath,
193 "Fault Path", "mpls_psc.fpath",
194 FT_UINT8, BASE_RANGE_STRING | BASE_DEC, RVALS(mpls_psc_fpath_rvals), 0x0,
195 NULL, HFILL
199 &hf_mpls_psc_dpath,
201 "Data Path", "mpls_psc.dpath",
202 FT_UINT8, BASE_RANGE_STRING | BASE_DEC, RVALS(mpls_psc_dpath_rvals), 0x0,
203 NULL, HFILL
207 &hf_mpls_psc_tlvlen,
209 "TLV Length", "mpls_psc.tlvlen",
210 FT_UINT16, BASE_DEC, NULL, 0x0,
211 NULL, HFILL
216 static int *ett[] = {
217 &ett_mpls_psc,
220 proto_mpls_psc =
221 proto_register_protocol("PSC", "MPLS[-TP] Protection State "
222 "Coordination (PSC) Protocol",
223 "mpls_psc");
225 proto_register_field_array(proto_mpls_psc, hf, array_length(hf));
226 proto_register_subtree_array(ett, array_length(ett));
228 mpls_psc_handle = register_dissector("mpls_psc", dissect_mpls_psc, proto_mpls_psc);
231 void
232 proto_reg_handoff_mpls_psc(void)
234 dissector_add_uint("pwach.channel_type", PW_ACH_TYPE_PSC, mpls_psc_handle);
238 * Editor modelines - https://www.wireshark.org/tools/modelines.html
240 * Local variables:
241 * c-basic-offset: 4
242 * tab-width: 8
243 * indent-tabs-mode: nil
244 * End:
246 * vi: set shiftwidth=4 tabstop=8 expandtab:
247 * :indentSize=4:tabSize=8:noTabs=true: