Removed trailing whitespaces from .h and .c files using the
[obnox/wireshark/wip.git] / packet-vrrp.c
index 6007a26c1f2c818bf0095aa6f1b503154c8bbd29..1b500dca04fdc95bc3601eda2e449a42231bf01c 100644 (file)
@@ -4,12 +4,11 @@
  *
  * Heikki Vatiainen <hessu@cs.tut.fi>
  *
- * $Id: packet-vrrp.c,v 1.13 2001/01/09 06:31:44 guy Exp $
+ * $Id: packet-vrrp.c,v 1.24 2002/08/02 23:36:04 jmayer Exp $
  *
  * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1998 Gerald Combs
- *
  * 
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
 # include "config.h"
 #endif
 
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-#include <netinet/in.h>
-#endif
-
 #include <string.h>
 #include <glib.h>
-#include "packet.h"
-#include "packet-ip.h"
+#include <epan/packet.h>
+#include "ipproto.h"
 #include "in_cksum.h"
 
 static gint proto_vrrp = -1;
@@ -51,6 +42,13 @@ static gint ett_vrrp_ver_type = -1;
 static gint hf_vrrp_ver_type = -1;
 static gint hf_vrrp_version = -1;
 static gint hf_vrrp_type = -1;
+static gint hf_vrrp_virt_rtr_id = -1;
+static gint hf_vrrp_prio = -1;
+static gint hf_vrrp_count_ip = -1;
+static gint hf_vrrp_auth_type = -1;
+static gint hf_vrrp_adver_int = -1;
+static gint hf_vrrp_ip = -1;
+static gint hf_vrrp_ip6 = -1;
 
 #define VRRP_VERSION_MASK 0xf0
 #define VRRP_TYPE_MASK 0x0f
@@ -90,32 +88,28 @@ dissect_vrrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
         int offset = 0;
         gint vrrp_len;
         guint8  ver_type;
-       vec_t cksum_vec[1];
-
-        CHECK_DISPLAY_AS_DATA(proto_vrrp, tvb, pinfo, tree);
+       vec_t cksum_vec[4];
+       guint32 phdr[2];
 
-        pinfo->current_proto = "VRRP";
-
-        if (check_col(pinfo->fd, COL_PROTOCOL))
-                col_set_str(pinfo->fd, COL_PROTOCOL, "VRRP");
-        if (check_col(pinfo->fd, COL_INFO))
-                col_clear(pinfo->fd, COL_INFO);
+        if (check_col(pinfo->cinfo, COL_PROTOCOL))
+                col_set_str(pinfo->cinfo, COL_PROTOCOL, "VRRP");
+        if (check_col(pinfo->cinfo, COL_INFO))
+                col_clear(pinfo->cinfo, COL_INFO);
         
        ver_type = tvb_get_guint8(tvb, 0);
