1999-11-21 20:02:32 +00:00
|
|
|
/* packet-hsrp.c
|
|
|
|
* Routines for the Cisco Hot Standby Router Protocol (HSRP)
|
|
|
|
* RFC2281
|
|
|
|
*
|
|
|
|
* Heikki Vatiainen <hessu@cs.tut.fi>
|
|
|
|
*
|
Allow either old-style (pre-tvbuff) or new-style (tvbuffified)
dissectors to be registered as dissectors for particular ports,
registered as heuristic dissectors, and registered as dissectors for
conversations, and have routines to be used both by old-style and
new-style dissectors to call registered dissectors.
Have the code that calls those dissectors translate the arguments as
necessary. (For conversation dissectors, replace
"find_conversation_dissector()", which just returns a pointer to the
dissector, with "old_try_conversation_dissector()" and
"try_conversation_dissector()", which actually call the dissector, so
that there's a single place at which we can do that translation. Also
make "dissector_lookup()" static and, instead of calling it and, if it
returns a non-null pointer, calling that dissector, just use
"old_dissector_try_port()" or "dissector_try_port()", for the same
reason.)
This allows some dissectors that took old-style arguments and
immediately translated them to new-style arguments to just take
new-style arguments; make them do so. It also allows some new-style
dissectors not to have to translate arguments before calling routines to
look up and call dissectors; make them not do so.
Get rid of checks for too-short frames in new-style dissectors - the
tvbuff code does those checks for you.
Give the routines to register old-style dissectors, and to call
dissectors from old-style dissectors, names beginning with "old_", with
the routines for new-style dissectors not having the "old_". Update the
dissectors that use those routines appropriately.
Rename "dissect_data()" to "old_dissect_data()", and
"dissect_data_tvb()" to "dissect_data()".
svn path=/trunk/; revision=2218
2000-08-07 03:21:25 +00:00
|
|
|
* $Id: packet-hsrp.c,v 1.6 2000/08/07 03:20:36 guy Exp $
|
1999-11-21 20:02:32 +00:00
|
|
|
*
|
|
|
|
* Ethereal - Network traffic analyzer
|
2000-01-07 22:05:43 +00:00
|
|
|
* By Gerald Combs <gerald@zing.org>
|
1999-11-21 20:02:32 +00:00
|
|
|
* Copyright 1998 Gerald Combs
|
|
|
|
*
|
|
|
|
* Copied from packet-vrrp.c
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
# include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_NETINET_IN_H
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include "packet.h"
|
|
|
|
|
|
|
|
static gint proto_hsrp = -1;
|
|
|
|
static gint ett_hsrp = -1;
|
|
|
|
|
2000-04-08 07:07:42 +00:00
|
|
|
#define UDP_PORT_HSRP 1985
|
|
|
|
|
1999-11-21 20:02:32 +00:00
|
|
|
struct hsrp_packet { /* Multicast to 224.0.0.2, TTL 1, UDP, port 1985 */
|
|
|
|
guint8 version; /* RFC2281 describes version 0 */
|
|
|
|
guint8 opcode;
|
|
|
|
guint8 state;
|
|
|
|
#define HSRP_DEFAULT_HELLOTIME 3
|
|
|
|
guint8 hellotime; /* In seconds */
|
|
|
|
#define HSRP_DEFAULT_HOLDTIME 10
|
|
|
|
guint8 holdtime; /* In seconds */
|
|
|
|
guint8 priority; /* Higher is stronger, highest IP address tie-breaker */
|
|
|
|
guint8 group; /* Identifies the standby group */
|
|
|
|
guint8 reserved;
|
|
|
|
guint8 auth_data[8]; /* Clear-text password, recommended default is `cisco' */
|
|
|
|
guint32 virt_ip_addr; /* The virtual IP address used by this group */
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#define HSRP_OPCODE_HELLO 0
|
|
|
|
#define HSRP_OPCODE_COUP 1
|
|
|
|
#define HSRP_OPCODE_RESIGN 2
|
|
|
|
static const value_string hsrp_opcode_vals[] = {
|
|
|
|
{HSRP_OPCODE_HELLO, "Hello"},
|
|
|
|
{HSRP_OPCODE_COUP, "Coup"},
|
|
|
|
{HSRP_OPCODE_RESIGN, "Resign"}
|
|
|
|
};
|
|
|
|
|
|
|
|
#define HSRP_STATE_INITIAL 0
|
|
|
|
#define HSRP_STATE_LEARN 1
|
|
|
|
#define HSRP_STATE_LISTEN 2
|
|
|
|
#define HSRP_STATE_SPEAK 4
|
|
|
|
#define HSRP_STATE_STANDBY 8
|
|
|
|
#define HSRP_STATE_ACTIVE 16
|
|
|
|
static const value_string hsrp_state_vals[] = {
|
|
|
|
{HSRP_STATE_INITIAL, "Initial"},
|
|
|
|
{HSRP_STATE_LEARN, "Learn"},
|
|
|
|
{HSRP_STATE_LISTEN, "Listen"},
|
|
|
|
{HSRP_STATE_SPEAK, "Speak"},
|
|
|
|
{HSRP_STATE_STANDBY, "Standby"},
|
|
|
|
{HSRP_STATE_ACTIVE, "Active"}
|
|
|
|
};
|
|
|
|
|
2000-04-08 07:07:42 +00:00
|
|
|
static void
|
|
|
|
dissect_hsrp(const u_char *pd, int offset, frame_data *fd, proto_tree *tree)
|
1999-11-21 20:02:32 +00:00
|
|
|
{
|
|
|
|
struct hsrp_packet hsrp;
|
|
|
|
gboolean short_packet = FALSE;
|
|
|
|
|
|
|
|
if (sizeof(struct hsrp_packet) > END_OF_FRAME)
|
|
|
|
short_packet = TRUE;
|
|
|
|
else
|
|
|
|
memcpy(&hsrp, pd + offset, sizeof(struct hsrp_packet));
|
|
|
|
|
|
|
|
if (check_col(fd, COL_PROTOCOL))
|
|
|
|
col_add_str(fd, COL_PROTOCOL, "HSRP");
|
|
|
|
|
|
|
|
if (check_col(fd, COL_INFO)) {
|
|
|
|
if (short_packet)
|
|
|
|
col_add_fstr(fd, COL_INFO, "Short packet, length %u", END_OF_FRAME);
|
|
|
|
else
|
|
|
|
col_add_fstr(fd, COL_INFO, "%s (state %s)",
|
|
|
|
val_to_str(hsrp.opcode, hsrp_opcode_vals, "Unknown"),
|
|
|
|
val_to_str(hsrp.state, hsrp_state_vals, "Unknown"));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tree) {
|
|
|
|
proto_item *ti;
|
|
|
|
proto_tree *hsrp_tree;
|
|
|
|
guint8 auth_buf[sizeof(hsrp.auth_data) + 1];
|
|
|
|
|
|
|
|
if (short_packet) {
|
Allow either old-style (pre-tvbuff) or new-style (tvbuffified)
dissectors to be registered as dissectors for particular ports,
registered as heuristic dissectors, and registered as dissectors for
conversations, and have routines to be used both by old-style and
new-style dissectors to call registered dissectors.
Have the code that calls those dissectors translate the arguments as
necessary. (For conversation dissectors, replace
"find_conversation_dissector()", which just returns a pointer to the
dissector, with "old_try_conversation_dissector()" and
"try_conversation_dissector()", which actually call the dissector, so
that there's a single place at which we can do that translation. Also
make "dissector_lookup()" static and, instead of calling it and, if it
returns a non-null pointer, calling that dissector, just use
"old_dissector_try_port()" or "dissector_try_port()", for the same
reason.)
This allows some dissectors that took old-style arguments and
immediately translated them to new-style arguments to just take
new-style arguments; make them do so. It also allows some new-style
dissectors not to have to translate arguments before calling routines to
look up and call dissectors; make them not do so.
Get rid of checks for too-short frames in new-style dissectors - the
tvbuff code does those checks for you.
Give the routines to register old-style dissectors, and to call
dissectors from old-style dissectors, names beginning with "old_", with
the routines for new-style dissectors not having the "old_". Update the
dissectors that use those routines appropriately.
Rename "dissect_data()" to "old_dissect_data()", and
"dissect_data_tvb()" to "dissect_data()".
svn path=/trunk/; revision=2218
2000-08-07 03:21:25 +00:00
|
|
|
old_dissect_data(pd, offset, fd, tree);
|
1999-11-21 20:02:32 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2000-05-31 05:09:07 +00:00
|
|
|
ti = proto_tree_add_item(tree, proto_hsrp, NullTVB, offset, END_OF_FRAME, FALSE);
|
1999-11-21 20:02:32 +00:00
|
|
|
hsrp_tree = proto_item_add_subtree(ti, ett_hsrp);
|
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(hsrp_tree, NullTVB, offset++, 1, "Version: %u", hsrp.version);
|
|
|
|
proto_tree_add_text(hsrp_tree, NullTVB, offset++, 1, "Opcode: %u (%s)", hsrp.opcode,
|
1999-11-21 20:02:32 +00:00
|
|
|
val_to_str(hsrp.opcode, hsrp_opcode_vals, "Unknown"));
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(hsrp_tree, NullTVB, offset++, 1, "State: %u (%s)", hsrp.state,
|
1999-11-21 20:02:32 +00:00
|
|
|
val_to_str(hsrp.state, hsrp_state_vals, "Unknown"));
|
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(hsrp_tree, NullTVB, offset++, 1, "Hellotime: %u second%s (%sdefault)",
|
1999-11-21 20:02:32 +00:00
|
|
|
hsrp.hellotime, plurality(hsrp.hellotime, "", "s"),
|
|
|
|
(hsrp.hellotime == HSRP_DEFAULT_HELLOTIME) ? "" : "non-");
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(hsrp_tree, NullTVB, offset++, 1, "Holdtime: %u second%s (%sdefault)",
|
1999-11-21 20:02:32 +00:00
|
|
|
hsrp.holdtime, plurality(hsrp.holdtime, "", "s"),
|
|
|
|
(hsrp.holdtime == HSRP_DEFAULT_HOLDTIME) ? "" : "non-");
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(hsrp_tree, NullTVB, offset++, 1, "Priority: %u", hsrp.priority);
|
|
|
|
proto_tree_add_text(hsrp_tree, NullTVB, offset++, 1, "Group: %u", hsrp.group);
|
|
|
|
proto_tree_add_text(hsrp_tree, NullTVB, offset++, 1, "Reserved: 0x%x", hsrp.reserved);
|
1999-11-21 20:02:32 +00:00
|
|
|
|
|
|
|
memcpy(auth_buf, hsrp.auth_data, sizeof(hsrp.auth_data));
|
|
|
|
auth_buf[sizeof(auth_buf)] = '\0';
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(hsrp_tree, NullTVB, offset, 8, "Authentication Data: `%s'", auth_buf);
|
1999-11-21 20:02:32 +00:00
|
|
|
offset+=8;
|
|
|
|
|
2000-05-11 08:18:09 +00:00
|
|
|
proto_tree_add_text(hsrp_tree, NullTVB, offset++, 4, "Virtual IP address: %s",
|
1999-11-21 20:02:32 +00:00
|
|
|
ip_to_str((guint8 *)&hsrp.virt_ip_addr));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void proto_register_hsrp(void)
|
|
|
|
{
|
|
|
|
static gint *ett[] = {
|
|
|
|
&ett_hsrp,
|
|
|
|
};
|
|
|
|
|
|
|
|
proto_hsrp = proto_register_protocol("Cisco Hot Standby Router Protocol", "hsrp");
|
|
|
|
proto_register_subtree_array(ett, array_length(ett));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2000-04-08 07:07:42 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
proto_reg_handoff_hsrp(void)
|
|
|
|
{
|
Allow either old-style (pre-tvbuff) or new-style (tvbuffified)
dissectors to be registered as dissectors for particular ports,
registered as heuristic dissectors, and registered as dissectors for
conversations, and have routines to be used both by old-style and
new-style dissectors to call registered dissectors.
Have the code that calls those dissectors translate the arguments as
necessary. (For conversation dissectors, replace
"find_conversation_dissector()", which just returns a pointer to the
dissector, with "old_try_conversation_dissector()" and
"try_conversation_dissector()", which actually call the dissector, so
that there's a single place at which we can do that translation. Also
make "dissector_lookup()" static and, instead of calling it and, if it
returns a non-null pointer, calling that dissector, just use
"old_dissector_try_port()" or "dissector_try_port()", for the same
reason.)
This allows some dissectors that took old-style arguments and
immediately translated them to new-style arguments to just take
new-style arguments; make them do so. It also allows some new-style
dissectors not to have to translate arguments before calling routines to
look up and call dissectors; make them not do so.
Get rid of checks for too-short frames in new-style dissectors - the
tvbuff code does those checks for you.
Give the routines to register old-style dissectors, and to call
dissectors from old-style dissectors, names beginning with "old_", with
the routines for new-style dissectors not having the "old_". Update the
dissectors that use those routines appropriately.
Rename "dissect_data()" to "old_dissect_data()", and
"dissect_data_tvb()" to "dissect_data()".
svn path=/trunk/; revision=2218
2000-08-07 03:21:25 +00:00
|
|
|
old_dissector_add("udp.port", UDP_PORT_HSRP, dissect_hsrp);
|
2000-04-08 07:07:42 +00:00
|
|
|
}
|