2 * Routines for 802.1ah ethernet header disassembly
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
28 #include <epan/packet.h>
29 #include <wsutil/pint.h>
30 #include <epan/addr_resolv.h>
32 #include "packet-ieee8021ah.h"
33 #include "packet-ipx.h"
34 #include "packet-llc.h"
35 #include "packet-vlan.h"
36 #include <epan/etypes.h>
37 #include <epan/prefs.h>
39 void proto_reg_handoff_ieee8021ah(void);
40 void dissect_ieee8021ah_common(tvbuff_t
*tvb
, packet_info
*pinfo
,
41 proto_tree
*tree
, proto_tree
*parent
, int tree_index
);
43 /* GLOBALS ************************************************************/
45 /* ethertype for 802.1ah tag - encapsulating an Ethernet packet */
46 static unsigned int ieee8021ah_ethertype
= ETHERTYPE_IEEE_802_1AH
;
48 static int proto_ieee8021ah
= -1;
49 static int proto_ieee8021ad
= -1;
51 /* dot1ad B-tag fields */
52 static int hf_ieee8021ad_priority
= -1;
53 static int hf_ieee8021ad_cfi
= -1;
54 static int hf_ieee8021ad_id
= -1;
55 static int hf_ieee8021ad_svid
= -1;
56 static int hf_ieee8021ad_cvid
= -1;
58 /* dot1ah C-tag fields */
59 static int hf_ieee8021ah_priority
= -1;
60 static int hf_ieee8021ah_drop
= -1; /* drop eligibility */
61 static int hf_ieee8021ah_nca
= -1; /* no customer addresses (c_daddr & c_saddr are 0) */
62 static int hf_ieee8021ah_res1
= -1; /* 2 bits reserved; ignored on receive */
63 static int hf_ieee8021ah_res2
= -1; /* 2 bits reserved; delete frame if non-zero */
64 static int hf_ieee8021ah_isid
= -1; /* I-SID */
65 static int hf_ieee8021ah_c_daddr
= -1; /* encapsulated customer dest addr */
66 static int hf_ieee8021ah_c_saddr
= -1; /* encapsulated customer src addr */
68 static int hf_ieee8021ah_etype
= -1;
69 /* static int hf_ieee8021ah_len = -1; */
70 static int hf_ieee8021ah_trailer
= -1;
72 static gint ett_ieee8021ah
= -1;
73 static gint ett_ieee8021ad
= -1;
75 /* FUNCTIONS ************************************************************/
79 capture_ieee8021ah(const guchar
*pd
, int offset
, int len
, packet_counts
*ld
)
83 if (!BYTES_ARE_IN_FRAME(offset
, len
, IEEE8021AH_LEN
+ 1)) {
87 encap_proto
= pntohs( &pd
[offset
+ IEEE8021AH_LEN
- 2] );
88 if (encap_proto
<= IEEE_802_3_MAX_LEN
) {
89 if ( pd
[offset
+ IEEE8021AH_LEN
] == 0xff
90 && pd
[offset
+ IEEE8021AH_LEN
+ 1] == 0xff ) {
94 capture_llc(pd
, offset
+ IEEE8021AH_LEN
,len
,ld
);
98 capture_ethertype(encap_proto
, pd
, offset
+ IEEE8021AH_LEN
, len
, ld
);
102 /* Dissector *************************************************************/
105 dissect_ieee8021ad(tvbuff_t
*tvb
, packet_info
*pinfo
,
108 proto_tree
*ptree
= NULL
;
109 proto_tree
*tagtree
= NULL
;
112 proto_tree
*volatile ieee8021ad_tree
;
113 proto_tree
*volatile ieee8021ad_tag_tree
;
114 int proto_tree_index
;
115 tvbuff_t
*volatile next_tvb
= NULL
;
118 proto_tree_index
= proto_ieee8021ad
;
120 /* add info to column display */
121 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "802.1ad");
122 col_clear(pinfo
->cinfo
, COL_INFO
);
124 tci
= tvb_get_ntohs( tvb
, 0 );
126 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
127 "PRI: %d DROP: %d ID: %d",
128 (tci
>> 13), ((tci
>> 12) & 1), (tci
& 0xFFF));
130 /* create the protocol tree */
131 ieee8021ad_tree
= NULL
;
134 ptree
= proto_tree_add_item(tree
, proto_tree_index
, tvb
, 0, IEEE8021AD_LEN
, ENC_NA
);
135 ieee8021ad_tree
= proto_item_add_subtree(ptree
, ett_ieee8021ad
);
138 encap_proto
= tvb_get_ntohs(tvb
, IEEE8021AD_LEN
- 2);
140 /* If it's a 1ah frame, create subtree for B-Tag, rename overall
141 tree to 802.1ah, pass to 1ah dissector */
142 if (encap_proto
== ETHERTYPE_IEEE_802_1AH
) {
144 tagtree
= proto_tree_add_item(ptree
, proto_tree_index
, tvb
, 0, 2, ENC_NA
);
145 ieee8021ad_tag_tree
= proto_item_add_subtree(tagtree
, ett_ieee8021ad
);
148 proto_tree_add_uint(ieee8021ad_tag_tree
, hf_ieee8021ad_priority
, tvb
,
150 proto_tree_add_uint(ieee8021ad_tag_tree
, hf_ieee8021ad_cfi
, tvb
, 0, 1, tci
);
151 proto_tree_add_uint(ieee8021ad_tag_tree
, hf_ieee8021ad_id
, tvb
, 0, 2, tci
);
153 /* set label of B-tag subtree */
154 proto_item_set_text(ieee8021ad_tag_tree
, "B-Tag, B-VID: %d", tci
& 0x0FFF);
157 next_tvb
= tvb_new_subset_remaining(tvb
, IEEE8021AD_LEN
);
160 /* add bvid to label */
161 proto_item_set_text(ptree
, "IEEE 802.1ah, B-VID: %d", tci
& 0x0FFF);
163 dissect_ieee8021ah_common(next_tvb
, pinfo
, ptree
, tree
, proto_tree_index
);
166 dissect_ieee8021ah_common(next_tvb
, pinfo
, tree
, NULL
, proto_tree_index
);
170 } else if (encap_proto
== ETHERTYPE_IEEE_802_1AD
) {
171 /* two VLAN tags (i.e. Q-in-Q) */
172 ctci
= tvb_get_ntohs(tvb
, IEEE8021AD_LEN
);
176 proto_tree_add_uint(ieee8021ad_tree
, hf_ieee8021ad_priority
, tvb
,
178 proto_tree_add_uint(ieee8021ad_tree
, hf_ieee8021ad_cfi
, tvb
, 0, 1, tci
);
179 proto_tree_add_uint(ieee8021ad_tree
, hf_ieee8021ad_svid
, tvb
, 0, 2, tci
);
180 proto_tree_add_uint(ieee8021ad_tree
, hf_ieee8021ad_priority
, tvb
,
181 IEEE8021AD_LEN
, 1, ctci
);
182 proto_tree_add_uint(ieee8021ad_tree
, hf_ieee8021ad_cfi
, tvb
,
183 IEEE8021AD_LEN
, 1, ctci
);
184 proto_tree_add_uint(ieee8021ad_tree
, hf_ieee8021ad_cvid
, tvb
, IEEE8021AD_LEN
,
188 proto_item_set_text(ptree
, "IEEE 802.1ad, S-VID: %d, C-VID: %d", tci
& 0x0FFF,
191 /* 802.1ad tags are always followed by an ethertype; call next
192 dissector based on ethertype */
193 encap_proto
= tvb_get_ntohs(tvb
, IEEE8021AD_LEN
* 2 - 2);
194 ethertype(encap_proto
, tvb
, IEEE8021AD_LEN
* 2, pinfo
, tree
, ieee8021ad_tree
,
195 hf_ieee8021ah_etype
, hf_ieee8021ah_trailer
, 0);
197 /* Something else (shouldn't really happen, but we'll support it anyways) */
200 proto_tree_add_uint(ieee8021ad_tree
, hf_ieee8021ad_priority
, tvb
,
202 proto_tree_add_uint(ieee8021ad_tree
, hf_ieee8021ad_cfi
, tvb
, 0, 1, tci
);
203 proto_tree_add_uint(ieee8021ad_tree
, hf_ieee8021ad_id
, tvb
, 0, 2, tci
);
206 /* label should be 802.1ad not .1ah */
207 proto_item_set_text(ptree
, "IEEE 802.1ad, ID: %d", tci
& 0x0FFF);
209 /* 802.1ad tags are always followed by an ethertype; call next
210 dissector based on ethertype */
211 ethertype(encap_proto
, tvb
, IEEE8021AD_LEN
, pinfo
, tree
, ieee8021ad_tree
,
212 hf_ieee8021ah_etype
, hf_ieee8021ah_trailer
, 0);
217 dissect_ieee8021ah_common(tvbuff_t
*tvb
, packet_info
*pinfo
,
218 proto_tree
*tree
, proto_tree
*parent
, int tree_index
) {
222 proto_tree
*volatile ieee8021ah_tag_tree
;
224 /* for parsing out ethernet addrs */
225 const guint8
*src_addr
, *dst_addr
;
227 tci
= tvb_get_ntohl( tvb
, 0 );
229 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
230 "PRI: %d Drop: %d NCA: %d Res1: %d Res2: %d I-SID: %d",
231 (tci
>> 29), ((tci
>> 28) & 1), ((tci
>> 27) & 1),
232 ((tci
>> 26) & 1), ((tci
>> 24) & 3), tci
& IEEE8021AH_ISIDMASK
);
234 /* create the protocol tree */
236 ieee8021ah_tag_tree
= NULL
;
240 ptree
= proto_tree_add_item(tree
, tree_index
, tvb
, 0, 4, ENC_NA
);
241 ieee8021ah_tag_tree
= proto_item_add_subtree(ptree
, ett_ieee8021ah
);
244 proto_tree_add_uint(ieee8021ah_tag_tree
, hf_ieee8021ah_priority
, tvb
,
246 proto_tree_add_uint(ieee8021ah_tag_tree
, hf_ieee8021ah_drop
, tvb
, 0, 1, tci
);
247 proto_tree_add_uint(ieee8021ah_tag_tree
, hf_ieee8021ah_nca
, tvb
, 0, 1, tci
);
248 proto_tree_add_uint(ieee8021ah_tag_tree
, hf_ieee8021ah_res1
, tvb
, 0, 1, tci
);
249 proto_tree_add_uint(ieee8021ah_tag_tree
, hf_ieee8021ah_res2
, tvb
, 0, 1, tci
);
250 proto_tree_add_uint(ieee8021ah_tag_tree
, hf_ieee8021ah_isid
, tvb
, 1, 3, tci
);
252 proto_item_set_text(ieee8021ah_tag_tree
, "I-Tag, I-SID: %d",
253 tci
& IEEE8021AH_ISIDMASK
);
255 /* ensure size of tag */
256 tvb_ensure_bytes_exist(tvb
, 4, 12);
258 /* parse out IP addrs */
259 dst_addr
= tvb_get_ptr(tvb
, 4, 6); /* safe to use this function? */
260 src_addr
= tvb_get_ptr(tvb
, 10, 6);
262 proto_tree_add_ether(tree
, hf_ieee8021ah_c_daddr
,
263 tvb
, 4, 6, dst_addr
);
265 proto_tree_add_ether(tree
, hf_ieee8021ah_c_saddr
,
266 tvb
, 10, 6, src_addr
);
268 /* add text to 802.1ad label */
270 proto_item_append_text(tree
, ", I-SID: %d, C-Src: %s (%s), C-Dst: %s (%s)",
271 tci
& IEEE8021AH_ISIDMASK
, get_ether_name(src_addr
),
272 ether_to_str(src_addr
), get_ether_name(dst_addr
),
273 ether_to_str(dst_addr
));
277 encap_proto
= tvb_get_ntohs(tvb
, IEEE8021AH_LEN
- 2);
279 /* 802.1ah I-tags are always followed by an ethertype; call next
280 dissector based on ethertype */
282 /* If this was preceded by a 802.1ad tag, must pass original tree
283 to next dissector, not 802.1ad tree */
285 ethertype(encap_proto
, tvb
, IEEE8021AH_LEN
, pinfo
, parent
, tree
,
286 hf_ieee8021ah_etype
, hf_ieee8021ah_trailer
, 0);
289 ethertype(encap_proto
, tvb
, IEEE8021AH_LEN
, pinfo
, tree
, tree
,
290 hf_ieee8021ah_etype
, hf_ieee8021ah_trailer
, 0);
296 dissect_ieee8021ah(tvbuff_t
*tvb
, packet_info
*pinfo
,
301 proto_tree
*volatile ieee8021ah_tree
;
302 int proto_tree_index
;
305 proto_tree_index
= proto_ieee8021ah
;
307 /* add info to column display */
308 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "802.1ah");
309 col_clear(pinfo
->cinfo
, COL_INFO
);
311 tci
= tvb_get_ntohl( tvb
, 0 );
313 col_add_fstr(pinfo
->cinfo
, COL_INFO
,
314 "PRI: %d Drop: %d NCA: %d Res1: %d Res2: %d I-SID: %d",
315 (tci
>> 29), ((tci
>> 28) & 1), ((tci
>> 27) & 1),
316 ((tci
>> 26) & 1), ((tci
>> 24) & 3), (tci
& 0x00FFFFFF));
318 /* create the protocol tree */
319 ieee8021ah_tree
= NULL
;
322 ptree
= proto_tree_add_item(tree
, proto_tree_index
, tvb
, 0, IEEE8021AH_LEN
, ENC_NA
);
323 ieee8021ah_tree
= proto_item_add_subtree(ptree
, ett_ieee8021ah
);
325 dissect_ieee8021ah_common(tvb
, pinfo
, ieee8021ah_tree
, tree
, proto_tree_index
);
329 /* Protocol Registration **************************************************/
332 proto_register_ieee8021ah(void)
334 static hf_register_info hf
[] = {
335 { &hf_ieee8021ah_priority
, {
336 "Priority", "ieee8021ah.priority", FT_UINT32
, BASE_DEC
,
337 0, 0xE0000000, NULL
, HFILL
}},
338 { &hf_ieee8021ah_drop
, {
339 "DROP", "ieee8021ah.drop", FT_UINT32
, BASE_DEC
,
340 0, 0x10000000, NULL
, HFILL
}},
341 { &hf_ieee8021ah_nca
, {
342 "NCA", "ieee8021ah.nca", FT_UINT32
, BASE_DEC
,
343 0, 0x08000000, "No Customer Addresses", HFILL
}},
344 { &hf_ieee8021ah_res1
, {
345 "RES1", "ieee8021ah.res1", FT_UINT32
, BASE_DEC
,
346 0, 0x04000000, "Reserved1", HFILL
}},
347 { &hf_ieee8021ah_res2
, {
348 "RES2", "ieee8021ah.res2", FT_UINT32
, BASE_DEC
,
349 0, 0x03000000, "Reserved2", HFILL
}},
350 { &hf_ieee8021ah_isid
, {
351 "I-SID", "ieee8021ah.isid", FT_UINT32
, BASE_DEC
,
352 0, 0x00FFFFFF, NULL
, HFILL
}},
353 { &hf_ieee8021ah_c_daddr
, {
354 "C-Destination", "ieee8021ah.cdst", FT_ETHER
, BASE_NONE
,
355 NULL
, 0x0, "Customer Destination Address", HFILL
}},
356 { &hf_ieee8021ah_c_saddr
, {
357 "C-Source", "ieee8021ah.csrc", FT_ETHER
, BASE_NONE
,
358 NULL
, 0x0, "Customer Source Address", HFILL
}},
359 { &hf_ieee8021ah_etype
, {
360 "Type", "ieee8021ah.etype", FT_UINT16
, BASE_HEX
,
361 VALS(etype_vals
), 0x0, NULL
, HFILL
}},
363 { &hf_ieee8021ah_len
, {
364 "Length", "ieee8021ah.len", FT_UINT16
, BASE_DEC
,
365 NULL
, 0x0, NULL
, HFILL
}},
367 { &hf_ieee8021ah_trailer
, {
368 "Trailer", "ieee8021ah.trailer", FT_BYTES
, BASE_NONE
,
369 NULL
, 0x0, "802.1ah Trailer", HFILL
}}
372 static hf_register_info hf_1ad
[] = {
373 { &hf_ieee8021ad_priority
, {
374 "Priority", "ieee8021ad.priority", FT_UINT16
, BASE_DEC
,
375 0, 0xE000, NULL
, HFILL
}},
376 { &hf_ieee8021ad_cfi
, {
377 "DEI", "ieee8021ad.dei", FT_UINT16
, BASE_DEC
,
378 0, 0x1000, "Drop Eligibility", HFILL
}},
379 { &hf_ieee8021ad_id
, {
380 "ID", "ieee8021ad.id", FT_UINT16
, BASE_DEC
,
381 0, 0x0FFF, "Vlan ID", HFILL
}},
382 { &hf_ieee8021ad_svid
, {
383 "ID", "ieee8021ad.svid", FT_UINT16
, BASE_DEC
,
384 0, 0x0FFF, "S-Vlan ID", HFILL
}},
385 { &hf_ieee8021ad_cvid
, {
386 "ID", "ieee8021ad.cvid", FT_UINT16
, BASE_DEC
,
387 0, 0x0FFF, "C-Vlan ID", HFILL
}},
390 static gint
*ett
[] = {
396 module_t
*ieee8021ah_module
;
400 proto_ieee8021ah
= proto_register_protocol("IEEE 802.1ah", "IEEE 802.1AH",
402 proto_register_field_array(proto_ieee8021ah
, hf
, array_length(hf
));
404 proto_ieee8021ad
= proto_register_protocol("IEEE 802.1ad", "IEEE 802.1AD",
406 proto_register_field_array(proto_ieee8021ad
, hf_1ad
, array_length(hf_1ad
));
408 /* register subtree array for both */
409 proto_register_subtree_array(ett
, array_length(ett
));
411 /* add a user preference to set the 802.1ah ethertype */
412 ieee8021ah_module
= prefs_register_protocol(proto_ieee8021ah
,
413 proto_reg_handoff_ieee8021ah
);
414 prefs_register_uint_preference(ieee8021ah_module
, "8021ah_ethertype",
415 "802.1ah Ethertype (in hex)",
416 "(Hexadecimal) Ethertype used to indicate IEEE 802.1ah tag.",
417 16, &ieee8021ah_ethertype
);
421 proto_reg_handoff_ieee8021ah(void)
423 static gboolean prefs_initialized
= FALSE
;
424 static dissector_handle_t ieee8021ah_handle
;
425 static unsigned int old_ieee8021ah_ethertype
;
427 if (!prefs_initialized
){
428 dissector_handle_t ieee8021ad_handle
;
429 ieee8021ah_handle
= create_dissector_handle(dissect_ieee8021ah
,
431 ieee8021ad_handle
= create_dissector_handle(dissect_ieee8021ad
,
433 dissector_add_uint("ethertype", ETHERTYPE_IEEE_802_1AD
, ieee8021ad_handle
);
434 prefs_initialized
= TRUE
;
437 dissector_delete_uint("ethertype", old_ieee8021ah_ethertype
, ieee8021ah_handle
);
440 old_ieee8021ah_ethertype
= ieee8021ah_ethertype
;
441 dissector_add_uint("ethertype", ieee8021ah_ethertype
, ieee8021ah_handle
);