-        if (check_col(pinfo->fd, COL_INFO)) {
-                col_add_fstr(pinfo->fd, COL_INFO, "%s (v%u)",
+        if (check_col(pinfo->cinfo, COL_INFO)) {
+                col_add_fstr(pinfo->cinfo, COL_INFO, "%s (v%u)",
                              "Announcement", hi_nibble(ver_type));
         }
 
         if (tree) {
                 proto_item *ti, *tv;
                 proto_tree *vrrp_tree, *ver_type_tree;
-                guint8 priority, ip_count, auth_type, adver_int;
+                guint8 priority, ip_count = 0, auth_type;
                 guint16 cksum, computed_cksum;
                 guint8 auth_buf[VRRP_AUTH_DATA_LEN+1];
 
-                ti = proto_tree_add_item(tree, proto_vrrp, tvb, 0,
-                                         tvb_length(tvb), FALSE);
+                ti = proto_tree_add_item(tree, proto_vrrp, tvb, 0, -1, FALSE);
                 vrrp_tree = proto_item_add_subtree(ti, ett_vrrp);
 
                 tv = proto_tree_add_uint_format(vrrp_tree, hf_vrrp_ver_type,
@@ -130,42 +124,63 @@ dissect_vrrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                                     ver_type);
                 offset++;
                 
-                proto_tree_add_text(vrrp_tree, tvb, offset, 1,
-                                    "Virtual Router ID: %u",
-                                    tvb_get_guint8(tvb, offset));
+                proto_tree_add_item(vrrp_tree, hf_vrrp_virt_rtr_id, tvb, offset, 1, FALSE);
                 offset++;
 
                 priority = tvb_get_guint8(tvb, offset);
-                proto_tree_add_text(vrrp_tree, tvb, offset, 1, "Priority: %u (%s)",
-                                    priority,
-                                    val_to_str(priority, vrrp_prio_vals, "Non-default backup priority"));
+                proto_tree_add_uint_format(vrrp_tree, hf_vrrp_prio, tvb, offset, 1, priority, "Priority: %u (%s)",
+                                           priority,
+                                           val_to_str(priority, vrrp_prio_vals, "Non-default backup priority"));
                 offset++;
 
-                ip_count = tvb_get_guint8(tvb, offset);
-                proto_tree_add_text(vrrp_tree, tvb, offset, 1,
-                                    "Count IP Addrs: %u", ip_count);
-                offset++;
+               switch(hi_nibble(ver_type)) {
+               case 3:
+                       /* Skip reserve field */
+                       offset++;
+                       break;
+               case 2:
+               default:
+                       ip_count = tvb_get_guint8(tvb, offset);
+                       proto_tree_add_uint(vrrp_tree, hf_vrrp_count_ip, tvb,
+                           offset, 1, ip_count);
+                       offset++;
+                       break;
+               }
 
                 auth_type = tvb_get_guint8(tvb, offset);
-                proto_tree_add_text(vrrp_tree, tvb, offset, 1,
-                                    "Authentication Type: %u (%s)", auth_type,
-                                    val_to_str(auth_type, vrrp_auth_vals, "Unknown"));
+                proto_tree_add_item(vrrp_tree, hf_vrrp_auth_type, tvb, offset, 1, FALSE);
                 offset++;
 
-                adver_int = tvb_get_guint8(tvb, offset);
-                proto_tree_add_text(vrrp_tree, tvb, offset, 1,
-                                    "Advertisement Interval: %u second%s",
-                                    adver_int, plurality(adver_int, "", "s"));
+                proto_tree_add_item(vrrp_tree, hf_vrrp_adver_int, tvb, offset, 1, FALSE);
                 offset++;
 
                 cksum = tvb_get_ntohs(tvb, offset);
-                vrrp_len = tvb_reported_length(tvb);
-                if (!pinfo->fragmented && tvb_length(tvb) >= vrrp_len) {
+                vrrp_len = (gint)tvb_reported_length(tvb);
+                if (!pinfo->fragmented && (gint)tvb_length(tvb) >= vrrp_len) {
                         /* The packet isn't part of a fragmented datagram
                            and isn't truncated, so we can checksum it. */
-                        cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, vrrp_len);
-                        cksum_vec[0].len = vrrp_len;
-                        computed_cksum = in_cksum(&cksum_vec[0], 1);
+                       switch(hi_nibble(ver_type)) {
+                       case 3:
+                               /* Set up the fields of the pseudo-header. */
+                               cksum_vec[0].ptr = pinfo->src.data;
+                               cksum_vec[0].len = pinfo->src.len;
+                               cksum_vec[1].ptr = pinfo->dst.data;
+                               cksum_vec[1].len = pinfo->dst.len;
+                               cksum_vec[2].ptr = (const guint8 *)&phdr;
+                               phdr[0] = g_htonl(vrrp_len);
+                               phdr[1] = g_htonl(IP_PROTO_VRRP);
+                               cksum_vec[2].len = 8;
+                               cksum_vec[3].ptr = tvb_get_ptr(tvb, 0, vrrp_len);
+                               cksum_vec[3].len = vrrp_len;
+                               computed_cksum = in_cksum(cksum_vec, 4);
+                               break;
+                       case 2:
+                       default:
+                               cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, vrrp_len);
+                               cksum_vec[0].len = vrrp_len;
+                               computed_cksum = in_cksum(&cksum_vec[0], 1);
+                               break;
+                       }
                         if (computed_cksum == 0) {
                                 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
                                                     "Checksum: 0x%04x (correct)",
@@ -182,14 +197,21 @@ dissect_vrrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                 }
                 offset+=2;
 
-                while (ip_count > 0) {
-                        proto_tree_add_text(vrrp_tree, tvb, offset, 4,
-                                            "Virtual Router IP address: %s",
-                                            ip_to_str(tvb_get_ptr(tvb, offset, 4)));
-                        offset+=4;
-                        ip_count--;
-                }
-
+               switch(hi_nibble(ver_type)) {
+               case 3:
+                       proto_tree_add_item(vrrp_tree, hf_vrrp_ip6, tvb, offset, 16, FALSE);
+                       offset+=16;
+                       break;
+               case 2:
+               default:
+                       while (ip_count > 0) {
+                               proto_tree_add_item(vrrp_tree, hf_vrrp_ip, tvb,
+                                   offset, 4, FALSE);
+                               offset+=4;
+                               ip_count--;
+                       }
+                       break;
+               }
                 if (auth_type != VRRP_AUTH_TYPE_SIMPLE_TEXT)
                         return; /* Contents of the authentication data is undefined */
 
@@ -209,17 +231,52 @@ void proto_register_vrrp(void)
                 { &hf_vrrp_ver_type,
                   {"VRRP message version and type", "vrrp.typever",
                    FT_UINT8, BASE_DEC, NULL, 0x0,
-                   "VRRP version and type"}},
+                   "VRRP version and type", HFILL }},
 
                 { &hf_vrrp_version,
                   {"VRRP protocol version", "vrrp.version",
                    FT_UINT8, BASE_DEC, NULL, VRRP_VERSION_MASK,
-                   "VRRP version"}},
+                   "VRRP version", HFILL }},
 
                 { &hf_vrrp_type,
                   {"VRRP packet type", "vrrp.type",
                    FT_UINT8, BASE_DEC, VALS(vrrp_type_vals), VRRP_TYPE_MASK,
-                   "VRRP type"}}
+                   "VRRP type", HFILL }},
+
+                { &hf_vrrp_virt_rtr_id,
+                  {"Virtual Rtr ID", "vrrp.virt_rtr_id",
+                   FT_UINT8, BASE_DEC, NULL, 0x0,
+                   "Virtual router this packet is reporting status for", HFILL }},
+
+                { &hf_vrrp_prio,
+                  {"Priority", "vrrp.prio",
+                   FT_UINT8, BASE_DEC, NULL, 0x0,
+                   "Sending VRRP router's priority for the virtual router", HFILL }},
+
+                { &hf_vrrp_count_ip,
+                  {"Count IP Addrs", "vrrp.count_ip_addrs",
+                   FT_UINT8, BASE_DEC, NULL, 0x0,
+                   "The number of IP addresses contained in this VRRP advertisement", HFILL }},
+
+                { &hf_vrrp_auth_type,
+                  {"Auth Type", "vrrp.auth_type",
+                   FT_UINT8, BASE_DEC, VALS(vrrp_auth_vals), 0x0,
+                   "The authentication method being utilized", HFILL }},
+
+                { &hf_vrrp_adver_int,
+                  {"Adver Int", "vrrp.adver_int",
+                   FT_UINT8, BASE_DEC, NULL, 0x0,
+                   "Time interval (in seconds) between ADVERTISEMENTS", HFILL }},
+
+                { &hf_vrrp_ip,
+                  {"IP Address", "vrrp.ip_addr",
+                   FT_IPv4, 0, NULL, 0x0,
+                   "IP address associated with the virtual router", HFILL }},
+
+                { &hf_vrrp_ip6,
+                  {"IPv6 Address", "vrrp.ipv6_addr",
+                   FT_IPv6, 0, NULL, 0x0,
+                   "IPv6 address associated with the virtual router", HFILL }},
         };
 
         static gint *ett[] = {
@@ -238,5 +295,8 @@ void proto_register_vrrp(void)
 void
 proto_reg_handoff_vrrp(void)
 {
-       dissector_add("ip.proto", IP_PROTO_VRRP, dissect_vrrp, proto_vrrp);
+       dissector_handle_t vrrp_handle;
+
+       vrrp_handle = create_dissector_handle(dissect_vrrp, proto_vrrp);
+       dissector_add("ip.proto", IP_PROTO_VRRP, vrrp_handle);
 }