2 * Routines for the Virtual Router Redundancy Protocol (VRRP)
5 * Heikki Vatiainen <hessu@cs.tut.fi>
7 * $Id: packet-vrrp.c,v 1.11 2001/01/03 16:41:07 gram 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"
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;
55 #define VRRP_VERSION_MASK 0xf0
56 #define VRRP_TYPE_MASK 0x0f
60 guint8 count_ip_addrs;
64 /* One or more IP addresses */
65 /* 8 octets of authentication data */
66 #define VRRP_AUTH_DATA_LEN 8
70 #define VRRP_TYPE_ADVERTISEMENT 1
71 static const value_string vrrp_type_vals[] = {
72 {VRRP_TYPE_ADVERTISEMENT, "Advertisement"},
76 #define VRRP_AUTH_TYPE_NONE 0
77 #define VRRP_AUTH_TYPE_SIMPLE_TEXT 1
78 #define VRRP_AUTH_TYPE_IP_AUTH_HDR 2
79 static const value_string vrrp_auth_vals[] = {
80 {VRRP_AUTH_TYPE_NONE, "No Authentication"},
81 {VRRP_AUTH_TYPE_SIMPLE_TEXT, "Simple Text Authentication"},
82 {VRRP_AUTH_TYPE_IP_AUTH_HDR, "IP Authentication Header"},
86 #define VRRP_PRIORITY_MASTER_STOPPING 0
87 /* Values between 1 and 254 inclusive are for backup VRRP routers */
88 #define VRRP_PRIORITY_DEFAULT 100
89 #define VRRP_PRIORITY_OWNER 255
90 static const value_string vrrp_prio_vals[] = {
91 {VRRP_PRIORITY_MASTER_STOPPING, "Current Master has stopped participating in VRRP"},
92 {VRRP_PRIORITY_DEFAULT, "Default priority for a backup VRRP router"},
93 {VRRP_PRIORITY_OWNER, "This VRRP router owns the virtual router's IP address(es)"},
99 dissect_vrrp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
101 struct vrrp_header vrh;
102 gboolean short_hdr = FALSE;
103 gboolean short_packet = FALSE;
104 guint calculated_len = -1; /* initialize to silence false warning from gcc */
106 OLD_CHECK_DISPLAY_AS_DATA(proto_vrrp, pd, offset, fd, tree);
108 if (sizeof(struct vrrp_header) > END_OF_FRAME)
109 short_hdr = short_packet = TRUE;
111 memcpy(&vrh, pd + offset, sizeof(struct vrrp_header));
112 calculated_len = sizeof(struct vrrp_header) + vrh.count_ip_addrs*4 + VRRP_AUTH_DATA_LEN;
113 if (calculated_len > END_OF_FRAME)
117 if (check_col(fd, COL_PROTOCOL))
118 col_set_str(fd, COL_PROTOCOL, "VRRP");
120 if (check_col(fd, COL_INFO)) {
122 col_add_fstr(fd, COL_INFO, "Short packet header, length %u", END_OF_FRAME);
123 else if (short_packet)
124 col_add_fstr(fd, COL_INFO, "Packet length mismatch, calculated %u, real %u",
125 calculated_len, END_OF_FRAME);
127 col_add_fstr(fd, COL_INFO, "%s (v%u)", "Announcement", hi_nibble(vrh.ver_type));
132 proto_tree *vrrp_tree, *ver_type_tree;
133 guint8 ip_count, auth_len, auth_buf[VRRP_AUTH_DATA_LEN+1];
136 old_dissect_data(pd, offset, fd, tree);
140 ti = proto_tree_add_item(tree, proto_vrrp, NullTVB, offset, END_OF_FRAME, FALSE);
141 vrrp_tree = proto_item_add_subtree(ti, ett_vrrp);
143 tv = proto_tree_add_uint_format(vrrp_tree, hf_vrrp_ver_type, NullTVB, offset, 1,
144 vrh.ver_type, "Version %u, Packet type %u (%s)",
145 hi_nibble(vrh.ver_type), lo_nibble(vrh.ver_type),
146 val_to_str(lo_nibble(vrh.ver_type), vrrp_type_vals, "Unknown"));
147 ver_type_tree = proto_item_add_subtree(tv, ett_vrrp_ver_type);
148 proto_tree_add_uint(ver_type_tree, hf_vrrp_version, NullTVB, offset, 1, vrh.ver_type);
149 proto_tree_add_uint(ver_type_tree, hf_vrrp_type, NullTVB, offset, 1, vrh.ver_type);
152 proto_tree_add_text(vrrp_tree, NullTVB, offset++, 1, "Virtual Router ID: %u", vrh.vrouter_id);
153 proto_tree_add_text(vrrp_tree, NullTVB, offset++, 1, "Priority: %u (%s)", vrh.priority,
154 val_to_str(vrh.priority, vrrp_prio_vals, "Non-default backup priority"));
155 proto_tree_add_text(vrrp_tree, NullTVB, offset++, 1, "Count IP Addrs: %u", vrh.count_ip_addrs);
156 proto_tree_add_text(vrrp_tree, NullTVB, offset++, 1, "Authentication Type: %u (%s)", vrh.auth_type,
157 val_to_str(vrh.auth_type, vrrp_auth_vals, "Unknown"));
158 proto_tree_add_text(vrrp_tree, NullTVB, offset++, 1, "Advertisement Interval: %u second%s",
159 vrh.adver_int, plurality(vrh.adver_int, "", "s"));
160 proto_tree_add_text(vrrp_tree, NullTVB, offset, 2, "Checksum: 0x%x", htons(vrh.checksum));
164 old_dissect_data(pd, offset, fd, vrrp_tree);
168 ip_count = vrh.count_ip_addrs;
169 while (ip_count > 0) {
170 proto_tree_add_text(vrrp_tree, NullTVB, offset, 4, "Virtual Router IP address: %s",
171 ip_to_str(pd+offset));
176 if (vrh.auth_type != VRRP_AUTH_TYPE_SIMPLE_TEXT)
177 return; /* Contents of the authentication data is undefined */
179 strncpy(auth_buf, pd+offset, VRRP_AUTH_DATA_LEN);
180 auth_buf[VRRP_AUTH_DATA_LEN] = '\0';
181 auth_len = strlen(auth_buf);
183 proto_tree_add_text(vrrp_tree, NullTVB, offset, auth_len, "Authentication string: `%s'", auth_buf);
191 void proto_register_vrrp(void)
193 static hf_register_info hf[] = {
195 {"VRRP message version and type", "vrrp.typever",
196 FT_UINT8, BASE_DEC, NULL, 0x0,
197 "VRRP version and type"}},
200 {"VRRP protocol version", "vrrp.version",
201 FT_UINT8, BASE_DEC, NULL, VRRP_VERSION_MASK,
205 {"VRRP packet type", "vrrp.type",
206 FT_UINT8, BASE_DEC, VALS(vrrp_type_vals), VRRP_TYPE_MASK,
210 static gint *ett[] = {
215 proto_vrrp = proto_register_protocol("Virtual Router Redundancy Protocol",
217 proto_register_field_array(proto_vrrp, hf, array_length(hf));
218 proto_register_subtree_array(ett, array_length(ett));
224 proto_reg_handoff_vrrp(void)
226 old_dissector_add("ip.proto", IP_PROTO_VRRP, dissect_vrrp);