2 * Routines for the Virtual Router Redundancy Protocol (VRRP)
5 * Heikki Vatiainen <hessu@cs.tut.fi>
7 * $Id: packet-vrrp.c,v 1.27 2003/06/12 06:58:38 guy 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.
34 #include <epan/packet.h>
38 static gint proto_vrrp = -1;
39 static gint ett_vrrp = -1;
40 static gint ett_vrrp_ver_type = -1;
42 static gint hf_vrrp_ver_type = -1;
43 static gint hf_vrrp_version = -1;
44 static gint hf_vrrp_type = -1;
45 static gint hf_vrrp_virt_rtr_id = -1;
46 static gint hf_vrrp_prio = -1;
47 static gint hf_vrrp_count_ip = -1;
48 static gint hf_vrrp_auth_type = -1;
49 static gint hf_vrrp_adver_int = -1;
50 static gint hf_vrrp_ip = -1;
51 static gint hf_vrrp_ip6 = -1;
53 #define VRRP_VERSION_MASK 0xf0
54 #define VRRP_TYPE_MASK 0x0f
55 #define VRRP_AUTH_DATA_LEN 8
57 #define VRRP_TYPE_ADVERTISEMENT 1
58 static const value_string vrrp_type_vals[] = {
59 {VRRP_TYPE_ADVERTISEMENT, "Advertisement"},
63 #define VRRP_AUTH_TYPE_NONE 0
64 #define VRRP_AUTH_TYPE_SIMPLE_TEXT 1
65 #define VRRP_AUTH_TYPE_IP_AUTH_HDR 2
66 static const value_string vrrp_auth_vals[] = {
67 {VRRP_AUTH_TYPE_NONE, "No Authentication"},
68 {VRRP_AUTH_TYPE_SIMPLE_TEXT, "Simple Text Authentication"},
69 {VRRP_AUTH_TYPE_IP_AUTH_HDR, "IP Authentication Header"},
73 #define VRRP_PRIORITY_MASTER_STOPPING 0
74 /* Values between 1 and 254 inclusive are for backup VRRP routers */
75 #define VRRP_PRIORITY_DEFAULT 100
76 #define VRRP_PRIORITY_OWNER 255
77 static const value_string vrrp_prio_vals[] = {
78 {VRRP_PRIORITY_MASTER_STOPPING, "Current Master has stopped participating in VRRP"},
79 {VRRP_PRIORITY_DEFAULT, "Default priority for a backup VRRP router"},
80 {VRRP_PRIORITY_OWNER, "This VRRP router owns the virtual router's IP address(es)"},
86 dissect_vrrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
94 if (check_col(pinfo->cinfo, COL_PROTOCOL))
95 col_set_str(pinfo->cinfo, COL_PROTOCOL, "VRRP");
96 if (check_col(pinfo->cinfo, COL_INFO))
97 col_clear(pinfo->cinfo, COL_INFO);
99 ver_type = tvb_get_guint8(tvb, 0);
100 if (check_col(pinfo->cinfo, COL_INFO)) {
101 col_add_fstr(pinfo->cinfo, COL_INFO, "%s (v%u)",
102 "Announcement", hi_nibble(ver_type));
107 proto_tree *vrrp_tree, *ver_type_tree;
108 guint8 priority, ip_count = 0, auth_type;
109 guint16 cksum, computed_cksum;
110 guint8 auth_buf[VRRP_AUTH_DATA_LEN + 1];
112 ti = proto_tree_add_item(tree, proto_vrrp, tvb, 0, -1, FALSE);
113 vrrp_tree = proto_item_add_subtree(ti, ett_vrrp);
115 tv = proto_tree_add_uint_format(vrrp_tree, hf_vrrp_ver_type,
116 tvb, offset, 1, ver_type,
117 "Version %u, Packet type %u (%s)",
118 hi_nibble(ver_type), lo_nibble(ver_type),
119 val_to_str(lo_nibble(ver_type), vrrp_type_vals, "Unknown"));
120 ver_type_tree = proto_item_add_subtree(tv, ett_vrrp_ver_type);
121 proto_tree_add_uint(ver_type_tree, hf_vrrp_version, tvb,
122 offset, 1, ver_type);
123 proto_tree_add_uint(ver_type_tree, hf_vrrp_type, tvb, offset, 1,
127 proto_tree_add_item(vrrp_tree, hf_vrrp_virt_rtr_id, tvb, offset, 1, FALSE);
130 priority = tvb_get_guint8(tvb, offset);
131 proto_tree_add_uint_format(vrrp_tree, hf_vrrp_prio, tvb, offset, 1, priority, "Priority: %u (%s)",
133 val_to_str(priority, vrrp_prio_vals, "Non-default backup priority"));
136 switch(hi_nibble(ver_type)) {
138 /* Skip reserve field */
143 ip_count = tvb_get_guint8(tvb, offset);
144 proto_tree_add_uint(vrrp_tree, hf_vrrp_count_ip, tvb,
145 offset, 1, ip_count);
150 auth_type = tvb_get_guint8(tvb, offset);
151 proto_tree_add_item(vrrp_tree, hf_vrrp_auth_type, tvb, offset, 1, FALSE);
154 proto_tree_add_item(vrrp_tree, hf_vrrp_adver_int, tvb, offset, 1, FALSE);
157 cksum = tvb_get_ntohs(tvb, offset);
158 vrrp_len = (gint)tvb_reported_length(tvb);
159 if (!pinfo->fragmented && (gint)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 switch(hi_nibble(ver_type)) {
164 /* Set up the fields of the pseudo-header. */
165 cksum_vec[0].ptr = pinfo->src.data;
166 cksum_vec[0].len = pinfo->src.len;
167 cksum_vec[1].ptr = pinfo->dst.data;
168 cksum_vec[1].len = pinfo->dst.len;
169 cksum_vec[2].ptr = (const guint8 *)&phdr;
170 phdr[0] = g_htonl(vrrp_len);
171 phdr[1] = g_htonl(IP_PROTO_VRRP);
172 cksum_vec[2].len = 8;
173 cksum_vec[3].ptr = tvb_get_ptr(tvb, 0, vrrp_len);
174 cksum_vec[3].len = vrrp_len;
175 computed_cksum = in_cksum(cksum_vec, 4);
179 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, vrrp_len);
180 cksum_vec[0].len = vrrp_len;
181 computed_cksum = in_cksum(&cksum_vec[0], 1);
184 if (computed_cksum == 0) {
185 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
186 "Checksum: 0x%04x (correct)",
189 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
190 "Checksum: 0x%04x (incorrect, should be 0x%04x)",
192 in_cksum_shouldbe(cksum, computed_cksum));
195 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
196 "Checksum: 0x%04x", cksum);
200 switch(hi_nibble(ver_type)) {
202 proto_tree_add_item(vrrp_tree, hf_vrrp_ip6, tvb, offset, 16, FALSE);
207 while (ip_count > 0) {
208 proto_tree_add_item(vrrp_tree, hf_vrrp_ip, tvb,
215 if (auth_type != VRRP_AUTH_TYPE_SIMPLE_TEXT)
216 return; /* Contents of the authentication data is undefined */
218 tvb_get_nstringz0(tvb, offset, sizeof auth_buf, auth_buf);
219 if (auth_buf[0] != '\0')
220 proto_tree_add_text(vrrp_tree, tvb, offset,
222 "Authentication string: `%s'",
228 void proto_register_vrrp(void)
230 static hf_register_info hf[] = {
232 {"VRRP message version and type", "vrrp.typever",
233 FT_UINT8, BASE_DEC, NULL, 0x0,
234 "VRRP version and type", HFILL }},
237 {"VRRP protocol version", "vrrp.version",
238 FT_UINT8, BASE_DEC, NULL, VRRP_VERSION_MASK,
239 "VRRP version", HFILL }},
242 {"VRRP packet type", "vrrp.type",
243 FT_UINT8, BASE_DEC, VALS(vrrp_type_vals), VRRP_TYPE_MASK,
244 "VRRP type", HFILL }},
246 { &hf_vrrp_virt_rtr_id,
247 {"Virtual Rtr ID", "vrrp.virt_rtr_id",
248 FT_UINT8, BASE_DEC, NULL, 0x0,
249 "Virtual router this packet is reporting status for", HFILL }},
252 {"Priority", "vrrp.prio",
253 FT_UINT8, BASE_DEC, NULL, 0x0,
254 "Sending VRRP router's priority for the virtual router", HFILL }},
257 {"Count IP Addrs", "vrrp.count_ip_addrs",
258 FT_UINT8, BASE_DEC, NULL, 0x0,
259 "The number of IP addresses contained in this VRRP advertisement", HFILL }},
261 { &hf_vrrp_auth_type,
262 {"Auth Type", "vrrp.auth_type",
263 FT_UINT8, BASE_DEC, VALS(vrrp_auth_vals), 0x0,
264 "The authentication method being utilized", HFILL }},
266 { &hf_vrrp_adver_int,
267 {"Adver Int", "vrrp.adver_int",
268 FT_UINT8, BASE_DEC, NULL, 0x0,
269 "Time interval (in seconds) between ADVERTISEMENTS", HFILL }},
272 {"IP Address", "vrrp.ip_addr",
273 FT_IPv4, 0, NULL, 0x0,
274 "IP address associated with the virtual router", HFILL }},
277 {"IPv6 Address", "vrrp.ipv6_addr",
278 FT_IPv6, 0, NULL, 0x0,
279 "IPv6 address associated with the virtual router", HFILL }},
282 static gint *ett[] = {
287 proto_vrrp = proto_register_protocol("Virtual Router Redundancy Protocol",
289 proto_register_field_array(proto_vrrp, hf, array_length(hf));
290 proto_register_subtree_array(ett, array_length(ett));
296 proto_reg_handoff_vrrp(void)
298 dissector_handle_t vrrp_handle;
300 vrrp_handle = create_dissector_handle(dissect_vrrp, proto_vrrp);
301 dissector_add("ip.proto", IP_PROTO_VRRP, vrrp_handle);