2 * Routines for the Virtual Router Redundancy Protocol (VRRP)
5 * Heikki Vatiainen <hessu@cs.tut.fi>
7 * $Id: packet-vrrp.c,v 1.21 2002/01/24 09:20:52 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.
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;
60 #define VRRP_VERSION_MASK 0xf0
61 #define VRRP_TYPE_MASK 0x0f
62 #define VRRP_AUTH_DATA_LEN 8
64 #define VRRP_TYPE_ADVERTISEMENT 1
65 static const value_string vrrp_type_vals[] = {
66 {VRRP_TYPE_ADVERTISEMENT, "Advertisement"},
70 #define VRRP_AUTH_TYPE_NONE 0
71 #define VRRP_AUTH_TYPE_SIMPLE_TEXT 1
72 #define VRRP_AUTH_TYPE_IP_AUTH_HDR 2
73 static const value_string vrrp_auth_vals[] = {
74 {VRRP_AUTH_TYPE_NONE, "No Authentication"},
75 {VRRP_AUTH_TYPE_SIMPLE_TEXT, "Simple Text Authentication"},
76 {VRRP_AUTH_TYPE_IP_AUTH_HDR, "IP Authentication Header"},
80 #define VRRP_PRIORITY_MASTER_STOPPING 0
81 /* Values between 1 and 254 inclusive are for backup VRRP routers */
82 #define VRRP_PRIORITY_DEFAULT 100
83 #define VRRP_PRIORITY_OWNER 255
84 static const value_string vrrp_prio_vals[] = {
85 {VRRP_PRIORITY_MASTER_STOPPING, "Current Master has stopped participating in VRRP"},
86 {VRRP_PRIORITY_DEFAULT, "Default priority for a backup VRRP router"},
87 {VRRP_PRIORITY_OWNER, "This VRRP router owns the virtual router's IP address(es)"},
93 dissect_vrrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
100 if (check_col(pinfo->cinfo, COL_PROTOCOL))
101 col_set_str(pinfo->cinfo, COL_PROTOCOL, "VRRP");
102 if (check_col(pinfo->cinfo, COL_INFO))
103 col_clear(pinfo->cinfo, COL_INFO);
105 ver_type = tvb_get_guint8(tvb, 0);
106 if (check_col(pinfo->cinfo, COL_INFO)) {
107 col_add_fstr(pinfo->cinfo, COL_INFO, "%s (v%u)",
108 "Announcement", hi_nibble(ver_type));
113 proto_tree *vrrp_tree, *ver_type_tree;
114 guint8 priority, ip_count, auth_type;
115 guint16 cksum, computed_cksum;
116 guint8 auth_buf[VRRP_AUTH_DATA_LEN+1];
118 ti = proto_tree_add_item(tree, proto_vrrp, tvb, 0, -1, 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_item(vrrp_tree, hf_vrrp_virt_rtr_id, tvb, offset, 1, FALSE);
136 priority = tvb_get_guint8(tvb, offset);
137 proto_tree_add_uint_format(vrrp_tree, hf_vrrp_prio, tvb, offset, 1, priority, "Priority: %u (%s)",
139 val_to_str(priority, vrrp_prio_vals, "Non-default backup priority"));
142 ip_count = tvb_get_guint8(tvb, offset);
143 proto_tree_add_uint(vrrp_tree, hf_vrrp_count_ip, tvb, offset, 1, ip_count);
146 auth_type = tvb_get_guint8(tvb, offset);
147 proto_tree_add_item(vrrp_tree, hf_vrrp_auth_type, tvb, offset, 1, FALSE);
150 proto_tree_add_item(vrrp_tree, hf_vrrp_adver_int, tvb, offset, 1, FALSE);
153 cksum = tvb_get_ntohs(tvb, offset);
154 vrrp_len = (gint)tvb_reported_length(tvb);
155 if (!pinfo->fragmented && (gint)tvb_length(tvb) >= vrrp_len) {
156 /* The packet isn't part of a fragmented datagram
157 and isn't truncated, so we can checksum it. */
158 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, vrrp_len);
159 cksum_vec[0].len = vrrp_len;
160 computed_cksum = in_cksum(&cksum_vec[0], 1);
161 if (computed_cksum == 0) {
162 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
163 "Checksum: 0x%04x (correct)",
166 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
167 "Checksum: 0x%04x (incorrect, should be 0x%04x)",
169 in_cksum_shouldbe(cksum, computed_cksum));
172 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
173 "Checksum: 0x%04x", cksum);
177 while (ip_count > 0) {
178 proto_tree_add_item(vrrp_tree, hf_vrrp_ip, tvb, offset, 4, FALSE);
183 if (auth_type != VRRP_AUTH_TYPE_SIMPLE_TEXT)
184 return; /* Contents of the authentication data is undefined */
186 tvb_get_nstringz0(tvb, offset, VRRP_AUTH_DATA_LEN, auth_buf);
187 if (auth_buf[0] != '\0')
188 proto_tree_add_text(vrrp_tree, tvb, offset,
190 "Authentication string: `%s'",
196 void proto_register_vrrp(void)
198 static hf_register_info hf[] = {
200 {"VRRP message version and type", "vrrp.typever",
201 FT_UINT8, BASE_DEC, NULL, 0x0,
202 "VRRP version and type", HFILL }},
205 {"VRRP protocol version", "vrrp.version",
206 FT_UINT8, BASE_DEC, NULL, VRRP_VERSION_MASK,
207 "VRRP version", HFILL }},
210 {"VRRP packet type", "vrrp.type",
211 FT_UINT8, BASE_DEC, VALS(vrrp_type_vals), VRRP_TYPE_MASK,
212 "VRRP type", HFILL }},
214 { &hf_vrrp_virt_rtr_id,
215 {"Virtual Rtr ID", "vrrp.virt_rtr_id",
216 FT_UINT8, BASE_DEC, NULL, 0x0,
217 "Virtual router this packet is reporting status for", HFILL }},
220 {"Priority", "vrrp.prio",
221 FT_UINT8, BASE_DEC, NULL, 0x0,
222 "Sending VRRP router's priority for the virtual router", HFILL }},
225 {"Count IP Addrs", "vrrp.count_ip_addrs",
226 FT_UINT8, BASE_DEC, NULL, 0x0,
227 "The number of IP addresses contained in this VRRP advertisement", HFILL }},
229 { &hf_vrrp_auth_type,
230 {"Auth Type", "vrrp.auth_type",
231 FT_UINT8, BASE_DEC, VALS(vrrp_auth_vals), 0x0,
232 "The authentication method being utilized", HFILL }},
234 { &hf_vrrp_adver_int,
235 {"Adver Int", "vrrp.adver_int",
236 FT_UINT8, BASE_DEC, NULL, 0x0,
237 "Time interval (in seconds) between ADVERTISEMENTS", HFILL }},
240 {"IP Address", "vrrp.ip_addr",
241 FT_IPv4, 0, NULL, 0x0,
242 "IP address associated with the virtual router", HFILL }},
246 static gint *ett[] = {
251 proto_vrrp = proto_register_protocol("Virtual Router Redundancy Protocol",
253 proto_register_field_array(proto_vrrp, hf, array_length(hf));
254 proto_register_subtree_array(ett, array_length(ett));
260 proto_reg_handoff_vrrp(void)
262 dissector_handle_t vrrp_handle;
264 vrrp_handle = create_dissector_handle(dissect_vrrp, proto_vrrp);
265 dissector_add("ip.proto", IP_PROTO_VRRP, vrrp_handle);