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