]> The Tcpdump Group git mirrors - tcpdump/blob - print-pgm.c
Update the "Error converting time" tests for packet times
[tcpdump] / print-pgm.c
1 /*
2 * Redistribution and use in source and binary forms, with or without
3 * modification, are permitted provided that: (1) source code
4 * distributions retain the above copyright notice and this paragraph
5 * in its entirety, and (2) distributions including binary code include
6 * the above copyright notice and this paragraph in its entirety in
7 * the documentation or other materials provided with the distribution.
8 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
9 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
10 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
11 * FOR A PARTICULAR PURPOSE.
12 *
13 * Original code by Andy Heffernan (ahh@juniper.net)
14 */
15
16 /* \summary: Pragmatic General Multicast (PGM) printer */
17
18 /* specification: RFC 3208
19
20 Plus https://dl.acm.org/doi/pdf/10.1145/347057.347390 for PGMCC,
21 whence the ACK packet type comes; there are some I-Ds for PGMCC,
22 draft-ietf-rmt-bb-pgmcc-00 through draft-ietf-rmt-bb-pgmcc-03,
23 but none of them give any description of the packet-level
24 changes to PGM, unlike the paper in question, which merely gives
25 an *insufficient* description of said changes. In particular,
26 it doesn't indicate what the packet type code for ACK is.
27
28 Luigi Rizzo's PGMCC code for FreeBSD, at
29
30 https://web.archive.org/web/20020302084503/http://info.iet.unipi.it/~luigi/pgm-code/
31
32 uses 0x0b (11) for ACK.
33
34 A capture file attached to
35
36 https://gitlab.com/wireshark/wireshark/-/issues/4798
37
38 has packets that use 0x0d for ACK, as does the Wireshark dissector
39 for PGM, and as does OpenPGM at https://github.com/steve-o/openpgm.
40 It may be that some proprietary PGMCC implementations, such as
41 SmartPGM, do so as well.
42
43 We use *both*, treating *either one* as a PGMCC ACK, pending
44 more information, such as an answer to
45
46 https://github.com/steve-o/openpgm/issues/75.
47
48 */
49
50 #ifdef HAVE_CONFIG_H
51 #include <config.h>
52 #endif
53
54 #include "netdissect-stdinc.h"
55
56 #define ND_LONGJMP_FROM_TCHECK
57 #include "netdissect.h"
58 #include "extract.h"
59 #include "addrtoname.h"
60 #include "addrtostr.h"
61
62 #include "ip.h"
63 #include "ip6.h"
64 #include "ipproto.h"
65 #include "af.h"
66
67 /*
68 * PGM header (RFC 3208)
69 */
70 struct pgm_header {
71 nd_uint16_t pgm_sport;
72 nd_uint16_t pgm_dport;
73 nd_uint8_t pgm_type;
74 nd_uint8_t pgm_options;
75 nd_uint16_t pgm_sum;
76 nd_byte pgm_gsid[6];
77 nd_uint16_t pgm_length;
78 };
79
80 struct pgm_spm {
81 nd_uint32_t pgms_seq;
82 nd_uint32_t pgms_trailseq;
83 nd_uint32_t pgms_leadseq;
84 nd_uint16_t pgms_nla_afi;
85 nd_uint16_t pgms_reserved;
86 /* ... uint8_t pgms_nla[0]; */
87 /* ... options */
88 };
89
90 struct pgm_nak {
91 nd_uint32_t pgmn_seq;
92 nd_uint16_t pgmn_source_afi;
93 nd_uint16_t pgmn_reserved;
94 /* ... uint8_t pgmn_source[0]; */
95 /* ... uint16_t pgmn_group_afi */
96 /* ... uint16_t pgmn_reserved2; */
97 /* ... uint8_t pgmn_group[0]; */
98 /* ... options */
99 };
100
101 struct pgm_ack {
102 nd_uint32_t pgma_rx_max_seq;
103 nd_uint32_t pgma_bitmap;
104 /* ... options */
105 };
106
107 struct pgm_poll {
108 nd_uint32_t pgmp_seq;
109 nd_uint16_t pgmp_round;
110 nd_uint16_t pgmp_subtype;
111 nd_uint16_t pgmp_nla_afi;
112 nd_uint16_t pgmp_reserved;
113 /* ... uint8_t pgmp_nla[0]; */
114 /* ... options */
115 };
116
117 struct pgm_polr {
118 nd_uint32_t pgmp_seq;
119 nd_uint16_t pgmp_round;
120 nd_uint16_t pgmp_reserved;
121 /* ... options */
122 };
123
124 struct pgm_data {
125 nd_uint32_t pgmd_seq;
126 nd_uint32_t pgmd_trailseq;
127 /* ... options */
128 };
129
130 typedef enum _pgm_type {
131 PGM_SPM = 0x00, /* source path message */
132 PGM_POLL = 0x01, /* POLL Request */
133 PGM_POLR = 0x02, /* POLL Response */
134 PGM_ODATA = 0x04, /* original data */
135 PGM_RDATA = 0x05, /* repair data */
136 PGM_NAK = 0x08, /* NAK */
137 PGM_NULLNAK = 0x09, /* Null NAK */
138 PGM_NCF = 0x0a, /* NAK Confirmation */
139 PGM_ACK = 0x0b, /* ACK for congestion control? */
140 PGM_SPMR = 0x0c, /* SPM request */
141 PGM_ACK2 = 0x0d, /* Also ACK for congestion control? */
142 } pgm_type;
143
144 #define PGM_OPT_BIT_PRESENT 0x01
145 #define PGM_OPT_BIT_NETWORK 0x02
146 #define PGM_OPT_BIT_VAR_PKTLEN 0x40
147 #define PGM_OPT_BIT_PARITY 0x80
148
149 #define PGM_OPT_LENGTH 0x00
150 #define PGM_OPT_FRAGMENT 0x01
151 #define PGM_OPT_NAK_LIST 0x02
152 #define PGM_OPT_JOIN 0x03
153 #define PGM_OPT_NAK_BO_IVL 0x04
154 #define PGM_OPT_NAK_BO_RNG 0x05
155
156 #define PGM_OPT_REDIRECT 0x07
157 #define PGM_OPT_PARITY_PRM 0x08
158 #define PGM_OPT_PARITY_GRP 0x09
159 #define PGM_OPT_CURR_TGSIZE 0x0A
160 #define PGM_OPT_NBR_UNREACH 0x0B
161 #define PGM_OPT_PATH_NLA 0x0C
162
163 #define PGM_OPT_SYN 0x0D
164 #define PGM_OPT_FIN 0x0E
165 #define PGM_OPT_RST 0x0F
166 #define PGM_OPT_CR 0x10
167 #define PGM_OPT_CRQST 0x11
168
169 #define PGM_OPT_PGMCC_DATA 0x12
170 #define PGM_OPT_PGMCC_FEEDBACK 0x13
171
172 #define PGM_OPT_MASK 0x7f
173
174 #define PGM_OPT_END 0x80 /* end of options marker */
175
176 #define PGM_MIN_OPT_LEN 4
177
178 void
179 pgm_print(netdissect_options *ndo,
180 const u_char *bp, u_int length,
181 const u_char *bp2)
182 {
183 const struct pgm_header *pgm;
184 const struct ip *ip;
185 uint8_t pgm_type_val;
186 uint16_t sport, dport;
187 u_int nla_afnum;
188 char nla_buf[INET6_ADDRSTRLEN];
189 const struct ip6_hdr *ip6;
190 uint8_t opt_type, opt_len;
191 uint32_t seq, opts_len, len, offset;
192
193 ndo->ndo_protocol = "pgm";
194 pgm = (const struct pgm_header *)bp;
195 ip = (const struct ip *)bp2;
196 if (IP_V(ip) == 6)
197 ip6 = (const struct ip6_hdr *)bp2;
198 else
199 ip6 = NULL;
200 if (!ND_TTEST_2(pgm->pgm_dport)) {
201 if (ip6) {
202 ND_PRINT("%s > %s:",
203 GET_IP6ADDR_STRING(ip6->ip6_src),
204 GET_IP6ADDR_STRING(ip6->ip6_dst));
205 } else {
206 ND_PRINT("%s > %s:",
207 GET_IPADDR_STRING(ip->ip_src),
208 GET_IPADDR_STRING(ip->ip_dst));
209 }
210 nd_trunc_longjmp(ndo);
211 }
212
213 sport = GET_BE_U_2(pgm->pgm_sport);
214 dport = GET_BE_U_2(pgm->pgm_dport);
215
216 if (ip6) {
217 if (GET_U_1(ip6->ip6_nxt) == IPPROTO_PGM) {
218 ND_PRINT("%s.%s > %s.%s: ",
219 GET_IP6ADDR_STRING(ip6->ip6_src),
220 tcpport_string(ndo, sport),
221 GET_IP6ADDR_STRING(ip6->ip6_dst),
222 tcpport_string(ndo, dport));
223 } else {
224 ND_PRINT("%s > %s: ",
225 tcpport_string(ndo, sport), tcpport_string(ndo, dport));
226 }
227 } else {
228 if (GET_U_1(ip->ip_p) == IPPROTO_PGM) {
229 ND_PRINT("%s.%s > %s.%s: ",
230 GET_IPADDR_STRING(ip->ip_src),
231 tcpport_string(ndo, sport),
232 GET_IPADDR_STRING(ip->ip_dst),
233 tcpport_string(ndo, dport));
234 } else {
235 ND_PRINT("%s > %s: ",
236 tcpport_string(ndo, sport), tcpport_string(ndo, dport));
237 }
238 }
239
240 ND_TCHECK_SIZE(pgm);
241
242 ND_PRINT("PGM, length %u", GET_BE_U_2(pgm->pgm_length));
243
244 if (!ndo->ndo_vflag)
245 return;
246
247 pgm_type_val = GET_U_1(pgm->pgm_type);
248 ND_PRINT(" 0x%02x%02x%02x%02x%02x%02x ",
249 pgm->pgm_gsid[0],
250 pgm->pgm_gsid[1],
251 pgm->pgm_gsid[2],
252 pgm->pgm_gsid[3],
253 pgm->pgm_gsid[4],
254 pgm->pgm_gsid[5]);
255 bp += sizeof(struct pgm_header);
256 switch (pgm_type_val) {
257 case PGM_SPM: {
258 const struct pgm_spm *spm;
259
260 spm = (const struct pgm_spm *)bp;
261 ND_TCHECK_SIZE(spm);
262 bp += sizeof(struct pgm_spm);
263
264 switch (GET_BE_U_2(spm->pgms_nla_afi)) {
265 case AFNUM_IP:
266 ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
267 addrtostr(bp, nla_buf, sizeof(nla_buf));
268 bp += sizeof(nd_ipv4);
269 break;
270 case AFNUM_IP6:
271 ND_TCHECK_LEN(bp, sizeof(nd_ipv6));
272 addrtostr6(bp, nla_buf, sizeof(nla_buf));
273 bp += sizeof(nd_ipv6);
274 break;
275 default:
276 goto invalid;
277 }
278
279 ND_PRINT("SPM seq %u trail %u lead %u nla %s",
280 GET_BE_U_4(spm->pgms_seq),
281 GET_BE_U_4(spm->pgms_trailseq),
282 GET_BE_U_4(spm->pgms_leadseq),
283 nla_buf);
284 break;
285 }
286
287 case PGM_POLL: {
288 const struct pgm_poll *pgm_poll;
289 uint32_t ivl, rnd, mask;
290
291 pgm_poll = (const struct pgm_poll *)bp;
292 ND_TCHECK_SIZE(pgm_poll);
293 bp += sizeof(struct pgm_poll);
294
295 switch (GET_BE_U_2(pgm_poll->pgmp_nla_afi)) {
296 case AFNUM_IP:
297 ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
298 addrtostr(bp, nla_buf, sizeof(nla_buf));
299 bp += sizeof(nd_ipv4);
300 break;
301 case AFNUM_IP6:
302 ND_TCHECK_LEN(bp, sizeof(nd_ipv6));
303 addrtostr6(bp, nla_buf, sizeof(nla_buf));
304 bp += sizeof(nd_ipv6);
305 break;
306 default:
307 goto invalid;
308 }
309
310 ivl = GET_BE_U_4(bp);
311 bp += sizeof(uint32_t);
312
313 rnd = GET_BE_U_4(bp);
314 bp += sizeof(uint32_t);
315
316 mask = GET_BE_U_4(bp);
317 bp += sizeof(uint32_t);
318
319 ND_PRINT("POLL seq %u round %u nla %s ivl %u rnd 0x%08x "
320 "mask 0x%08x", GET_BE_U_4(pgm_poll->pgmp_seq),
321 GET_BE_U_2(pgm_poll->pgmp_round), nla_buf, ivl, rnd,
322 mask);
323 break;
324 }
325 case PGM_POLR: {
326 const struct pgm_polr *polr_msg;
327
328 polr_msg = (const struct pgm_polr *)bp;
329 ND_TCHECK_SIZE(polr_msg);
330 ND_PRINT("POLR seq %u round %u",
331 GET_BE_U_4(polr_msg->pgmp_seq),
332 GET_BE_U_2(polr_msg->pgmp_round));
333 bp += sizeof(struct pgm_polr);
334 break;
335 }
336 case PGM_ODATA: {
337 const struct pgm_data *odata;
338
339 odata = (const struct pgm_data *)bp;
340 ND_PRINT("ODATA trail %u seq %u",
341 GET_BE_U_4(odata->pgmd_trailseq),
342 GET_BE_U_4(odata->pgmd_seq));
343 bp += sizeof(struct pgm_data);
344 break;
345 }
346
347 case PGM_RDATA: {
348 const struct pgm_data *rdata;
349
350 rdata = (const struct pgm_data *)bp;
351 ND_PRINT("RDATA trail %u seq %u",
352 GET_BE_U_4(rdata->pgmd_trailseq),
353 GET_BE_U_4(rdata->pgmd_seq));
354 bp += sizeof(struct pgm_data);
355 break;
356 }
357
358 case PGM_NAK:
359 case PGM_NULLNAK:
360 case PGM_NCF: {
361 const struct pgm_nak *nak;
362 char source_buf[INET6_ADDRSTRLEN], group_buf[INET6_ADDRSTRLEN];
363
364 nak = (const struct pgm_nak *)bp;
365 ND_TCHECK_SIZE(nak);
366 bp += sizeof(struct pgm_nak);
367
368 /*
369 * Skip past the source, saving info along the way
370 * and stopping if we don't have enough.
371 */
372 switch (GET_BE_U_2(nak->pgmn_source_afi)) {
373 case AFNUM_IP:
374 ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
375 addrtostr(bp, source_buf, sizeof(source_buf));
376 bp += sizeof(nd_ipv4);
377 break;
378 case AFNUM_IP6:
379 ND_TCHECK_LEN(bp, sizeof(nd_ipv6));
380 addrtostr6(bp, source_buf, sizeof(source_buf));
381 bp += sizeof(nd_ipv6);
382 break;
383 default:
384 goto invalid;
385 }
386
387 /*
388 * Skip past the group, saving info along the way
389 * and stopping if we don't have enough.
390 */
391 bp += (2 * sizeof(uint16_t));
392 switch (GET_BE_U_2(bp)) {
393 case AFNUM_IP:
394 ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
395 addrtostr(bp, group_buf, sizeof(group_buf));
396 bp += sizeof(nd_ipv4);
397 break;
398 case AFNUM_IP6:
399 ND_TCHECK_LEN(bp, sizeof(nd_ipv6));
400 addrtostr6(bp, group_buf, sizeof(group_buf));
401 bp += sizeof(nd_ipv6);
402 break;
403 default:
404 goto invalid;
405 }
406
407 /*
408 * Options decoding can go here.
409 */
410 switch (pgm_type_val) {
411 case PGM_NAK:
412 ND_PRINT("NAK ");
413 break;
414 case PGM_NULLNAK:
415 ND_PRINT("NNAK ");
416 break;
417 case PGM_NCF:
418 ND_PRINT("NCF ");
419 break;
420 default:
421 break;
422 }
423 ND_PRINT("(%s -> %s), seq %u",
424 source_buf, group_buf, GET_BE_U_4(nak->pgmn_seq));
425 break;
426 }
427
428 case PGM_ACK:
429 case PGM_ACK2: {
430 const struct pgm_ack *ack;
431
432 ack = (const struct pgm_ack *)bp;
433 ND_TCHECK_SIZE(ack);
434 ND_PRINT("ACK seq %u",
435 GET_BE_U_4(ack->pgma_rx_max_seq));
436 bp += sizeof(struct pgm_ack);
437 break;
438 }
439
440 case PGM_SPMR:
441 ND_PRINT("SPMR");
442 break;
443
444 default:
445 ND_PRINT("UNKNOWN type 0x%02x", pgm_type_val);
446 break;
447
448 }
449 if (GET_U_1(pgm->pgm_options) & PGM_OPT_BIT_PRESENT) {
450
451 /*
452 * make sure there's enough for the first option header
453 */
454 ND_TCHECK_LEN(bp, PGM_MIN_OPT_LEN);
455
456 /*
457 * That option header MUST be an OPT_LENGTH option
458 * (see the first paragraph of section 9.1 in RFC 3208).
459 */
460 opt_type = GET_U_1(bp);
461 bp++;
462 if ((opt_type & PGM_OPT_MASK) != PGM_OPT_LENGTH) {
463 ND_PRINT("[First option bad, should be PGM_OPT_LENGTH, is %u]", opt_type & PGM_OPT_MASK);
464 return;
465 }
466 opt_len = GET_U_1(bp);
467 bp++;
468 if (opt_len != 4) {
469 ND_PRINT("[Bad OPT_LENGTH option, length %u != 4]", opt_len);
470 return;
471 }
472 opts_len = GET_BE_U_2(bp);
473 bp += sizeof(uint16_t);
474 if (opts_len < 4) {
475 ND_PRINT("[Bad total option length %u < 4]", opts_len);
476 return;
477 }
478 ND_PRINT(" OPTS LEN %u", opts_len);
479 opts_len -= 4;
480
481 while (opts_len) {
482 if (opts_len < PGM_MIN_OPT_LEN) {
483 ND_PRINT("[Total option length leaves no room for final option]");
484 return;
485 }
486 opt_type = GET_U_1(bp);
487 bp++;
488 opt_len = GET_U_1(bp);
489 bp++;
490 if (opt_len < PGM_MIN_OPT_LEN) {
491 ND_PRINT("[Bad option, length %u < %u]", opt_len,
492 PGM_MIN_OPT_LEN);
493 break;
494 }
495 if (opts_len < opt_len) {
496 ND_PRINT("[Total option length leaves no room for final option]");
497 return;
498 }
499 ND_TCHECK_LEN(bp, opt_len - 2);
500
501 switch (opt_type & PGM_OPT_MASK) {
502 case PGM_OPT_LENGTH:
503 #define PGM_OPT_LENGTH_LEN (2+2)
504 if (opt_len != PGM_OPT_LENGTH_LEN) {
505 ND_PRINT("[Bad OPT_LENGTH option, length %u != %u]",
506 opt_len, PGM_OPT_LENGTH_LEN);
507 return;
508 }
509 ND_PRINT(" OPTS LEN (extra?) %u", GET_BE_U_2(bp));
510 bp += 2;
511 opts_len -= PGM_OPT_LENGTH_LEN;
512 break;
513
514 case PGM_OPT_FRAGMENT:
515 #define PGM_OPT_FRAGMENT_LEN (2+2+4+4+4)
516 if (opt_len != PGM_OPT_FRAGMENT_LEN) {
517 ND_PRINT("[Bad OPT_FRAGMENT option, length %u != %u]",
518 opt_len, PGM_OPT_FRAGMENT_LEN);
519 return;
520 }
521 bp += 2;
522 seq = GET_BE_U_4(bp);
523 bp += 4;
524 offset = GET_BE_U_4(bp);
525 bp += 4;
526 len = GET_BE_U_4(bp);
527 bp += 4;
528 ND_PRINT(" FRAG seq %u off %u len %u", seq, offset, len);
529 opts_len -= PGM_OPT_FRAGMENT_LEN;
530 break;
531
532 case PGM_OPT_NAK_LIST:
533 bp += 2;
534 opt_len -= 4; /* option header */
535 ND_PRINT(" NAK LIST");
536 while (opt_len) {
537 if (opt_len < 4) {
538 ND_PRINT("[Option length not a multiple of 4]");
539 return;
540 }
541 ND_PRINT(" %u", GET_BE_U_4(bp));
542 bp += 4;
543 opt_len -= 4;
544 opts_len -= 4;
545 }
546 break;
547
548 case PGM_OPT_JOIN:
549 #define PGM_OPT_JOIN_LEN (2+2+4)
550 if (opt_len != PGM_OPT_JOIN_LEN) {
551 ND_PRINT("[Bad OPT_JOIN option, length %u != %u]",
552 opt_len, PGM_OPT_JOIN_LEN);
553 return;
554 }
555 bp += 2;
556 seq = GET_BE_U_4(bp);
557 bp += 4;
558 ND_PRINT(" JOIN %u", seq);
559 opts_len -= PGM_OPT_JOIN_LEN;
560 break;
561
562 case PGM_OPT_NAK_BO_IVL:
563 #define PGM_OPT_NAK_BO_IVL_LEN (2+2+4+4)
564 if (opt_len != PGM_OPT_NAK_BO_IVL_LEN) {
565 ND_PRINT("[Bad OPT_NAK_BO_IVL option, length %u != %u]",
566 opt_len, PGM_OPT_NAK_BO_IVL_LEN);
567 return;
568 }
569 bp += 2;
570 offset = GET_BE_U_4(bp);
571 bp += 4;
572 seq = GET_BE_U_4(bp);
573 bp += 4;
574 ND_PRINT(" BACKOFF ivl %u ivlseq %u", offset, seq);
575 opts_len -= PGM_OPT_NAK_BO_IVL_LEN;
576 break;
577
578 case PGM_OPT_NAK_BO_RNG:
579 #define PGM_OPT_NAK_BO_RNG_LEN (2+2+4+4)
580 if (opt_len != PGM_OPT_NAK_BO_RNG_LEN) {
581 ND_PRINT("[Bad OPT_NAK_BO_RNG option, length %u != %u]",
582 opt_len, PGM_OPT_NAK_BO_RNG_LEN);
583 return;
584 }
585 bp += 2;
586 offset = GET_BE_U_4(bp);
587 bp += 4;
588 seq = GET_BE_U_4(bp);
589 bp += 4;
590 ND_PRINT(" BACKOFF max %u min %u", offset, seq);
591 opts_len -= PGM_OPT_NAK_BO_RNG_LEN;
592 break;
593
594 case PGM_OPT_REDIRECT:
595 #define PGM_OPT_REDIRECT_FIXED_LEN (2+2+2+2)
596 if (opt_len < PGM_OPT_REDIRECT_FIXED_LEN) {
597 ND_PRINT("[Bad OPT_REDIRECT option, length %u < %u]",
598 opt_len, PGM_OPT_REDIRECT_FIXED_LEN);
599 return;
600 }
601 bp += 2;
602 nla_afnum = GET_BE_U_2(bp);
603 bp += 2+2;
604 switch (nla_afnum) {
605 case AFNUM_IP:
606 if (opt_len != PGM_OPT_REDIRECT_FIXED_LEN + sizeof(nd_ipv4)) {
607 ND_PRINT("[Bad OPT_REDIRECT option, length %u != %u + address size]",
608 opt_len, PGM_OPT_REDIRECT_FIXED_LEN);
609 return;
610 }
611 ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
612 addrtostr(bp, nla_buf, sizeof(nla_buf));
613 bp += sizeof(nd_ipv4);
614 opts_len -= PGM_OPT_REDIRECT_FIXED_LEN + sizeof(nd_ipv4);
615 break;
616 case AFNUM_IP6:
617 if (opt_len != PGM_OPT_REDIRECT_FIXED_LEN + sizeof(nd_ipv6)) {
618 ND_PRINT("[Bad OPT_REDIRECT option, length %u != %u + address size]",
619 opt_len, PGM_OPT_REDIRECT_FIXED_LEN);
620 return;
621 }
622 ND_TCHECK_LEN(bp, sizeof(nd_ipv6));
623 addrtostr6(bp, nla_buf, sizeof(nla_buf));
624 bp += sizeof(nd_ipv6);
625 opts_len -= PGM_OPT_REDIRECT_FIXED_LEN + sizeof(nd_ipv6);
626 break;
627 default:
628 goto invalid;
629 }
630
631 ND_PRINT(" REDIRECT %s", nla_buf);
632 break;
633
634 case PGM_OPT_PARITY_PRM:
635 #define PGM_OPT_PARITY_PRM_LEN (2+2+4)
636 if (opt_len != PGM_OPT_PARITY_PRM_LEN) {
637 ND_PRINT("[Bad OPT_PARITY_PRM option, length %u != %u]",
638 opt_len, PGM_OPT_PARITY_PRM_LEN);
639 return;
640 }
641 bp += 2;
642 len = GET_BE_U_4(bp);
643 bp += 4;
644 ND_PRINT(" PARITY MAXTGS %u", len);
645 opts_len -= PGM_OPT_PARITY_PRM_LEN;
646 break;
647
648 case PGM_OPT_PARITY_GRP:
649 #define PGM_OPT_PARITY_GRP_LEN (2+2+4)
650 if (opt_len != PGM_OPT_PARITY_GRP_LEN) {
651 ND_PRINT("[Bad OPT_PARITY_GRP option, length %u != %u]",
652 opt_len, PGM_OPT_PARITY_GRP_LEN);
653 return;
654 }
655 bp += 2;
656 seq = GET_BE_U_4(bp);
657 bp += 4;
658 ND_PRINT(" PARITY GROUP %u", seq);
659 opts_len -= PGM_OPT_PARITY_GRP_LEN;
660 break;
661
662 case PGM_OPT_CURR_TGSIZE:
663 #define PGM_OPT_CURR_TGSIZE_LEN (2+2+4)
664 if (opt_len != PGM_OPT_CURR_TGSIZE_LEN) {
665 ND_PRINT("[Bad OPT_CURR_TGSIZE option, length %u != %u]",
666 opt_len, PGM_OPT_CURR_TGSIZE_LEN);
667 return;
668 }
669 bp += 2;
670 len = GET_BE_U_4(bp);
671 bp += 4;
672 ND_PRINT(" PARITY ATGS %u", len);
673 opts_len -= PGM_OPT_CURR_TGSIZE_LEN;
674 break;
675
676 case PGM_OPT_NBR_UNREACH:
677 #define PGM_OPT_NBR_UNREACH_LEN (2+2)
678 if (opt_len != PGM_OPT_NBR_UNREACH_LEN) {
679 ND_PRINT("[Bad OPT_NBR_UNREACH option, length %u != %u]",
680 opt_len, PGM_OPT_NBR_UNREACH_LEN);
681 return;
682 }
683 bp += 2;
684 ND_PRINT(" NBR_UNREACH");
685 opts_len -= PGM_OPT_NBR_UNREACH_LEN;
686 break;
687
688 case PGM_OPT_PATH_NLA:
689 ND_PRINT(" PATH_NLA [%u]", opt_len);
690 bp += opt_len - 2;
691 opts_len -= opt_len;
692 break;
693
694 case PGM_OPT_SYN:
695 #define PGM_OPT_SYN_LEN (2+2)
696 if (opt_len != PGM_OPT_SYN_LEN) {
697 ND_PRINT("[Bad OPT_SYN option, length %u != %u]",
698 opt_len, PGM_OPT_SYN_LEN);
699 return;
700 }
701 bp += 2;
702 ND_PRINT(" SYN");
703 opts_len -= PGM_OPT_SYN_LEN;
704 break;
705
706 case PGM_OPT_FIN:
707 #define PGM_OPT_FIN_LEN (2+2)
708 if (opt_len != PGM_OPT_FIN_LEN) {
709 ND_PRINT("[Bad OPT_FIN option, length %u != %u]",
710 opt_len, PGM_OPT_FIN_LEN);
711 return;
712 }
713 bp += 2;
714 ND_PRINT(" FIN");
715 opts_len -= PGM_OPT_FIN_LEN;
716 break;
717
718 case PGM_OPT_RST:
719 #define PGM_OPT_RST_LEN (2+2)
720 if (opt_len != PGM_OPT_RST_LEN) {
721 ND_PRINT("[Bad OPT_RST option, length %u != %u]",
722 opt_len, PGM_OPT_RST_LEN);
723 return;
724 }
725 bp += 2;
726 ND_PRINT(" RST");
727 opts_len -= PGM_OPT_RST_LEN;
728 break;
729
730 case PGM_OPT_CR:
731 ND_PRINT(" CR");
732 bp += opt_len - 2;
733 opts_len -= opt_len;
734 break;
735
736 case PGM_OPT_CRQST:
737 #define PGM_OPT_CRQST_LEN (2+2)
738 if (opt_len != PGM_OPT_CRQST_LEN) {
739 ND_PRINT("[Bad OPT_CRQST option, length %u != %u]",
740 opt_len, PGM_OPT_CRQST_LEN);
741 return;
742 }
743 bp += 2;
744 ND_PRINT(" CRQST");
745 opts_len -= PGM_OPT_CRQST_LEN;
746 break;
747
748 case PGM_OPT_PGMCC_DATA:
749 #define PGM_OPT_PGMCC_DATA_FIXED_LEN (2+2+4+2+2)
750 if (opt_len < PGM_OPT_PGMCC_DATA_FIXED_LEN) {
751 ND_PRINT("[Bad OPT_PGMCC_DATA option, length %u < %u]",
752 opt_len, PGM_OPT_PGMCC_DATA_FIXED_LEN);
753 return;
754 }
755 bp += 2;
756 offset = GET_BE_U_4(bp);
757 bp += 4;
758 nla_afnum = GET_BE_U_2(bp);
759 bp += 2+2;
760 switch (nla_afnum) {
761 case AFNUM_IP:
762 if (opt_len != PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(nd_ipv4)) {
763 ND_PRINT("[Bad OPT_PGMCC_DATA option, length %u != %u + address size]",
764 opt_len, PGM_OPT_PGMCC_DATA_FIXED_LEN);
765 return;
766 }
767 ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
768 addrtostr(bp, nla_buf, sizeof(nla_buf));
769 bp += sizeof(nd_ipv4);
770 opts_len -= PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(nd_ipv4);
771 break;
772 case AFNUM_IP6:
773 if (opt_len != PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(nd_ipv6)) {
774 ND_PRINT("[Bad OPT_PGMCC_DATA option, length %u != %u + address size]",
775 opt_len, PGM_OPT_PGMCC_DATA_FIXED_LEN);
776 return;
777 }
778 ND_TCHECK_LEN(bp, sizeof(nd_ipv6));
779 addrtostr6(bp, nla_buf, sizeof(nla_buf));
780 bp += sizeof(nd_ipv6);
781 opts_len -= PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(nd_ipv6);
782 break;
783 default:
784 goto invalid;
785 }
786
787 ND_PRINT(" PGMCC DATA %u %s", offset, nla_buf);
788 break;
789
790 case PGM_OPT_PGMCC_FEEDBACK:
791 #define PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN (2+2+4+2+2)
792 if (opt_len < PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN) {
793 ND_PRINT("[Bad PGM_OPT_PGMCC_FEEDBACK option, length %u < %u]",
794 opt_len, PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN);
795 return;
796 }
797 bp += 2;
798 offset = GET_BE_U_4(bp);
799 bp += 4;
800 nla_afnum = GET_BE_U_2(bp);
801 bp += 2+2;
802 switch (nla_afnum) {
803 case AFNUM_IP:
804 if (opt_len != PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(nd_ipv4)) {
805 ND_PRINT("[Bad OPT_PGMCC_FEEDBACK option, length %u != %u + address size]",
806 opt_len, PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN);
807 return;
808 }
809 ND_TCHECK_LEN(bp, sizeof(nd_ipv4));
810 addrtostr(bp, nla_buf, sizeof(nla_buf));
811 bp += sizeof(nd_ipv4);
812 opts_len -= PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(nd_ipv4);
813 break;
814 case AFNUM_IP6:
815 if (opt_len != PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(nd_ipv6)) {
816 ND_PRINT("[Bad OPT_PGMCC_FEEDBACK option, length %u != %u + address size]",
817 opt_len, PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN);
818 return;
819 }
820 ND_TCHECK_LEN(bp, sizeof(nd_ipv6));
821 addrtostr6(bp, nla_buf, sizeof(nla_buf));
822 bp += sizeof(nd_ipv6);
823 opts_len -= PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(nd_ipv6);
824 break;
825 default:
826 goto invalid;
827 }
828
829 ND_PRINT(" PGMCC FEEDBACK %u %s", offset, nla_buf);
830 break;
831
832 default:
833 ND_PRINT(" OPT_%02X [%u] ", opt_type, opt_len);
834 bp += opt_len - 2;
835 opts_len -= opt_len;
836 break;
837 }
838
839 if (opt_type & PGM_OPT_END)
840 break;
841 }
842 }
843
844 ND_PRINT(" [%u]", length);
845 if (ndo->ndo_packettype == PT_PGM_ZMTP1 &&
846 (pgm_type_val == PGM_ODATA || pgm_type_val == PGM_RDATA))
847 zmtp1_datagram_print(ndo, bp,
848 GET_BE_U_2(pgm->pgm_length));
849
850 return;
851 invalid:
852 nd_print_invalid(ndo);
853 }