OSDN Git Service

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