xref: /freebsd/contrib/tcpdump/print-hsrp.c (revision 3c602fabf9b894ff79f08a80cbb7ad3b1eb84e62)
1a90e161bSBill Fenner /*
2a90e161bSBill Fenner  * Copyright (C) 2001 Julian Cowley
3a90e161bSBill Fenner  * All rights reserved.
4a90e161bSBill Fenner  *
5a90e161bSBill Fenner  * Redistribution and use in source and binary forms, with or without
6a90e161bSBill Fenner  * modification, are permitted provided that the following conditions
7a90e161bSBill Fenner  * are met:
8a90e161bSBill Fenner  * 1. Redistributions of source code must retain the above copyright
9a90e161bSBill Fenner  *    notice, this list of conditions and the following disclaimer.
10a90e161bSBill Fenner  * 2. Redistributions in binary form must reproduce the above copyright
11a90e161bSBill Fenner  *    notice, this list of conditions and the following disclaimer in the
12a90e161bSBill Fenner  *    documentation and/or other materials provided with the distribution.
13a90e161bSBill Fenner  * 3. Neither the name of the project nor the names of its contributors
14a90e161bSBill Fenner  *    may be used to endorse or promote products derived from this software
15a90e161bSBill Fenner  *    without specific prior written permission.
16a90e161bSBill Fenner  *
17a90e161bSBill Fenner  * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
18a90e161bSBill Fenner  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19a90e161bSBill Fenner  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20a90e161bSBill Fenner  * ARE DISCLAIMED.  IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
21a90e161bSBill Fenner  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22a90e161bSBill Fenner  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23a90e161bSBill Fenner  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24a90e161bSBill Fenner  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25a90e161bSBill Fenner  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26a90e161bSBill Fenner  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27a90e161bSBill Fenner  * SUCH DAMAGE.
28a90e161bSBill Fenner  */
29a90e161bSBill Fenner 
30a90e161bSBill Fenner /* Cisco Hot Standby Router Protocol (HSRP). */
31a90e161bSBill Fenner 
32*3c602fabSXin LI #define NETDISSECT_REWORKED
33a90e161bSBill Fenner #ifdef HAVE_CONFIG_H
34a90e161bSBill Fenner #include "config.h"
35a90e161bSBill Fenner #endif
36a90e161bSBill Fenner 
375b0fe478SBruce M Simpson #include <tcpdump-stdinc.h>
38a90e161bSBill Fenner 
39a90e161bSBill Fenner #include "interface.h"
40a90e161bSBill Fenner #include "addrtoname.h"
41a90e161bSBill Fenner 
42a90e161bSBill Fenner /* HSRP op code types. */
43a90e161bSBill Fenner static const char *op_code_str[] = {
44a90e161bSBill Fenner 	"hello",
45a90e161bSBill Fenner 	"coup",
46a90e161bSBill Fenner 	"resign"
47a90e161bSBill Fenner };
48a90e161bSBill Fenner 
49a90e161bSBill Fenner /* HSRP states and associated names. */
50*3c602fabSXin LI static const struct tok states[] = {
51a90e161bSBill Fenner 	{  0, "initial" },
52a90e161bSBill Fenner 	{  1, "learn" },
53a90e161bSBill Fenner 	{  2, "listen" },
54a90e161bSBill Fenner 	{  4, "speak" },
55a90e161bSBill Fenner 	{  8, "standby" },
56a90e161bSBill Fenner 	{ 16, "active" },
57a90e161bSBill Fenner 	{  0, NULL }
58a90e161bSBill Fenner };
59a90e161bSBill Fenner 
60a90e161bSBill Fenner /*
61a90e161bSBill Fenner  * RFC 2281:
62a90e161bSBill Fenner  *
63a90e161bSBill Fenner  *  0                   1                   2                   3
64a90e161bSBill Fenner  *  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
65a90e161bSBill Fenner  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
66a90e161bSBill Fenner  * |   Version     |   Op Code     |     State     |   Hellotime   |
67a90e161bSBill Fenner  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68a90e161bSBill Fenner  * |   Holdtime    |   Priority    |     Group     |   Reserved    |
69a90e161bSBill Fenner  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70a90e161bSBill Fenner  * |                      Authentication  Data                     |
71a90e161bSBill Fenner  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72a90e161bSBill Fenner  * |                      Authentication  Data                     |
73a90e161bSBill Fenner  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
74a90e161bSBill Fenner  * |                      Virtual IP Address                       |
75a90e161bSBill Fenner  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
76a90e161bSBill Fenner  */
77a90e161bSBill Fenner 
78a90e161bSBill Fenner #define HSRP_AUTH_SIZE	8
79a90e161bSBill Fenner 
80a90e161bSBill Fenner /* HSRP protocol header. */
81a90e161bSBill Fenner struct hsrp {
82*3c602fabSXin LI 	uint8_t		hsrp_version;
83*3c602fabSXin LI 	uint8_t		hsrp_op_code;
84*3c602fabSXin LI 	uint8_t		hsrp_state;
85*3c602fabSXin LI 	uint8_t		hsrp_hellotime;
86*3c602fabSXin LI 	uint8_t		hsrp_holdtime;
87*3c602fabSXin LI 	uint8_t		hsrp_priority;
88*3c602fabSXin LI 	uint8_t		hsrp_group;
89*3c602fabSXin LI 	uint8_t		hsrp_reserved;
90*3c602fabSXin LI 	uint8_t		hsrp_authdata[HSRP_AUTH_SIZE];
91a90e161bSBill Fenner 	struct in_addr	hsrp_virtaddr;
92a90e161bSBill Fenner };
93a90e161bSBill Fenner 
94a90e161bSBill Fenner void
95*3c602fabSXin LI hsrp_print(netdissect_options *ndo, register const uint8_t *bp, register u_int len)
96a90e161bSBill Fenner {
97a90e161bSBill Fenner 	struct hsrp *hp = (struct hsrp *) bp;
98a90e161bSBill Fenner 
99*3c602fabSXin LI 	ND_TCHECK(hp->hsrp_version);
100*3c602fabSXin LI 	ND_PRINT((ndo, "HSRPv%d", hp->hsrp_version));
101a90e161bSBill Fenner 	if (hp->hsrp_version != 0)
102a90e161bSBill Fenner 		return;
103*3c602fabSXin LI 	ND_TCHECK(hp->hsrp_op_code);
104*3c602fabSXin LI 	ND_PRINT((ndo, "-"));
105*3c602fabSXin LI 	ND_PRINT((ndo, "%s ", tok2strary(op_code_str, "unknown (%d)", hp->hsrp_op_code)));
106*3c602fabSXin LI 	ND_PRINT((ndo, "%d: ", len));
107*3c602fabSXin LI 	ND_TCHECK(hp->hsrp_state);
108*3c602fabSXin LI 	ND_PRINT((ndo, "state=%s ", tok2str(states, "Unknown (%d)", hp->hsrp_state)));
109*3c602fabSXin LI 	ND_TCHECK(hp->hsrp_group);
110*3c602fabSXin LI 	ND_PRINT((ndo, "group=%d ", hp->hsrp_group));
111*3c602fabSXin LI 	ND_TCHECK(hp->hsrp_reserved);
112a90e161bSBill Fenner 	if (hp->hsrp_reserved != 0) {
113*3c602fabSXin LI 		ND_PRINT((ndo, "[reserved=%d!] ", hp->hsrp_reserved));
114a90e161bSBill Fenner 	}
115*3c602fabSXin LI 	ND_TCHECK(hp->hsrp_virtaddr);
116*3c602fabSXin LI 	ND_PRINT((ndo, "addr=%s", ipaddr_string(ndo, &hp->hsrp_virtaddr)));
117*3c602fabSXin LI 	if (ndo->ndo_vflag) {
118*3c602fabSXin LI 		ND_PRINT((ndo, " hellotime="));
119*3c602fabSXin LI 		relts_print(ndo, hp->hsrp_hellotime);
120*3c602fabSXin LI 		ND_PRINT((ndo, " holdtime="));
121*3c602fabSXin LI 		relts_print(ndo, hp->hsrp_holdtime);
122*3c602fabSXin LI 		ND_PRINT((ndo, " priority=%d", hp->hsrp_priority));
123*3c602fabSXin LI 		ND_PRINT((ndo, " auth=\""));
124*3c602fabSXin LI 		if (fn_printn(ndo, hp->hsrp_authdata, sizeof(hp->hsrp_authdata),
125*3c602fabSXin LI 		    ndo->ndo_snapend)) {
126*3c602fabSXin LI 			ND_PRINT((ndo, "\""));
127f4d0c64aSSam Leffler 			goto trunc;
128f4d0c64aSSam Leffler 		}
129*3c602fabSXin LI 		ND_PRINT((ndo, "\""));
130a90e161bSBill Fenner 	}
131a90e161bSBill Fenner 	return;
132a90e161bSBill Fenner trunc:
133*3c602fabSXin LI 	ND_PRINT((ndo, "[|hsrp]"));
134a90e161bSBill Fenner }
135