Coverage Report

Created: 2025-02-15 06:25

/src/wireshark/epan/dissectors/packet-nhrp.c
Line
Count
Source (jump to first uncovered line)
1
/* packet-nhrp.c
2
 * Routines for NBMA Next Hop Resolution Protocol
3
 * RFC 2332 plus Cisco extensions:
4
 *     I-D draft-detienne-dmvpn-01: Flexible Dynamic Mesh VPN
5
 *     others?  (documented where?)
6
 * plus extensions from:
7
 *     RFC 2520: NHRP with Mobile NHCs
8
 *     RFC 2735: NHRP Support for Virtual Private Networks
9
 *
10
 * Wireshark - Network traffic analyzer
11
 * By Gerald Combs <gerald@wireshark.org>
12
 * Copyright 1998 Gerald Combs
13
 *
14
 * SPDX-License-Identifier: GPL-2.0-or-later
15
 *
16
 * CIE decoding for extensions and Cisco 12.4T extensions
17
 * added by Timo Teras <timo.teras@iki.fi>
18
 */
19
20
#include "config.h"
21
22
23
#include <epan/packet.h>
24
#include <epan/prefs.h>
25
#include <epan/addr_resolv.h>
26
#include <epan/expert.h>
27
#include <epan/etypes.h>
28
#include <epan/ipproto.h>
29
#include <epan/nlpid.h>
30
#include <epan/afn.h>
31
#include <epan/in_cksum.h>
32
#include "packet-iana-oui.h"
33
#include "packet-llc.h"
34
#include "packet-gre.h"
35
36
void proto_register_nhrp(void);
37
void proto_reg_handoff_nhrp(void);
38
39
static dissector_handle_t nhrp_handle;
40
41
/* forward reference */
42
static void _dissect_nhrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
43
    bool nested, bool codeinfo);
44
45
static int proto_nhrp;
46
static int hf_nhrp_hdr_afn;
47
static int hf_nhrp_hdr_pro_type;
48
static int hf_nhrp_hdr_pro_snap_oui;
49
static int hf_nhrp_hdr_pro_snap_pid;
50
static int hf_nhrp_hdr_hopcnt;
51
static int hf_nhrp_hdr_pktsz;
52
static int hf_nhrp_hdr_chksum;
53
static int hf_nhrp_hdr_chksum_status;
54
static int hf_nhrp_hdr_extoff;
55
static int hf_nhrp_hdr_version;
56
static int hf_nhrp_hdr_op_type;
57
static int hf_nhrp_hdr_shtl;
58
static int hf_nhrp_hdr_shtl_type;
59
static int hf_nhrp_hdr_shtl_len;
60
static int hf_nhrp_hdr_sstl;
61
static int hf_nhrp_hdr_sstl_type;
62
static int hf_nhrp_hdr_sstl_len;
63
64
static int hf_nhrp_src_proto_len;
65
static int hf_nhrp_dst_proto_len;
66
static int hf_nhrp_flags;
67
static int hf_nhrp_flag_Q;
68
static int hf_nhrp_flag_N;
69
static int hf_nhrp_flag_A;
70
static int hf_nhrp_flag_D;
71
static int hf_nhrp_flag_U1;
72
static int hf_nhrp_flag_U2;
73
static int hf_nhrp_flag_S;
74
static int hf_nhrp_flag_NAT;
75
static int hf_nhrp_src_nbma_addr;
76
static int hf_nhrp_src_nbma_saddr;
77
static int hf_nhrp_src_prot_addr;
78
static int hf_nhrp_dst_prot_addr;
79
static int hf_nhrp_request_id;
80
81
static int hf_nhrp_code;
82
static int hf_nhrp_prefix_len;
83
static int hf_nhrp_unused;
84
static int hf_nhrp_mtu;
85
static int hf_nhrp_holding_time;
86
static int hf_nhrp_cli_addr_tl;
87
static int hf_nhrp_cli_addr_tl_type;
88
static int hf_nhrp_cli_addr_tl_len;
89
static int hf_nhrp_cli_saddr_tl;
90
static int hf_nhrp_cli_saddr_tl_type;
91
static int hf_nhrp_cli_saddr_tl_len;
92
static int hf_nhrp_cli_prot_len;
93
static int hf_nhrp_pref;
94
static int hf_nhrp_client_nbma_addr;
95
static int hf_nhrp_client_nbma_saddr;
96
static int hf_nhrp_client_prot_addr;
97
static int hf_nhrp_ext_C;
98
static int hf_nhrp_ext_type;
99
static int hf_nhrp_ext_len;
100
/* static int hf_nhrp_ext_value; */          /* TBD: Not used */
101
static int hf_nhrp_error_code;
102
static int hf_nhrp_error_offset;
103
static int hf_nhrp_traffic_code;
104
/* static int hf_nhrp_error_packet; */       /* TBD: Not used */
105
106
static int hf_nhrp_auth_ext_reserved;
107
static int hf_nhrp_auth_ext_spi;
108
static int hf_nhrp_auth_ext_src_addr;
109
static int hf_nhrp_vendor_ext_id;
110
static int hf_nhrp_devcap_ext_srccap;
111
static int hf_nhrp_devcap_ext_srccap_V;
112
static int hf_nhrp_devcap_ext_dstcap;
113
static int hf_nhrp_devcap_ext_dstcap_V;
114
static int hf_nhrp_unknown_ext_value;
115
116
/* Generated from convert_proto_tree_add_text.pl */
117
static int hf_nhrp_dst_prot_addr_bytes;
118
static int hf_nhrp_auth_ext_src_addr_bytes;
119
static int hf_nhrp_vendor_ext_data;
120
static int hf_nhrp_protocol_type;
121
static int hf_nhrp_src_nbma_addr_bytes;
122
static int hf_nhrp_client_nbma_address_bytes;
123
static int hf_nhrp_client_prot_addr_bytes;
124
static int hf_nhrp_auth_data;
125
static int hf_nhrp_src_prot_addr_bytes;
126
127
static int ett_nhrp;
128
static int ett_nhrp_hdr;
129
static int ett_nhrp_hdr_shtl;
130
static int ett_nhrp_hdr_sstl;
131
static int ett_nhrp_mand;
132
static int ett_nhrp_ext;
133
static int ett_nhrp_mand_flag;
134
static int ett_nhrp_cie;
135
static int ett_nhrp_cie_cli_addr_tl;
136
static int ett_nhrp_cie_cli_saddr_tl;
137
static int ett_nhrp_indication;
138
static int ett_nhrp_auth_ext;
139
static int ett_nhrp_vendor_ext;
140
static int ett_nhrp_devcap_ext;
141
static int ett_nhrp_devcap_ext_srccap;
142
static int ett_nhrp_devcap_ext_dstcap;
143
144
static expert_field ei_nhrp_hdr_pktsz;
145
static expert_field ei_nhrp_hdr_extoff;
146
static expert_field ei_nhrp_hdr_chksum;
147
static expert_field ei_nhrp_ext_not_allowed;
148
static expert_field ei_nhrp_ext_malformed;
149
static expert_field ei_nhrp_ext_extra;
150
151
static bool pref_auth_ext_has_addr = true;
152
153
/* NHRP Packet Types */
154
30
#define NHRP_RESOLUTION_REQ     1
155
30
#define NHRP_RESOLUTION_REPLY   2
156
22
#define NHRP_REGISTRATION_REQ   3
157
29
#define NHRP_REGISTRATION_REPLY 4
158
27
#define NHRP_PURGE_REQ          5
159
28
#define NHRP_PURGE_REPLY        6
160
140
#define NHRP_ERROR_INDICATION   7
161
8
#define NHRP_TRAFFIC_INDICATION 8
162
163
/* NHRP Extension Types */
164
38
#define NHRP_EXT_NULL              0   /* End of Extension */
165
2
#define NHRP_EXT_RESP_ADDR         3   /* Responder Address Extension */
166
2
#define NHRP_EXT_FWD_RECORD        4   /* NHRP Forward Transit NHS Record Extension */
167
2
#define NHRP_EXT_REV_RECORD        5   /* NHRP Reverse Transit NHS Record Extension */
168
0
#define NHRP_EXT_AUTH              7   /* NHRP Authentication Extension */
169
0
#define NHRP_EXT_VENDOR_PRIV       8   /* NHRP Vendor Private Extension */
170
78
#define NHRP_EXT_NAT_ADDRESS       9   /* Cisco NAT Address Extension */
171
#define NHRP_EXT_DEV_CAPABILITIES  9   /* RFC 2735: Device Capabilities Extension */
172
0
#define NHRP_EXT_MOBILE_AUTH      10   /* RFC 2520: NHRP Mobile NHC Authentication Extension */
173
174
/* NHRP Error Codes */
175
#define NHRP_ERR_UNRECOGNIZED_EXT       0x0001
176
#define NHRP_ERR_NHRP_LOOP_DETECT       0x0003
177
#define NHRP_ERR_PROT_ADDR_UNREACHABLE  0x0006
178
#define NHRP_ERR_PROT_ERROR             0x0007
179
#define NHRP_ERR_SDU_SIZE_EXCEEDED      0x0008
180
#define NHRP_ERR_INV_EXT                0x0009
181
#define NHRP_ERR_INV_RESOLUTION_REPLY   0x000a
182
#define NHRP_ERR_AUTH_FAILURE           0x000b
183
#define NHRP_ERR_HOP_COUNT_EXCEEDED     0x000f
184
#define NHRP_ERR_VPN_MISMATCH           0x0010  /* RFC 2735 */
185
#define NHRP_ERR_VPN_UNSUPPORTED        0x0011  /* RFC 2735 */
186
187
/* NHRP CIE codes */
188
#define NHRP_CODE_SUCCESS                   0x00
189
#define NHRP_CODE_ADMIN_PROHIBITED          0x04
190
#define NHRP_CODE_INSUFFICIENT_RESOURCES    0x05
191
#define NHRP_CODE_NO_BINDING_EXISTS         0x0c
192
#define NHRP_CODE_NON_UNIQUE_BINDING        0x0d
193
#define NHRP_CODE_ALREADY_REGISTERED        0x0e
194
195
/* NHRP Subnetwork layer address type/length */
196
856
#define NHRP_SHTL_TYPE_MASK 0x40
197
1.11k
#define NHRP_SHTL_LEN_MASK  0x3F
198
800
#define NHRP_SHTL_TYPE(val) (((val) & (NHRP_SHTL_TYPE_MASK)) >> 6)
199
1.06k
#define NHRP_SHTL_LEN(val)  ((val) & (NHRP_SHTL_LEN_MASK))
200
201
#define NHRP_SHTL_TYPE_NSAP 0
202
#define NHRP_SHTL_TYPE_E164 1
203
204
static const value_string nhrp_shtl_type_vals[] = {
205
    { NHRP_SHTL_TYPE_NSAP, "NSAP format" },
206
    { NHRP_SHTL_TYPE_E164, "Native E.164 format" },
207
    { 0, NULL }
208
};
209
210
static const value_string nhrp_op_type_vals[] = {
211
    { NHRP_RESOLUTION_REQ,      "NHRP Resolution Request" },
212
    { NHRP_RESOLUTION_REPLY,    "NHRP Resolution Reply" },
213
    { NHRP_REGISTRATION_REQ,    "NHRP Registration Request" },
214
    { NHRP_REGISTRATION_REPLY,  "NHRP Registration Reply" },
215
    { NHRP_PURGE_REQ,           "NHRP Purge Request" },
216
    { NHRP_PURGE_REPLY,         "NHRP Purge Reply" },
217
    { NHRP_ERROR_INDICATION,    "NHRP Error Indication" },
218
    { NHRP_TRAFFIC_INDICATION,  "NHRP Traffic Indication" },
219
    { 0,                        NULL }
220
};
221
222
static const value_string ext_type_vals[] = {
223
    { NHRP_EXT_NULL,            "End of Extension" },
224
    { NHRP_EXT_RESP_ADDR,       "Responder Address Extension" },
225
    { NHRP_EXT_FWD_RECORD,      "Forward Transit NHS Record Extension" },
226
    { NHRP_EXT_REV_RECORD,      "Reverse Transit NHS Record Extension" },
227
    { NHRP_EXT_AUTH,            "NHRP Authentication Extension" },
228
    { NHRP_EXT_VENDOR_PRIV,     "NHRP Vendor Private Extension" },
229
    { NHRP_EXT_NAT_ADDRESS,     "Cisco NAT Address Extension" },
230
#if 0 /* Dup (which is handled in the code) */
231
    { NHRP_EXT_DEV_CAPABILITIES,"Device Capabilities Extension" },
232
#endif
233
    { NHRP_EXT_MOBILE_AUTH,     "Mobile NHC Authentication Extension" },
234
    { 0,                        NULL }
235
};
236
237
static const value_string nhrp_error_code_vals[] = {
238
    { NHRP_ERR_UNRECOGNIZED_EXT,        "Unrecognized Extension" },
239
    { NHRP_ERR_NHRP_LOOP_DETECT,        "NHRP Loop Detected" },
240
    { NHRP_ERR_PROT_ADDR_UNREACHABLE,   "Protocol Address Unreachable" },
241
    { NHRP_ERR_PROT_ERROR,              "Protocol Error" },
242
    { NHRP_ERR_SDU_SIZE_EXCEEDED,       "NHRP SDU Size Exceeded" },
243
    { NHRP_ERR_INV_EXT,                 "Invalid Extension" },
244
    { NHRP_ERR_INV_RESOLUTION_REPLY,    "Invalid NHRP Resolution Reply Received" },
245
    { NHRP_ERR_AUTH_FAILURE,            "Authentication Failure" },
246
    { NHRP_ERR_HOP_COUNT_EXCEEDED,      "Hop Count Exceeded" },
247
    { NHRP_ERR_VPN_MISMATCH,            "VPN Mismatch" },
248
    { NHRP_ERR_VPN_UNSUPPORTED,         "VPN Unsupported" },
249
    { 0,                                NULL }
250
};
251
252
static const value_string nhrp_traffic_code_vals[] = {
253
    { 0, "NHRP traffic redirect/indirection" },
254
    { 0, NULL }
255
};
256
257
static const value_string nhrp_cie_code_vals[] = {
258
    { NHRP_CODE_SUCCESS,                "Success" },
259
    { NHRP_CODE_ADMIN_PROHIBITED,       "Administratively Prohibited" },
260
    { NHRP_CODE_INSUFFICIENT_RESOURCES, "Insufficient Resources" },
261
    { NHRP_CODE_NO_BINDING_EXISTS,      "No Interworking Layer Address to NBMA Address Binding Exists" },
262
    { NHRP_CODE_NON_UNIQUE_BINDING,     "Binding Exists But Is Not Unique" },
263
    { NHRP_CODE_ALREADY_REGISTERED,     "Unique Internetworking Layer Address Already Registered" },
264
    { 0,                                NULL }
265
};
266
267
static dissector_table_t osinl_incl_subdissector_table;
268
static dissector_table_t osinl_excl_subdissector_table;
269
static dissector_table_t ethertype_subdissector_table;
270
271
/*
272
 * The header fields needed outside of dissect_nhrp_hdr().
273
 * This is not all of the fields.
274
 */
