blob: f2db8c7681655ba2b3a712e1a3e0129f0ba524c6 [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
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 Hughese2e3bd12017-05-15 10:59:29 -070022/* \summary: Protocol Independent Multicast (PIM) printer */
23
The Android Open Source Project2949f582009-03-03 19:30:46 -080024#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070025#include <config.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080026#endif
27
Elliott Hughes820eced2021-08-20 18:00:50 -070028#include "netdissect-stdinc.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080029
Elliott Hughese2e3bd12017-05-15 10:59:29 -070030#include "netdissect.h"
JP Abgrall53f17a92014-02-12 14:02:41 -080031#include "addrtoname.h"
32#include "extract.h"
33
34#include "ip.h"
Elliott Hughese2e3bd12017-05-15 10:59:29 -070035#include "ip6.h"
36#include "ipproto.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080037
Elliott Hughes892a68b2015-10-19 14:43:53 -070038#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
47static 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 Project2949f582009-03-03 19:30:46 -080059#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 Hughes892a68b2015-10-19 14:43:53 -070069#define PIMV2_TYPE_DF_ELECTION 10
70#define PIMV2_TYPE_ECMP_REDIRECT 11
The Android Open Source Project2949f582009-03-03 19:30:46 -080071
JP Abgrall53f17a92014-02-12 14:02:41 -080072static const struct tok pimv2_type_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080073 { 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 Hughes892a68b2015-10-19 14:43:53 -070083 { PIMV2_TYPE_DF_ELECTION, "DF Election" },
84 { PIMV2_TYPE_ECMP_REDIRECT, "ECMP Redirect" },
The Android Open Source Project2949f582009-03-03 19:30:46 -080085 { 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 Abgrall53f17a92014-02-12 14:02:41 -080098static const struct tok pimv2_hello_option_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -080099 { 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 Abgrall53f17a92014-02-12 14:02:41 -0800115static const struct tok pimv2_register_flag_values[] = {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800116 { PIMV2_REGISTER_FLAG_BORDER, "Border" },
117 { PIMV2_REGISTER_FLAG_NULL, "Null" },
118 { 0, NULL}
Elliott Hughes892a68b2015-10-19 14:43:53 -0700119};
The Android Open Source Project2949f582009-03-03 19:30:46 -0800120
Elliott Hughes820eced2021-08-20 18:00:50 -0700121#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
126static 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 Project2949f582009-03-03 19:30:46 -0800138/*
139 * XXX: We consider a case where IPv6 is not ready yet for portability,
Elliott Hughes820eced2021-08-20 18:00:50 -0700140 * but PIM dependent definitions should be independent of IPv6...
The Android Open Source Project2949f582009-03-03 19:30:46 -0800141 */
142
143struct pim {
Elliott Hughes820eced2021-08-20 18:00:50 -0700144 nd_uint8_t pim_typever;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800145 /* 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 Hughes820eced2021-08-20 18:00:50 -0700153 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 Project2949f582009-03-03 19:30:46 -0800156};
157
Elliott Hughes820eced2021-08-20 18:00:50 -0700158static void pimv2_print(netdissect_options *, const u_char *bp, u_int len, const u_char *);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800159
160static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700161pimv1_join_prune_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700162 const u_char *bp, u_int len)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800163{
Elliott Hughes820eced2021-08-20 18:00:50 -0700164 u_int ngroups, njoin, nprune;
165 u_int njp;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800166
167 /* If it's a single group and a single source, use 1-line output. */
Elliott Hughes820eced2021-08-20 18:00:50 -0700168 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 Project2949f582009-03-03 19:30:46 -0800171
Elliott Hughes820eced2021-08-20 18:00:50 -0700172 ND_PRINT(" RPF %s ", GET_IPADDR_STRING(bp));
173 hold = GET_BE_U_2(bp + 6);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800174 if (hold != 180) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700175 ND_PRINT("Hold ");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700176 unsigned_relts_print(ndo, hold);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800177 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700178 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 Project2949f582009-03-03 19:30:46 -0800187 return;
188 }
189
Elliott Hughes820eced2021-08-20 18:00:50 -0700190 if (len < sizeof(nd_ipv4))
Elliott Hughescec480a2017-12-19 16:54:57 -0800191 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700192 if (ndo->ndo_vflag > 1)
Elliott Hughes820eced2021-08-20 18:00:50 -0700193 ND_PRINT("\n");
194 ND_PRINT(" Upstream Nbr: %s", GET_IPADDR_STRING(bp));
Elliott Hughescec480a2017-12-19 16:54:57 -0800195 bp += 4;
196 len -= 4;
197 if (len < 4)
198 goto trunc;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700199 if (ndo->ndo_vflag > 1)
Elliott Hughes820eced2021-08-20 18:00:50 -0700200 ND_PRINT("\n");
201 ND_PRINT(" Hold time: ");
202 unsigned_relts_print(ndo, GET_BE_U_2(bp + 2));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700203 if (ndo->ndo_vflag < 2)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800204 return;
Elliott Hughescec480a2017-12-19 16:54:57 -0800205 bp += 4;
206 len -= 4;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800207
Elliott Hughescec480a2017-12-19 16:54:57 -0800208 if (len < 4)
209 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700210 ngroups = GET_U_1(bp + 3);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800211 bp += 4;
212 len -= 4;
Elliott Hughes820eced2021-08-20 18:00:50 -0700213 while (ngroups != 0) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800214 /*
215 * XXX - does the address have length "addrlen" and the
216 * mask length "maddrlen"?
217 */
Elliott Hughescec480a2017-12-19 16:54:57 -0800218 if (len < 4)
219 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700220 ND_PRINT("\n\tGroup: %s", GET_IPADDR_STRING(bp));
Elliott Hughescec480a2017-12-19 16:54:57 -0800221 bp += 4;
222 len -= 4;
223 if (len < 4)
224 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700225 if (GET_BE_U_4(bp) != 0xffffffff)
226 ND_PRINT("/%s", GET_IPADDR_STRING(bp));
Elliott Hughescec480a2017-12-19 16:54:57 -0800227 bp += 4;
228 len -= 4;
229 if (len < 4)
230 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700231 njoin = GET_BE_U_2(bp);
232 nprune = GET_BE_U_2(bp + 2);
233 ND_PRINT(" joined: %u pruned: %u", njoin, nprune);
Elliott Hughescec480a2017-12-19 16:54:57 -0800234 bp += 4;
235 len -= 4;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800236 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 Hughescec480a2017-12-19 16:54:57 -0800243 if (len < 6)
244 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700245 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 Project2949f582009-03-03 19:30:46 -0800251 bp += 6;
252 len -= 6;
253 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700254 ngroups--;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800255 }
256 return;
257trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -0700258 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800259}
260
261void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700262pimv1_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700263 const u_char *bp, u_int len)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800264{
Elliott Hughes820eced2021-08-20 18:00:50 -0700265 u_char type;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800266
Elliott Hughes820eced2021-08-20 18:00:50 -0700267 ndo->ndo_protocol = "pimv1";
268 type = GET_U_1(bp + 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800269
Elliott Hughes820eced2021-08-20 18:00:50 -0700270 ND_PRINT(" %s", tok2str(pimv1_type_str, "[type %u]", type));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800271 switch (type) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700272 case PIMV1_TYPE_QUERY:
Elliott Hughes820eced2021-08-20 18:00:50 -0700273 if (ND_TTEST_1(bp + 8)) {
274 switch (GET_U_1(bp + 8) >> 4) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800275 case 0:
Elliott Hughes820eced2021-08-20 18:00:50 -0700276 ND_PRINT(" Dense-mode");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800277 break;
278 case 1:
Elliott Hughes820eced2021-08-20 18:00:50 -0700279 ND_PRINT(" Sparse-mode");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800280 break;
281 case 2:
Elliott Hughes820eced2021-08-20 18:00:50 -0700282 ND_PRINT(" Sparse-Dense-mode");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800283 break;
284 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700285 ND_PRINT(" mode-%u", GET_U_1(bp + 8) >> 4);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800286 break;
287 }
288 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700289 if (ndo->ndo_vflag) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700290 ND_PRINT(" (Hold-time ");
291 unsigned_relts_print(ndo, GET_BE_U_2(bp + 10));
292 ND_PRINT(")");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800293 }
294 break;
295
Elliott Hughes892a68b2015-10-19 14:43:53 -0700296 case PIMV1_TYPE_REGISTER:
Elliott Hughes820eced2021-08-20 18:00:50 -0700297 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 Project2949f582009-03-03 19:30:46 -0800300 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700301 case PIMV1_TYPE_REGISTER_STOP:
Elliott Hughes820eced2021-08-20 18:00:50 -0700302 ND_PRINT(" for %s > %s", GET_IPADDR_STRING(bp + 8),
303 GET_IPADDR_STRING(bp + 12));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800304 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700305 case PIMV1_TYPE_RP_REACHABILITY:
306 if (ndo->ndo_vflag) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700307 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 Project2949f582009-03-03 19:30:46 -0800312 }
313 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700314 case PIMV1_TYPE_ASSERT:
Elliott Hughes820eced2021-08-20 18:00:50 -0700315 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 Project2949f582009-03-03 19:30:46 -0800323 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700324 case PIMV1_TYPE_JOIN_PRUNE:
325 case PIMV1_TYPE_GRAFT:
326 case PIMV1_TYPE_GRAFT_ACK:
Elliott Hughescec480a2017-12-19 16:54:57 -0800327 if (ndo->ndo_vflag) {
328 if (len < 8)
329 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700330 pimv1_join_prune_print(ndo, bp + 8, len - 8);
Elliott Hughescec480a2017-12-19 16:54:57 -0800331 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800332 break;
333 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700334 if ((GET_U_1(bp + 4) >> 4) != 1)
335 ND_PRINT(" [v%u]", GET_U_1(bp + 4) >> 4);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800336 return;
337
338trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -0700339 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800340}
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 */
348void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700349cisco_autorp_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700350 const u_char *bp, u_int len)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800351{
Elliott Hughes820eced2021-08-20 18:00:50 -0700352 u_int type;
353 u_int numrps;
354 u_int hold;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800355
Elliott Hughes820eced2021-08-20 18:00:50 -0700356 ndo->ndo_protocol = "cisco_autorp";
Elliott Hughescec480a2017-12-19 16:54:57 -0800357 if (len < 8)
358 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700359 ND_PRINT(" auto-rp ");
360 type = GET_U_1(bp);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800361 switch (type) {
362 case 0x11:
Elliott Hughes820eced2021-08-20 18:00:50 -0700363 ND_PRINT("candidate-advert");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800364 break;
365 case 0x12:
Elliott Hughes820eced2021-08-20 18:00:50 -0700366 ND_PRINT("mapping");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800367 break;
368 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700369 ND_PRINT("type-0x%02x", type);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800370 break;
371 }
372
Elliott Hughes820eced2021-08-20 18:00:50 -0700373 numrps = GET_U_1(bp + 1);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800374
Elliott Hughes820eced2021-08-20 18:00:50 -0700375 ND_PRINT(" Hold ");
376 hold = GET_BE_U_2(bp + 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800377 if (hold)
Elliott Hughes820eced2021-08-20 18:00:50 -0700378 unsigned_relts_print(ndo, GET_BE_U_2(bp + 2));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800379 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700380 ND_PRINT("FOREVER");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800381
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 Hughes820eced2021-08-20 18:00:50 -0700399 while (numrps != 0) {
400 u_int nentries;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800401 char s;
402
Elliott Hughescec480a2017-12-19 16:54:57 -0800403 if (len < 4)
404 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700405 ND_PRINT(" RP %s", GET_IPADDR_STRING(bp));
Elliott Hughescec480a2017-12-19 16:54:57 -0800406 bp += 4;
407 len -= 4;
408 if (len < 1)
409 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700410 switch (GET_U_1(bp) & 0x3) {
411 case 0: ND_PRINT(" PIMv?");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800412 break;
Elliott Hughes820eced2021-08-20 18:00:50 -0700413 case 1: ND_PRINT(" PIMv1");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800414 break;
Elliott Hughes820eced2021-08-20 18:00:50 -0700415 case 2: ND_PRINT(" PIMv2");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800416 break;
Elliott Hughes820eced2021-08-20 18:00:50 -0700417 case 3: ND_PRINT(" PIMv1+2");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800418 break;
419 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700420 if (GET_U_1(bp) & 0xfc)
421 ND_PRINT(" [rsvd=0x%02x]", GET_U_1(bp) & 0xfc);
Elliott Hughescec480a2017-12-19 16:54:57 -0800422 bp += 1;
423 len -= 1;
424 if (len < 1)
425 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700426 nentries = GET_U_1(bp);
Elliott Hughescec480a2017-12-19 16:54:57 -0800427 bp += 1;
428 len -= 1;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800429 s = ' ';
Elliott Hughes820eced2021-08-20 18:00:50 -0700430 while (nentries != 0) {
Elliott Hughescec480a2017-12-19 16:54:57 -0800431 if (len < 6)
432 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700433 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 Abgrall53f17a92014-02-12 14:02:41 -0800437 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700438 if (GET_U_1(bp) & 0xfc) {
439 ND_PRINT("[rsvd=0x%02x]", GET_U_1(bp) & 0xfc);
JP Abgrall53f17a92014-02-12 14:02:41 -0800440 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800441 s = ',';
442 bp += 6; len -= 6;
Elliott Hughes820eced2021-08-20 18:00:50 -0700443 nentries--;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800444 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700445 numrps--;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800446 }
447 return;
448
449trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -0700450 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800451}
452
453void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700454pim_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700455 const u_char *bp, u_int len, const u_char *bp2)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800456{
Elliott Hughes820eced2021-08-20 18:00:50 -0700457 const struct pim *pim = (const struct pim *)bp;
458 uint8_t pim_typever;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800459
Elliott Hughes820eced2021-08-20 18:00:50 -0700460 ndo->ndo_protocol = "pim";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800461
Elliott Hughes820eced2021-08-20 18:00:50 -0700462 pim_typever = GET_U_1(pim->pim_typever);
463 switch (PIM_VER(pim_typever)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800464 case 2:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700465 if (!ndo->ndo_vflag) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700466 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 Hughes892a68b2015-10-19 14:43:53 -0700470 return;
471 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700472 ND_PRINT("PIMv%u, length %u\n\t%s",
473 PIM_VER(pim_typever),
Elliott Hughes892a68b2015-10-19 14:43:53 -0700474 len,
Elliott Hughes820eced2021-08-20 18:00:50 -0700475 tok2str(pimv2_type_values,"Unknown Type",PIM_TYPE(pim_typever)));
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700476 pimv2_print(ndo, bp, len, bp2);
Elliott Hughes892a68b2015-10-19 14:43:53 -0700477 }
478 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800479 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700480 ND_PRINT("PIMv%u, length %u",
481 PIM_VER(pim_typever),
482 len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800483 break;
484 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800485}
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 Project2949f582009-03-03 19:30:46 -0800527enum 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 */
551static int
Elliott Hughes892a68b2015-10-19 14:43:53 -0700552pimv2_addr_print(netdissect_options *ndo,
Elliott Hughescec480a2017-12-19 16:54:57 -0800553 const u_char *bp, u_int len, enum pimv2_addrtype at,
554 u_int addr_len, int silent)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800555{
Elliott Hughes820eced2021-08-20 18:00:50 -0700556 u_int af;
Elliott Hughescec480a2017-12-19 16:54:57 -0800557 int hdrlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800558
Elliott Hughescec480a2017-12-19 16:54:57 -0800559 if (addr_len == 0) {
560 if (len < 2)
561 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700562 switch (GET_U_1(bp)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800563 case 1:
564 af = AF_INET;
Elliott Hughes820eced2021-08-20 18:00:50 -0700565 addr_len = (u_int)sizeof(nd_ipv4);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800566 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800567 case 2:
568 af = AF_INET6;
Elliott Hughes820eced2021-08-20 18:00:50 -0700569 addr_len = (u_int)sizeof(nd_ipv6);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800570 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800571 default:
572 return -1;
573 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700574 if (GET_U_1(bp + 1) != 0)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800575 return -1;
576 hdrlen = 2;
577 } else {
Elliott Hughescec480a2017-12-19 16:54:57 -0800578 switch (addr_len) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700579 case sizeof(nd_ipv4):
The Android Open Source Project2949f582009-03-03 19:30:46 -0800580 af = AF_INET;
581 break;
Elliott Hughes820eced2021-08-20 18:00:50 -0700582 case sizeof(nd_ipv6):
The Android Open Source Project2949f582009-03-03 19:30:46 -0800583 af = AF_INET6;
584 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800585 default:
586 return -1;
587 break;
588 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800589 hdrlen = 0;
590 }
591
592 bp += hdrlen;
Elliott Hughescec480a2017-12-19 16:54:57 -0800593 len -= hdrlen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800594 switch (at) {
595 case pimv2_unicast:
Elliott Hughescec480a2017-12-19 16:54:57 -0800596 if (len < addr_len)
597 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700598 ND_TCHECK_LEN(bp, addr_len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800599 if (af == AF_INET) {
600 if (!silent)
Elliott Hughes820eced2021-08-20 18:00:50 -0700601 ND_PRINT("%s", GET_IPADDR_STRING(bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800602 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800603 else if (af == AF_INET6) {
604 if (!silent)
Elliott Hughes820eced2021-08-20 18:00:50 -0700605 ND_PRINT("%s", GET_IP6ADDR_STRING(bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800606 }
Elliott Hughescec480a2017-12-19 16:54:57 -0800607 return hdrlen + addr_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800608 case pimv2_group:
609 case pimv2_source:
Elliott Hughescec480a2017-12-19 16:54:57 -0800610 if (len < addr_len + 2)
611 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700612 ND_TCHECK_LEN(bp, addr_len + 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800613 if (af == AF_INET) {
614 if (!silent) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700615 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 Project2949f582009-03-03 19:30:46 -0800618 }
619 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800620 else if (af == AF_INET6) {
621 if (!silent) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700622 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 Project2949f582009-03-03 19:30:46 -0800625 }
626 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700627 if (GET_U_1(bp) && !silent) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800628 if (at == pimv2_group) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700629 ND_PRINT("(0x%02x)", GET_U_1(bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800630 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700631 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 Project2949f582009-03-03 19:30:46 -0800638 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700639 ND_PRINT(")");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800640 }
641 }
Elliott Hughescec480a2017-12-19 16:54:57 -0800642 return hdrlen + 2 + addr_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800643 default:
644 return -1;
645 }
646trunc:
647 return -1;
648}
649
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700650enum checksum_status {
651 CORRECT,
652 INCORRECT,
653 UNVERIFIED
654};
655
656static enum checksum_status
657pimv2_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 Hughes820eced2021-08-20 18:00:50 -0700663 if (!ND_TTEST_LEN(bp, len)) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700664 /* 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 Project2949f582009-03-03 19:30:46 -0800686static void
Elliott Hughes892a68b2015-10-19 14:43:53 -0700687pimv2_print(netdissect_options *ndo,
Elliott Hughes820eced2021-08-20 18:00:50 -0700688 const u_char *bp, u_int len, const u_char *bp2)
The Android Open Source Project2949f582009-03-03 19:30:46 -0800689{
Elliott Hughes820eced2021-08-20 18:00:50 -0700690 const struct pim *pim = (const struct pim *)bp;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800691 int advance;
Elliott Hughes820eced2021-08-20 18:00:50 -0700692 int subtype;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700693 enum checksum_status cksum_status;
Elliott Hughes820eced2021-08-20 18:00:50 -0700694 u_int pim_typever;
695 u_int pimv2_addr_len;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800696
Elliott Hughes820eced2021-08-20 18:00:50 -0700697 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 Project2949f582009-03-03 19:30:46 -0800706 if (pimv2_addr_len != 0)
Elliott Hughes820eced2021-08-20 18:00:50 -0700707 ND_PRINT(", RFC2117-encoding");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800708
Elliott Hughes820eced2021-08-20 18:00:50 -0700709 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 Hughes892a68b2015-10-19 14:43:53 -0700717 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700718 if (PIM_TYPE(pim_typever) == PIMV2_TYPE_REGISTER) {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700719 /*
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 Hughes820eced2021-08-20 18:00:50 -0700742 ND_PRINT("(correct)");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700743 break;
744
745 case INCORRECT:
Elliott Hughes820eced2021-08-20 18:00:50 -0700746 ND_PRINT("(incorrect)");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700747 break;
748
749 case UNVERIFIED:
Elliott Hughes820eced2021-08-20 18:00:50 -0700750 ND_PRINT("(unverified)");
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700751 break;
752 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700753 }
Elliott Hughescec480a2017-12-19 16:54:57 -0800754 bp += 4;
755 len -= 4;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800756
Elliott Hughes820eced2021-08-20 18:00:50 -0700757 switch (PIM_TYPE(pim_typever)) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800758 case PIMV2_TYPE_HELLO:
759 {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700760 uint16_t otype, olen;
Elliott Hughescec480a2017-12-19 16:54:57 -0800761 while (len > 0) {
762 if (len < 4)
763 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700764 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 Hughes892a68b2015-10-19 14:43:53 -0700767 tok2str(pimv2_hello_option_values, "Unknown", otype),
768 otype,
Elliott Hughes820eced2021-08-20 18:00:50 -0700769 olen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800770 bp += 4;
Elliott Hughescec480a2017-12-19 16:54:57 -0800771 len -= 4;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800772
Elliott Hughescec480a2017-12-19 16:54:57 -0800773 if (len < olen)
774 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700775 ND_TCHECK_LEN(bp, olen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800776 switch (otype) {
777 case PIMV2_HELLO_OPTION_HOLDTIME:
Elliott Hughescec480a2017-12-19 16:54:57 -0800778 if (olen != 2) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700779 ND_PRINT("[option length %u != 2]", olen);
780 nd_print_invalid(ndo);
781 return;
Elliott Hughescec480a2017-12-19 16:54:57 -0800782 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700783 unsigned_relts_print(ndo,
784 GET_BE_U_2(bp));
Elliott Hughescec480a2017-12-19 16:54:57 -0800785 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700786 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800787
788 case PIMV2_HELLO_OPTION_LANPRUNEDELAY:
789 if (olen != 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700790 ND_PRINT("[option length %u != 4]", olen);
791 nd_print_invalid(ndo);
792 return;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800793 } else {
794 char t_bit;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700795 uint16_t lan_delay, override_interval;
Elliott Hughes820eced2021-08-20 18:00:50 -0700796 lan_delay = GET_BE_U_2(bp);
797 override_interval = GET_BE_U_2(bp + 2);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800798 t_bit = (lan_delay & 0x8000)? 1 : 0;
799 lan_delay &= ~0x8000;
Elliott Hughes820eced2021-08-20 18:00:50 -0700800 ND_PRINT("\n\t T-bit=%u, LAN delay %ums, Override interval %ums",
801 t_bit, lan_delay, override_interval);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800802 }
803 break;
804
805 case PIMV2_HELLO_OPTION_DR_PRIORITY_OLD:
806 case PIMV2_HELLO_OPTION_DR_PRIORITY:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700807 switch (olen) {
808 case 0:
Elliott Hughes820eced2021-08-20 18:00:50 -0700809 ND_PRINT("Bi-Directional Capability (Old)");
Elliott Hughes892a68b2015-10-19 14:43:53 -0700810 break;
811 case 4:
Elliott Hughes820eced2021-08-20 18:00:50 -0700812 ND_PRINT("%u", GET_BE_U_4(bp));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700813 break;
814 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700815 ND_PRINT("[option length %u != 4]", olen);
816 nd_print_invalid(ndo);
817 return;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700818 break;
819 }
820 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800821
822 case PIMV2_HELLO_OPTION_GENID:
Elliott Hughescec480a2017-12-19 16:54:57 -0800823 if (olen != 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700824 ND_PRINT("[option length %u != 4]", olen);
825 nd_print_invalid(ndo);
826 return;
Elliott Hughescec480a2017-12-19 16:54:57 -0800827 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700828 ND_PRINT("0x%08x", GET_BE_U_4(bp));
Elliott Hughescec480a2017-12-19 16:54:57 -0800829 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800830 break;
831
832 case PIMV2_HELLO_OPTION_REFRESH_CAP:
Elliott Hughescec480a2017-12-19 16:54:57 -0800833 if (olen != 4) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700834 ND_PRINT("[option length %u != 4]", olen);
835 nd_print_invalid(ndo);
836 return;
Elliott Hughescec480a2017-12-19 16:54:57 -0800837 } else {
Elliott Hughes820eced2021-08-20 18:00:50 -0700838 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 Hughescec480a2017-12-19 16:54:57 -0800843 }
Elliott Hughes820eced2021-08-20 18:00:50 -0700844 if (GET_BE_U_2(bp + 2) != 0) {
845 ND_PRINT(" ?0x%04x?",
846 GET_BE_U_2(bp + 2));
Elliott Hughescec480a2017-12-19 16:54:57 -0800847 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800848 }
849 break;
850
851 case PIMV2_HELLO_OPTION_BIDIR_CAP:
852 break;
853
Elliott Hughes892a68b2015-10-19 14:43:53 -0700854 case PIMV2_HELLO_OPTION_ADDRESS_LIST_OLD:
855 case PIMV2_HELLO_OPTION_ADDRESS_LIST:
856 if (ndo->ndo_vflag > 1) {
The Android Open Source Project2949f582009-03-03 19:30:46 -0800857 const u_char *ptr = bp;
Elliott Hughescec480a2017-12-19 16:54:57 -0800858 u_int plen = len;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800859 while (ptr < (bp+olen)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700860 ND_PRINT("\n\t ");
Elliott Hughescec480a2017-12-19 16:54:57 -0800861 advance = pimv2_addr_print(ndo, ptr, plen, pimv2_unicast, pimv2_addr_len, 0);
862 if (advance < 0)
863 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800864 ptr += advance;
Elliott Hughescec480a2017-12-19 16:54:57 -0800865 plen -= advance;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800866 }
867 }
868 break;
869 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700870 if (ndo->ndo_vflag <= 1)
871 print_unknown_data(ndo, bp, "\n\t ", olen);
872 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800873 }
Elliott Hughes892a68b2015-10-19 14:43:53 -0700874 /* 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 Project2949f582009-03-03 19:30:46 -0800877 bp += olen;
Elliott Hughescec480a2017-12-19 16:54:57 -0800878 len -= olen;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800879 }
880 break;
881 }
882
883 case PIMV2_TYPE_REGISTER:
884 {
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700885 const struct ip *ip;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800886
Elliott Hughescec480a2017-12-19 16:54:57 -0800887 if (len < 4)
888 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700889 ND_TCHECK_LEN(bp, PIMV2_REGISTER_FLAG_LEN);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800890
Elliott Hughes820eced2021-08-20 18:00:50 -0700891 ND_PRINT(", Flags [ %s ]\n\t",
Elliott Hughes892a68b2015-10-19 14:43:53 -0700892 tok2str(pimv2_register_flag_values,
893 "none",
Elliott Hughes820eced2021-08-20 18:00:50 -0700894 GET_BE_U_4(bp)));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800895
Elliott Hughescec480a2017-12-19 16:54:57 -0800896 bp += 4; len -= 4;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800897 /* encapsulated multicast packet */
Elliott Hughescec480a2017-12-19 16:54:57 -0800898 if (len == 0)
899 goto trunc;
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700900 ip = (const struct ip *)bp;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800901 switch (IP_V(ip)) {
902 case 0: /* Null header */
Elliott Hughes820eced2021-08-20 18:00:50 -0700903 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 Project2949f582009-03-03 19:30:46 -0800906 break;
907
908 case 4: /* IPv4 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700909 ip_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800910 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700911
The Android Open Source Project2949f582009-03-03 19:30:46 -0800912 case 6: /* IPv6 */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700913 ip6_print(ndo, bp, len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800914 break;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700915
916 default:
Elliott Hughes820eced2021-08-20 18:00:50 -0700917 ND_PRINT("IP ver %u", IP_V(ip));
Elliott Hughes892a68b2015-10-19 14:43:53 -0700918 break;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800919 }
920 break;
921 }
922
923 case PIMV2_TYPE_REGISTER_STOP:
Elliott Hughes820eced2021-08-20 18:00:50 -0700924 ND_PRINT(" group=");
Elliott Hughescec480a2017-12-19 16:54:57 -0800925 if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_group, pimv2_addr_len, 0)) < 0)
926 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800927 bp += advance; len -= advance;
Elliott Hughes820eced2021-08-20 18:00:50 -0700928 ND_PRINT(" source=");
Elliott Hughescec480a2017-12-19 16:54:57 -0800929 if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0)
930 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800931 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 Hughes892a68b2015-10-19 14:43:53 -0700975 uint8_t ngroup;
976 uint16_t holdtime;
977 uint16_t njoin;
978 uint16_t nprune;
Elliott Hughes820eced2021-08-20 18:00:50 -0700979 u_int i, j;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800980
Elliott Hughes820eced2021-08-20 18:00:50 -0700981 if (PIM_TYPE(pim_typever) != 7) { /*not for Graft-ACK*/
982 ND_PRINT(", upstream-neighbor: ");
Elliott Hughescec480a2017-12-19 16:54:57 -0800983 if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0)
984 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800985 bp += advance; len -= advance;
986 }
Elliott Hughescec480a2017-12-19 16:54:57 -0800987 if (len < 4)
988 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -0700989 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 Project2949f582009-03-03 19:30:46 -0800995 if (holdtime == 0xffff)
Elliott Hughes820eced2021-08-20 18:00:50 -0700996 ND_PRINT("infinite");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800997 else
Elliott Hughese2e3bd12017-05-15 10:59:29 -0700998 unsigned_relts_print(ndo, holdtime);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800999 }
1000 bp += 4; len -= 4;
1001 for (i = 0; i < ngroup; i++) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001002 ND_PRINT("\n\t group #%u: ", i+1);
Elliott Hughescec480a2017-12-19 16:54:57 -08001003 if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_group, pimv2_addr_len, 0)) < 0)
1004 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001005 bp += advance; len -= advance;
Elliott Hughescec480a2017-12-19 16:54:57 -08001006 if (len < 4)
1007 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001008 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 Project2949f582009-03-03 19:30:46 -08001012 bp += 4; len -= 4;
1013 for (j = 0; j < njoin; j++) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001014 ND_PRINT("\n\t joined source #%u: ", j+1);
Elliott Hughescec480a2017-12-19 16:54:57 -08001015 if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_source, pimv2_addr_len, 0)) < 0)
1016 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001017 bp += advance; len -= advance;
1018 }
1019 for (j = 0; j < nprune; j++) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001020 ND_PRINT("\n\t pruned source #%u: ", j+1);
Elliott Hughescec480a2017-12-19 16:54:57 -08001021 if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_source, pimv2_addr_len, 0)) < 0)
1022 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001023 bp += advance; len -= advance;
1024 }
1025 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001026 break;
1027 }
1028
1029 case PIMV2_TYPE_BOOTSTRAP:
1030 {
Elliott Hughes820eced2021-08-20 18:00:50 -07001031 u_int i, j, frpcnt;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001032
1033 /* Fragment Tag, Hash Mask len, and BSR-priority */
Elliott Hughescec480a2017-12-19 16:54:57 -08001034 if (len < 2)
1035 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001036 ND_PRINT(" tag=%x", GET_BE_U_2(bp));
Elliott Hughescec480a2017-12-19 16:54:57 -08001037 bp += 2;
1038 len -= 2;
1039 if (len < 1)
1040 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001041 ND_PRINT(" hashmlen=%u", GET_U_1(bp));
Elliott Hughescec480a2017-12-19 16:54:57 -08001042 if (len < 2)
1043 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001044 ND_TCHECK_1(bp + 2);
1045 ND_PRINT(" BSRprio=%u", GET_U_1(bp + 1));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001046 bp += 2;
Elliott Hughescec480a2017-12-19 16:54:57 -08001047 len -= 2;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001048
1049 /* Encoded-Unicast-BSR-Address */
Elliott Hughes820eced2021-08-20 18:00:50 -07001050 ND_PRINT(" BSR=");
Elliott Hughescec480a2017-12-19 16:54:57 -08001051 if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0)
1052 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001053 bp += advance;
Elliott Hughescec480a2017-12-19 16:54:57 -08001054 len -= advance;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001055
Elliott Hughescec480a2017-12-19 16:54:57 -08001056 for (i = 0; len > 0; i++) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001057 /* Encoded-Group Address */
Elliott Hughes820eced2021-08-20 18:00:50 -07001058 ND_PRINT(" (group%u: ", i);
Elliott Hughescec480a2017-12-19 16:54:57 -08001059 if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_group, pimv2_addr_len, 0)) < 0)
1060 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001061 bp += advance;
Elliott Hughescec480a2017-12-19 16:54:57 -08001062 len -= advance;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001063
1064 /* RP-Count, Frag RP-Cnt, and rsvd */
Elliott Hughescec480a2017-12-19 16:54:57 -08001065 if (len < 1)
1066 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001067 ND_PRINT(" RPcnt=%u", GET_U_1(bp));
Elliott Hughescec480a2017-12-19 16:54:57 -08001068 if (len < 2)
1069 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001070 frpcnt = GET_U_1(bp + 1);
1071 ND_PRINT(" FRPcnt=%u", frpcnt);
Elliott Hughescec480a2017-12-19 16:54:57 -08001072 if (len < 4)
1073 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001074 bp += 4;
Elliott Hughescec480a2017-12-19 16:54:57 -08001075 len -= 4;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001076
Elliott Hughescec480a2017-12-19 16:54:57 -08001077 for (j = 0; j < frpcnt && len > 0; j++) {
The Android Open Source Project2949f582009-03-03 19:30:46 -08001078 /* each RP info */
Elliott Hughes820eced2021-08-20 18:00:50 -07001079 ND_PRINT(" RP%u=", j);
Elliott Hughescec480a2017-12-19 16:54:57 -08001080 if ((advance = pimv2_addr_print(ndo, bp, len,
The Android Open Source Project2949f582009-03-03 19:30:46 -08001081 pimv2_unicast,
Elliott Hughescec480a2017-12-19 16:54:57 -08001082 pimv2_addr_len,
1083 0)) < 0)
1084 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001085 bp += advance;
Elliott Hughescec480a2017-12-19 16:54:57 -08001086 len -= advance;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001087
Elliott Hughescec480a2017-12-19 16:54:57 -08001088 if (len < 2)
1089 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001090 ND_PRINT(",holdtime=");
1091 unsigned_relts_print(ndo,
1092 GET_BE_U_2(bp));
Elliott Hughescec480a2017-12-19 16:54:57 -08001093 if (len < 3)
1094 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001095 ND_PRINT(",prio=%u", GET_U_1(bp + 2));
Elliott Hughescec480a2017-12-19 16:54:57 -08001096 if (len < 4)
1097 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001098 bp += 4;
Elliott Hughescec480a2017-12-19 16:54:57 -08001099 len -= 4;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001100 }
Elliott Hughes820eced2021-08-20 18:00:50 -07001101 ND_PRINT(")");
The Android Open Source Project2949f582009-03-03 19:30:46 -08001102 }
The Android Open Source Project2949f582009-03-03 19:30:46 -08001103 break;
1104 }
1105 case PIMV2_TYPE_ASSERT:
Elliott Hughes820eced2021-08-20 18:00:50 -07001106 ND_PRINT(" group=");
Elliott Hughescec480a2017-12-19 16:54:57 -08001107 if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_group, pimv2_addr_len, 0)) < 0)
1108 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001109 bp += advance; len -= advance;
Elliott Hughes820eced2021-08-20 18:00:50 -07001110 ND_PRINT(" src=");
Elliott Hughescec480a2017-12-19 16:54:57 -08001111 if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0)
1112 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001113 bp += advance; len -= advance;
Elliott Hughescec480a2017-12-19 16:54:57 -08001114 if (len < 8)
1115 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001116 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 Project2949f582009-03-03 19:30:46 -08001121 break;
1122
1123 case PIMV2_TYPE_CANDIDATE_RP:
1124 {
Elliott Hughes820eced2021-08-20 18:00:50 -07001125 u_int i, pfxcnt;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001126
1127 /* Prefix-Cnt, Priority, and Holdtime */
Elliott Hughescec480a2017-12-19 16:54:57 -08001128 if (len < 1)
1129 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001130 ND_PRINT(" prefix-cnt=%u", GET_U_1(bp));
1131 pfxcnt = GET_U_1(bp);
Elliott Hughescec480a2017-12-19 16:54:57 -08001132 if (len < 2)
1133 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001134 ND_PRINT(" prio=%u", GET_U_1(bp + 1));
Elliott Hughescec480a2017-12-19 16:54:57 -08001135 if (len < 4)
1136 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001137 ND_PRINT(" holdtime=");
1138 unsigned_relts_print(ndo, GET_BE_U_2(bp + 2));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001139 bp += 4;
Elliott Hughescec480a2017-12-19 16:54:57 -08001140 len -= 4;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001141
1142 /* Encoded-Unicast-RP-Address */
Elliott Hughes820eced2021-08-20 18:00:50 -07001143 ND_PRINT(" RP=");
Elliott Hughescec480a2017-12-19 16:54:57 -08001144 if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0)
1145 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001146 bp += advance;
Elliott Hughescec480a2017-12-19 16:54:57 -08001147 len -= advance;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001148
1149 /* Encoded-Group Addresses */
Elliott Hughescec480a2017-12-19 16:54:57 -08001150 for (i = 0; i < pfxcnt && len > 0; i++) {
Elliott Hughes820eced2021-08-20 18:00:50 -07001151 ND_PRINT(" Group%u=", i);
Elliott Hughescec480a2017-12-19 16:54:57 -08001152 if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_group, pimv2_addr_len, 0)) < 0)
1153 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001154 bp += advance;
Elliott Hughescec480a2017-12-19 16:54:57 -08001155 len -= advance;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001156 }
1157 break;
1158 }
1159
1160 case PIMV2_TYPE_PRUNE_REFRESH:
Elliott Hughes820eced2021-08-20 18:00:50 -07001161 ND_PRINT(" src=");
Elliott Hughescec480a2017-12-19 16:54:57 -08001162 if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0)
1163 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001164 bp += advance;
Elliott Hughescec480a2017-12-19 16:54:57 -08001165 len -= advance;
Elliott Hughes820eced2021-08-20 18:00:50 -07001166 ND_PRINT(" grp=");
Elliott Hughescec480a2017-12-19 16:54:57 -08001167 if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_group, pimv2_addr_len, 0)) < 0)
1168 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001169 bp += advance;
Elliott Hughescec480a2017-12-19 16:54:57 -08001170 len -= advance;
Elliott Hughes820eced2021-08-20 18:00:50 -07001171 ND_PRINT(" forwarder=");
Elliott Hughescec480a2017-12-19 16:54:57 -08001172 if ((advance = pimv2_addr_print(ndo, bp, len, pimv2_unicast, pimv2_addr_len, 0)) < 0)
1173 goto trunc;
The Android Open Source Project2949f582009-03-03 19:30:46 -08001174 bp += advance;
Elliott Hughescec480a2017-12-19 16:54:57 -08001175 len -= advance;
1176 if (len < 2)
1177 goto trunc;
Elliott Hughes820eced2021-08-20 18:00:50 -07001178 ND_PRINT(" TUNR ");
1179 unsigned_relts_print(ndo, GET_BE_U_2(bp));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001180 break;
1181
Elliott Hughes820eced2021-08-20 18:00:50 -07001182 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 Project2949f582009-03-03 19:30:46 -08001224
1225 default:
Elliott Hughes820eced2021-08-20 18:00:50 -07001226 ND_PRINT(" [type %u]", PIM_TYPE(pim_typever));
The Android Open Source Project2949f582009-03-03 19:30:46 -08001227 break;
1228 }
1229
1230 return;
1231
1232trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -07001233 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -08001234}