2 * Routines for the Virtual Router Redundancy Protocol (VRRP)
5 * Heikki Vatiainen <hessu@cs.tut.fi>
7 * $Id: packet-vrrp.c,v 1.17 2001/07/12 19:43:59 guy Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
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>
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;
54 static gint hf_vrrp_virt_rtr_id = -1;
55 static gint hf_vrrp_prio = -1;
56 static gint hf_vrrp_count_ip = -1;
57 static gint hf_vrrp_auth_type = -1;
58 static gint hf_vrrp_adver_int = -1;
59 static gint hf_vrrp_ip = -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)
101 if (check_col(pinfo->fd, COL_PROTOCOL))
102 col_set_str(pinfo->fd, COL_PROTOCOL, "VRRP");
103 if (check_col(pinfo->fd, COL_INFO))
104 col_clear(pinfo->fd, COL_INFO);
106 ver_type = tvb_get_guint8(tvb, 0);
107 if (check_col(pinfo->fd, COL_INFO)) {
108 col_add_fstr(pinfo->fd, COL_INFO, "%s (v%u)",
109 "Announcement", hi_nibble(ver_type));
114 proto_tree *vrrp_tree, *ver_type_tree;
115 guint8 priority, ip_count, auth_type;
116 guint16 cksum, computed_cksum;
117 guint8 auth_buf[VRRP_AUTH_DATA_LEN+1];
119 ti = proto_tree_add_item(tree, proto_vrrp, tvb, 0,
120 tvb_length(tvb), 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 ip_count = tvb_get_guint8(tvb, offset);
145 proto_tree_add_uint(vrrp_tree, hf_vrrp_count_ip, tvb, offset, 1, ip_count);
148 auth_type = tvb_get_guint8(tvb, offset);
149 proto_tree_add_item(vrrp_tree, hf_vrrp_auth_type, tvb, offset, 1, FALSE);
152 proto_tree_add_item(vrrp_tree, hf_vrrp_adver_int, tvb, offset, 1, FALSE);
155 cksum = tvb_get_ntohs(tvb, offset);
156 vrrp_len = (gint)tvb_reported_length(tvb);
157 if (!pinfo->fragmented && (gint)tvb_length(tvb) >= vrrp_len) {
158 /* The packet isn't part of a fragmented datagram
159 and isn't truncated, so we can checksum it. */
160 cksum_vec[0].ptr = tvb_get_ptr(tvb, 0, vrrp_len);
161 cksum_vec[0].len = vrrp_len;
162 computed_cksum = in_cksum(&cksum_vec[0], 1);
163 if (computed_cksum == 0) {
164 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
165 "Checksum: 0x%04x (correct)",
168 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
169 "Checksum: 0x%04x (incorrect, should be 0x%04x)",
171 in_cksum_shouldbe(cksum, computed_cksum));
174 proto_tree_add_text(vrrp_tree, tvb, offset, 2,
175 "Checksum: 0x%04x", cksum);
179 while (ip_count > 0) {
180 proto_tree_add_item(vrrp_tree, hf_vrrp_ip, tvb, offset, 4, FALSE);
185 if (auth_type != VRRP_AUTH_TYPE_SIMPLE_TEXT)
186 return; /* Contents of the authentication data is undefined */
188 tvb_get_nstringz0(tvb, offset, VRRP_AUTH_DATA_LEN, auth_buf);
189 if (auth_buf[0] != '\0')
190 proto_tree_add_text(vrrp_tree, tvb, offset,
192 "Authentication string: `%s'",
198 void proto_register_vrrp(void)
200 static hf_register_info hf[] = {
202 {"VRRP message version and type", "vrrp.typever",
203 FT_UINT8, BASE_DEC, NULL, 0x0,
204 "VRRP version and type", HFILL }},
207 {"VRRP protocol version", "vrrp.version",
208 FT_UINT8, BASE_DEC, NULL, VRRP_VERSION_MASK,
209 "VRRP version", HFILL }},
212 {"VRRP packet type", "vrrp.type",
213 FT_UINT8, BASE_DEC, VALS(vrrp_type_vals), VRRP_TYPE_MASK,
214 "VRRP type", HFILL }},
216 { &hf_vrrp_virt_rtr_id,
217 {"Virtual Rtr ID", "vrrp.virt_rtr_id",
218 FT_UINT8, BASE_DEC, NULL, 0x0,
219 "Virtual router this packet is reporting status for", HFILL }},
222 {"Priority", "vrrp.prio",
223 FT_UINT8, BASE_DEC, NULL, 0x0,
224 "Sending VRRP router's priority for the virtual router", HFILL }},
227 {"Count IP Addrs", "vrrp.count_ip_addrs",
228 FT_UINT8, BASE_DEC, NULL, 0x0,
229 "The number of IP addresses contained in this VRRP advertisement", HFILL }},
231 { &hf_vrrp_auth_type,
232 {"Auth Type", "vrrp.auth_type",
233 FT_UINT8, BASE_DEC, VALS(vrrp_auth_vals), 0x0,
234 "The authentication method being utilized", HFILL }},
236 { &hf_vrrp_adver_int,
237 {"Adver Int", "vrrp.adver_int",
238 FT_UINT8, BASE_DEC, NULL, 0x0,
239 "Time interval (in seconds) between ADVERTISEMENTS", HFILL }},
242 {"IP Address", "vrrp.ip_addr",
243 FT_IPv4, 0, NULL, 0x0,
244 "IP address associated with the virtual router", HFILL }},
248 static gint *ett[] = {
253 proto_vrrp = proto_register_protocol("Virtual Router Redundancy Protocol",
255 proto_register_field_array(proto_vrrp, hf, array_length(hf));
256 proto_register_subtree_array(ett, array_length(ett));
262 proto_reg_handoff_vrrp(void)
264 dissector_add("ip.proto", IP_PROTO_VRRP, dissect_vrrp, proto_vrrp);