From Kovarththanan Rajaratnam via bug 3548:
[obnox/wireshark/wip.git] / epan / dissectors / packet-nhrp.c
1 /* packet-nhrp.c
2  * Routines for NBMA Next Hop Resolution Protocol
3  * RFC 2332 plus Cisco extensions (documented where?)
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
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.
15  *
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.
20  *
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.
24  *
25  * CIE decoding for extensions and Cisco 12.4T extensions
26  * added by Timo Teras <timo.teras@iki.fi>
27  */
28
29 #ifdef HAVE_CONFIG_H
30 # include "config.h"
31 #endif
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <ctype.h>
37 #include <glib.h>
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>
45 #include <epan/oui.h>
46 #include <epan/sminmpec.h>
47 #include <epan/afn.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"
52
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);
57
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;
75
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;
92
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;
115
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;
127
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
137
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 */
146
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
157
158 /* NHRP CIE codes */
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
165
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))
171
172 #define NHRP_SHTL_TYPE_NSAP     0
173 #define NHRP_SHTL_TYPE_E164     1
174
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" },
178         { 0, NULL }
179 };
180
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" },
190         { 0,                                            NULL }
191 };
192
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" },
201         { 0,                                            NULL }
202 };
203
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" },
214         { 0,                                                            NULL }
215 };
216
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" },
224         { 0,                                                            NULL }
225 };
226
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;
230
231 static dissector_handle_t data_handle;
232
233 typedef struct _e_nhrp {
234         guint16 ar_afn;
235         guint16 ar_pro_type;
236         guint32 ar_pro_type_oui;
237         guint16 ar_pro_type_pid;
238         guint8  ar_hopCnt;
239         guint16 ar_pktsz;
240         guint16 ar_chksum;
241         guint16 ar_extoff;
242         guint8  ar_op_version;
243         guint8  ar_op_type;
244         guint8  ar_shtl;
245         guint8  ar_sstl;
246 } e_nhrp_hdr;
247
248 static guint16 nhrp_checksum(const guint8 *ptr, int len)
249 {
250         vec_t cksum_vec[1];
251
252         cksum_vec[0].ptr = ptr;
253         cksum_vec[0].len = len;
254         return in_cksum(&cksum_vec[0], 1);
255 }
256
257 void dissect_nhrp_hdr(tvbuff_t *tvb,
258                                           packet_info *pinfo,
259                                           proto_tree *tree,
260                                           gint *pOffset,
261                                           gint *pMandLen,
262                                           gint *pExtLen,
263                                           oui_info_t **pOuiInfo,
264                                           e_nhrp_hdr *hdr)
265 {
266         gint    offset = *pOffset;
267         const gchar *pro_type_str;
268         guint   total_len = tvb_reported_length(tvb);
269         guint16 ipcsum, rx_chksum;
270         
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;
277         proto_item *ti;
278
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);
281
282         hdr->ar_pktsz = tvb_get_ntohs(tvb, 10);
283         if (total_len > hdr->ar_pktsz) {
284                 total_len = hdr->ar_pktsz;
285         }
286
287         hdr->ar_afn = tvb_get_ntohs(tvb, offset);
288         proto_tree_add_item(nhrp_tree, hf_nhrp_hdr_afn, tvb, offset, 2, FALSE);
289         offset += 2;
290
291         hdr->ar_pro_type = tvb_get_ntohs(tvb, offset);
292         if (hdr->ar_pro_type <= 0xFF) {
293                 /* It's an NLPID */
294                 pro_type_str = val_to_str(hdr->ar_pro_type, nlpid_vals,
295                     "Unknown NLPID");
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";
305         } else {
306                 pro_type_str = val_to_str(hdr->ar_pro_type, etype_vals,
307                     "Unknown Ethertype");
308         }
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);
312         offset += 2;
313
314         if (hdr->ar_pro_type == NLPID_SNAP) {
315                 /*
316                  * The long form protocol type is a SNAP OUI and PID.
317                  */
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);
321                 offset += 3;
322
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);
329                 } else {
330                         proto_tree_add_uint(nhrp_tree, hf_nhrp_hdr_pro_snap_pid,
331                             tvb, offset, 2, hdr->ar_pro_type_pid);
332                 }
333         } else {
334                 /*
335                  * XXX - we should check that this is zero, as RFC 2332
336                  * says it should be zero.
337                  */
338                 proto_tree_add_text(nhrp_tree, tvb, offset, 5,
339                                                 "Protocol Type (long form): %s",
340                                                 tvb_bytes_to_str(tvb, offset, 5));
341                 offset += 5;
342         }
343
344         proto_tree_add_item(nhrp_tree, hf_nhrp_hdr_hopcnt, tvb, offset, 1, FALSE);
345         offset += 1;
346
347         proto_tree_add_item(nhrp_tree, hf_nhrp_hdr_pktsz, tvb, offset, 2, FALSE);
348         offset += 2;
349
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),
353                     total_len);
354                 if (ipcsum == 0) {
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);
357                 } else {
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));
361                 }
362         } else {
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);
365         }
366         offset += 2;
367
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");
373         }
374         offset += 2;
375
376         hdr->ar_op_version = tvb_get_guint8(tvb, offset);
377         proto_tree_add_text(nhrp_tree, tvb, offset, 1, "Version : %u (%s)",
378                                                 hdr->ar_op_version,
379                                                 (hdr->ar_op_version == 1) ? "NHRP - rfc2332" : "Unknown");
380         offset += 1;
381
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)")) ;
384         offset += 1;
385
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);
394         offset += 1;
395         
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);
404         offset += 1;
405         
406         *pOffset = offset;
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;
411                 } else {
412                         /* Error */
413                         *pMandLen = 0;
414                         *pExtLen = 0;
415                 }
416         }
417         else {
418                 if (total_len >= 20)
419                         *pMandLen = total_len - 20;
420                 else {
421                         /* "Can't happen" - we would have thrown an exception */
422                         *pMandLen = 0;
423                 }
424                 *pExtLen = 0;
425         }
426 }
427
428 void dissect_cie_list(tvbuff_t *tvb,
429                                           proto_tree *tree,
430                                           gint offset,
431                                           gint cieEnd,
432                                           e_nhrp_hdr *hdr,
433                                           gint isReq)
434 {
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;
439         guint8 val;
440
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);
448
449                 if (isReq) {
450                         proto_tree_add_item(cie_tree, hf_nhrp_code, tvb, offset, 1, FALSE);
451                 }
452                 else {
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)"));
456                 }
457                 offset += 1;
458                 
459                 proto_tree_add_item(cie_tree, hf_nhrp_prefix_len, tvb, offset, 1, FALSE);
460                 offset += 1;
461
462                 proto_tree_add_item(cie_tree, hf_nhrp_unused, tvb, offset, 2, FALSE);
463                 offset += 2;
464
465                 proto_tree_add_item(cie_tree, hf_nhrp_mtu, tvb, offset, 2, FALSE);
466                 offset += 2;
467
468                 proto_tree_add_item(cie_tree, hf_nhrp_holding_time, tvb, offset, 2, FALSE);
469                 offset += 2;
470
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"),
476                         NHRP_SHTL_LEN(val));
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);
480                 offset += 1;
481
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"),
487                         NHRP_SHTL_LEN(val));
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);
491                 offset += 1;
492
493                 proto_tree_add_item(cie_tree, hf_nhrp_cli_prot_len, tvb, offset, 1, FALSE);
494                 offset += 1;
495
496                 proto_tree_add_item(cie_tree, hf_nhrp_pref, tvb, offset, 1, FALSE);
497                 offset += 1;
498
499                 if (cli_addr_len) {
500                         switch (hdr->ar_afn) {
501
502                         case AFNUM_INET:
503                                 if (cli_addr_len == 4)
504                                         proto_tree_add_item(cie_tree, hf_nhrp_client_nbma_addr, tvb, offset, 4, FALSE);
505                                 else {
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));
509                                 }
510                                 break;
511
512                         default:
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));
516                                 break;
517                         }
518                         offset += cli_addr_len;
519                 }
520                 
521                 if (cli_saddr_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));
525                 }
526
527                 if (cli_prot_len) {
528                         if (cli_prot_len == 4)
529                                 proto_tree_add_ipv4(cie_tree, hf_nhrp_client_prot_addr, tvb, offset, 4, FALSE);
530                         else {
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));
534                         }
535                         offset += cli_prot_len;
536                 }
537         }
538 }
539
540 void dissect_nhrp_mand(tvbuff_t *tvb,
541                                            packet_info *pinfo,
542                                            proto_tree *tree,
543                                            gint *pOffset,
544                                            gint mandLen,
545                                            oui_info_t *oui_info,
546                                            e_nhrp_hdr *hdr)
547 {
548         gint    offset = *pOffset;
549         gint    mandEnd = offset + mandLen;
550         guint8  ssl, shl;
551         guint16 flags;
552         guint   srcLen, dstLen;
553         gboolean isReq = 0;
554         gboolean isErr = 0;
555         gboolean isInd = 0;
556         
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;
561
562         tvb_ensure_bytes_exist(tvb, offset, mandLen);
563
564         switch (hdr->ar_op_type)
565         {
566         case NHRP_RESOLUTION_REQ:
567         case NHRP_REGISTRATION_REQ:
568         case NHRP_PURGE_REQ:
569                 isReq = 1;
570                 break;
571         case NHRP_ERROR_INDICATION:     /* This needs special treatment */
572                 isErr = 1;
573                 isInd = 1;
574                 break;
575         case NHRP_TRAFFIC_INDICATION:
576                 isInd = 1;
577                 break;
578         }
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);
581
582         srcLen = tvb_get_guint8(tvb, offset);
583         proto_tree_add_item(nhrp_tree, hf_nhrp_src_proto_len, tvb, offset, 1, FALSE);
584         offset += 1;
585         
586         dstLen = tvb_get_guint8(tvb, offset);
587         proto_tree_add_item(nhrp_tree, hf_nhrp_dst_proto_len, tvb, offset, 1, FALSE);
588         offset += 1;
589
590         if (!isInd) {
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);
594
595                 switch (hdr->ar_op_type)
596                 {
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);
604                         break;
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);
608                         break;
609                         
610                 case NHRP_PURGE_REQ:
611                 case NHRP_PURGE_REPLY:
612                         proto_tree_add_boolean(flag_tree, hf_nhrp_flag_N, tvb, offset, 2, flags);
613                         break;
614                 }
615                 proto_tree_add_boolean(flag_tree, hf_nhrp_flag_NAT, tvb, offset, 2, flags);
616
617                 offset += 2;
618
619                 proto_tree_add_item(nhrp_tree, hf_nhrp_request_id, tvb, offset, 4, FALSE);
620                 offset += 4;
621         }
622         else if (isErr) {
623                 guint16 err_code;
624                 offset += 2;
625                 
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)"));
629                 offset += 2;
630                 
631                 proto_tree_add_item(nhrp_tree, hf_nhrp_error_offset, tvb, offset, 2, FALSE);
632                 offset += 2;
633         }
634         else {
635                 offset += 6;
636         }
637
638         shl = NHRP_SHTL_LEN(hdr->ar_shtl);
639         if (shl) {
640                 switch (hdr->ar_afn) {
641
642                 case AFNUM_INET:
643                         if (shl == 4)
644                                 proto_tree_add_item(nhrp_tree, hf_nhrp_src_nbma_addr, tvb, offset, 4, FALSE);
645                         else {
646                                 proto_tree_add_text(nhrp_tree, tvb, offset, shl,
647                                     "Source NBMA Address: %s",
648                                     tvb_bytes_to_str(tvb, offset, shl));
649                         }
650                         break;
651
652                 default:
653                         proto_tree_add_text(nhrp_tree, tvb, offset, shl,
654                             "Source NBMA Address: %s",
655                             tvb_bytes_to_str(tvb, offset, shl));
656                         break;
657                 }
658                 offset += shl;
659         }
660         
661         ssl = NHRP_SHTL_LEN(hdr->ar_sstl);
662         if (ssl) {
663                 proto_tree_add_text(nhrp_tree, tvb, offset, ssl,
664                                                         "Source NBMA Sub Address: %s",
665                                                         tvb_bytes_to_str(tvb, offset, ssl));
666                 offset += ssl;
667         }
668
669         if (srcLen) {
670                 if (srcLen == 4)
671                         proto_tree_add_item(nhrp_tree, hf_nhrp_src_prot_addr, tvb, offset, 4, FALSE);
672                 else {
673                         proto_tree_add_text(nhrp_tree, tvb, offset, srcLen,
674                                                                 "Source Protocol Address: %s",
675                                                                 tvb_bytes_to_str(tvb, offset, srcLen));
676                 }
677                 offset += srcLen;
678         }
679
680         if (dstLen) {
681                 if (dstLen == 4)
682                         proto_tree_add_item(nhrp_tree, hf_nhrp_dst_prot_addr, tvb, offset, 4, FALSE);
683                 else {
684                         proto_tree_add_text(nhrp_tree, tvb, offset, dstLen,
685                                                                 "Destination Protocol Address: %s",
686                                                                 tvb_bytes_to_str(tvb, offset, dstLen));
687                 }
688                 offset += dstLen;
689         }
690
691         if (isInd) {
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);
696                 gboolean dissected;
697                 tvbuff_t *sub_tvb;
698
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);
702                 if (isErr) {
703                         dissect_nhrp(sub_tvb, pinfo, ind_tree);
704                 }
705                 else {
706                         if (hdr->ar_pro_type <= 0xFF) {
707                                 /* It's an NLPID */
708                                 if (hdr->ar_pro_type == NLPID_SNAP) {
709                                         /*
710                                          * Dissect based on the SNAP OUI
711                                          * and PID.
712                                          */
713                                         if (hdr->ar_pro_type_oui == 0x000000) {
714                                                 /*
715                                                  * "Should not happen", as
716                                                  * the protocol type should
717                                                  * be the Ethertype, but....
718                                                  */
719                                                 dissected = dissector_try_port(
720                                                     ethertype_subdissector_table,
721                                                     hdr->ar_pro_type_pid,
722                                                     sub_tvb, pinfo, ind_tree);
723                                         } else {
724                                                 /*
725                                                  * If we have a dissector
726                                                  * table, use it, otherwise
727                                                  * just dissect as data.
728                                                  */
729                                                 if (oui_info != NULL) {
730                                                         dissected = dissector_try_port(
731                                                             oui_info->table,
732                                                             hdr->ar_pro_type_pid,
733                                                             sub_tvb, pinfo,
734                                                             ind_tree);
735                                                 } else
736                                                         dissected = FALSE;
737                                         }
738                                 } else {
739                                         /*
740                                          * Dissect based on the NLPID.
741                                          */
742                                         dissected = dissector_try_port(
743                                             osinl_subdissector_table,
744                                             hdr->ar_pro_type, sub_tvb, pinfo,
745                                             ind_tree) ||
746                                                     dissector_try_port(
747                                             osinl_excl_subdissector_table,
748                                             hdr->ar_pro_type, sub_tvb, pinfo,
749                                             ind_tree);
750                                 }
751                         } else if (hdr->ar_pro_type <= 0x3FF) {
752                                 /* Reserved for future use by the IETF */
753                                 dissected = FALSE;
754                         } else if (hdr->ar_pro_type <= 0x04FF) {
755                                 /* Allocated for use by the ATM Forum */
756                                 dissected = FALSE;
757                         } else if (hdr->ar_pro_type <= 0x05FF) {
758                                 /* Experimental/Local use */
759                                 dissected = FALSE;
760                         } else {
761                                 dissected = dissector_try_port(
762                                     ethertype_subdissector_table,
763                                     hdr->ar_pro_type, sub_tvb, pinfo, ind_tree);
764                         }
765                         if (!dissected) {
766                                 call_dissector(data_handle, sub_tvb, pinfo,
767                                     ind_tree);
768                         }
769                 }
770                 pinfo->in_error_pkt = save_in_error_pkt;
771                 offset = mandEnd;
772         }
773
774         dissect_cie_list(tvb, nhrp_tree, offset, mandEnd, hdr, isReq);
775
776         *pOffset = mandEnd;
777 }
778
779 /* TBD : Decode Authentication Extension and Vendor Specific Extension */
780 void dissect_nhrp_ext(tvbuff_t *tvb,
781                                           proto_tree *tree,
782                                           gint *pOffset,
783                                           gint extLen,
784                                           e_nhrp_hdr *hdr)
785 {
786         gint    offset = *pOffset;
787         gint    extEnd = offset + extLen;
788         
789         proto_item *nhrp_tree_item = NULL;
790         proto_tree *nhrp_tree = NULL;
791         
792         tvb_ensure_bytes_exist(tvb, offset, extLen);
793
794         while ((offset + 4) <= extEnd)
795         {
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,
800                     len + 4, "%s",
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);
805                 offset += 2;
806                 
807                 proto_tree_add_item(nhrp_tree, hf_nhrp_ext_len, tvb, offset, 2, FALSE);
808                 offset += 2;
809
810                 if (len) {
811                         tvb_ensure_bytes_exist(tvb, offset, len);
812                         switch (extType) {
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);
819                                 break;
820                         default:
821                                 proto_tree_add_text(nhrp_tree, tvb, offset, len,
822                                     "Extension Value: %s",
823                                     tvb_bytes_to_str(tvb, offset, len));
824                                 break;
825                         }
826                         offset += len;
827                 }
828         }       
829
830         *pOffset = extEnd;
831 }
832
833 void dissect_nhrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
834 {
835         e_nhrp_hdr hdr;
836         gint mandLen = 0;
837         gint extLen = 0;
838         gint offset = 0;
839         proto_item *ti = NULL;
840         proto_tree *nhrp_tree = NULL;
841         oui_info_t *oui_info;
842                 
843         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
844                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "NHRP");
845         }
846         if (check_col(pinfo->cinfo, COL_INFO)) {
847                 col_clear(pinfo->cinfo, COL_INFO);
848         }
849         
850         memset(&hdr, 0, sizeof(e_nhrp_hdr));
851         
852         hdr.ar_op_type = tvb_get_guint8(tvb, 17);
853         
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"));
858         }
859         col_set_writable(pinfo->cinfo, FALSE);
860
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);
865                 
866         dissect_nhrp_hdr(tvb, pinfo, nhrp_tree, &offset, &mandLen, &extLen,
867             &oui_info, &hdr);
868         if (mandLen) {
869                 dissect_nhrp_mand(tvb, pinfo, nhrp_tree, &offset, mandLen,
870                     oui_info, &hdr);
871         }
872
873         if (extLen) {
874                 dissect_nhrp_ext(tvb, nhrp_tree, &offset, extLen, &hdr);
875         }
876 }
877
878 void
879 proto_register_nhrp(void)
880 {
881         static hf_register_info hf[] = {
882                 
883                 { &hf_nhrp_hdr_afn,
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 }},
903                 { &hf_nhrp_hdr_shtl,
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 }},
909                 { &hf_nhrp_hdr_sstl,
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 }},
915
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 }},
920                 { &hf_nhrp_flags,
921                   { "Flags",                                            "nhrp.flags",           FT_UINT16, BASE_HEX, NULL, 0x0, NULL, HFILL }},
922                 { &hf_nhrp_flag_Q,
923                   { "Is Router",                                        "nhrp.flag.q",          FT_BOOLEAN, 16, NULL, 0x8000, NULL, HFILL }},
924                 { &hf_nhrp_flag_N,
925                   { "Expected Purge Reply",                     "nhrp.flag.n",          FT_BOOLEAN, 16, NULL, 0x8000, NULL, HFILL }},
926                 { &hf_nhrp_flag_A,
927                   { "Authoritative",                            "nhrp.flag.a",          FT_BOOLEAN, 16, NULL, 0x4000, "A bit", HFILL }},
928                 { &hf_nhrp_flag_D,
929                   { "Stable Association",                       "nhrp.flag.d",          FT_BOOLEAN, 16, NULL, 0x2000, "D bit", HFILL }},
930                 { &hf_nhrp_flag_U1,
931                   { "Uniqueness Bit",                           "nhrp.flag.u1",         FT_BOOLEAN, 16, NULL, 0x1000, "U bit", HFILL }},
932                 { &hf_nhrp_flag_U2,
933                   { "Uniqueness Bit",                           "nhrp.flag.u1",         FT_BOOLEAN, 16, NULL, 0x8000, "U bit", HFILL }},
934                 { &hf_nhrp_flag_S,
935                   { "Stable Binding",                           "nhrp.flag.s",          FT_BOOLEAN, 16, NULL, 0x0800, "S bit", HFILL }},
936                 { &hf_nhrp_flag_NAT,
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 }},
948
949                 { &hf_nhrp_code,
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 }},
953                 { &hf_nhrp_unused,
954                   { "Unused",                                   "nhrp.unused",                  FT_UINT16,BASE_DEC, NULL, 0x0, NULL, HFILL }},
955                 { &hf_nhrp_mtu,
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 }},
973                 { &hf_nhrp_pref,
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 }},
981
982                 { &hf_nhrp_ext_C,
983                   { "Compulsory Flag",                  "nhrp.ext.c",                   FT_BOOLEAN, 16, NULL, 0x8000, NULL, HFILL }},
984                 { &hf_nhrp_ext_type,
985                   { "Extension Type",                   "nhrp.ext.type",                FT_UINT16,      BASE_HEX, NULL, 0x3FFF, NULL, HFILL }},
986                 { &hf_nhrp_ext_len,
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 }},
990
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 }},
995         };
996         
997         static gint *ett[] = {
998                 &ett_nhrp,
999                 &ett_nhrp_hdr,
1000                 &ett_nhrp_hdr_shtl,
1001                 &ett_nhrp_hdr_sstl,
1002                 &ett_nhrp_mand,
1003                 &ett_nhrp_ext,
1004                 &ett_nhrp_mand_flag,
1005                 &ett_nhrp_cie,
1006                 &ett_nhrp_cie_cli_addr_tl,
1007                 &ett_nhrp_cie_cli_saddr_tl,
1008                 &ett_nhrp_indication
1009         };
1010         
1011         proto_nhrp = proto_register_protocol(
1012                 "NBMA Next Hop Resolution Protocol",
1013                 "NHRP",
1014                 "nhrp");
1015         proto_register_field_array(proto_nhrp, hf, array_length(hf));
1016         proto_register_subtree_array(ett, array_length(ett));
1017 }
1018
1019 void
1020 proto_reg_handoff_nhrp(void)
1021 {
1022         dissector_handle_t nhrp_handle;
1023
1024         data_handle = find_dissector("data");
1025
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");
1029
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);
1034 }