1 /* $OpenBSD: print-hsrp.c,v 1.2 2002/01/22 18:52:38 mickey Exp $ */ 2 3 /* 4 * Copyright (C) 2001 Julian Cowley 5 * All rights reserved. 6 * 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. 18 * 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. 30 */ 31 32 /* Cisco Hot Standby Router Protocol (HSRP). */ 33 34 #ifndef lint 35 static const char rcsid[] = 36 "@(#) $Header: /home/cvs/src/usr.sbin/tcpdump/print-hsrp.c,v 1.2 2002/01/22 18:52:38 mickey Exp $"; 37 #endif 38 39 #ifdef HAVE_CONFIG_H 40 #include "config.h" 41 #endif 42 43 #include <sys/types.h> 44 45 #include <stdio.h> 46 #include <netinet/in.h> 47 48 #include "interface.h" 49 #include "addrtoname.h" 50 51 /* HSRP op code types. */ 52 static const char *op_code_str[] = { 53 "hello", 54 "coup", 55 "resign" 56 }; 57 58 /* HSRP states and associated names. */ 59 static struct tok states[] = { 60 { 0, "initial" }, 61 { 1, "learn" }, 62 { 2, "listen" }, 63 { 4, "speak" }, 64 { 8, "standby" }, 65 { 16, "active" }, 66 { 0, NULL } 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 struct hsrp *hp = (struct hsrp *) bp; 107 108 TCHECK(hp->hsrp_version); 109 printf("HSRPv%d", hp->hsrp_version); 110 if (hp->hsrp_version != 0) 111 return; 112 TCHECK(hp->hsrp_op_code); 113 printf("-"); 114 if (hp->hsrp_op_code >= sizeof(op_code_str)/sizeof(*op_code_str)) 115 printf("unknown (%d) ", hp->hsrp_op_code); 116 else 117 printf("%s ", op_code_str[hp->hsrp_op_code]); 118 printf("%d: ", len); 119 TCHECK(hp->hsrp_state); 120 printf("state=%s ", tok2str(states, "Unknown (%d)", hp->hsrp_state)); 121 TCHECK(hp->hsrp_group); 122 printf("group=%d ", hp->hsrp_group); 123 TCHECK(hp->hsrp_reserved); 124 if (hp->hsrp_reserved != 0) { 125 printf("[reserved=%d!] ", hp->hsrp_reserved); 126 } 127 TCHECK2(hp->hsrp_virtaddr, sizeof(hp->hsrp_virtaddr)); 128 printf("addr=%s", ipaddr_string(&hp->hsrp_virtaddr)); 129 if (vflag) { 130 printf(" hellotime="); 131 relts_print(hp->hsrp_hellotime); 132 printf(" holdtime="); 133 relts_print(hp->hsrp_holdtime); 134 printf(" priority=%d", hp->hsrp_priority); 135 printf(" auth=\""); 136 fn_printn(hp->hsrp_authdata, sizeof(hp->hsrp_authdata), NULL); 137 printf("\""); 138 } 139 return; 140 trunc: 141 printf("[|hsrp]"); 142 } 143