dissectors: use SPDX identifiers.
[metze/wireshark/wip.git] / epan / dissectors / packet-nsrp.c
1 /* packet-nsrp.c
2  * Routines for the Juniper Netscreen Redundant Protocol (NSRP)
3  *
4  * Secfire <secfire@gmail.com>
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  *
11  * SPDX-License-Identifier: GPL-2.0-or-later
12  */
13
14 /*
15  *
16  * NSRP update information can be found at www.juniper.net
17  *
18  *
19  *
20  *    NSRP Packet Header is defined as follow:
21  *
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  *   +--------+--------+--------+--------+--------+--------+--------+--------+
28  *
29  *
30  *
31  */
32
33 #include "config.h"
34
35 #include <epan/packet.h>
36 #include <epan/etypes.h>
37
38 void proto_register_nsrp(void);
39 void proto_reg_handoff_nsrp(void);
40
41 #define NSRP_MIN_LEN    32
42
43 /* Initialize the protocol and registered fields */
44 static int proto_nsrp       = -1;
45
46 static int hf_nsrp_version       = -1;
47 static int hf_nsrp_msg_type      = -1;
48 static int hf_nsrp_clust_id      = -1;
49 static int hf_nsrp_msg_flag      = -1;
50 static int hf_nsrp_len           = -1;
51 static int hf_nsrp_ha_port       = -1;
52 static int hf_nsrp_not_used      = -1;
53 static int hf_nsrp_dst_unit      = -1;
54 static int hf_nsrp_src_unit      = -1;
55 static int hf_nsrp_msgtype       = -1;
56 static int hf_nsrp_wst_group     = -1;
57 static int hf_nsrp_hst_group     = -1;
58 static int hf_nsrp_msgflag     = -1;
59 static int hf_nsrp_authflag      = -1;
60 static int hf_nsrp_priority      = -1;
61 static int hf_nsrp_dummy         = -1;
62 static int hf_nsrp_authchecksum  = -1;
63 static int hf_nsrp_ifnum         = -1;
64
65
66 /* Dada defined for HA Message */
67 static int hf_nsrp_msglen      = -1;
68 static int hf_nsrp_encflag      = -1;
69 /* static int hf_nsrp_notused = -1; */
70
71 static int hf_nsrp_total_size = -1;
72
73 static int hf_nsrp_ns = -1;
74 static int hf_nsrp_nr = -1;
75
76 static int hf_nsrp_no_used = -1;
77 static int hf_nsrp_checksum = -1;
78
79 static int hf_nsrp_data = -1;
80
81
82 static const value_string nsrp_msg_type_vals[] = {
83     { 0x01,     "HA MESSAGE" },
84     { 0x02,     "MNG MESSAGE" },
85     { 0x03,     "DADA MESSAGE" },
86     { 0,                        NULL }
87 };
88
89 static const value_string nsrp_msgtype_vals[] = {
90     { 0x01,     "CREATE SESSION" },
91     { 0x02,     "CLOSE SESSION" },
92     { 0x03,     "CHANG SESSION" },
93     { 0x04,     "CREATE SP SESSION" },
94     { 0x05,     "SYS CONFIG" },
95     { 0x06,     "FILE SYS" },
96     { 0x07,     "CMD WEB" },
97     { 0x08,     "SAVE SLAVE" },
98     { 0x09,     "VPN SPI" },
99     { 0x0a,     "ARP" },
100     { 0x0b,     "HEALTH CHECK" },
101     { 0x0c,     "EMW DATA" },
102     { 0x0d,     "INVITE SYNC" },
103     { 0x0e,     "DOWNLOAD CONFIG" },
104     { 0x0f,     "L2TP TUNL CREATE" },
105     { 0x10,     "L2TP TUNL DELETE" },
106     { 0x11,     "L2TP CALL CREATE" },
107     { 0x12,     "L2TP CALL DELETE" },
108     { 0x13,     "PKI SYNC" },
109     { 0x14,     "VPN SEQ" },
110     { 0x15,     "MAX" },
111     { 0,                        NULL }
112 };
113
114 static const value_string nsrp_flag_vals[] = {
115     { 0x80,     "ENCRPT MESSAGE" },
116     { 0x40,     "CLOSE SESSION" },
117     { 0x20,     "CHANG SESSION" },
118     { 0x10,     "CREATE SP SESSION" },
119     { 0x08,     "SYS CONFIG" },
120     { 0x04,     "FILE SYS" },
121     { 0x02,     "CMD WEB" },
122     { 0,                        NULL }
123 };
124
125 static const value_string nsrp_encflag_vals[] = {
126     { 0xf0,     "ENCRYPT METHOD MASK" },
127     { 0x0f,     "ENCRYPT PAD BIT MASK" },
128     { 0,                        NULL }
129 };
130
131
132 /* Initialize the subtree pointers */
133 static gint ett_nsrp = -1;
134
135 /* Code to actually dissect the packets */
136 static int
137 dissect_nsrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
138 {
139     proto_item  *ti;
140     proto_tree  *nsrp_tree = NULL;
141     gint        offset = 0;
142     guint8      msgtype = 0;
143
144     col_set_str(pinfo->cinfo, COL_PROTOCOL, "NSRP");
145
146     col_set_str(pinfo->cinfo, COL_INFO, "NSRP Protocol");
147
148     if (tree) {
149         ti = proto_tree_add_item(tree, proto_nsrp, tvb, 0, -1, ENC_NA);
150         nsrp_tree = proto_item_add_subtree(ti, ett_nsrp);
151
152
153         proto_tree_add_item(nsrp_tree, hf_nsrp_version, tvb, offset, 1, ENC_BIG_ENDIAN);
154         offset += 1;
155
156         msgtype = tvb_get_guint8(tvb, offset);
157         proto_tree_add_item(nsrp_tree, hf_nsrp_msg_type, tvb, offset, 1, ENC_BIG_ENDIAN);
158         offset += 1;
159
160         proto_tree_add_item(nsrp_tree, hf_nsrp_clust_id, tvb, offset, 1, ENC_BIG_ENDIAN);
161         offset += 1;
162
163         proto_tree_add_item(nsrp_tree, hf_nsrp_msg_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
164         offset += 1;
165
166         proto_tree_add_item(nsrp_tree, hf_nsrp_len, tvb, offset, 2, ENC_BIG_ENDIAN);
167         offset += 2;
168
169         proto_tree_add_item(nsrp_tree, hf_nsrp_ha_port, tvb, offset, 1, ENC_BIG_ENDIAN);
170         offset += 1;
171
172         proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, ENC_BIG_ENDIAN);
173         offset += 1;
174
175         proto_tree_add_item(nsrp_tree, hf_nsrp_dst_unit, tvb, offset, 4, ENC_BIG_ENDIAN);
176         offset += 4;
177
178         proto_tree_add_item(nsrp_tree, hf_nsrp_src_unit, tvb, offset, 4, ENC_BIG_ENDIAN);
179         offset += 4;
180     }
181
182 /*
183  *
184  *
185  *    NSRP HA Packet is defined as follow:
186  *
187  *       1         2       3        4        5         6       7        8
188  *   +--------+--------+--------+--------+--------+--------+--------+--------+
189  *   | Type   |WstGroup|HstGroup|MSG Flag|     Length      |Enc Flag|Not Used|
190  *   +--------+--------+--------+--------+--------+--------+--------+--------+
191  *   |            Total Size             |        NS       |        NR       |
192  *   +--------+--------+--------+--------+--------+--------+--------+--------+
193  *   |     No Used     |    Checksum     |              Data                 |
194  *   +--------+--------+--------+--------+-----------------------------------+
195  *
196  *
197  */
198
199     if ( msgtype == 0x00 ) {
200
201         proto_tree_add_item(nsrp_tree, hf_nsrp_msgtype, tvb, offset, 1, ENC_BIG_ENDIAN);
202         offset += 1;
203
204         proto_tree_add_item(nsrp_tree, hf_nsrp_wst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
205         offset += 1;
206
207         proto_tree_add_item(nsrp_tree, hf_nsrp_hst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
208         offset += 1;
209
210         proto_tree_add_item(nsrp_tree, hf_nsrp_msgflag, tvb, offset, 1, ENC_BIG_ENDIAN);
211         offset += 1;
212
213         proto_tree_add_item(nsrp_tree, hf_nsrp_msglen, tvb, offset, 2, ENC_BIG_ENDIAN);
214         offset += 2;
215
216         proto_tree_add_item(nsrp_tree, hf_nsrp_encflag, tvb, offset, 1, ENC_BIG_ENDIAN);
217         offset += 1;
218
219         proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, ENC_BIG_ENDIAN);
220         offset += 1;
221
222         proto_tree_add_item(nsrp_tree, hf_nsrp_total_size, tvb, offset, 4, ENC_BIG_ENDIAN);
223         offset += 4;
224
225         proto_tree_add_item(nsrp_tree, hf_nsrp_ns, tvb, offset, 2, ENC_BIG_ENDIAN);
226         offset += 2;
227
228         proto_tree_add_item(nsrp_tree, hf_nsrp_nr, tvb, offset, 2, ENC_BIG_ENDIAN);
229         offset += 2;
230
231         proto_tree_add_item(nsrp_tree, hf_nsrp_no_used, tvb, offset, 2, ENC_BIG_ENDIAN);
232         offset += 2;
233
234         proto_tree_add_checksum(nsrp_tree, tvb, offset, hf_nsrp_checksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
235         offset += 2;
236
237         proto_tree_add_item(nsrp_tree, hf_nsrp_data, tvb, offset, -1, ENC_ASCII|ENC_NA);
238
239     }
240
241 /*
242  *
243  *    NSRP MNG Packet is defined as follow:
244  *
245  *       1         2       3        4        5         6       7        8
246  *   +--------+--------+--------+--------+--------+--------+--------+--------+
247  *   | Type   |WstGroup|HstGroup|MSG Flag|     Length      |AuthFlag|Not Used|
248  *   +--------+--------+--------+--------+--------+--------+--------+--------+
249  *   |Priority+ Dummy  +   Auth CheckSum +                Data               |
250  *   +--------+--------+--------+--------+-----------------------------------+
251  *
252  *
253  */
254
255     if ( msgtype == 0x02 ) {
256
257         proto_tree_add_item(nsrp_tree, hf_nsrp_msgtype, tvb, offset, 1, ENC_BIG_ENDIAN);
258         offset += 1;
259
260         proto_tree_add_item(nsrp_tree, hf_nsrp_wst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
261         offset += 1;
262
263         proto_tree_add_item(nsrp_tree, hf_nsrp_hst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
264         offset += 1;
265
266         proto_tree_add_item(nsrp_tree, hf_nsrp_msgflag, tvb, offset, 1, ENC_BIG_ENDIAN);
267         offset += 1;
268
269         proto_tree_add_item(nsrp_tree, hf_nsrp_msglen, tvb, offset, 2, ENC_BIG_ENDIAN);
270         offset += 2;
271
272         proto_tree_add_item(nsrp_tree, hf_nsrp_authflag, tvb, offset, 1, ENC_BIG_ENDIAN);
273         offset += 1;
274
275         proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, ENC_BIG_ENDIAN);
276         offset += 1;
277
278         proto_tree_add_item(nsrp_tree, hf_nsrp_priority, tvb, offset, 1, ENC_BIG_ENDIAN);
279         offset += 1;
280
281         proto_tree_add_item(nsrp_tree, hf_nsrp_dummy, tvb, offset, 1, ENC_BIG_ENDIAN);
282         offset += 1;
283
284         proto_tree_add_checksum(nsrp_tree, tvb, offset, hf_nsrp_authchecksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
285         offset += 2;
286
287         proto_tree_add_item(nsrp_tree, hf_nsrp_data, tvb, offset, -1, ENC_ASCII|ENC_NA);
288
289     }
290
291
292
293
294 /*
295  *    NSRP DATA Packet is defined as follow:
296  *
297  *       1         2       3        4        5         6       7        8
298  *   +--------+--------+--------+--------+--------+--------+--------+--------+
299  *   | Type   |WstGroup|HstGroup|MSG Flag|     Length      | Ifnum  |Not Used|
300  *   +--------+--------+--------+--------+--------+--------+--------+--------+
301  *   |            Total Size             |                Data               |
302  *   +--------+--------+--------+--------+-----------------------------------+
303  *
304  *
305  */
306     if ( msgtype == 0x03 ) {
307
308         proto_tree_add_item(nsrp_tree, hf_nsrp_msgtype, tvb, offset, 1, ENC_BIG_ENDIAN);
309         offset += 1;
310
311         proto_tree_add_item(nsrp_tree, hf_nsrp_wst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
312         offset += 1;
313
314         proto_tree_add_item(nsrp_tree, hf_nsrp_hst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
315         offset += 1;
316
317         proto_tree_add_item(nsrp_tree, hf_nsrp_msgflag, tvb, offset, 1, ENC_BIG_ENDIAN);
318         offset += 1;
319
320         proto_tree_add_item(nsrp_tree, hf_nsrp_msglen, tvb, offset, 2, ENC_BIG_ENDIAN);
321         offset += 2;
322
323         proto_tree_add_item(nsrp_tree, hf_nsrp_ifnum, tvb, offset, 1, ENC_BIG_ENDIAN);
324         offset += 1;
325
326         proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, ENC_BIG_ENDIAN);
327         offset += 1;
328
329         proto_tree_add_item(nsrp_tree, hf_nsrp_total_size, tvb, offset, 4, ENC_BIG_ENDIAN);
330         offset += 4;
331
332         proto_tree_add_item(nsrp_tree, hf_nsrp_data, tvb, offset, -1, ENC_ASCII|ENC_NA);
333
334     }
335
336     return tvb_captured_length(tvb);
337 }
338
339
340 void
341 proto_register_nsrp(void)
342 {
343
344     static hf_register_info hf[] = {
345         { &hf_nsrp_version,
346           { "Version", "nsrp.version",
347             FT_UINT8, BASE_DEC, NULL, 0,
348             "NSRP Version", HFILL }
349         },
350         { &hf_nsrp_msg_type,
351           { "Type", "nsrp.type",
352             FT_UINT8, BASE_DEC, VALS(nsrp_msg_type_vals), 0,
353             "NSRP Message Type", HFILL }
354         },
355         { &hf_nsrp_clust_id,
356           { "Clust ID", "nsrp.clustid",
357             FT_UINT8, BASE_DEC, NULL, 0,
358             "NSRP CLUST ID", HFILL }
359         },
360         { &hf_nsrp_msg_flag,
361           { "Flag", "nsrp.flag",
362             FT_UINT8, BASE_DEC, NULL, 0,
363             "NSRP FLAG", HFILL }
364         },
365         { &hf_nsrp_len,
366           { "Length", "nsrp.length",
367             FT_UINT16, BASE_DEC, NULL, 0,
368             "NSRP Length", HFILL }
369         },
370         { &hf_nsrp_ha_port,
371           { "Port", "nsrp.haport",
372             FT_UINT8, BASE_DEC, NULL, 0,
373             "NSRP HA Port", HFILL }
374         },
375         { &hf_nsrp_not_used,
376           { "Not used", "nsrp.notused",
377             FT_UINT8, BASE_DEC, NULL, 0,
378             NULL, HFILL }
379         },
380         { &hf_nsrp_dst_unit,
381           { "Destination", "nsrp.dst",
382             FT_UINT32, BASE_DEC, NULL, 0,
383             "DESTINATION UNIT INFORMATION", HFILL }
384         },
385         { &hf_nsrp_src_unit,
386           { "Source", "nsrp.src",
387             FT_UINT32, BASE_DEC, NULL, 0,
388             "SOURCE UNIT INFORMATION", HFILL }
389         },
390         { &hf_nsrp_msgtype,
391           { "MsgType", "nsrp.msgtype",
392             FT_UINT8, BASE_DEC, VALS(nsrp_msgtype_vals), 0,
393             "Message Type", HFILL }
394         },
395         { &hf_nsrp_wst_group,
396           { "Wst group", "nsrp.wst",
397             FT_UINT8, BASE_DEC, NULL, 0,
398             "NSRP WST GROUP", HFILL }
399         },
400         { &hf_nsrp_hst_group,
401           { "Hst group", "nsrp.hst",
402             FT_UINT8, BASE_DEC, NULL, 0,
403             "NSRP HST GROUP", HFILL }
404         },
405         { &hf_nsrp_msgflag,
406           { "Msgflag", "nsrp.msgflag",
407             FT_UINT8, BASE_DEC, VALS(nsrp_flag_vals), 0,
408             "NSRP MSG FLAG", HFILL }
409         },
410         { &hf_nsrp_msglen,
411           { "Msg Length", "nsrp.msglen",
412             FT_UINT16, BASE_DEC, NULL, 0,
413             "NSRP MESSAGE LENGTH", HFILL }
414         },
415
416         { &hf_nsrp_encflag,
417           { "Enc Flag", "nsrp.encflag",
418             FT_UINT8, BASE_DEC, VALS(nsrp_encflag_vals), 0,
419             "NSRP ENCRYPT FLAG", HFILL }
420         },
421 #if 0
422         { &hf_nsrp_notused,
423           { "Not Used", "nsrp.notused",
424             FT_UINT8, BASE_DEC, NULL, 0,
425             NULL, HFILL }
426         },
427 #endif
428         { &hf_nsrp_total_size,
429           { "Total Size", "nsrp.totalsize",
430             FT_UINT32, BASE_DEC, NULL, 0,
431             "NSRP MSG TOTAL MESSAGE", HFILL }
432         },
433         { &hf_nsrp_ns,
434           { "Ns", "nsrp.ns",
435             FT_UINT16, BASE_DEC, NULL, 0,
436             NULL, HFILL }
437         },
438         { &hf_nsrp_nr,
439           { "Nr", "nsrp.nr",
440             FT_UINT16, BASE_DEC, NULL, 0,
441             NULL, HFILL }
442         },
443         { &hf_nsrp_no_used,
444           { "Reserved", "nsrp.reserved",
445             FT_UINT16, BASE_DEC, NULL, 0,
446             NULL, HFILL }
447         },
448         { &hf_nsrp_checksum,
449           { "Checksum", "nsrp.checksum",
450             FT_UINT16, BASE_HEX, NULL, 0,
451             "NSRP PACKET CHECKSUM", HFILL }
452         },
453         { &hf_nsrp_authflag,
454           { "AuthFlag", "nsrp.authflag",
455             FT_UINT8, BASE_HEX, NULL, 0,
456             "NSRP Auth Flag", HFILL }
457         },
458         { &hf_nsrp_priority,
459           { "Priority", "nsrp.priority",
460             FT_UINT8, BASE_HEX, NULL, 0,
461             "NSRP Priority", HFILL }
462         },
463         { &hf_nsrp_dummy,
464           { "Dummy", "nsrp.dummy",
465             FT_UINT8, BASE_HEX, NULL, 0,
466             "NSRP Dummy", HFILL }
467         },
468         { &hf_nsrp_authchecksum,
469           { "Checksum", "nsrp.authchecksum",
470             FT_UINT16, BASE_HEX, NULL, 0,
471             "NSRP AUTH CHECKSUM", HFILL }
472         },
473         { &hf_nsrp_ifnum,
474           { "Ifnum", "nsrp.ifnum",
475             FT_UINT16, BASE_HEX, NULL, 0,
476             "NSRP IfNum", HFILL }
477         },
478         { &hf_nsrp_data,
479           { "Data", "nsrp.data",
480             FT_STRING, BASE_NONE, NULL, 0,
481             "PADDING", HFILL }
482         }
483     };
484
485     static gint *ett[] = {
486         &ett_nsrp
487     };
488
489     proto_nsrp = proto_register_protocol("Juniper Netscreen Redundant Protocol",
490                                          "NSRP", "nsrp");
491     proto_register_field_array(proto_nsrp, hf, array_length(hf));
492     proto_register_subtree_array(ett, array_length(ett));
493 }
494
495
496 void
497 proto_reg_handoff_nsrp(void)
498 {
499     dissector_handle_t nsrp_handle;
500
501     nsrp_handle = create_dissector_handle(dissect_nsrp, proto_nsrp);
502     dissector_add_uint("ethertype", ETHERTYPE_NSRP, nsrp_handle);
503 }
504
505
506 /*
507  * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
508  *
509  * Local variables:
510  * c-basic-offset: 4
511  * tab-width: 8
512  * indent-tabs-mode: nil
513  * End:
514  *
515  * vi: set shiftwidth=4 tabstop=8 expandtab:
516  * :indentSize=4:tabSize=8:noTabs=true:
517  */