2 * Routines for NBMA Next Hop Resolution Protocol
3 * RFC 2332 plus Cisco extensions (documented where?)
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * CIE decoding for extensions and Cisco 12.4T extensions
26 * added by Timo Teras <timo.teras@iki.fi>
38 #include <epan/packet.h>
39 #include <epan/addr_resolv.h>
40 #include <epan/expert.h>
41 #include <epan/etypes.h>
42 #include <epan/ipproto.h>
43 #include <epan/greproto.h>
44 #include <epan/nlpid.h>
46 #include <epan/sminmpec.h>
48 #include <epan/in_cksum.h>
49 #include <epan/iana_snap_pid.h>
50 #include <epan/dissectors/packet-llc.h>
51 #include "packet-nhrp.h"
53 /* forward reference */
54 void proto_register_nhrp(void);
55 void proto_reg_handoff_nhrp(void);
56 void dissect_nhrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
58 static int proto_nhrp = -1;
59 static int hf_nhrp_hdr_afn = -1;
60 static int hf_nhrp_hdr_pro_type = -1;
61 static int hf_nhrp_hdr_pro_snap_oui = -1;
62 static int hf_nhrp_hdr_pro_snap_pid = -1;
63 static int hf_nhrp_hdr_hopcnt = -1;
64 static int hf_nhrp_hdr_pktsz = -1;
65 static int hf_nhrp_hdr_chksum = -1;
66 static int hf_nhrp_hdr_extoff = -1;
67 static int hf_nhrp_hdr_version = -1;
68 static int hf_nhrp_hdr_op_type = -1;
69 static int hf_nhrp_hdr_shtl = -1;
70 static int hf_nhrp_hdr_shtl_type = -1;
71 static int hf_nhrp_hdr_shtl_len = -1;
72 static int hf_nhrp_hdr_sstl = -1;
73 static int hf_nhrp_hdr_sstl_type = -1;
74 static int hf_nhrp_hdr_sstl_len = -1;
76 static int hf_nhrp_src_proto_len = -1;
77 static int hf_nhrp_dst_proto_len = -1;
78 static int hf_nhrp_flags = -1;
79 static int hf_nhrp_flag_Q = -1;
80 static int hf_nhrp_flag_N = -1;
81 static int hf_nhrp_flag_A = -1;
82 static int hf_nhrp_flag_D = -1;
83 static int hf_nhrp_flag_U1 = -1;
84 static int hf_nhrp_flag_U2 = -1;
85 static int hf_nhrp_flag_S = -1;
86 static int hf_nhrp_flag_NAT = -1;
87 static int hf_nhrp_src_nbma_addr = -1;
88 static int hf_nhrp_src_nbma_saddr = -1;
89 static int hf_nhrp_src_prot_addr = -1;
90 static int hf_nhrp_dst_prot_addr = -1;
91 static int hf_nhrp_request_id = -1;
93 static int hf_nhrp_code = -1;
94 static int hf_nhrp_prefix_len = -1;
95 static int hf_nhrp_unused = -1;
96 static int hf_nhrp_mtu = -1;
97 static int hf_nhrp_holding_time = -1;
98 static int hf_nhrp_cli_addr_tl = -1;
99 static int hf_nhrp_cli_addr_tl_type = -1;
100 static int hf_nhrp_cli_addr_tl_len = -1;
101 static int hf_nhrp_cli_saddr_tl = -1;
102 static int hf_nhrp_cli_saddr_tl_type = -1;
103 static int hf_nhrp_cli_saddr_tl_len = -1;
104 static int hf_nhrp_cli_prot_len = -1;
105 static int hf_nhrp_pref = -1;
106 static int hf_nhrp_client_nbma_addr = -1;
107 static int hf_nhrp_client_nbma_saddr = -1;
108 static int hf_nhrp_client_prot_addr = -1;
109 static int hf_nhrp_ext_C = -1;
110 static int hf_nhrp_ext_type = -1;
111 static int hf_nhrp_ext_len = -1;
112 static int hf_nhrp_ext_value = -1;
113 static int hf_nhrp_error_offset = -1;
114 static int hf_nhrp_error_packet = -1;
116 static gint ett_nhrp = -1;
117 static gint ett_nhrp_hdr = -1;
118 static gint ett_nhrp_hdr_shtl = -1;
119 static gint ett_nhrp_hdr_sstl = -1;
120 static gint ett_nhrp_mand = -1;
121 static gint ett_nhrp_ext = -1;
122 static gint ett_nhrp_mand_flag = -1;
123 static gint ett_nhrp_cie = -1;
124 static gint ett_nhrp_cie_cli_addr_tl = -1;
125 static gint ett_nhrp_cie_cli_saddr_tl = -1;
126 static gint ett_nhrp_indication = -1;
128 /* NHRP Packet Types */
129 #define NHRP_RESOLUTION_REQ 1
130 #define NHRP_RESOLUTION_REPLY 2
131 #define NHRP_REGISTRATION_REQ 3
132 #define NHRP_REGISTRATION_REPLY 4
133 #define NHRP_PURGE_REQ 5
134 #define NHRP_PURGE_REPLY 6
135 #define NHRP_ERROR_INDICATION 7
136 #define NHRP_TRAFFIC_INDICATION 8
138 /* NHRP Extension Types */
139 #define NHRP_EXT_NULL 0 /* End of Extension */
140 #define NHRP_EXT_RESP_ADDR 3 /* Responder Address Extension */
141 #define NHRP_EXT_FWD_RECORD 4 /* NHRP Forward Transit NHS Record Extension */
142 #define NHRP_EXT_REV_RECORD 5 /* NHRP Reverse Transit NHS Record Extension */
143 #define NHRP_EXT_AUTH 7 /* NHRP Authentication Extension */
144 #define NHRP_EXT_VENDOR_PRIV 8 /* NHRP Vendor Private Extension */
145 #define NHRP_EXT_NAT_ADDRESS 9 /* Cisco NAT Address Extension */
147 /* NHRP Error Codes */
148 #define NHRP_ERR_UNRECOGNIZED_EXT 0x0001
149 #define NHRP_ERR_NHRP_LOOP_DETECT 0x0003
150 #define NHRP_ERR_PROT_ADDR_UNREACHABLE 0x0006
151 #define NHRP_ERR_PROT_ERROR 0x0007
152 #define NHRP_ERR_SDU_SIZE_EXCEEDED 0x0008
153 #define NHRP_ERR_INV_EXT 0x0009
154 #define NHRP_ERR_INV_RESOLUTION_REPLY 0x000a
155 #define NHRP_ERR_AUTH_FAILURE 0x000b
156 #define NHRP_ERR_HOP_COUNT_EXCEEDED 0x000f
159 #define NHRP_CODE_SUCCESS 0x00
160 #define NHRP_CODE_ADMIN_PROHIBITED 0x04
161 #define NHRP_CODE_INSUFFICIENT_RESOURCES 0x05
162 #define NHRP_CODE_NO_BINDING_EXISTS 0x0c
163 #define NHRP_CODE_NON_UNIQUE_BINDING 0x0d
164 #define NHRP_CODE_ALREADY_REGISTERED 0x0e
166 /* NHRP Subnetwork layer address type/length */
167 #define NHRP_SHTL_TYPE_MASK 0x40
168 #define NHRP_SHTL_LEN_MASK 0x3F
169 #define NHRP_SHTL_TYPE(val) (((val) & (NHRP_SHTL_TYPE_MASK)) >> 6)
170 #define NHRP_SHTL_LEN(val) ((val) & (NHRP_SHTL_LEN_MASK))
172 #define NHRP_SHTL_TYPE_NSAP 0
173 #define NHRP_SHTL_TYPE_E164 1
175 static const value_string nhrp_shtl_type_vals[] = {
176 { NHRP_SHTL_TYPE_NSAP, "NSAP format" },
177 { NHRP_SHTL_TYPE_E164, "Native E.164 format" },
181 static const value_string nhrp_op_type_vals[] = {
182 { NHRP_RESOLUTION_REQ, "NHRP Resolution Request" },
183 { NHRP_RESOLUTION_REPLY, "NHRP Resolution Reply" },
184 { NHRP_REGISTRATION_REQ, "NHRP Registration Request" },
185 { NHRP_REGISTRATION_REPLY, "NHRP Registration Reply" },
186 { NHRP_PURGE_REQ, "NHRP Purge Request" },
187 { NHRP_PURGE_REPLY, "NHRP Purge Reply" },
188 { NHRP_ERROR_INDICATION, "NHRP Error Indication" },
189 { NHRP_TRAFFIC_INDICATION, "NHRP Traffic Indication" },
193 static const value_string ext_type_vals[] = {
194 { NHRP_EXT_NULL, "End of Extension" },
195 { NHRP_EXT_RESP_ADDR, "Responder Address Extension" },
196 { NHRP_EXT_FWD_RECORD, "Forward Transit NHS Record Extension" },
197 { NHRP_EXT_REV_RECORD, "Reverse Transit NHS Record Extension" },
198 { NHRP_EXT_AUTH, "NHRP Authentication Extension" },
199 { NHRP_EXT_VENDOR_PRIV, "NHRP Vendor Private Extension" },
200 { NHRP_EXT_NAT_ADDRESS, "Cisco NAT Address Extension" },
204 static const value_string nhrp_error_code_vals[] = {
205 { NHRP_ERR_UNRECOGNIZED_EXT, "Unrecognized Extension" },
206 { NHRP_ERR_NHRP_LOOP_DETECT, "NHRP Loop Detected" },
207 { NHRP_ERR_PROT_ADDR_UNREACHABLE, "Protocol Address Unreachable" },
208 { NHRP_ERR_PROT_ERROR, "Protocol Error" },
209 { NHRP_ERR_SDU_SIZE_EXCEEDED, "NHRP SDU Size Exceeded" },
210 { NHRP_ERR_INV_EXT, "Invalid Extension" },
211 { NHRP_ERR_INV_RESOLUTION_REPLY, "Invalid NHRP Resolution Reply Received" },
212 { NHRP_ERR_AUTH_FAILURE, "Authentication Failure" },
213 { NHRP_ERR_HOP_COUNT_EXCEEDED, "Hop Count Exceeded" },
217 static const value_string nhrp_cie_code_vals[] = {
218 { NHRP_CODE_SUCCESS, "Success" },
219 { NHRP_CODE_ADMIN_PROHIBITED, "Administratively Prohibited" },
220 { NHRP_CODE_INSUFFICIENT_RESOURCES, "Insufficient Resources" },
221 { NHRP_CODE_NO_BINDING_EXISTS, "No Interworking Layer Address to NBMA Address Binding Exists" },
222 { NHRP_CODE_NON_UNIQUE_BINDING, "Binding Exists But Is Not Unique" },
223 { NHRP_CODE_ALREADY_REGISTERED, "Unique Internetworking Layer Address Already Registered" },
227 static dissector_table_t osinl_subdissector_table;
228 static dissector_table_t osinl_excl_subdissector_table;
229 static dissector_table_t ethertype_subdissector_table;
231 static dissector_handle_t data_handle;
233 typedef struct _e_nhrp {
236 guint32 ar_pro_type_oui;
237 guint16 ar_pro_type_pid;
242 guint8 ar_op_version;
248 static guint16 nhrp_checksum(const guint8 *ptr, int len)
252 cksum_vec[0].ptr = ptr;
253 cksum_vec[0].len = len;
254 return in_cksum(&cksum_vec[0], 1);
257 void dissect_nhrp_hdr(tvbuff_t *tvb,
263 oui_info_t **pOuiInfo,
266 gint offset = *pOffset;
267 const gchar *pro_type_str;
268 guint total_len = tvb_reported_length(tvb);
269 guint16 ipcsum, rx_chksum;
271 proto_item *nhrp_tree_item = NULL;
272 proto_tree *nhrp_tree = NULL;
273 proto_item *shtl_tree_item = NULL;
274 proto_tree *shtl_tree = NULL;
275 proto_item *sstl_tree_item = NULL;
276 proto_tree *sstl_tree = NULL;
279 nhrp_tree_item = proto_tree_add_text(tree, tvb, offset, 20, "NHRP Fixed Header");
280 nhrp_tree = proto_item_add_subtree(nhrp_tree_item, ett_nhrp_hdr);
282 hdr->ar_pktsz = tvb_get_ntohs(tvb, 10);
283 if (total_len > hdr->ar_pktsz) {
284 total_len = hdr->ar_pktsz;
287 hdr->ar_afn = tvb_get_ntohs(tvb, offset);
288 proto_tree_add_item(nhrp_tree, hf_nhrp_hdr_afn, tvb, offset, 2, FALSE);
291 hdr->ar_pro_type = tvb_get_ntohs(tvb, offset);
292 if (hdr->ar_pro_type <= 0xFF) {
294 pro_type_str = val_to_str(hdr->ar_pro_type, nlpid_vals,
296 } else if (hdr->ar_pro_type <= 0x3FF) {
297 /* Reserved for future use by the IETF */
298 pro_type_str = "Reserved for future use by the IETF";
299 } else if (hdr->ar_pro_type <= 0x04FF) {
300 /* Allocated for use by the ATM Forum */
301 pro_type_str = "Allocated for use by the ATM Forum";
302 } else if (hdr->ar_pro_type <= 0x05FF) {
303 /* Experimental/Local use */
304 pro_type_str = "Experimental/Local use";
306 pro_type_str = val_to_str(hdr->ar_pro_type, etype_vals,
307 "Unknown Ethertype");
309 proto_tree_add_uint_format(nhrp_tree, hf_nhrp_hdr_pro_type, tvb, offset, 2,
310 hdr->ar_pro_type, "Protocol Type (short form): %s (0x%04x)",
311 pro_type_str, hdr->ar_pro_type);
314 if (hdr->ar_pro_type == NLPID_SNAP) {
316 * The long form protocol type is a SNAP OUI and PID.
318 hdr->ar_pro_type_oui = tvb_get_ntoh24(tvb, offset);
319 proto_tree_add_uint(nhrp_tree, hf_nhrp_hdr_pro_snap_oui,
320 tvb, offset, 3, hdr->ar_pro_type_oui);
323 hdr->ar_pro_type_pid = tvb_get_ntohs(tvb, offset);
324 *pOuiInfo = get_snap_oui_info(hdr->ar_pro_type_oui);
325 if (*pOuiInfo != NULL) {
326 proto_tree_add_uint(nhrp_tree,
327 *(*pOuiInfo)->field_info->p_id,
328 tvb, offset, 2, hdr->ar_pro_type_pid);
330 proto_tree_add_uint(nhrp_tree, hf_nhrp_hdr_pro_snap_pid,
331 tvb, offset, 2, hdr->ar_pro_type_pid);
335 * XXX - we should check that this is zero, as RFC 2332
336 * says it should be zero.
338 proto_tree_add_text(nhrp_tree, tvb, offset, 5,
339 "Protocol Type (long form): %s",
340 tvb_bytes_to_str(tvb, offset, 5));
344 proto_tree_add_item(nhrp_tree, hf_nhrp_hdr_hopcnt, tvb, offset, 1, FALSE);
347 proto_tree_add_item(nhrp_tree, hf_nhrp_hdr_pktsz, tvb, offset, 2, FALSE);
350 rx_chksum = tvb_get_ntohs(tvb, offset);
351 if (tvb_bytes_exist(tvb, 0, total_len)) {
352 ipcsum = nhrp_checksum(tvb_get_ptr(tvb, 0, total_len),
355 proto_tree_add_uint_format(nhrp_tree, hf_nhrp_hdr_chksum, tvb, offset, 2, rx_chksum,
356 "NHRP Packet checksum: 0x%04x [correct]", rx_chksum);
358 proto_tree_add_uint_format(nhrp_tree, hf_nhrp_hdr_chksum, tvb, offset, 2, rx_chksum,
359 "NHRP Packet checksum: 0x%04x [incorrect, should be 0x%04x]", rx_chksum,
360 in_cksum_shouldbe(rx_chksum, ipcsum));
363 proto_tree_add_uint_format(nhrp_tree, hf_nhrp_hdr_chksum, tvb, offset, 2, rx_chksum,
364 "NHRP Packet checksum: 0x%04x [not all data available]", rx_chksum);
368 hdr->ar_extoff = tvb_get_ntohs(tvb, offset);
369 ti = proto_tree_add_item(nhrp_tree, hf_nhrp_hdr_extoff, tvb, offset, 2, FALSE);
370 if (hdr->ar_extoff != 0 && hdr->ar_extoff < 20) {
371 expert_add_info_format(pinfo, ti, PI_MALFORMED, PI_ERROR,
372 "Extension offset is less than the fixed header length");
376 hdr->ar_op_version = tvb_get_guint8(tvb, offset);
377 proto_tree_add_text(nhrp_tree, tvb, offset, 1, "Version : %u (%s)",
379 (hdr->ar_op_version == 1) ? "NHRP - rfc2332" : "Unknown");
382 proto_tree_add_text(nhrp_tree, tvb, offset, 1, "NHRP Packet Type : (%s)",
383 val_to_str(hdr->ar_op_type, nhrp_op_type_vals, "Unknown (%u)")) ;
386 hdr->ar_shtl = tvb_get_guint8(tvb, offset);
387 shtl_tree_item = proto_tree_add_uint_format(nhrp_tree, hf_nhrp_hdr_shtl,
388 tvb, offset, 1, hdr->ar_shtl, "Source Address Type/Len: %s/%u",
389 val_to_str(NHRP_SHTL_TYPE(hdr->ar_shtl), nhrp_shtl_type_vals, "Unknown Type"),
390 NHRP_SHTL_LEN(hdr->ar_shtl));
391 shtl_tree = proto_item_add_subtree(shtl_tree_item, ett_nhrp_hdr_shtl);
392 proto_tree_add_item(shtl_tree, hf_nhrp_hdr_shtl_type, tvb, offset, 1, FALSE);
393 proto_tree_add_item(shtl_tree, hf_nhrp_hdr_shtl_len, tvb, offset, 1, FALSE);
396 hdr->ar_sstl = tvb_get_guint8(tvb, offset);
397 sstl_tree_item = proto_tree_add_uint_format(nhrp_tree, hf_nhrp_hdr_sstl,
398 tvb, offset, 1, hdr->ar_sstl, "Source SubAddress Type/Len: %s/%u",
399 val_to_str(NHRP_SHTL_TYPE(hdr->ar_sstl), nhrp_shtl_type_vals, "Unknown Type"),
400 NHRP_SHTL_LEN(hdr->ar_sstl));
401 sstl_tree = proto_item_add_subtree(sstl_tree_item, ett_nhrp_hdr_sstl);
402 proto_tree_add_item(sstl_tree, hf_nhrp_hdr_sstl_type, tvb, offset, 1, FALSE);
403 proto_tree_add_item(sstl_tree, hf_nhrp_hdr_sstl_len, tvb, offset, 1, FALSE);
407 if (hdr->ar_extoff != 0) {
408 if (hdr->ar_extoff >= 20) {
409 *pMandLen = hdr->ar_extoff - 20;
410 *pExtLen = total_len - hdr->ar_extoff;
419 *pMandLen = total_len - 20;
421 /* "Can't happen" - we would have thrown an exception */
428 void dissect_cie_list(tvbuff_t *tvb,
435 proto_item *cli_addr_tree_item = NULL;
436 proto_tree *cli_addr_tree = NULL;
437 proto_item *cli_saddr_tree_item = NULL;
438 proto_tree *cli_saddr_tree = NULL;
441 while ((offset + 12) <= cieEnd) {
442 guint cli_addr_len = tvb_get_guint8(tvb, offset + 8);
443 guint cli_saddr_len = tvb_get_guint8(tvb, offset + 9);
444 guint cli_prot_len = tvb_get_guint8(tvb, offset + 10);
445 guint cie_len = 12 + cli_addr_len + cli_saddr_len + cli_prot_len;
446 proto_item *cie_tree_item = proto_tree_add_text(tree, tvb, offset, cie_len, "Client Information Entry");
447 proto_tree *cie_tree = proto_item_add_subtree(cie_tree_item, ett_nhrp_cie);
450 proto_tree_add_item(cie_tree, hf_nhrp_code, tvb, offset, 1, FALSE);
453 guint8 code = tvb_get_guint8(tvb, offset);
454 proto_tree_add_text(cie_tree, tvb, offset, 1, "Code: %s",
455 val_to_str(code, nhrp_cie_code_vals, "Unknown (%u)"));
459 proto_tree_add_item(cie_tree, hf_nhrp_prefix_len, tvb, offset, 1, FALSE);
462 proto_tree_add_item(cie_tree, hf_nhrp_unused, tvb, offset, 2, FALSE);
465 proto_tree_add_item(cie_tree, hf_nhrp_mtu, tvb, offset, 2, FALSE);
468 proto_tree_add_item(cie_tree, hf_nhrp_holding_time, tvb, offset, 2, FALSE);
471 val = tvb_get_guint8(tvb, offset);
472 cli_addr_tree_item = proto_tree_add_uint_format(cie_tree,
473 hf_nhrp_cli_addr_tl, tvb, offset, 1, val,
474 "Client Address Type/Len: %s/%u",
475 val_to_str(NHRP_SHTL_TYPE(val), nhrp_shtl_type_vals, "Unknown Type"),
477 cli_addr_tree = proto_item_add_subtree(cli_addr_tree_item, ett_nhrp_cie_cli_addr_tl);
478 proto_tree_add_item(cli_addr_tree, hf_nhrp_cli_addr_tl_type, tvb, offset, 1, FALSE);
479 proto_tree_add_item(cli_addr_tree, hf_nhrp_cli_addr_tl_len, tvb, offset, 1, FALSE);
482 val = tvb_get_guint8(tvb, offset);
483 cli_saddr_tree_item = proto_tree_add_uint_format(cie_tree,
484 hf_nhrp_cli_saddr_tl, tvb, offset, 1, val,
485 "Client Sub Address Type/Len: %s/%u",
486 val_to_str(NHRP_SHTL_TYPE(val), nhrp_shtl_type_vals, "Unknown Type"),
488 cli_saddr_tree = proto_item_add_subtree(cli_saddr_tree_item, ett_nhrp_cie_cli_saddr_tl);
489 proto_tree_add_item(cli_saddr_tree, hf_nhrp_cli_saddr_tl_type, tvb, offset, 1, FALSE);
490 proto_tree_add_item(cli_saddr_tree, hf_nhrp_cli_saddr_tl_len, tvb, offset, 1, FALSE);
493 proto_tree_add_item(cie_tree, hf_nhrp_cli_prot_len, tvb, offset, 1, FALSE);
496 proto_tree_add_item(cie_tree, hf_nhrp_pref, tvb, offset, 1, FALSE);
500 switch (hdr->ar_afn) {
503 if (cli_addr_len == 4)
504 proto_tree_add_item(cie_tree, hf_nhrp_client_nbma_addr, tvb, offset, 4, FALSE);
506 proto_tree_add_text(cie_tree, tvb, offset, cli_addr_len,
507 "Client NBMA Address: %s",
508 tvb_bytes_to_str(tvb, offset, cli_addr_len));
513 proto_tree_add_text(cie_tree, tvb, offset, cli_addr_len,
514 "Client NBMA Address: %s",
515 tvb_bytes_to_str(tvb, offset, cli_addr_len));
518 offset += cli_addr_len;
522 proto_tree_add_text(cie_tree, tvb, offset, cli_saddr_len,
523 "Client NBMA Sub Address: %s",
524 tvb_bytes_to_str(tvb, offset, cli_saddr_len));
528 if (cli_prot_len == 4)
529 proto_tree_add_ipv4(cie_tree, hf_nhrp_client_prot_addr, tvb, offset, 4, FALSE);
531 proto_tree_add_text(cie_tree, tvb, offset, cli_prot_len,
532 "Client Protocol Address: %s",
533 tvb_bytes_to_str(tvb, offset, cli_prot_len));
535 offset += cli_prot_len;
540 void dissect_nhrp_mand(tvbuff_t *tvb,
545 oui_info_t *oui_info,
548 gint offset = *pOffset;
549 gint mandEnd = offset + mandLen;
552 guint srcLen, dstLen;
557 proto_item *nhrp_tree_item = NULL;
558 proto_item *flag_item = NULL;
559 proto_tree *nhrp_tree = NULL;
560 proto_tree *flag_tree = NULL;
562 tvb_ensure_bytes_exist(tvb, offset, mandLen);
564 switch (hdr->ar_op_type)
566 case NHRP_RESOLUTION_REQ:
567 case NHRP_REGISTRATION_REQ:
571 case NHRP_ERROR_INDICATION: /* This needs special treatment */
575 case NHRP_TRAFFIC_INDICATION:
579 nhrp_tree_item = proto_tree_add_text(tree, tvb, offset, mandLen, "NHRP Mandatory Part");
580 nhrp_tree = proto_item_add_subtree(nhrp_tree_item, ett_nhrp_mand);
582 srcLen = tvb_get_guint8(tvb, offset);
583 proto_tree_add_item(nhrp_tree, hf_nhrp_src_proto_len, tvb, offset, 1, FALSE);
586 dstLen = tvb_get_guint8(tvb, offset);
587 proto_tree_add_item(nhrp_tree, hf_nhrp_dst_proto_len, tvb, offset, 1, FALSE);
591 flags = tvb_get_ntohs(tvb, offset);
592 flag_item = proto_tree_add_uint(nhrp_tree, hf_nhrp_flags, tvb, offset, 2, flags);
593 flag_tree = proto_item_add_subtree(flag_item, ett_nhrp_mand_flag);
595 switch (hdr->ar_op_type)
597 case NHRP_RESOLUTION_REQ:
598 case NHRP_RESOLUTION_REPLY:
599 proto_tree_add_boolean(flag_tree, hf_nhrp_flag_Q, tvb, offset, 2, flags);
600 proto_tree_add_boolean(flag_tree, hf_nhrp_flag_A, tvb, offset, 2, flags);
601 proto_tree_add_boolean(flag_tree, hf_nhrp_flag_D, tvb, offset, 2, flags);
602 proto_tree_add_boolean(flag_tree, hf_nhrp_flag_U1, tvb, offset, 2, flags);
603 proto_tree_add_boolean(flag_tree, hf_nhrp_flag_S, tvb, offset, 2, flags);
605 case NHRP_REGISTRATION_REQ:
606 case NHRP_REGISTRATION_REPLY:
607 proto_tree_add_boolean(flag_tree, hf_nhrp_flag_U2, tvb, offset, 2, flags);
611 case NHRP_PURGE_REPLY:
612 proto_tree_add_boolean(flag_tree, hf_nhrp_flag_N, tvb, offset, 2, flags);
615 proto_tree_add_boolean(flag_tree, hf_nhrp_flag_NAT, tvb, offset, 2, flags);
619 proto_tree_add_item(nhrp_tree, hf_nhrp_request_id, tvb, offset, 4, FALSE);
626 err_code = tvb_get_ntohs(tvb, offset);
627 proto_tree_add_text(tree, tvb, offset, 2, "Error Code: %s",
628 val_to_str(err_code, nhrp_error_code_vals, "Unknown (%u)"));
631 proto_tree_add_item(nhrp_tree, hf_nhrp_error_offset, tvb, offset, 2, FALSE);
638 shl = NHRP_SHTL_LEN(hdr->ar_shtl);
640 switch (hdr->ar_afn) {
644 proto_tree_add_item(nhrp_tree, hf_nhrp_src_nbma_addr, tvb, offset, 4, FALSE);
646 proto_tree_add_text(nhrp_tree, tvb, offset, shl,
647 "Source NBMA Address: %s",
648 tvb_bytes_to_str(tvb, offset, shl));
653 proto_tree_add_text(nhrp_tree, tvb, offset, shl,
654 "Source NBMA Address: %s",
655 tvb_bytes_to_str(tvb, offset, shl));
661 ssl = NHRP_SHTL_LEN(hdr->ar_sstl);
663 proto_tree_add_text(nhrp_tree, tvb, offset, ssl,
664 "Source NBMA Sub Address: %s",
665 tvb_bytes_to_str(tvb, offset, ssl));
671 proto_tree_add_item(nhrp_tree, hf_nhrp_src_prot_addr, tvb, offset, 4, FALSE);
673 proto_tree_add_text(nhrp_tree, tvb, offset, srcLen,
674 "Source Protocol Address: %s",
675 tvb_bytes_to_str(tvb, offset, srcLen));
682 proto_tree_add_item(nhrp_tree, hf_nhrp_dst_prot_addr, tvb, offset, 4, FALSE);
684 proto_tree_add_text(nhrp_tree, tvb, offset, dstLen,
685 "Destination Protocol Address: %s",
686 tvb_bytes_to_str(tvb, offset, dstLen));
692 gboolean save_in_error_pkt;
693 gint pkt_len = mandEnd - offset;
694 proto_item *ind_tree_item = proto_tree_add_text(tree, tvb, offset, pkt_len, "Packet Causing Indication");
695 proto_tree *ind_tree = proto_item_add_subtree(ind_tree_item, ett_nhrp_indication);
699 save_in_error_pkt = pinfo->in_error_pkt;
700 pinfo->in_error_pkt = TRUE;
701 sub_tvb = tvb_new_subset(tvb, offset, -1, -1);
703 dissect_nhrp(sub_tvb, pinfo, ind_tree);
706 if (hdr->ar_pro_type <= 0xFF) {
708 if (hdr->ar_pro_type == NLPID_SNAP) {
710 * Dissect based on the SNAP OUI
713 if (hdr->ar_pro_type_oui == 0x000000) {
715 * "Should not happen", as
716 * the protocol type should
717 * be the Ethertype, but....
719 dissected = dissector_try_port(
720 ethertype_subdissector_table,
721 hdr->ar_pro_type_pid,
722 sub_tvb, pinfo, ind_tree);
725 * If we have a dissector
726 * table, use it, otherwise
727 * just dissect as data.
729 if (oui_info != NULL) {
730 dissected = dissector_try_port(
732 hdr->ar_pro_type_pid,
740 * Dissect based on the NLPID.
742 dissected = dissector_try_port(
743 osinl_subdissector_table,
744 hdr->ar_pro_type, sub_tvb, pinfo,
747 osinl_excl_subdissector_table,
748 hdr->ar_pro_type, sub_tvb, pinfo,
751 } else if (hdr->ar_pro_type <= 0x3FF) {
752 /* Reserved for future use by the IETF */
754 } else if (hdr->ar_pro_type <= 0x04FF) {
755 /* Allocated for use by the ATM Forum */
757 } else if (hdr->ar_pro_type <= 0x05FF) {
758 /* Experimental/Local use */
761 dissected = dissector_try_port(
762 ethertype_subdissector_table,
763 hdr->ar_pro_type, sub_tvb, pinfo, ind_tree);
766 call_dissector(data_handle, sub_tvb, pinfo,
770 pinfo->in_error_pkt = save_in_error_pkt;
774 dissect_cie_list(tvb, nhrp_tree, offset, mandEnd, hdr, isReq);
779 /* TBD : Decode Authentication Extension and Vendor Specific Extension */
780 void dissect_nhrp_ext(tvbuff_t *tvb,
786 gint offset = *pOffset;
787 gint extEnd = offset + extLen;
789 proto_item *nhrp_tree_item = NULL;
790 proto_tree *nhrp_tree = NULL;
792 tvb_ensure_bytes_exist(tvb, offset, extLen);
794 while ((offset + 4) <= extEnd)
796 gint extTypeC = tvb_get_ntohs(tvb, offset);
797 gint extType = extTypeC & 0x3FFF;
798 gint len = tvb_get_ntohs(tvb, offset+2);
799 nhrp_tree_item = proto_tree_add_text(tree, tvb, offset,
801 val_to_str(extType, ext_type_vals, "Unknown (%u)"));
802 nhrp_tree = proto_item_add_subtree(nhrp_tree_item, ett_nhrp_ext);
803 proto_tree_add_boolean(nhrp_tree, hf_nhrp_ext_C, tvb, offset, 2, extTypeC);
804 proto_tree_add_item(nhrp_tree, hf_nhrp_ext_type, tvb, offset, 2, FALSE);
807 proto_tree_add_item(nhrp_tree, hf_nhrp_ext_len, tvb, offset, 2, FALSE);
811 tvb_ensure_bytes_exist(tvb, offset, len);
813 case NHRP_EXT_RESP_ADDR:
814 case NHRP_EXT_FWD_RECORD:
815 case NHRP_EXT_REV_RECORD:
816 case NHRP_EXT_NAT_ADDRESS:
817 dissect_cie_list(tvb, nhrp_tree,
818 offset, offset + len, hdr, 0);
821 proto_tree_add_text(nhrp_tree, tvb, offset, len,
822 "Extension Value: %s",
823 tvb_bytes_to_str(tvb, offset, len));
833 void dissect_nhrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
839 proto_item *ti = NULL;
840 proto_tree *nhrp_tree = NULL;
841 oui_info_t *oui_info;
843 if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
844 col_set_str(pinfo->cinfo, COL_PROTOCOL, "NHRP");
846 if (check_col(pinfo->cinfo, COL_INFO)) {
847 col_clear(pinfo->cinfo, COL_INFO);
850 memset(&hdr, 0, sizeof(e_nhrp_hdr));
852 hdr.ar_op_type = tvb_get_guint8(tvb, 17);
854 if (check_col(pinfo->cinfo, COL_INFO)) {
855 col_add_str(pinfo->cinfo, COL_INFO,
856 val_to_str(hdr.ar_op_type, nhrp_op_type_vals,
857 "0x%02X - unknown"));
859 col_set_writable(pinfo->cinfo, FALSE);
861 ti = proto_tree_add_protocol_format(tree, proto_nhrp, tvb, 0, -1,
862 "Next Hop Resolution Protocol (%s)",
863 val_to_str(hdr.ar_op_type, nhrp_op_type_vals, "0x%02X - unknown"));
864 nhrp_tree = proto_item_add_subtree(ti, ett_nhrp);
866 dissect_nhrp_hdr(tvb, pinfo, nhrp_tree, &offset, &mandLen, &extLen,
869 dissect_nhrp_mand(tvb, pinfo, nhrp_tree, &offset, mandLen,
874 dissect_nhrp_ext(tvb, nhrp_tree, &offset, extLen, &hdr);
879 proto_register_nhrp(void)
881 static hf_register_info hf[] = {
884 { "Address Family Number", "nhrp.hdr.afn", FT_UINT16, BASE_HEX_DEC, VALS(afn_vals), 0x0, NULL, HFILL }},
885 { &hf_nhrp_hdr_pro_type,
886 { "Protocol Type (short form)", "nhrp.hdr.pro.type",FT_UINT16, BASE_HEX_DEC, NULL, 0x0, NULL, HFILL }},
887 { &hf_nhrp_hdr_pro_snap_oui,
888 { "Protocol Type (long form) - OUI", "nhrp.hdr.pro.snap.oui",FT_UINT24, BASE_HEX, VALS(oui_vals), 0x0, NULL, HFILL }},
889 { &hf_nhrp_hdr_pro_snap_pid,
890 { "Protocol Type (long form) - PID", "nhrp.hdr.pro.snap.pid",FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
891 { &hf_nhrp_hdr_hopcnt,
892 { "Hop Count", "nhrp.hdr.hopcnt", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
893 { &hf_nhrp_hdr_pktsz,
894 { "Packet Length", "nhrp.hdr.pktsz", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
895 { &hf_nhrp_hdr_chksum,
896 { "Packet Checksum", "nhrp.hdr.chksum", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
897 { &hf_nhrp_hdr_extoff,
898 { "Extension Offset", "nhrp.hdr.extoff", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
899 { &hf_nhrp_hdr_version,
900 { "Version", "nhrp.hdr.version", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
901 { &hf_nhrp_hdr_op_type,
902 { "NHRP Packet Type", "nhrp.hdr.op.type", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
904 { "Source Address Type/Len", "nhrp.hdr.shtl", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
905 { &hf_nhrp_hdr_shtl_type,
906 { "Type", "nhrp.hdr.shtl.type", FT_UINT8, BASE_DEC, VALS(nhrp_shtl_type_vals), NHRP_SHTL_TYPE_MASK, NULL, HFILL }},
907 { &hf_nhrp_hdr_shtl_len,
908 { "Length", "nhrp.hdr.shtl.len", FT_UINT8, BASE_DEC, NULL, NHRP_SHTL_LEN_MASK, NULL, HFILL }},
910 { "Source SubAddress Type/Len", "nhrp.hdr.sstl", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
911 { &hf_nhrp_hdr_sstl_type,
912 { "Type", "nhrp.hdr.sstl.type", FT_UINT8, BASE_DEC, VALS(nhrp_shtl_type_vals), NHRP_SHTL_TYPE_MASK, NULL, HFILL }},
913 { &hf_nhrp_hdr_sstl_len,
914 { "Length", "nhrp.hdr.sstl.len", FT_UINT8, BASE_DEC, NULL, NHRP_SHTL_LEN_MASK, NULL, HFILL }},
916 { &hf_nhrp_src_proto_len,
917 { "Source Protocol Len", "nhrp.src.prot.len",FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
918 { &hf_nhrp_dst_proto_len,
919 { "Destination Protocol Len", "nhrp.dst.prot.len",FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
921 { "Flags", "nhrp.flags", FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
923 { "Is Router", "nhrp.flag.q", FT_BOOLEAN, 16, NULL, 0x8000, NULL, HFILL }},
925 { "Expected Purge Reply", "nhrp.flag.n", FT_BOOLEAN, 16, NULL, 0x8000, NULL, HFILL }},
927 { "Authoritative", "nhrp.flag.a", FT_BOOLEAN, 16, NULL, 0x4000, "A bit", HFILL }},
929 { "Stable Association", "nhrp.flag.d", FT_BOOLEAN, 16, NULL, 0x2000, "D bit", HFILL }},
931 { "Uniqueness Bit", "nhrp.flag.u1", FT_BOOLEAN, 16, NULL, 0x1000, "U bit", HFILL }},
933 { "Uniqueness Bit", "nhrp.flag.u1", FT_BOOLEAN, 16, NULL, 0x8000, "U bit", HFILL }},
935 { "Stable Binding", "nhrp.flag.s", FT_BOOLEAN, 16, NULL, 0x0800, "S bit", HFILL }},
937 { "Cisco NAT Supported", "nhrp.flag.nat", FT_BOOLEAN, 16, NULL, 0x0002, "NAT bit", HFILL }},
938 { &hf_nhrp_request_id,
939 { "Request ID", "nhrp.reqid", FT_UINT32, BASE_HEX_DEC, NULL, 0x0, NULL, HFILL }},
940 { &hf_nhrp_src_nbma_addr,
941 { "Source NBMA Address", "nhrp.src.nbma.addr",FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
942 { &hf_nhrp_src_nbma_saddr,
943 { "Source NBMA Sub Address", "nhrp.src.nbma.saddr",FT_UINT_BYTES,BASE_HEX, NULL, 0x0, NULL, HFILL }},
944 { &hf_nhrp_src_prot_addr,
945 { "Source Protocol Address", "nhrp.src.prot.addr",FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
946 { &hf_nhrp_dst_prot_addr,
947 { "Destination Protocol Address", "nhrp.dst.prot.addr",FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
950 { "Code", "nhrp.code", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
951 { &hf_nhrp_prefix_len,
952 { "Prefix Length", "nhrp.prefix", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
954 { "Unused", "nhrp.unused", FT_UINT16,BASE_DEC, NULL, 0x0, NULL, HFILL }},
956 { "Max Transmission Unit", "nhrp.mtu", FT_UINT16,BASE_DEC, NULL, 0x0, NULL, HFILL }},
957 { &hf_nhrp_holding_time,
958 { "Holding Time (s)", "nhrp.htime", FT_UINT16,BASE_DEC, NULL, 0x0, NULL, HFILL }},
959 { &hf_nhrp_cli_addr_tl,
960 { "Client Address Type/Len", "nhrp.cli.addr_tl", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
961 { &hf_nhrp_cli_addr_tl_type,
962 { "Type", "nhrp.cli.addr_tl.type", FT_UINT8, BASE_DEC, VALS(nhrp_shtl_type_vals), NHRP_SHTL_TYPE_MASK, NULL, HFILL }},
963 { &hf_nhrp_cli_addr_tl_len,
964 { "Length", "nhrp.cli.addr_tl.len", FT_UINT8, BASE_DEC, NULL, NHRP_SHTL_LEN_MASK, NULL, HFILL }},
965 { &hf_nhrp_cli_saddr_tl,
966 { "Client Sub Address Type/Len","nhrp.cli.saddr_tl", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
967 { &hf_nhrp_cli_saddr_tl_type,
968 { "Type", "nhrp.cli.saddr_tl.type", FT_UINT8, BASE_DEC, VALS(nhrp_shtl_type_vals), NHRP_SHTL_TYPE_MASK, NULL, HFILL }},
969 { &hf_nhrp_cli_saddr_tl_len,
970 { "Length", "nhrp.cli.saddr_tl.len", FT_UINT8, BASE_DEC, NULL, NHRP_SHTL_LEN_MASK, NULL, HFILL }},
971 { &hf_nhrp_cli_prot_len,
972 { "Client Protocol Length", "nhrp.prot.len", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
974 { "CIE Preference Value", "nhrp.pref", FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }},
975 { &hf_nhrp_client_nbma_addr,
976 { "Client NBMA Address", "nhrp.client.nbma.addr", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
977 { &hf_nhrp_client_nbma_saddr,
978 { "Client NBMA Sub Address", "nhrp.client.nbma.saddr",FT_UINT_BYTES, BASE_HEX, NULL, 0x0, NULL, HFILL }},
979 { &hf_nhrp_client_prot_addr,
980 { "Client Protocol Address", "nhrp.client.prot.addr", FT_IPv4, BASE_NONE, NULL, 0x0, NULL, HFILL }},
983 { "Compulsory Flag", "nhrp.ext.c", FT_BOOLEAN, 16, NULL, 0x8000, NULL, HFILL }},
985 { "Extension Type", "nhrp.ext.type", FT_UINT16, BASE_HEX, NULL, 0x3FFF, NULL, HFILL }},
987 { "Extension length", "nhrp.ext.len", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
988 { &hf_nhrp_ext_value,
989 { "Extension Value", "nhrp.ext.val", FT_UINT_BYTES,BASE_HEX, NULL, 0x0, NULL, HFILL }},
991 { &hf_nhrp_error_offset,
992 { "Error Offset", "nhrp.err.offset", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL }},
993 { &hf_nhrp_error_packet,
994 { "Errored Packet", "nhrp.err.pkt", FT_UINT_BYTES,BASE_HEX, NULL, 0x0, NULL, HFILL }},
997 static gint *ett[] = {
1004 &ett_nhrp_mand_flag,
1006 &ett_nhrp_cie_cli_addr_tl,
1007 &ett_nhrp_cie_cli_saddr_tl,
1008 &ett_nhrp_indication
1011 proto_nhrp = proto_register_protocol(
1012 "NBMA Next Hop Resolution Protocol",
1015 proto_register_field_array(proto_nhrp, hf, array_length(hf));
1016 proto_register_subtree_array(ett, array_length(ett));
1020 proto_reg_handoff_nhrp(void)
1022 dissector_handle_t nhrp_handle;
1024 data_handle = find_dissector("data");
1026 osinl_subdissector_table = find_dissector_table("osinl");
1027 osinl_excl_subdissector_table = find_dissector_table("osinl.excl");
1028 ethertype_subdissector_table = find_dissector_table("ethertype");
1030 nhrp_handle = create_dissector_handle(dissect_nhrp, proto_nhrp);
1031 dissector_add("ip.proto", IP_PROTO_NARP, nhrp_handle);
1032 dissector_add("gre.proto", GRE_NHRP, nhrp_handle);
1033 dissector_add("llc.iana_pid", IANA_PID_MARS_NHRP_CONTROL, nhrp_handle);