275
typedef struct _e_nhrp {
276
    uint16_t ar_afn;
277
    uint16_t ar_pro_type;
278
    uint32_t ar_pro_type_oui;
279
    uint16_t ar_pro_type_pid;
280
    uint8_t ar_op_type;
281
    uint8_t ar_shtl;
282
    uint8_t ar_sstl;
283
} e_nhrp_hdr;
284
285
static bool dissect_nhrp_hdr(tvbuff_t     *tvb,
286
                      packet_info  *pinfo,
287
                      proto_tree   *tree,
288
                      int          *pOffset,
289
                      int          *pMandLen,
290
                      int          *pExtLen,
291
                      oui_info_t  **pOuiInfo,
292
                      e_nhrp_hdr   *hdr)
293
157
{
294
157
    int          offset    = *pOffset;
295
157
    const char *pro_type_str;
296
297
157
    proto_tree *nhrp_tree;
298
157
    proto_item *nhrp_item;
299
157
    proto_item *shtl_tree_item;
300
157
    proto_tree *shtl_tree;
301
157
    proto_item *sstl_tree_item;
302
157
    proto_tree *sstl_tree;
303
157
    proto_item *ti, *ti_extoff;
304
157
    uint32_t    afn;
305
157
    uint32_t    oui;
306
157
    uint32_t    pid;
307
157
    uint32_t    pktsz;
308
157
    uint32_t    extoff;
309
157
    uint8_t     version;
310
311
157
    nhrp_tree = proto_tree_add_subtree(tree, tvb, offset, -1, ett_nhrp_hdr, &nhrp_item, "NHRP Fixed Header");
312
313
157
    proto_tree_add_item_ret_uint(nhrp_tree, hf_nhrp_hdr_afn, tvb, offset, 2, ENC_BIG_ENDIAN, &afn);
314
157
    hdr->ar_afn = (uint16_t)afn;
315
157
    offset += 2;
316
317
    /* XXX - range_string? */
318
157
    hdr->ar_pro_type = tvb_get_ntohs(tvb, offset);
319
157
    if (hdr->ar_pro_type <= 0xFF) {
320
        /* It's an NLPID */
321
30
        pro_type_str = val_to_str_const(hdr->ar_pro_type, nlpid_vals,
322
30
            "Unknown NLPID");
323
127
    } else if (hdr->ar_pro_type <= 0x3FF) {
324
        /* Reserved for future use by the IETF */
325
8
        pro_type_str = "Reserved for future use by the IETF";
326
119
    } else if (hdr->ar_pro_type <= 0x04FF) {
327
        /* Allocated for use by the ATM Forum */
328
8
        pro_type_str = "Allocated for use by the ATM Forum";
329
111
    } else if (hdr->ar_pro_type <= 0x05FF) {
330
        /* Experimental/Local use */
331
6
        pro_type_str = "Experimental/Local use";
332
105
    } else {
333
105
        pro_type_str = val_to_str_const(hdr->ar_pro_type, etype_vals,
334
105
            "Unknown Ethertype");
335
105
    }
336
157
    proto_tree_add_uint_format_value(nhrp_tree, hf_nhrp_hdr_pro_type, tvb, offset, 2,
337
157
        hdr->ar_pro_type, "%s (0x%04x)",
338
157
        pro_type_str, hdr->ar_pro_type);
339
157
    offset += 2;
340
341
157
    if (hdr->ar_pro_type == NLPID_SNAP) {
342
        /*
343
         * The long form protocol type is a SNAP OUI and PID.
344
         */
345
1
        proto_tree_add_item_ret_uint(nhrp_tree, hf_nhrp_hdr_pro_snap_oui,
346
1
            tvb, offset, 3, hdr->ar_pro_type_oui, &oui);
347
1
        offset += 3;
348
1
        hdr->ar_pro_type_oui = oui;
349
350
1
        *pOuiInfo = get_snap_oui_info(hdr->ar_pro_type_oui);
351
1
        if (*pOuiInfo != NULL) {
352
0
            proto_tree_add_item_ret_uint(nhrp_tree,
353
0
                *(*pOuiInfo)->field_info->p_id,
354
0
                tvb, offset, 2, ENC_BIG_ENDIAN, &pid);
355
1
        } else {
356
1
            proto_tree_add_item_ret_uint(nhrp_tree, hf_nhrp_hdr_pro_snap_pid,
357
1
                tvb, offset, 2, ENC_BIG_ENDIAN, &pid);
358
1
        }
359
1
        hdr->ar_pro_type_pid = (uint16_t)pid;
360
156
    } else {
361
        /*
362
         * XXX - we should check that this is zero, as RFC 2332
363
         * says it should be zero.
364
         */
365
156
        proto_tree_add_item(nhrp_tree, hf_nhrp_protocol_type, tvb, offset, 5, ENC_NA);
366
156
        offset += 5;
367
156
    }
368
369
157
    proto_tree_add_item(nhrp_tree, hf_nhrp_hdr_hopcnt, tvb, offset, 1, ENC_BIG_ENDIAN);
370
157
    offset += 1;
371
372
157
    ti = proto_tree_add_item_ret_uint(nhrp_tree, hf_nhrp_hdr_pktsz, tvb, offset, 2, ENC_BIG_ENDIAN, &pktsz);
373
157
    if (pktsz < 20) {
374
        /*
375
         * The total packet size isn't large enough for a full header.
376
         */
377
4
        expert_add_info(pinfo, ti, &ei_nhrp_hdr_pktsz);
378
4
        proto_item_set_end(nhrp_item, tvb, offset + 2);
379
4
        return false;
380
4
    }
381
153
    offset += 2;
382
383
153
    if (tvb_bytes_exist(tvb, 0, pktsz)) {
384
11
        vec_t cksum_vec[1];
385
11
        SET_CKSUM_VEC_TVB(cksum_vec[0], tvb, 0, pktsz);
386
387
11
        proto_tree_add_checksum(nhrp_tree, tvb, offset, hf_nhrp_hdr_chksum, hf_nhrp_hdr_chksum_status, &ei_nhrp_hdr_chksum,
388
11
                                pinfo, in_cksum(&cksum_vec[0], 1), ENC_BIG_ENDIAN, PROTO_CHECKSUM_VERIFY|PROTO_CHECKSUM_IN_CKSUM);
389
142
    } else {
390
142
        proto_tree_add_checksum(nhrp_tree, tvb, offset, hf_nhrp_hdr_chksum, hf_nhrp_hdr_chksum_status, &ei_nhrp_hdr_chksum,
391
142
                                pinfo, 0, ENC_BIG_ENDIAN, PROTO_CHECKSUM_NO_FLAGS);
392
142
    }
393
153
    offset += 2;
394
395
153
    ti_extoff = proto_tree_add_item_ret_uint(nhrp_tree, hf_nhrp_hdr_extoff, tvb, offset, 2, ENC_BIG_ENDIAN, &extoff);
396
153
    if (extoff != 0) {
397
140
        if (extoff < 20 || extoff > pktsz) {
398
            /* Bogus value; keep dissecting the header */
399
16
            expert_add_info(pinfo, ti_extoff, &ei_nhrp_hdr_extoff);
400
16
        }
401
140
        switch (hdr->ar_op_type)
402
140
        {
403
48
        case NHRP_ERROR_INDICATION:
404
            /* According to RFC 2332, section 5.2.7, there shouldn't be any
405
             * extensions in the Error Indication packet. */
406
48
            expert_add_info(pinfo, ti_extoff, &ei_nhrp_ext_not_allowed);
407
48
            break;
408
92
        default:
409
92
            break;
410
140
        }
411
140
    }
412
153
    offset += 2;
413
414
153
    version = tvb_get_uint8(tvb, offset);
415
153
    proto_tree_add_uint_format_value(nhrp_tree, hf_nhrp_hdr_version, tvb, offset, 1,
416
153
        version, "%u (%s)", version,
417
153
        (version == 1) ? "NHRP - rfc2332" : "Unknown");
418
153
    offset += 1;
419
153
    proto_tree_add_item(nhrp_tree, hf_nhrp_hdr_op_type, tvb, offset, 1, ENC_BIG_ENDIAN);
420
153
    offset += 1;
421
422
153
    hdr->ar_shtl = tvb_get_uint8(tvb, offset);
423
153
    shtl_tree_item = proto_tree_add_uint_format_value(nhrp_tree, hf_nhrp_hdr_shtl,
424
153
        tvb, offset, 1, hdr->ar_shtl, "%s/%u",
425
153
        val_to_str_const(NHRP_SHTL_TYPE(hdr->ar_shtl), nhrp_shtl_type_vals, "Unknown Type"),
426
153
        NHRP_SHTL_LEN(hdr->ar_shtl));
427
153
    shtl_tree = proto_item_add_subtree(shtl_tree_item, ett_nhrp_hdr_shtl);
428
153
    proto_tree_add_item(shtl_tree, hf_nhrp_hdr_shtl_type, tvb, offset, 1, ENC_BIG_ENDIAN);
429
153
    proto_tree_add_item(shtl_tree, hf_nhrp_hdr_shtl_len, tvb, offset, 1, ENC_BIG_ENDIAN);
430
153
    offset += 1;
431
432
153
    hdr->ar_sstl = tvb_get_uint8(tvb, offset);
433
153
    sstl_tree_item = proto_tree_add_uint_format_value(nhrp_tree, hf_nhrp_hdr_sstl,
434
153
        tvb, offset, 1, hdr->ar_sstl, "%s/%u",
435
153
        val_to_str_const(NHRP_SHTL_TYPE(hdr->ar_sstl), nhrp_shtl_type_vals, "Unknown Type"),
436
153
        NHRP_SHTL_LEN(hdr->ar_sstl));
437
153
    sstl_tree = proto_item_add_subtree(sstl_tree_item, ett_nhrp_hdr_sstl);
438
153
    proto_tree_add_item(sstl_tree, hf_nhrp_hdr_sstl_type, tvb, offset, 1, ENC_BIG_ENDIAN);
439
153
    proto_tree_add_item(sstl_tree, hf_nhrp_hdr_sstl_len, tvb, offset, 1, ENC_BIG_ENDIAN);
440
153
    offset += 1;
441
442
153
    proto_item_set_end(nhrp_item, tvb, offset);
443
153
    *pOffset = offset;
444
153
    if (extoff != 0) {
445
139
        if (extoff < 20 || extoff > pktsz) {
446
            /* Bogus value */
447
16
            return false;
448
16
        }
449
123
        *pMandLen = extoff - 20;
450
123
        *pExtLen = pktsz - extoff;
451
123
    }
452
14
    else {
453
14
        *pMandLen = pktsz - 20;
454
14
        *pExtLen = 0;
455
14
    }
456
137
    return true;
457
153
}
458
459
static void dissect_cie_list(tvbuff_t    *tvb,
460
                      packet_info *pinfo,
461
                      proto_tree  *tree,
462
                      int          offset,
463
                      int          cieEnd,
464
                      e_nhrp_hdr  *hdr,
465
                      int          isReq,
466
                      bool         codeinfo)
