/src/wireshark/epan/dissectors/packet-ieee8021cb.c
Line | Count | Source |
1 | | /* packet-ieee8021cb.c |
2 | | * Routines for 802.1CB R-tag ethernet header disassembly |
3 | | * |
4 | | * Copyright 2020, Rene Nielsen <rene.nielsen@microchip.com> |
5 | | * In association with Microchip Technology Inc. |
6 | | * |
7 | | * Wireshark - Network traffic analyzer |
8 | | * By Gerald Combs <gerald@wireshark.org> |
9 | | * Copyright 1998 Gerald Combs |
10 | | * |
11 | | * SPDX-License-Identifier: GPL-2.0-or-later |
12 | | */ |
13 | | |
14 | | #include "config.h" |
15 | | |
16 | | #include <epan/packet.h> |
17 | | #include <epan/capture_dissectors.h> |
18 | | #include <wsutil/pint.h> |
19 | | #include <epan/addr_resolv.h> |
20 | | |
21 | | #include "packet-ipx.h" |
22 | | #include "packet-llc.h" |
23 | | #include <epan/etypes.h> |
24 | | #include <epan/prefs.h> |
25 | | |
26 | | void proto_register_ieee8021cb(void); |
27 | | void proto_reg_handoff_ieee8021cb(void); |
28 | | |
29 | | static dissector_handle_t ieee8021cb_handle; |
30 | | static dissector_handle_t ethertype_handle; |
31 | | |
32 | | static capture_dissector_handle_t ieee8021cb_cap_handle; |
33 | | static capture_dissector_handle_t ipx_cap_handle; |
34 | | static capture_dissector_handle_t llc_cap_handle; |
35 | | |
36 | | /* GLOBALS ************************************************************/ |
37 | | |
38 | | static int proto_ieee8021cb; |
39 | | |
40 | | /* dot1cb R-tag fields */ |
41 | | static int hf_ieee8021cb_res; |
42 | | static int hf_ieee8021cb_seq; |
43 | | |
44 | | /* Encapsulated protocol */ |
45 | | static int hf_ieee8021cb_etype; |
46 | | static int hf_ieee8021cb_trailer; |
47 | | |
48 | | static int ett_ieee8021cb; |
49 | | |
50 | 0 | #define IEEE8021CB_LEN 6 |
51 | | |
52 | | static bool |
53 | | capture_ieee8021cb(const unsigned char *pd, int offset, int len, capture_packet_info_t *cpinfo, const union wtap_pseudo_header *pseudo_header) |
54 | 0 | { |
55 | 0 | uint16_t encap_proto; |
56 | |
|
57 | 0 | if (!BYTES_ARE_IN_FRAME(offset, len, IEEE8021CB_LEN + 1)) |
58 | 0 | return false; |
59 | | |
60 | 0 | encap_proto = pntohu16( &pd[offset + IEEE8021CB_LEN - 2] ); |
61 | 0 | if (encap_proto <= IEEE_802_3_MAX_LEN) { |
62 | 0 | if ( pd[offset + IEEE8021CB_LEN] == 0xff |
63 | 0 | && pd[offset + IEEE8021CB_LEN + 1] == 0xff ) { |
64 | 0 | return call_capture_dissector(ipx_cap_handle, pd, offset + IEEE8021CB_LEN, len, cpinfo, pseudo_header); |
65 | 0 | } |
66 | 0 | else { |
67 | 0 | return call_capture_dissector(llc_cap_handle, pd, offset + IEEE8021CB_LEN, len, cpinfo, pseudo_header); |
68 | 0 | } |
69 | 0 | } |
70 | | |
71 | 0 | return try_capture_dissector("ethertype", encap_proto, pd, offset + IEEE8021CB_LEN, len, cpinfo, pseudo_header); |
72 | 0 | } |
73 | | |
74 | | /* Dissector *************************************************************/ |
75 | | static |
76 | | int dissect_ieee8021cb(tvbuff_t *tvb, packet_info *pinfo, |
77 | | proto_tree *tree, void* data _U_) |
78 | 0 | { |
79 | 0 | proto_tree *ptree = NULL; |
80 | 0 | uint16_t seq, pro; |
81 | 0 | ethertype_data_t ethertype_data = { 0 }; |
82 | 0 | proto_tree *ieee8021cb_tree; |
83 | | |
84 | | /* add info to column display */ |
85 | 0 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "802.1CB R-Tag"); |
86 | 0 | col_clear(pinfo->cinfo, COL_INFO); |
87 | |
|
88 | 0 | seq = tvb_get_ntohs(tvb, 2); |
89 | 0 | pro = tvb_get_ntohs(tvb, 4); |
90 | |
|
91 | 0 | col_add_fstr(pinfo->cinfo, COL_INFO, "SEQ: %u", seq); |
92 | | |
93 | | /* create the protocol tree */ |
94 | 0 | ptree = proto_tree_add_item(tree, proto_ieee8021cb, tvb, 0, IEEE8021CB_LEN, ENC_NA); |
95 | 0 | ieee8021cb_tree = proto_item_add_subtree(ptree, ett_ieee8021cb); |
96 | | |
97 | | /* add fields */ |
98 | 0 | proto_tree_add_uint(ieee8021cb_tree, hf_ieee8021cb_seq, tvb, 2, 2, seq); |
99 | 0 | proto_tree_add_uint(ieee8021cb_tree, hf_ieee8021cb_etype, tvb, 4, 2, pro); |
100 | |
|
101 | 0 | proto_item_append_text(ptree, ", SEQ: %u", seq); |
102 | |
|
103 | 0 | ethertype_data.fh_tree = ieee8021cb_tree; |
104 | 0 | ethertype_data.trailer_id = hf_ieee8021cb_trailer; |
105 | 0 | ethertype_data.fcs_len = 0; |
106 | 0 | ethertype_data.etype = pro; |
107 | 0 | ethertype_data.payload_offset = IEEE8021CB_LEN; |
108 | | |
109 | | /* 802.1CB tags are always followed by an ethertype; call next dissector |
110 | | based on ethertype */ |
111 | 0 | call_dissector_with_data(ethertype_handle, tvb, pinfo, tree, ðertype_data); |
112 | |
|
113 | 0 | return tvb_captured_length(tvb); |
114 | 0 | } |
115 | | |
116 | | void |
117 | | proto_register_ieee8021cb(void) |
118 | 16 | { |
119 | 16 | static hf_register_info hf_1cb[] = { |
120 | 16 | { &hf_ieee8021cb_res, { |
121 | 16 | "Reserved", "ieee8021cb.reserved", FT_UINT16, BASE_HEX, |
122 | 16 | NULL, 0x0, NULL, HFILL }}, |
123 | 16 | { &hf_ieee8021cb_seq, { |
124 | 16 | "SEQ", "ieee8021cb.seq", FT_UINT16, BASE_HEX_DEC, |
125 | 16 | NULL, 0x0, NULL, HFILL }}, |
126 | 16 | { &hf_ieee8021cb_etype, { |
127 | 16 | "Type", "ieee8021cb.etype", FT_UINT16, BASE_HEX, |
128 | 16 | VALS(etype_vals), 0x0, "Ethertype", HFILL }}, |
129 | 16 | { &hf_ieee8021cb_trailer, { |
130 | 16 | "Trailer", "ieee8021cb.trailer", FT_BYTES, BASE_NONE, |
131 | 16 | NULL, 0x0, NULL, HFILL }} |
132 | 16 | }; |
133 | | |
134 | 16 | static int *ett[] = { |
135 | 16 | &ett_ieee8021cb |
136 | 16 | }; |
137 | | |
138 | | /* registration */ |
139 | 16 | proto_ieee8021cb = proto_register_protocol("802.1CB Redundancy Tag", "R-Tag", "ieee8021cb"); |
140 | 16 | proto_register_field_array(proto_ieee8021cb, hf_1cb, array_length(hf_1cb)); |
141 | 16 | proto_register_subtree_array(ett, array_length(ett)); |
142 | | |
143 | 16 | ieee8021cb_handle = register_dissector("ieee8021cb", dissect_ieee8021cb, proto_ieee8021cb); |
144 | 16 | ieee8021cb_cap_handle = register_capture_dissector("ieee8021cb", capture_ieee8021cb, proto_ieee8021cb); |
145 | 16 | } |
146 | | |
147 | | void |
148 | | proto_reg_handoff_ieee8021cb(void) |
149 | 16 | { |
150 | | |
151 | 16 | dissector_add_uint("ethertype", ETHERTYPE_IEEE_802_1CB, ieee8021cb_handle); |
152 | 16 | ethertype_handle = find_dissector_add_dependency("ethertype", proto_ieee8021cb); |
153 | 16 | capture_dissector_add_uint("ethertype", ETHERTYPE_IEEE_802_1CB, ieee8021cb_cap_handle); |
154 | | |
155 | 16 | ipx_cap_handle = find_capture_dissector("ipx"); |
156 | 16 | llc_cap_handle = find_capture_dissector("llc"); |
157 | 16 | } |
158 | | |
159 | | /* |
160 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
161 | | * |
162 | | * Local Variables: |
163 | | * c-basic-offset: 4 |
164 | | * tab-width: 8 |
165 | | * indent-tabs-mode: nil |
166 | | * End: |
167 | | * |
168 | | * ex: set shiftwidth=4 tabstop=8 expandtab: |
169 | | * :indentSize=4:tabSize=8:noTabs=true: |
170 | | */ |