2 * Routines for the Cisco Hot Standby Router Protocol (HSRP)
5 * Heikki Vatiainen <hessu@cs.tut.fi>
7 * $Id: packet-hsrp.c,v 1.18 2001/07/12 19:42:57 guy 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 if (check_col(pinfo->fd, COL_PROTOCOL))
111 col_set_str(pinfo->fd, COL_PROTOCOL, "HSRP");
112 if (check_col(pinfo->fd, COL_INFO))
113 col_clear(pinfo->fd, COL_INFO);
115 opcode = tvb_get_guint8(tvb, 1);
116 state = tvb_get_guint8(tvb, 2);
117 if (check_col(pinfo->fd, COL_INFO)) {
118 col_add_fstr(pinfo->fd, COL_INFO, "%s (state %s)",
119 val_to_str(opcode, hsrp_opcode_vals, "Unknown"),
120 val_to_str(state, hsrp_state_vals, "Unknown"));
125 proto_tree *hsrp_tree;
127 guint8 hellotime, holdtime;
128 guint8 auth_buf[8 + 1];
131 ti = proto_tree_add_item(tree, proto_hsrp, tvb, offset, tvb_length(tvb), FALSE);
132 hsrp_tree = proto_item_add_subtree(ti, ett_hsrp);
134 proto_tree_add_item(hsrp_tree, hf_hsrp_version, tvb, offset, 1, FALSE);
136 proto_tree_add_uint(hsrp_tree, hf_hsrp_opcode, tvb, offset, 1, opcode);
138 proto_tree_add_uint(hsrp_tree, hf_hsrp_state, tvb, offset, 1, state);
140 hellotime = tvb_get_guint8(tvb, offset);
141 proto_tree_add_uint_format(hsrp_tree, hf_hsrp_hellotime, tvb, offset, 1, hellotime,
142 "Hellotime: %sDefault (%u)",
143 (hellotime == HSRP_DEFAULT_HELLOTIME) ? "" : "Non-",
146 holdtime = tvb_get_guint8(tvb, offset);
147 proto_tree_add_uint_format(hsrp_tree, hf_hsrp_holdtime, tvb, offset, 1, holdtime,
148 "Holdtime: %sDefault (%u)",
149 (holdtime == HSRP_DEFAULT_HOLDTIME) ? "" : "Non-",
152 proto_tree_add_item(hsrp_tree, hf_hsrp_priority, tvb, offset, 1, FALSE);
154 proto_tree_add_item(hsrp_tree, hf_hsrp_group, tvb, offset, 1, FALSE);
156 proto_tree_add_item(hsrp_tree, hf_hsrp_reserved, tvb, offset, 1, FALSE);
158 tvb_memcpy(tvb, auth_buf, offset, 8);
159 auth_buf[sizeof auth_buf - 1] = '\0';
160 proto_tree_add_string_format(hsrp_tree, hf_hsrp_auth_data, tvb, offset, 8, auth_buf,
161 "Authentication Data: %sDefault (%s)",
162 (tvb_strneql(tvb, offset, "cisco", strlen("cisco"))) == 0 ? "" : "Non-",
165 proto_tree_add_item(hsrp_tree, hf_hsrp_virt_ip_addr, tvb, offset, 4, FALSE);
173 void proto_register_hsrp(void)
175 static hf_register_info hf[] = {
177 { "Version", "hsrp.version",
178 FT_UINT8, BASE_DEC, NULL, 0x0,
179 "The version of the HSRP messages", HFILL }},
182 { "Op Code", "hsrp.opcode",
183 FT_UINT8, BASE_DEC, VALS(hsrp_opcode_vals), 0x0,
184 "The type of message contained in this packet", HFILL }},
187 { "State", "hsrp.state",
188 FT_UINT8, BASE_DEC, VALS(hsrp_state_vals), 0x0,
189 "The current state of the router sending the message", HFILL }},
191 { &hf_hsrp_hellotime,
192 { "Hellotime", "hsrp.hellotime",
193 FT_UINT8, BASE_DEC, NULL, 0x0,
194 "The approximate period between the Hello messages that the router sends", HFILL }},
197 { "Holdtime", "hsrp.holdtime",
198 FT_UINT8, BASE_DEC, NULL, 0x0,
199 "Time that the current Hello message should be considered valid", HFILL }},
202 { "Priority", "hsrp.priority",
203 FT_UINT8, BASE_DEC, NULL, 0x0,
204 "Used to elect the active and standby routers. Numerically higher priority wins vote", HFILL }},
207 { "Group", "hsrp.group",
208 FT_UINT8, BASE_DEC, NULL, 0x0,
209 "This field identifies the standby group", HFILL }},
212 { "Reserved", "hsrp.reserved",
213 FT_UINT8, BASE_DEC, NULL, 0x0,
214 "Reserved", HFILL }},
216 { &hf_hsrp_auth_data,
217 { "Authentication Data", "hsrp.auth_data",
218 FT_STRING, 0, NULL, 0x0,
219 "Contains a clear-text 8 character reused password", HFILL }},
221 { &hf_hsrp_virt_ip_addr,
222 { "Virtual IP Address", "hsrp.virt_ip",
223 FT_IPv4, 0, NULL, 0x0,
224 "The virtual IP address used by this group", HFILL }},
228 static gint *ett[] = {
232 proto_hsrp = proto_register_protocol("Cisco Hot Standby Router Protocol",
234 proto_register_field_array(proto_hsrp, hf, array_length(hf));
235 proto_register_subtree_array(ett, array_length(ett));
241 proto_reg_handoff_hsrp(void)
243 dissector_add("udp.port", UDP_PORT_HSRP, dissect_hsrp, proto_hsrp);