xref: /dflybsd-src/contrib/tcpdump/print-hsrp.c (revision 59c07fbdf8168fa08c76c515186d561b5a92690c)
141c99275SPeter Avalos /*
241c99275SPeter Avalos  * Copyright (C) 2001 Julian Cowley
341c99275SPeter Avalos  * All rights reserved.
441c99275SPeter Avalos  *
541c99275SPeter Avalos  * Redistribution and use in source and binary forms, with or without
641c99275SPeter Avalos  * modification, are permitted provided that the following conditions
741c99275SPeter Avalos  * are met:
841c99275SPeter Avalos  * 1. Redistributions of source code must retain the above copyright
941c99275SPeter Avalos  *    notice, this list of conditions and the following disclaimer.
1041c99275SPeter Avalos  * 2. Redistributions in binary form must reproduce the above copyright
1141c99275SPeter Avalos  *    notice, this list of conditions and the following disclaimer in the
1241c99275SPeter Avalos  *    documentation and/or other materials provided with the distribution.
1341c99275SPeter Avalos  * 3. Neither the name of the project nor the names of its contributors
1441c99275SPeter Avalos  *    may be used to endorse or promote products derived from this software
1541c99275SPeter Avalos  *    without specific prior written permission.
1641c99275SPeter Avalos  *
1741c99275SPeter Avalos  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
1841c99275SPeter Avalos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1941c99275SPeter Avalos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2041c99275SPeter Avalos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
2141c99275SPeter Avalos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2241c99275SPeter Avalos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2341c99275SPeter Avalos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2441c99275SPeter Avalos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2541c99275SPeter Avalos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2641c99275SPeter Avalos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2741c99275SPeter Avalos  * SUCH DAMAGE.
2841c99275SPeter Avalos  */
2941c99275SPeter Avalos 
30411677aeSAaron LI /* \summary: Cisco Hot Standby Router Protocol (HSRP) printer */
3141c99275SPeter Avalos 
32*ed775ee7SAntonio Huete Jimenez /* specification: RFC 2281 for version 1 */
3341c99275SPeter Avalos 
3441c99275SPeter Avalos #ifdef HAVE_CONFIG_H
35*ed775ee7SAntonio Huete Jimenez #include <config.h>
3641c99275SPeter Avalos #endif
3741c99275SPeter Avalos 
38*ed775ee7SAntonio Huete Jimenez #include "netdissect-stdinc.h"
3941c99275SPeter Avalos 
40411677aeSAaron LI #include "netdissect.h"
4141c99275SPeter Avalos #include "addrtoname.h"
42*ed775ee7SAntonio Huete Jimenez #include "extract.h"
4341c99275SPeter Avalos 
4441c99275SPeter Avalos /* HSRP op code types. */
4541c99275SPeter Avalos static const char *op_code_str[] = {
4641c99275SPeter Avalos 	"hello",
4741c99275SPeter Avalos 	"coup",
4841c99275SPeter Avalos 	"resign"
4941c99275SPeter Avalos };
5041c99275SPeter Avalos 
5141c99275SPeter Avalos /* HSRP states and associated names. */
52411677aeSAaron LI static const struct tok states[] = {
5341c99275SPeter Avalos 	{  0, "initial" },
5441c99275SPeter Avalos 	{  1, "learn" },
5541c99275SPeter Avalos 	{  2, "listen" },
5641c99275SPeter Avalos 	{  4, "speak" },
5741c99275SPeter Avalos 	{  8, "standby" },
5841c99275SPeter Avalos 	{ 16, "active" },
5941c99275SPeter Avalos 	{  0, NULL }
6041c99275SPeter Avalos };
6141c99275SPeter Avalos 
6241c99275SPeter Avalos /*
6341c99275SPeter Avalos  * RFC 2281:
6441c99275SPeter Avalos  *
6541c99275SPeter Avalos  *  0                   1                   2                   3
6641c99275SPeter Avalos  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
6741c99275SPeter Avalos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
6841c99275SPeter Avalos  * |   Version     |   Op Code     |     State     |   Hellotime   |
6941c99275SPeter Avalos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
7041c99275SPeter Avalos  * |   Holdtime    |   Priority    |     Group     |   Reserved    |
7141c99275SPeter Avalos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
7241c99275SPeter Avalos  * |                      Authentication  Data                     |
7341c99275SPeter Avalos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
7441c99275SPeter Avalos  * |                      Authentication  Data                     |
7541c99275SPeter Avalos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
7641c99275SPeter Avalos  * |                      Virtual IP Address                       |
7741c99275SPeter Avalos  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
7841c99275SPeter Avalos  */
7941c99275SPeter Avalos 
8041c99275SPeter Avalos #define HSRP_AUTH_SIZE	8
8141c99275SPeter Avalos 
8241c99275SPeter Avalos /* HSRP protocol header. */
8341c99275SPeter Avalos struct hsrp {
84*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t	hsrp_version;
85*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t	hsrp_op_code;
86*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t	hsrp_state;
87*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t	hsrp_hellotime;
88*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t	hsrp_holdtime;
89*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t	hsrp_priority;
90*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t	hsrp_group;
91*ed775ee7SAntonio Huete Jimenez 	nd_uint8_t	hsrp_reserved;
92*ed775ee7SAntonio Huete Jimenez 	nd_byte		hsrp_authdata[HSRP_AUTH_SIZE];
93*ed775ee7SAntonio Huete Jimenez 	nd_ipv4		hsrp_virtaddr;
9441c99275SPeter Avalos };
9541c99275SPeter Avalos 
9641c99275SPeter Avalos void
hsrp_print(netdissect_options * ndo,const u_char * bp,u_int len)97*ed775ee7SAntonio Huete Jimenez hsrp_print(netdissect_options *ndo, const u_char *bp, u_int len)
9841c99275SPeter Avalos {
99411677aeSAaron LI 	const struct hsrp *hp = (const struct hsrp *) bp;
100*ed775ee7SAntonio Huete Jimenez 	uint8_t version;
10141c99275SPeter Avalos 
102*ed775ee7SAntonio Huete Jimenez 	ndo->ndo_protocol = "hsrp";
103*ed775ee7SAntonio Huete Jimenez 	version = GET_U_1(hp->hsrp_version);
104*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("HSRPv%u", version);
105*ed775ee7SAntonio Huete Jimenez 	if (version != 0)
10641c99275SPeter Avalos 		return;
107*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("-");
108*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%s ",
109*ed775ee7SAntonio Huete Jimenez 		 tok2strary(op_code_str, "unknown (%u)", GET_U_1(hp->hsrp_op_code)));
110*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("%u: ", len);
111*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("state=%s ",
112*ed775ee7SAntonio Huete Jimenez 		 tok2str(states, "Unknown (%u)", GET_U_1(hp->hsrp_state)));
113*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("group=%u ", GET_U_1(hp->hsrp_group));
114*ed775ee7SAntonio Huete Jimenez 	if (GET_U_1(hp->hsrp_reserved) != 0) {
115*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("[reserved=%u!] ", GET_U_1(hp->hsrp_reserved));
11641c99275SPeter Avalos 	}
117*ed775ee7SAntonio Huete Jimenez 	ND_PRINT("addr=%s", GET_IPADDR_STRING(hp->hsrp_virtaddr));
118411677aeSAaron LI 	if (ndo->ndo_vflag) {
119*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" hellotime=");
120*ed775ee7SAntonio Huete Jimenez 		unsigned_relts_print(ndo, GET_U_1(hp->hsrp_hellotime));
121*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" holdtime=");
122*ed775ee7SAntonio Huete Jimenez 		unsigned_relts_print(ndo, GET_U_1(hp->hsrp_holdtime));
123*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" priority=%u", GET_U_1(hp->hsrp_priority));
124*ed775ee7SAntonio Huete Jimenez 		ND_PRINT(" auth=\"");
125*ed775ee7SAntonio Huete Jimenez 		/*
126*ed775ee7SAntonio Huete Jimenez 		 * RFC 2281 Section 5.1 does not specify the encoding of
127*ed775ee7SAntonio Huete Jimenez 		 * Authentication Data explicitly, but zero padding can be
128*ed775ee7SAntonio Huete Jimenez 		 * inferred from the "recommended default value".
129*ed775ee7SAntonio Huete Jimenez 		 */
130*ed775ee7SAntonio Huete Jimenez 		nd_printjnp(ndo, hp->hsrp_authdata, HSRP_AUTH_SIZE);
131*ed775ee7SAntonio Huete Jimenez 		ND_PRINT("\"");
13241c99275SPeter Avalos 	}
13341c99275SPeter Avalos }
134