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