summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-nsrp.c
blob: a9819f0583e86102af3e2cf822d201cbefefac6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
/* packet-nsrp.c
 * Routines for the Juniper Netscreen Redundant Protocol (NSRP)
 *
 * Secfire <secfire@gmail.com>
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

/*
 *
 * NSRP update information can be found at www.juniper.net
 *
 *
 *
 *    NSRP Packet Header is defined as follow:
 *
 *       1         2       3        4        5         6       7        8
 *   +--------+--------+--------+--------+--------+--------+--------+--------+
 *   |Version | Type   |Clust ID|MSG Flag|     Length      |HA Port |Not Used|
 *   +--------+--------+--------+--------+--------+--------+--------+--------+
 *   |          Destination Unit         |             Source Unit           |
 *   +--------+--------+--------+--------+--------+--------+--------+--------+
 *
 *
 *
 */

#include "config.h"

#include <epan/packet.h>
#include <epan/etypes.h>

void proto_register_nsrp(void);
void proto_reg_handoff_nsrp(void);

static dissector_handle_t nsrp_handle;

#define NSRP_MIN_LEN    32

/* Initialize the protocol and registered fields */
static int proto_nsrp;

static int hf_nsrp_version;
static int hf_nsrp_msg_type;
static int hf_nsrp_clust_id;
static int hf_nsrp_msg_flag;
static int hf_nsrp_len;
static int hf_nsrp_ha_port;
static int hf_nsrp_not_used;
static int hf_nsrp_dst_unit;
static int hf_nsrp_src_unit;
static int hf_nsrp_msgtype;
static int hf_nsrp_wst_group;
static int hf_nsrp_hst_group;
static int hf_nsrp_msgflag;
static int hf_nsrp_authflag;
static int hf_nsrp_priority;
static int hf_nsrp_dummy;
static int hf_nsrp_authchecksum;
static int hf_nsrp_ifnum;


/* Dada defined for HA Message */
static int hf_nsrp_msglen;
static int hf_nsrp_encflag;
/* static int hf_nsrp_notused; */

static int hf_nsrp_total_size;

static int hf_nsrp_ns;
static int hf_nsrp_nr;

static int hf_nsrp_no_used;
static int hf_nsrp_checksum;

static int hf_nsrp_data;


static const value_string nsrp_msg_type_vals[] = {
    { 0x01,     "HA MESSAGE" },
    { 0x02,     "MNG MESSAGE" },
    { 0x03,     "DADA MESSAGE" },
    { 0,                        NULL }
};

static const value_string nsrp_msgtype_vals[] = {
    { 0x01,     "CREATE SESSION" },
    { 0x02,     "CLOSE SESSION" },
    { 0x03,     "CHANG SESSION" },
    { 0x04,     "CREATE SP SESSION" },
    { 0x05,     "SYS CONFIG" },
    { 0x06,     "FILE SYS" },
    { 0x07,     "CMD WEB" },
    { 0x08,     "SAVE SLAVE" },
    { 0x09,     "VPN SPI" },
    { 0x0a,     "ARP" },
    { 0x0b,     "HEALTH CHECK" },
    { 0x0c,     "EMW DATA" },
    { 0x0d,     "INVITE SYNC" },
    { 0x0e,     "DOWNLOAD CONFIG" },
    { 0x0f,     "L2TP TUNL CREATE" },
    { 0x10,     "L2TP TUNL DELETE" },
    { 0x11,     "L2TP CALL CREATE" },
    { 0x12,     "L2TP CALL DELETE" },
    { 0x13,     "PKI SYNC" },
    { 0x14,     "VPN SEQ" },
    { 0x15,     "MAX" },
    { 0,                        NULL }
};

static const value_string nsrp_flag_vals[] = {
    { 0x80,     "ENCRYPT MESSAGE" },
    { 0x40,     "CLOSE SESSION" },
    { 0x20,     "CHANG SESSION" },
    { 0x10,     "CREATE SP SESSION" },
    { 0x08,     "SYS CONFIG" },
    { 0x04,     "FILE SYS" },
    { 0x02,     "CMD WEB" },
    { 0,                        NULL }
};

