Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-esis.c
blobb6bc3b3f0541cba0ed8902274f921321b9e06eb0
1 /* packet-esis.c
2 * Routines for ISO/OSI End System to Intermediate System
3 * Routing Exchange Protocol ISO 9542.
5 * Ralf Schneider <Ralf.Schneider@t-online.de>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include "config.h"
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"
23 /* The version we support is 1 */
24 #define ESIS_REQUIRED_VERSION 1
26 /* ESIS PDU types */
27 #define ESIS_ESH_PDU 02
28 #define ESIS_ISH_PDU 04
29 #define ESIS_RD_PDU 06
31 /* The length of the fixed part */
32 #define ESIS_HDR_FIXED_LENGTH 9
34 void proto_register_esis(void);
35 void proto_reg_handoff_esis(void);
37 /* esis base header */
38 static int proto_esis;
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;
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;
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;
71 static dissector_handle_t esis_handle;
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} };
79 /* ################## Descriptions ###########################################*/
80 /* Parameters for the ESH PDU
81 * Source Address Parameter:
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
90 * Parameter for the ISH PDU:
91 * Network Entity Title Parameter:
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
99 * Parameter for the RD PDU:
100 * When re-directed to an IS:
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
112 * Parameter for the RD PDU:
113 * When re-directed to an ES:
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
125 /* ############################ Tool Functions ############################## */
128 static void
129 esis_dissect_esh_pdu( uint8_t len, tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo) {
130 proto_tree *esis_area_tree;
131 int offset = 0;
132 unsigned no_sa, sal;
134 proto_item *ti;
136 offset += ESIS_HDR_FIXED_LENGTH;
138 ti = proto_tree_add_item_ret_uint( tree, hf_esis_number_of_source_addresses, tvb, offset, 1, ENC_NA, &no_sa);
139 len--;
140 offset++;
142 esis_area_tree = proto_item_add_subtree( ti, ett_esis_area_addr );
143 while ( no_sa-- > 0 ) {
144 proto_tree_add_item_ret_uint(esis_area_tree, hf_esis_sal, tvb, offset, 1, ENC_NA, &sal);
145 offset++;
146 proto_tree_add_string(esis_area_tree, hf_esis_sa, tvb, offset, sal, print_nsap_net( pinfo->pool, tvb, offset, sal ) );
147 offset += sal;
148 len -= ( sal + 1 );
150 dissect_osi_options( len, tvb, offset, tree, pinfo );
152 } /* esis_dissect_esh_pdu */
154 static void
155 esis_dissect_ish_pdu( uint8_t len, tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo) {
157 int offset = 0;
158 int netl = 0;
159 proto_tree* network_tree;
161 offset += ESIS_HDR_FIXED_LENGTH;
163 netl = (int) tvb_get_uint8(tvb, offset);
164 network_tree = proto_tree_add_subtree( tree, tvb, offset, netl + 1, ett_esis_network, NULL,
165 "### Network Entity Title Section ###");
166 proto_tree_add_uint(network_tree, hf_esis_netl, tvb, offset++, 1, netl);
167 proto_tree_add_string(network_tree, hf_esis_net, tvb, offset, netl, print_nsap_net( pinfo->pool, tvb, offset, netl ) );
168 offset += netl;
169 len -= ( netl + 1 );
171 dissect_osi_options( len, tvb, offset, network_tree, pinfo );
174 static void
175 esis_dissect_redirect_pdu( uint8_t len, tvbuff_t *tvb, proto_tree *tree, packet_info *pinfo) {
177 int offset = 0;
178 int tmpl = 0;
179 proto_tree *dest_tree, *subnet_tree, *network_tree;
181 offset += ESIS_HDR_FIXED_LENGTH;
183 tmpl = (int) tvb_get_uint8(tvb, offset);
184 dest_tree = proto_tree_add_subtree( tree, tvb, offset, tmpl + 1, ett_esis_dest_addr, NULL,
185 "### Destination Address Section ###" );
186 proto_tree_add_uint(dest_tree, hf_esis_dal, tvb, offset++, 1, tmpl);
187 proto_tree_add_string( dest_tree, hf_esis_da, tvb, offset, tmpl,
188 print_nsap_net( pinfo->pool, tvb, offset, tmpl ) );
189 offset += tmpl;
190 len -= ( tmpl + 1 );
191 tmpl = (int) tvb_get_uint8(tvb, offset);
193 subnet_tree = proto_tree_add_subtree( tree, tvb, offset, tmpl + 1, ett_esis_subnetwork, NULL,
194 "### Subnetwork Address Section ###");
195 proto_tree_add_uint(subnet_tree, hf_esis_bsnpal, tvb, offset++, 1, tmpl);
196 proto_tree_add_item(subnet_tree, hf_esis_bsnpa, tvb, offset, tmpl, ENC_NA);
197 offset += tmpl;
198 len -= ( tmpl + 1 );
199 tmpl = (int) tvb_get_uint8(tvb, offset);
201 if ( 0 == tmpl ) {
202 network_tree = proto_tree_add_subtree( tree, tvb, offset, 1, ett_esis_network, NULL,
203 "### No Network Entity Title Section ###" );
204 offset++;
205 len--;
207 else {
208 network_tree = proto_tree_add_subtree( tree, tvb, offset, 1, ett_esis_network, NULL,
209 "### Network Entity Title Section ###" );
210 proto_tree_add_uint(network_tree, hf_esis_netl, tvb, offset++, 1, tmpl);
211 proto_tree_add_string( network_tree, hf_esis_net, tvb, offset, tmpl,
212 print_nsap_net( pinfo->pool, tvb, offset, tmpl ) );
213 offset += tmpl;
214 len -= ( tmpl + 1 );
216 dissect_osi_options( len, tvb, offset, network_tree, pinfo );
221 * Name: dissect_esis()
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.
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.
232 * Output:
233 * void, but we will add to the proto_tree if it is not NULL.
235 static int
236 dissect_esis(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) {
237 uint8_t version, length;
238 proto_item *ti, *type_item;
239 proto_tree *esis_tree = NULL;
240 uint8_t variable_len, type;
241 uint16_t checksum;
243 col_set_str(pinfo->cinfo, COL_PROTOCOL, "ESIS");
244 col_clear(pinfo->cinfo, COL_INFO);
246 ti = proto_tree_add_item(tree, proto_esis, tvb, 0, -1, ENC_NA);
247 esis_tree = proto_item_add_subtree(ti, ett_esis);
249 proto_tree_add_item( esis_tree, hf_esis_nlpi, tvb, 0, 1, ENC_BIG_ENDIAN);
250 ti = proto_tree_add_item( esis_tree, hf_esis_length, tvb, 1, 1, ENC_BIG_ENDIAN );
251 length = tvb_get_uint8(tvb, 1);
252 if (length < ESIS_HDR_FIXED_LENGTH) {
253 expert_add_info_format(pinfo, ti, &ei_esis_length,
254 "Bogus ESIS length (%u, must be >= %u)",
255 length, ESIS_HDR_FIXED_LENGTH );
258 version = tvb_get_uint8(tvb, 2);
259 ti = proto_tree_add_item( esis_tree, hf_esis_version, tvb, 2, 1, ENC_BIG_ENDIAN);
260 if (version != ESIS_REQUIRED_VERSION){
261 expert_add_info_format(pinfo, ti, &ei_esis_version,
262 "Unknown ESIS version (%u vs %u)",
263 version, ESIS_REQUIRED_VERSION );
266 proto_tree_add_item( esis_tree, hf_esis_reserved, tvb, 3, 1, ENC_BIG_ENDIAN);
268 type_item = proto_tree_add_item( esis_tree, hf_esis_type, tvb, 4, 1, ENC_BIG_ENDIAN);
269 type = tvb_get_uint8(tvb, 4) & OSI_PDU_TYPE_MASK;
271 proto_tree_add_item(esis_tree, hf_esis_holdtime, tvb, 5, 2, ENC_BIG_ENDIAN);
273 checksum = tvb_get_ntohs(tvb, 7);
274 if (checksum == 0) {
275 /* No checksum present */
276 proto_tree_add_checksum(esis_tree, tvb, 7, hf_esis_checksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NOT_PRESENT);
277 } else {
278 uint32_t c0 = 0, c1 = 0;
280 if (osi_calc_checksum(tvb, 0, length, &c0, &c1)) {
281 /* Successfully processed checksum, verify it */
282 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 } else {
284 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);
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.
293 col_add_str(pinfo->cinfo, COL_INFO,
294 val_to_str( type, esis_vals,
295 "Unknown (0x%x)" ) );
297 variable_len = length - ESIS_HDR_FIXED_LENGTH;
299 switch (type) {
300 case ESIS_ESH_PDU:
301 esis_dissect_esh_pdu( variable_len, tvb, esis_tree, pinfo);
302 break;
303 case ESIS_ISH_PDU:
304 esis_dissect_ish_pdu( variable_len, tvb, esis_tree, pinfo);
305 break;
306 case ESIS_RD_PDU:
307 esis_dissect_redirect_pdu( variable_len, tvb, esis_tree, pinfo);
308 break;
309 default:
310 expert_add_info(pinfo, type_item, &ei_esis_type);
312 return tvb_captured_length(tvb);
313 } /* dissect_esis */
317 * Name: proto_register_esis()
319 * Description:
320 * main register for esis protocol set. We register some display
321 * formats and the protocol module variables.
323 * NOTE: this procedure to autolinked by the makefile process that
324 * builds register.c
326 * Input:
327 * void
329 * Output:
330 * void
332 void
333 proto_register_esis(void) {
334 static hf_register_info hf[] = {
335 { &hf_esis_nlpi,
336 { "Network Layer Protocol Identifier", "esis.nlpi",
337 FT_UINT8, BASE_HEX, VALS(nlpid_vals), 0x0, NULL, HFILL }},
339 { &hf_esis_length,
340 { "PDU Length", "esis.length", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
342 { &hf_esis_version,
343 { "Version", "esis.ver", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
345 { &hf_esis_reserved,
346 { "Reserved(==0)", "esis.res", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
348 { &hf_esis_type,
349 { "PDU Type", "esis.type", FT_UINT8, BASE_DEC, VALS(esis_vals), OSI_PDU_TYPE_MASK, NULL, HFILL }},
351 { &hf_esis_holdtime,
352 { "Holding Time", "esis.htime", FT_UINT16, BASE_DEC|BASE_UNIT_STRING, UNS(&units_second_seconds), 0x0, NULL, HFILL }},
354 { &hf_esis_checksum,
355 { "Checksum", "esis.chksum", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
357 { &hf_esis_checksum_status,
358 { "Checksum Status", "esis.chksum.status", FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0x0, NULL, HFILL }},
360 /* Generated from convert_proto_tree_add_text.pl */
361 { &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 { &hf_esis_sal, { "SAL", "esis.sal", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_octet_octets), 0x0, NULL, HFILL }},
363 { &hf_esis_sa, { "SA", "esis.sa", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
364 { &hf_esis_netl, { "NETL", "esis.netl", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_octet_octets), 0x0, NULL, HFILL }},
365 { &hf_esis_dal, { "DAL", "esis.dal", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_octet_octets), 0x0, NULL, HFILL }},
366 { &hf_esis_bsnpal, { "BSNPAL", "esis.bsnpal", FT_UINT8, BASE_DEC|BASE_UNIT_STRING, UNS(&units_octet_octets), 0x0, NULL, HFILL }},
367 { &hf_esis_net, { "NET", "esis.net", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
368 { &hf_esis_da, { "DA", "esis.da", FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
369 { &hf_esis_bsnpa, { "BSNPA", "esis.bsnpa", FT_SYSTEM_ID, BASE_NONE, NULL, 0x0, NULL, HFILL }},
372 static int *ett[] = {
373 &ett_esis,
374 &ett_esis_area_addr,
375 &ett_esis_network,
376 &ett_esis_dest_addr,
377 &ett_esis_subnetwork
380 static ei_register_info ei[] = {
381 { &ei_esis_version, { "esis.ver.unknown", PI_PROTOCOL, PI_WARN, "Unknown ESIS version", EXPFILL }},
382 { &ei_esis_length, { "esis.length.invalid", PI_MALFORMED, PI_ERROR, "Bogus ESIS length", EXPFILL }},
383 { &ei_esis_type, { "esis.type.unknown", PI_PROTOCOL, PI_WARN, "Unknown ESIS packet type", EXPFILL }},
384 { &ei_esis_checksum, { "esis.bad_checksum", PI_CHECKSUM, PI_ERROR, "Bad checksum", EXPFILL }},
387 expert_module_t* expert_esis;
389 proto_esis = proto_register_protocol( PROTO_STRING_ESIS, "ESIS", "esis");
390 proto_register_field_array(proto_esis, hf, array_length(hf));
391 proto_register_subtree_array(ett, array_length(ett));
392 expert_esis = expert_register_protocol(proto_esis);
393 expert_register_field_array(expert_esis, ei, array_length(ei));
394 esis_handle = register_dissector("esis", dissect_esis, proto_esis);
397 void
398 proto_reg_handoff_esis(void)
400 dissector_add_uint("osinl.incl", NLPID_ISO9542_ESIS, esis_handle);
404 * Editor modelines - https://www.wireshark.org/tools/modelines.html
406 * Local Variables:
407 * c-basic-offset: 2
408 * tab-width: 8
409 * indent-tabs-mode: nil
410 * End:
412 * ex: set shiftwidth=2 tabstop=8 expandtab:
413 * :indentSize=2:tabSize=8:noTabs=true: