Put back an unused variable, as a reminder that the routine it's in
[obnox/wireshark/wip.git] / packet-dvmrp.c
1 /* packet-dvmrp.c   2001 Ronnie Sahlberg <See AUTHORS for email>
2  * Routines for IGMP/DVMRP packet disassembly
3  *
4  * $Id: packet-dvmrp.c,v 1.9 2002/04/02 05:12:12 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  * 
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  * 
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  * 
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24 /*
25
26
27                         DVMRP   DVMRP
28         code            v1      v3
29
30         0x01            *       *
31         0x02            *       *
32         0x03            x
33         0x04            x
34         0x07                    x
35         0x08                    x
36         0x09                    x
37
38
39         * V3 has len>=8 and byte[6]==0xff and byte[7]==0x03
40
41
42         DVMRP is defined in the following RFCs
43         RFC1075 Version 1
44         draft-ietf-idmr-dvmrp-v3-10.txt Version 3
45
46         V1 and V3 can be distinguished by looking at bytes 6 and 7 in the 
47         IGMP/DVMRP header.
48         If header[6]==0xff and header[7]==0x03 we have version 3.
49
50
51         RFC1075 has typos in 3.12.2 and 3.12.4, see if you can spot them.
52 */
53
54 #ifdef HAVE_CONFIG_H
55 # include "config.h"
56 #endif
57
58 #ifdef HAVE_SYS_TYPES_H
59 # include <sys/types.h>
60 #endif
61
62 #include <stdio.h>
63 #include <string.h>
64 #include <glib.h>
65
66 #include <epan/packet.h>
67 #include "ipproto.h"
68 #include "packet-igmp.h"
69 #include "packet-dvmrp.h"
70
71 static int proto_dvmrp = -1;
72 static int hf_version = -1;
73 static int hf_type = -1;
74 static int hf_code_v1 = -1;
75 static int hf_checksum = -1;
76 static int hf_checksum_bad = -1;
77 static int hf_commands = -1;
78 static int hf_command = -1;
79 static int hf_count = -1;
80 static int hf_afi = -1;
81 static int hf_netmask = -1;
82 static int hf_metric = -1;
83 static int hf_dest_unr = -1;
84 static int hf_split_horiz = -1;
85 static int hf_infinity = -1;
86 static int hf_daddr = -1;
87 static int hf_maddr = -1;
88 static int hf_hold = -1;
89 static int hf_code_v3 = -1;
90 static int hf_capabilities = -1;
91 static int hf_cap_leaf = -1;
92 static int hf_cap_prune = -1;
93 static int hf_cap_genid = -1;
94 static int hf_cap_mtrace = -1;
95 static int hf_cap_snmp = -1;
96 static int hf_cap_netmask = -1;
97 static int hf_min_ver = -1;
98 static int hf_maj_ver = -1;
99 static int hf_genid = -1;
100 static int hf_route = -1;
101 static int hf_saddr = -1;
102 static int hf_life = -1;
103 static int hf_neighbor = -1;
104
105 static int ett_dvmrp = -1;
106 static int ett_commands = -1;
107 static int ett_capabilities = -1;
108 static int ett_route = -1;
109
110
111 #define DVMRP_TYPE                              0x13
112 static const value_string dvmrp_type[] = {
113         {DVMRP_TYPE,    "DVMRP" },
114         {0,             NULL}
115 };
116
117 #define DVMRP_V1_RESPONSE                       1
118 #define DVMRP_V1_REQUEST                        2
119 #define DVMRP_V1_NON_MEMBERSHIP_REPORT          3
120 #define DVMRP_V1_NON_MEMBERSHIP_CANCELLATION    4
121 static const value_string code_v1[] = {
122         {DVMRP_V1_RESPONSE,                     "Response"                      },
123         {DVMRP_V1_REQUEST,                      "Request"                       },
124         {DVMRP_V1_NON_MEMBERSHIP_REPORT,        "Non-membership report"         },
125         {DVMRP_V1_NON_MEMBERSHIP_CANCELLATION,  "Non-membership cancellation"   },      
126         {0,                                     NULL}
127 };
128
129 #define DVMRP_V3_PROBE                          0x1
130 #define DVMRP_V3_REPORT                         0x2
131 #define DVMRP_V3_ASK_NEIGHBORS                  0x3
132 #define DVMRP_V3_NEIGHBORS                      0x4
133 #define DVMRP_V3_ASK_NEIGHBORS_2                0x5
134 #define DVMRP_V3_NEIGHBORS_2                    0x6
135 #define DVMRP_V3_PRUNE                          0x7
136 #define DVMRP_V3_GRAFT                          0x8
137 #define DVMRP_V3_GRAFT_ACK                      0x9
138 static const value_string code_v3[] = {
139         {DVMRP_V3_PROBE,                "Probe"},
140         {DVMRP_V3_REPORT,               "Report"},
141         {DVMRP_V3_ASK_NEIGHBORS,        "Ask Neighbors"},
142         {DVMRP_V3_NEIGHBORS,            "Neighbors"},
143         {DVMRP_V3_ASK_NEIGHBORS_2,      "Ask Neighbors 2"},
144         {DVMRP_V3_NEIGHBORS_2,          "Neighbors 2"},
145         {DVMRP_V3_PRUNE,                "Prune"},
146         {DVMRP_V3_GRAFT,                "Graft"},
147         {DVMRP_V3_GRAFT_ACK,            "Graft ACK"},
148         {0,                             NULL}
149 };
150
151 #define DVMRP_V3_CAP_LEAF       0x01
152 #define DVMRP_V3_CAP_PRUNE      0x02
153 #define DVMRP_V3_CAP_GENID      0x04
154 #define DVMRP_V3_CAP_MTRACE     0x08
155 #define DVMRP_V3_CAP_SNMP       0x10
156 #define DVMRP_V3_CAP_NETMASK    0x20
157         
158
159 #define V1_COMMAND_NULL         0
160 #define V1_COMMAND_AFI          2
161 #define V1_COMMAND_SUBNETMASK   3
162 #define V1_COMMAND_METRIC       4
163 #define V1_COMMAND_FLAGS0       5
164 #define V1_COMMAND_INFINITY     6
165 #define V1_COMMAND_DA           7
166 #define V1_COMMAND_RDA          8
167 #define V1_COMMAND_NMR          9
168 #define V1_COMMAND_NMR_CANCEL   10
169 static const value_string command[] = {
170         {V1_COMMAND_NULL,       "NULL"  },
171         {V1_COMMAND_AFI,        "Address Family Indicator"},
172         {V1_COMMAND_SUBNETMASK, "Subnetmask"},
173         {V1_COMMAND_METRIC,     "Metric"},
174         {V1_COMMAND_FLAGS0,     "Flags0"},
175         {V1_COMMAND_INFINITY,   "Infinity"},
176         {V1_COMMAND_DA,         "Destination Address"},
177         {V1_COMMAND_RDA,        "Requested Destination Address"},
178         {V1_COMMAND_NMR,        "Non-Membership Report"},
179         {V1_COMMAND_NMR_CANCEL, "Non-Membership Report Cancel"},
180         {0,                     NULL}
181 };
182
183 #define V1_AFI_IP               2
184 static const value_string afi[] = {
185         {V1_AFI_IP,     "IP v4 Family"},
186         {0,             NULL}
187 };
188
189 static const true_false_string tfs_dest_unreach = {
190         "Destination Unreachable",
191         "NOT Destination Unreachable"
192 };
193
194 static const true_false_string tfs_split_horiz = {
195         "Split Horizon concealed route",
196         "NOT Split Horizon concealed route"
197 };
198
199 static const true_false_string tfs_cap_leaf = {
200         "Leaf",
201         "NOT Leaf"
202 };
203 static const true_false_string tfs_cap_prune = {
204         "Prune capable",
205         "NOT Prune capable"
206 };
207 static const true_false_string tfs_cap_genid = {
208         "Genid capable",
209         "NOT Genid capable"
210 };
211 static const true_false_string tfs_cap_mtrace = {
212         "Multicast Traceroute capable",
213         "NOT Multicast Traceroute capable"
214 };
215 static const true_false_string tfs_cap_snmp = {
216         "SNMP capable",
217         "NOT SNMP capable"
218 };
219 static const true_false_string tfs_cap_netmask = {
220         "Netmask capable",
221         "NOT Netmask capable"
222 };
223
224 int
225 dissect_v3_report(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
226 {
227         guint8 m0,m1,m2,m3;
228         guint8 s0,s1,s2,s3;
229         guint8 metric;
230         guint32 ip;
231
232         while (tvb_reported_length_remaining(tvb, offset) > 0) {
233                 proto_tree *tree;
234                 proto_item *item;
235                 int old_offset = offset;
236
237                 item = proto_tree_add_item(parent_tree, hf_route, 
238                                 tvb, offset, -1, FALSE);
239                 tree = proto_item_add_subtree(item, ett_route);
240
241                 m0 = 0xff;
242                 /* read the mask */
243                 m1 = tvb_get_guint8(tvb, offset);
244                 m2 = tvb_get_guint8(tvb, offset+1);
245                 m3 = tvb_get_guint8(tvb, offset+2);
246
247                 ip = m3;
248                 ip = (ip<<8)|m2;
249                 ip = (ip<<8)|m1;
250                 ip = (ip<<8)|m0;
251                 proto_tree_add_ipv4(tree, hf_netmask, tvb, offset, 3, ip);
252
253                 offset += 3;
254
255                 /* read every srcnet, metric  pairs */
256                 do {
257                         int old_offset = offset;
258                         m0 = 0xff;
259
260                         s0 = 0;
261                         s1 = 0;
262                         s2 = 0;
263                         s3 = 0;
264
265                         s0 = tvb_get_guint8(tvb, offset);
266                         offset += 1;
267                         if (m1) {
268                                 s1 = tvb_get_guint8(tvb, offset);
269                                 offset += 1;
270                         }
271                         if (m2) {
272                                 s2 = tvb_get_guint8(tvb, offset);
273                                 offset += 1;
274                         }
275                         if (m3) {
276                                 s3 = tvb_get_guint8(tvb, offset);
277                                 offset += 1;
278                         }
279
280                         /* handle special case for default route V3/3.4.3 */
281                         if ((!m1)&&(!m2)&&(!m3)&&(!s0)) {
282                                 m0 = 0;
283                         }
284
285                         ip = s3;
286                         ip = (ip<<8)|s2;
287                         ip = (ip<<8)|s1;
288                         ip = (ip<<8)|s0;
289                         proto_tree_add_ipv4_format(tree, hf_saddr, tvb, 
290                                 old_offset, offset-old_offset, ip,
291                                 "%s %d.%d.%d.%d (netmask %d.%d.%d.%d)",
292                                 m0?"Source Network":"Default Route",
293                                 s0,s1,s2,s3,m0,m1,m2,m3);
294                         
295                         metric = tvb_get_guint8(tvb, offset);
296                         proto_tree_add_uint(tree, hf_metric, tvb,
297                                 offset, 1, metric&0x7f);
298                         offset += 1;
299
300
301                 } while (!(metric&0x80));
302
303                 proto_item_set_len(item, offset-old_offset);
304         }
305
306         return offset;
307 }
308
309 int
310 dissect_dvmrp_v3(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
311 {
312         guint8 code,count;
313
314         /* version */
315         proto_tree_add_uint(parent_tree, hf_version, tvb, 0, 0, 3);
316
317         /* type of command */
318         proto_tree_add_uint(parent_tree, hf_type, tvb, offset, 1, 0x13);
319         offset += 1;
320
321         /* code */
322         code = tvb_get_guint8(tvb, offset);
323         proto_tree_add_uint(parent_tree, hf_code_v3, tvb, offset, 1, code);
324         offset += 1;
325         if (check_col(pinfo->cinfo, COL_INFO)) {
326                 col_add_fstr(pinfo->cinfo, COL_INFO,
327                         "V%d %s",3 ,val_to_str(code, code_v3, 
328                                 "Unknown Type:0x%02x"));
329         }
330
331         /* checksum */
332         igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
333         offset += 2;
334
335         /* skip unused byte */
336         offset += 1;
337
338         /* PROBE and NEIGHBORS 2 packets have capabilities flags, unused
339            for other packets */
340         if (code==DVMRP_V3_PROBE || code==DVMRP_V3_NEIGHBORS_2) {
341                 proto_tree *tree;
342                 proto_item *item;
343
344                 item = proto_tree_add_item(parent_tree, hf_capabilities, 
345                                 tvb, offset, 1, FALSE);
346                 tree = proto_item_add_subtree(item, ett_capabilities);
347
348                 count = tvb_get_guint8(tvb, offset);
349                 proto_tree_add_boolean(tree, hf_cap_netmask, tvb, offset, 1, count);
350                 proto_tree_add_boolean(tree, hf_cap_snmp, tvb, offset, 1, count);
351                 proto_tree_add_boolean(tree, hf_cap_mtrace, tvb, offset, 1, count);
352                 proto_tree_add_boolean(tree, hf_cap_genid, tvb, offset, 1, count);
353                 proto_tree_add_boolean(tree, hf_cap_prune, tvb, offset, 1, count);
354                 proto_tree_add_boolean(tree, hf_cap_leaf, tvb, offset, 1, count);
355         }
356         offset += 1;
357
358         /* minor version */
359         proto_tree_add_item(parent_tree, hf_min_ver, tvb, offset, 1, FALSE);
360         offset += 1;
361
362         /* major version */
363         proto_tree_add_item(parent_tree, hf_maj_ver, tvb, offset, 1, FALSE);
364         offset += 1;
365
366         switch (code) {
367         case DVMRP_V3_PROBE:
368                 /* generation id */
369                 proto_tree_add_item(parent_tree, hf_genid, tvb, 
370                         offset, 4, FALSE);
371                 offset += 4;
372                 while (tvb_reported_length_remaining(tvb, offset) > 0) {
373                         proto_tree_add_item(parent_tree, hf_neighbor, 
374                                 tvb, offset, 4, FALSE);
375                         offset += 4;
376                 }
377                 break;
378         case DVMRP_V3_REPORT:
379                 offset = dissect_v3_report(tvb, pinfo, parent_tree, offset);
380                 break;
381         case DVMRP_V3_PRUNE:
382                 /* source address */
383                 proto_tree_add_item(parent_tree, hf_saddr, 
384                         tvb, offset, 4, FALSE);
385                 offset += 4;
386                 /* group address */
387                 proto_tree_add_item(parent_tree, hf_maddr, 
388                         tvb, offset, 4, FALSE);
389                 offset += 4;
390                 /* prune lifetime */
391                 proto_tree_add_item(parent_tree, hf_life, 
392                         tvb, offset, 4, FALSE);
393                 offset += 4;
394                 /* source netmask */
395                 if (tvb_reported_length_remaining(tvb, offset)>=4) {
396                         proto_tree_add_item(parent_tree, hf_netmask,
397                                 tvb, offset, 4, FALSE);
398                         offset += 4;
399                 }
400                 break;
401         case DVMRP_V3_GRAFT:
402                 /* source address */
403                 proto_tree_add_item(parent_tree, hf_saddr, 
404                         tvb, offset, 4, FALSE);
405                 offset += 4;
406                 /* group address */
407                 proto_tree_add_item(parent_tree, hf_maddr, 
408                         tvb, offset, 4, FALSE);
409                 offset += 4;
410                 /* source netmask */
411                 if (tvb_reported_length_remaining(tvb, offset)>=4) {
412                         proto_tree_add_item(parent_tree, hf_netmask, 
413                                 tvb, offset, 4, FALSE);
414                         offset += 4;
415                 }
416                 break;
417         case DVMRP_V3_GRAFT_ACK:
418                 /* source address */
419                 proto_tree_add_item(parent_tree, hf_saddr, 
420                         tvb, offset, 4, FALSE);
421                 offset += 4;
422                 /* group address */
423                 proto_tree_add_item(parent_tree, hf_maddr, 
424                         tvb, offset, 4, FALSE);
425                 offset += 4;
426                 /* source netmask */
427                 if (tvb_reported_length_remaining(tvb, offset)>=4) {
428                         proto_tree_add_item(parent_tree, hf_netmask, 
429                                 tvb, offset, 4, FALSE);
430                         offset += 4;
431                 }
432                 break;
433         case DVMRP_V3_ASK_NEIGHBORS:
434         case DVMRP_V3_NEIGHBORS:
435                 /* XXX - obsolete, and the draft doesn't describe them */
436                 break;
437         case DVMRP_V3_ASK_NEIGHBORS_2:
438                 /* No data */
439                 break;
440         case DVMRP_V3_NEIGHBORS_2:
441                 /* XXX - fill this in */
442                 break;
443         }
444
445         return offset;
446 }
447         
448
449 int
450 dissect_dvmrp_v1(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
451 {
452         guint8 code;
453         guint8 af=2; /* default */
454
455         /* version */
456         proto_tree_add_uint(parent_tree, hf_version, tvb, 0, 0, 1);
457
458         /* type of command */
459         proto_tree_add_uint(parent_tree, hf_type, tvb, offset, 1, 0x13);
460         offset += 1;
461
462         /* code */
463         code = tvb_get_guint8(tvb, offset);
464         proto_tree_add_uint(parent_tree, hf_code_v1, tvb, offset, 1, code);
465         offset += 1;
466         if (check_col(pinfo->cinfo, COL_INFO)) {
467                 col_add_fstr(pinfo->cinfo, COL_INFO,
468                         "V%d %s",1 ,val_to_str(code, code_v1, 
469                                 "Unknown Type:0x%02x"));
470         }
471
472         /* checksum */
473         igmp_checksum(parent_tree, tvb, hf_checksum, hf_checksum_bad, pinfo, 0);
474         offset += 2;
475
476         /* decode all the v1 commands */
477         while (tvb_reported_length_remaining(tvb, offset)) {
478                 proto_tree *tree;
479                 proto_item *item;
480                 guint8 cmd,count;
481                 int old_offset = offset;
482
483                 item = proto_tree_add_item(parent_tree, hf_commands, 
484                                 tvb, offset, -1, FALSE);
485                 tree = proto_item_add_subtree(item, ett_commands);
486
487                 cmd = tvb_get_guint8(tvb, offset);
488                 proto_tree_add_uint(tree, hf_command, tvb,
489                         offset, 1, cmd);
490                 offset += 1;
491
492                 switch (cmd){
493                 case V1_COMMAND_NULL:
494                         offset += 1; /* skip ignored/pad byte*/
495                         if (item) {
496                                 proto_item_set_text(item, "Command: NULL");
497                         }
498                         break;
499                 case V1_COMMAND_AFI:
500                         af = tvb_get_guint8(tvb, offset);
501                         proto_tree_add_uint(tree, hf_afi, tvb,
502                                 offset, 1, af);
503                         offset += 1;
504                         if (item) {
505                                 proto_item_set_text(item, "%s: %s",
506                                         val_to_str(cmd, command, "Unknown Command:0x%02x"),
507                                         val_to_str(af, afi, "Unknown Family:0x%02x")
508                                 );
509                         }
510                         break;          
511                 case V1_COMMAND_SUBNETMASK:
512                         count = tvb_get_guint8(tvb, offset);
513                         proto_tree_add_uint(tree, hf_count, tvb,
514                                 offset, 1, count);
515                         offset += 1;
516                         if (count) { /* must be 0 or 1 */
517                                 proto_tree_add_item(tree, hf_netmask, 
518                                         tvb, offset, 4, FALSE);
519                                 if (item) {
520                                         proto_item_set_text(item, "%s: %d.%d.%d.%d",
521                                                 val_to_str(cmd, command, "Unknown Command:0x%02x"), 
522                                                 tvb_get_guint8(tvb, offset),
523                                                 tvb_get_guint8(tvb, offset+1),
524                                                 tvb_get_guint8(tvb, offset+2),
525                                                 tvb_get_guint8(tvb, offset+3));
526                                 }
527                                 offset += 4;
528                         } else {
529                                 if (item) {
530                                         proto_item_set_text(item, "%s: <no mask supplied>",
531                                                 val_to_str(cmd, command, "Unknown Command:0x%02x"));
532                                 }
533                         }
534                         break;  
535                 case V1_COMMAND_METRIC:
536                         proto_tree_add_item(tree, hf_metric, tvb,
537                                 offset, 1, FALSE);
538                         if (item) {
539                                 proto_item_set_text(item, "%s: %d",
540                                         val_to_str(cmd, command, "Unknown Command:0x%02x"), 
541                                         tvb_get_guint8(tvb, offset));
542                         }
543                         offset += 1;
544                         break;          
545                 case V1_COMMAND_FLAGS0:
546                         count = tvb_get_guint8(tvb, offset);
547                         proto_tree_add_boolean(tree, hf_dest_unr, tvb, offset, 1, count);
548                         proto_tree_add_boolean(tree, hf_split_horiz, tvb, offset, 1, count);
549                         if (item) {
550                                 proto_item_set_text(item, "%s: 0x%02x",
551                                         val_to_str(cmd, command, "Unknown Command:0x%02x"), count);
552                         }
553                         offset += 1;
554                         break;
555                 case V1_COMMAND_INFINITY:
556                         proto_tree_add_item(tree, hf_infinity, tvb,
557                                 offset, 1, FALSE);
558                         if (item) {
559                                 proto_item_set_text(item, "%s: %d",
560                                         val_to_str(cmd, command, "Unknown Command:0x%02x"), tvb_get_guint8(tvb, offset));
561                         }
562                         offset += 1;
563                         break;          
564                 case V1_COMMAND_DA:
565                 case V1_COMMAND_RDA: /* same as DA */
566                         count = tvb_get_guint8(tvb, offset);
567                         proto_tree_add_uint(tree, hf_count, tvb,
568                                 offset, 1, count);
569                         offset += 1;
570                         while (count--) {
571                                 proto_tree_add_item(tree, hf_daddr, 
572                                         tvb, offset, 4, FALSE);
573                                 offset += 4;
574                         }
575                         if (item) {
576                                 proto_item_set_text(item, "%s",
577                                         val_to_str(cmd, command, "Unknown Command:0x%02x"));
578                         }
579                         break;  
580                 case V1_COMMAND_NMR:
581                         count = tvb_get_guint8(tvb, offset);
582                         proto_tree_add_uint(tree, hf_count, tvb,
583                                 offset, 1, count);
584                         offset += 1;
585                         while (count--) {
586                                 proto_tree_add_item(tree, hf_maddr, 
587                                         tvb, offset, 4, FALSE);
588                                 offset += 4;
589                                 proto_tree_add_item(tree, hf_hold, tvb,
590                                         offset, 4, FALSE);
591                                 offset += 4;
592                         }
593                         if (item) {
594                                 proto_item_set_text(item, "%s",
595                                         val_to_str(cmd, command, "Unknown Command:0x%02x"));
596                         }
597                         break;  
598                 case V1_COMMAND_NMR_CANCEL:
599                         count = tvb_get_guint8(tvb, offset);
600                         proto_tree_add_uint(tree, hf_count, tvb,
601                                 offset, 1, count);
602                         offset += 1;
603                         while (count--) {
604                                 proto_tree_add_item(tree, hf_maddr, 
605                                         tvb, offset, 4, FALSE);
606                                 offset += 4;
607                         }
608                         if (item) {
609                                 proto_item_set_text(item, "%s",
610                                         val_to_str(cmd, command, "Unknown Command:0x%02x"));
611                         }
612                         break;  
613                 }
614
615                 proto_item_set_len(item, offset-old_offset);
616         }
617
618         return offset;
619 }
620
621 /* This function is only called from the IGMP dissector */
622 int
623 dissect_dvmrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, int offset)
624 {
625         proto_tree *tree;
626         proto_item *item;
627
628         if (!proto_is_protocol_enabled(proto_dvmrp)) {
629                 /* we are not enabled, skip entire packet to be nice
630                    to the igmp layer. (so clicking on IGMP will display the data)
631                  */
632                 return offset+tvb_length_remaining(tvb, offset);
633         }
634
635         item = proto_tree_add_item(parent_tree, proto_dvmrp, tvb, offset, -1, FALSE);
636         tree = proto_item_add_subtree(item, ett_dvmrp);
637
638
639         if (check_col(pinfo->cinfo, COL_PROTOCOL)) {
640                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "DVMRP");
641         }
642         if (check_col(pinfo->cinfo, COL_INFO)) {
643                 col_clear(pinfo->cinfo, COL_INFO);
644         }
645
646
647         if ((tvb_length_remaining(tvb, offset)>=8)
648          && (tvb_get_guint8(tvb, 6)==0xff)
649          && (tvb_get_guint8(tvb, 7)==0x03)) {
650                 offset = dissect_dvmrp_v3(tvb, pinfo, tree, offset);
651                 proto_item_set_len(item, offset);
652                 return offset;
653         }
654
655         
656         offset = dissect_dvmrp_v1(tvb, pinfo, tree, offset);
657         proto_item_set_len(item, offset);
658         return offset;
659 }
660
661 void
662 proto_register_dvmrp(void)
663 {
664         static hf_register_info hf[] = {
665                 { &hf_version,
666                         { "DVMRP Version", "dvmrp.version", FT_UINT8, BASE_DEC,
667                           NULL, 0, "DVMRP Version", HFILL }},
668
669                 { &hf_type,
670                         { "Type", "dvmrp.type", FT_UINT8, BASE_HEX,
671                           VALS(dvmrp_type), 0, "DVMRP Packet Type", HFILL }},
672
673                 { &hf_code_v1,
674                         { "Code", "dvmrp.v1.code", FT_UINT8, BASE_HEX,
675                           VALS(code_v1), 0, "DVMRP Packet Code", HFILL }},
676
677                 { &hf_checksum,
678                         { "Checksum", "dvmrp.checksum", FT_UINT16, BASE_HEX,
679                           NULL, 0, "DVMRP Checksum", HFILL }},
680
681                 { &hf_checksum_bad,
682                         { "Bad Checksum", "dvmrp.checksum_bad", FT_BOOLEAN, BASE_NONE,
683                           NULL, 0, "Bad DVMRP Checksum", HFILL }},
684
685                 { &hf_commands,
686                         { "Commands", "dvmrp.commands", FT_NONE, BASE_NONE,
687                           NULL, 0, "DVMRP V1 Commands", HFILL }},
688
689                 { &hf_command,
690                         { "Command", "dvmrp.command", FT_UINT8, BASE_HEX,
691                           VALS(command), 0, "DVMRP V1 Command", HFILL }},
692
693                 { &hf_afi,
694                         { "Address Family", "dvmrp.afi", FT_UINT8, BASE_HEX,
695                           VALS(afi), 0, "DVMRP Address Family Indicator", HFILL }},
696
697                 { &hf_count,
698                         { "Count", "dvmrp.count", FT_UINT8, BASE_HEX,
699                           NULL, 0, "Count", HFILL }},
700
701                 { &hf_netmask,
702                         { "Netmask", "igmp.netmask", FT_IPv4, BASE_NONE,
703                           NULL, 0, "DVMRP Netmask", HFILL }},
704
705                 { &hf_metric,
706                         { "Metric", "dvmrp.metric", FT_UINT8, BASE_DEC,
707                           NULL, 0, "DVMRP Metric", HFILL }},
708
709                 {&hf_dest_unr,
710                         { "Destination Unreachable", "dvmrp.dest_unreach", FT_BOOLEAN, 8,
711                         TFS(&tfs_dest_unreach), 0x01, "Destination Unreachable", HFILL }},
712
713                 {&hf_split_horiz,
714                         { "Split Horizon", "dvmrp.split_horiz", FT_BOOLEAN, 8,
715                         TFS(&tfs_split_horiz), 0x02, "Split Horizon concealed route", HFILL }},
716
717                 { &hf_infinity,
718                         { "Infinity", "dvmrp.infinity", FT_UINT8, BASE_DEC,
719                           NULL, 0, "DVMRP Infinity", HFILL }},
720
721                 { &hf_daddr,
722                         { "Dest Addr", "igmp.daddr", FT_IPv4, BASE_NONE,
723                           NULL, 0, "DVMRP Destination Address", HFILL }},
724
725                 { &hf_maddr,
726                         { "Multicast Addr", "igmp.maddr", FT_IPv4, BASE_NONE,
727                           NULL, 0, "DVMRP Multicast Address", HFILL }},
728
729                 { &hf_hold,
730                         { "Hold Time", "dvmrp.hold", FT_UINT32, BASE_DEC,
731                           NULL, 0, "DVMRP Hold Time in seconds", HFILL }},
732
733                 { &hf_code_v3,
734                         { "Code", "dvmrp.v3.code", FT_UINT8, BASE_HEX,
735                           VALS(code_v3), 0, "DVMRP Packet Code", HFILL }},
736
737                 { &hf_capabilities,
738                         { "Capabilities", "dvmrp.capabilities", FT_NONE, BASE_NONE,
739                           NULL, 0, "DVMRP V3 Capabilities", HFILL }},
740
741                 {&hf_cap_leaf,
742                         { "Leaf", "dvmrp.cap.leaf", FT_BOOLEAN, 8,
743                         TFS(&tfs_cap_leaf), DVMRP_V3_CAP_LEAF, "Leaf", HFILL }},
744
745                 {&hf_cap_prune,
746                         { "Prune", "dvmrp.cap.prune", FT_BOOLEAN, 8,
747                         TFS(&tfs_cap_prune), DVMRP_V3_CAP_PRUNE, "Prune capability", HFILL }},
748
749                 {&hf_cap_genid,
750                         { "Genid", "dvmrp.cap.genid", FT_BOOLEAN, 8,
751                         TFS(&tfs_cap_genid), DVMRP_V3_CAP_GENID, "Genid capability", HFILL }},
752
753                 {&hf_cap_mtrace,
754                         { "Mtrace", "dvmrp.cap.mtrace", FT_BOOLEAN, 8,
755                         TFS(&tfs_cap_mtrace), DVMRP_V3_CAP_MTRACE, "Mtrace capability", HFILL }},
756
757                 {&hf_cap_snmp,
758                         { "SNMP", "dvmrp.cap.snmp", FT_BOOLEAN, 8,
759                         TFS(&tfs_cap_snmp), DVMRP_V3_CAP_SNMP, "SNMP capability", HFILL }},
760
761                 {&hf_cap_netmask,
762                         { "Netmask", "dvmrp.cap.netmask", FT_BOOLEAN, 8,
763                         TFS(&tfs_cap_netmask), DVMRP_V3_CAP_NETMASK, "Netmask capability", HFILL }},
764
765                 { &hf_min_ver,
766                         { "Minor Version", "dvmrp.min_ver", FT_UINT8, BASE_HEX,
767                           NULL, 0, "DVMRP Minor Version", HFILL }},
768
769                 { &hf_maj_ver,
770                         { "Major Version", "dvmrp.maj_ver", FT_UINT8, BASE_HEX,
771                           NULL, 0, "DVMRP Major Version", HFILL }},
772
773                 { &hf_genid,
774                         { "Generation ID", "dvmrp.genid", FT_UINT32, BASE_DEC,
775                           NULL, 0, "DVMRP Generation ID", HFILL }},
776
777                 { &hf_route,
778                         { "Route", "dvmrp.route", FT_NONE, BASE_NONE,
779                           NULL, 0, "DVMRP V3 Route Report", HFILL }},
780
781                 { &hf_saddr,
782                         { "Source Addr", "igmp.saddr", FT_IPv4, BASE_NONE,
783                           NULL, 0, "DVMRP Source Address", HFILL }},
784
785                 { &hf_life,
786                         { "Prune lifetime", "dvmrp.lifetime", FT_UINT32, BASE_DEC,
787                           NULL, 0, "DVMRP Prune Lifetime", HFILL }},
788
789                 { &hf_neighbor,
790                         { "Neighbor Addr", "igmp.neighbor", FT_IPv4, BASE_NONE,
791                           NULL, 0, "DVMRP Neighbor Address", HFILL }},
792
793         };
794         static gint *ett[] = {
795                 &ett_dvmrp,
796                 &ett_commands,
797                 &ett_capabilities,
798                 &ett_route,
799         };
800
801         proto_dvmrp = proto_register_protocol("Distance Vector Multicast Routing Protocol",
802             "DVMRP", "dvmrp");
803         proto_register_field_array(proto_dvmrp, hf, array_length(hf));
804         proto_register_subtree_array(ett, array_length(ett));
805 }