2 * Routines for the Virtual Router Redundancy Protocol (VRRP)
5 * Heikki Vatiainen <hessu@cs.tut.fi>
7 * $Id: packet-vrrp.c,v 1.2 2000/01/07 22:05:42 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>
45 static gint proto_vrrp = -1;
46 static gint ett_vrrp = -1;
47 static gint ett_vrrp_ver_type = -1;
49 static gint hf_vrrp_ver_type = -1;
50 static gint hf_vrrp_version = -1;
51 static gint hf_vrrp_type = -1;
54 #define VRRP_VERSION_MASK 0xf0
55 #define VRRP_TYPE_MASK 0x0f
59 guint8 count_ip_addrs;
63 /* One or more IP addresses */
64 /* 8 octets of authentication data */
65 #define VRRP_AUTH_DATA_LEN 8
69 #define VRRP_TYPE_ADVERTISEMENT 1
70 static const value_string vrrp_type_vals[] = {
71 {VRRP_TYPE_ADVERTISEMENT, "Advertisement"}
74 #define VRRP_AUTH_TYPE_NONE 0
75 #define VRRP_AUTH_TYPE_SIMPLE_TEXT 1
76 #define VRRP_AUTH_TYPE_IP_AUTH_HDR 2
77 static const value_string vrrp_auth_vals[] = {
78 {VRRP_AUTH_TYPE_NONE, "No Authentication"},
79 {VRRP_AUTH_TYPE_SIMPLE_TEXT, "Simple Text Authentication"},
80 {VRRP_AUTH_TYPE_IP_AUTH_HDR, "IP Authentication Header"}
83 #define VRRP_PRIORITY_MASTER_STOPPING 0
84 /* Values between 1 and 254 inclusive are for backup VRRP routers */
85 #define VRRP_PRIORITY_DEFAULT 100
86 #define VRRP_PRIORITY_OWNER 255
87 static const value_string vrrp_prio_vals[] = {
88 {VRRP_PRIORITY_MASTER_STOPPING, "Current Master has stopped participating in VRRP"},
89 {VRRP_PRIORITY_DEFAULT, "Default priority for a backup VRRP router"},
90 {VRRP_PRIORITY_OWNER, "This VRRP router owns the virtual router's IP address(es)"}
94 void dissect_vrrp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
96 struct vrrp_header vrh;
97 gboolean short_hdr = FALSE;
98 gboolean short_packet = FALSE;
99 guint calculated_len = -1; /* initialize to silence false warning from gcc */
101 if (sizeof(struct vrrp_header) > END_OF_FRAME)
102 short_hdr = short_packet = TRUE;
104 memcpy(&vrh, pd + offset, sizeof(struct vrrp_header));
105 calculated_len = sizeof(struct vrrp_header) + vrh.count_ip_addrs*4 + VRRP_AUTH_DATA_LEN;
106 if (calculated_len > END_OF_FRAME)
110 if (check_col(fd, COL_PROTOCOL))
111 col_add_str(fd, COL_PROTOCOL, "VRRP");
113 if (check_col(fd, COL_INFO)) {
115 col_add_fstr(fd, COL_INFO, "Short packet header, length %u", END_OF_FRAME);
116 else if (short_packet)
117 col_add_fstr(fd, COL_INFO, "Packet length mismatch, calculated %u, real %u",
118 calculated_len, END_OF_FRAME);
120 col_add_fstr(fd, COL_INFO, "%s (v%u)", "Announcement", hi_nibble(vrh.ver_type));
125 proto_tree *vrrp_tree, *ver_type_tree;
126 guint8 ip_count, auth_len, auth_buf[VRRP_AUTH_DATA_LEN+1];
129 dissect_data(pd, offset, fd, tree);
133 ti = proto_tree_add_item(tree, proto_vrrp, offset, END_OF_FRAME, NULL);
134 vrrp_tree = proto_item_add_subtree(ti, ett_vrrp);
136 tv = proto_tree_add_item_format(vrrp_tree, hf_vrrp_ver_type, offset, 1,
137 vrh.ver_type, "Version %u, Packet type %u (%s)",
138 hi_nibble(vrh.ver_type), lo_nibble(vrh.ver_type),
139 val_to_str(lo_nibble(vrh.ver_type), vrrp_type_vals, "Unknown"));
140 ver_type_tree = proto_item_add_subtree(tv, ett_vrrp_ver_type);
141 proto_tree_add_item(ver_type_tree, hf_vrrp_version, offset, 1, vrh.ver_type);
142 proto_tree_add_item(ver_type_tree, hf_vrrp_type, offset, 1, vrh.ver_type);
145 proto_tree_add_text(vrrp_tree, offset++, 1, "Virtual Router ID: %u", vrh.vrouter_id);
146 proto_tree_add_text(vrrp_tree, offset++, 1, "Priority: %u (%s)", vrh.priority,
147 val_to_str(vrh.priority, vrrp_prio_vals, "Non-default backup priority"));
148 proto_tree_add_text(vrrp_tree, offset++, 1, "Count IP Addrs: %u", vrh.count_ip_addrs);
149 proto_tree_add_text(vrrp_tree, offset++, 1, "Authentication Type: %u (%s)", vrh.auth_type,
150 val_to_str(vrh.auth_type, vrrp_auth_vals, "Unknown"));
151 proto_tree_add_text(vrrp_tree, offset++, 1, "Advertisement Interval: %u second%s",
152 vrh.adver_int, plurality(vrh.adver_int, "", "s"));
153 proto_tree_add_text(vrrp_tree, offset, 2, "Checksum: 0x%x", htons(vrh.checksum));
157 dissect_data(pd, offset, fd, vrrp_tree);
161 ip_count = vrh.count_ip_addrs;
162 while (ip_count > 0) {
163 proto_tree_add_text(vrrp_tree, offset, 4, "Virtual Router IP address: %s",
164 ip_to_str(pd+offset));
169 if (vrh.auth_type != VRRP_AUTH_TYPE_SIMPLE_TEXT)
170 return; /* Contents of the authentication data is undefined */
172 strncpy(auth_buf, pd+offset, VRRP_AUTH_DATA_LEN);
173 auth_buf[VRRP_AUTH_DATA_LEN] = '\0';
174 auth_len = strlen(auth_buf);
176 proto_tree_add_text(vrrp_tree, offset, auth_len, "Authentication string: `%s'", auth_buf);
184 void proto_register_vrrp(void)
186 static hf_register_info hf[] = {
188 {"VRRP message version and type", "vrrp.typever",
189 FT_UINT8, BASE_DEC, NULL, 0x0,
190 "VRRP version and type"}},
193 {"VRRP protocol version", "vrrp.version",
194 FT_UINT8, BASE_DEC, NULL, VRRP_VERSION_MASK,
198 {"VRRP packet type", "vrrp.type",
199 FT_UINT8, BASE_DEC, VALS(vrrp_type_vals), VRRP_TYPE_MASK,
203 static gint *ett[] = {
208 proto_vrrp = proto_register_protocol("Virtual Router Redundancy Protocol", "vrrp");
209 proto_register_field_array(proto_vrrp, hf, array_length(hf));
210 proto_register_subtree_array(ett, array_length(ett));