467
42
{
468
42
    proto_item *cli_addr_tree_item;
469
42
    proto_tree *cli_addr_tree;
470
42
    proto_item *cli_saddr_tree_item;
471
42
    proto_tree *cli_saddr_tree;
472
42
    uint8_t     val;
473
474
270
    while ((offset + 12)          <= cieEnd) {
475
247
        unsigned    cli_addr_len   = tvb_get_uint8(tvb, offset + 8);
476
247
        unsigned    cli_saddr_len  = tvb_get_uint8(tvb, offset + 9);
477
247
        unsigned    cli_prot_len   = tvb_get_uint8(tvb, offset + 10);
478
247
        unsigned    cie_len        = 12 + cli_addr_len + cli_saddr_len + cli_prot_len;
479
247
        proto_tree *cie_tree       = proto_tree_add_subtree(tree, tvb, offset, cie_len, ett_nhrp_cie, NULL, "Client Information Entry");
480
481
247
        if (isReq) {
482
112
            proto_tree_add_item(cie_tree, hf_nhrp_code, tvb, offset, 1, ENC_BIG_ENDIAN);
483
112
        }
484
135
        else {
485
135
            uint8_t code = tvb_get_uint8(tvb, offset);
486
135
            if ( codeinfo ) {
487
116
                col_append_fstr(pinfo->cinfo, COL_INFO, ", Code=%s",
488
116
                    val_to_str(code, nhrp_cie_code_vals, "Unknown (%u)"));
489
116
            }
490
135
            proto_tree_add_item(cie_tree, hf_nhrp_code, tvb, offset, 1, ENC_BIG_ENDIAN);
491
135
        }
492
247
        offset += 1;
493
494
247
        proto_tree_add_item(cie_tree, hf_nhrp_prefix_len, tvb, offset, 1, ENC_BIG_ENDIAN);
495
247
        offset += 1;
496
497
247
        proto_tree_add_item(cie_tree, hf_nhrp_unused, tvb, offset, 2, ENC_BIG_ENDIAN);
498
247
        offset += 2;
499
500
247
        proto_tree_add_item(cie_tree, hf_nhrp_mtu, tvb, offset, 2, ENC_BIG_ENDIAN);
501
247
        offset += 2;
502
503
247
        proto_tree_add_item(cie_tree, hf_nhrp_holding_time, tvb, offset, 2, ENC_BIG_ENDIAN);
504
247
        offset += 2;
505
506
247
        val = tvb_get_uint8(tvb, offset);
507
247
        cli_addr_tree_item = proto_tree_add_uint_format_value(cie_tree,
508
247
            hf_nhrp_cli_addr_tl, tvb, offset, 1, val, "%s/%u",
509
247
            val_to_str_const(NHRP_SHTL_TYPE(val), nhrp_shtl_type_vals, "Unknown Type"),
510
247
            NHRP_SHTL_LEN(val));
511
247
        cli_addr_tree = proto_item_add_subtree(cli_addr_tree_item, ett_nhrp_cie_cli_addr_tl);
512
247
        proto_tree_add_item(cli_addr_tree, hf_nhrp_cli_addr_tl_type, tvb, offset, 1, ENC_BIG_ENDIAN);
513
247
        proto_tree_add_item(cli_addr_tree, hf_nhrp_cli_addr_tl_len, tvb, offset, 1, ENC_BIG_ENDIAN);
514
247
        offset += 1;
515
516
247
        val = tvb_get_uint8(tvb, offset);
517
247
        cli_saddr_tree_item = proto_tree_add_uint_format_value(cie_tree,
518
247
            hf_nhrp_cli_saddr_tl, tvb, offset, 1, val, "%s/%u",
519
247
            val_to_str_const(NHRP_SHTL_TYPE(val), nhrp_shtl_type_vals, "Unknown Type"),
520
247
            NHRP_SHTL_LEN(val));
521
247
        cli_saddr_tree = proto_item_add_subtree(cli_saddr_tree_item, ett_nhrp_cie_cli_saddr_tl);
522
247
        proto_tree_add_item(cli_saddr_tree, hf_nhrp_cli_saddr_tl_type, tvb, offset, 1, ENC_BIG_ENDIAN);
523
247
        proto_tree_add_item(cli_saddr_tree, hf_nhrp_cli_saddr_tl_len, tvb, offset, 1, ENC_BIG_ENDIAN);
524
247
        offset += 1;
525
526
247
        proto_tree_add_item(cie_tree, hf_nhrp_cli_prot_len, tvb, offset, 1, ENC_BIG_ENDIAN);
527
247
        offset += 1;
528
529
247
        proto_tree_add_item(cie_tree, hf_nhrp_pref, tvb, offset, 1, ENC_BIG_ENDIAN);
530
247
        offset += 1;
531
532
247
        if (cli_addr_len) {
533
103
            switch (hdr->ar_afn) {
534
535
16
            case AFNUM_INET:
536
16
                if (cli_addr_len == 4)
537
0
                    proto_tree_add_item(cie_tree, hf_nhrp_client_nbma_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
538
16
                else {
539
16
                    proto_tree_add_item(cie_tree, hf_nhrp_client_nbma_address_bytes, tvb, offset, cli_addr_len, ENC_NA);
540
16
                }
541
16
                break;
542
543
87
            default:
544
87
                proto_tree_add_item(cie_tree, hf_nhrp_client_nbma_address_bytes, tvb, offset, cli_addr_len, ENC_NA);
545
87
                break;
546
103
            }
547
84
            offset += cli_addr_len;
548
84
        }
549
550
228
        if (cli_saddr_len) {
551
89
            proto_tree_add_item(cie_tree, hf_nhrp_client_nbma_saddr, tvb, offset, cli_saddr_len, ENC_NA);
552
89
        }
553
554
228
        if (cli_prot_len) {
555
86
            if (cli_prot_len == 4)
556
4
                proto_tree_add_item(cie_tree, hf_nhrp_client_prot_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
557
82
            else {
558
82
                proto_tree_add_item(cie_tree, hf_nhrp_client_prot_addr_bytes, tvb, offset, cli_prot_len, ENC_NA);
559
82
            }
560
86
            offset += cli_prot_len;
561
86
        }
562
228
    }
563
42
}
564
565
// NOLINTNEXTLINE(misc-no-recursion)
566
static void dissect_nhrp_mand(tvbuff_t    *tvb,
567
                       packet_info *pinfo,
568
                       proto_tree  *tree,
569
                       oui_info_t  *oui_info,
570
                       e_nhrp_hdr  *hdr,
571
                       unsigned    *srcLen,
572
                       bool         codeinfo)
573
136
{
574
136
    int      offset  = 0;
575
136
    int      mandEnd = tvb_reported_length(tvb);
576
136
    uint8_t  ssl, shl;
577
136
    unsigned dstLen;
578
579
136
    proto_tree *nhrp_tree;
580
136
    proto_item *nhrp_item;
581
582
136
    proto_tree *ind_tree;
583
136
    proto_item *ind_item;
584
136
    bool        save_in_error_pkt;
585
136
    int         dissected;
586
136
    tvbuff_t   *sub_tvb;
587
588
136
    nhrp_tree = proto_tree_add_subtree(tree, tvb, offset, -1, ett_nhrp_mand, &nhrp_item, "NHRP Mandatory Part");
589
590
    /* Src Proto Len, present in all current packet types */
591
136
    *srcLen = tvb_get_uint8(tvb, offset);
592
136
    proto_tree_add_item(nhrp_tree, hf_nhrp_src_proto_len, tvb, offset, 1, ENC_BIG_ENDIAN);
593
136
    offset += 1;
594
595
    /* Dst Proto Len, present in all current packet types */
596
136
    dstLen = tvb_get_uint8(tvb, offset);
597
136
    proto_tree_add_item(nhrp_tree, hf_nhrp_dst_proto_len, tvb, offset, 1, ENC_BIG_ENDIAN);
598
136
    offset += 1;
599
600
    /*
601
     * Flags: different flags are used for different packet types, and
602
     * aren't even present in all packet types.
603
     *
604
     * Next 4 bytes: request ID in most packet types, error code and
605
     * offset in Error Indication, traffic code and unused field in
606
     * Traffic Indication.
607
     */
608
136
    switch (hdr->ar_op_type)
609
136
    {
610
17
    case NHRP_RESOLUTION_REQ:
611
24
    case NHRP_RESOLUTION_REPLY:
612
24
        {
613
24
        static int * const flags[] = {
614
24
            &hf_nhrp_flag_Q,
615
24
            &hf_nhrp_flag_A,
616
24
            &hf_nhrp_flag_D,
617
24
            &hf_nhrp_flag_U1,
618
24
            &hf_nhrp_flag_S,
619
24
            &hf_nhrp_flag_NAT,
620
24
            NULL
621
24
        };
622
24
        proto_tree_add_bitmask(nhrp_tree, tvb, offset, hf_nhrp_flags, ett_nhrp_mand_flag, flags, ENC_BIG_ENDIAN);
623
24
        offset += 2;
624
625
24
        col_append_fstr(pinfo->cinfo, COL_INFO, ", ID=%u", tvb_get_ntohl(tvb, offset));
626
24
        proto_tree_add_item(nhrp_tree, hf_nhrp_request_id, tvb, offset, 4, ENC_BIG_ENDIAN);
627
24
        offset += 4;
628
24
        }
629
24
        break;
630
5
    case NHRP_REGISTRATION_REQ:
631
15
    case NHRP_REGISTRATION_REPLY:
632
15
        {
633
15
        static int * const flags[] = {
634
15
            &hf_nhrp_flag_U2,
635
15
            &hf_nhrp_flag_NAT,
636
15
            NULL
637
15
        };
638
15
        proto_tree_add_bitmask(nhrp_tree, tvb, offset, hf_nhrp_flags, ett_nhrp_mand_flag, flags, ENC_BIG_ENDIAN);
639
15
        offset += 2;
640
641
15
        col_append_fstr(pinfo->cinfo, COL_INFO, ", ID=%u", tvb_get_ntohl(tvb, offset));
642
15
        proto_tree_add_item(nhrp_tree, hf_nhrp_request_id, tvb, offset, 4, ENC_BIG_ENDIAN);
643
15
        offset += 4;
644
15
        }
645
15
        break;
646
647
5
    case NHRP_PURGE_REQ:
648
10
    case NHRP_PURGE_REPLY:
649
10
        {
650
10
        static int * const flags[] = {
651
10
            &hf_nhrp_flag_N,
652
10
            &hf_nhrp_flag_NAT,
653
10
            NULL
654
10
        };
655
10
        proto_tree_add_bitmask(nhrp_tree, tvb, offset, hf_nhrp_flags, ett_nhrp_mand_flag, flags, ENC_BIG_ENDIAN);
656
10
        offset += 2;
657
658
10
        col_append_fstr(pinfo->cinfo, COL_INFO, ", ID=%u", tvb_get_ntohl(tvb, offset));
659
10
        proto_tree_add_item(nhrp_tree, hf_nhrp_request_id, tvb, offset, 4, ENC_BIG_ENDIAN);
660
10
        offset += 4;
661
10
        }
662
10
        break;
663
47
    case NHRP_ERROR_INDICATION:
664
47
        {
665
        /* Skip unused field */
666
47
        offset += 2;
667
668
47
        col_append_fstr(pinfo->cinfo, COL_INFO, ", %s",
669
47
            val_to_str(tvb_get_ntohs(tvb, offset), nhrp_error_code_vals, "Unknown Error (%u)"));
670
47
        proto_tree_add_item(nhrp_tree, hf_nhrp_error_code, tvb, offset, 2, ENC_BIG_ENDIAN);
671
47
        offset += 2;
672
673
47
        proto_tree_add_item(nhrp_tree, hf_nhrp_error_offset, tvb, offset, 2, ENC_BIG_ENDIAN);
674
47
        offset += 2;
675
47
        }
676
47
        break;
677
4
    case NHRP_TRAFFIC_INDICATION:
678
4
        {
679
        /* Skip unused field */
680
4
        offset += 2;
681
682
4
        col_append_fstr(pinfo->cinfo, COL_INFO, ", %s",
683
4
            val_to_str(tvb_get_ntohs(tvb, offset), nhrp_traffic_code_vals, "Unknown traffic code (%u)"));
684
4
        proto_tree_add_item(nhrp_tree, hf_nhrp_traffic_code, tvb, offset, 2, ENC_BIG_ENDIAN);
685
4
        offset += 2;
686
687
        /* Skip unused field */
688
4
        offset += 2;
689
4
        }
690
4
        break;
691
35
    default:
692
        /* Unknown packet type */
693
35
        offset += 6;
694
35
        break;
695
136
    }
696
697
135
    shl = NHRP_SHTL_LEN(hdr->ar_shtl);
698
135
    if (shl) {
699
113
        switch (hdr->ar_afn) {
700
701
6
        case AFNUM_INET:
702
6
            if (shl == 4)
703
1
                proto_tree_add_item(nhrp_tree, hf_nhrp_src_nbma_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
704
5
            else {
705
5
                proto_tree_add_item(nhrp_tree, hf_nhrp_src_nbma_addr_bytes, tvb, offset, shl, ENC_NA);
706
5
            }
707
6
            break;
708
709
107
        default:
710
107
            proto_tree_add_item(nhrp_tree, hf_nhrp_src_nbma_addr_bytes, tvb, offset, shl, ENC_NA);
711
107
            break;
712
113
        }
713
104
        offset += shl;
714
104
    }
715
716
126
    ssl = NHRP_SHTL_LEN(hdr->ar_sstl);
717
126
    if (ssl) {
718
97
        proto_tree_add_item(nhrp_tree, hf_nhrp_src_nbma_saddr, tvb, offset, ssl, ENC_NA);
719
97
        offset += ssl;
720
97
    }
721
722
126
    if (*srcLen == 4) {
723
5
        proto_tree_add_item(nhrp_tree, hf_nhrp_src_prot_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
724
5
        offset += 4;
725
5
    }
726
121
    else if (*srcLen) {
727
75
        proto_tree_add_item(nhrp_tree, hf_nhrp_src_prot_addr_bytes, tvb, offset, *srcLen, ENC_NA);
728
75
        offset += *srcLen;
729
75
    }
730
731
126
    if (dstLen == 4) {
732
6
        proto_tree_add_item(nhrp_tree, hf_nhrp_dst_prot_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
733
6
        offset += 4;
734
6
    }
735
120
    else if (dstLen) {
736
79
        proto_tree_add_item(nhrp_tree, hf_nhrp_dst_prot_addr_bytes, tvb, offset, dstLen, ENC_NA);
737
79
        offset += dstLen;
738
79
    }
739
740
    /*
741
     * CIE list in most packet types, NHRP packet in error in Error
742
     * Indication, data packet in Traffic Indication.
743
     */
744
126
    switch (hdr->ar_op_type)
745
126
    {
746
13
    case NHRP_RESOLUTION_REQ:
747
17
    case NHRP_REGISTRATION_REQ:
748
22
    case NHRP_PURGE_REQ:
749
22
        dissect_cie_list(tvb, pinfo, nhrp_tree, offset, mandEnd, hdr, true, codeinfo);
750
22
        break;
751
6
    case NHRP_RESOLUTION_REPLY:
752
14
    case NHRP_REGISTRATION_REPLY:
753
18
    case NHRP_PURGE_REPLY:
754
18
        dissect_cie_list(tvb, pinfo, nhrp_tree, offset, mandEnd, hdr, false, codeinfo);
755
18
        break;
756
45
    case NHRP_ERROR_INDICATION:
757
45
        ind_tree = proto_tree_add_subtree(tree, tvb, offset, -1, ett_nhrp_indication, &ind_item, "Packet Causing Indication");
758
45
        save_in_error_pkt = pinfo->flags.in_error_pkt;
759
45
        pinfo->flags.in_error_pkt = true;
760
45
        sub_tvb = tvb_new_subset_remaining(tvb, offset);
761
        // We recurse here, but we'll run out of packet before we run out of stack.
762
45
        _dissect_nhrp(sub_tvb, pinfo, ind_tree, true, false);
763
45
        pinfo->flags.in_error_pkt = save_in_error_pkt;
764
45
        break;
765
4
    case NHRP_TRAFFIC_INDICATION:
766
4
        ind_tree = proto_tree_add_subtree(tree, tvb, offset, -1, ett_nhrp_indication, &ind_item, "Packet Causing Indication");
767
4
        save_in_error_pkt = pinfo->flags.in_error_pkt;
768
4
        pinfo->flags.in_error_pkt = true;
769
4
        sub_tvb = tvb_new_subset_remaining(tvb, offset);
770
4
        if (hdr->ar_pro_type <= 0xFF) {
771
            /* It's an NLPID */
772
0
            if (hdr->ar_pro_type == NLPID_SNAP) {
773
                /*
774
                 * Dissect based on the SNAP OUI and PID.
775
                 */
776
0
                if (hdr->ar_pro_type_oui == 0x000000) {
777
                    /*
778
                     * "Should not happen", as the protocol type should
779
                     * be the Ethertype, but....
780
                     */
781
0
                    dissected = dissector_try_uint(
782
0
                        ethertype_subdissector_table,
783
0
                        hdr->ar_pro_type_pid,
784
0
                        sub_tvb, pinfo, ind_tree);
785
0
                } else {
786
                    /*
787
                     * If we have a dissector table, use it, otherwise
788
                     * just dissect as data.
789
                     */
790
0
                    if (oui_info != NULL) {
791
0
                        dissected = dissector_try_uint(
792
0
                            oui_info->table,
793
0
                            hdr->ar_pro_type_pid,
794
0
                            sub_tvb, pinfo,
795
0
                            ind_tree);
796
0
                    } else
797
0
                        dissected = 0;
798
0
                }
799
0
            } else {
800
                /*
801
                 * Dissect based on the NLPID.
802
                 */
803
0
                dissected = dissector_try_uint(
804
0
                    osinl_incl_subdissector_table,
805
0
                    hdr->ar_pro_type, sub_tvb, pinfo,
806
0
                    ind_tree) ||
807
0
                            dissector_try_uint(
808
0
                    osinl_excl_subdissector_table,
809
0
                    hdr->ar_pro_type, sub_tvb, pinfo,
810
0
                    ind_tree);
811
0
            }
812
4
        } else if (hdr->ar_pro_type <= 0x3FF) {
813
            /* Reserved for future use by the IETF */
814
1
            dissected = 0;
815
3
        } else if (hdr->ar_pro_type <= 0x04FF) {
816
            /* Allocated for use by the ATM Forum */
817
0
            dissected = 0;
818
3
        } else if (hdr->ar_pro_type <= 0x05FF) {
819
            /* Experimental/Local use */
820
0
            dissected = 0;
821
3
        } else {
822
3
            dissected = dissector_try_uint(
823
3
                ethertype_subdissector_table,
824
3
                hdr->ar_pro_type, sub_tvb, pinfo, ind_tree);
825
3
        }
826
4
        if (!dissected) {
827
2
            call_data_dissector(sub_tvb, pinfo, ind_tree);
828
2
        }
829
4
        pinfo->flags.in_error_pkt = save_in_error_pkt;
830
4
        break;
831
24
    default:
832
24
        break;
833
126
    }
834
126
}
835
836
static void dissect_nhrp_ext(tvbuff_t    *tvb,
837
                      packet_info *pinfo,
838
                      proto_tree  *tree,
839
                      int         *pOffset,
840
                      int          extLen,
841
                      e_nhrp_hdr  *hdr,
842
                      unsigned     srcLen,
843
                      bool         nested)
844
26
{
845
26
    int offset = *pOffset;
846
26
    int extEnd = offset + extLen;
847
848
73
    while ((offset + 4) <= extEnd)
849
61
    {
850
61
        proto_tree *nhrp_tree;
851
61
        proto_item *nhrp_item;
852
61
        int         extTypeC = tvb_get_ntohs(tvb, offset);
853
61
        int         extType  = extTypeC & 0x3FFF;
854
61
        unsigned    len      = tvb_get_ntohs(tvb, offset+2);
855
856
61
        if ((extType == NHRP_EXT_NAT_ADDRESS) && (len == 8)) {
857
            /* Assume it's not really a Cisco NAT extension, but a device
858
             * capabilities extension instead (see RFC 2735). */
859
0
            nhrp_tree =  proto_tree_add_subtree(tree, tvb, offset,
860
0
                -1, ett_nhrp_ext, &nhrp_item, "Device Capabilities Extension");
861
0
        }
862
61
        else {
863
61
            nhrp_tree =  proto_tree_add_subtree(tree, tvb, offset,
864
61
                -1, ett_nhrp_ext, &nhrp_item,
865
61
                val_to_str(extType, ext_type_vals, "Unknown (%u)"));
866
61
        }
867
61
        proto_tree_add_boolean(nhrp_tree, hf_nhrp_ext_C, tvb, offset, 2, extTypeC);
868
61
        proto_tree_add_item(nhrp_tree, hf_nhrp_ext_type, tvb, offset, 2, ENC_BIG_ENDIAN);
869
61
        offset += 2;
870
871
61
        proto_tree_add_item(nhrp_tree, hf_nhrp_ext_len, tvb, offset, 2, ENC_BIG_ENDIAN);
872
61
        offset += 2;
873
874
61
        if (len && (extType != NHRP_EXT_NULL)) {
875
15
            if ((extType == NHRP_EXT_NAT_ADDRESS) && (len == 8)) {
876
                /* Assume it's not really a Cisco NAT extension, but a device
877
                 * capabilities extension instead (see RFC 2735). */
878
0
                proto_tree *devcap_tree;
879
0
                proto_item *cap_item;
880
0
                proto_tree *cap_tree;
881
882
0
                devcap_tree = proto_tree_add_subtree_format(nhrp_tree, tvb, offset, len,
883
0
                    ett_nhrp_devcap_ext, NULL, "Extension Data: Src is %sVPN-aware; Dst is %sVPN-aware",
884
0
                    tvb_get_ntohl(tvb, offset) & 1 ? "" : "non-",
885
0
                    tvb_get_ntohl(tvb, offset + 4) & 1 ? "" : "non-");
886
0
                cap_item = proto_tree_add_item(devcap_tree, hf_nhrp_devcap_ext_srccap, tvb, offset, 4, ENC_BIG_ENDIAN);
887
0
                cap_tree = proto_item_add_subtree(cap_item, ett_nhrp_devcap_ext_srccap);
888
0
                proto_tree_add_item(cap_tree, hf_nhrp_devcap_ext_srccap_V, tvb, offset, 4, ENC_BIG_ENDIAN);
889
890
0
                cap_item = proto_tree_add_item(devcap_tree, hf_nhrp_devcap_ext_dstcap, tvb, offset + 4, 4, ENC_BIG_ENDIAN);
891
0
                cap_tree = proto_item_add_subtree(cap_item, ett_nhrp_devcap_ext_dstcap);
892
0
                proto_tree_add_item(cap_tree, hf_nhrp_devcap_ext_dstcap_V, tvb, offset + 4, 4, ENC_BIG_ENDIAN);
893
0
                goto skip_switch;
894
0
            }
895
896
15
            switch (extType) {
897
2
            case NHRP_EXT_RESP_ADDR:
898
2
            case NHRP_EXT_FWD_RECORD:
899
2
            case NHRP_EXT_REV_RECORD:
900
2
            case NHRP_EXT_NAT_ADDRESS:
901
2
                dissect_cie_list(tvb, pinfo, nhrp_tree,
902
2
                    offset, offset + len, hdr, 0, false);
903
2
                break;
904
905
0
            case NHRP_EXT_AUTH:
906
                /* This is ugly, but this is the only place srcLen is actually
907
                 * used so we manipulate it here.
908
                 */
909
0
                if (!pref_auth_ext_has_addr)
910
0
                    srcLen = 0;
911
                /* fallthrough */
912
0
            case NHRP_EXT_MOBILE_AUTH:
913
0
                if (len < (4 + srcLen)) {
914
0
                    proto_tree_add_expert_format(nhrp_tree, pinfo, &ei_nhrp_ext_malformed, tvb, offset, len,
915
0
                        "Incomplete Authentication Extension");
916
0
                }
917
0
                else {
918
0
                    proto_tree *auth_tree;
919
0
                    proto_item *auth_item;
920
0
                    uint32_t spi;
921
922
0
                    auth_tree = proto_tree_add_subtree_format(nhrp_tree, tvb, offset, -1,
923
0
                        ett_nhrp_auth_ext, &auth_item, "Extension Data");
924
0
                    proto_tree_add_item(auth_tree, hf_nhrp_auth_ext_reserved, tvb, offset, 2, ENC_BIG_ENDIAN);
925
0
                    proto_tree_add_item_ret_uint(auth_tree, hf_nhrp_auth_ext_spi, tvb, offset + 2, 2, ENC_BIG_ENDIAN, &spi);
926
0
                    proto_item_append_text(auth_item, ": SPI=%u", spi);
927
0
                    if (srcLen == 4)
928
0
                        proto_tree_add_item(auth_tree, hf_nhrp_auth_ext_src_addr, tvb, offset + 4, 4, ENC_BIG_ENDIAN);
929
0
                    else if (srcLen) {
930
0
                        proto_tree_add_item(auth_tree, hf_nhrp_auth_ext_src_addr_bytes, tvb, offset + 4, srcLen, ENC_NA);
931
0
                    }
932
0
                    if (len > (4 + srcLen)) {
933
0
                        proto_tree_add_item(auth_tree, hf_nhrp_auth_data, tvb, offset + 4 + srcLen, len - (4 + srcLen), ENC_NA);
934
0
                        proto_item_append_text(auth_item, ": Data=%s",
935
0
                            tvb_bytes_to_str(pinfo->pool, tvb, offset + 4 + srcLen, len - (4 + srcLen)));
936
0
                    }
937
0
                    proto_item_set_len(auth_item, len);
938
0
                }
939
0
                break;
940
941
0
            case NHRP_EXT_VENDOR_PRIV:
942
0
                if (len < 3) {
943
0
                    proto_tree_add_expert_format(nhrp_tree, pinfo, &ei_nhrp_ext_malformed, tvb, offset, len,
944
0
                        "Incomplete Vendor-Private Extension");
945
0
                }
946
0
                else {
947
0
                    proto_tree *vendor_tree;
948
0
                    proto_item *vendor_item;
949
0
                    uint32_t manuf;
950
0
                    const char* oui;
951
952
0
                    vendor_tree = proto_tree_add_subtree(nhrp_tree, tvb, offset, len,
953
0
                        ett_nhrp_vendor_ext, &vendor_item, "Extension Data:");
954
0
                    proto_tree_add_item_ret_uint(vendor_tree, hf_nhrp_vendor_ext_id, tvb, offset, 3, ENC_BIG_ENDIAN, &manuf);
955
0
                    oui = uint_get_manuf_name_if_known(manuf);
956
0
                    if (oui != NULL) {
957
0
                        proto_item_append_text(vendor_item, " Vendor ID=%s", oui);
958
0
                    } else {
959
0
                        proto_item_append_text(vendor_item, " Vendor ID=Unknown");
960
0
                    }
961
0
                    if (len > 3) {
962
0
                        proto_tree_add_item(vendor_tree, hf_nhrp_vendor_ext_data, tvb, offset + 3, len - 3, ENC_NA);
963
0
                        proto_item_append_text(vendor_item, ", Data=%s", tvb_bytes_to_str(pinfo->pool, tvb, offset + 3, len - 3));
964
0
                    } else {
965
0
                        proto_item_append_text(vendor_item, ", Data=<none>");
966
0
                    }
967
0
                }
968
0
                break;
969
970
13
            default:
971
13
                proto_tree_add_item(nhrp_tree, hf_nhrp_unknown_ext_value, tvb,
972
13
                    offset, len, ENC_NA);
973
13
                break;
974
15
            }
975
6
skip_switch:
976
6
            offset += len;
977
6
        }
978
52
        proto_item_set_end(nhrp_item, tvb, offset);
979
980
52
        if (!nested) {
981
18
            len = tvb_reported_length_remaining(tvb, offset);
982
18
            if ((extType == NHRP_EXT_NULL) && len) {
983
5
                proto_tree_add_expert_format(tree, pinfo, &ei_nhrp_ext_extra, tvb, offset, len,
984
5
                    "Unknown Data (%d bytes)", len);
985
5
                break;
986
5
            }
987
18
        }
988
52
    }
989
990
17
    *pOffset = extEnd;
991
17
}
992
993
static int dissect_nhrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
994
113
{
995
113
    _dissect_nhrp(tvb, pinfo, tree, false, true);
996
113
    return tvb_captured_length(tvb);
997
113
}
998
999
// NOLINTNEXTLINE(misc-no-recursion)
1000
static void _dissect_nhrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
1001
    bool nested, bool codeinfo)
1002
158
{
1003
158
    e_nhrp_hdr  hdr;
1004
158
    int         mandLen  = 0;
1005
158
    int         extLen   = 0;
1006
158
    int         offset   = 0;
1007
158
    proto_item *ti;
1008
158
    proto_tree *nhrp_tree;
1009
158
    oui_info_t *oui_info = NULL;
1010
158
    unsigned    srcLen   = 0;
1011
1012
158
    if (!nested) {
1013
113
        col_set_str(pinfo->cinfo, COL_PROTOCOL, "NHRP");
1014
113
        col_clear(pinfo->cinfo, COL_INFO);
1015
113
    }
1016
1017
158
    memset(&hdr, 0, sizeof(e_nhrp_hdr));
1018
158
    hdr.ar_op_type = tvb_get_uint8(tvb, 17);
1019
1020
158
    if (!nested) {
1021
112
        col_add_str(pinfo->cinfo, COL_INFO,
1022
112
            val_to_str(hdr.ar_op_type, nhrp_op_type_vals,
1023
112
                "0x%02X - unknown"));
1024
112
    }
1025
1026
158
    ti = proto_tree_add_protocol_format(tree, proto_nhrp, tvb, 0, -1,
1027
158
        "Next Hop Resolution Protocol (%s)",
1028
158
        val_to_str(hdr.ar_op_type, nhrp_op_type_vals, "0x%02X - unknown"));
1029
158
    nhrp_tree = proto_item_add_subtree(ti, ett_nhrp);
1030
1031
158
    if (!dissect_nhrp_hdr(tvb, pinfo, nhrp_tree, &offset, &mandLen, &extLen,
1032
158
        &oui_info, &hdr)) {
1033
        /*
1034
         * Header is bogus in a way that we can't dissect any further.
1035
         */
1036
20
        return;
1037
20
    }
1038
138
    if (mandLen) {
1039
136
        tvbuff_t *mand_tvb = tvb_new_subset_length(tvb, offset, mandLen);
1040
        // We recurse here, but we'll run out of packet before we run out of stack.
1041
136
        dissect_nhrp_mand(mand_tvb, pinfo, nhrp_tree, oui_info, &hdr, &srcLen,
1042
136
            codeinfo);
1043
136
        offset += mandLen;
1044
136
    }
1045
1046
138
    if (extLen) {
1047
26
        dissect_nhrp_ext(tvb, pinfo, nhrp_tree, &offset, extLen, &hdr, srcLen, nested);
1048
26
    }
1049
138
}
1050
1051
void
1052
proto_register_nhrp(void)
1053
14
{
1054
14
    static hf_register_info hf[] = {
1055
1056
14
        { &hf_nhrp_hdr_afn,
1057
14
          { "Address Family Number", "nhrp.hdr.afn",
1058
14
            FT_UINT16, BASE_HEX_DEC, VALS(afn_vals), 0x0,
1059
14
            NULL, HFILL }
1060
14
        },
1061
14
        { &hf_nhrp_hdr_pro_type,
1062
14
          { "Protocol Type (short form)", "nhrp.hdr.pro.type",
1063
14
            FT_UINT16, BASE_HEX_DEC, NULL, 0x0,
1064
14
            NULL, HFILL }
1065
14
        },
1066
14
        { &hf_nhrp_hdr_pro_snap_oui,
1067
14
          { "Protocol Type (long form) - OUI", "nhrp.hdr.pro.snap.oui",
1068
14
            FT_UINT24, BASE_OUI, NULL, 0x0,
1069
14
            NULL, HFILL }
1070
14
        },
1071
14
        { &hf_nhrp_hdr_pro_snap_pid,
1072
14
          { "Protocol Type (long form) - PID", "nhrp.hdr.pro.snap.pid",
1073
14
            FT_UINT16, BASE_HEX, NULL, 0x0,
1074
14
            NULL, HFILL }
1075
14
        },
1076
14
        { &hf_nhrp_hdr_hopcnt,
1077
14
          { "Hop Count", "nhrp.hdr.hopcnt",
1078
14
            FT_UINT8, BASE_DEC, NULL, 0x0,
1079
14
            NULL, HFILL }
1080
14
        },
1081
14
        { &hf_nhrp_hdr_pktsz,
1082
14
          { "Packet Length", "nhrp.hdr.pktsz",
1083
14
            FT_UINT16, BASE_DEC, NULL, 0x0,
1084
14
            NULL, HFILL }
1085
14
        },
1086
14
        { &hf_nhrp_hdr_chksum,
1087
14
          { "NHRP Packet Checksum", "nhrp.hdr.chksum",
1088
14
            FT_UINT16, BASE_HEX, NULL, 0x0,
1089
14
            NULL, HFILL }
1090
14
        },
1091
14
        { &hf_nhrp_hdr_chksum_status,
1092
14
          { "NHRP Packet Checksum Status", "nhrp.hdr.chksum.status",
1093
14
            FT_UINT8, BASE_NONE, VALS(proto_checksum_vals), 0x0,
1094
14
            NULL, HFILL }
1095
14
        },
1096
14
        { &hf_nhrp_hdr_extoff,
1097
14
          { "Extension Offset", "nhrp.hdr.extoff",
1098
14
            FT_UINT16, BASE_DEC, NULL, 0x0,
1099
14
            NULL, HFILL }
1100
14
        },
1101
14
        { &hf_nhrp_hdr_version,
1102
14
          { "Version", "nhrp.hdr.version",
1103
14
            FT_UINT8, BASE_DEC, NULL, 0x0,
1104
14
            NULL, HFILL }
1105
14
        },
1106
14
        { &hf_nhrp_hdr_op_type,
1107
14
          { "NHRP Packet Type", "nhrp.hdr.op.type",
1108
14
            FT_UINT8, BASE_DEC, VALS(nhrp_op_type_vals), 0x0,
1109
14
            NULL, HFILL }
1110
14
        },
1111
14
        { &hf_nhrp_hdr_shtl,
1112
14
          { "Source Address Type/Len", "nhrp.hdr.shtl",
1113
14
            FT_UINT8, BASE_DEC, NULL, 0x0,
1114
14
            NULL, HFILL }
1115
14
        },
1116
14
        { &hf_nhrp_hdr_shtl_type,
1117
14
          { "Type", "nhrp.hdr.shtl.type",
1118
14
            FT_UINT8, BASE_DEC, VALS(nhrp_shtl_type_vals), NHRP_SHTL_TYPE_MASK,
1119
14
            NULL, HFILL }
1120
14
        },
1121
14
        { &hf_nhrp_hdr_shtl_len,
1122
14
          { "Length", "nhrp.hdr.shtl.len",
1123
14
            FT_UINT8, BASE_DEC, NULL, NHRP_SHTL_LEN_MASK,
1124
14
            NULL, HFILL }
1125
14
        },
1126
14
        { &hf_nhrp_hdr_sstl,
1127
14
          { "Source SubAddress Type/Len", "nhrp.hdr.sstl",
1128
14
            FT_UINT8, BASE_DEC, NULL, 0x0,
1129
14
            NULL, HFILL }
1130
14
        },
1131
14
        { &hf_nhrp_hdr_sstl_type,
1132
14
          { "Type", "nhrp.hdr.sstl.type",
1133
14
            FT_UINT8, BASE_DEC, VALS(nhrp_shtl_type_vals), NHRP_SHTL_TYPE_MASK,
1134
14
            NULL, HFILL }
1135
14
        },
1136
14
        { &hf_nhrp_hdr_sstl_len,
1137
14
          { "Length", "nhrp.hdr.sstl.len",
1138
14
            FT_UINT8, BASE_DEC, NULL, NHRP_SHTL_LEN_MASK,
1139
14
            NULL, HFILL }
1140
14
        },
1141
1142
14
        { &hf_nhrp_src_proto_len,
1143
14
          { "Source Protocol Len", "nhrp.src.prot.len",
1144
14
            FT_UINT16, BASE_DEC, NULL, 0x0,
1145
14
            NULL, HFILL }
1146
14
        },
1147
14
        { &hf_nhrp_dst_proto_len,
1148
14
          { "Destination Protocol Len", "nhrp.dst.prot.len",
1149
14
            FT_UINT16, BASE_DEC, NULL, 0x0,
1150
14
            NULL, HFILL }
1151
14
        },
1152
14
        { &hf_nhrp_flags,
1153
14
          { "Flags", "nhrp.flags",
1154
14
            FT_UINT16, BASE_HEX, NULL, 0x0,
1155
14
            NULL, HFILL }
1156
14
        },
1157
14
        { &hf_nhrp_flag_Q,
1158
14
          { "Is Router", "nhrp.flag.q",
1159
14
            FT_BOOLEAN, 16, NULL, 0x8000,
1160
14
            NULL, HFILL }
1161
14
        },
1162
14
        { &hf_nhrp_flag_N,
1163
14
          { "Expected Purge Reply", "nhrp.flag.n",
1164
14
            FT_BOOLEAN, 16, NULL, 0x8000,
1165
14
            NULL, HFILL }
1166
14
        },
1167
14
        { &hf_nhrp_flag_A,
1168
14
          { "Authoritative", "nhrp.flag.a",
1169
14
            FT_BOOLEAN, 16, NULL, 0x4000,
1170
14
            "A bit", HFILL }
1171
14
        },
1172
14
        { &hf_nhrp_flag_D,
1173
14
          { "Stable Association", "nhrp.flag.d",
1174
14
            FT_BOOLEAN, 16, NULL, 0x2000,
1175
14
            "D bit", HFILL }
1176
14
        },
1177
14
        { &hf_nhrp_flag_U1,
1178
14
          { "Uniqueness Bit", "nhrp.flag.u",
1179
14
            FT_BOOLEAN, 16, NULL, 0x1000,
1180
14
            "U bit", HFILL }
1181
14
        },
1182
14
        { &hf_nhrp_flag_U2,
1183
14
          { "Uniqueness Bit", "nhrp.flag.u",
1184
14
            FT_BOOLEAN, 16, NULL, 0x8000,
1185
14
            "U bit", HFILL }
1186
14
        },
1187
14
        { &hf_nhrp_flag_S,
1188
14
          { "Stable Binding", "nhrp.flag.s",
1189
14
            FT_BOOLEAN, 16, NULL, 0x0800,
1190
14
            "S bit", HFILL }
1191
14
        },
1192
14
        { &hf_nhrp_flag_NAT,
1193
14
          { "Cisco NAT Supported", "nhrp.flag.nat",
1194
14
            FT_BOOLEAN, 16, NULL, 0x0002,
1195
14
            "NAT bit", HFILL }
1196
14
        },
1197
14
        { &hf_nhrp_request_id,
1198
14
          { "Request ID", "nhrp.reqid",
1199
14
            FT_UINT32, BASE_HEX_DEC, NULL, 0x0,
1200
14
            NULL, HFILL }
1201
14
        },
1202
14
        { &hf_nhrp_src_nbma_addr,
1203
14
          { "Source NBMA Address", "nhrp.src.nbma.addr",
1204
14
            FT_IPv4, BASE_NONE, NULL, 0x0,
1205
14
            NULL, HFILL }
1206
14
        },
1207
14
        { &hf_nhrp_src_nbma_saddr,
1208
14
          { "Source NBMA Sub Address", "nhrp.src.nbma.saddr",
1209
14
            FT_BYTES, BASE_NONE, NULL, 0x0,
1210
14
            NULL, HFILL }
1211
14
        },
1212
14
        { &hf_nhrp_src_prot_addr,
1213
14
          { "Source Protocol Address", "nhrp.src.prot.addr",
1214
14
            FT_IPv4, BASE_NONE, NULL, 0x0,
1215
14
            NULL, HFILL }
1216
14
        },
1217
14
        { &hf_nhrp_dst_prot_addr,
1218
14
          { "Destination Protocol Address", "nhrp.dst.prot.addr",
1219
14
            FT_IPv4, BASE_NONE, NULL, 0x0,
1220
14
            NULL, HFILL }
1221
14
        },
1222
1223
14
        { &hf_nhrp_code,
1224
14
          { "Code", "nhrp.code",
1225
14
            FT_UINT8, BASE_DEC, VALS(nhrp_cie_code_vals), 0x0,
1226
14
            NULL, HFILL }
1227
14
        },
1228
14
        { &hf_nhrp_prefix_len,
1229
14
          { "Prefix Length", "nhrp.prefix",
1230
14
            FT_UINT8, BASE_DEC, NULL, 0x0,
1231
14
            NULL, HFILL }
1232
14
        },
1233
14
        { &hf_nhrp_unused,
1234
14
          { "Unused", "nhrp.unused",
1235
14
            FT_UINT16, BASE_DEC, NULL, 0x0,
1236
14
            NULL, HFILL }
1237
14
        },
1238
14
        { &hf_nhrp_mtu,
1239
14
          { "Max Transmission Unit", "nhrp.mtu",
1240
14
            FT_UINT16, BASE_DEC, NULL, 0x0,
1241
14
            NULL, HFILL }
1242
14
        },
1243
14
        { &hf_nhrp_holding_time,
1244
14
          { "Holding Time (s)", "nhrp.htime",
1245
14
            FT_UINT16, BASE_DEC, NULL, 0x0,
1246
14
            NULL, HFILL }
1247
14
        },
1248
14
        { &hf_nhrp_cli_addr_tl,
1249
14
          { "Client Address Type/Len", "nhrp.cli.addr_tl",
1250
14
            FT_UINT8, BASE_DEC, NULL, 0x0,
1251
14
            NULL, HFILL }
1252
14
        },
1253
14
        { &hf_nhrp_cli_addr_tl_type,
1254
14
          { "Type", "nhrp.cli.addr_tl.type",
1255
14
            FT_UINT8, BASE_DEC, VALS(nhrp_shtl_type_vals), NHRP_SHTL_TYPE_MASK,
1256
14
            NULL, HFILL }
1257
14
        },
1258
14
        { &hf_nhrp_cli_addr_tl_len,
1259
14
          { "Length", "nhrp.cli.addr_tl.len",
1260
14
            FT_UINT8, BASE_DEC, NULL, NHRP_SHTL_LEN_MASK,
1261
14
            NULL, HFILL }
1262
14
        },
1263
14
        { &hf_nhrp_cli_saddr_tl,
1264
14
          { "Client Sub Address Type/Len", "nhrp.cli.saddr_tl",
1265
14
            FT_UINT8, BASE_DEC, NULL, 0x0,
1266
14
            NULL, HFILL }
1267
14
        },
1268
14
        { &hf_nhrp_cli_saddr_tl_type,
1269
14
          { "Type", "nhrp.cli.saddr_tl.type",
1270
14
            FT_UINT8, BASE_DEC, VALS(nhrp_shtl_type_vals), NHRP_SHTL_TYPE_MASK,
1271
14
            NULL, HFILL }
1272
14
        },
1273
14
        { &hf_nhrp_cli_saddr_tl_len,
1274
14
          { "Length", "nhrp.cli.saddr_tl.len",
1275
14
            FT_UINT8, BASE_DEC, NULL, NHRP_SHTL_LEN_MASK,
1276
14
            NULL, HFILL }
1277
14
        },
1278
14
        { &hf_nhrp_cli_prot_len,
1279
14
          { "Client Protocol Length", "nhrp.prot.len",
1280
14
            FT_UINT8, BASE_DEC, NULL, 0x0,
1281
14
            NULL, HFILL }
1282
14
        },
1283
14
        { &hf_nhrp_pref,
1284
14
          { "CIE Preference Value", "nhrp.pref",
1285
14
            FT_UINT8, BASE_DEC, NULL, 0x0,
1286
14
            NULL, HFILL }
1287
14
        },
1288
14
        { &hf_nhrp_client_nbma_addr,
1289
14
          { "Client NBMA Address", "nhrp.client.nbma.addr",
1290
14
            FT_IPv4, BASE_NONE, NULL, 0x0,
1291
14
            NULL, HFILL }
1292
14
        },
1293
14
        { &hf_nhrp_client_nbma_saddr,
1294
14
          { "Client NBMA Sub Address", "nhrp.client.nbma.saddr",
1295
14
            FT_BYTES, BASE_NONE, NULL, 0x0,
1296
14
            NULL, HFILL }
1297
14
        },
1298
14
        { &hf_nhrp_client_prot_addr,
1299
14
          { "Client Protocol Address", "nhrp.client.prot.addr",
1300
14
            FT_IPv4, BASE_NONE, NULL, 0x0,
1301
14
            NULL, HFILL }
1302
14
        },
1303
1304
14
        { &hf_nhrp_ext_C,
1305
14
          { "Compulsory Flag", "nhrp.ext.c",
1306
14
            FT_BOOLEAN, 16, NULL, 0x8000,
1307
14
            NULL, HFILL }
1308
14
        },
1309
14
        { &hf_nhrp_ext_type,
1310
14
          { "Extension Type", "nhrp.ext.type",
1311
14
            FT_UINT16, BASE_HEX, VALS(ext_type_vals), 0x3FFF,
1312
14
            NULL, HFILL }
1313
14
        },
1314
14
        { &hf_nhrp_ext_len,
1315
14
          { "Extension length", "nhrp.ext.len",
1316
14
            FT_UINT16, BASE_DEC, NULL, 0x0,
1317
14
            NULL, HFILL }
1318
14
        },
1319
#if 0
1320
        { &hf_nhrp_ext_value,
1321
          { "Extension Value", "nhrp.ext.val",
1322
            FT_UINT_BYTES, BASE_NONE, NULL, 0x0,
1323
            NULL, HFILL }
1324
        },
1325
#endif
1326
1327
14
        { &hf_nhrp_error_code,
1328
14
          { "Error Code", "nhrp.err.code",
1329
14
            FT_UINT16, BASE_DEC, VALS(nhrp_error_code_vals), 0x0,
1330
14
            NULL, HFILL }
1331
14
        },
1332
14
        { &hf_nhrp_error_offset,
1333
14
          { "Error Offset", "nhrp.err.offset",
1334
14
            FT_UINT16, BASE_DEC, NULL, 0x0,
1335
14
            NULL, HFILL }
1336
14
        },
1337
#if 0
1338
        { &hf_nhrp_error_packet,
1339
          { "Errored Packet", "nhrp.err.pkt",
1340
            FT_UINT_BYTES, BASE_NONE, NULL, 0x0,
1341
            NULL, HFILL }
1342
        },
1343
#endif
1344
14
        { &hf_nhrp_traffic_code,
1345
14
          { "Traffic Code", "nhrp.tind.code",
1346
14
            FT_UINT16, BASE_DEC, VALS(nhrp_traffic_code_vals), 0x0,
1347
14
            NULL, HFILL }
1348
14
        },
1349
14
        { &hf_nhrp_auth_ext_reserved,
1350
14
          { "Reserved", "nhrp.auth_ext.reserved",
1351
14
            FT_UINT16, BASE_DEC, NULL, 0x0,
1352
14
            NULL, HFILL }
1353
14
        },
1354
14
        { &hf_nhrp_auth_ext_spi,
1355
14
          { "SPI", "nhrp.auth_ext.spi",
1356
14
            FT_UINT16, BASE_DEC, NULL, 0x0,
1357
14
            "Security Parameter Index", HFILL }
1358
14
        },
1359
14
        { &hf_nhrp_auth_ext_src_addr,
1360
14
          { "Source Address", "nhrp.auth_ext.src_addr",
1361
14
            FT_IPv4, BASE_NONE, NULL, 0x0,
1362
14
            NULL, HFILL }
1363
14
        },
1364
14
        { &hf_nhrp_vendor_ext_id      ,
1365
14
          { "Vendor ID", "nhrp.vendor_ext.id",
1366
14
            FT_UINT24, BASE_DEC, NULL, 0x0,
1367
14
            NULL, HFILL }
1368
14
        },
1369
14
        { &hf_nhrp_devcap_ext_srccap,
1370
14
          { "Source Capabilities", "nhrp.devcap_ext.srccap",
1371
14
            FT_UINT32, BASE_HEX, NULL, 0x0,
1372
14
            NULL, HFILL }
1373
14
        },
1374
14
        { &hf_nhrp_devcap_ext_srccap_V,
1375
14
          { "VPN-aware", "nhrp.devcap_ext.srccap.V",
1376
14
            FT_BOOLEAN, 32, NULL, 0x00000001,
1377
14
            NULL, HFILL }
1378
14
        },
1379
14
        { &hf_nhrp_devcap_ext_dstcap,
1380
14
          { "Destination Capabilities", "nhrp.devcap_ext.dstcap",
1381
14
            FT_UINT32, BASE_HEX, NULL, 0x0,
1382
14
            NULL, HFILL }
1383
14
        },
1384
14
        { &hf_nhrp_devcap_ext_dstcap_V,
1385
14
          { "VPN-aware", "nhrp.devcap_ext.dstcap.V",
1386
14
            FT_BOOLEAN, 32, NULL, 0x00000001,
1387
14
            NULL, HFILL }
1388
14
        },
1389
14
        { &hf_nhrp_unknown_ext_value,
1390
14
          { "Extension Value", "nhrp.unknown_ext.value",
1391
14
            FT_BYTES, BASE_NONE, NULL, 0x0,
1392
14
            NULL, HFILL }
1393
14
        },
1394
1395
      /* Generated from convert_proto_tree_add_text.pl */
1396
14
      { &hf_nhrp_protocol_type, { "Protocol Type (long form)", "nhrp.protocol_type", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1397
14
      { &hf_nhrp_client_nbma_address_bytes, { "Client NBMA Address", "nhrp.client.nbma.addr_bytes", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1398
14
      { &hf_nhrp_client_prot_addr_bytes, { "Client Protocol Address", "nhrp.client.prot.addr_bytes", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1399
14
      { &hf_nhrp_src_nbma_addr_bytes, { "Source NBMA Address", "nhrp.src.nbma.addr_bytes", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1400
14
      { &hf_nhrp_src_prot_addr_bytes, { "Source Protocol Address", "nhrp.src.prot.addr_bytes", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1401
14
      { &hf_nhrp_dst_prot_addr_bytes, { "Destination Protocol Address", "nhrp.dst.prot.addr_byets", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1402
14
      { &hf_nhrp_auth_ext_src_addr_bytes, { "Source Address", "nhrp.auth_ext.src_addr_bytes", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1403
14
      { &hf_nhrp_auth_data, { "Data", "nhrp.auth_ext.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1404
14
      { &hf_nhrp_vendor_ext_data, { "Data", "nhrp.vendor_ext.data", FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1405
14
    };
1406
1407
14
    static int *ett[] = {
1408
14
        &ett_nhrp,
1409
14
        &ett_nhrp_hdr,
1410
14
        &ett_nhrp_hdr_shtl,
1411
14
        &ett_nhrp_hdr_sstl,
1412
14
        &ett_nhrp_mand,
1413
14
        &ett_nhrp_ext,
1414
14
        &ett_nhrp_mand_flag,
1415
14
        &ett_nhrp_cie,
1416
14
        &ett_nhrp_cie_cli_addr_tl,
1417
14
        &ett_nhrp_cie_cli_saddr_tl,
1418
14
        &ett_nhrp_indication,
1419
14
        &ett_nhrp_auth_ext,
1420
14
        &ett_nhrp_vendor_ext,
1421
14
        &ett_nhrp_devcap_ext,
1422
14
        &ett_nhrp_devcap_ext_srccap,
1423
14
        &ett_nhrp_devcap_ext_dstcap
1424
14
    };
1425
1426
14
    static ei_register_info ei[] = {
1427
14
        { &ei_nhrp_hdr_pktsz, { "nhrp.hdr.pktsz.invalid", PI_MALFORMED, PI_ERROR, "Packet length is less than the fixed header length", EXPFILL }},
1428
14
        { &ei_nhrp_hdr_extoff, { "nhrp.hdr.extoff.invalid", PI_MALFORMED, PI_ERROR, "Extension offset is less than the fixed header length or larger than the packet size", EXPFILL }},
1429
14
        { &ei_nhrp_hdr_chksum, { "nhrp.hdr.bad_checksum", PI_CHECKSUM, PI_ERROR, "Bad checksum", EXPFILL }},
1430
14
        { &ei_nhrp_ext_not_allowed, { "nhrp.ext.not_allowed", PI_MALFORMED, PI_ERROR, "Extensions not allowed per RFC2332 section 5.2.7", EXPFILL }},
1431
14
        { &ei_nhrp_ext_malformed, { "nhrp.ext.malformed", PI_MALFORMED, PI_ERROR, "Incomplete Authentication Extension", EXPFILL }},
1432
14
        { &ei_nhrp_ext_extra, { "nhrp.ext.extra", PI_MALFORMED, PI_ERROR, "Superfluous data follows End Extension", EXPFILL }},
1433
14
    };
1434
1435
14
    module_t *nhrp_module;
1436
14
    expert_module_t* expert_nhrp;
1437
1438
14
    proto_nhrp = proto_register_protocol("NBMA Next Hop Resolution Protocol", "NHRP", "nhrp");
1439
14
    proto_register_field_array(proto_nhrp, hf, array_length(hf));
1440
14
    proto_register_subtree_array(ett, array_length(ett));
1441
14
    nhrp_module = prefs_register_protocol(proto_nhrp, NULL);
1442
14
    prefs_register_bool_preference(nhrp_module, "auth_ext_has_addr",
1443
14
                                   "Authentication Extension data contains the source address",
1444
14
                                   "Whether the Authentication Extension data contains the source address. "
1445
14
                                   "Some Cisco IOS implementations forgo this part of RFC2332.",
1446
14
                                   &pref_auth_ext_has_addr);
1447
14
    expert_nhrp = expert_register_protocol(proto_nhrp);
1448
14
    expert_register_field_array(expert_nhrp, ei, array_length(ei));
1449
1450
14
    nhrp_handle = register_dissector("nhrp", dissect_nhrp, proto_nhrp);
1451
14
}
1452
1453
void
1454
proto_reg_handoff_nhrp(void)
1455
14
{
1456
14
    osinl_incl_subdissector_table = find_dissector_table("osinl.incl");
1457
14
    osinl_excl_subdissector_table = find_dissector_table("osinl.excl");
1458
14
    ethertype_subdissector_table  = find_dissector_table("ethertype");
1459
1460
14
    dissector_add_uint("ip.proto", IP_PROTO_NARP, nhrp_handle);
1461
14
    dissector_add_uint("gre.proto", GRE_NHRP, nhrp_handle);
1462
14
    dissector_add_uint("llc.iana_pid", IANA_PID_MARS_NHRP_CONTROL, nhrp_handle);
1463
14
}
1464
1465
/*
1466
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
1467
 *
1468
 * Local variables:
1469
 * c-basic-offset: 4
1470
 * tab-width: 8
1471
 * indent-tabs-mode: nil
1472
 * End:
1473
 *
1474
 * vi: set shiftwidth=4 tabstop=8 expandtab:
1475
 * :indentSize=4:tabSize=8:noTabs=true:
1476
 */