2 * Routines for the Cisco Hot Standby Router Protocol (HSRP)
5 * Heikki Vatiainen <hessu@cs.tut.fi>
7 * $Id: packet-hsrp.c,v 1.14 2001/01/03 16:41:06 gram Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@zing.org>
11 * Copyright 1998 Gerald Combs
13 * Copied from packet-vrrp.c
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License
17 * as published by the Free Software Foundation; either version 2
18 * of the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
34 #ifdef HAVE_SYS_TYPES_H
35 # include <sys/types.h>
38 #ifdef HAVE_NETINET_IN_H
39 #include <netinet/in.h>
46 static gint proto_hsrp = -1;
48 static gint hf_hsrp_version = -1;
49 static gint hf_hsrp_opcode = -1;
50 static gint hf_hsrp_state = -1;
51 static gint hf_hsrp_hellotime = -1;
52 static gint hf_hsrp_holdtime = -1;
53 static gint hf_hsrp_priority = -1;
54 static gint hf_hsrp_group = -1;
55 static gint hf_hsrp_reserved = -1;
56 static gint hf_hsrp_auth_data = -1;
57 static gint hf_hsrp_virt_ip_addr = -1;
59 static gint ett_hsrp = -1;
61 #define UDP_PORT_HSRP 1985
63 struct hsrp_packet { /* Multicast to 224.0.0.2, TTL 1, UDP, port 1985 */
64 guint8 version; /* RFC2281 describes version 0 */
67 #define HSRP_DEFAULT_HELLOTIME 3
68 guint8 hellotime; /* In seconds */
69 #define HSRP_DEFAULT_HOLDTIME 10
70 guint8 holdtime; /* In seconds */
71 guint8 priority; /* Higher is stronger, highest IP address tie-breaker */
72 guint8 group; /* Identifies the standby group */
74 guint8 auth_data[8]; /* Clear-text password, recommended default is `cisco' */
75 guint32 virt_ip_addr; /* The virtual IP address used by this group */
79 #define HSRP_OPCODE_HELLO 0
80 #define HSRP_OPCODE_COUP 1
81 #define HSRP_OPCODE_RESIGN 2
82 static const value_string hsrp_opcode_vals[] = {
83 {HSRP_OPCODE_HELLO, "Hello"},
84 {HSRP_OPCODE_COUP, "Coup"},
85 {HSRP_OPCODE_RESIGN, "Resign"},
89 #define HSRP_STATE_INITIAL 0
90 #define HSRP_STATE_LEARN 1
91 #define HSRP_STATE_LISTEN 2
92 #define HSRP_STATE_SPEAK 4
93 #define HSRP_STATE_STANDBY 8
94 #define HSRP_STATE_ACTIVE 16
95 static const value_string hsrp_state_vals[] = {
96 {HSRP_STATE_INITIAL, "Initial"},
97 {HSRP_STATE_LEARN, "Learn"},
98 {HSRP_STATE_LISTEN, "Listen"},
99 {HSRP_STATE_SPEAK, "Speak"},
100 {HSRP_STATE_STANDBY, "Standby"},
101 {HSRP_STATE_ACTIVE, "Active"},
106 dissect_hsrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
108 guint8 opcode, state;
110 CHECK_DISPLAY_AS_DATA(proto_hsrp, tvb, pinfo, tree);
112 pinfo->current_proto = "HSRP";
114 if (check_col(pinfo->fd, COL_PROTOCOL))
115 col_set_str(pinfo->fd, COL_PROTOCOL, "HSRP");
117 opcode = tvb_get_guint8(tvb, 1);
118 state = tvb_get_guint8(tvb, 2);
119 if (check_col(pinfo->fd, COL_INFO)) {
120 col_add_fstr(pinfo->fd, COL_INFO, "%s (state %s)",
121 val_to_str(opcode, hsrp_opcode_vals, "Unknown"),
122 val_to_str(state, hsrp_state_vals, "Unknown"));
127 proto_tree *hsrp_tree;
129 guint8 hellotime, holdtime;
130 guint8 auth_buf[8 + 1];
131 guint32 virt_ip_addr;
134 ti = proto_tree_add_item(tree, proto_hsrp, tvb, offset, tvb_length(tvb), FALSE);
135 hsrp_tree = proto_item_add_subtree(ti, ett_hsrp);
137 proto_tree_add_uint(hsrp_tree, hf_hsrp_version, tvb, offset, 1, tvb_get_guint8(tvb, offset));
139 proto_tree_add_uint(hsrp_tree, hf_hsrp_opcode, tvb, offset, 1, opcode);
141 proto_tree_add_uint(hsrp_tree, hf_hsrp_state, tvb, offset, 1, state);
143 hellotime = tvb_get_guint8(tvb, offset);
144 proto_tree_add_uint_format(hsrp_tree, hf_hsrp_hellotime, tvb, offset, 1, hellotime,
145 "Hellotime: %sDefault (%u)",
146 (hellotime == HSRP_DEFAULT_HELLOTIME) ? "" : "Non-",
149 holdtime = tvb_get_guint8(tvb, offset);
150 proto_tree_add_uint_format(hsrp_tree, hf_hsrp_holdtime, tvb, offset, 1, holdtime,
151 "Holdtime: %sDefault (%u)",
152 (holdtime == HSRP_DEFAULT_HOLDTIME) ? "" : "Non-",
155 proto_tree_add_item(hsrp_tree, hf_hsrp_priority, tvb, offset, 1, tvb_get_guint8(tvb, offset));
157 proto_tree_add_item(hsrp_tree, hf_hsrp_group, tvb, offset, 1, tvb_get_guint8(tvb, offset));
159 proto_tree_add_item(hsrp_tree, hf_hsrp_reserved, tvb, offset, 1, tvb_get_guint8(tvb, offset));
161 tvb_memcpy(tvb, auth_buf, offset, 8);
162 auth_buf[sizeof auth_buf - 1] = '\0';
163 proto_tree_add_string_format(hsrp_tree, hf_hsrp_auth_data, tvb, offset, 8, auth_buf,
164 "Authentication Data: %sDefault (%s)",
165 (tvb_strneql(tvb, offset, "cisco", strlen("cisco"))) == 0 ? "" : "Non-",
168 tvb_memcpy(tvb, (guint8 *)&virt_ip_addr, offset, 4);
169 proto_tree_add_ipv4(hsrp_tree, hf_hsrp_virt_ip_addr, tvb, offset, 4, virt_ip_addr);
177 void proto_register_hsrp(void)
179 static hf_register_info hf[] = {
181 { "Version", "hsrp.version",
182 FT_UINT8, BASE_DEC, NULL, 0x0,
183 "The version of the HSRP messages"}},
186 { "Op Code", "hsrp.opcode",
187 FT_UINT8, BASE_DEC, VALS(hsrp_opcode_vals), 0x0,
188 "The type of message contained in this packet" }},
191 { "State", "hsrp.state",
192 FT_UINT8, BASE_DEC, VALS(hsrp_state_vals), 0x0,
193 "The current state of the router sending the message" }},
195 { &hf_hsrp_hellotime,
196 { "Hellotime", "hsrp.hellotime",
197 FT_UINT8, BASE_DEC, NULL, 0x0,
198 "The approximate period between the Hello messages that the router sends" }},
201 { "Holdtime", "hsrp.holdtime",
202 FT_UINT8, BASE_DEC, NULL, 0x0,
203 "Time that the current Hello message should be considered valid" }},
206 { "Priority", "hsrp.priority",
207 FT_UINT8, BASE_DEC, NULL, 0x0,
208 "Used to elect the active and standby routers. Numerically higher priority wins vote" }},
211 { "Group", "hsrp.group",
212 FT_UINT8, BASE_DEC, NULL, 0x0,
213 "This field identifies the standby group" }},
216 { "Reserved", "hsrp.reserved",
217 FT_UINT8, BASE_DEC, NULL, 0x0,
220 { &hf_hsrp_auth_data,
221 { "Authentication Data", "hsrp.auth_data",
222 FT_STRING, 0, NULL, 0x0,
223 "Contains a clear-text 8 character reused password" }},
225 { &hf_hsrp_virt_ip_addr,
226 { "Virtual IP Address", "hsrp.virt_ip",
227 FT_IPv4, 0, NULL, 0x0,
228 "The virtual IP address used by this group" }},
232 static gint *ett[] = {
236 proto_hsrp = proto_register_protocol("Cisco Hot Standby Router Protocol",
238 proto_register_field_array(proto_hsrp, hf, array_length(hf));
239 proto_register_subtree_array(ett, array_length(ett));
245 proto_reg_handoff_hsrp(void)
247 dissector_add("udp.port", UDP_PORT_HSRP, dissect_hsrp);