Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-mpls-mac.c
blob39a88e74273cd2d9a101da593a7d22ec82df4315
1 /* packet-mpls-mac.c
3 * Routines for MPLS Media Access Control (MAC) Address Withdrawal over Static Pseudowire.
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #include "config.h"
14 #include <epan/packet.h>
15 #include "packet-mpls.h"
17 void proto_register_mpls_mac(void);
18 void proto_reg_handoff_mpls_mac(void);
20 static dissector_handle_t mpls_mac_handle;
22 static int proto_mpls_mac;
24 static int ett_mpls_mac;
25 static int ett_mpls_mac_flags;
26 static int ett_mpls_mac_tlv;
28 static int hf_mpls_mac_reserved;
29 static int hf_mpls_mac_tlv_length_total;
30 static int hf_mpls_mac_flags;
31 static int hf_mpls_mac_flags_a;
32 static int hf_mpls_mac_flags_r;
33 static int hf_mpls_mac_flags_reserved;
34 static int hf_mpls_mac_tlv;
35 static int hf_mpls_mac_tlv_res;
36 static int hf_mpls_mac_tlv_type;
37 static int hf_mpls_mac_tlv_length;
38 static int hf_mpls_mac_tlv_value;
39 static int hf_mpls_mac_tlv_sequence_number;
42 static int * const mpls_mac_flags[] = {
43 &hf_mpls_mac_flags_a,
44 &hf_mpls_mac_flags_r,
45 &hf_mpls_mac_flags_reserved,
46 NULL
49 static int
50 dissect_mpls_mac(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
52 proto_item *ti;
53 proto_tree *mac_tree;
54 uint32_t offset = 0, tlv_length, offset_end;
56 col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPLS-MAC");
57 col_clear(pinfo->cinfo, COL_INFO);
59 ti = proto_tree_add_item(tree, proto_mpls_mac, tvb, 0, -1, ENC_NA);
60 mac_tree = proto_item_add_subtree(ti, ett_mpls_mac);
61 /* Reserved */
62 proto_tree_add_item(mac_tree, hf_mpls_mac_reserved, tvb, offset, 2, ENC_NA);
63 offset += 2;
64 /* TLV length */
65 proto_tree_add_item_ret_uint(mac_tree, hf_mpls_mac_tlv_length_total, tvb, offset, 1, ENC_BIG_ENDIAN, &tlv_length);
66 offset += 1;
67 /* Flags */
68 proto_tree_add_bitmask(mac_tree, tvb, offset, hf_mpls_mac_flags,
69 ett_mpls_mac_flags,
70 mpls_mac_flags,
71 ENC_BIG_ENDIAN);
72 offset += 1;
73 offset_end = offset + tlv_length;
75 while(offset < offset_end){
76 uint32_t type, length;
77 proto_tree *tlv_tree;
79 ti = proto_tree_add_item(mac_tree, hf_mpls_mac_tlv, tvb, offset, 4, ENC_NA);
81 tlv_tree = proto_item_add_subtree(ti, ett_mpls_mac_tlv);
82 /* res(erved) */
83 proto_tree_add_item(tlv_tree, hf_mpls_mac_tlv_res, tvb, offset, 2, ENC_BIG_ENDIAN);
85 /* TLV Type */
86 proto_tree_add_item_ret_uint(tlv_tree, hf_mpls_mac_tlv_type, tvb, offset, 2, ENC_BIG_ENDIAN, &type);
87 offset += 2;
89 /* TLV Length */
90 proto_tree_add_item_ret_uint(tlv_tree, hf_mpls_mac_tlv_length, tvb, offset, 2, ENC_BIG_ENDIAN, &length);
91 offset += 2;
92 proto_item_set_len(ti, 2+2+length);
93 proto_item_append_text(ti, " (t=0x%x, l=%u)", type, length);
95 /* TLV Value */
96 proto_tree_add_item(tlv_tree, hf_mpls_mac_tlv_value, tvb, offset, length, ENC_NA);
98 switch(type){
99 case 0x0001:
100 proto_tree_add_item(tlv_tree, hf_mpls_mac_tlv_sequence_number, tvb, offset, 4, ENC_BIG_ENDIAN);
101 offset += 4;
102 break;
103 default:
104 offset += length;
105 break;
109 return offset;
112 void
113 proto_register_mpls_mac(void)
115 static hf_register_info hf[] = {
117 &hf_mpls_mac_reserved,
119 "Reserved", "mpls_mac.reserved",
120 FT_BYTES, BASE_NONE, NULL, 0x0,
121 NULL, HFILL
125 &hf_mpls_mac_tlv_length_total,
127 "TLV Length (Total)", "mpls_mac.tlv_length_total",
128 FT_UINT8, BASE_DEC, NULL, 0x0,
129 NULL, HFILL
133 &hf_mpls_mac_flags,
135 "Flags", "mpls_mac.flags",
136 FT_UINT8, BASE_HEX, NULL, 0x0,
137 NULL, HFILL
141 &hf_mpls_mac_flags_a,
143 "Flags A", "mpls_mac.flags.a",
144 FT_BOOLEAN, 8, NULL, 0x80,
145 "set by a receiver to acknowledge receipt and processing of a MAC Address Withdraw OAM Message", HFILL
149 &hf_mpls_mac_flags_r,
151 "Flags R", "mpls_mac.flags.r",
152 FT_BOOLEAN, 8, NULL, 0x40,
153 "Set to indicate if the sender is requesting reset of the sequence numbers", HFILL
157 &hf_mpls_mac_flags_reserved,
159 "Flags Reserved", "mpls_mac.flags.reserved",
160 FT_UINT8, BASE_HEX, NULL, 0x3F,
161 NULL, HFILL
165 &hf_mpls_mac_tlv,
167 "TLV", "mpls_mac.tlv",
168 FT_NONE, BASE_NONE, NULL, 0x0,
169 NULL, HFILL
173 &hf_mpls_mac_tlv_res,
175 "Res(erved)", "mpls_mac.tlv.res",
176 FT_UINT16, BASE_HEX, NULL, 0xC000,
177 NULL, HFILL
181 &hf_mpls_mac_tlv_type,
183 "TLV Type", "mpls_mac.tlv.type",
184 FT_UINT16, BASE_HEX, NULL, 0x3FFF,
185 NULL, HFILL
189 &hf_mpls_mac_tlv_length,
191 "TLV Length", "mpls_mac.tlv.length",
192 FT_UINT16, BASE_DEC, NULL, 0x0,
193 NULL, HFILL
197 &hf_mpls_mac_tlv_value,
199 "TLV Value", "mpls_mac.tlv.value",
200 FT_BYTES, BASE_NONE, NULL, 0x0,
201 NULL, HFILL
205 &hf_mpls_mac_tlv_sequence_number,
207 "Sequence Number", "mpls_mac.tlv.sequence_number",
208 FT_UINT32, BASE_DEC, NULL, 0x0,
209 NULL, HFILL
214 static int *ett[] = {
215 &ett_mpls_mac,
216 &ett_mpls_mac_flags,
217 &ett_mpls_mac_tlv,
220 proto_mpls_mac =
221 proto_register_protocol("Media Access Control (MAC) Address Withdrawal over Static Pseudowire", "MPLS-MAC", "mpls_mac");
223 proto_register_field_array(proto_mpls_mac, hf, array_length(hf));
224 proto_register_subtree_array(ett, array_length(ett));
226 mpls_mac_handle = register_dissector("mpls_mac", dissect_mpls_mac, proto_mpls_mac);
229 void
230 proto_reg_handoff_mpls_mac(void)
232 dissector_add_uint("pwach.channel_type", PW_ACH_TYPE_MAC, mpls_mac_handle);
236 * Editor modelines - https://www.wireshark.org/tools/modelines.html
238 * Local variables:
239 * c-basic-offset: 4
240 * tab-width: 8
241 * indent-tabs-mode: nil
242 * End:
244 * vi: set shiftwidth=4 tabstop=8 expandtab:
245 * :indentSize=4:tabSize=8:noTabs=true: