2 * Routines for the Virtual Router Redundancy Protocol (VRRP)
5 * Heikki Vatiainen <hessu@cs.tut.fi>
7 * $Id: packet-vrrp.c,v 1.14 2001/01/22 03:33:45 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 if (check_col(pinfo->fd, COL_PROTOCOL))
96 col_set_str(pinfo->fd, COL_PROTOCOL, "VRRP");
97 if (check_col(pinfo->fd, COL_INFO))
98 col_clear(pinfo->fd, COL_INFO);
100 ver_type = tvb_get_guint8(tvb, 0);
101 if (check_col(pinfo->fd, COL_INFO)) {
102 col_add_fstr(pinfo->fd, COL_INFO, "%s (v%u)",
103 "Announcement", hi_nibble(ver_type));
108 proto_tree *vrrp_tree, *ver_type_tree;
109 guint8 priority, ip_count, auth_type, adver_int;
110 guint16 cksum, computed_cksum;
111 guint8 auth_buf[VRRP_AUTH_DATA_LEN+1];
113 ti = proto_tree_add_item(tree, proto_vrrp, tvb, 0,
114 tvb_length(tvb), FALSE);
115 vrrp_tree = proto_item_add_subtree(ti, ett_vrrp);
117 tv = proto_tree_add_uint_format(vrrp_tree, hf_vrrp_ver_type,
118 tvb, offset, 1, ver_type,
119 "Version %u, Packet type %u (%s)",
120 hi_nibble(ver_type), lo_nibble(ver_type),
121 val_to_str(lo_nibble(ver_type), vrrp_type_vals, "Unknown"));
122 ver_type_tree = proto_item_add_subtree(tv, ett_vrrp_ver_type);
123 proto_tree_add_uint(ver_type_tree, hf_vrrp_version, tvb,
124 offset, 1, ver_type);
125 proto_tree_add_uint(ver_type_tree, hf_vrrp_type, tvb, offset, 1,
129 proto_tree_add_text(vrrp_tree, tvb, offset, 1,
130 "Virtual Router ID: %u",
131 tvb_get_guint8(tvb, offset));
134 priority = tvb_get_guint8(tvb, offset);
135 proto_tree_add_text(vrrp_tree, tvb, offset, 1, "Priority: %u (%s)",
137 val_to_str(priority, vrrp_prio_vals, "Non-default backup priority"));
140 ip_count = tvb_get_guint8(tvb, offset);
141 proto_tree_add_text(vrrp_tree, tvb, offset, 1,
142 "Count IP Addrs: %u", ip_count);
145 auth_type = tvb_get_guint8(tvb, offset);
146 proto_tree_add_text(vrrp_tree, tvb, offset, 1,
147 "Authentication Type: %u (%s)", auth_type,
148 val_to_str(auth_type, vrrp_auth_vals, "Unknown"));
151 adver_int = tvb_get_guint8(tvb, offset);
152 proto_tree_add_text(vrrp_tree, tvb, offset, 1,
153 "Advertisement Interval: %u second%s",
154 adver_int, plurality(adver_int, "", "s"));
157 cksum = tvb_get_ntohs(tvb, offset);
158 vrrp_len = tvb_reported_length(tvb);
159 if (!pinfo->fragmented && tvb_length(tvb) >= vrrp_len) {
160 /* The packet isn't part of a fragmented datagram
161 and isn't truncated, so we can checksum it. */
162 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, vrrp_len);
163 cksum_vec[0].len = vrrp_len;
164 computed_cksum = in_cksum(&cksum_vec[0], 1);
165 if (computed_cksum == 0) {
166 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
167 "Checksum: 0x%04x (correct)",
170 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
171 "Checksum: 0x%04x (incorrect, should be 0x%04x)",
173 in_cksum_shouldbe(cksum, computed_cksum));
176 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
177 "Checksum: 0x%04x", cksum);
181 while (ip_count > 0) {
182 proto_tree_add_text(vrrp_tree, tvb, offset, 4,
183 "Virtual Router IP address: %s",
184 ip_to_str(tvb_get_ptr(tvb, offset, 4)));
189 if (auth_type != VRRP_AUTH_TYPE_SIMPLE_TEXT)
190 return; /* Contents of the authentication data is undefined */
192 tvb_get_nstringz0(tvb, offset, VRRP_AUTH_DATA_LEN, auth_buf);
193 if (auth_buf[0] != '\0')
194 proto_tree_add_text(vrrp_tree, tvb, offset,
196 "Authentication string: `%s'",
202 void proto_register_vrrp(void)
204 static hf_register_info hf[] = {
206 {"VRRP message version and type", "vrrp.typever",
207 FT_UINT8, BASE_DEC, NULL, 0x0,
208 "VRRP version and type"}},
211 {"VRRP protocol version", "vrrp.version",
212 FT_UINT8, BASE_DEC, NULL, VRRP_VERSION_MASK,
216 {"VRRP packet type", "vrrp.type",
217 FT_UINT8, BASE_DEC, VALS(vrrp_type_vals), VRRP_TYPE_MASK,
221 static gint *ett[] = {
226 proto_vrrp = proto_register_protocol("Virtual Router Redundancy Protocol",
228 proto_register_field_array(proto_vrrp, hf, array_length(hf));
229 proto_register_subtree_array(ett, array_length(ett));
235 proto_reg_handoff_vrrp(void)
237 dissector_add("ip.proto", IP_PROTO_VRRP, dissect_vrrp, proto_vrrp);