1a90e161bSBill Fenner /* 2a90e161bSBill Fenner * Copyright (C) 2001 Julian Cowley 3a90e161bSBill Fenner * All rights reserved. 4a90e161bSBill Fenner * 5a90e161bSBill Fenner * Redistribution and use in source and binary forms, with or without 6a90e161bSBill Fenner * modification, are permitted provided that the following conditions 7a90e161bSBill Fenner * are met: 8a90e161bSBill Fenner * 1. Redistributions of source code must retain the above copyright 9a90e161bSBill Fenner * notice, this list of conditions and the following disclaimer. 10a90e161bSBill Fenner * 2. Redistributions in binary form must reproduce the above copyright 11a90e161bSBill Fenner * notice, this list of conditions and the following disclaimer in the 12a90e161bSBill Fenner * documentation and/or other materials provided with the distribution. 13a90e161bSBill Fenner * 3. Neither the name of the project nor the names of its contributors 14a90e161bSBill Fenner * may be used to endorse or promote products derived from this software 15a90e161bSBill Fenner * without specific prior written permission. 16a90e161bSBill Fenner * 17a90e161bSBill Fenner * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 18a90e161bSBill Fenner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19a90e161bSBill Fenner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20a90e161bSBill Fenner * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 21a90e161bSBill Fenner * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22a90e161bSBill Fenner * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23a90e161bSBill Fenner * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24a90e161bSBill Fenner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25a90e161bSBill Fenner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26a90e161bSBill Fenner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27a90e161bSBill Fenner * SUCH DAMAGE. 28a90e161bSBill Fenner */ 29a90e161bSBill Fenner 303340d773SGleb Smirnoff /* \summary: Cisco Hot Standby Router Protocol (HSRP) printer */ 313340d773SGleb Smirnoff 32*ee67461eSJoseph Mingrone /* specification: RFC 2281 for version 1 */ 33a90e161bSBill Fenner 34*ee67461eSJoseph Mingrone #include <config.h> 35a90e161bSBill Fenner 36*ee67461eSJoseph Mingrone #include "netdissect-stdinc.h" 37a90e161bSBill Fenner 383340d773SGleb Smirnoff #include "netdissect.h" 39a90e161bSBill Fenner #include "addrtoname.h" 40*ee67461eSJoseph Mingrone #include "extract.h" 41a90e161bSBill Fenner 42a90e161bSBill Fenner /* HSRP op code types. */ 43a90e161bSBill Fenner static const char *op_code_str[] = { 44a90e161bSBill Fenner "hello", 45a90e161bSBill Fenner "coup", 46a90e161bSBill Fenner "resign" 47a90e161bSBill Fenner }; 48a90e161bSBill Fenner 49a90e161bSBill Fenner /* HSRP states and associated names. */ 503c602fabSXin LI static const struct tok states[] = { 51a90e161bSBill Fenner { 0, "initial" }, 52a90e161bSBill Fenner { 1, "learn" }, 53a90e161bSBill Fenner { 2, "listen" }, 54a90e161bSBill Fenner { 4, "speak" }, 55a90e161bSBill Fenner { 8, "standby" }, 56a90e161bSBill Fenner { 16, "active" }, 57a90e161bSBill Fenner { 0, NULL } 58a90e161bSBill Fenner }; 59a90e161bSBill Fenner 60a90e161bSBill Fenner /* 61a90e161bSBill Fenner * RFC 2281: 62a90e161bSBill Fenner * 63a90e161bSBill Fenner * 0 1 2 3 64a90e161bSBill Fenner * 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 65a90e161bSBill Fenner * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 66a90e161bSBill Fenner * | Version | Op Code | State | Hellotime | 67a90e161bSBill Fenner * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 68a90e161bSBill Fenner * | Holdtime | Priority | Group | Reserved | 69a90e161bSBill Fenner * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 70a90e161bSBill Fenner * | Authentication Data | 71a90e161bSBill Fenner * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 72a90e161bSBill Fenner * | Authentication Data | 73a90e161bSBill Fenner * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 74a90e161bSBill Fenner * | Virtual IP Address | 75a90e161bSBill Fenner * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 76a90e161bSBill Fenner */ 77a90e161bSBill Fenner 78a90e161bSBill Fenner #define HSRP_AUTH_SIZE 8 79a90e161bSBill Fenner 80a90e161bSBill Fenner /* HSRP protocol header. */ 81a90e161bSBill Fenner struct hsrp { 82*ee67461eSJoseph Mingrone nd_uint8_t hsrp_version; 83*ee67461eSJoseph Mingrone nd_uint8_t hsrp_op_code; 84*ee67461eSJoseph Mingrone nd_uint8_t hsrp_state; 85*ee67461eSJoseph Mingrone nd_uint8_t hsrp_hellotime; 86*ee67461eSJoseph Mingrone nd_uint8_t hsrp_holdtime; 87*ee67461eSJoseph Mingrone nd_uint8_t hsrp_priority; 88*ee67461eSJoseph Mingrone nd_uint8_t hsrp_group; 89*ee67461eSJoseph Mingrone nd_uint8_t hsrp_reserved; 90*ee67461eSJoseph Mingrone nd_byte hsrp_authdata[HSRP_AUTH_SIZE]; 91*ee67461eSJoseph Mingrone nd_ipv4 hsrp_virtaddr; 92a90e161bSBill Fenner }; 93a90e161bSBill Fenner 94a90e161bSBill Fenner void 95*ee67461eSJoseph Mingrone hsrp_print(netdissect_options *ndo, const u_char *bp, u_int len) 96a90e161bSBill Fenner { 973340d773SGleb Smirnoff const struct hsrp *hp = (const struct hsrp *) bp; 98*ee67461eSJoseph Mingrone uint8_t version; 99a90e161bSBill Fenner 100*ee67461eSJoseph Mingrone ndo->ndo_protocol = "hsrp"; 101*ee67461eSJoseph Mingrone version = GET_U_1(hp->hsrp_version); 102*ee67461eSJoseph Mingrone ND_PRINT("HSRPv%u", version); 103*ee67461eSJoseph Mingrone if (version != 0) 104a90e161bSBill Fenner return; 105*ee67461eSJoseph Mingrone ND_PRINT("-"); 106*ee67461eSJoseph Mingrone ND_PRINT("%s ", 107*ee67461eSJoseph Mingrone tok2strary(op_code_str, "unknown (%u)", GET_U_1(hp->hsrp_op_code))); 108*ee67461eSJoseph Mingrone ND_PRINT("%u: ", len); 109*ee67461eSJoseph Mingrone ND_PRINT("state=%s ", 110*ee67461eSJoseph Mingrone tok2str(states, "Unknown (%u)", GET_U_1(hp->hsrp_state))); 111*ee67461eSJoseph Mingrone ND_PRINT("group=%u ", GET_U_1(hp->hsrp_group)); 112*ee67461eSJoseph Mingrone if (GET_U_1(hp->hsrp_reserved) != 0) { 113*ee67461eSJoseph Mingrone ND_PRINT("[reserved=%u!] ", GET_U_1(hp->hsrp_reserved)); 114a90e161bSBill Fenner } 115*ee67461eSJoseph Mingrone ND_PRINT("addr=%s", GET_IPADDR_STRING(hp->hsrp_virtaddr)); 1163c602fabSXin LI if (ndo->ndo_vflag) { 117*ee67461eSJoseph Mingrone ND_PRINT(" hellotime="); 118*ee67461eSJoseph Mingrone unsigned_relts_print(ndo, GET_U_1(hp->hsrp_hellotime)); 119*ee67461eSJoseph Mingrone ND_PRINT(" holdtime="); 120*ee67461eSJoseph Mingrone unsigned_relts_print(ndo, GET_U_1(hp->hsrp_holdtime)); 121*ee67461eSJoseph Mingrone ND_PRINT(" priority=%u", GET_U_1(hp->hsrp_priority)); 122*ee67461eSJoseph Mingrone ND_PRINT(" auth=\""); 123*ee67461eSJoseph Mingrone /* 124*ee67461eSJoseph Mingrone * RFC 2281 Section 5.1 does not specify the encoding of 125*ee67461eSJoseph Mingrone * Authentication Data explicitly, but zero padding can be 126*ee67461eSJoseph Mingrone * inferred from the "recommended default value". 127*ee67461eSJoseph Mingrone */ 128*ee67461eSJoseph Mingrone nd_printjnp(ndo, hp->hsrp_authdata, HSRP_AUTH_SIZE); 129*ee67461eSJoseph Mingrone ND_PRINT("\""); 130f4d0c64aSSam Leffler } 131a90e161bSBill Fenner } 132