The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 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 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 30 | /* \summary: Cisco Hot Standby Router Protocol (HSRP) printer */ |
| 31 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 32 | /* specification: RFC 2281 for version 1 */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 33 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 34 | #ifdef HAVE_CONFIG_H |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 35 | #include <config.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 36 | #endif |
| 37 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 38 | #include "netdissect-stdinc.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 39 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 40 | #include "netdissect.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 41 | #include "addrtoname.h" |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 42 | #include "extract.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 43 | |
| 44 | /* HSRP op code types. */ |
| 45 | static const char *op_code_str[] = { |
| 46 | "hello", |
| 47 | "coup", |
| 48 | "resign" |
| 49 | }; |
| 50 | |
| 51 | /* HSRP states and associated names. */ |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 52 | static const struct tok states[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 53 | { 0, "initial" }, |
| 54 | { 1, "learn" }, |
| 55 | { 2, "listen" }, |
| 56 | { 4, "speak" }, |
| 57 | { 8, "standby" }, |
| 58 | { 16, "active" }, |
| 59 | { 0, NULL } |
| 60 | }; |
| 61 | |
| 62 | /* |
| 63 | * RFC 2281: |
| 64 | * |
| 65 | * 0 1 2 3 |
| 66 | * 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 |
| 67 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 68 | * | Version | Op Code | State | Hellotime | |
| 69 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 70 | * | Holdtime | Priority | Group | Reserved | |
| 71 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 72 | * | Authentication Data | |
| 73 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 74 | * | Authentication Data | |
| 75 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 76 | * | Virtual IP Address | |
| 77 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 78 | */ |
| 79 | |
| 80 | #define HSRP_AUTH_SIZE 8 |
| 81 | |
| 82 | /* HSRP protocol header. */ |
| 83 | struct hsrp { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 84 | nd_uint8_t hsrp_version; |
| 85 | nd_uint8_t hsrp_op_code; |
| 86 | nd_uint8_t hsrp_state; |
| 87 | nd_uint8_t hsrp_hellotime; |
| 88 | nd_uint8_t hsrp_holdtime; |
| 89 | nd_uint8_t hsrp_priority; |
| 90 | nd_uint8_t hsrp_group; |
| 91 | nd_uint8_t hsrp_reserved; |
| 92 | nd_byte hsrp_authdata[HSRP_AUTH_SIZE]; |
| 93 | nd_ipv4 hsrp_virtaddr; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 94 | }; |
| 95 | |
| 96 | void |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 97 | hsrp_print(netdissect_options *ndo, const u_char *bp, u_int len) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 98 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 99 | const struct hsrp *hp = (const struct hsrp *) bp; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 100 | uint8_t version; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 101 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 102 | ndo->ndo_protocol = "hsrp"; |
| 103 | version = GET_U_1(hp->hsrp_version); |
| 104 | ND_PRINT("HSRPv%u", version); |
| 105 | if (version != 0) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 106 | return; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 107 | ND_PRINT("-"); |
| 108 | ND_PRINT("%s ", |
| 109 | tok2strary(op_code_str, "unknown (%u)", GET_U_1(hp->hsrp_op_code))); |
| 110 | ND_PRINT("%u: ", len); |
| 111 | ND_PRINT("state=%s ", |
| 112 | tok2str(states, "Unknown (%u)", GET_U_1(hp->hsrp_state))); |
| 113 | ND_PRINT("group=%u ", GET_U_1(hp->hsrp_group)); |
| 114 | if (GET_U_1(hp->hsrp_reserved) != 0) { |
| 115 | ND_PRINT("[reserved=%u!] ", GET_U_1(hp->hsrp_reserved)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 116 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 117 | ND_PRINT("addr=%s", GET_IPADDR_STRING(hp->hsrp_virtaddr)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 118 | if (ndo->ndo_vflag) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 119 | ND_PRINT(" hellotime="); |
| 120 | unsigned_relts_print(ndo, GET_U_1(hp->hsrp_hellotime)); |
| 121 | ND_PRINT(" holdtime="); |
| 122 | unsigned_relts_print(ndo, GET_U_1(hp->hsrp_holdtime)); |
| 123 | ND_PRINT(" priority=%u", GET_U_1(hp->hsrp_priority)); |
| 124 | ND_PRINT(" auth=\""); |
| 125 | /* |
| 126 | * RFC 2281 Section 5.1 does not specify the encoding of |
| 127 | * Authentication Data explicitly, but zero padding can be |
| 128 | * inferred from the "recommended default value". |
| 129 | */ |
| 130 | nd_printjnp(ndo, hp->hsrp_authdata, HSRP_AUTH_SIZE); |
| 131 | ND_PRINT("\""); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 132 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 133 | } |