2 * Routines for the Cisco Hot Standby Router Protocol (HSRP)
5 * Heikki Vatiainen <hessu@cs.tut.fi>
7 * $Id: packet-hsrp.c,v 1.24 2002/08/28 21:00:16 jmayer Exp $
9 * Ethereal - Network traffic analyzer
10 * By Gerald Combs <gerald@ethereal.com>
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.
36 #include <epan/packet.h>
38 static gint proto_hsrp = -1;
40 static gint hf_hsrp_version = -1;
41 static gint hf_hsrp_opcode = -1;
42 static gint hf_hsrp_state = -1;
43 static gint hf_hsrp_hellotime = -1;
44 static gint hf_hsrp_holdtime = -1;
45 static gint hf_hsrp_priority = -1;
46 static gint hf_hsrp_group = -1;
47 static gint hf_hsrp_reserved = -1;
48 static gint hf_hsrp_auth_data = -1;
49 static gint hf_hsrp_virt_ip_addr = -1;
51 static gint ett_hsrp = -1;
53 #define UDP_PORT_HSRP 1985
55 struct hsrp_packet { /* Multicast to 224.0.0.2, TTL 1, UDP, port 1985 */
56 guint8 version; /* RFC2281 describes version 0 */
59 #define HSRP_DEFAULT_HELLOTIME 3
60 guint8 hellotime; /* In seconds */
61 #define HSRP_DEFAULT_HOLDTIME 10
62 guint8 holdtime; /* In seconds */
63 guint8 priority; /* Higher is stronger, highest IP address tie-breaker */
64 guint8 group; /* Identifies the standby group */
66 guint8 auth_data[8]; /* Clear-text password, recommended default is `cisco' */
67 guint32 virt_ip_addr; /* The virtual IP address used by this group */
71 #define HSRP_OPCODE_HELLO 0
72 #define HSRP_OPCODE_COUP 1
73 #define HSRP_OPCODE_RESIGN 2
74 static const value_string hsrp_opcode_vals[] = {
75 {HSRP_OPCODE_HELLO, "Hello"},
76 {HSRP_OPCODE_COUP, "Coup"},
77 {HSRP_OPCODE_RESIGN, "Resign"},
81 #define HSRP_STATE_INITIAL 0
82 #define HSRP_STATE_LEARN 1
83 #define HSRP_STATE_LISTEN 2
84 #define HSRP_STATE_SPEAK 4
85 #define HSRP_STATE_STANDBY 8
86 #define HSRP_STATE_ACTIVE 16
87 static const value_string hsrp_state_vals[] = {
88 {HSRP_STATE_INITIAL, "Initial"},
89 {HSRP_STATE_LEARN, "Learn"},
90 {HSRP_STATE_LISTEN, "Listen"},
91 {HSRP_STATE_SPEAK, "Speak"},
92 {HSRP_STATE_STANDBY, "Standby"},
93 {HSRP_STATE_ACTIVE, "Active"},
98 dissect_hsrp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
100 guint8 opcode, state;
102 if (check_col(pinfo->cinfo, COL_PROTOCOL))
103 col_set_str(pinfo->cinfo, COL_PROTOCOL, "HSRP");
104 if (check_col(pinfo->cinfo, COL_INFO))
105 col_clear(pinfo->cinfo, COL_INFO);
107 opcode = tvb_get_guint8(tvb, 1);
108 state = tvb_get_guint8(tvb, 2);
109 if (check_col(pinfo->cinfo, COL_INFO)) {
110 col_add_fstr(pinfo->cinfo, COL_INFO, "%s (state %s)",
111 val_to_str(opcode, hsrp_opcode_vals, "Unknown"),
112 val_to_str(state, hsrp_state_vals, "Unknown"));
117 proto_tree *hsrp_tree;
119 guint8 hellotime, holdtime;
120 guint8 auth_buf[8 + 1];
123 ti = proto_tree_add_item(tree, proto_hsrp, tvb, offset, -1, FALSE);
124 hsrp_tree = proto_item_add_subtree(ti, ett_hsrp);
126 proto_tree_add_item(hsrp_tree, hf_hsrp_version, tvb, offset, 1, FALSE);
128 proto_tree_add_uint(hsrp_tree, hf_hsrp_opcode, tvb, offset, 1, opcode);
130 proto_tree_add_uint(hsrp_tree, hf_hsrp_state, tvb, offset, 1, state);
132 hellotime = tvb_get_guint8(tvb, offset);
133 proto_tree_add_uint_format(hsrp_tree, hf_hsrp_hellotime, tvb, offset, 1, hellotime,
134 "Hellotime: %sDefault (%u)",
135 (hellotime == HSRP_DEFAULT_HELLOTIME) ? "" : "Non-",
138 holdtime = tvb_get_guint8(tvb, offset);
139 proto_tree_add_uint_format(hsrp_tree, hf_hsrp_holdtime, tvb, offset, 1, holdtime,
140 "Holdtime: %sDefault (%u)",
141 (holdtime == HSRP_DEFAULT_HOLDTIME) ? "" : "Non-",
144 proto_tree_add_item(hsrp_tree, hf_hsrp_priority, tvb, offset, 1, FALSE);
146 proto_tree_add_item(hsrp_tree, hf_hsrp_group, tvb, offset, 1, FALSE);
148 proto_tree_add_item(hsrp_tree, hf_hsrp_reserved, tvb, offset, 1, FALSE);
150 tvb_memcpy(tvb, auth_buf, offset, 8);
151 auth_buf[sizeof auth_buf - 1] = '\0';
152 proto_tree_add_string_format(hsrp_tree, hf_hsrp_auth_data, tvb, offset, 8, auth_buf,
153 "Authentication Data: %sDefault (%s)",
154 (tvb_strneql(tvb, offset, "cisco", strlen("cisco"))) == 0 ? "" : "Non-",
157 proto_tree_add_item(hsrp_tree, hf_hsrp_virt_ip_addr, tvb, offset, 4, FALSE);
165 void proto_register_hsrp(void)
167 static hf_register_info hf[] = {
169 { "Version", "hsrp.version",
170 FT_UINT8, BASE_DEC, NULL, 0x0,
171 "The version of the HSRP messages", HFILL }},
174 { "Op Code", "hsrp.opcode",
175 FT_UINT8, BASE_DEC, VALS(hsrp_opcode_vals), 0x0,
176 "The type of message contained in this packet", HFILL }},
179 { "State", "hsrp.state",
180 FT_UINT8, BASE_DEC, VALS(hsrp_state_vals), 0x0,
181 "The current state of the router sending the message", HFILL }},
183 { &hf_hsrp_hellotime,
184 { "Hellotime", "hsrp.hellotime",
185 FT_UINT8, BASE_DEC, NULL, 0x0,
186 "The approximate period between the Hello messages that the router sends", HFILL }},
189 { "Holdtime", "hsrp.holdtime",
190 FT_UINT8, BASE_DEC, NULL, 0x0,
191 "Time that the current Hello message should be considered valid", HFILL }},
194 { "Priority", "hsrp.priority",
195 FT_UINT8, BASE_DEC, NULL, 0x0,
196 "Used to elect the active and standby routers. Numerically higher priority wins vote", HFILL }},
199 { "Group", "hsrp.group",
200 FT_UINT8, BASE_DEC, NULL, 0x0,
201 "This field identifies the standby group", HFILL }},
204 { "Reserved", "hsrp.reserved",
205 FT_UINT8, BASE_DEC, NULL, 0x0,
206 "Reserved", HFILL }},
208 { &hf_hsrp_auth_data,
209 { "Authentication Data", "hsrp.auth_data",
210 FT_STRING, 0, NULL, 0x0,
211 "Contains a clear-text 8 character reused password", HFILL }},
213 { &hf_hsrp_virt_ip_addr,
214 { "Virtual IP Address", "hsrp.virt_ip",
215 FT_IPv4, 0, NULL, 0x0,
216 "The virtual IP address used by this group", HFILL }},
220 static gint *ett[] = {
224 proto_hsrp = proto_register_protocol("Cisco Hot Standby Router Protocol",
226 proto_register_field_array(proto_hsrp, hf, array_length(hf));
227 proto_register_subtree_array(ett, array_length(ett));
233 proto_reg_handoff_hsrp(void)
235 dissector_handle_t hsrp_handle;
237 hsrp_handle = create_dissector_handle(dissect_hsrp, proto_hsrp);
238 dissector_add("udp.port", UDP_PORT_HSRP, hsrp_handle);