The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1995, 1996 |
| 3 | * The Regents of the University of California. All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that: (1) source code distributions |
| 7 | * retain the above copyright notice and this paragraph in its entirety, (2) |
| 8 | * distributions including binary code include the above copyright notice and |
| 9 | * this paragraph in its entirety in the documentation or other materials |
| 10 | * provided with the distribution, and (3) all advertising materials mentioning |
| 11 | * features or use of this software display the following acknowledgement: |
| 12 | * ``This product includes software developed by the University of California, |
| 13 | * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of |
| 14 | * the University nor the names of its contributors may be used to endorse |
| 15 | * or promote products derived from this software without specific prior |
| 16 | * written permission. |
| 17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
| 20 | */ |
| 21 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 22 | /* \summary: Protocol Independent Multicast (PIM) printer */ |
| 23 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 24 | #ifdef HAVE_CONFIG_H |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 25 | #include <config.h> |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 26 | #endif |
| 27 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 28 | #include "netdissect-stdinc.h" |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 29 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 30 | #include "netdissect.h" |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 31 | #include "addrtoname.h" |
| 32 | #include "extract.h" |
| 33 | |
| 34 | #include "ip.h" |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 35 | #include "ip6.h" |
| 36 | #include "ipproto.h" |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 37 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 38 | #define PIMV1_TYPE_QUERY 0 |
| 39 | #define PIMV1_TYPE_REGISTER 1 |
| 40 | #define PIMV1_TYPE_REGISTER_STOP 2 |
| 41 | #define PIMV1_TYPE_JOIN_PRUNE 3 |
| 42 | #define PIMV1_TYPE_RP_REACHABILITY 4 |
| 43 | #define PIMV1_TYPE_ASSERT 5 |
| 44 | #define PIMV1_TYPE_GRAFT 6 |
| 45 | #define PIMV1_TYPE_GRAFT_ACK 7 |
| 46 | |
| 47 | static const struct tok pimv1_type_str[] = { |
| 48 | { PIMV1_TYPE_QUERY, "Query" }, |
| 49 | { PIMV1_TYPE_REGISTER, "Register" }, |
| 50 | { PIMV1_TYPE_REGISTER_STOP, "Register-Stop" }, |
| 51 | { PIMV1_TYPE_JOIN_PRUNE, "Join/Prune" }, |
| 52 | { PIMV1_TYPE_RP_REACHABILITY, "RP-reachable" }, |
| 53 | { PIMV1_TYPE_ASSERT, "Assert" }, |
| 54 | { PIMV1_TYPE_GRAFT, "Graft" }, |
| 55 | { PIMV1_TYPE_GRAFT_ACK, "Graft-ACK" }, |
| 56 | { 0, NULL } |
| 57 | }; |
| 58 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 59 | #define PIMV2_TYPE_HELLO 0 |
| 60 | #define PIMV2_TYPE_REGISTER 1 |
| 61 | #define PIMV2_TYPE_REGISTER_STOP 2 |
| 62 | #define PIMV2_TYPE_JOIN_PRUNE 3 |
| 63 | #define PIMV2_TYPE_BOOTSTRAP 4 |
| 64 | #define PIMV2_TYPE_ASSERT 5 |
| 65 | #define PIMV2_TYPE_GRAFT 6 |
| 66 | #define PIMV2_TYPE_GRAFT_ACK 7 |
| 67 | #define PIMV2_TYPE_CANDIDATE_RP 8 |
| 68 | #define PIMV2_TYPE_PRUNE_REFRESH 9 |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 69 | #define PIMV2_TYPE_DF_ELECTION 10 |
| 70 | #define PIMV2_TYPE_ECMP_REDIRECT 11 |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 71 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 72 | static const struct tok pimv2_type_values[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 73 | { PIMV2_TYPE_HELLO, "Hello" }, |
| 74 | { PIMV2_TYPE_REGISTER, "Register" }, |
| 75 | { PIMV2_TYPE_REGISTER_STOP, "Register Stop" }, |
| 76 | { PIMV2_TYPE_JOIN_PRUNE, "Join / Prune" }, |
| 77 | { PIMV2_TYPE_BOOTSTRAP, "Bootstrap" }, |
| 78 | { PIMV2_TYPE_ASSERT, "Assert" }, |
| 79 | { PIMV2_TYPE_GRAFT, "Graft" }, |
| 80 | { PIMV2_TYPE_GRAFT_ACK, "Graft Acknowledgement" }, |
| 81 | { PIMV2_TYPE_CANDIDATE_RP, "Candidate RP Advertisement" }, |
| 82 | { PIMV2_TYPE_PRUNE_REFRESH, "Prune Refresh" }, |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 83 | { PIMV2_TYPE_DF_ELECTION, "DF Election" }, |
| 84 | { PIMV2_TYPE_ECMP_REDIRECT, "ECMP Redirect" }, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 85 | { 0, NULL} |
| 86 | }; |
| 87 | |
| 88 | #define PIMV2_HELLO_OPTION_HOLDTIME 1 |
| 89 | #define PIMV2_HELLO_OPTION_LANPRUNEDELAY 2 |
| 90 | #define PIMV2_HELLO_OPTION_DR_PRIORITY_OLD 18 |
| 91 | #define PIMV2_HELLO_OPTION_DR_PRIORITY 19 |
| 92 | #define PIMV2_HELLO_OPTION_GENID 20 |
| 93 | #define PIMV2_HELLO_OPTION_REFRESH_CAP 21 |
| 94 | #define PIMV2_HELLO_OPTION_BIDIR_CAP 22 |
| 95 | #define PIMV2_HELLO_OPTION_ADDRESS_LIST 24 |
| 96 | #define PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD 65001 |
| 97 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 98 | static const struct tok pimv2_hello_option_values[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 99 | { PIMV2_HELLO_OPTION_HOLDTIME, "Hold Time" }, |
| 100 | { PIMV2_HELLO_OPTION_LANPRUNEDELAY, "LAN Prune Delay" }, |
| 101 | { PIMV2_HELLO_OPTION_DR_PRIORITY_OLD, "DR Priority (Old)" }, |
| 102 | { PIMV2_HELLO_OPTION_DR_PRIORITY, "DR Priority" }, |
| 103 | { PIMV2_HELLO_OPTION_GENID, "Generation ID" }, |
| 104 | { PIMV2_HELLO_OPTION_REFRESH_CAP, "State Refresh Capability" }, |
| 105 | { PIMV2_HELLO_OPTION_BIDIR_CAP, "Bi-Directional Capability" }, |
| 106 | { PIMV2_HELLO_OPTION_ADDRESS_LIST, "Address List" }, |
| 107 | { PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD, "Address List (Old)" }, |
| 108 | { 0, NULL} |
| 109 | }; |
| 110 | |
| 111 | #define PIMV2_REGISTER_FLAG_LEN 4 |
| 112 | #define PIMV2_REGISTER_FLAG_BORDER 0x80000000 |
| 113 | #define PIMV2_REGISTER_FLAG_NULL 0x40000000 |
| 114 | |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 115 | static const struct tok pimv2_register_flag_values[] = { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 116 | { PIMV2_REGISTER_FLAG_BORDER, "Border" }, |
| 117 | { PIMV2_REGISTER_FLAG_NULL, "Null" }, |
| 118 | { 0, NULL} |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 119 | }; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 120 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 121 | #define PIMV2_DF_ELECTION_OFFER 1 |
| 122 | #define PIMV2_DF_ELECTION_WINNER 2 |
| 123 | #define PIMV2_DF_ELECTION_BACKOFF 3 |
| 124 | #define PIMV2_DF_ELECTION_PASS 4 |
| 125 | |
| 126 | static const struct tok pimv2_df_election_flag_values[] = { |
| 127 | { PIMV2_DF_ELECTION_OFFER, "Offer" }, |
| 128 | { PIMV2_DF_ELECTION_WINNER, "Winner" }, |
| 129 | { PIMV2_DF_ELECTION_BACKOFF, "Backoff" }, |
| 130 | { PIMV2_DF_ELECTION_PASS, "Pass" }, |
| 131 | { 0, NULL} |
| 132 | }; |
| 133 | |
| 134 | #define PIMV2_DF_ELECTION_PASS_BACKOFF_STR(x) ( \ |
| 135 | x == PIMV2_DF_ELECTION_BACKOFF ? "offer" : "new winner" ) |
| 136 | |
| 137 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 138 | /* |
| 139 | * XXX: We consider a case where IPv6 is not ready yet for portability, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 140 | * but PIM dependent definitions should be independent of IPv6... |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 141 | */ |
| 142 | |
| 143 | struct pim { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 144 | nd_uint8_t pim_typever; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 145 | /* upper 4bit: PIM version number; 2 for PIMv2 */ |
| 146 | /* lower 4bit: the PIM message type, currently they are: |
| 147 | * Hello, Register, Register-Stop, Join/Prune, |
| 148 | * Bootstrap, Assert, Graft (PIM-DM only), |
| 149 | * Graft-Ack (PIM-DM only), C-RP-Adv |
| 150 | */ |
| 151 | #define PIM_VER(x) (((x) & 0xf0) >> 4) |
| 152 | #define PIM_TYPE(x) ((x) & 0x0f) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 153 | nd_uint8_t pim_rsv; /* Reserved in v1, subtype+address length in v2 */ |
| 154 | #define PIM_SUBTYPE(x) (((x) & 0xf0) >> 4) |
| 155 | nd_uint16_t pim_cksum; /* IP style check sum */ |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 156 | }; |
| 157 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 158 | static void pimv2_print(netdissect_options *, const u_char *bp, u_int len, const u_char *); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 159 | |
| 160 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 161 | pimv1_join_prune_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 162 | const u_char *bp, u_int len) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 163 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 164 | u_int ngroups, njoin, nprune; |
| 165 | u_int njp; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 166 | |
| 167 | /* If it's a single group and a single source, use 1-line output. */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 168 | if (ND_TTEST_LEN(bp, 30) && GET_U_1(bp + 11) == 1 && |
| 169 | ((njoin = GET_BE_U_2(bp + 20)) + GET_BE_U_2(bp + 22)) == 1) { |
| 170 | u_int hold; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 171 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 172 | ND_PRINT(" RPF %s ", GET_IPADDR_STRING(bp)); |
| 173 | hold = GET_BE_U_2(bp + 6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 174 | if (hold != 180) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 175 | ND_PRINT("Hold "); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 176 | unsigned_relts_print(ndo, hold); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 177 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 178 | ND_PRINT("%s (%s/%u, %s", njoin ? "Join" : "Prune", |
| 179 | GET_IPADDR_STRING(bp + 26), GET_U_1(bp + 25) & 0x3f, |
| 180 | GET_IPADDR_STRING(bp + 12)); |
| 181 | if (GET_BE_U_4(bp + 16) != 0xffffffff) |
| 182 | ND_PRINT("/%s", GET_IPADDR_STRING(bp + 16)); |
| 183 | ND_PRINT(") %s%s %s", |
| 184 | (GET_U_1(bp + 24) & 0x01) ? "Sparse" : "Dense", |
| 185 | (GET_U_1(bp + 25) & 0x80) ? " WC" : "", |
| 186 | (GET_U_1(bp + 25) & 0x40) ? "RP" : "SPT"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 187 | return; |
| 188 | } |
| 189 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 190 | if (len < sizeof(nd_ipv4)) |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 191 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 192 | if (ndo->ndo_vflag > 1) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 193 | ND_PRINT("\n"); |
| 194 | ND_PRINT(" Upstream Nbr: %s", GET_IPADDR_STRING(bp)); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 195 | bp += 4; |
| 196 | len -= 4; |
| 197 | if (len < 4) |
| 198 | goto trunc; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 199 | if (ndo->ndo_vflag > 1) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 200 | ND_PRINT("\n"); |
| 201 | ND_PRINT(" Hold time: "); |
| 202 | unsigned_relts_print(ndo, GET_BE_U_2(bp + 2)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 203 | if (ndo->ndo_vflag < 2) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 204 | return; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 205 | bp += 4; |
| 206 | len -= 4; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 207 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 208 | if (len < 4) |
| 209 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 210 | ngroups = GET_U_1(bp + 3); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 211 | bp += 4; |
| 212 | len -= 4; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 213 | while (ngroups != 0) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 214 | /* |
| 215 | * XXX - does the address have length "addrlen" and the |
| 216 | * mask length "maddrlen"? |
| 217 | */ |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 218 | if (len < 4) |
| 219 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 220 | ND_PRINT("\n\tGroup: %s", GET_IPADDR_STRING(bp)); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 221 | bp += 4; |
| 222 | len -= 4; |
| 223 | if (len < 4) |
| 224 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 225 | if (GET_BE_U_4(bp) != 0xffffffff) |
| 226 | ND_PRINT("/%s", GET_IPADDR_STRING(bp)); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 227 | bp += 4; |
| 228 | len -= 4; |
| 229 | if (len < 4) |
| 230 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 231 | njoin = GET_BE_U_2(bp); |
| 232 | nprune = GET_BE_U_2(bp + 2); |
| 233 | ND_PRINT(" joined: %u pruned: %u", njoin, nprune); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 234 | bp += 4; |
| 235 | len -= 4; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 236 | for (njp = 0; njp < (njoin + nprune); njp++) { |
| 237 | const char *type; |
| 238 | |
| 239 | if (njp < njoin) |
| 240 | type = "Join "; |
| 241 | else |
| 242 | type = "Prune"; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 243 | if (len < 6) |
| 244 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 245 | ND_PRINT("\n\t%s %s%s%s%s/%u", type, |
| 246 | (GET_U_1(bp) & 0x01) ? "Sparse " : "Dense ", |
| 247 | (GET_U_1(bp + 1) & 0x80) ? "WC " : "", |
| 248 | (GET_U_1(bp + 1) & 0x40) ? "RP " : "SPT ", |
| 249 | GET_IPADDR_STRING(bp + 2), |
| 250 | GET_U_1(bp + 1) & 0x3f); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 251 | bp += 6; |
| 252 | len -= 6; |
| 253 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 254 | ngroups--; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 255 | } |
| 256 | return; |
| 257 | trunc: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 258 | nd_print_trunc(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 262 | pimv1_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 263 | const u_char *bp, u_int len) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 264 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 265 | u_char type; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 266 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 267 | ndo->ndo_protocol = "pimv1"; |
| 268 | type = GET_U_1(bp + 1); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 269 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 270 | ND_PRINT(" %s", tok2str(pimv1_type_str, "[type %u]", type)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 271 | switch (type) { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 272 | case PIMV1_TYPE_QUERY: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 273 | if (ND_TTEST_1(bp + 8)) { |
| 274 | switch (GET_U_1(bp + 8) >> 4) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 275 | case 0: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 276 | ND_PRINT(" Dense-mode"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 277 | break; |
| 278 | case 1: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 279 | ND_PRINT(" Sparse-mode"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 280 | break; |
| 281 | case 2: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 282 | ND_PRINT(" Sparse-Dense-mode"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 283 | break; |
| 284 | default: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 285 | ND_PRINT(" mode-%u", GET_U_1(bp + 8) >> 4); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 286 | break; |
| 287 | } |
| 288 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 289 | if (ndo->ndo_vflag) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 290 | ND_PRINT(" (Hold-time "); |
| 291 | unsigned_relts_print(ndo, GET_BE_U_2(bp + 10)); |
| 292 | ND_PRINT(")"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 293 | } |
| 294 | break; |
| 295 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 296 | case PIMV1_TYPE_REGISTER: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 297 | ND_TCHECK_LEN(bp + 8, 20); /* ip header */ |
| 298 | ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp + 20), |
| 299 | GET_IPADDR_STRING(bp + 24)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 300 | break; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 301 | case PIMV1_TYPE_REGISTER_STOP: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 302 | ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp + 8), |
| 303 | GET_IPADDR_STRING(bp + 12)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 304 | break; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 305 | case PIMV1_TYPE_RP_REACHABILITY: |
| 306 | if (ndo->ndo_vflag) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 307 | ND_PRINT(" group %s", GET_IPADDR_STRING(bp + 8)); |
| 308 | if (GET_BE_U_4(bp + 12) != 0xffffffff) |
| 309 | ND_PRINT("/%s", GET_IPADDR_STRING(bp + 12)); |
| 310 | ND_PRINT(" RP %s hold ", GET_IPADDR_STRING(bp + 16)); |
| 311 | unsigned_relts_print(ndo, GET_BE_U_2(bp + 22)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 312 | } |
| 313 | break; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 314 | case PIMV1_TYPE_ASSERT: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 315 | ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp + 16), |
| 316 | GET_IPADDR_STRING(bp + 8)); |
| 317 | if (GET_BE_U_4(bp + 12) != 0xffffffff) |
| 318 | ND_PRINT("/%s", GET_IPADDR_STRING(bp + 12)); |
| 319 | ND_PRINT(" %s pref %u metric %u", |
| 320 | (GET_U_1(bp + 20) & 0x80) ? "RP-tree" : "SPT", |
| 321 | GET_BE_U_4(bp + 20) & 0x7fffffff, |
| 322 | GET_BE_U_4(bp + 24)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 323 | break; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 324 | case PIMV1_TYPE_JOIN_PRUNE: |
| 325 | case PIMV1_TYPE_GRAFT: |
| 326 | case PIMV1_TYPE_GRAFT_ACK: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 327 | if (ndo->ndo_vflag) { |
| 328 | if (len < 8) |
| 329 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 330 | pimv1_join_prune_print(ndo, bp + 8, len - 8); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 331 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 332 | break; |
| 333 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 334 | if ((GET_U_1(bp + 4) >> 4) != 1) |
| 335 | ND_PRINT(" [v%u]", GET_U_1(bp + 4) >> 4); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 336 | return; |
| 337 | |
| 338 | trunc: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 339 | nd_print_trunc(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /* |
| 343 | * auto-RP is a cisco protocol, documented at |
| 344 | * ftp://ftpeng.cisco.com/ipmulticast/specs/pim-autorp-spec01.txt |
| 345 | * |
| 346 | * This implements version 1+, dated Sept 9, 1998. |
| 347 | */ |
| 348 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 349 | cisco_autorp_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 350 | const u_char *bp, u_int len) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 351 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 352 | u_int type; |
| 353 | u_int numrps; |
| 354 | u_int hold; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 355 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 356 | ndo->ndo_protocol = "cisco_autorp"; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 357 | if (len < 8) |
| 358 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 359 | ND_PRINT(" auto-rp "); |
| 360 | type = GET_U_1(bp); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 361 | switch (type) { |
| 362 | case 0x11: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 363 | ND_PRINT("candidate-advert"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 364 | break; |
| 365 | case 0x12: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 366 | ND_PRINT("mapping"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 367 | break; |
| 368 | default: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 369 | ND_PRINT("type-0x%02x", type); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 370 | break; |
| 371 | } |
| 372 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 373 | numrps = GET_U_1(bp + 1); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 374 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 375 | ND_PRINT(" Hold "); |
| 376 | hold = GET_BE_U_2(bp + 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 377 | if (hold) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 378 | unsigned_relts_print(ndo, GET_BE_U_2(bp + 2)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 379 | else |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 380 | ND_PRINT("FOREVER"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 381 | |
| 382 | /* Next 4 bytes are reserved. */ |
| 383 | |
| 384 | bp += 8; len -= 8; |
| 385 | |
| 386 | /*XXX skip unless -v? */ |
| 387 | |
| 388 | /* |
| 389 | * Rest of packet: |
| 390 | * numrps entries of the form: |
| 391 | * 32 bits: RP |
| 392 | * 6 bits: reserved |
| 393 | * 2 bits: PIM version supported, bit 0 is "supports v1", 1 is "v2". |
| 394 | * 8 bits: # of entries for this RP |
| 395 | * each entry: 7 bits: reserved, 1 bit: negative, |
| 396 | * 8 bits: mask 32 bits: source |
| 397 | * lather, rinse, repeat. |
| 398 | */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 399 | while (numrps != 0) { |
| 400 | u_int nentries; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 401 | char s; |
| 402 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 403 | if (len < 4) |
| 404 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 405 | ND_PRINT(" RP %s", GET_IPADDR_STRING(bp)); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 406 | bp += 4; |
| 407 | len -= 4; |
| 408 | if (len < 1) |
| 409 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 410 | switch (GET_U_1(bp) & 0x3) { |
| 411 | case 0: ND_PRINT(" PIMv?"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 412 | break; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 413 | case 1: ND_PRINT(" PIMv1"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 414 | break; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 415 | case 2: ND_PRINT(" PIMv2"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 416 | break; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 417 | case 3: ND_PRINT(" PIMv1+2"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 418 | break; |
| 419 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 420 | if (GET_U_1(bp) & 0xfc) |
| 421 | ND_PRINT(" [rsvd=0x%02x]", GET_U_1(bp) & 0xfc); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 422 | bp += 1; |
| 423 | len -= 1; |
| 424 | if (len < 1) |
| 425 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 426 | nentries = GET_U_1(bp); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 427 | bp += 1; |
| 428 | len -= 1; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 429 | s = ' '; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 430 | while (nentries != 0) { |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 431 | if (len < 6) |
| 432 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 433 | ND_PRINT("%c%s%s/%u", s, GET_U_1(bp) & 1 ? "!" : "", |
| 434 | GET_IPADDR_STRING(bp + 2), GET_U_1(bp + 1)); |
| 435 | if (GET_U_1(bp) & 0x02) { |
| 436 | ND_PRINT(" bidir"); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 437 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 438 | if (GET_U_1(bp) & 0xfc) { |
| 439 | ND_PRINT("[rsvd=0x%02x]", GET_U_1(bp) & 0xfc); |
JP Abgrall | 53f17a9 | 2014-02-12 14:02:41 -0800 | [diff] [blame] | 440 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 441 | s = ','; |
| 442 | bp += 6; len -= 6; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 443 | nentries--; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 444 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 445 | numrps--; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 446 | } |
| 447 | return; |
| 448 | |
| 449 | trunc: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 450 | nd_print_trunc(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 454 | pim_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 455 | const u_char *bp, u_int len, const u_char *bp2) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 456 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 457 | const struct pim *pim = (const struct pim *)bp; |
| 458 | uint8_t pim_typever; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 459 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 460 | ndo->ndo_protocol = "pim"; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 461 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 462 | pim_typever = GET_U_1(pim->pim_typever); |
| 463 | switch (PIM_VER(pim_typever)) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 464 | case 2: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 465 | if (!ndo->ndo_vflag) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 466 | ND_PRINT("PIMv%u, %s, length %u", |
| 467 | PIM_VER(pim_typever), |
| 468 | tok2str(pimv2_type_values,"Unknown Type",PIM_TYPE(pim_typever)), |
| 469 | len); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 470 | return; |
| 471 | } else { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 472 | ND_PRINT("PIMv%u, length %u\n\t%s", |
| 473 | PIM_VER(pim_typever), |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 474 | len, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 475 | tok2str(pimv2_type_values,"Unknown Type",PIM_TYPE(pim_typever))); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 476 | pimv2_print(ndo, bp, len, bp2); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 477 | } |
| 478 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 479 | default: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 480 | ND_PRINT("PIMv%u, length %u", |
| 481 | PIM_VER(pim_typever), |
| 482 | len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 483 | break; |
| 484 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 485 | } |
| 486 | |
| 487 | /* |
| 488 | * PIMv2 uses encoded address representations. |
| 489 | * |
| 490 | * The last PIM-SM I-D before RFC2117 was published specified the |
| 491 | * following representation for unicast addresses. However, RFC2117 |
| 492 | * specified no encoding for unicast addresses with the unicast |
| 493 | * address length specified in the header. Therefore, we have to |
| 494 | * guess which encoding is being used (Cisco's PIMv2 implementation |
| 495 | * uses the non-RFC encoding). RFC2117 turns a previously "Reserved" |
| 496 | * field into a 'unicast-address-length-in-bytes' field. We guess |
| 497 | * that it's the draft encoding if this reserved field is zero. |
| 498 | * |
| 499 | * RFC2362 goes back to the encoded format, and calls the addr length |
| 500 | * field "reserved" again. |
| 501 | * |
| 502 | * The first byte is the address family, from: |
| 503 | * |
| 504 | * 0 Reserved |
| 505 | * 1 IP (IP version 4) |
| 506 | * 2 IP6 (IP version 6) |
| 507 | * 3 NSAP |
| 508 | * 4 HDLC (8-bit multidrop) |
| 509 | * 5 BBN 1822 |
| 510 | * 6 802 (includes all 802 media plus Ethernet "canonical format") |
| 511 | * 7 E.163 |
| 512 | * 8 E.164 (SMDS, Frame Relay, ATM) |
| 513 | * 9 F.69 (Telex) |
| 514 | * 10 X.121 (X.25, Frame Relay) |
| 515 | * 11 IPX |
| 516 | * 12 Appletalk |
| 517 | * 13 Decnet IV |
| 518 | * 14 Banyan Vines |
| 519 | * 15 E.164 with NSAP format subaddress |
| 520 | * |
| 521 | * In addition, the second byte is an "Encoding". 0 is the default |
| 522 | * encoding for the address family, and no other encodings are currently |
| 523 | * specified. |
| 524 | * |
| 525 | */ |
| 526 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 527 | enum pimv2_addrtype { |
| 528 | pimv2_unicast, pimv2_group, pimv2_source |
| 529 | }; |
| 530 | |
| 531 | /* 0 1 2 3 |
| 532 | * 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 |
| 533 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 534 | * | Addr Family | Encoding Type | Unicast Address | |
| 535 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+++++++ |
| 536 | * 0 1 2 3 |
| 537 | * 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 |
| 538 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 539 | * | Addr Family | Encoding Type | Reserved | Mask Len | |
| 540 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 541 | * | Group multicast Address | |
| 542 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 543 | * 0 1 2 3 |
| 544 | * 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 |
| 545 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 546 | * | Addr Family | Encoding Type | Rsrvd |S|W|R| Mask Len | |
| 547 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 548 | * | Source Address | |
| 549 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 550 | */ |
| 551 | static int |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 552 | pimv2_addr_print(netdissect_options *ndo, |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 553 | const u_char *bp, u_int len, enum pimv2_addrtype at, |
| 554 | u_int addr_len, int silent) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 555 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 556 | u_int af; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 557 | int hdrlen; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 558 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 559 | if (addr_len == 0) { |
| 560 | if (len < 2) |
| 561 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 562 | switch (GET_U_1(bp)) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 563 | case 1: |
| 564 | af = AF_INET; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 565 | addr_len = (u_int)sizeof(nd_ipv4); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 566 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 567 | case 2: |
| 568 | af = AF_INET6; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 569 | addr_len = (u_int)sizeof(nd_ipv6); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 570 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 571 | default: |
| 572 | return -1; |
| 573 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 574 | if (GET_U_1(bp + 1) != 0) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 575 | return -1; |
| 576 | hdrlen = 2; |
| 577 | } else { |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 578 | switch (addr_len) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 579 | case sizeof(nd_ipv4): |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 580 | af = AF_INET; |
| 581 | break; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 582 | case sizeof(nd_ipv6): |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 583 | af = AF_INET6; |
| 584 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 585 | default: |
| 586 | return -1; |
| 587 | break; |
| 588 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 589 | hdrlen = 0; |
| 590 | } |
| 591 | |
| 592 | bp += hdrlen; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 593 | len -= hdrlen; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 594 | switch (at) { |
| 595 | case pimv2_unicast: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 596 | if (len < addr_len) |
| 597 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 598 | ND_TCHECK_LEN(bp, addr_len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 599 | if (af == AF_INET) { |
| 600 | if (!silent) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 601 | ND_PRINT("%s", GET_IPADDR_STRING(bp)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 602 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 603 | else if (af == AF_INET6) { |
| 604 | if (!silent) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 605 | ND_PRINT("%s", GET_IP6ADDR_STRING(bp)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 606 | } |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 607 | return hdrlen + addr_len; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 608 | case pimv2_group: |
| 609 | case pimv2_source: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 610 | if (len < addr_len + 2) |
| 611 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 612 | ND_TCHECK_LEN(bp, addr_len + 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 613 | if (af == AF_INET) { |
| 614 | if (!silent) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 615 | ND_PRINT("%s", GET_IPADDR_STRING(bp + 2)); |
| 616 | if (GET_U_1(bp + 1) != 32) |
| 617 | ND_PRINT("/%u", GET_U_1(bp + 1)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 618 | } |
| 619 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 620 | else if (af == AF_INET6) { |
| 621 | if (!silent) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 622 | ND_PRINT("%s", GET_IP6ADDR_STRING(bp + 2)); |
| 623 | if (GET_U_1(bp + 1) != 128) |
| 624 | ND_PRINT("/%u", GET_U_1(bp + 1)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 625 | } |
| 626 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 627 | if (GET_U_1(bp) && !silent) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 628 | if (at == pimv2_group) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 629 | ND_PRINT("(0x%02x)", GET_U_1(bp)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 630 | } else { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 631 | ND_PRINT("(%s%s%s", |
| 632 | GET_U_1(bp) & 0x04 ? "S" : "", |
| 633 | GET_U_1(bp) & 0x02 ? "W" : "", |
| 634 | GET_U_1(bp) & 0x01 ? "R" : ""); |
| 635 | if (GET_U_1(bp) & 0xf8) { |
| 636 | ND_PRINT("+0x%02x", |
| 637 | GET_U_1(bp) & 0xf8); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 638 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 639 | ND_PRINT(")"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 640 | } |
| 641 | } |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 642 | return hdrlen + 2 + addr_len; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 643 | default: |
| 644 | return -1; |
| 645 | } |
| 646 | trunc: |
| 647 | return -1; |
| 648 | } |
| 649 | |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 650 | enum checksum_status { |
| 651 | CORRECT, |
| 652 | INCORRECT, |
| 653 | UNVERIFIED |
| 654 | }; |
| 655 | |
| 656 | static enum checksum_status |
| 657 | pimv2_check_checksum(netdissect_options *ndo, const u_char *bp, |
| 658 | const u_char *bp2, u_int len) |
| 659 | { |
| 660 | const struct ip *ip; |
| 661 | u_int cksum; |
| 662 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 663 | if (!ND_TTEST_LEN(bp, len)) { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 664 | /* We don't have all the data. */ |
| 665 | return (UNVERIFIED); |
| 666 | } |
| 667 | ip = (const struct ip *)bp2; |
| 668 | if (IP_V(ip) == 4) { |
| 669 | struct cksum_vec vec[1]; |
| 670 | |
| 671 | vec[0].ptr = bp; |
| 672 | vec[0].len = len; |
| 673 | cksum = in_cksum(vec, 1); |
| 674 | return (cksum ? INCORRECT : CORRECT); |
| 675 | } else if (IP_V(ip) == 6) { |
| 676 | const struct ip6_hdr *ip6; |
| 677 | |
| 678 | ip6 = (const struct ip6_hdr *)bp2; |
| 679 | cksum = nextproto6_cksum(ndo, ip6, bp, len, len, IPPROTO_PIM); |
| 680 | return (cksum ? INCORRECT : CORRECT); |
| 681 | } else { |
| 682 | return (UNVERIFIED); |
| 683 | } |
| 684 | } |
| 685 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 686 | static void |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 687 | pimv2_print(netdissect_options *ndo, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 688 | const u_char *bp, u_int len, const u_char *bp2) |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 689 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 690 | const struct pim *pim = (const struct pim *)bp; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 691 | int advance; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 692 | int subtype; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 693 | enum checksum_status cksum_status; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 694 | u_int pim_typever; |
| 695 | u_int pimv2_addr_len; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 696 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 697 | ndo->ndo_protocol = "pimv2"; |
| 698 | if (len < 2) { |
| 699 | ND_PRINT("[length %u < 2]", len); |
| 700 | nd_print_invalid(ndo); |
| 701 | return; |
| 702 | } |
| 703 | pim_typever = GET_U_1(pim->pim_typever); |
| 704 | /* RFC5015 allocates the high 4 bits of pim_rsv for "subtype". */ |
| 705 | pimv2_addr_len = GET_U_1(pim->pim_rsv) & 0x0f; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 706 | if (pimv2_addr_len != 0) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 707 | ND_PRINT(", RFC2117-encoding"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 708 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 709 | if (len < 4) { |
| 710 | ND_PRINT("[length %u < 4]", len); |
| 711 | nd_print_invalid(ndo); |
| 712 | return; |
| 713 | } |
| 714 | ND_PRINT(", cksum 0x%04x ", GET_BE_U_2(pim->pim_cksum)); |
| 715 | if (GET_BE_U_2(pim->pim_cksum) == 0) { |
| 716 | ND_PRINT("(unverified)"); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 717 | } else { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 718 | if (PIM_TYPE(pim_typever) == PIMV2_TYPE_REGISTER) { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 719 | /* |
| 720 | * The checksum only covers the packet header, |
| 721 | * not the encapsulated packet. |
| 722 | */ |
| 723 | cksum_status = pimv2_check_checksum(ndo, bp, bp2, 8); |
| 724 | if (cksum_status == INCORRECT) { |
| 725 | /* |
| 726 | * To quote RFC 4601, "For interoperability |
| 727 | * reasons, a message carrying a checksum |
| 728 | * calculated over the entire PIM Register |
| 729 | * message should also be accepted." |
| 730 | */ |
| 731 | cksum_status = pimv2_check_checksum(ndo, bp, bp2, len); |
| 732 | } |
| 733 | } else { |
| 734 | /* |
| 735 | * The checksum covers the entire packet. |
| 736 | */ |
| 737 | cksum_status = pimv2_check_checksum(ndo, bp, bp2, len); |
| 738 | } |
| 739 | switch (cksum_status) { |
| 740 | |
| 741 | case CORRECT: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 742 | ND_PRINT("(correct)"); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 743 | break; |
| 744 | |
| 745 | case INCORRECT: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 746 | ND_PRINT("(incorrect)"); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 747 | break; |
| 748 | |
| 749 | case UNVERIFIED: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 750 | ND_PRINT("(unverified)"); |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 751 | break; |
| 752 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 753 | } |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 754 | bp += 4; |
| 755 | len -= 4; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 756 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 757 | switch (PIM_TYPE(pim_typever)) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 758 | case PIMV2_TYPE_HELLO: |
| 759 | { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 760 | uint16_t otype, olen; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 761 | while (len > 0) { |
| 762 | if (len < 4) |
| 763 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 764 | otype = GET_BE_U_2(bp); |
| 765 | olen = GET_BE_U_2(bp + 2); |
| 766 | ND_PRINT("\n\t %s Option (%u), length %u, Value: ", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 767 | tok2str(pimv2_hello_option_values, "Unknown", otype), |
| 768 | otype, |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 769 | olen); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 770 | bp += 4; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 771 | len -= 4; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 772 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 773 | if (len < olen) |
| 774 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 775 | ND_TCHECK_LEN(bp, olen); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 776 | switch (otype) { |
| 777 | case PIMV2_HELLO_OPTION_HOLDTIME: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 778 | if (olen != 2) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 779 | ND_PRINT("[option length %u != 2]", olen); |
| 780 | nd_print_invalid(ndo); |
| 781 | return; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 782 | } else { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 783 | unsigned_relts_print(ndo, |
| 784 | GET_BE_U_2(bp)); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 785 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 786 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 787 | |
| 788 | case PIMV2_HELLO_OPTION_LANPRUNEDELAY: |
| 789 | if (olen != 4) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 790 | ND_PRINT("[option length %u != 4]", olen); |
| 791 | nd_print_invalid(ndo); |
| 792 | return; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 793 | } else { |
| 794 | char t_bit; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 795 | uint16_t lan_delay, override_interval; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 796 | lan_delay = GET_BE_U_2(bp); |
| 797 | override_interval = GET_BE_U_2(bp + 2); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 798 | t_bit = (lan_delay & 0x8000)? 1 : 0; |
| 799 | lan_delay &= ~0x8000; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 800 | ND_PRINT("\n\t T-bit=%u, LAN delay %ums, Override interval %ums", |
| 801 | t_bit, lan_delay, override_interval); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 802 | } |
| 803 | break; |
| 804 | |
| 805 | case PIMV2_HELLO_OPTION_DR_PRIORITY_OLD: |
| 806 | case PIMV2_HELLO_OPTION_DR_PRIORITY: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 807 | switch (olen) { |
| 808 | case 0: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 809 | ND_PRINT("Bi-Directional Capability (Old)"); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 810 | break; |
| 811 | case 4: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 812 | ND_PRINT("%u", GET_BE_U_4(bp)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 813 | break; |
| 814 | default: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 815 | ND_PRINT("[option length %u != 4]", olen); |
| 816 | nd_print_invalid(ndo); |
| 817 | return; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 818 | break; |
| 819 | } |
| 820 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 821 | |
| 822 | case PIMV2_HELLO_OPTION_GENID: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 823 | if (olen != 4) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 824 | ND_PRINT("[option length %u != 4]", olen); |
| 825 | nd_print_invalid(ndo); |
| 826 | return; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 827 | } else { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 828 | ND_PRINT("0x%08x", GET_BE_U_4(bp)); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 829 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 830 | break; |
| 831 | |
| 832 | case PIMV2_HELLO_OPTION_REFRESH_CAP: |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 833 | if (olen != 4) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 834 | ND_PRINT("[option length %u != 4]", olen); |
| 835 | nd_print_invalid(ndo); |
| 836 | return; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 837 | } else { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 838 | ND_PRINT("v%u", GET_U_1(bp)); |
| 839 | if (GET_U_1(bp + 1) != 0) { |
| 840 | ND_PRINT(", interval "); |
| 841 | unsigned_relts_print(ndo, |
| 842 | GET_U_1(bp + 1)); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 843 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 844 | if (GET_BE_U_2(bp + 2) != 0) { |
| 845 | ND_PRINT(" ?0x%04x?", |
| 846 | GET_BE_U_2(bp + 2)); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 847 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 848 | } |
| 849 | break; |
| 850 | |
| 851 | case PIMV2_HELLO_OPTION_BIDIR_CAP: |
| 852 | break; |
| 853 | |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 854 | case PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD: |
| 855 | case PIMV2_HELLO_OPTION_ADDRESS_LIST: |
| 856 | if (ndo->ndo_vflag > 1) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 857 | const u_char *ptr = bp; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 858 | u_int plen = len; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 859 | while (ptr < (bp+olen)) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 860 | ND_PRINT("\n\t "); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 861 | advance = pimv2_addr_print(ndo, ptr, plen, pimv2_unicast, pimv2_addr_len, 0); |
| 862 | if (advance < 0) |
| 863 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 864 | ptr += advance; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 865 | plen -= advance; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 866 | } |
| 867 | } |
| 868 | break; |
| 869 | default: |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 870 | if (ndo->ndo_vflag <= 1) |
| 871 | print_unknown_data(ndo, bp, "\n\t ", olen); |
| 872 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 873 | } |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 874 | /* do we want to see an additionally hexdump ? */ |
| 875 | if (ndo->ndo_vflag> 1) |
| 876 | print_unknown_data(ndo, bp, "\n\t ", olen); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 877 | bp += olen; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 878 | len -= olen; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 879 | } |
| 880 | break; |
| 881 | } |
| 882 | |
| 883 | case PIMV2_TYPE_REGISTER: |
| 884 | { |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 885 | const struct ip *ip; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 886 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 887 | if (len < 4) |
| 888 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 889 | ND_TCHECK_LEN(bp, PIMV2_REGISTER_FLAG_LEN); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 890 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 891 | ND_PRINT(", Flags [ %s ]\n\t", |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 892 | tok2str(pimv2_register_flag_values, |
| 893 | "none", |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 894 | GET_BE_U_4(bp))); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 895 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 896 | bp += 4; len -= 4; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 897 | /* encapsulated multicast packet */ |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 898 | if (len == 0) |
| 899 | goto trunc; |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 900 | ip = (const struct ip *)bp; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 901 | switch (IP_V(ip)) { |
| 902 | case 0: /* Null header */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 903 | ND_PRINT("IP-Null-header %s > %s", |
| 904 | GET_IPADDR_STRING(ip->ip_src), |
| 905 | GET_IPADDR_STRING(ip->ip_dst)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 906 | break; |
| 907 | |
| 908 | case 4: /* IPv4 */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 909 | ip_print(ndo, bp, len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 910 | break; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 911 | |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 912 | case 6: /* IPv6 */ |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 913 | ip6_print(ndo, bp, len); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 914 | break; |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 915 | |
| 916 | default: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 917 | ND_PRINT("IP ver %u", IP_V(ip)); |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 918 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 919 | } |
| 920 | break; |
| 921 | } |
| 922 | |
| 923 | case PIMV2_TYPE_REGISTER_STOP: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 924 | ND_PRINT(" group="); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 925 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_group, pimv2_addr_len, 0)) < 0) |
| 926 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 927 | bp += advance; len -= advance; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 928 | ND_PRINT(" source="); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 929 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0) |
| 930 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 931 | bp += advance; len -= advance; |
| 932 | break; |
| 933 | |
| 934 | case PIMV2_TYPE_JOIN_PRUNE: |
| 935 | case PIMV2_TYPE_GRAFT: |
| 936 | case PIMV2_TYPE_GRAFT_ACK: |
| 937 | |
| 938 | |
| 939 | /* |
| 940 | * 0 1 2 3 |
| 941 | * 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 |
| 942 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 943 | * |PIM Ver| Type | Addr length | Checksum | |
| 944 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 945 | * | Unicast-Upstream Neighbor Address | |
| 946 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 947 | * | Reserved | Num groups | Holdtime | |
| 948 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 949 | * | Encoded-Multicast Group Address-1 | |
| 950 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 951 | * | Number of Joined Sources | Number of Pruned Sources | |
| 952 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 953 | * | Encoded-Joined Source Address-1 | |
| 954 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 955 | * | . | |
| 956 | * | . | |
| 957 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 958 | * | Encoded-Joined Source Address-n | |
| 959 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 960 | * | Encoded-Pruned Source Address-1 | |
| 961 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 962 | * | . | |
| 963 | * | . | |
| 964 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 965 | * | Encoded-Pruned Source Address-n | |
| 966 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 967 | * | . | |
| 968 | * | . | |
| 969 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 970 | * | Encoded-Multicast Group Address-n | |
| 971 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 972 | */ |
| 973 | |
| 974 | { |
Elliott Hughes | 892a68b | 2015-10-19 14:43:53 -0700 | [diff] [blame] | 975 | uint8_t ngroup; |
| 976 | uint16_t holdtime; |
| 977 | uint16_t njoin; |
| 978 | uint16_t nprune; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 979 | u_int i, j; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 980 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 981 | if (PIM_TYPE(pim_typever) != 7) { /*not for Graft-ACK*/ |
| 982 | ND_PRINT(", upstream-neighbor: "); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 983 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0) |
| 984 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 985 | bp += advance; len -= advance; |
| 986 | } |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 987 | if (len < 4) |
| 988 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 989 | ND_TCHECK_4(bp); |
| 990 | ngroup = GET_U_1(bp + 1); |
| 991 | holdtime = GET_BE_U_2(bp + 2); |
| 992 | ND_PRINT("\n\t %u group(s)", ngroup); |
| 993 | if (PIM_TYPE(pim_typever) != 7) { /*not for Graft-ACK*/ |
| 994 | ND_PRINT(", holdtime: "); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 995 | if (holdtime == 0xffff) |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 996 | ND_PRINT("infinite"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 997 | else |
Elliott Hughes | e2e3bd1 | 2017-05-15 10:59:29 -0700 | [diff] [blame] | 998 | unsigned_relts_print(ndo, holdtime); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 999 | } |
| 1000 | bp += 4; len -= 4; |
| 1001 | for (i = 0; i < ngroup; i++) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1002 | ND_PRINT("\n\t group #%u: ", i+1); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1003 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_group, pimv2_addr_len, 0)) < 0) |
| 1004 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1005 | bp += advance; len -= advance; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1006 | if (len < 4) |
| 1007 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1008 | ND_TCHECK_4(bp); |
| 1009 | njoin = GET_BE_U_2(bp); |
| 1010 | nprune = GET_BE_U_2(bp + 2); |
| 1011 | ND_PRINT(", joined sources: %u, pruned sources: %u", njoin, nprune); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1012 | bp += 4; len -= 4; |
| 1013 | for (j = 0; j < njoin; j++) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1014 | ND_PRINT("\n\t joined source #%u: ", j+1); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1015 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_source, pimv2_addr_len, 0)) < 0) |
| 1016 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1017 | bp += advance; len -= advance; |
| 1018 | } |
| 1019 | for (j = 0; j < nprune; j++) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1020 | ND_PRINT("\n\t pruned source #%u: ", j+1); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1021 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_source, pimv2_addr_len, 0)) < 0) |
| 1022 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1023 | bp += advance; len -= advance; |
| 1024 | } |
| 1025 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1026 | break; |
| 1027 | } |
| 1028 | |
| 1029 | case PIMV2_TYPE_BOOTSTRAP: |
| 1030 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1031 | u_int i, j, frpcnt; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1032 | |
| 1033 | /* Fragment Tag, Hash Mask len, and BSR-priority */ |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1034 | if (len < 2) |
| 1035 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1036 | ND_PRINT(" tag=%x", GET_BE_U_2(bp)); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1037 | bp += 2; |
| 1038 | len -= 2; |
| 1039 | if (len < 1) |
| 1040 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1041 | ND_PRINT(" hashmlen=%u", GET_U_1(bp)); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1042 | if (len < 2) |
| 1043 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1044 | ND_TCHECK_1(bp + 2); |
| 1045 | ND_PRINT(" BSRprio=%u", GET_U_1(bp + 1)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1046 | bp += 2; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1047 | len -= 2; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1048 | |
| 1049 | /* Encoded-Unicast-BSR-Address */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1050 | ND_PRINT(" BSR="); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1051 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0) |
| 1052 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1053 | bp += advance; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1054 | len -= advance; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1055 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1056 | for (i = 0; len > 0; i++) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1057 | /* Encoded-Group Address */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1058 | ND_PRINT(" (group%u: ", i); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1059 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_group, pimv2_addr_len, 0)) < 0) |
| 1060 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1061 | bp += advance; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1062 | len -= advance; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1063 | |
| 1064 | /* RP-Count, Frag RP-Cnt, and rsvd */ |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1065 | if (len < 1) |
| 1066 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1067 | ND_PRINT(" RPcnt=%u", GET_U_1(bp)); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1068 | if (len < 2) |
| 1069 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1070 | frpcnt = GET_U_1(bp + 1); |
| 1071 | ND_PRINT(" FRPcnt=%u", frpcnt); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1072 | if (len < 4) |
| 1073 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1074 | bp += 4; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1075 | len -= 4; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1076 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1077 | for (j = 0; j < frpcnt && len > 0; j++) { |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1078 | /* each RP info */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1079 | ND_PRINT(" RP%u=", j); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1080 | if ((advance = pimv2_addr_print(ndo, bp, len, |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1081 | pimv2_unicast, |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1082 | pimv2_addr_len, |
| 1083 | 0)) < 0) |
| 1084 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1085 | bp += advance; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1086 | len -= advance; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1087 | |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1088 | if (len < 2) |
| 1089 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1090 | ND_PRINT(",holdtime="); |
| 1091 | unsigned_relts_print(ndo, |
| 1092 | GET_BE_U_2(bp)); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1093 | if (len < 3) |
| 1094 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1095 | ND_PRINT(",prio=%u", GET_U_1(bp + 2)); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1096 | if (len < 4) |
| 1097 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1098 | bp += 4; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1099 | len -= 4; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1100 | } |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1101 | ND_PRINT(")"); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1102 | } |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1103 | break; |
| 1104 | } |
| 1105 | case PIMV2_TYPE_ASSERT: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1106 | ND_PRINT(" group="); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1107 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_group, pimv2_addr_len, 0)) < 0) |
| 1108 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1109 | bp += advance; len -= advance; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1110 | ND_PRINT(" src="); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1111 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0) |
| 1112 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1113 | bp += advance; len -= advance; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1114 | if (len < 8) |
| 1115 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1116 | ND_TCHECK_8(bp); |
| 1117 | if (GET_U_1(bp) & 0x80) |
| 1118 | ND_PRINT(" RPT"); |
| 1119 | ND_PRINT(" pref=%u", GET_BE_U_4(bp) & 0x7fffffff); |
| 1120 | ND_PRINT(" metric=%u", GET_BE_U_4(bp + 4)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1121 | break; |
| 1122 | |
| 1123 | case PIMV2_TYPE_CANDIDATE_RP: |
| 1124 | { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1125 | u_int i, pfxcnt; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1126 | |
| 1127 | /* Prefix-Cnt, Priority, and Holdtime */ |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1128 | if (len < 1) |
| 1129 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1130 | ND_PRINT(" prefix-cnt=%u", GET_U_1(bp)); |
| 1131 | pfxcnt = GET_U_1(bp); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1132 | if (len < 2) |
| 1133 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1134 | ND_PRINT(" prio=%u", GET_U_1(bp + 1)); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1135 | if (len < 4) |
| 1136 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1137 | ND_PRINT(" holdtime="); |
| 1138 | unsigned_relts_print(ndo, GET_BE_U_2(bp + 2)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1139 | bp += 4; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1140 | len -= 4; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1141 | |
| 1142 | /* Encoded-Unicast-RP-Address */ |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1143 | ND_PRINT(" RP="); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1144 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0) |
| 1145 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1146 | bp += advance; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1147 | len -= advance; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1148 | |
| 1149 | /* Encoded-Group Addresses */ |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1150 | for (i = 0; i < pfxcnt && len > 0; i++) { |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1151 | ND_PRINT(" Group%u=", i); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1152 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_group, pimv2_addr_len, 0)) < 0) |
| 1153 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1154 | bp += advance; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1155 | len -= advance; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1156 | } |
| 1157 | break; |
| 1158 | } |
| 1159 | |
| 1160 | case PIMV2_TYPE_PRUNE_REFRESH: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1161 | ND_PRINT(" src="); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1162 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0) |
| 1163 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1164 | bp += advance; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1165 | len -= advance; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1166 | ND_PRINT(" grp="); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1167 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_group, pimv2_addr_len, 0)) < 0) |
| 1168 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1169 | bp += advance; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1170 | len -= advance; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1171 | ND_PRINT(" forwarder="); |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1172 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0) |
| 1173 | goto trunc; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1174 | bp += advance; |
Elliott Hughes | cec480a | 2017-12-19 16:54:57 -0800 | [diff] [blame] | 1175 | len -= advance; |
| 1176 | if (len < 2) |
| 1177 | goto trunc; |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1178 | ND_PRINT(" TUNR "); |
| 1179 | unsigned_relts_print(ndo, GET_BE_U_2(bp)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1180 | break; |
| 1181 | |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1182 | case PIMV2_TYPE_DF_ELECTION: |
| 1183 | subtype = PIM_SUBTYPE(GET_U_1(pim->pim_rsv)); |
| 1184 | ND_PRINT("\n\t %s,", tok2str( pimv2_df_election_flag_values, |
| 1185 | "Unknown", subtype) ); |
| 1186 | |
| 1187 | ND_PRINT(" rpa="); |
| 1188 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0) { |
| 1189 | goto trunc; |
| 1190 | } |
| 1191 | bp += advance; |
| 1192 | len -= advance; |
| 1193 | ND_PRINT(" sender pref=%u", GET_BE_U_4(bp) ); |
| 1194 | ND_PRINT(" sender metric=%u", GET_BE_U_4(bp + 4)); |
| 1195 | |
| 1196 | bp += 8; |
| 1197 | len -= 8; |
| 1198 | |
| 1199 | switch (subtype) { |
| 1200 | case PIMV2_DF_ELECTION_BACKOFF: |
| 1201 | case PIMV2_DF_ELECTION_PASS: |
| 1202 | ND_PRINT("\n\t %s addr=", PIMV2_DF_ELECTION_PASS_BACKOFF_STR(subtype)); |
| 1203 | if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0) { |
| 1204 | goto trunc; |
| 1205 | } |
| 1206 | bp += advance; |
| 1207 | len -= advance; |
| 1208 | |
| 1209 | ND_PRINT(" %s pref=%u", PIMV2_DF_ELECTION_PASS_BACKOFF_STR(subtype), GET_BE_U_4(bp) ); |
| 1210 | ND_PRINT(" %s metric=%u", PIMV2_DF_ELECTION_PASS_BACKOFF_STR(subtype), GET_BE_U_4(bp + 4)); |
| 1211 | |
| 1212 | bp += 8; |
| 1213 | len -= 8; |
| 1214 | |
| 1215 | if (subtype == PIMV2_DF_ELECTION_BACKOFF) { |
| 1216 | ND_PRINT(" interval %dms", GET_BE_U_2(bp)); |
| 1217 | } |
| 1218 | |
| 1219 | break; |
| 1220 | default: |
| 1221 | break; |
| 1222 | } |
| 1223 | break; |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1224 | |
| 1225 | default: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1226 | ND_PRINT(" [type %u]", PIM_TYPE(pim_typever)); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1227 | break; |
| 1228 | } |
| 1229 | |
| 1230 | return; |
| 1231 | |
| 1232 | trunc: |
Elliott Hughes | 820eced | 2021-08-20 18:00:50 -0700 | [diff] [blame] | 1233 | nd_print_trunc(ndo); |
The Android Open Source Project | 2949f58 | 2009-03-03 19:30:46 -0800 | [diff] [blame] | 1234 | } |