/src/wireshark/epan/dissectors/packet-esis.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* packet-esis.c |
2 | | * Routines for ISO/OSI End System to Intermediate System |
3 | | * Routing Exchange Protocol ISO 9542. |
4 | | * |
5 | | * Ralf Schneider <Ralf.Schneider@t-online.de> |
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/expert.h> |
18 | | #include <epan/nlpid.h> |
19 | | #include <epan/unit_strings.h> |
20 | | #include "packet-osi.h" |
21 | | #include "packet-osi-options.h" |
22 | | |
23 | | /* The version we support is 1 */ |
24 | 281 | #define ESIS_REQUIRED_VERSION 1 |
25 | | |
26 | | /* ESIS PDU types */ |
27 | 99 | #define ESIS_ESH_PDU 02 |
28 | 15 | #define ESIS_ISH_PDU 04 |
29 | 12 | #define ESIS_RD_PDU 06 |
30 | | |
31 | | /* The length of the fixed part */ |
32 | 448 | #define ESIS_HDR_FIXED_LENGTH 9 |
33 | | |
34 | | void proto_register_esis(void); |
35 | | void proto_reg_handoff_esis(void); |
36 | | |
37 | | /* esis base header */ |
38 | | static int proto_esis; |
39 | | |
40 | | static int hf_esis_nlpi; |
41 | | static int hf_esis_length; |
42 | | static int hf_esis_version; |
43 | | static int hf_esis_reserved; |
44 | | static int hf_esis_type; |
45 | | static int hf_esis_holdtime; |
46 | | static int hf_esis_checksum; |
47 | | static int hf_esis_checksum_status; |
48 | | /* Generated from convert_proto_tree_add_text.pl */ |
49 | | static int hf_esis_dal; |
50 | | static int hf_esis_number_of_source_addresses; |
51 | | static int hf_esis_netl; |
52 | | static int hf_esis_sal; |
53 | | static int hf_esis_sa; |
54 | | static int hf_esis_bsnpal; |
55 | | static int hf_esis_net; |
56 | | static int hf_esis_da; |
57 | | static int hf_esis_bsnpa; |
58 | | |
59 | | static int ett_esis; |
60 | | static int ett_esis_area_addr; |
61 | | static int ett_esis_network; |
62 | | static int ett_esis_dest_addr; |
63 | | static int ett_esis_subnetwork; |
64 | | |
65 | | |
66 | | static expert_field ei_esis_version; |
67 | | static expert_field ei_esis_length; |
68 | | static expert_field ei_esis_type; |
69 | | static expert_field ei_esis_checksum; |
70 | | |
71 | | static dissector_handle_t esis_handle; |
72 | | |
73 | | static const value_string esis_vals[] = { |
74 | | { ESIS_ESH_PDU, "ES HELLO"}, |
75 | | { ESIS_ISH_PDU, "IS HELLO"}, |
76 | | { ESIS_RD_PDU, "RD REQUEST"}, |
77 | | { 0, NULL} }; |
78 | | |
79 | | /* ################## Descriptions ###########################################*/ |
80 | | /* Parameters for the ESH PDU |
81 | | * Source Address Parameter: |
82 | | * |
83 | | * Octet: Length: Parameter Type: |
84 | | * 10 1 Number of Source Addresses ( NSAPs served by this Network |
85 | | * 11 1 Source Address Length Indicator ( SAL ) # Entity ) |
86 | | * 12-m-1 variable Source Address ( NSAP ) |
87 | | * m Options, dissected in osi.c |
88 | | * |
89 | | * |
90 | | * Parameter for the ISH PDU: |
91 | | * Network Entity Title Parameter: |
92 | | * |
93 | | * Octet: Length: Parameter Type: |
94 | | * 10 1 Network Entity Title Length Indicator ( NETL ) |
95 | | * 11-m-1 variable Network Entity Title ( NET ) |
96 | | * m Options, dissected in osi.c |
97 | | * |
98 | | * |
99 | | * Parameter for the RD PDU: |
100 | | * When re-directed to an IS: |
101 | | * |
102 | | * Octet: Length: Parameter Type: |
103 | | * 10 1 Destination Address Length Indicator ( DAL ) |
104 | | * 11>m-1 variable Destination Address ( DA ) |
105 | | * m 1 Subnetwork Address Length Indicator ( BSNPAL ) |
106 | | * m+1>n-1 variable Subnetwork Address ( BSNPA ) |
107 | | * n 1 Network Entity Title Length Indicator ( NETL ) |
108 | | * n+1>p-1 variable Network Entity Title ( NET ) |
109 | | * p Options, dissected in osi.c |
110 | | * |
111 | | * |
112 | | * Parameter for the RD PDU: |
113 | | * When re-directed to an ES: |
114 | | * |
115 | | * Octet: Length: Parameter Type: |
116 | | * 10 1 Destination Address Length Indicator ( DAL ) |
117 | | * 11>m-1 variable Destination Address ( DA ) |
118 | | * m 1 Subnetwork Address Length Indicator ( BSNPAL ) |
119 | | * m+1>n-1 variable Subnetwork Address ( BSNPA ) |
120 | | * n 1 Network Entity Title Length Indicator ( NETL ) == 0 |
121 | | * n+1 Options, dissected in osi.c |
122 | | * |
123 | | */ |
124 | | |
125 | | /* ############################ Tool Functions ############################## */ |
126 | | |
127 | | |
128 | | static void |
129 | 99 | esis_dissect_esh_pdu( uint8_t len, tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo) { |
130 | 99 | proto_tree *esis_area_tree; |
131 | 99 | int offset = 0; |
132 | 99 | unsigned no_sa, sal; |
133 | | |
134 | 99 | proto_item *ti; |
135 | | |
136 | 99 | offset += ESIS_HDR_FIXED_LENGTH; |
137 | | |
138 | 99 | ti = proto_tree_add_item_ret_uint( tree, hf_esis_number_of_source_addresses, tvb, offset, 1, ENC_NA, &no_sa); |
139 | 99 | len--; |
140 | 99 | offset++; |
141 | | |
142 | 99 | esis_area_tree = proto_item_add_subtree( ti, ett_esis_area_addr ); |
143 | 1.90k | while ( no_sa-- > 0 ) { |
144 | 1.80k | proto_tree_add_item_ret_uint(esis_area_tree, hf_esis_sal, tvb, offset, 1, ENC_NA, &sal); |
145 | 1.80k | offset++; |
146 | 1.80k | proto_tree_add_string(esis_area_tree, hf_esis_sa, tvb, offset, sal, print_nsap_net( pinfo->pool, tvb, offset, sal ) ); |
147 | 1.80k | offset += sal; |
148 | 1.80k | len -= ( sal + 1 ); |
149 | 1.80k | } |
150 | 99 | dissect_osi_options( len, tvb, offset, tree, pinfo ); |
151 | | |
152 | 99 | } /* esis_dissect_esh_pdu */ |
153 | | |
154 | | static void |
155 | 15 | esis_dissect_ish_pdu( uint8_t len, tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo) { |
156 | | |
157 | 15 | int offset = 0; |
158 | 15 | int netl = 0; |
159 | 15 | proto_tree* network_tree; |
160 | | |
161 | 15 | offset += ESIS_HDR_FIXED_LENGTH; |
162 | | |
163 | 15 | netl = (int) tvb_get_uint8(tvb, offset); |
164 | 15 | network_tree = proto_tree_add_subtree( tree, tvb, offset, netl + 1, ett_esis_network, NULL, |
165 | 15 | "### Network Entity Title Section ###"); |
166 | 15 | proto_tree_add_uint(network_tree, hf_esis_netl, tvb, offset++, 1, netl); |
167 | 15 | proto_tree_add_string(network_tree, hf_esis_net, tvb, offset, netl, print_nsap_net( pinfo->pool, tvb, offset, netl ) ); |
168 | 15 | offset += netl; |
169 | 15 | len -= ( netl + 1 ); |
170 | | |
171 | 15 | dissect_osi_options( len, tvb, offset, network_tree, pinfo ); |
172 | 15 | } |
173 | | |
174 | | static void |
175 | 12 | esis_dissect_redirect_pdu( uint8_t len, tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo) { |
176 | | |
177 | 12 | int offset = 0; |
178 | 12 | int tmpl = 0; |
179 | 12 | proto_tree *dest_tree, *subnet_tree, *network_tree; |
180 | | |
181 | 12 | offset += ESIS_HDR_FIXED_LENGTH; |
182 | | |
183 | 12 | tmpl = (int) tvb_get_uint8(tvb, offset); |
184 | 12 | dest_tree = proto_tree_add_subtree( tree, tvb, offset, tmpl + 1, ett_esis_dest_addr, NULL, |
185 | 12 | "### Destination Address Section ###" ); |
186 | 12 | proto_tree_add_uint(dest_tree, hf_esis_dal, tvb, offset++, 1, tmpl); |
187 | 12 | proto_tree_add_string( dest_tree, hf_esis_da, tvb, offset, tmpl, |
188 | 12 | print_nsap_net( pinfo->pool, tvb, offset, tmpl ) ); |
189 | 12 | offset += tmpl; |
190 | 12 | len -= ( tmpl + 1 ); |
191 | 12 | tmpl = (int) tvb_get_uint8(tvb, offset); |
192 | | |
193 | 12 | subnet_tree = proto_tree_add_subtree( tree, tvb, offset, tmpl + 1, ett_esis_subnetwork, NULL, |
194 | 12 | "### Subnetwork Address Section ###"); |
195 | 12 | proto_tree_add_uint(subnet_tree, hf_esis_bsnpal, tvb, offset++, 1, tmpl); |
196 | 12 | proto_tree_add_item(subnet_tree, hf_esis_bsnpa, tvb, offset, tmpl, ENC_NA); |
197 | 12 | offset += tmpl; |
198 | 12 | len -= ( tmpl + 1 ); |
199 | 12 | tmpl = (int) tvb_get_uint8(tvb, offset); |
200 | | |
201 | 12 | if ( 0 == tmpl ) { |
202 | 4 | network_tree = proto_tree_add_subtree( tree, tvb, offset, 1, ett_esis_network, NULL, |
203 | 4 | "### No Network Entity Title Section ###" ); |
204 | 4 | offset++; |
205 | 4 | len--; |
206 | 4 | } |
207 | 8 | else { |
208 | 8 | network_tree = proto_tree_add_subtree( tree, tvb, offset, 1, ett_esis_network, NULL, |
209 | 8 | "### Network Entity Title Section ###" ); |
210 | 8 | proto_tree_add_uint(network_tree, hf_esis_netl, tvb, offset++, 1, tmpl); |
211 | 8 | proto_tree_add_string( network_tree, hf_esis_net, tvb, offset, tmpl, |
212 | 8 | print_nsap_net( pinfo->pool, tvb, offset, tmpl ) ); |
213 | 8 | offset += tmpl; |
214 | 8 | len -= ( tmpl + 1 ); |
215 | 8 | } |
216 | 12 | dissect_osi_options( len, tvb, offset, network_tree, pinfo ); |
217 | 12 | } |
218 | | |
219 | | |
220 | | /* |
221 | | * Name: dissect_esis() |
222 | | * |
223 | | * Description: |
224 | | * Main entry area for esis de-mangling. This will build the |
225 | | * main esis tree data and call the sub-protocols as needed. |
226 | | * |
227 | | * Input: |
228 | | * tvbuff * : tvbuff referring to packet data |
229 | | * packet_info * : info for current packet |
230 | | * proto_tree * : tree of display data. May be NULL. |
231 | | * |
232 | | * Output: |
233 | | * void, but we will add to the proto_tree if it is not NULL. |
234 | | */ |
235 | | static int |
236 | 144 | dissect_esis(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) { |
237 | 144 | uint8_t version, length; |
238 | 144 | proto_item *ti, *type_item; |
239 | 144 | proto_tree *esis_tree = NULL; |
240 | 144 | uint8_t variable_len, type; |
241 | 144 | uint16_t checksum; |
242 | | |
243 | 144 | col_set_str(pinfo->cinfo, COL_PROTOCOL, "ESIS"); |
244 | 144 | col_clear(pinfo->cinfo, COL_INFO); |
245 | | |
246 | 144 | ti = proto_tree_add_item(tree, proto_esis, tvb, 0, -1, ENC_NA); |
247 | 144 | esis_tree = proto_item_add_subtree(ti, ett_esis); |
248 | | |
249 | 144 | proto_tree_add_item( esis_tree, hf_esis_nlpi, tvb, 0, 1, ENC_BIG_ENDIAN); |
250 | 144 | ti = proto_tree_add_item( esis_tree, hf_esis_length, tvb, 1, 1, ENC_BIG_ENDIAN ); |
251 | 144 | length = tvb_get_uint8(tvb, 1); |
252 | 144 | if (length < ESIS_HDR_FIXED_LENGTH) { |
253 | 34 | expert_add_info_format(pinfo, ti, &ei_esis_length, |
254 | 34 | "Bogus ESIS length (%u, must be >= %u)", |
255 | 34 | length, ESIS_HDR_FIXED_LENGTH ); |
256 | 34 | } |
257 | | |
258 | 144 | version = tvb_get_uint8(tvb, 2); |
259 | 144 | ti = proto_tree_add_item( esis_tree, hf_esis_version, tvb, 2, 1, ENC_BIG_ENDIAN); |
260 | 144 | if (version != ESIS_REQUIRED_VERSION){ |
261 | 137 | expert_add_info_format(pinfo, ti, &ei_esis_version, |
262 | 137 | "Unknown ESIS version (%u vs %u)", |
263 | 137 | version, ESIS_REQUIRED_VERSION ); |
264 | 137 | } |
265 | | |
266 | 144 | proto_tree_add_item( esis_tree, hf_esis_reserved, tvb, 3, 1, ENC_BIG_ENDIAN); |
267 | | |
268 | 144 | type_item = proto_tree_add_item( esis_tree, hf_esis_type, tvb, 4, 1, ENC_BIG_ENDIAN); |
269 | 144 | type = tvb_get_uint8(tvb, 4) & OSI_PDU_TYPE_MASK; |
270 | | |
271 | 144 | proto_tree_add_item(esis_tree, hf_esis_holdtime, tvb, 5, 2, ENC_BIG_ENDIAN); |
272 | | |
273 | 144 | checksum = tvb_get_ntohs(tvb, 7); |
274 | 144 | if (checksum == 0) { |
275 | | /* No checksum present */ |
276 | 8 | proto_tree_add_checksum(esis_tree, tvb, 7, hf_esis_checksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NOT_PRESENT); |
277 | 136 | } else { |
278 | 136 | uint32_t c0 = 0, c1 = 0; |
279 | | |
280 | 136 | if (osi_calc_checksum(tvb, 0, length, &c0, &c1)) { |
281 | | /* Successfully processed checksum, verify it */ |
282 | 110 | proto_tree_add_checksum(esis_tree, tvb, 7, hf_esis_checksum, hf_esis_checksum_status, &ei_esis_checksum, pinfo, c0 | c1, ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY|PROTO_CHECKSUM_ZERO); |
283 | 110 | } else { |
284 | 26 | proto_tree_add_checksum(esis_tree, tvb, 7, hf_esis_checksum, hf_esis_checksum_status, &ei_esis_checksum, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS); |
285 | 26 | } |
286 | 136 | } |
287 | | |
288 | | /* |
289 | | * Let us make sure we use the same names for all our decodes |
290 | | * here. First, dump the name into info column, and THEN |
291 | | * dispatch the sub-type. |
292 | | */ |
293 | 144 | col_add_str(pinfo->cinfo, COL_INFO, |
294 | 144 | val_to_str( type, esis_vals, |
295 | 144 | "Unknown (0x%x)" ) ); |
296 | | |
297 | 144 | variable_len = length - ESIS_HDR_FIXED_LENGTH; |
298 | | |
299 | 144 | switch (type) { |
300 | 99 | case ESIS_ESH_PDU: |
301 | 99 | esis_dissect_esh_pdu( variable_len, tvb, esis_tree, pinfo); |
302 | 99 | break; |
303 | 15 | case ESIS_ISH_PDU: |
304 | 15 | esis_dissect_ish_pdu( variable_len, tvb, esis_tree, pinfo); |
305 | 15 | break; |
306 | 12 | case ESIS_RD_PDU: |
307 | 12 | esis_dissect_redirect_pdu( variable_len, tvb, esis_tree, pinfo); |
308 | 12 | break; |
309 | 18 | default: |
310 | 18 | expert_add_info(pinfo, type_item, &ei_esis_type); |
311 | 144 | } |
312 | 19 | return tvb_captured_length(tvb); |
313 | 144 | } /* dissect_esis */ |
314 | | |
315 | | |
316 | | /* |
317 | | * Name: proto_register_esis() |
318 | | * |
319 | | * Description: |
320 | | * main register for esis protocol set. We register some display |
321 | | * formats and the protocol module variables. |
322 | | * |
323 | | * NOTE: this procedure to autolinked by the makefile process that |
324 | | * builds register.c |
325 | | * |
326 | | * Input: |
327 | | * void |
328 | | * |
329 | | * Output: |
330 | | * void |
331 | | */ |
332 | | void |
333 | 14 | proto_register_esis(void) { |
334 | 14 | static hf_register_info hf[] = { |
335 | 14 | { &hf_esis_nlpi, |
336 | 14 | { "Network Layer Protocol Identifier", "esis.nlpi", |
337 | 14 | FT_UINT8, BASE_HEX, VALS(nlpid_vals), 0x0, NULL, HFILL }}, |
338 | | |
339 | 14 | { &hf_esis_length, |
340 | 14 | { "PDU Length", "esis.length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }}, |
341 | | |
342 | 14 | { &hf_esis_version, |
343 | 14 | { "Version", "esis.ver", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }}, |
344 | | |
345 | 14 | { &hf_esis_reserved, |
346 | 14 | { "Reserved(==0)", "esis.res", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }}, |
347 | | |
348 | 14 | { &hf_esis_type, |
349 | 14 | { "PDU Type", "esis.type", FT_UINT8, BASE_DEC, VALS(esis_vals), OSI_PDU_TYPE_MASK, NULL, HFILL }}, |
350 | | |
351 | 14 | { &hf_esis_holdtime, |
352 | 14 | { "Holding Time", "esis.htime", FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_second_seconds), 0x0, NULL, HFILL }}, |
353 | | |
354 | 14 | { &hf_esis_checksum, |
355 | 14 | { "Checksum", "esis.chksum", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }}, |
356 | | |
357 | 14 | { &hf_esis_checksum_status, |
358 | 14 | { "Checksum Status", "esis.chksum.status", FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0x0, NULL, HFILL }}, |
359 | | |
360 | | /* Generated from convert_proto_tree_add_text.pl */ |
361 | 14 | { &hf_esis_number_of_source_addresses, { "Number of Source Addresses (SA, Format: NSAP)", "esis.number_of_source_addresses", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }}, |
362 | 14 | { &hf_esis_sal, { "SAL", "esis.sal", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_octet_octets), 0x0, NULL, HFILL }}, |
363 | 14 | { &hf_esis_sa, { "SA", "esis.sa", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }}, |
364 | 14 | { &hf_esis_netl, { "NETL", "esis.netl", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_octet_octets), 0x0, NULL, HFILL }}, |
365 | 14 | { &hf_esis_dal, { "DAL", "esis.dal", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_octet_octets), 0x0, NULL, HFILL }}, |
366 | 14 | { &hf_esis_bsnpal, { "BSNPAL", "esis.bsnpal", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_octet_octets), 0x0, NULL, HFILL }}, |
367 | 14 | { &hf_esis_net, { "NET", "esis.net", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }}, |
368 | 14 | { &hf_esis_da, { "DA", "esis.da", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }}, |
369 | 14 | { &hf_esis_bsnpa, { "BSNPA", "esis.bsnpa", FT_SYSTEM_ID, BASE_NONE, NULL, 0x0, NULL, HFILL }}, |
370 | 14 | }; |
371 | | |
372 | 14 | static int *ett[] = { |
373 | 14 | &ett_esis, |
374 | 14 | &ett_esis_area_addr, |
375 | 14 | &ett_esis_network, |
376 | 14 | &ett_esis_dest_addr, |
377 | 14 | &ett_esis_subnetwork |
378 | 14 | }; |
379 | | |
380 | 14 | static ei_register_info ei[] = { |
381 | 14 | { &ei_esis_version, { "esis.ver.unknown", PI_PROTOCOL, PI_WARN, "Unknown ESIS version", EXPFILL }}, |
382 | 14 | { &ei_esis_length, { "esis.length.invalid", PI_MALFORMED, PI_ERROR, "Bogus ESIS length", EXPFILL }}, |
383 | 14 | { &ei_esis_type, { "esis.type.unknown", PI_PROTOCOL, PI_WARN, "Unknown ESIS packet type", EXPFILL }}, |
384 | 14 | { &ei_esis_checksum, { "esis.bad_checksum", PI_CHECKSUM, PI_ERROR, "Bad checksum", EXPFILL }}, |
385 | 14 | }; |
386 | | |
387 | 14 | expert_module_t* expert_esis; |
388 | | |
389 | 14 | proto_esis = proto_register_protocol( PROTO_STRING_ESIS, "ESIS", "esis"); |
390 | 14 | proto_register_field_array(proto_esis, hf, array_length(hf)); |
391 | 14 | proto_register_subtree_array(ett, array_length(ett)); |
392 | 14 | expert_esis = expert_register_protocol(proto_esis); |
393 | 14 | expert_register_field_array(expert_esis, ei, array_length(ei)); |
394 | 14 | esis_handle = register_dissector("esis", dissect_esis, proto_esis); |
395 | 14 | } |
396 | | |
397 | | void |
398 | | proto_reg_handoff_esis(void) |
399 | 14 | { |
400 | 14 | dissector_add_uint("osinl.incl", NLPID_ISO9542_ESIS, esis_handle); |
401 | 14 | } |
402 | | |
403 | | /* |
404 | | * Editor modelines - https://www.wireshark.org/tools/modelines.html |
405 | | * |
406 | | * Local Variables: |
407 | | * c-basic-offset: 2 |
408 | | * tab-width: 8 |
409 | | * indent-tabs-mode: nil |
410 | | * End: |
411 | | * |
412 | | * ex: set shiftwidth=2 tabstop=8 expandtab: |
413 | | * :indentSize=2:tabSize=8:noTabs=true: |
414 | | */ |