2 * Routines for the Virtual Router Redundancy Protocol (VRRP)
5 * Heikki Vatiainen <hessu@cs.tut.fi>
7 * $Id: packet-vrrp.c,v 1.7 2000/08/07 03:21:19 guy 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"}
75 #define VRRP_AUTH_TYPE_NONE 0
76 #define VRRP_AUTH_TYPE_SIMPLE_TEXT 1
77 #define VRRP_AUTH_TYPE_IP_AUTH_HDR 2
78 static const value_string vrrp_auth_vals[] = {
79 {VRRP_AUTH_TYPE_NONE, "No Authentication"},
80 {VRRP_AUTH_TYPE_SIMPLE_TEXT, "Simple Text Authentication"},
81 {VRRP_AUTH_TYPE_IP_AUTH_HDR, "IP Authentication Header"}
84 #define VRRP_PRIORITY_MASTER_STOPPING 0
85 /* Values between 1 and 254 inclusive are for backup VRRP routers */
86 #define VRRP_PRIORITY_DEFAULT 100
87 #define VRRP_PRIORITY_OWNER 255
88 static const value_string vrrp_prio_vals[] = {
89 {VRRP_PRIORITY_MASTER_STOPPING, "Current Master has stopped participating in VRRP"},
90 {VRRP_PRIORITY_DEFAULT, "Default priority for a backup VRRP router"},
91 {VRRP_PRIORITY_OWNER, "This VRRP router owns the virtual router's IP address(es)"}
96 dissect_vrrp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
98 struct vrrp_header vrh;
99 gboolean short_hdr = FALSE;
100 gboolean short_packet = FALSE;
101 guint calculated_len = -1; /* initialize to silence false warning from gcc */
103 if (sizeof(struct vrrp_header) > END_OF_FRAME)
104 short_hdr = short_packet = TRUE;
106 memcpy(&vrh, pd + offset, sizeof(struct vrrp_header));
107 calculated_len = sizeof(struct vrrp_header) + vrh.count_ip_addrs*4 + VRRP_AUTH_DATA_LEN;
108 if (calculated_len > END_OF_FRAME)
112 if (check_col(fd, COL_PROTOCOL))
113 col_add_str(fd, COL_PROTOCOL, "VRRP");
115 if (check_col(fd, COL_INFO)) {
117 col_add_fstr(fd, COL_INFO, "Short packet header, length %u", END_OF_FRAME);
118 else if (short_packet)
119 col_add_fstr(fd, COL_INFO, "Packet length mismatch, calculated %u, real %u",
120 calculated_len, END_OF_FRAME);
122 col_add_fstr(fd, COL_INFO, "%s (v%u)", "Announcement", hi_nibble(vrh.ver_type));
127 proto_tree *vrrp_tree, *ver_type_tree;
128 guint8 ip_count, auth_len, auth_buf[VRRP_AUTH_DATA_LEN+1];
131 old_dissect_data(pd, offset, fd, tree);
135 ti = proto_tree_add_item(tree, proto_vrrp, NullTVB, offset, END_OF_FRAME, FALSE);
136 vrrp_tree = proto_item_add_subtree(ti, ett_vrrp);
138 tv = proto_tree_add_uint_format(vrrp_tree, hf_vrrp_ver_type, NullTVB, offset, 1,
139 vrh.ver_type, "Version %u, Packet type %u (%s)",
140 hi_nibble(vrh.ver_type), lo_nibble(vrh.ver_type),
141 val_to_str(lo_nibble(vrh.ver_type), vrrp_type_vals, "Unknown"));
142 ver_type_tree = proto_item_add_subtree(tv, ett_vrrp_ver_type);
143 proto_tree_add_uint(ver_type_tree, hf_vrrp_version, NullTVB, offset, 1, vrh.ver_type);
144 proto_tree_add_uint(ver_type_tree, hf_vrrp_type, NullTVB, offset, 1, vrh.ver_type);
147 proto_tree_add_text(vrrp_tree, NullTVB, offset++, 1, "Virtual Router ID: %u", vrh.vrouter_id);
148 proto_tree_add_text(vrrp_tree, NullTVB, offset++, 1, "Priority: %u (%s)", vrh.priority,
149 val_to_str(vrh.priority, vrrp_prio_vals, "Non-default backup priority"));
150 proto_tree_add_text(vrrp_tree, NullTVB, offset++, 1, "Count IP Addrs: %u", vrh.count_ip_addrs);
151 proto_tree_add_text(vrrp_tree, NullTVB, offset++, 1, "Authentication Type: %u (%s)", vrh.auth_type,
152 val_to_str(vrh.auth_type, vrrp_auth_vals, "Unknown"));
153 proto_tree_add_text(vrrp_tree, NullTVB, offset++, 1, "Advertisement Interval: %u second%s",
154 vrh.adver_int, plurality(vrh.adver_int, "", "s"));
155 proto_tree_add_text(vrrp_tree, NullTVB, offset, 2, "Checksum: 0x%x", htons(vrh.checksum));
159 old_dissect_data(pd, offset, fd, vrrp_tree);
163 ip_count = vrh.count_ip_addrs;
164 while (ip_count > 0) {
165 proto_tree_add_text(vrrp_tree, NullTVB, offset, 4, "Virtual Router IP address: %s",
166 ip_to_str(pd+offset));
171 if (vrh.auth_type != VRRP_AUTH_TYPE_SIMPLE_TEXT)
172 return; /* Contents of the authentication data is undefined */
174 strncpy(auth_buf, pd+offset, VRRP_AUTH_DATA_LEN);
175 auth_buf[VRRP_AUTH_DATA_LEN] = '\0';
176 auth_len = strlen(auth_buf);
178 proto_tree_add_text(vrrp_tree, NullTVB, offset, auth_len, "Authentication string: `%s'", auth_buf);
186 void proto_register_vrrp(void)
188 static hf_register_info hf[] = {
190 {"VRRP message version and type", "vrrp.typever",
191 FT_UINT8, BASE_DEC, NULL, 0x0,
192 "VRRP version and type"}},
195 {"VRRP protocol version", "vrrp.version",
196 FT_UINT8, BASE_DEC, NULL, VRRP_VERSION_MASK,
200 {"VRRP packet type", "vrrp.type",
201 FT_UINT8, BASE_DEC, VALS(vrrp_type_vals), VRRP_TYPE_MASK,
205 static gint *ett[] = {
210 proto_vrrp = proto_register_protocol("Virtual Router Redundancy Protocol", "vrrp");
211 proto_register_field_array(proto_vrrp, hf, array_length(hf));
212 proto_register_subtree_array(ett, array_length(ett));
218 proto_reg_handoff_vrrp(void)
220 old_dissector_add("ip.proto", IP_PROTO_VRRP, dissect_vrrp);