2 * Routines for the Cisco Hot Standby Router Protocol (HSRP)
5 * Heikki Vatiainen <hessu@cs.tut.fi>
7 * $Id: packet-hsrp.c,v 1.2 2000/01/07 22:05:31 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>
45 static gint proto_hsrp = -1;
46 static gint ett_hsrp = -1;
48 struct hsrp_packet { /* Multicast to 224.0.0.2, TTL 1, UDP, port 1985 */
49 guint8 version; /* RFC2281 describes version 0 */
52 #define HSRP_DEFAULT_HELLOTIME 3
53 guint8 hellotime; /* In seconds */
54 #define HSRP_DEFAULT_HOLDTIME 10
55 guint8 holdtime; /* In seconds */
56 guint8 priority; /* Higher is stronger, highest IP address tie-breaker */
57 guint8 group; /* Identifies the standby group */
59 guint8 auth_data[8]; /* Clear-text password, recommended default is `cisco' */
60 guint32 virt_ip_addr; /* The virtual IP address used by this group */
64 #define HSRP_OPCODE_HELLO 0
65 #define HSRP_OPCODE_COUP 1
66 #define HSRP_OPCODE_RESIGN 2
67 static const value_string hsrp_opcode_vals[] = {
68 {HSRP_OPCODE_HELLO, "Hello"},
69 {HSRP_OPCODE_COUP, "Coup"},
70 {HSRP_OPCODE_RESIGN, "Resign"}
73 #define HSRP_STATE_INITIAL 0
74 #define HSRP_STATE_LEARN 1
75 #define HSRP_STATE_LISTEN 2
76 #define HSRP_STATE_SPEAK 4
77 #define HSRP_STATE_STANDBY 8
78 #define HSRP_STATE_ACTIVE 16
79 static const value_string hsrp_state_vals[] = {
80 {HSRP_STATE_INITIAL, "Initial"},
81 {HSRP_STATE_LEARN, "Learn"},
82 {HSRP_STATE_LISTEN, "Listen"},
83 {HSRP_STATE_SPEAK, "Speak"},
84 {HSRP_STATE_STANDBY, "Standby"},
85 {HSRP_STATE_ACTIVE, "Active"}
88 void dissect_hsrp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
90 struct hsrp_packet hsrp;
91 gboolean short_packet = FALSE;
93 if (sizeof(struct hsrp_packet) > END_OF_FRAME)
96 memcpy(&hsrp, pd + offset, sizeof(struct hsrp_packet));
98 if (check_col(fd, COL_PROTOCOL))
99 col_add_str(fd, COL_PROTOCOL, "HSRP");
101 if (check_col(fd, COL_INFO)) {
103 col_add_fstr(fd, COL_INFO, "Short packet, length %u", END_OF_FRAME);
105 col_add_fstr(fd, COL_INFO, "%s (state %s)",
106 val_to_str(hsrp.opcode, hsrp_opcode_vals, "Unknown"),
107 val_to_str(hsrp.state, hsrp_state_vals, "Unknown"));
112 proto_tree *hsrp_tree;
113 guint8 auth_buf[sizeof(hsrp.auth_data) + 1];
116 dissect_data(pd, offset, fd, tree);
120 ti = proto_tree_add_item(tree, proto_hsrp, offset, END_OF_FRAME, NULL);
121 hsrp_tree = proto_item_add_subtree(ti, ett_hsrp);
123 proto_tree_add_text(hsrp_tree, offset++, 1, "Version: %u", hsrp.version);
124 proto_tree_add_text(hsrp_tree, offset++, 1, "Opcode: %u (%s)", hsrp.opcode,
125 val_to_str(hsrp.opcode, hsrp_opcode_vals, "Unknown"));
126 proto_tree_add_text(hsrp_tree, offset++, 1, "State: %u (%s)", hsrp.state,
127 val_to_str(hsrp.state, hsrp_state_vals, "Unknown"));
129 proto_tree_add_text(hsrp_tree, offset++, 1, "Hellotime: %u second%s (%sdefault)",
130 hsrp.hellotime, plurality(hsrp.hellotime, "", "s"),
131 (hsrp.hellotime == HSRP_DEFAULT_HELLOTIME) ? "" : "non-");
132 proto_tree_add_text(hsrp_tree, offset++, 1, "Holdtime: %u second%s (%sdefault)",
133 hsrp.holdtime, plurality(hsrp.holdtime, "", "s"),
134 (hsrp.holdtime == HSRP_DEFAULT_HOLDTIME) ? "" : "non-");
135 proto_tree_add_text(hsrp_tree, offset++, 1, "Priority: %u", hsrp.priority);
136 proto_tree_add_text(hsrp_tree, offset++, 1, "Group: %u", hsrp.group);
137 proto_tree_add_text(hsrp_tree, offset++, 1, "Reserved: 0x%x", hsrp.reserved);
139 memcpy(auth_buf, hsrp.auth_data, sizeof(hsrp.auth_data));
140 auth_buf[sizeof(auth_buf)] = '\0';
141 proto_tree_add_text(hsrp_tree, offset, 8, "Authentication Data: `%s'", auth_buf);
144 proto_tree_add_text(hsrp_tree, offset++, 4, "Virtual IP address: %s",
145 ip_to_str((guint8 *)&hsrp.virt_ip_addr));
152 void proto_register_hsrp(void)
154 static gint *ett[] = {
158 proto_hsrp = proto_register_protocol("Cisco Hot Standby Router Protocol", "hsrp");
159 proto_register_subtree_array(ett, array_length(ett));