Switch a bunch of dissectors over to using tvb_new_subset_remaining()
[obnox/wireshark/wip.git] / epan / dissectors / packet-eigrp.c
1 /* packet-eigrp.c
2  * Routines for EIGRP dissection
3  * Copyright 2000, Paul Ionescu <paul@acorp.ro>
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
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <glib.h>
31 #include <epan/packet.h>
32 #include <epan/addr_resolv.h>
33
34 #include <epan/atalk-utils.h>
35 #include <epan/addr_and_mask.h>
36 #include <epan/ipproto.h>
37 #include "packet-ipx.h"
38
39 /*
40  * See
41  *
42  *      http://www.rhyshaden.com/eigrp.htm
43  */
44
45 #define EIGRP_UPDATE    0x01
46 #define EIGRP_REQUEST   0x02
47 #define EIGRP_QUERY     0x03
48 #define EIGRP_REPLY     0x04
49 #define EIGRP_HELLO     0x05
50 #define EIGRP_SAP       0x06
51 #define EIGRP_HI        0x20  /* This value is for my own need to make a difference between Hello and Ack */
52 #define EIGRP_ACK       0x40  /* This value is for my own need to make a difference between Hello and Ack */
53
54 #define TLV_PAR         0x0001
55 #define TLV_AUTH        0x0002
56 #define TLV_SEQ         0x0003
57 #define TLV_SV          0x0004
58 #define TLV_NMS         0x0005
59 #define TLV_IP_INT      0x0102
60 #define TLV_IP_EXT      0x0103
61 #define TLV_AT_INT      0x0202
62 #define TLV_AT_EXT      0x0203
63 #define TLV_AT_CBL      0x0204
64 #define TLV_IPX_INT     0x0302
65 #define TLV_IPX_EXT     0x0303
66
67 #define EIGRP_HEADER_LENGTH     20
68
69 static gint proto_eigrp = -1;
70
71 static gint hf_eigrp_opcode = -1;
72 static gint hf_eigrp_as = -1;
73 static gint hf_eigrp_tlv = -1;
74
75 static gint ett_eigrp = -1;
76 static gint ett_tlv = -1;
77
78 static dissector_handle_t ipxsap_handle;
79
80
81 static const value_string eigrp_opcode_vals[] = {
82         { EIGRP_HELLO,          "Hello/Ack" },
83         { EIGRP_UPDATE,         "Update" },
84         { EIGRP_REPLY,          "Reply" },
85         { EIGRP_QUERY,          "Query" },
86         { EIGRP_REQUEST,        "Request" },
87         { EIGRP_SAP,            "IPX/SAP Update" },
88         { EIGRP_HI,             "Hello" },
89         { EIGRP_ACK,            "Acknowledge" },
90         { 0,                            NULL }
91 };
92
93 static const value_string eigrp_tlv_vals[] = {
94         { TLV_PAR,     "EIGRP Parameters"},
95         { TLV_AUTH,    "Authentication data"},
96         { TLV_SEQ ,    "Sequence"},
97         { TLV_SV,      "Software Version"},
98         { TLV_NMS   ,  "Next multicast sequence"},
99         { TLV_IP_INT,  "IP internal route"},
100         { TLV_IP_EXT,  "IP external route"},
101         { TLV_AT_INT,  "AppleTalk internal route"},
102         { TLV_AT_EXT,  "AppleTalk external route"},
103         { TLV_AT_CBL,  "AppleTalk cable configuration"},
104         { TLV_IPX_INT, "IPX internal route"},
105         { TLV_IPX_EXT, "IPX external route"},
106         { 0,            NULL}
107 };
108
109 static const value_string eigrp_pid_vals[] = {
110         { 1,    "IGRP"},
111         { 2,    "EIGRP"},
112         { 3,    "Static Route"},
113         { 4,    "RIP"},
114         { 5,    "Hello"},
115         { 6,    "OSPF"},
116         { 7,    "IS-IS"},
117         { 8,    "EGP"},
118         { 9,    "BGP"},
119         { 10,   "IDRP"},
120         { 11,   "Connected link"},
121         { 0,    NULL}
122 };
123
124
125 static void dissect_eigrp_par (tvbuff_t *tvb, proto_tree *tree);
126 static void dissect_eigrp_seq (tvbuff_t *tvb, proto_tree *tree);
127 static void dissect_eigrp_sv  (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
128 static void dissect_eigrp_nms (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
129
130 static void dissect_eigrp_ip_int (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
131 static void dissect_eigrp_ip_ext (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
132
133 static void dissect_eigrp_ipx_int (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
134 static void dissect_eigrp_ipx_ext (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
135
136 static void dissect_eigrp_at_cbl (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
137 static void dissect_eigrp_at_int (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
138 static void dissect_eigrp_at_ext (tvbuff_t *tvb, proto_tree *tree, proto_item *ti);
139
140 static void
141 dissect_eigrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
142
143   proto_tree *eigrp_tree,*tlv_tree;
144   proto_item *ti;
145
146   guint opcode,opcode_tmp;
147   guint16 tlv;
148   guint32 ack, size, offset = EIGRP_HEADER_LENGTH;
149
150   col_set_str(pinfo->cinfo, COL_PROTOCOL, "EIGRP");
151   col_clear(pinfo->cinfo, COL_INFO);
152
153   opcode_tmp=opcode=tvb_get_guint8(tvb,1);
154   ack = tvb_get_ntohl(tvb,12);
155   if (opcode==EIGRP_HELLO) { if (ack == 0) opcode_tmp=EIGRP_HI; else opcode_tmp=EIGRP_ACK; }
156
157   if (check_col(pinfo->cinfo, COL_INFO))
158     col_add_str(pinfo->cinfo, COL_INFO,
159         val_to_str(opcode_tmp , eigrp_opcode_vals, "Unknown (0x%04x)"));
160
161
162
163
164   if (tree) {
165
166      ti = proto_tree_add_protocol_format(tree, proto_eigrp, tvb, 0, -1,
167               "Cisco EIGRP");
168
169      eigrp_tree = proto_item_add_subtree(ti, ett_eigrp);
170
171      proto_tree_add_text (eigrp_tree, tvb, 0,1,"Version    = %u",tvb_get_guint8(tvb,0)) ;
172      proto_tree_add_uint_format (eigrp_tree, hf_eigrp_opcode, tvb, 1,1,opcode,"Opcode = %u (%s)",opcode,val_to_str(opcode_tmp,eigrp_opcode_vals, "Unknown")) ;
173      proto_tree_add_text (eigrp_tree, tvb, 2,2,"Checksum   = 0x%04x",tvb_get_ntohs(tvb,2)) ;
174      proto_tree_add_text (eigrp_tree, tvb, 4,4,"Flags      = 0x%08x",tvb_get_ntohl(tvb,4)) ;
175      proto_tree_add_text (eigrp_tree, tvb, 8,4,"Sequence   = %u",tvb_get_ntohl(tvb,8)) ;
176      proto_tree_add_text (eigrp_tree, tvb, 12,4,"Acknowledge  = %u",tvb_get_ntohl(tvb,12)) ;
177      proto_tree_add_uint (eigrp_tree, hf_eigrp_as, tvb, 16,4,tvb_get_ntohl(tvb,16)) ;
178
179      if (opcode==EIGRP_SAP)
180         {
181         call_dissector(ipxsap_handle, tvb_new_subset_remaining(tvb, EIGRP_HEADER_LENGTH), pinfo, eigrp_tree);
182         return;
183         }
184
185      while ( tvb_reported_length_remaining(tvb,offset)>0 ) {
186
187              tlv = tvb_get_ntohs(tvb,offset);
188              size =  tvb_get_ntohs(tvb,offset+2);
189              if ( size == 0 )
190                 {
191                 proto_tree_add_text(eigrp_tree,tvb,offset,-1,"Unknown data (maybe authentication)");
192                 return;
193                 }
194
195              ti = proto_tree_add_text (eigrp_tree, tvb, offset,size,
196                  "%s",val_to_str(tlv, eigrp_tlv_vals, "Unknown (0x%04x)"));
197
198              tlv_tree = proto_item_add_subtree (ti, ett_tlv);
199              proto_tree_add_uint_format (tlv_tree,hf_eigrp_tlv, tvb,offset,2,tlv,"Type = 0x%04x (%s)",tlv,val_to_str(tlv,eigrp_tlv_vals, "Unknown")) ;
200              proto_tree_add_text (tlv_tree,tvb,offset+2,2,"Size = %u bytes",size) ;
201
202
203              switch (tlv){
204                 case TLV_PAR:
205                         dissect_eigrp_par(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree);
206                         break;
207                 case TLV_SEQ:
208                         dissect_eigrp_seq(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree);
209                         break;
210                 case TLV_SV:
211                         dissect_eigrp_sv(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
212                         break;
213                 case TLV_NMS:
214                         dissect_eigrp_nms(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
215                         break;
216
217                 case TLV_IP_INT:
218                         dissect_eigrp_ip_int(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
219                         break;
220                 case TLV_IP_EXT:
221                         dissect_eigrp_ip_ext(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
222                         break;
223
224                 case TLV_IPX_INT:
225                         dissect_eigrp_ipx_int(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
226                         break;
227                 case TLV_IPX_EXT:
228                         dissect_eigrp_ipx_ext(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
229                         break;
230
231                 case TLV_AT_CBL:
232                         dissect_eigrp_at_cbl(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
233                         break;
234                 case TLV_AT_INT:
235                         dissect_eigrp_at_int(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
236                         break;
237                 case TLV_AT_EXT:
238                         dissect_eigrp_at_ext(tvb_new_subset(tvb, offset+4, size-4, -1), tlv_tree, ti);
239                         break;
240                 case TLV_AUTH:
241                         proto_tree_add_text(tlv_tree,tvb,offset+4,size-4,"Authentication data");
242                         break;
243              }
244
245              offset+=size;
246      }
247
248    }
249 }
250
251
252
253 static void dissect_eigrp_par (tvbuff_t *tvb, proto_tree *tree) {
254         proto_tree_add_text (tree,tvb,0,1,"K1 = %u",tvb_get_guint8(tvb,0));
255         proto_tree_add_text (tree,tvb,1,1,"K2 = %u",tvb_get_guint8(tvb,1));
256         proto_tree_add_text (tree,tvb,2,1,"K3 = %u",tvb_get_guint8(tvb,2));
257         proto_tree_add_text (tree,tvb,3,1,"K4 = %u",tvb_get_guint8(tvb,3));
258         proto_tree_add_text (tree,tvb,4,1,"K5 = %u",tvb_get_guint8(tvb,4));
259         proto_tree_add_text (tree,tvb,5,1,"Reserved");
260         proto_tree_add_text (tree,tvb,6,2,"Hold Time = %u",tvb_get_ntohs(tvb,6));
261 }
262
263 static void dissect_eigrp_seq (tvbuff_t *tvb, proto_tree *tree)
264 {       guint8 addr_len;
265         addr_len=tvb_get_guint8(tvb,0);
266         proto_tree_add_text (tree,tvb,0,1,"Address length = %u",addr_len);
267         switch (addr_len){
268                 case 4:
269                         proto_tree_add_text (tree,tvb,1,addr_len,"IP Address = %u.%u.%u.%u",tvb_get_guint8(tvb,1),tvb_get_guint8(tvb,2),tvb_get_guint8(tvb,3),tvb_get_guint8(tvb,4));
270                         break;
271                 case 10:
272                         proto_tree_add_text (tree,tvb,1,addr_len,"IPX Address = %08x.%04x.%04x.%04x",tvb_get_ntohl(tvb,1),tvb_get_ntohs(tvb,5),tvb_get_ntohs(tvb,7),tvb_get_ntohs(tvb,9));
273                         break;
274                 default:
275                         /* nothing */
276                         ;
277                 }
278 }
279
280 static void dissect_eigrp_sv (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
281 {
282         guint8 ios_rel_major, ios_rel_minor;
283         guint8 eigrp_rel_major, eigrp_rel_minor;
284
285         ios_rel_major = tvb_get_guint8(tvb,0);
286         ios_rel_minor = tvb_get_guint8(tvb,1);
287         proto_tree_add_text (tree,tvb,0,2," IOS  release version = %u.%u",
288                              ios_rel_major, ios_rel_minor);
289         proto_item_append_text (ti,": IOS=%u.%u", ios_rel_major, ios_rel_minor);
290
291         eigrp_rel_major = tvb_get_guint8(tvb,2);
292         eigrp_rel_minor = tvb_get_guint8(tvb,3);
293         proto_tree_add_text (tree,tvb,2,2,"EIGRP release version = %u.%u",
294                              eigrp_rel_major, eigrp_rel_minor);
295         proto_item_append_text (ti,", EIGRP=%u.%u",
296                                 eigrp_rel_major, eigrp_rel_minor);
297 }
298
299 static void dissect_eigrp_nms (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
300 {
301         proto_tree_add_text (tree,tvb,0,4,"Next Multicast Sequence = %u",tvb_get_ntohl(tvb,0));
302         proto_item_append_text (ti,": %u",tvb_get_ntohl(tvb,0));
303 }
304
305
306
307 static void dissect_eigrp_ip_int (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
308 {
309         guint8 ip_addr[4],length;
310         int addr_len,offset;
311
312         tvb_memcpy(tvb,ip_addr,0,4);
313         proto_tree_add_text (tree,tvb,0,4, "Next Hop    = %s",ip_to_str(ip_addr));
314         proto_tree_add_text (tree,tvb,4,4, "Delay       = %u",tvb_get_ntohl(tvb,4));
315         proto_tree_add_text (tree,tvb,8,4, "Bandwidth   = %u",tvb_get_ntohl(tvb,8));
316         proto_tree_add_text (tree,tvb,12,3,"MTU         = %u",tvb_get_ntoh24(tvb,12));
317         proto_tree_add_text (tree,tvb,15,1,"Hop Count   = %u",tvb_get_guint8(tvb,15));
318         proto_tree_add_text (tree,tvb,16,1,"Reliability = %u",tvb_get_guint8(tvb,16));
319         proto_tree_add_text (tree,tvb,17,1,"Load        = %u",tvb_get_guint8(tvb,17));
320         proto_tree_add_text (tree,tvb,18,2,"Reserved ");
321
322         for (offset = 20; tvb_length_remaining(tvb, offset) > 0; offset += (1+addr_len))
323         {
324                 length=tvb_get_guint8(tvb,offset);
325                 addr_len=ipv4_addr_and_mask (tvb,offset+1,ip_addr,length);
326                 if (addr_len < 0) {
327                     proto_tree_add_text (tree,tvb,offset,1,"Prefix length = %u (invalid, must be <= 32)",length);
328                     proto_item_append_text (ti,"  [Invalid prefix length %u > 32]",length);
329                     addr_len = 4; /* assure we can exit the loop */
330                 } else {
331                     proto_tree_add_text (tree,tvb,offset,1,"Prefix Length = %u",length);
332                     proto_tree_add_text (tree,tvb,offset+1,addr_len,"Destination = %s",ip_to_str(ip_addr));
333                     proto_item_append_text (ti,"  %c   %s/%u%s",offset==20?'=':',',ip_to_str(ip_addr),length,((tvb_get_ntohl(tvb,4)==0xffffffff)?" - Destination unreachable":""));
334                 }
335         }
336 }
337
338 static void dissect_eigrp_ip_ext (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
339 {
340         guint8 ip_addr[4],length;
341         int addr_len,offset;
342
343         tvb_memcpy(tvb,ip_addr,0,4);
344         proto_tree_add_text (tree,tvb,0,4,"Next Hop = %s",ip_to_str(ip_addr));
345         tvb_memcpy(tvb,ip_addr,4,4);
346         proto_tree_add_text (tree,tvb,4,4,"Originating router = %s",ip_to_str(ip_addr));
347         proto_tree_add_text (tree,tvb,8,4,"Originating A.S. = %u",tvb_get_ntohl(tvb,8));
348         proto_tree_add_text (tree,tvb,12,4,"Arbitrary tag = %u",tvb_get_ntohl(tvb,12));
349         proto_tree_add_text (tree,tvb,16,4,"External protocol metric = %u",tvb_get_ntohl(tvb,16));
350         proto_tree_add_text (tree,tvb,20,2,"Reserved");
351         proto_tree_add_text (tree,tvb,22,1,"External protocol ID = %u (%s)",tvb_get_guint8(tvb,22),val_to_str(tvb_get_guint8(tvb,22),eigrp_pid_vals, "Unknown"));
352         proto_tree_add_text (tree,tvb,23,1,"Flags = 0x%0x",tvb_get_guint8(tvb,23));
353
354         proto_tree_add_text (tree,tvb,24,4,"Delay     = %u",tvb_get_ntohl(tvb,24));
355         proto_tree_add_text (tree,tvb,28,4,"Bandwidth = %u",tvb_get_ntohl(tvb,28));
356         proto_tree_add_text (tree,tvb,32,3,"MTU    = %u",tvb_get_ntoh24(tvb,32));
357         proto_tree_add_text (tree,tvb,35,1,"Hop Count = %u",tvb_get_guint8(tvb,35));
358         proto_tree_add_text (tree,tvb,36,1,"Reliability = %u",tvb_get_guint8(tvb,36));
359         proto_tree_add_text (tree,tvb,37,1,"Load = %u",tvb_get_guint8(tvb,37));
360         proto_tree_add_text (tree,tvb,38,2,"Reserved ");
361
362         for (offset = 40; tvb_length_remaining(tvb, offset) > 0; offset += (1+addr_len))
363         {
364                 length=tvb_get_guint8(tvb,offset);
365                 addr_len=ipv4_addr_and_mask (tvb,offset+1,ip_addr,length);
366                 if (addr_len < 0) {
367                     proto_tree_add_text (tree,tvb,offset,1,"Prefix length = %u (invalid, must be <= 32)",length);
368                     proto_item_append_text (ti,"  [Invalid prefix length %u > 32]",length);
369                     addr_len = 4; /* assure we can exit the loop */
370                 } else {
371                     proto_tree_add_text (tree,tvb,offset,1,"Prefix Length = %u",length);
372                     proto_tree_add_text (tree,tvb,offset+1,addr_len,"Destination = %s",ip_to_str(ip_addr));
373                     proto_item_append_text (ti,"  %c   %s/%u%s",offset==40?'=':',',ip_to_str(ip_addr),length,((tvb_get_ntohl(tvb,24)==0xffffffff)?" - Destination unreachable":""));
374                 }
375         }
376 }
377
378
379
380 static void dissect_eigrp_ipx_int (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
381 {
382         proto_tree_add_text (tree,tvb,0,4,"Next Hop Address = %08x",tvb_get_ntohl(tvb,4));
383         proto_tree_add_text (tree,tvb,4,6,"Next Hop ID      = %04x:%04x:%04x",tvb_get_ntohs(tvb,4),tvb_get_ntohs(tvb,6),tvb_get_ntohs(tvb,8));
384         proto_tree_add_text (tree,tvb,10,4,"Delay     = %u",tvb_get_ntohl(tvb,10));
385         proto_tree_add_text (tree,tvb,14,4,"Bandwidth = %u",tvb_get_ntohl(tvb,14));
386         proto_tree_add_text (tree,tvb,18,3,"MTU    = %u",tvb_get_ntoh24(tvb,18));
387         proto_tree_add_text (tree,tvb,21,1,"Hop Count = %u",tvb_get_guint8(tvb,21));
388         proto_tree_add_text (tree,tvb,22,1,"Reliability = %u",tvb_get_guint8(tvb,22));
389         proto_tree_add_text (tree,tvb,23,1,"Load = %u",tvb_get_guint8(tvb,23));
390         proto_tree_add_text (tree,tvb,24,2,"Reserved ");
391         proto_tree_add_text (tree,tvb,26,4,"Destination Address =  %08x",tvb_get_ntohl(tvb,26));
392         proto_item_append_text (ti,"  =   %08x%s",tvb_get_ntohl(tvb,26),((tvb_get_ntohl(tvb,10)==0xffffffff)?" - Destination unreachable":""));
393 }
394
395 static void dissect_eigrp_ipx_ext (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
396 {
397         proto_tree_add_text (tree,tvb,0,4,"Next Hop Address = %08x",tvb_get_ntohl(tvb,4));
398         proto_tree_add_text (tree,tvb,4,6,"Next Hop ID      = %04x:%04x:%04x",tvb_get_ntohs(tvb,4),tvb_get_ntohs(tvb,6),tvb_get_ntohs(tvb,8));
399
400         proto_tree_add_text (tree,tvb,10,6,"Originating router ID = %04x:%04x:%04x",tvb_get_ntohs(tvb,10),tvb_get_ntohs(tvb,12),tvb_get_ntohs(tvb,14));
401         proto_tree_add_text (tree,tvb,16,4,"Originating A.S. = %u",tvb_get_ntohl(tvb,16));
402         proto_tree_add_text (tree,tvb,20,4,"Arbitrary tag = %u",tvb_get_ntohl(tvb,20));
403         proto_tree_add_text (tree,tvb,24,1,"External protocol  = %u",tvb_get_guint8(tvb,24));
404         proto_tree_add_text (tree,tvb,25,1,"Reserved");
405         proto_tree_add_text (tree,tvb,26,2,"External metric = %u ",tvb_get_ntohs(tvb,26));
406         proto_tree_add_text (tree,tvb,28,2,"External delay  = %u ",tvb_get_ntohs(tvb,28));
407
408         proto_tree_add_text (tree,tvb,30,4,"Delay     = %u",tvb_get_ntohl(tvb,30));
409         proto_tree_add_text (tree,tvb,34,4,"Bandwidth = %u",tvb_get_ntohl(tvb,34));
410         proto_tree_add_text (tree,tvb,38,3,"MTU    = %u",tvb_get_ntoh24(tvb,38));
411         proto_tree_add_text (tree,tvb,41,1,"Hop Count = %u",tvb_get_guint8(tvb,41));
412         proto_tree_add_text (tree,tvb,42,1,"Reliability = %u",tvb_get_guint8(tvb,42));
413         proto_tree_add_text (tree,tvb,43,1,"Load = %u",tvb_get_guint8(tvb,43));
414         proto_tree_add_text (tree,tvb,44,2,"Reserved ");
415         proto_tree_add_text (tree,tvb,46,4,"Destination Address =  %08x",tvb_get_ntohl(tvb,46));
416         proto_item_append_text (ti,"  =   %08x%s",tvb_get_ntohl(tvb,46),((tvb_get_ntohl(tvb,30)==0xffffffff)?" - Destination unreachable":""));
417
418 }
419
420
421
422 static void dissect_eigrp_at_cbl (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
423 {
424         proto_tree_add_text (tree,tvb,0,4,"AppleTalk Cable Range = %u-%u",tvb_get_ntohs(tvb,0),tvb_get_ntohs(tvb,2));
425         proto_tree_add_text (tree,tvb,4,4,"AppleTalk Router ID   = %u",tvb_get_ntohl(tvb,4));
426         proto_item_append_text (ti,": Cable range= %u-%u, Router ID= %u",tvb_get_ntohs(tvb,0),tvb_get_ntohs(tvb,2),tvb_get_ntohl(tvb,4));
427
428 }
429
430 static void dissect_eigrp_at_int (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
431 {
432         proto_tree_add_text (tree,tvb,0,4,"Next Hop Address = %u.%u",tvb_get_ntohs(tvb,0),tvb_get_ntohs(tvb,2));
433
434         proto_tree_add_text (tree,tvb,4,4,"Delay     = %u",tvb_get_ntohl(tvb,4));
435         proto_tree_add_text (tree,tvb,8,4,"Bandwidth = %u",tvb_get_ntohl(tvb,8));
436         proto_tree_add_text (tree,tvb,12,3,"MTU    = %u",tvb_get_ntoh24(tvb,12));
437         proto_tree_add_text (tree,tvb,15,1,"Hop Count = %u",tvb_get_guint8(tvb,15));
438         proto_tree_add_text (tree,tvb,16,1,"Reliability = %u",tvb_get_guint8(tvb,16));
439         proto_tree_add_text (tree,tvb,17,1,"Load = %u",tvb_get_guint8(tvb,17));
440         proto_tree_add_text (tree,tvb,18,2,"Reserved ");
441         proto_tree_add_text (tree,tvb,20,4,"Cable range = %u-%u",tvb_get_ntohs(tvb,20),tvb_get_ntohs(tvb,22));
442
443         proto_item_append_text (ti,": %u-%u",tvb_get_ntohs(tvb,20),tvb_get_ntohs(tvb,22));
444
445 }
446
447 static void dissect_eigrp_at_ext (tvbuff_t *tvb, proto_tree *tree, proto_item *ti)
448 {
449         proto_tree_add_text (tree,tvb,0,4,"Next Hop Address = %u.%u",tvb_get_ntohs(tvb,0),tvb_get_ntohs(tvb,2));
450         proto_tree_add_text (tree,tvb,4,4,"Originating router ID = %u",tvb_get_ntohl(tvb,4));
451         proto_tree_add_text (tree,tvb,8,4,"Originating A.S. = %u",tvb_get_ntohl(tvb,8));
452         proto_tree_add_text (tree,tvb,12,4,"Arbitrary tag = %u",tvb_get_ntohl(tvb,12));
453         proto_tree_add_text (tree,tvb,16,1,"External protocol ID = %u ",tvb_get_guint8(tvb,16));
454         proto_tree_add_text (tree,tvb,17,1,"Flags = 0x%0x",tvb_get_guint8(tvb,17));
455         proto_tree_add_text (tree,tvb,18,2,"External protocol metric = %u",tvb_get_ntohs(tvb,18));
456
457         proto_tree_add_text (tree,tvb,20,4,"Delay     = %u",tvb_get_ntohl(tvb,20));
458         proto_tree_add_text (tree,tvb,24,4,"Bandwidth = %u",tvb_get_ntohl(tvb,24));
459         proto_tree_add_text (tree,tvb,28,3,"MTU    = %u",tvb_get_ntoh24(tvb,28));
460         proto_tree_add_text (tree,tvb,31,1,"Hop Count = %u",tvb_get_guint8(tvb,31));
461         proto_tree_add_text (tree,tvb,32,1,"Reliability = %u",tvb_get_guint8(tvb,32));
462         proto_tree_add_text (tree,tvb,33,1,"Load = %u",tvb_get_guint8(tvb,33));
463         proto_tree_add_text (tree,tvb,34,2,"Reserved ");
464         proto_tree_add_text (tree,tvb,36,4,"Cable range = %u-%u",tvb_get_ntohs(tvb,36),tvb_get_ntohs(tvb,38));
465
466         proto_item_append_text (ti,": %u-%u",tvb_get_ntohs(tvb,36),tvb_get_ntohs(tvb,38));
467 }
468
469
470
471
472 void
473 proto_register_eigrp(void)
474 {
475   static hf_register_info hf[] = {
476    { &hf_eigrp_opcode,
477     { "Opcode", "eigrp.opcode",
478      FT_UINT8, BASE_DEC, NULL, 0x0 ,
479      "Opcode number", HFILL }
480      },
481    { &hf_eigrp_as,
482     { "Autonomous System", "eigrp.as",
483       FT_UINT16, BASE_DEC, NULL, 0x0 ,
484      "Autonomous System number", HFILL }
485     },
486    { &hf_eigrp_tlv,
487     { "Entry",           "eigrp.tlv",
488       FT_UINT16, BASE_DEC, NULL, 0x0 ,
489      "Type/Length/Value", HFILL }
490     },
491    };
492
493    static gint *ett[] = {
494      &ett_eigrp,
495      &ett_tlv,
496    };
497    proto_eigrp = proto_register_protocol("Enhanced Interior Gateway Routing Protocol",
498                                          "EIGRP", "eigrp");
499    proto_register_field_array(proto_eigrp, hf, array_length(hf));
500    proto_register_subtree_array(ett, array_length(ett));
501 }
502
503 void
504 proto_reg_handoff_eigrp(void)
505 {
506     dissector_handle_t eigrp_handle;
507
508     ipxsap_handle = find_dissector("ipxsap");
509     eigrp_handle = create_dissector_handle(dissect_eigrp, proto_eigrp);
510     dissector_add("ip.proto", IP_PROTO_EIGRP, eigrp_handle);
511     dissector_add("ddp.type", DDP_EIGRP, eigrp_handle);
512     dissector_add("ipx.socket", IPX_SOCKET_EIGRP, eigrp_handle);
513 }