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