]> The Tcpdump Group git mirrors - tcpdump/blob - print-pgm.c
NDOize 8 more small decoders
[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 #ifdef HAVE_CONFIG_H
17 #include "config.h"
18 #endif
19
20 #include <tcpdump-stdinc.h>
21
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25
26 #include "interface.h"
27 #include "extract.h"
28 #include "addrtoname.h"
29
30 #include "ip.h"
31 #ifdef INET6
32 #include "ip6.h"
33 #endif
34 #include "ipproto.h"
35
36 /*
37 * PGM header (RFC 3208)
38 */
39 struct pgm_header {
40 u_int16_t pgm_sport;
41 u_int16_t pgm_dport;
42 u_int8_t pgm_type;
43 u_int8_t pgm_options;
44 u_int16_t pgm_sum;
45 u_int8_t pgm_gsid[6];
46 u_int16_t pgm_length;
47 };
48
49 struct pgm_spm {
50 u_int32_t pgms_seq;
51 u_int32_t pgms_trailseq;
52 u_int32_t pgms_leadseq;
53 u_int16_t pgms_nla_afi;
54 u_int16_t pgms_reserved;
55 /* ... u_int8_t pgms_nla[0]; */
56 /* ... options */
57 };
58
59 struct pgm_nak {
60 u_int32_t pgmn_seq;
61 u_int16_t pgmn_source_afi;
62 u_int16_t pgmn_reserved;
63 /* ... u_int8_t pgmn_source[0]; */
64 /* ... u_int16_t pgmn_group_afi */
65 /* ... u_int16_t pgmn_reserved2; */
66 /* ... u_int8_t pgmn_group[0]; */
67 /* ... options */
68 };
69
70 struct pgm_ack {
71 u_int32_t pgma_rx_max_seq;
72 u_int32_t pgma_bitmap;
73 /* ... options */
74 };
75
76 struct pgm_poll {
77 u_int32_t pgmp_seq;
78 u_int16_t pgmp_round;
79 u_int16_t pgmp_reserved;
80 /* ... options */
81 };
82
83 struct pgm_polr {
84 u_int32_t pgmp_seq;
85 u_int16_t pgmp_round;
86 u_int16_t pgmp_subtype;
87 u_int16_t pgmp_nla_afi;
88 u_int16_t pgmp_reserved;
89 /* ... u_int8_t pgmp_nla[0]; */
90 /* ... options */
91 };
92
93 struct pgm_data {
94 u_int32_t pgmd_seq;
95 u_int32_t pgmd_trailseq;
96 /* ... options */
97 };
98
99 typedef enum _pgm_type {
100 PGM_SPM = 0, /* source path message */
101 PGM_POLL = 1, /* POLL Request */
102 PGM_POLR = 2, /* POLL Response */
103 PGM_ODATA = 4, /* original data */
104 PGM_RDATA = 5, /* repair data */
105 PGM_NAK = 8, /* NAK */
106 PGM_NULLNAK = 9, /* Null NAK */
107 PGM_NCF = 10, /* NAK Confirmation */
108 PGM_ACK = 11, /* ACK for congestion control */
109 PGM_SPMR = 12, /* SPM request */
110 PGM_MAX = 255
111 } pgm_type;
112
113 #define PGM_OPT_BIT_PRESENT 0x01
114 #define PGM_OPT_BIT_NETWORK 0x02
115 #define PGM_OPT_BIT_VAR_PKTLEN 0x40
116 #define PGM_OPT_BIT_PARITY 0x80
117
118 #define PGM_OPT_LENGTH 0x00
119 #define PGM_OPT_FRAGMENT 0x01
120 #define PGM_OPT_NAK_LIST 0x02
121 #define PGM_OPT_JOIN 0x03
122 #define PGM_OPT_NAK_BO_IVL 0x04
123 #define PGM_OPT_NAK_BO_RNG 0x05
124
125 #define PGM_OPT_REDIRECT 0x07
126 #define PGM_OPT_PARITY_PRM 0x08
127 #define PGM_OPT_PARITY_GRP 0x09
128 #define PGM_OPT_CURR_TGSIZE 0x0A
129 #define PGM_OPT_NBR_UNREACH 0x0B
130 #define PGM_OPT_PATH_NLA 0x0C
131
132 #define PGM_OPT_SYN 0x0D
133 #define PGM_OPT_FIN 0x0E
134 #define PGM_OPT_RST 0x0F
135 #define PGM_OPT_CR 0x10
136 #define PGM_OPT_CRQST 0x11
137
138 #define PGM_OPT_PGMCC_DATA 0x12
139 #define PGM_OPT_PGMCC_FEEDBACK 0x13
140
141 #define PGM_OPT_MASK 0x7f
142
143 #define PGM_OPT_END 0x80 /* end of options marker */
144
145 #define PGM_MIN_OPT_LEN 4
146
147 #ifndef AFI_IP
148 #define AFI_IP 1
149 #define AFI_IP6 2
150 #endif
151
152 void
153 pgm_print(register const u_char *bp, register u_int length,
154 register const u_char *bp2)
155 {
156 register const struct pgm_header *pgm;
157 register const struct ip *ip;
158 register char ch;
159 u_int16_t sport, dport;
160 int addr_size;
161 const void *nla;
162 int nla_af;
163 #ifdef INET6
164 char nla_buf[INET6_ADDRSTRLEN];
165 register const struct ip6_hdr *ip6;
166 #else
167 char nla_buf[INET_ADDRSTRLEN];
168 #endif
169 u_int8_t opt_type, opt_len;
170 u_int32_t seq, opts_len, len, offset;
171
172 pgm = (struct pgm_header *)bp;
173 ip = (struct ip *)bp2;
174 #ifdef INET6
175 if (IP_V(ip) == 6)
176 ip6 = (struct ip6_hdr *)bp2;
177 else
178 ip6 = NULL;
179 #else /* INET6 */
180 if (IP_V(ip) == 6) {
181 (void)printf("Can't handle IPv6");
182 return;
183 }
184 #endif /* INET6 */
185 ch = '\0';
186 if (!TTEST(pgm->pgm_dport)) {
187 #ifdef INET6
188 if (ip6) {
189 (void)printf("%s > %s: [|pgm]",
190 ip6addr_string(&ip6->ip6_src),
191 ip6addr_string(&ip6->ip6_dst));
192 return;
193 } else
194 #endif /* INET6 */
195 {
196 (void)printf("%s > %s: [|pgm]",
197 ipaddr_string(&ip->ip_src),
198 ipaddr_string(&ip->ip_dst));
199 return;
200 }
201 }
202
203 sport = EXTRACT_16BITS(&pgm->pgm_sport);
204 dport = EXTRACT_16BITS(&pgm->pgm_dport);
205
206 #ifdef INET6
207 if (ip6) {
208 if (ip6->ip6_nxt == IPPROTO_PGM) {
209 (void)printf("%s.%s > %s.%s: ",
210 ip6addr_string(&ip6->ip6_src),
211 tcpport_string(sport),
212 ip6addr_string(&ip6->ip6_dst),
213 tcpport_string(dport));
214 } else {
215 (void)printf("%s > %s: ",
216 tcpport_string(sport), tcpport_string(dport));
217 }
218 } else
219 #endif /*INET6*/
220 {
221 if (ip->ip_p == IPPROTO_PGM) {
222 (void)printf("%s.%s > %s.%s: ",
223 ipaddr_string(&ip->ip_src),
224 tcpport_string(sport),
225 ipaddr_string(&ip->ip_dst),
226 tcpport_string(dport));
227 } else {
228 (void)printf("%s > %s: ",
229 tcpport_string(sport), tcpport_string(dport));
230 }
231 }
232
233 TCHECK(*pgm);
234
235 (void)printf("PGM, length %u", EXTRACT_16BITS(&pgm->pgm_length));
236
237 if (!vflag)
238 return;
239
240 (void)printf(" 0x%02x%02x%02x%02x%02x%02x ",
241 pgm->pgm_gsid[0],
242 pgm->pgm_gsid[1],
243 pgm->pgm_gsid[2],
244 pgm->pgm_gsid[3],
245 pgm->pgm_gsid[4],
246 pgm->pgm_gsid[5]);
247 switch (pgm->pgm_type) {
248 case PGM_SPM: {
249 struct pgm_spm *spm;
250
251 spm = (struct pgm_spm *)(pgm + 1);
252 TCHECK(*spm);
253
254 switch (EXTRACT_16BITS(&spm->pgms_nla_afi)) {
255 case AFI_IP:
256 addr_size = sizeof(struct in_addr);
257 nla_af = AF_INET;
258 break;
259 #ifdef INET6
260 case AFI_IP6:
261 addr_size = sizeof(struct in6_addr);
262 nla_af = AF_INET6;
263 break;
264 #endif
265 default:
266 goto trunc;
267 break;
268 }
269 bp = (u_char *) (spm + 1);
270 TCHECK2(*bp, addr_size);
271 nla = bp;
272 bp += addr_size;
273
274 inet_ntop(nla_af, nla, nla_buf, sizeof(nla_buf));
275 (void)printf("SPM seq %u trail %u lead %u nla %s",
276 EXTRACT_32BITS(&spm->pgms_seq),
277 EXTRACT_32BITS(&spm->pgms_trailseq),
278 EXTRACT_32BITS(&spm->pgms_leadseq),
279 nla_buf);
280 break;
281 }
282
283 case PGM_POLL: {
284 struct pgm_poll *poll;
285
286 poll = (struct pgm_poll *)(pgm + 1);
287 TCHECK(*poll);
288 (void)printf("POLL seq %u round %u",
289 EXTRACT_32BITS(&poll->pgmp_seq),
290 EXTRACT_16BITS(&poll->pgmp_round));
291 bp = (u_char *) (poll + 1);
292 break;
293 }
294 case PGM_POLR: {
295 struct pgm_polr *polr;
296 u_int32_t ivl, rnd, mask;
297
298 polr = (struct pgm_polr *)(pgm + 1);
299 TCHECK(*polr);
300
301 switch (EXTRACT_16BITS(&polr->pgmp_nla_afi)) {
302 case AFI_IP:
303 addr_size = sizeof(struct in_addr);
304 nla_af = AF_INET;
305 break;
306 #ifdef INET6
307 case AFI_IP6:
308 addr_size = sizeof(struct in6_addr);
309 nla_af = AF_INET6;
310 break;
311 #endif
312 default:
313 goto trunc;
314 break;
315 }
316 bp = (u_char *) (polr + 1);
317 TCHECK2(*bp, addr_size);
318 nla = bp;
319 bp += addr_size;
320
321 inet_ntop(nla_af, nla, nla_buf, sizeof(nla_buf));
322
323 TCHECK2(*bp, sizeof(u_int32_t));
324 ivl = EXTRACT_32BITS(bp);
325 bp += sizeof(u_int32_t);
326
327 TCHECK2(*bp, sizeof(u_int32_t));
328 rnd = EXTRACT_32BITS(bp);
329 bp += sizeof(u_int32_t);
330
331 TCHECK2(*bp, sizeof(u_int32_t));
332 mask = EXTRACT_32BITS(bp);
333 bp += sizeof(u_int32_t);
334
335 (void)printf("POLR seq %u round %u nla %s ivl %u rnd 0x%08x "
336 "mask 0x%08x", EXTRACT_32BITS(&polr->pgmp_seq),
337 EXTRACT_16BITS(&polr->pgmp_round), nla_buf, ivl, rnd, mask);
338 break;
339 }
340 case PGM_ODATA: {
341 struct pgm_data *odata;
342
343 odata = (struct pgm_data *)(pgm + 1);
344 TCHECK(*odata);
345 (void)printf("ODATA trail %u seq %u",
346 EXTRACT_32BITS(&odata->pgmd_trailseq),
347 EXTRACT_32BITS(&odata->pgmd_seq));
348 bp = (u_char *) (odata + 1);
349 break;
350 }
351
352 case PGM_RDATA: {
353 struct pgm_data *rdata;
354
355 rdata = (struct pgm_data *)(pgm + 1);
356 TCHECK(*rdata);
357 (void)printf("RDATA trail %u seq %u",
358 EXTRACT_32BITS(&rdata->pgmd_trailseq),
359 EXTRACT_32BITS(&rdata->pgmd_seq));
360 bp = (u_char *) (rdata + 1);
361 break;
362 }
363
364 case PGM_NAK:
365 case PGM_NULLNAK:
366 case PGM_NCF: {
367 struct pgm_nak *nak;
368 const void *source, *group;
369 int source_af, group_af;
370 #ifdef INET6
371 char source_buf[INET6_ADDRSTRLEN], group_buf[INET6_ADDRSTRLEN];
372 #else
373 char source_buf[INET_ADDRSTRLEN], group_buf[INET_ADDRSTRLEN];
374 #endif
375
376 nak = (struct pgm_nak *)(pgm + 1);
377 TCHECK(*nak);
378
379 /*
380 * Skip past the source, saving info along the way
381 * and stopping if we don't have enough.
382 */
383 switch (EXTRACT_16BITS(&nak->pgmn_source_afi)) {
384 case AFI_IP:
385 addr_size = sizeof(struct in_addr);
386 source_af = AF_INET;
387 break;
388 #ifdef INET6
389 case AFI_IP6:
390 addr_size = sizeof(struct in6_addr);
391 source_af = AF_INET6;
392 break;
393 #endif
394 default:
395 goto trunc;
396 break;
397 }
398 bp = (u_char *) (nak + 1);
399 TCHECK2(*bp, addr_size);
400 source = bp;
401 bp += addr_size;
402
403 /*
404 * Skip past the group, saving info along the way
405 * and stopping if we don't have enough.
406 */
407 switch (EXTRACT_16BITS(bp)) {
408 case AFI_IP:
409 addr_size = sizeof(struct in_addr);
410 group_af = AF_INET;
411 break;
412 #ifdef INET6
413 case AFI_IP6:
414 addr_size = sizeof(struct in6_addr);
415 group_af = AF_INET6;
416 break;
417 #endif
418 default:
419 goto trunc;
420 break;
421 }
422 bp += (2 * sizeof(u_int16_t));
423 TCHECK2(*bp, addr_size);
424 group = bp;
425 bp += addr_size;
426
427 /*
428 * Options decoding can go here.
429 */
430 inet_ntop(source_af, source, source_buf, sizeof(source_buf));
431 inet_ntop(group_af, group, group_buf, sizeof(group_buf));
432 switch (pgm->pgm_type) {
433 case PGM_NAK:
434 (void)printf("NAK ");
435 break;
436 case PGM_NULLNAK:
437 (void)printf("NNAK ");
438 break;
439 case PGM_NCF:
440 (void)printf("NCF ");
441 break;
442 default:
443 break;
444 }
445 (void)printf("(%s -> %s), seq %u",
446 source_buf, group_buf, EXTRACT_32BITS(&nak->pgmn_seq));
447 break;
448 }
449
450 case PGM_ACK: {
451 struct pgm_ack *ack;
452
453 ack = (struct pgm_ack *)(pgm + 1);
454 TCHECK(*ack);
455 (void)printf("ACK seq %u",
456 EXTRACT_32BITS(&ack->pgma_rx_max_seq));
457 bp = (u_char *) (ack + 1);
458 break;
459 }
460
461 case PGM_SPMR:
462 (void)printf("SPMR");
463 break;
464
465 default:
466 (void)printf("UNKNOWN type 0x%02x", pgm->pgm_type);
467 break;
468
469 }
470 if (pgm->pgm_options & PGM_OPT_BIT_PRESENT) {
471
472 /*
473 * make sure there's enough for the first option header
474 */
475 if (!TTEST2(*bp, PGM_MIN_OPT_LEN)) {
476 (void)printf("[|OPT]");
477 return;
478 }
479
480 /*
481 * That option header MUST be an OPT_LENGTH option
482 * (see the first paragraph of section 9.1 in RFC 3208).
483 */
484 opt_type = *bp++;
485 if ((opt_type & PGM_OPT_MASK) != PGM_OPT_LENGTH) {
486 (void)printf("[First option bad, should be PGM_OPT_LENGTH, is %u]", opt_type & PGM_OPT_MASK);
487 return;
488 }
489 opt_len = *bp++;
490 if (opt_len != 4) {
491 (void)printf("[Bad OPT_LENGTH option, length %u != 4]", opt_len);
492 return;
493 }
494 opts_len = EXTRACT_16BITS(bp);
495 if (opts_len < 4) {
496 (void)printf("[Bad total option length %u < 4]", opts_len);
497 return;
498 }
499 bp += sizeof(u_int16_t);
500 (void)printf(" OPTS LEN %d", opts_len);
501 opts_len -= 4;
502
503 while (opts_len) {
504 if (opts_len < PGM_MIN_OPT_LEN) {
505 (void)printf("[Total option length leaves no room for final option]");
506 return;
507 }
508 opt_type = *bp++;
509 opt_len = *bp++;
510 if (opt_len < PGM_MIN_OPT_LEN) {
511 (void)printf("[Bad option, length %u < %u]", opt_len,
512 PGM_MIN_OPT_LEN);
513 break;
514 }
515 if (opts_len < opt_len) {
516 (void)printf("[Total option length leaves no room for final option]");
517 return;
518 }
519 if (!TTEST2(*bp, opt_len - 2)) {
520 (void)printf(" [|OPT]");
521 return;
522 }
523
524 switch (opt_type & PGM_OPT_MASK) {
525 case PGM_OPT_LENGTH:
526 if (opt_len != 4) {
527 (void)printf("[Bad OPT_LENGTH option, length %u != 4]", opt_len);
528 return;
529 }
530 (void)printf(" OPTS LEN (extra?) %d", EXTRACT_16BITS(bp));
531 bp += sizeof(u_int16_t);
532 opts_len -= 4;
533 break;
534
535 case PGM_OPT_FRAGMENT:
536 if (opt_len != 16) {
537 (void)printf("[Bad OPT_FRAGMENT option, length %u != 16]", opt_len);
538 return;
539 }
540 bp += 2;
541 seq = EXTRACT_32BITS(bp);
542 bp += sizeof(u_int32_t);
543 offset = EXTRACT_32BITS(bp);
544 bp += sizeof(u_int32_t);
545 len = EXTRACT_32BITS(bp);
546 bp += sizeof(u_int32_t);
547 (void)printf(" FRAG seq %u off %u len %u", seq, offset, len);
548 opts_len -= 16;
549 break;
550
551 case PGM_OPT_NAK_LIST:
552 bp += 2;
553 opt_len -= sizeof(u_int32_t); /* option header */
554 (void)printf(" NAK LIST");
555 while (opt_len) {
556 if (opt_len < sizeof(u_int32_t)) {
557 (void)printf("[Option length not a multiple of 4]");
558 return;
559 }
560 TCHECK2(*bp, sizeof(u_int32_t));
561 (void)printf(" %u", EXTRACT_32BITS(bp));
562 bp += sizeof(u_int32_t);
563 opt_len -= sizeof(u_int32_t);
564 opts_len -= sizeof(u_int32_t);
565 }
566 break;
567
568 case PGM_OPT_JOIN:
569 if (opt_len != 8) {
570 (void)printf("[Bad OPT_JOIN option, length %u != 8]", opt_len);
571 return;
572 }
573 bp += 2;
574 seq = EXTRACT_32BITS(bp);
575 bp += sizeof(u_int32_t);
576 (void)printf(" JOIN %u", seq);
577 opts_len -= 8;
578 break;
579
580 case PGM_OPT_NAK_BO_IVL:
581 if (opt_len != 12) {
582 (void)printf("[Bad OPT_NAK_BO_IVL option, length %u != 12]", opt_len);
583 return;
584 }
585 bp += 2;
586 offset = EXTRACT_32BITS(bp);
587 bp += sizeof(u_int32_t);
588 seq = EXTRACT_32BITS(bp);
589 bp += sizeof(u_int32_t);
590 (void)printf(" BACKOFF ivl %u ivlseq %u", offset, seq);
591 opts_len -= 12;
592 break;
593
594 case PGM_OPT_NAK_BO_RNG:
595 if (opt_len != 12) {
596 (void)printf("[Bad OPT_NAK_BO_RNG option, length %u != 12]", opt_len);
597 return;
598 }
599 bp += 2;
600 offset = EXTRACT_32BITS(bp);
601 bp += sizeof(u_int32_t);
602 seq = EXTRACT_32BITS(bp);
603 bp += sizeof(u_int32_t);
604 (void)printf(" BACKOFF max %u min %u", offset, seq);
605 opts_len -= 12;
606 break;
607
608 case PGM_OPT_REDIRECT:
609 bp += 2;
610 switch (EXTRACT_16BITS(bp)) {
611 case AFI_IP:
612 addr_size = sizeof(struct in_addr);
613 nla_af = AF_INET;
614 break;
615 #ifdef INET6
616 case AFI_IP6:
617 addr_size = sizeof(struct in6_addr);
618 nla_af = AF_INET6;
619 break;
620 #endif
621 default:
622 goto trunc;
623 break;
624 }
625 bp += (2 * sizeof(u_int16_t));
626 if (opt_len != 4 + addr_size) {
627 (void)printf("[Bad OPT_REDIRECT option, length %u != 4 + address size]", opt_len);
628 return;
629 }
630 TCHECK2(*bp, addr_size);
631 nla = bp;
632 bp += addr_size;
633
634 inet_ntop(nla_af, nla, nla_buf, sizeof(nla_buf));
635 (void)printf(" REDIRECT %s", (char *)nla);
636 opts_len -= 4 + addr_size;
637 break;
638
639 case PGM_OPT_PARITY_PRM:
640 if (opt_len != 8) {
641 (void)printf("[Bad OPT_PARITY_PRM option, length %u != 8]", opt_len);
642 return;
643 }
644 bp += 2;
645 len = EXTRACT_32BITS(bp);
646 bp += sizeof(u_int32_t);
647 (void)printf(" PARITY MAXTGS %u", len);
648 opts_len -= 8;
649 break;
650
651 case PGM_OPT_PARITY_GRP:
652 if (opt_len != 8) {
653 (void)printf("[Bad OPT_PARITY_GRP option, length %u != 8]", opt_len);
654 return;
655 }
656 bp += 2;
657 seq = EXTRACT_32BITS(bp);
658 bp += sizeof(u_int32_t);
659 (void)printf(" PARITY GROUP %u", seq);
660 opts_len -= 8;
661 break;
662
663 case PGM_OPT_CURR_TGSIZE:
664 if (opt_len != 8) {
665 (void)printf("[Bad OPT_CURR_TGSIZE option, length %u != 8]", opt_len);
666 return;
667 }
668 bp += 2;
669 len = EXTRACT_32BITS(bp);
670 bp += sizeof(u_int32_t);
671 (void)printf(" PARITY ATGS %u", len);
672 opts_len -= 8;
673 break;
674
675 case PGM_OPT_NBR_UNREACH:
676 if (opt_len != 4) {
677 (void)printf("[Bad OPT_NBR_UNREACH option, length %u != 4]", opt_len);
678 return;
679 }
680 bp += 2;
681 (void)printf(" NBR_UNREACH");
682 opts_len -= 4;
683 break;
684
685 case PGM_OPT_PATH_NLA:
686 (void)printf(" PATH_NLA [%d]", opt_len);
687 bp += opt_len;
688 opts_len -= opt_len;
689 break;
690
691 case PGM_OPT_SYN:
692 if (opt_len != 4) {
693 (void)printf("[Bad OPT_SYN option, length %u != 4]", opt_len);
694 return;
695 }
696 bp += 2;
697 (void)printf(" SYN");
698 opts_len -= 4;
699 break;
700
701 case PGM_OPT_FIN:
702 if (opt_len != 4) {
703 (void)printf("[Bad OPT_FIN option, length %u != 4]", opt_len);
704 return;
705 }
706 bp += 2;
707 (void)printf(" FIN");
708 opts_len -= 4;
709 break;
710
711 case PGM_OPT_RST:
712 if (opt_len != 4) {
713 (void)printf("[Bad OPT_RST option, length %u != 4]", opt_len);
714 return;
715 }
716 bp += 2;
717 (void)printf(" RST");
718 opts_len -= 4;
719 break;
720
721 case PGM_OPT_CR:
722 (void)printf(" CR");
723 bp += opt_len;
724 opts_len -= opt_len;
725 break;
726
727 case PGM_OPT_CRQST:
728 if (opt_len != 4) {
729 (void)printf("[Bad OPT_CRQST option, length %u != 4]", opt_len);
730 return;
731 }
732 bp += 2;
733 (void)printf(" CRQST");
734 opts_len -= 4;
735 break;
736
737 case PGM_OPT_PGMCC_DATA:
738 bp += 2;
739 offset = EXTRACT_32BITS(bp);
740 bp += sizeof(u_int32_t);
741 switch (EXTRACT_16BITS(bp)) {
742 case AFI_IP:
743 addr_size = sizeof(struct in_addr);
744 nla_af = AF_INET;
745 break;
746 #ifdef INET6
747 case AFI_IP6:
748 addr_size = sizeof(struct in6_addr);
749 nla_af = AF_INET6;
750 break;
751 #endif
752 default:
753 goto trunc;
754 break;
755 }
756 bp += (2 * sizeof(u_int16_t));
757 if (opt_len != 12 + addr_size) {
758 (void)printf("[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len);
759 return;
760 }
761 TCHECK2(*bp, addr_size);
762 nla = bp;
763 bp += addr_size;
764
765 inet_ntop(nla_af, nla, nla_buf, sizeof(nla_buf));
766 (void)printf(" PGMCC DATA %u %s", offset, (char*)nla);
767 opts_len -= 16;
768 break;
769
770 case PGM_OPT_PGMCC_FEEDBACK:
771 bp += 2;
772 offset = EXTRACT_32BITS(bp);
773 bp += sizeof(u_int32_t);
774 switch (EXTRACT_16BITS(bp)) {
775 case AFI_IP:
776 addr_size = sizeof(struct in_addr);
777 nla_af = AF_INET;
778 break;
779 #ifdef INET6
780 case AFI_IP6:
781 addr_size = sizeof(struct in6_addr);
782 nla_af = AF_INET6;
783 break;
784 #endif
785 default:
786 goto trunc;
787 break;
788 }
789 bp += (2 * sizeof(u_int16_t));
790 if (opt_len != 12 + addr_size) {
791 (void)printf("[Bad OPT_PGMCC_FEEDBACK option, length %u != 12 + address size]", opt_len);
792 return;
793 }
794 TCHECK2(*bp, addr_size);
795 nla = bp;
796 bp += addr_size;
797
798 inet_ntop(nla_af, nla, nla_buf, sizeof(nla_buf));
799 (void)printf(" PGMCC FEEDBACK %u %s", offset, (char*)nla);
800 opts_len -= 16;
801 break;
802
803 default:
804 (void)printf(" OPT_%02X [%d] ", opt_type, opt_len);
805 bp += opt_len;
806 opts_len -= opt_len;
807 break;
808 }
809
810 if (opt_type & PGM_OPT_END)
811 break;
812 }
813 }
814
815 (void)printf(" [%u]", length);
816 if (packettype == PT_PGM_ZMTP1 &&
817 (pgm->pgm_type == PGM_ODATA || pgm->pgm_type == PGM_RDATA))
818 zmtp1_print_datagram(gndo, bp, EXTRACT_16BITS(&pgm->pgm_length));
819
820 return;
821
822 trunc:
823 fputs("[|pgm]", stdout);
824 if (ch != '\0')
825 putchar('>');
826 }