]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/tcpdump/print-hsrp.c
Commit vendor update for vulnerabilities found by
[FreeBSD/FreeBSD.git] / contrib / 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.2 2001/10/08 16:12:37 fenner 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 const char *op_code_str[] = {
51         "hello",
52         "coup",
53         "resign"
54 };
55
56 /* HSRP states and associated names. */
57 static struct tok states[] = {
58         {  0, "initial" },
59         {  1, "learn" },
60         {  2, "listen" },
61         {  4, "speak" },
62         {  8, "standby" },
63         { 16, "active" },
64         {  0, NULL }
65 };
66
67 /*
68  * RFC 2281:
69  *
70  *  0                   1                   2                   3
71  *  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
72  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
73  * |   Version     |   Op Code     |     State     |   Hellotime   |
74  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
75  * |   Holdtime    |   Priority    |     Group     |   Reserved    |
76  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
77  * |                      Authentication  Data                     |
78  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
79  * |                      Authentication  Data                     |
80  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
81  * |                      Virtual IP Address                       |
82  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
83  */
84
85 #define HSRP_AUTH_SIZE  8
86
87 /* HSRP protocol header. */
88 struct hsrp {
89         u_char          hsrp_version;
90         u_char          hsrp_op_code;
91         u_char          hsrp_state;
92         u_char          hsrp_hellotime;
93         u_char          hsrp_holdtime;
94         u_char          hsrp_priority;
95         u_char          hsrp_group;
96         u_char          hsrp_reserved;
97         u_char          hsrp_authdata[HSRP_AUTH_SIZE];
98         struct in_addr  hsrp_virtaddr;
99 };
100
101 void
102 hsrp_print(register const u_char *bp, register u_int len)
103 {
104         struct hsrp *hp = (struct hsrp *) bp;
105
106         TCHECK(hp->hsrp_version);
107         printf("HSRPv%d", hp->hsrp_version);
108         if (hp->hsrp_version != 0)
109                 return;
110         TCHECK(hp->hsrp_op_code);
111         printf("-");
112         printf("%s ", tok2strary(op_code_str, "unknown (%d)", hp->hsrp_op_code));
113         printf("%d: ", len);
114         TCHECK(hp->hsrp_state);
115         printf("state=%s ", tok2str(states, "Unknown (%d)", hp->hsrp_state));
116         TCHECK(hp->hsrp_group);
117         printf("group=%d ", hp->hsrp_group);
118         TCHECK(hp->hsrp_reserved);
119         if (hp->hsrp_reserved != 0) {
120                 printf("[reserved=%d!] ", hp->hsrp_reserved);
121         }
122         TCHECK2(hp->hsrp_virtaddr, sizeof(hp->hsrp_virtaddr));
123         printf("addr=%s", ipaddr_string(&hp->hsrp_virtaddr));
124         if (vflag) {
125                 printf(" hellotime=");
126                 relts_print(hp->hsrp_hellotime);
127                 printf(" holdtime=");
128                 relts_print(hp->hsrp_holdtime);
129                 printf(" priority=%d", hp->hsrp_priority);
130                 printf(" auth=\"");
131                 fn_printn(hp->hsrp_authdata, sizeof(hp->hsrp_authdata), NULL);
132                 printf("\"");
133         }
134         return;
135 trunc:
136         printf("[|hsrp]");
137 }