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