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