xref: /freebsd/contrib/tcpdump/print-hsrp.c (revision a90e161be323456b08b7fe13acb201536809510f)
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 
32a90e161bSBill Fenner #ifndef lint
33a90e161bSBill Fenner static const char rcsid[] =
34a90e161bSBill Fenner     "@(#) $Header: /tcpdump/master/tcpdump/print-hsrp.c,v 1.2 2001/10/08 16:12:37 fenner Exp $";
35a90e161bSBill Fenner #endif
36a90e161bSBill Fenner 
37a90e161bSBill Fenner #ifdef HAVE_CONFIG_H
38a90e161bSBill Fenner #include "config.h"
39a90e161bSBill Fenner #endif
40a90e161bSBill Fenner 
41a90e161bSBill Fenner #include <sys/types.h>
42a90e161bSBill Fenner 
43a90e161bSBill Fenner #include <stdio.h>
44a90e161bSBill Fenner #include <netinet/in.h>
45a90e161bSBill Fenner 
46a90e161bSBill Fenner #include "interface.h"
47a90e161bSBill Fenner #include "addrtoname.h"
48a90e161bSBill Fenner 
49a90e161bSBill Fenner /* HSRP op code types. */
50a90e161bSBill Fenner static const char *op_code_str[] = {
51a90e161bSBill Fenner 	"hello",
52a90e161bSBill Fenner 	"coup",
53a90e161bSBill Fenner 	"resign"
54a90e161bSBill Fenner };
55a90e161bSBill Fenner 
56a90e161bSBill Fenner /* HSRP states and associated names. */
57a90e161bSBill Fenner static struct tok states[] = {
58a90e161bSBill Fenner 	{  0, "initial" },
59a90e161bSBill Fenner 	{  1, "learn" },
60a90e161bSBill Fenner 	{  2, "listen" },
61a90e161bSBill Fenner 	{  4, "speak" },
62a90e161bSBill Fenner 	{  8, "standby" },
63a90e161bSBill Fenner 	{ 16, "active" },
64a90e161bSBill Fenner 	{  0, NULL }
65a90e161bSBill Fenner };
66a90e161bSBill Fenner 
67a90e161bSBill Fenner /*
68a90e161bSBill Fenner  * RFC 2281:
69a90e161bSBill Fenner  *
70a90e161bSBill Fenner  *  0                   1                   2                   3
71a90e161bSBill 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
72a90e161bSBill Fenner  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73a90e161bSBill Fenner  * |   Version     |   Op Code     |     State     |   Hellotime   |
74a90e161bSBill Fenner  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75a90e161bSBill Fenner  * |   Holdtime    |   Priority    |     Group     |   Reserved    |
76a90e161bSBill Fenner  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77a90e161bSBill Fenner  * |                      Authentication  Data                     |
78a90e161bSBill Fenner  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
79a90e161bSBill Fenner  * |                      Authentication  Data                     |
80a90e161bSBill Fenner  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
81a90e161bSBill Fenner  * |                      Virtual IP Address                       |
82a90e161bSBill Fenner  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83a90e161bSBill Fenner  */
84a90e161bSBill Fenner 
85a90e161bSBill Fenner #define HSRP_AUTH_SIZE	8
86a90e161bSBill Fenner 
87a90e161bSBill Fenner /* HSRP protocol header. */
88a90e161bSBill Fenner struct hsrp {
89a90e161bSBill Fenner 	u_char		hsrp_version;
90a90e161bSBill Fenner 	u_char		hsrp_op_code;
91a90e161bSBill Fenner 	u_char		hsrp_state;
92a90e161bSBill Fenner 	u_char		hsrp_hellotime;
93a90e161bSBill Fenner 	u_char		hsrp_holdtime;
94a90e161bSBill Fenner 	u_char		hsrp_priority;
95a90e161bSBill Fenner 	u_char		hsrp_group;
96a90e161bSBill Fenner 	u_char		hsrp_reserved;
97a90e161bSBill Fenner 	u_char		hsrp_authdata[HSRP_AUTH_SIZE];
98a90e161bSBill Fenner 	struct in_addr	hsrp_virtaddr;
99a90e161bSBill Fenner };
100a90e161bSBill Fenner 
101a90e161bSBill Fenner void
102a90e161bSBill Fenner hsrp_print(register const u_char *bp, register u_int len)
103a90e161bSBill Fenner {
104a90e161bSBill Fenner 	struct hsrp *hp = (struct hsrp *) bp;
105a90e161bSBill Fenner 
106a90e161bSBill Fenner 	TCHECK(hp->hsrp_version);
107a90e161bSBill Fenner 	printf("HSRPv%d", hp->hsrp_version);
108a90e161bSBill Fenner 	if (hp->hsrp_version != 0)
109a90e161bSBill Fenner 		return;
110a90e161bSBill Fenner 	TCHECK(hp->hsrp_op_code);
111a90e161bSBill Fenner 	printf("-");
112a90e161bSBill Fenner 	printf("%s ", tok2strary(op_code_str, "unknown (%d)", hp->hsrp_op_code));
113a90e161bSBill Fenner 	printf("%d: ", len);
114a90e161bSBill Fenner 	TCHECK(hp->hsrp_state);
115a90e161bSBill Fenner 	printf("state=%s ", tok2str(states, "Unknown (%d)", hp->hsrp_state));
116a90e161bSBill Fenner 	TCHECK(hp->hsrp_group);
117a90e161bSBill Fenner 	printf("group=%d ", hp->hsrp_group);
118a90e161bSBill Fenner 	TCHECK(hp->hsrp_reserved);
119a90e161bSBill Fenner 	if (hp->hsrp_reserved != 0) {
120a90e161bSBill Fenner 		printf("[reserved=%d!] ", hp->hsrp_reserved);
121a90e161bSBill Fenner 	}
122a90e161bSBill Fenner 	TCHECK2(hp->hsrp_virtaddr, sizeof(hp->hsrp_virtaddr));
123a90e161bSBill Fenner 	printf("addr=%s", ipaddr_string(&hp->hsrp_virtaddr));
124a90e161bSBill Fenner 	if (vflag) {
125a90e161bSBill Fenner 		printf(" hellotime=");
126a90e161bSBill Fenner 		relts_print(hp->hsrp_hellotime);
127a90e161bSBill Fenner 		printf(" holdtime=");
128a90e161bSBill Fenner 		relts_print(hp->hsrp_holdtime);
129a90e161bSBill Fenner 		printf(" priority=%d", hp->hsrp_priority);
130a90e161bSBill Fenner 		printf(" auth=\"");
131a90e161bSBill Fenner 		fn_printn(hp->hsrp_authdata, sizeof(hp->hsrp_authdata), NULL);
132a90e161bSBill Fenner 		printf("\"");
133a90e161bSBill Fenner 	}
134a90e161bSBill Fenner 	return;
135a90e161bSBill Fenner trunc:
136a90e161bSBill Fenner 	printf("[|hsrp]");
137a90e161bSBill Fenner }
138