epan/dissectors/pidl/samr/samr.cnf cnf_dissect_lsa_BinaryString => lsarpc_dissect_str...
[wireshark-sm.git] / epan / dissectors / packet-nsrp.c
bloba9819f0583e86102af3e2cf822d201cbefefac6a
1 /* packet-nsrp.c
2 * Routines for the Juniper Netscreen Redundant Protocol (NSRP)
4 * Secfire <secfire@gmail.com>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
11 * SPDX-License-Identifier: GPL-2.0-or-later
16 * NSRP update information can be found at www.juniper.net
20 * NSRP Packet Header is defined as follow:
22 * 1 2 3 4 5 6 7 8
23 * +--------+--------+--------+--------+--------+--------+--------+--------+
24 * |Version | Type |Clust ID|MSG Flag| Length |HA Port |Not Used|
25 * +--------+--------+--------+--------+--------+--------+--------+--------+
26 * | Destination Unit | Source Unit |
27 * +--------+--------+--------+--------+--------+--------+--------+--------+
33 #include "config.h"
35 #include <epan/packet.h>
36 #include <epan/etypes.h>
38 void proto_register_nsrp(void);
39 void proto_reg_handoff_nsrp(void);
41 static dissector_handle_t nsrp_handle;
43 #define NSRP_MIN_LEN 32
45 /* Initialize the protocol and registered fields */
46 static int proto_nsrp;
48 static int hf_nsrp_version;
49 static int hf_nsrp_msg_type;
50 static int hf_nsrp_clust_id;
51 static int hf_nsrp_msg_flag;
52 static int hf_nsrp_len;
53 static int hf_nsrp_ha_port;
54 static int hf_nsrp_not_used;
55 static int hf_nsrp_dst_unit;
56 static int hf_nsrp_src_unit;
57 static int hf_nsrp_msgtype;
58 static int hf_nsrp_wst_group;
59 static int hf_nsrp_hst_group;
60 static int hf_nsrp_msgflag;
61 static int hf_nsrp_authflag;
62 static int hf_nsrp_priority;
63 static int hf_nsrp_dummy;
64 static int hf_nsrp_authchecksum;
65 static int hf_nsrp_ifnum;
68 /* Dada defined for HA Message */
69 static int hf_nsrp_msglen;
70 static int hf_nsrp_encflag;
71 /* static int hf_nsrp_notused; */
73 static int hf_nsrp_total_size;
75 static int hf_nsrp_ns;
76 static int hf_nsrp_nr;
78 static int hf_nsrp_no_used;
79 static int hf_nsrp_checksum;
81 static int hf_nsrp_data;
84 static const value_string nsrp_msg_type_vals[] = {
85 { 0x01, "HA MESSAGE" },
86 { 0x02, "MNG MESSAGE" },
87 { 0x03, "DADA MESSAGE" },
88 { 0, NULL }
91 static const value_string nsrp_msgtype_vals[] = {
92 { 0x01, "CREATE SESSION" },
93 { 0x02, "CLOSE SESSION" },
94 { 0x03, "CHANG SESSION" },
95 { 0x04, "CREATE SP SESSION" },
96 { 0x05, "SYS CONFIG" },
97 { 0x06, "FILE SYS" },
98 { 0x07, "CMD WEB" },
99 { 0x08, "SAVE SLAVE" },
100 { 0x09, "VPN SPI" },
101 { 0x0a, "ARP" },
102 { 0x0b, "HEALTH CHECK" },
103 { 0x0c, "EMW DATA" },
104 { 0x0d, "INVITE SYNC" },
105 { 0x0e, "DOWNLOAD CONFIG" },
106 { 0x0f, "L2TP TUNL CREATE" },
107 { 0x10, "L2TP TUNL DELETE" },
108 { 0x11, "L2TP CALL CREATE" },
109 { 0x12, "L2TP CALL DELETE" },
110 { 0x13, "PKI SYNC" },
111 { 0x14, "VPN SEQ" },
112 { 0x15, "MAX" },
113 { 0, NULL }
116 static const value_string nsrp_flag_vals[] = {
117 { 0x80, "ENCRYPT MESSAGE" },
118 { 0x40, "CLOSE SESSION" },
119 { 0x20, "CHANG SESSION" },
120 { 0x10, "CREATE SP SESSION" },
121 { 0x08, "SYS CONFIG" },
122 { 0x04, "FILE SYS" },
123 { 0x02, "CMD WEB" },
124 { 0, NULL }
127 static const value_string nsrp_encflag_vals[] = {
128 { 0xf0, "ENCRYPT METHOD MASK" },
129 { 0x0f, "ENCRYPT PAD BIT MASK" },
130 { 0, NULL }
134 /* Initialize the subtree pointers */
135 static int ett_nsrp;
137 /* Code to actually dissect the packets */
138 static int
139 dissect_nsrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
141 proto_item *ti;
142 proto_tree *nsrp_tree = NULL;
143 int offset = 0;
144 uint8_t msgtype = 0;
146 col_set_str(pinfo->cinfo, COL_PROTOCOL, "NSRP");
148 col_set_str(pinfo->cinfo, COL_INFO, "NSRP Protocol");
150 if (tree) {
151 ti = proto_tree_add_item(tree, proto_nsrp, tvb, 0, -1, ENC_NA);
152 nsrp_tree = proto_item_add_subtree(ti, ett_nsrp);
155 proto_tree_add_item(nsrp_tree, hf_nsrp_version, tvb, offset, 1, ENC_BIG_ENDIAN);
156 offset += 1;
158 msgtype = tvb_get_uint8(tvb, offset);
159 proto_tree_add_item(nsrp_tree, hf_nsrp_msg_type, tvb, offset, 1, ENC_BIG_ENDIAN);
160 offset += 1;
162 proto_tree_add_item(nsrp_tree, hf_nsrp_clust_id, tvb, offset, 1, ENC_BIG_ENDIAN);
163 offset += 1;
165 proto_tree_add_item(nsrp_tree, hf_nsrp_msg_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
166 offset += 1;
168 proto_tree_add_item(nsrp_tree, hf_nsrp_len, tvb, offset, 2, ENC_BIG_ENDIAN);
169 offset += 2;
171 proto_tree_add_item(nsrp_tree, hf_nsrp_ha_port, tvb, offset, 1, ENC_BIG_ENDIAN);
172 offset += 1;
174 proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, ENC_BIG_ENDIAN);
175 offset += 1;
177 proto_tree_add_item(nsrp_tree, hf_nsrp_dst_unit, tvb, offset, 4, ENC_BIG_ENDIAN);
178 offset += 4;
180 proto_tree_add_item(nsrp_tree, hf_nsrp_src_unit, tvb, offset, 4, ENC_BIG_ENDIAN);
181 offset += 4;
187 * NSRP HA Packet is defined as follow:
189 * 1 2 3 4 5 6 7 8
190 * +--------+--------+--------+--------+--------+--------+--------+--------+
191 * | Type |WstGroup|HstGroup|MSG Flag| Length |Enc Flag|Not Used|
192 * +--------+--------+--------+--------+--------+--------+--------+--------+
193 * | Total Size | NS | NR |
194 * +--------+--------+--------+--------+--------+--------+--------+--------+
195 * | No Used | Checksum | Data |
196 * +--------+--------+--------+--------+-----------------------------------+
201 if ( msgtype == 0x00 ) {
203 proto_tree_add_item(nsrp_tree, hf_nsrp_msgtype, tvb, offset, 1, ENC_BIG_ENDIAN);
204 offset += 1;
206 proto_tree_add_item(nsrp_tree, hf_nsrp_wst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
207 offset += 1;
209 proto_tree_add_item(nsrp_tree, hf_nsrp_hst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
210 offset += 1;
212 proto_tree_add_item(nsrp_tree, hf_nsrp_msgflag, tvb, offset, 1, ENC_BIG_ENDIAN);
213 offset += 1;
215 proto_tree_add_item(nsrp_tree, hf_nsrp_msglen, tvb, offset, 2, ENC_BIG_ENDIAN);
216 offset += 2;
218 proto_tree_add_item(nsrp_tree, hf_nsrp_encflag, tvb, offset, 1, ENC_BIG_ENDIAN);
219 offset += 1;
221 proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, ENC_BIG_ENDIAN);
222 offset += 1;
224 proto_tree_add_item(nsrp_tree, hf_nsrp_total_size, tvb, offset, 4, ENC_BIG_ENDIAN);
225 offset += 4;
227 proto_tree_add_item(nsrp_tree, hf_nsrp_ns, tvb, offset, 2, ENC_BIG_ENDIAN);
228 offset += 2;
230 proto_tree_add_item(nsrp_tree, hf_nsrp_nr, tvb, offset, 2, ENC_BIG_ENDIAN);
231 offset += 2;
233 proto_tree_add_item(nsrp_tree, hf_nsrp_no_used, tvb, offset, 2, ENC_BIG_ENDIAN);
234 offset += 2;
236 proto_tree_add_checksum(nsrp_tree, tvb, offset, hf_nsrp_checksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
237 offset += 2;
239 proto_tree_add_item(nsrp_tree, hf_nsrp_data, tvb, offset, -1, ENC_ASCII);
245 * NSRP MNG Packet is defined as follow:
247 * 1 2 3 4 5 6 7 8
248 * +--------+--------+--------+--------+--------+--------+--------+--------+
249 * | Type |WstGroup|HstGroup|MSG Flag| Length |AuthFlag|Not Used|
250 * +--------+--------+--------+--------+--------+--------+--------+--------+
251 * |Priority+ Dummy + Auth CheckSum + Data |
252 * +--------+--------+--------+--------+-----------------------------------+
257 if ( msgtype == 0x02 ) {
259 proto_tree_add_item(nsrp_tree, hf_nsrp_msgtype, tvb, offset, 1, ENC_BIG_ENDIAN);
260 offset += 1;
262 proto_tree_add_item(nsrp_tree, hf_nsrp_wst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
263 offset += 1;
265 proto_tree_add_item(nsrp_tree, hf_nsrp_hst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
266 offset += 1;
268 proto_tree_add_item(nsrp_tree, hf_nsrp_msgflag, tvb, offset, 1, ENC_BIG_ENDIAN);
269 offset += 1;
271 proto_tree_add_item(nsrp_tree, hf_nsrp_msglen, tvb, offset, 2, ENC_BIG_ENDIAN);
272 offset += 2;
274 proto_tree_add_item(nsrp_tree, hf_nsrp_authflag, tvb, offset, 1, ENC_BIG_ENDIAN);
275 offset += 1;
277 proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, ENC_BIG_ENDIAN);
278 offset += 1;
280 proto_tree_add_item(nsrp_tree, hf_nsrp_priority, tvb, offset, 1, ENC_BIG_ENDIAN);
281 offset += 1;
283 proto_tree_add_item(nsrp_tree, hf_nsrp_dummy, tvb, offset, 1, ENC_BIG_ENDIAN);
284 offset += 1;
286 proto_tree_add_checksum(nsrp_tree, tvb, offset, hf_nsrp_authchecksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
287 offset += 2;
289 proto_tree_add_item(nsrp_tree, hf_nsrp_data, tvb, offset, -1, ENC_ASCII);
297 * NSRP DATA Packet is defined as follow:
299 * 1 2 3 4 5 6 7 8
300 * +--------+--------+--------+--------+--------+--------+--------+--------+
301 * | Type |WstGroup|HstGroup|MSG Flag| Length | Ifnum |Not Used|
302 * +--------+--------+--------+--------+--------+--------+--------+--------+
303 * | Total Size | Data |
304 * +--------+--------+--------+--------+-----------------------------------+
308 if ( msgtype == 0x03 ) {
310 proto_tree_add_item(nsrp_tree, hf_nsrp_msgtype, tvb, offset, 1, ENC_BIG_ENDIAN);
311 offset += 1;
313 proto_tree_add_item(nsrp_tree, hf_nsrp_wst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
314 offset += 1;
316 proto_tree_add_item(nsrp_tree, hf_nsrp_hst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
317 offset += 1;
319 proto_tree_add_item(nsrp_tree, hf_nsrp_msgflag, tvb, offset, 1, ENC_BIG_ENDIAN);
320 offset += 1;
322 proto_tree_add_item(nsrp_tree, hf_nsrp_msglen, tvb, offset, 2, ENC_BIG_ENDIAN);
323 offset += 2;
325 proto_tree_add_item(nsrp_tree, hf_nsrp_ifnum, tvb, offset, 1, ENC_BIG_ENDIAN);
326 offset += 1;
328 proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, ENC_BIG_ENDIAN);
329 offset += 1;
331 proto_tree_add_item(nsrp_tree, hf_nsrp_total_size, tvb, offset, 4, ENC_BIG_ENDIAN);
332 offset += 4;
334 proto_tree_add_item(nsrp_tree, hf_nsrp_data, tvb, offset, -1, ENC_ASCII);
338 return tvb_captured_length(tvb);
342 void
343 proto_register_nsrp(void)
346 static hf_register_info hf[] = {
347 { &hf_nsrp_version,
348 { "Version", "nsrp.version",
349 FT_UINT8, BASE_DEC, NULL, 0,
350 "NSRP Version", HFILL }
352 { &hf_nsrp_msg_type,
353 { "Type", "nsrp.type",
354 FT_UINT8, BASE_DEC, VALS(nsrp_msg_type_vals), 0,
355 "NSRP Message Type", HFILL }
357 { &hf_nsrp_clust_id,
358 { "Clust ID", "nsrp.clustid",
359 FT_UINT8, BASE_DEC, NULL, 0,
360 "NSRP CLUST ID", HFILL }
362 { &hf_nsrp_msg_flag,
363 { "Flag", "nsrp.flag",
364 FT_UINT8, BASE_DEC, NULL, 0,
365 "NSRP FLAG", HFILL }
367 { &hf_nsrp_len,
368 { "Length", "nsrp.length",
369 FT_UINT16, BASE_DEC, NULL, 0,
370 "NSRP Length", HFILL }
372 { &hf_nsrp_ha_port,
373 { "Port", "nsrp.haport",
374 FT_UINT8, BASE_DEC, NULL, 0,
375 "NSRP HA Port", HFILL }
377 { &hf_nsrp_not_used,
378 { "Not used", "nsrp.notused",
379 FT_UINT8, BASE_DEC, NULL, 0,
380 NULL, HFILL }
382 { &hf_nsrp_dst_unit,
383 { "Destination", "nsrp.dst",
384 FT_UINT32, BASE_DEC, NULL, 0,
385 "DESTINATION UNIT INFORMATION", HFILL }
387 { &hf_nsrp_src_unit,
388 { "Source", "nsrp.src",
389 FT_UINT32, BASE_DEC, NULL, 0,
390 "SOURCE UNIT INFORMATION", HFILL }
392 { &hf_nsrp_msgtype,
393 { "MsgType", "nsrp.msgtype",
394 FT_UINT8, BASE_DEC, VALS(nsrp_msgtype_vals), 0,
395 "Message Type", HFILL }
397 { &hf_nsrp_wst_group,
398 { "Wst group", "nsrp.wst",
399 FT_UINT8, BASE_DEC, NULL, 0,
400 "NSRP WST GROUP", HFILL }
402 { &hf_nsrp_hst_group,
403 { "Hst group", "nsrp.hst",
404 FT_UINT8, BASE_DEC, NULL, 0,
405 "NSRP HST GROUP", HFILL }
407 { &hf_nsrp_msgflag,
408 { "Msgflag", "nsrp.msgflag",
409 FT_UINT8, BASE_DEC, VALS(nsrp_flag_vals), 0,
410 "NSRP MSG FLAG", HFILL }
412 { &hf_nsrp_msglen,
413 { "Msg Length", "nsrp.msglen",
414 FT_UINT16, BASE_DEC, NULL, 0,
415 "NSRP MESSAGE LENGTH", HFILL }
418 { &hf_nsrp_encflag,
419 { "Enc Flag", "nsrp.encflag",
420 FT_UINT8, BASE_DEC, VALS(nsrp_encflag_vals), 0,
421 "NSRP ENCRYPT FLAG", HFILL }
423 #if 0
424 { &hf_nsrp_notused,
425 { "Not Used", "nsrp.notused",
426 FT_UINT8, BASE_DEC, NULL, 0,
427 NULL, HFILL }
429 #endif
430 { &hf_nsrp_total_size,
431 { "Total Size", "nsrp.totalsize",
432 FT_UINT32, BASE_DEC, NULL, 0,
433 "NSRP MSG TOTAL MESSAGE", HFILL }
435 { &hf_nsrp_ns,
436 { "Ns", "nsrp.ns",
437 FT_UINT16, BASE_DEC, NULL, 0,
438 NULL, HFILL }
440 { &hf_nsrp_nr,
441 { "Nr", "nsrp.nr",
442 FT_UINT16, BASE_DEC, NULL, 0,
443 NULL, HFILL }
445 { &hf_nsrp_no_used,
446 { "Reserved", "nsrp.reserved",
447 FT_UINT16, BASE_DEC, NULL, 0,
448 NULL, HFILL }
450 { &hf_nsrp_checksum,
451 { "Checksum", "nsrp.checksum",
452 FT_UINT16, BASE_HEX, NULL, 0,
453 "NSRP PACKET CHECKSUM", HFILL }
455 { &hf_nsrp_authflag,
456 { "AuthFlag", "nsrp.authflag",
457 FT_UINT8, BASE_HEX, NULL, 0,
458 "NSRP Auth Flag", HFILL }
460 { &hf_nsrp_priority,
461 { "Priority", "nsrp.priority",
462 FT_UINT8, BASE_HEX, NULL, 0,
463 "NSRP Priority", HFILL }
465 { &hf_nsrp_dummy,
466 { "Dummy", "nsrp.dummy",
467 FT_UINT8, BASE_HEX, NULL, 0,
468 "NSRP Dummy", HFILL }
470 { &hf_nsrp_authchecksum,
471 { "Checksum", "nsrp.authchecksum",
472 FT_UINT16, BASE_HEX, NULL, 0,
473 "NSRP AUTH CHECKSUM", HFILL }
475 { &hf_nsrp_ifnum,
476 { "Ifnum", "nsrp.ifnum",
477 FT_UINT16, BASE_HEX, NULL, 0,
478 "NSRP IfNum", HFILL }
480 { &hf_nsrp_data,
481 { "Data", "nsrp.data",
482 FT_STRING, BASE_NONE, NULL, 0,
483 "PADDING", HFILL }
487 static int *ett[] = {
488 &ett_nsrp
491 proto_nsrp = proto_register_protocol("Juniper Netscreen Redundant Protocol",
492 "NSRP", "nsrp");
493 proto_register_field_array(proto_nsrp, hf, array_length(hf));
494 proto_register_subtree_array(ett, array_length(ett));
496 nsrp_handle = register_dissector("nsrp", dissect_nsrp, proto_nsrp);
500 void
501 proto_reg_handoff_nsrp(void)
503 dissector_add_uint("ethertype", ETHERTYPE_NSRP, nsrp_handle);
508 * Editor modelines - https://www.wireshark.org/tools/modelines.html
510 * Local variables:
511 * c-basic-offset: 4
512 * tab-width: 8
513 * indent-tabs-mode: nil
514 * End:
516 * vi: set shiftwidth=4 tabstop=8 expandtab:
517 * :indentSize=4:tabSize=8:noTabs=true: