2 * Routines for the Virtual Router Redundancy Protocol (VRRP)
5 * Heikki Vatiainen <hessu@cs.tut.fi>
7 * $Id: packet-vrrp.c,v 1.12 2001/01/06 05:43:13 guy Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@zing.org>
11 * Copyright 1998 Gerald Combs
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
33 #ifdef HAVE_SYS_TYPES_H
34 # include <sys/types.h>
37 #ifdef HAVE_NETINET_IN_H
38 #include <netinet/in.h>
44 #include "packet-ip.h"
47 static gint proto_vrrp = -1;
48 static gint ett_vrrp = -1;
49 static gint ett_vrrp_ver_type = -1;
51 static gint hf_vrrp_ver_type = -1;
52 static gint hf_vrrp_version = -1;
53 static gint hf_vrrp_type = -1;
55 #define VRRP_VERSION_MASK 0xf0
56 #define VRRP_TYPE_MASK 0x0f
57 #define VRRP_AUTH_DATA_LEN 8
59 #define VRRP_TYPE_ADVERTISEMENT 1
60 static const value_string vrrp_type_vals[] = {
61 {VRRP_TYPE_ADVERTISEMENT, "Advertisement"},
65 #define VRRP_AUTH_TYPE_NONE 0
66 #define VRRP_AUTH_TYPE_SIMPLE_TEXT 1
67 #define VRRP_AUTH_TYPE_IP_AUTH_HDR 2
68 static const value_string vrrp_auth_vals[] = {
69 {VRRP_AUTH_TYPE_NONE, "No Authentication"},
70 {VRRP_AUTH_TYPE_SIMPLE_TEXT, "Simple Text Authentication"},
71 {VRRP_AUTH_TYPE_IP_AUTH_HDR, "IP Authentication Header"},
75 #define VRRP_PRIORITY_MASTER_STOPPING 0
76 /* Values between 1 and 254 inclusive are for backup VRRP routers */
77 #define VRRP_PRIORITY_DEFAULT 100
78 #define VRRP_PRIORITY_OWNER 255
79 static const value_string vrrp_prio_vals[] = {
80 {VRRP_PRIORITY_MASTER_STOPPING, "Current Master has stopped participating in VRRP"},
81 {VRRP_PRIORITY_DEFAULT, "Default priority for a backup VRRP router"},
82 {VRRP_PRIORITY_OWNER, "This VRRP router owns the virtual router's IP address(es)"},
88 dissect_vrrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
95 CHECK_DISPLAY_AS_DATA(proto_vrrp, tvb, pinfo, tree);
97 pinfo->current_proto = "VRRP";
99 if (check_col(pinfo->fd, COL_PROTOCOL))
100 col_set_str(pinfo->fd, COL_PROTOCOL, "VRRP");
101 if (check_col(pinfo->fd, COL_INFO))
102 col_clear(pinfo->fd, COL_INFO);
104 ver_type = tvb_get_guint8(tvb, 0);
105 if (check_col(pinfo->fd, COL_INFO)) {
106 col_add_fstr(pinfo->fd, COL_INFO, "%s (v%u)",
107 "Announcement", hi_nibble(ver_type));
112 proto_tree *vrrp_tree, *ver_type_tree;
113 guint8 priority, ip_count, auth_type, adver_int;
114 guint16 cksum, computed_cksum;
115 guint8 auth_buf[VRRP_AUTH_DATA_LEN+1];
117 ti = proto_tree_add_item(tree, proto_vrrp, tvb, 0,
118 tvb_length(tvb), FALSE);
119 vrrp_tree = proto_item_add_subtree(ti, ett_vrrp);
121 tv = proto_tree_add_uint_format(vrrp_tree, hf_vrrp_ver_type,
122 tvb, offset, 1, ver_type,
123 "Version %u, Packet type %u (%s)",
124 hi_nibble(ver_type), lo_nibble(ver_type),
125 val_to_str(lo_nibble(ver_type), vrrp_type_vals, "Unknown"));
126 ver_type_tree = proto_item_add_subtree(tv, ett_vrrp_ver_type);
127 proto_tree_add_uint(ver_type_tree, hf_vrrp_version, tvb,
128 offset, 1, ver_type);
129 proto_tree_add_uint(ver_type_tree, hf_vrrp_type, tvb, offset, 1,
133 proto_tree_add_text(vrrp_tree, tvb, offset, 1,
134 "Virtual Router ID: %u",
135 tvb_get_guint8(tvb, offset));
138 priority = tvb_get_guint8(tvb, offset);
139 proto_tree_add_text(vrrp_tree, tvb, offset, 1, "Priority: %u (%s)",
141 val_to_str(priority, vrrp_prio_vals, "Non-default backup priority"));
144 ip_count = tvb_get_guint8(tvb, offset);
145 proto_tree_add_text(vrrp_tree, tvb, offset, 1,
146 "Count IP Addrs: %u", ip_count);
149 auth_type = tvb_get_guint8(tvb, offset);
150 proto_tree_add_text(vrrp_tree, tvb, offset, 1,
151 "Authentication Type: %u (%s)", auth_type,
152 val_to_str(auth_type, vrrp_auth_vals, "Unknown"));
155 adver_int = tvb_get_guint8(tvb, offset);
156 proto_tree_add_text(vrrp_tree, tvb, offset, 1,
157 "Advertisement Interval: %u second%s",
158 adver_int, plurality(adver_int, "", "s"));
161 cksum = tvb_get_ntohs(tvb, offset);
162 vrrp_len = tvb_reported_length(tvb);
163 if (!pinfo->fragmented && tvb_length(tvb) >= vrrp_len) {
164 /* The packet isn't part of a fragmented datagram
165 and isn't truncated, so we can checksum it. */
166 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, vrrp_len);
167 cksum_vec[0].len = vrrp_len;
168 computed_cksum = in_cksum(&cksum_vec[0], 1);
169 if (computed_cksum == 0) {
170 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
171 "Checksum: 0x%04x (correct)",
174 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
175 "Checksum: 0x%04x (incorrect, should be 0x%04x)",
177 in_cksum_shouldbe(cksum, computed_cksum));
180 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
181 "Checksum: 0x%04x", cksum);
185 while (ip_count > 0) {
186 proto_tree_add_text(vrrp_tree, tvb, offset, 4,
187 "Virtual Router IP address: %s",
188 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
193 if (auth_type != VRRP_AUTH_TYPE_SIMPLE_TEXT)
194 return; /* Contents of the authentication data is undefined */
196 tvb_get_nstringz0(tvb, offset, VRRP_AUTH_DATA_LEN, auth_buf);
197 if (auth_buf[0] != '\0')
198 proto_tree_add_text(vrrp_tree, tvb, offset,
200 "Authentication string: `%s'",
206 void proto_register_vrrp(void)
208 static hf_register_info hf[] = {
210 {"VRRP message version and type", "vrrp.typever",
211 FT_UINT8, BASE_DEC, NULL, 0x0,
212 "VRRP version and type"}},
215 {"VRRP protocol version", "vrrp.version",
216 FT_UINT8, BASE_DEC, NULL, VRRP_VERSION_MASK,
220 {"VRRP packet type", "vrrp.type",
221 FT_UINT8, BASE_DEC, VALS(vrrp_type_vals), VRRP_TYPE_MASK,
225 static gint *ett[] = {
230 proto_vrrp = proto_register_protocol("Virtual Router Redundancy Protocol",
232 proto_register_field_array(proto_vrrp, hf, array_length(hf));
233 proto_register_subtree_array(ett, array_length(ett));
239 proto_reg_handoff_vrrp(void)
241 dissector_add("ip.proto", IP_PROTO_VRRP, dissect_vrrp);