static const value_string nsrp_encflag_vals[] = {
    { 0xf0,     "ENCRYPT METHOD MASK" },
    { 0x0f,     "ENCRYPT PAD BIT MASK" },
    { 0,                        NULL }
};


/* Initialize the subtree pointers */
static int ett_nsrp;

/* Code to actually dissect the packets */
static int
dissect_nsrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
    proto_item  *ti;
    proto_tree  *nsrp_tree = NULL;
    int         offset = 0;
    uint8_t     msgtype = 0;

    col_set_str(pinfo->cinfo, COL_PROTOCOL, "NSRP");

    col_set_str(pinfo->cinfo, COL_INFO, "NSRP Protocol");

    if (tree) {
        ti = proto_tree_add_item(tree, proto_nsrp, tvb, 0, -1, ENC_NA);
        nsrp_tree = proto_item_add_subtree(ti, ett_nsrp);


        proto_tree_add_item(nsrp_tree, hf_nsrp_version, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        msgtype = tvb_get_uint8(tvb, offset);
        proto_tree_add_item(nsrp_tree, hf_nsrp_msg_type, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_clust_id, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_msg_flag, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_len, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(nsrp_tree, hf_nsrp_ha_port, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_dst_unit, tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;

        proto_tree_add_item(nsrp_tree, hf_nsrp_src_unit, tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;
    }

/*
 *
 *
 *    NSRP HA Packet is defined as follow:
 *
 *       1         2       3        4        5         6       7        8
 *   +--------+--------+--------+--------+--------+--------+--------+--------+
 *   | Type   |WstGroup|HstGroup|MSG Flag|     Length      |Enc Flag|Not Used|
 *   +--------+--------+--------+--------+--------+--------+--------+--------+
 *   |            Total Size             |        NS       |        NR       |
 *   +--------+--------+--------+--------+--------+--------+--------+--------+
 *   |     No Used     |    Checksum     |              Data                 |
 *   +--------+--------+--------+--------+-----------------------------------+
 *
 *
 */

    if ( msgtype == 0x00 ) {

        proto_tree_add_item(nsrp_tree, hf_nsrp_msgtype, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_wst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_hst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_msgflag, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_msglen, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(nsrp_tree, hf_nsrp_encflag, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_total_size, tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;

        proto_tree_add_item(nsrp_tree, hf_nsrp_ns, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(nsrp_tree, hf_nsrp_nr, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(nsrp_tree, hf_nsrp_no_used, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_checksum(nsrp_tree, tvb, offset, hf_nsrp_checksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
        offset += 2;

        proto_tree_add_item(nsrp_tree, hf_nsrp_data, tvb, offset, -1, ENC_ASCII);

    }

/*
 *
 *    NSRP MNG Packet is defined as follow:
 *
 *       1         2       3        4        5         6       7        8
 *   +--------+--------+--------+--------+--------+--------+--------+--------+
 *   | Type   |WstGroup|HstGroup|MSG Flag|     Length      |AuthFlag|Not Used|
 *   +--------+--------+--------+--------+--------+--------+--------+--------+
 *   |Priority+ Dummy  +   Auth CheckSum +                Data               |
 *   +--------+--------+--------+--------+-----------------------------------+
 *
 *
 */

    if ( msgtype == 0x02 ) {

        proto_tree_add_item(nsrp_tree, hf_nsrp_msgtype, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_wst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_hst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_msgflag, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_msglen, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(nsrp_tree, hf_nsrp_authflag, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_priority, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_dummy, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_checksum(nsrp_tree, tvb, offset, hf_nsrp_authchecksum, -1, NULL, pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
        offset += 2;

        proto_tree_add_item(nsrp_tree, hf_nsrp_data, tvb, offset, -1, ENC_ASCII);

    }




/*
 *    NSRP DATA Packet is defined as follow:
 *
 *       1         2       3        4        5         6       7        8
 *   +--------+--------+--------+--------+--------+--------+--------+--------+
 *   | Type   |WstGroup|HstGroup|MSG Flag|     Length      | Ifnum  |Not Used|
 *   +--------+--------+--------+--------+--------+--------+--------+--------+
 *   |            Total Size             |                Data               |
 *   +--------+--------+--------+--------+-----------------------------------+
 *
 *
 */
    if ( msgtype == 0x03 ) {

        proto_tree_add_item(nsrp_tree, hf_nsrp_msgtype, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_wst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_hst_group, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_msgflag, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_msglen, tvb, offset, 2, ENC_BIG_ENDIAN);
        offset += 2;

        proto_tree_add_item(nsrp_tree, hf_nsrp_ifnum, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_not_used, tvb, offset, 1, ENC_BIG_ENDIAN);
        offset += 1;

        proto_tree_add_item(nsrp_tree, hf_nsrp_total_size, tvb, offset, 4, ENC_BIG_ENDIAN);
        offset += 4;

        proto_tree_add_item(nsrp_tree, hf_nsrp_data, tvb, offset, -1, ENC_ASCII);

    }

    return tvb_captured_length(tvb);
}


void
proto_register_nsrp(void)
{

    static hf_register_info hf[] = {
        { &hf_nsrp_version,
          { "Version", "nsrp.version",
            FT_UINT8, BASE_DEC, NULL, 0,
            "NSRP Version", HFILL }
        },
        { &hf_nsrp_msg_type,
          { "Type", "nsrp.type",
            FT_UINT8, BASE_DEC, VALS(nsrp_msg_type_vals), 0,
            "NSRP Message Type", HFILL }
        },
        { &hf_nsrp_clust_id,
          { "Clust ID", "nsrp.clustid",
            FT_UINT8, BASE_DEC, NULL, 0,
            "NSRP CLUST ID", HFILL }
        },
        { &hf_nsrp_msg_flag,
          { "Flag", "nsrp.flag",
            FT_UINT8, BASE_DEC, NULL, 0,
            "NSRP FLAG", HFILL }
        },
        { &hf_nsrp_len,
          { "Length", "nsrp.length",
            FT_UINT16, BASE_DEC, NULL, 0,
            "NSRP Length", HFILL }
        },
        { &hf_nsrp_ha_port,
          { "Port", "nsrp.haport",
            FT_UINT8, BASE_DEC, NULL, 0,
            "NSRP HA Port", HFILL }
        },
        { &hf_nsrp_not_used,
          { "Not used", "nsrp.notused",
            FT_UINT8, BASE_DEC, NULL, 0,
            NULL, HFILL }
        },
        { &hf_nsrp_dst_unit,
          { "Destination", "nsrp.dst",
            FT_UINT32, BASE_DEC, NULL, 0,
            "DESTINATION UNIT INFORMATION", HFILL }
        },
        { &hf_nsrp_src_unit,
          { "Source", "nsrp.src",
            FT_UINT32, BASE_DEC, NULL, 0,
            "SOURCE UNIT INFORMATION", HFILL }
        },
        { &hf_nsrp_msgtype,
          { "MsgType", "nsrp.msgtype",
            FT_UINT8, BASE_DEC, VALS(nsrp_msgtype_vals), 0,
            "Message Type", HFILL }
        },
        { &hf_nsrp_wst_group,
          { "Wst group", "nsrp.wst",
            FT_UINT8, BASE_DEC, NULL, 0,
            "NSRP WST GROUP", HFILL }
        },
        { &hf_nsrp_hst_group,
          { "Hst group", "nsrp.hst",
            FT_UINT8, BASE_DEC, NULL, 0,
            "NSRP HST GROUP", HFILL }
        },
        { &hf_nsrp_msgflag,
          { "Msgflag", "nsrp.msgflag",
            FT_UINT8, BASE_DEC, VALS(nsrp_flag_vals), 0,
            "NSRP MSG FLAG", HFILL }
        },
        { &hf_nsrp_msglen,
          { "Msg Length", "nsrp.msglen",
            FT_UINT16, BASE_DEC, NULL, 0,
            "NSRP MESSAGE LENGTH", HFILL }
        },

        { &hf_nsrp_encflag,
          { "Enc Flag", "nsrp.encflag",
            FT_UINT8, BASE_DEC, VALS(nsrp_encflag_vals), 0,
            "NSRP ENCRYPT FLAG", HFILL }
        },
#if 0
        { &hf_nsrp_notused,
          { "Not Used", "nsrp.notused",
            FT_UINT8, BASE_DEC, NULL, 0,
            NULL, HFILL }
        },
#endif
        { &hf_nsrp_total_size,
          { "Total Size", "nsrp.totalsize",
            FT_UINT32, BASE_DEC, NULL, 0,
            "NSRP MSG TOTAL MESSAGE", HFILL }
        },
        { &hf_nsrp_ns,
          { "Ns", "nsrp.ns",
            FT_UINT16, BASE_DEC, NULL, 0,
            NULL, HFILL }
        },
        { &hf_nsrp_nr,
          { "Nr", "nsrp.nr",
            FT_UINT16, BASE_DEC, NULL, 0,
            NULL, HFILL }
        },
        { &hf_nsrp_no_used,
          { "Reserved", "nsrp.reserved",
            FT_UINT16, BASE_DEC, NULL, 0,
            NULL, HFILL }
        },
        { &hf_nsrp_checksum,
          { "Checksum", "nsrp.checksum",
            FT_UINT16, BASE_HEX, NULL, 0,
            "NSRP PACKET CHECKSUM", HFILL }
        },
        { &hf_nsrp_authflag,
          { "AuthFlag", "nsrp.authflag",
            FT_UINT8, BASE_HEX, NULL, 0,
            "NSRP Auth Flag", HFILL }
        },
        { &hf_nsrp_priority,
          { "Priority", "nsrp.priority",
            FT_UINT8, BASE_HEX, NULL, 0,
            "NSRP Priority", HFILL }
        },
        { &hf_nsrp_dummy,
          { "Dummy", "nsrp.dummy",
            FT_UINT8, BASE_HEX, NULL, 0,
            "NSRP Dummy", HFILL }
        },
        { &hf_nsrp_authchecksum,
          { "Checksum", "nsrp.authchecksum",
            FT_UINT16, BASE_HEX, NULL, 0,
            "NSRP AUTH CHECKSUM", HFILL }
        },
        { &hf_nsrp_ifnum,
          { "Ifnum", "nsrp.ifnum",
            FT_UINT16, BASE_HEX, NULL, 0,
            "NSRP IfNum", HFILL }
        },
        { &hf_nsrp_data,
          { "Data", "nsrp.data",
            FT_STRING, BASE_NONE, NULL, 0,
            "PADDING", HFILL }
        }
    };

    static int *ett[] = {
        &ett_nsrp
    };

    proto_nsrp = proto_register_protocol("Juniper Netscreen Redundant Protocol",
                                         "NSRP", "nsrp");
    proto_register_field_array(proto_nsrp, hf, array_length(hf));
    proto_register_subtree_array(ett, array_length(ett));

    nsrp_handle = register_dissector("nsrp", dissect_nsrp, proto_nsrp);
}


void
proto_reg_handoff_nsrp(void)
{
    dissector_add_uint("ethertype", ETHERTYPE_NSRP, nsrp_handle);
}


/*
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
 *
 * Local variables:
 * c-basic-offset: 4
 * tab-width: 8
 * indent-tabs-mode: nil
 * End:
 *
 * vi: set shiftwidth=4 tabstop=8 expandtab:
 * :indentSize=4:tabSize=8:noTabs=true:
 */