1 /* packet-pw-oam.c
2 *
3 * Routines for Pseudowire Status for static pseudowires : RFC 6478
4 *
5 * (c) Copyright 2012, Krishnamurthy Mayya <krishnamurthymayya@gmail.com>
6 * Nikitha Malgi <nikitha01@gmail.com>
7 *
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
11 *
12 * SPDX-License-Identifier: GPL-2.0-or-later
13 */
14
15 #include "config.h"
16 #include <epan/packet.h>
17 #include "packet-mpls.h"
18
19 void proto_register_pw_oam(void);
20 void proto_reg_handoff_pw_oam(void);
21
22 /* MPLS-TP FM protocol specific variables */
23 static gint proto_pw_oam = -1;
24 static gint ett_pw_oam = -1;
25 static gint ett_pw_oam_flags = -1;
26 static gint ett_pw_oam_tlv_tree = -1;
27
28 static int hf_pw_oam_tlv_reserved = -1;
29 static int hf_pw_oam_tlv_type = -1;
30 static int hf_pw_oam_total_tlv_len = -1;
31 static int hf_pw_oam_code = -1;
32 static int hf_pw_oam_flags = -1;
33 static int hf_pw_oam_flags_a = -1;
34 static int hf_pw_oam_refresh_timer = -1;
35 static int hf_pw_oam_tlv_len = -1;
36
37 static const value_string pw_oam_code[] = {
38 {0x00000002, "Local Attachment Circuit(ingress) Receive Fault"},
39 {0x00000004, "Local Attachment Circuit(egress) Transmit Fault"},
40 {0x00000020, "PW Forwarding Standby"},
41 {0x00000040, "Request Switchover to this PW"},
42 {0, NULL}
43 };
44
45 /* PW-Status TLV dissector */
46 static void
dissect_pw_status_tlv(tvbuff_t * tvb,proto_tree * tree,gint offset)47 dissect_pw_status_tlv (tvbuff_t *tvb, proto_tree *tree, gint offset)
48 {
49 proto_item *ti;
50 proto_tree *pw_oam_tlv_tree;
51
52
53 ti = proto_tree_add_protocol_format (tree, proto_pw_oam, tvb, offset, 8,
54 "Pseudo-Wire Status TLV");
55
56
57 if (!tree)
58 return;
59
60 pw_oam_tlv_tree = proto_item_add_subtree (ti, ett_pw_oam_tlv_tree);
61
62 proto_tree_add_item (pw_oam_tlv_tree, hf_pw_oam_tlv_reserved, tvb, offset,
63 2, ENC_BIG_ENDIAN);
64 proto_tree_add_item (pw_oam_tlv_tree, hf_pw_oam_tlv_type, tvb, offset,
65 2, ENC_BIG_ENDIAN);
66 offset = offset + 2;
67
68 proto_tree_add_item (pw_oam_tlv_tree, hf_pw_oam_tlv_len, tvb, offset,
69 2, ENC_BIG_ENDIAN);
70 offset = offset + 2;
71 proto_tree_add_item (pw_oam_tlv_tree, hf_pw_oam_code, tvb, offset,
72 4, ENC_BIG_ENDIAN);
73 /*offset = offset + 4;*/
74
75 return ;
76 }
77
78 /* Dissector for PW OAM protocol: RFC 6478 */
79 static int
dissect_pw_oam(tvbuff_t * tvb,packet_info * pinfo,proto_tree * tree,void * data _U_)80 dissect_pw_oam(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
81 {
82 proto_item *ti = NULL, *ti_flags = NULL;
83 proto_tree *pw_oam_tree = NULL, *pw_oam_flags = NULL;
84
85 guint8 offset = 0;
86 guint16 pw_tlv_type = 0;
87
88 col_set_str(pinfo->cinfo, COL_PROTOCOL, "PW OAM");
89 col_clear(pinfo->cinfo, COL_INFO);
90
91 if (!tree)
92 return tvb_captured_length(tvb);
93
94 ti = proto_tree_add_item(tree, proto_pw_oam, tvb, 0, -1, ENC_NA);
95
96 pw_oam_tree = proto_item_add_subtree (ti, ett_pw_oam);
97
98 /* Refresh-Timer field */
99 proto_tree_add_item (pw_oam_tree, hf_pw_oam_refresh_timer, tvb, offset,
100 2, ENC_BIG_ENDIAN);
101 offset = offset + 2;
102
103 /* Total-TLV length */
104 proto_tree_add_item (pw_oam_tree, hf_pw_oam_total_tlv_len, tvb, offset,
105 1, ENC_BIG_ENDIAN);
106 offset = offset + 1;
107
108 /* Flags field */
109 ti_flags = proto_tree_add_item (pw_oam_tree, hf_pw_oam_flags, tvb,
110 offset, 1, ENC_BIG_ENDIAN);
111 pw_oam_flags = proto_item_add_subtree(ti_flags, ett_pw_oam_flags);
112 proto_tree_add_item (pw_oam_flags, hf_pw_oam_flags_a, tvb, offset, 1, ENC_BIG_ENDIAN);
113
114 offset = offset + 1;
115 pw_tlv_type = tvb_get_ntohs (tvb, offset);
116
117 /* TLVs */
118 switch (pw_tlv_type)
119 {
120 /* The switch cases below have to be based on the LDP-name space.
121 http://www.iana.org/assignments/ldp-namespaces/ldp-namespaces.xml */
122
123 case 0x096A: /* PW-Status TLV */
124 dissect_pw_status_tlv (tvb, tree, offset);
125 break;
126
127 default:
128 break;
129 }
130
131 return tvb_captured_length(tvb);
132 }
133
134 void
proto_register_pw_oam(void)135 proto_register_pw_oam(void)
136 {
137 static hf_register_info hf[] = {
138
139 {&hf_pw_oam_refresh_timer,
140 {"Refresh-Timer", "pw_oam.refresh-timer", FT_UINT16,
141 BASE_HEX, NULL, 0x0, NULL, HFILL }},
142
143 {&hf_pw_oam_total_tlv_len,
144 {"TLV Length", "pw_oam.total-tlv-len", FT_UINT8,
145 BASE_HEX, NULL, 0x0, NULL, HFILL }},
146
147 {&hf_pw_oam_flags,
148 {"Flags", "pw_oam.flags", FT_UINT8,
149 BASE_HEX, NULL, 0x0, "OAM Flags", HFILL }},
150
151 {&hf_pw_oam_flags_a,
152 {"Acknowledgement", "pw_oam.flags_a",
153 FT_BOOLEAN, 8, NULL, 0x0080, "ACK bit", HFILL}
154 },
155
156 {&hf_pw_oam_tlv_reserved,
157 {"Reserved", "pw_oam.tlv-reserved",
158 FT_UINT16, BASE_HEX, NULL, 0xC000, NULL, HFILL}
159 },
160
161 {&hf_pw_oam_tlv_type,
162 {"TLV Type", "pw_oam.tlv-type",
163 FT_UINT16, BASE_HEX, NULL, 0x3FFF, NULL, HFILL}
164 },
165
166 {&hf_pw_oam_tlv_len,
167 {"TLV Length", "pw_oam.tlv-len",
168 FT_UINT16, BASE_HEX, NULL, 0x00, NULL, HFILL}
169 },
170
171 {&hf_pw_oam_code,
172 {"Status code", "pw_oam.code", FT_UINT16,
173 BASE_HEX, VALS(pw_oam_code), 0x0, "PW Status Code", HFILL }
174 },
175
176 };
177
178 static gint *ett[] = {
179 &ett_pw_oam,
180 &ett_pw_oam_tlv_tree,
181 &ett_pw_oam_flags,
182 };
183
184 proto_pw_oam =
185 proto_register_protocol("Pseudo-Wire OAM", "PW-OAM "
186 "Pseudo-Wire OAM Protocol",
187 "pw_oam");
188
189 proto_register_field_array (proto_pw_oam, hf, array_length(hf));
190 proto_register_subtree_array (ett, array_length(ett));
191 }
192
193 void
proto_reg_handoff_pw_oam(void)194 proto_reg_handoff_pw_oam(void)
195 {
196 dissector_handle_t pw_oam_handle;
197
198 pw_oam_handle = create_dissector_handle( dissect_pw_oam, proto_pw_oam );
199 dissector_add_uint("pwach.channel_type", PW_ACH_TYPE_PW_OAM, pw_oam_handle);
200 }
201
202 /*
203 * Editor modelines - https://www.wireshark.org/tools/modelines.html
204 *
205 * Local variables:
206 * c-basic-offset: 2
207 * tab-width: 8
208 * indent-tabs-mode: nil
209 * End:
210 *
211 * vi: set shiftwidth=2 tabstop=8 expandtab:
212 * :indentSize=2:tabSize=8:noTabs=true:
213 */
214