2 * Routines for the Virtual Router Redundancy Protocol (VRRP)
5 * Heikki Vatiainen <hessu@cs.tut.fi>
7 * $Id: packet-vrrp.c,v 1.23 2002/03/28 07:40:54 itojun Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
11 * Copyright 1998 Gerald Combs
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
32 #ifdef HAVE_SYS_TYPES_H
33 # include <sys/types.h>
36 #ifdef HAVE_NETINET_IN_H
37 #include <netinet/in.h>
42 #include <epan/packet.h>
46 static gint proto_vrrp = -1;
47 static gint ett_vrrp = -1;
48 static gint ett_vrrp_ver_type = -1;
50 static gint hf_vrrp_ver_type = -1;
51 static gint hf_vrrp_version = -1;
52 static gint hf_vrrp_type = -1;
53 static gint hf_vrrp_virt_rtr_id = -1;
54 static gint hf_vrrp_prio = -1;
55 static gint hf_vrrp_count_ip = -1;
56 static gint hf_vrrp_auth_type = -1;
57 static gint hf_vrrp_adver_int = -1;
58 static gint hf_vrrp_ip = -1;
59 static gint hf_vrrp_ip6 = -1;
61 #define VRRP_VERSION_MASK 0xf0
62 #define VRRP_TYPE_MASK 0x0f
63 #define VRRP_AUTH_DATA_LEN 8
65 #define VRRP_TYPE_ADVERTISEMENT 1
66 static const value_string vrrp_type_vals[] = {
67 {VRRP_TYPE_ADVERTISEMENT, "Advertisement"},
71 #define VRRP_AUTH_TYPE_NONE 0
72 #define VRRP_AUTH_TYPE_SIMPLE_TEXT 1
73 #define VRRP_AUTH_TYPE_IP_AUTH_HDR 2
74 static const value_string vrrp_auth_vals[] = {
75 {VRRP_AUTH_TYPE_NONE, "No Authentication"},
76 {VRRP_AUTH_TYPE_SIMPLE_TEXT, "Simple Text Authentication"},
77 {VRRP_AUTH_TYPE_IP_AUTH_HDR, "IP Authentication Header"},
81 #define VRRP_PRIORITY_MASTER_STOPPING 0
82 /* Values between 1 and 254 inclusive are for backup VRRP routers */
83 #define VRRP_PRIORITY_DEFAULT 100
84 #define VRRP_PRIORITY_OWNER 255
85 static const value_string vrrp_prio_vals[] = {
86 {VRRP_PRIORITY_MASTER_STOPPING, "Current Master has stopped participating in VRRP"},
87 {VRRP_PRIORITY_DEFAULT, "Default priority for a backup VRRP router"},
88 {VRRP_PRIORITY_OWNER, "This VRRP router owns the virtual router's IP address(es)"},
94 dissect_vrrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
102 if (check_col(pinfo->cinfo, COL_PROTOCOL))
103 col_set_str(pinfo->cinfo, COL_PROTOCOL, "VRRP");
104 if (check_col(pinfo->cinfo, COL_INFO))
105 col_clear(pinfo->cinfo, COL_INFO);
107 ver_type = tvb_get_guint8(tvb, 0);
108 if (check_col(pinfo->cinfo, COL_INFO)) {
109 col_add_fstr(pinfo->cinfo, COL_INFO, "%s (v%u)",
110 "Announcement", hi_nibble(ver_type));
115 proto_tree *vrrp_tree, *ver_type_tree;
116 guint8 priority, ip_count = 0, auth_type;
117 guint16 cksum, computed_cksum;
118 guint8 auth_buf[VRRP_AUTH_DATA_LEN+1];
120 ti = proto_tree_add_item(tree, proto_vrrp, tvb, 0, -1, FALSE);
121 vrrp_tree = proto_item_add_subtree(ti, ett_vrrp);
123 tv = proto_tree_add_uint_format(vrrp_tree, hf_vrrp_ver_type,
124 tvb, offset, 1, ver_type,
125 "Version %u, Packet type %u (%s)",
126 hi_nibble(ver_type), lo_nibble(ver_type),
127 val_to_str(lo_nibble(ver_type), vrrp_type_vals, "Unknown"));
128 ver_type_tree = proto_item_add_subtree(tv, ett_vrrp_ver_type);
129 proto_tree_add_uint(ver_type_tree, hf_vrrp_version, tvb,
130 offset, 1, ver_type);
131 proto_tree_add_uint(ver_type_tree, hf_vrrp_type, tvb, offset, 1,
135 proto_tree_add_item(vrrp_tree, hf_vrrp_virt_rtr_id, tvb, offset, 1, FALSE);
138 priority = tvb_get_guint8(tvb, offset);
139 proto_tree_add_uint_format(vrrp_tree, hf_vrrp_prio, tvb, offset, 1, priority, "Priority: %u (%s)",
141 val_to_str(priority, vrrp_prio_vals, "Non-default backup priority"));
144 switch(hi_nibble(ver_type)) {
146 /* Skip reserve field */
151 ip_count = tvb_get_guint8(tvb, offset);
152 proto_tree_add_uint(vrrp_tree, hf_vrrp_count_ip, tvb,
153 offset, 1, ip_count);
158 auth_type = tvb_get_guint8(tvb, offset);
159 proto_tree_add_item(vrrp_tree, hf_vrrp_auth_type, tvb, offset, 1, FALSE);
162 proto_tree_add_item(vrrp_tree, hf_vrrp_adver_int, tvb, offset, 1, FALSE);
165 cksum = tvb_get_ntohs(tvb, offset);
166 vrrp_len = (gint)tvb_reported_length(tvb);
167 if (!pinfo->fragmented && (gint)tvb_length(tvb) >= vrrp_len) {
168 /* The packet isn't part of a fragmented datagram
169 and isn't truncated, so we can checksum it. */
170 switch(hi_nibble(ver_type)) {
172 /* Set up the fields of the pseudo-header. */
173 cksum_vec[0].ptr = pinfo->src.data;
174 cksum_vec[0].len = pinfo->src.len;
175 cksum_vec[1].ptr = pinfo->dst.data;
176 cksum_vec[1].len = pinfo->dst.len;
177 cksum_vec[2].ptr = (const guint8 *)&phdr;
178 phdr[0] = htonl(vrrp_len);
179 phdr[1] = htonl(IP_PROTO_VRRP);
180 cksum_vec[2].len = 8;
181 cksum_vec[3].ptr = tvb_get_ptr(tvb, 0, vrrp_len);
182 cksum_vec[3].len = vrrp_len;
183 computed_cksum = in_cksum(cksum_vec, 4);
187 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, vrrp_len);
188 cksum_vec[0].len = vrrp_len;
189 computed_cksum = in_cksum(&cksum_vec[0], 1);
192 if (computed_cksum == 0) {
193 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
194 "Checksum: 0x%04x (correct)",
197 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
198 "Checksum: 0x%04x (incorrect, should be 0x%04x)",
200 in_cksum_shouldbe(cksum, computed_cksum));
203 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
204 "Checksum: 0x%04x", cksum);
208 switch(hi_nibble(ver_type)) {
210 proto_tree_add_item(vrrp_tree, hf_vrrp_ip6, tvb, offset, 16, FALSE);
215 while (ip_count > 0) {
216 proto_tree_add_item(vrrp_tree, hf_vrrp_ip, tvb,
223 if (auth_type != VRRP_AUTH_TYPE_SIMPLE_TEXT)
224 return; /* Contents of the authentication data is undefined */
226 tvb_get_nstringz0(tvb, offset, VRRP_AUTH_DATA_LEN, auth_buf);
227 if (auth_buf[0] != '\0')
228 proto_tree_add_text(vrrp_tree, tvb, offset,
230 "Authentication string: `%s'",
236 void proto_register_vrrp(void)
238 static hf_register_info hf[] = {
240 {"VRRP message version and type", "vrrp.typever",
241 FT_UINT8, BASE_DEC, NULL, 0x0,
242 "VRRP version and type", HFILL }},
245 {"VRRP protocol version", "vrrp.version",
246 FT_UINT8, BASE_DEC, NULL, VRRP_VERSION_MASK,
247 "VRRP version", HFILL }},
250 {"VRRP packet type", "vrrp.type",
251 FT_UINT8, BASE_DEC, VALS(vrrp_type_vals), VRRP_TYPE_MASK,
252 "VRRP type", HFILL }},
254 { &hf_vrrp_virt_rtr_id,
255 {"Virtual Rtr ID", "vrrp.virt_rtr_id",
256 FT_UINT8, BASE_DEC, NULL, 0x0,
257 "Virtual router this packet is reporting status for", HFILL }},
260 {"Priority", "vrrp.prio",
261 FT_UINT8, BASE_DEC, NULL, 0x0,
262 "Sending VRRP router's priority for the virtual router", HFILL }},
265 {"Count IP Addrs", "vrrp.count_ip_addrs",
266 FT_UINT8, BASE_DEC, NULL, 0x0,
267 "The number of IP addresses contained in this VRRP advertisement", HFILL }},
269 { &hf_vrrp_auth_type,
270 {"Auth Type", "vrrp.auth_type",
271 FT_UINT8, BASE_DEC, VALS(vrrp_auth_vals), 0x0,
272 "The authentication method being utilized", HFILL }},
274 { &hf_vrrp_adver_int,
275 {"Adver Int", "vrrp.adver_int",
276 FT_UINT8, BASE_DEC, NULL, 0x0,
277 "Time interval (in seconds) between ADVERTISEMENTS", HFILL }},
280 {"IP Address", "vrrp.ip_addr",
281 FT_IPv4, 0, NULL, 0x0,
282 "IP address associated with the virtual router", HFILL }},
285 {"IPv6 Address", "vrrp.ipv6_addr",
286 FT_IPv6, 0, NULL, 0x0,
287 "IPv6 address associated with the virtual router", HFILL }},
290 static gint *ett[] = {
295 proto_vrrp = proto_register_protocol("Virtual Router Redundancy Protocol",
297 proto_register_field_array(proto_vrrp, hf, array_length(hf));
298 proto_register_subtree_array(ett, array_length(ett));
304 proto_reg_handoff_vrrp(void)
306 dissector_handle_t vrrp_handle;
308 vrrp_handle = create_dissector_handle(dissect_vrrp, proto_vrrp);
309 dissector_add("ip.proto", IP_PROTO_VRRP, vrrp_handle);