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.
13 * Original code by Andy Heffernan (ahh@juniper.net)
17 static const char rcsid
[] _U_
=
18 "@(#) $Header: /tcpdump/master/tcpdump/print-pgm.c,v 1.5 2005-06-07 22:05:58 guy Exp $";
25 #include <tcpdump-stdinc.h>
31 #include "interface.h"
33 #include "addrtoname.h"
42 * PGM header (RFC 3208)
56 u_int32_t pgms_trailseq
;
57 u_int32_t pgms_leadseq
;
58 u_int16_t pgms_nla_afi
;
59 u_int16_t pgms_reserved
;
60 /* ... u_int8_t pgms_nla[0]; */
66 u_int16_t pgmn_source_afi
;
67 u_int16_t pgmn_reserved
;
68 /* ... u_int8_t pgmn_source[0]; */
69 /* ... u_int16_t pgmn_group_afi */
70 /* ... u_int16_t pgmn_reserved2; */
71 /* ... u_int8_t pgmn_group[0]; */
76 u_int32_t pgma_rx_max_seq
;
77 u_int32_t pgma_bitmap
;
84 u_int16_t pgmp_reserved
;
91 u_int16_t pgmp_subtype
;
92 u_int16_t pgmp_nla_afi
;
93 u_int16_t pgmp_reserved
;
94 /* ... u_int8_t pgmp_nla[0]; */
100 u_int32_t pgmd_trailseq
;
104 typedef enum _pgm_type
{
105 PGM_SPM
= 0, /* source path message */
106 PGM_POLL
= 1, /* POLL Request */
107 PGM_POLR
= 2, /* POLL Response */
108 PGM_ODATA
= 4, /* original data */
109 PGM_RDATA
= 5, /* repair data */
110 PGM_NAK
= 8, /* NAK */
111 PGM_NULLNAK
= 9, /* Null NAK */
112 PGM_NCF
= 10, /* NAK Confirmation */
113 PGM_ACK
= 11, /* ACK for congestion control */
114 PGM_SPMR
= 12, /* SPM request */
118 #define PGM_OPT_BIT_PRESENT 0x01
119 #define PGM_OPT_BIT_NETWORK 0x02
120 #define PGM_OPT_BIT_VAR_PKTLEN 0x40
121 #define PGM_OPT_BIT_PARITY 0x80
123 #define PGM_OPT_LENGTH 0x00
124 #define PGM_OPT_FRAGMENT 0x01
125 #define PGM_OPT_NAK_LIST 0x02
126 #define PGM_OPT_JOIN 0x03
127 #define PGM_OPT_NAK_BO_IVL 0x04
128 #define PGM_OPT_NAK_BO_RNG 0x05
130 #define PGM_OPT_REDIRECT 0x07
131 #define PGM_OPT_PARITY_PRM 0x08
132 #define PGM_OPT_PARITY_GRP 0x09
133 #define PGM_OPT_CURR_TGSIZE 0x0A
134 #define PGM_OPT_NBR_UNREACH 0x0B
135 #define PGM_OPT_PATH_NLA 0x0C
137 #define PGM_OPT_SYN 0x0D
138 #define PGM_OPT_FIN 0x0E
139 #define PGM_OPT_RST 0x0F
140 #define PGM_OPT_CR 0x10
141 #define PGM_OPT_CRQST 0x11
143 #define PGM_OPT_PGMCC_DATA 0x12
144 #define PGM_OPT_PGMCC_FEEDBACK 0x13
146 #define PGM_OPT_MASK 0x7f
148 #define PGM_OPT_END 0x80 /* end of options marker */
150 #define PGM_MIN_OPT_LEN 4
158 pgm_print(register const u_char
*bp
, register u_int length
,
159 register const u_char
*bp2
)
161 register const struct pgm_header
*pgm
;
162 register const struct ip
*ip
;
164 u_int16_t sport
, dport
;
169 char nla_buf
[INET6_ADDRSTRLEN
];
170 register const struct ip6_hdr
*ip6
;
172 char nla_buf
[INET_ADDRSTRLEN
];
174 u_int8_t opt_type
, opt_len
, flags1
, flags2
;
175 u_int32_t seq
, opts_len
, len
, offset
;
177 pgm
= (struct pgm_header
*)bp
;
178 ip
= (struct ip
*)bp2
;
181 ip6
= (struct ip6_hdr
*)bp2
;
186 (void)printf("Can't handle IPv6");
191 if (!TTEST(pgm
->pgm_dport
)) {
194 (void)printf("%s > %s: [|pgm]",
195 ip6addr_string(&ip6
->ip6_src
),
196 ip6addr_string(&ip6
->ip6_dst
));
201 (void)printf("%s > %s: [|pgm]",
202 ipaddr_string(&ip
->ip_src
),
203 ipaddr_string(&ip
->ip_dst
));
208 sport
= EXTRACT_16BITS(&pgm
->pgm_sport
);
209 dport
= EXTRACT_16BITS(&pgm
->pgm_dport
);
213 if (ip6
->ip6_nxt
== IPPROTO_PGM
) {
214 (void)printf("%s.%s > %s.%s: ",
215 ip6addr_string(&ip6
->ip6_src
),
216 tcpport_string(sport
),
217 ip6addr_string(&ip6
->ip6_dst
),
218 tcpport_string(dport
));
220 (void)printf("%s > %s: ",
221 tcpport_string(sport
), tcpport_string(dport
));
226 if (ip
->ip_p
== IPPROTO_PGM
) {
227 (void)printf("%s.%s > %s.%s: ",
228 ipaddr_string(&ip
->ip_src
),
229 tcpport_string(sport
),
230 ipaddr_string(&ip
->ip_dst
),
231 tcpport_string(dport
));
233 (void)printf("%s > %s: ",
234 tcpport_string(sport
), tcpport_string(dport
));
240 (void)printf("PGM, length %u", pgm
->pgm_length
);
245 if (length
> pgm
->pgm_length
)
246 length
= pgm
->pgm_length
;
248 (void)printf(" 0x%02x%02x%02x%02x%02x%02x ",
255 switch (pgm
->pgm_type
) {
259 spm
= (struct pgm_spm
*)(pgm
+ 1);
262 switch (EXTRACT_16BITS(&spm
->pgms_nla_afi
)) {
264 addr_size
= sizeof(struct in_addr
);
269 addr_size
= sizeof(struct in6_addr
);
277 bp
= (u_char
*) (spm
+ 1);
278 TCHECK2(*bp
, addr_size
);
282 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
283 (void)printf("SPM seq %u trail %u lead %u nla %s",
284 EXTRACT_32BITS(&spm
->pgms_seq
),
285 EXTRACT_32BITS(&spm
->pgms_trailseq
),
286 EXTRACT_32BITS(&spm
->pgms_leadseq
),
292 struct pgm_poll
*poll
;
294 poll
= (struct pgm_poll
*)(pgm
+ 1);
296 (void)printf("POLL seq %u round %u",
297 EXTRACT_32BITS(&poll
->pgmp_seq
),
298 EXTRACT_16BITS(&poll
->pgmp_round
));
299 bp
= (u_char
*) (poll
+ 1);
303 struct pgm_polr
*polr
;
304 u_int32_t ivl
, rnd
, mask
;
306 polr
= (struct pgm_polr
*)(pgm
+ 1);
309 switch (EXTRACT_16BITS(&polr
->pgmp_nla_afi
)) {
311 addr_size
= sizeof(struct in_addr
);
316 addr_size
= sizeof(struct in6_addr
);
324 bp
= (u_char
*) (polr
+ 1);
325 TCHECK2(*bp
, addr_size
);
329 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
331 TCHECK2(*bp
, sizeof(u_int32_t
));
332 ivl
= EXTRACT_32BITS(bp
);
333 bp
+= sizeof(u_int32_t
);
335 TCHECK2(*bp
, sizeof(u_int32_t
));
336 rnd
= EXTRACT_32BITS(bp
);
337 bp
+= sizeof(u_int32_t
);
339 TCHECK2(*bp
, sizeof(u_int32_t
));
340 mask
= EXTRACT_32BITS(bp
);
341 bp
+= sizeof(u_int32_t
);
343 (void)printf("POLR seq %u round %u nla %s ivl %u rnd 0x%08x "
344 "mask 0x%08x", EXTRACT_32BITS(&polr
->pgmp_seq
),
345 EXTRACT_16BITS(&polr
->pgmp_round
), nla_buf
, ivl
, rnd
, mask
);
349 struct pgm_data
*odata
;
351 odata
= (struct pgm_data
*)(pgm
+ 1);
353 (void)printf("ODATA trail %u seq %u",
354 EXTRACT_32BITS(&odata
->pgmd_trailseq
),
355 EXTRACT_32BITS(&odata
->pgmd_seq
));
356 bp
= (u_char
*) (odata
+ 1);
361 struct pgm_data
*rdata
;
363 rdata
= (struct pgm_data
*)(pgm
+ 1);
365 (void)printf("RDATA trail %u seq %u",
366 EXTRACT_32BITS(&rdata
->pgmd_trailseq
),
367 EXTRACT_32BITS(&rdata
->pgmd_seq
));
368 bp
= (u_char
*) (rdata
+ 1);
376 const void *source
, *group
;
377 int source_af
, group_af
;
379 char source_buf
[INET6_ADDRSTRLEN
], group_buf
[INET6_ADDRSTRLEN
];
381 char source_buf
[INET_ADDRSTRLEN
], group_buf
[INET_ADDRSTRLEN
];
384 nak
= (struct pgm_nak
*)(pgm
+ 1);
388 * Skip past the source, saving info along the way
389 * and stopping if we don't have enough.
391 switch (EXTRACT_16BITS(&nak
->pgmn_source_afi
)) {
393 addr_size
= sizeof(struct in_addr
);
398 addr_size
= sizeof(struct in6_addr
);
399 source_af
= AF_INET6
;
406 bp
= (u_char
*) (nak
+ 1);
407 TCHECK2(*bp
, addr_size
);
412 * Skip past the group, saving info along the way
413 * and stopping if we don't have enough.
415 switch (EXTRACT_16BITS(bp
)) {
417 addr_size
= sizeof(struct in_addr
);
422 addr_size
= sizeof(struct in6_addr
);
430 bp
+= (2 * sizeof(u_int16_t
));
431 TCHECK2(*bp
, addr_size
);
436 * Options decoding can go here.
438 inet_ntop(source_af
, source
, source_buf
, sizeof(source_buf
));
439 inet_ntop(group_af
, group
, group_buf
, sizeof(group_buf
));
440 switch (pgm
->pgm_type
) {
442 (void)printf("NAK ");
445 (void)printf("NNAK ");
448 (void)printf("NCF ");
453 (void)printf("(%s -> %s), seq %u",
454 source_buf
, group_buf
, EXTRACT_32BITS(&nak
->pgmn_seq
));
461 ack
= (struct pgm_ack
*)(pgm
+ 1);
463 (void)printf("ACK seq %u",
464 EXTRACT_32BITS(&ack
->pgma_rx_max_seq
));
465 bp
= (u_char
*) (ack
+ 1);
470 (void)printf("SPMR");
474 (void)printf("UNKNOWN type 0x%02x", pgm
->pgm_type
);
478 if (pgm
->pgm_options
& PGM_OPT_BIT_PRESENT
) {
481 * make sure there's enough for the first option header
483 if (!TTEST2(*bp
, PGM_MIN_OPT_LEN
)) {
484 (void)printf("[|OPT]");
489 * That option header MUST be an OPT_LENGTH option
490 * (see the first paragraph of section 9.1 in RFC 3208).
493 if ((opt_type
& PGM_OPT_MASK
) != PGM_OPT_LENGTH
) {
494 (void)printf("[First option bad, should be PGM_OPT_LENGTH, is %u]", opt_type
& PGM_OPT_MASK
);
499 (void)printf("[Bad OPT_LENGTH option, length %u != 4]", opt_len
);
502 opts_len
= EXTRACT_16BITS(bp
);
504 (void)printf("[Bad total option length %u < 4]", opts_len
);
507 bp
+= sizeof(u_int16_t
);
508 (void)printf(" OPTS LEN %d", opts_len
);
512 if (opts_len
< PGM_MIN_OPT_LEN
) {
513 (void)printf("[Total option length leaves no room for final option]");
518 if (opt_len
< PGM_MIN_OPT_LEN
) {
519 (void)printf("[Bad option, length %u < %u]", opt_len
,
523 if (opts_len
< opt_len
) {
524 (void)printf("[Total option length leaves no room for final option]");
527 if (!TTEST2(*bp
, opt_len
- 2)) {
528 (void)printf(" [|OPT]");
532 switch (opt_type
& PGM_OPT_MASK
) {
535 (void)printf("[Bad OPT_LENGTH option, length %u != 4]", opt_len
);
538 (void)printf(" OPTS LEN (extra?) %d", EXTRACT_16BITS(bp
));
539 bp
+= sizeof(u_int16_t
);
543 case PGM_OPT_FRAGMENT
:
545 (void)printf("[Bad OPT_FRAGMENT option, length %u != 16]", opt_len
);
550 seq
= EXTRACT_32BITS(bp
);
551 bp
+= sizeof(u_int32_t
);
552 offset
= EXTRACT_32BITS(bp
);
553 bp
+= sizeof(u_int32_t
);
554 len
= EXTRACT_32BITS(bp
);
555 bp
+= sizeof(u_int32_t
);
556 (void)printf(" FRAG seq %u off %u len %u", seq
, offset
, len
);
560 case PGM_OPT_NAK_LIST
:
563 opt_len
-= sizeof(u_int32_t
); /* option header */
564 (void)printf(" NAK LIST");
566 if (opt_len
< sizeof(u_int32_t
)) {
567 (void)printf("[Option length not a multiple of 4]");
570 TCHECK2(*bp
, sizeof(u_int32_t
));
571 (void)printf(" %u", EXTRACT_32BITS(bp
));
572 bp
+= sizeof(u_int32_t
);
573 opt_len
-= sizeof(u_int32_t
);
574 opts_len
-= sizeof(u_int32_t
);
580 (void)printf("[Bad OPT_JOIN option, length %u != 8]", opt_len
);
585 seq
= EXTRACT_32BITS(bp
);
586 bp
+= sizeof(u_int32_t
);
587 (void)printf(" JOIN %u", seq
);
591 case PGM_OPT_NAK_BO_IVL
:
593 (void)printf("[Bad OPT_NAK_BO_IVL option, length %u != 12]", opt_len
);
598 offset
= EXTRACT_32BITS(bp
);
599 bp
+= sizeof(u_int32_t
);
600 seq
= EXTRACT_32BITS(bp
);
601 bp
+= sizeof(u_int32_t
);
602 (void)printf(" BACKOFF ivl %u ivlseq %u", offset
, seq
);
606 case PGM_OPT_NAK_BO_RNG
:
608 (void)printf("[Bad OPT_NAK_BO_RNG option, length %u != 12]", opt_len
);
613 offset
= EXTRACT_32BITS(bp
);
614 bp
+= sizeof(u_int32_t
);
615 seq
= EXTRACT_32BITS(bp
);
616 bp
+= sizeof(u_int32_t
);
617 (void)printf(" BACKOFF max %u min %u", offset
, seq
);
621 case PGM_OPT_REDIRECT
:
624 switch (EXTRACT_16BITS(bp
)) {
626 addr_size
= sizeof(struct in_addr
);
631 addr_size
= sizeof(struct in6_addr
);
639 bp
+= (2 * sizeof(u_int16_t
));
640 if (opt_len
!= 4 + addr_size
) {
641 (void)printf("[Bad OPT_REDIRECT option, length %u != 4 + address size]", opt_len
);
644 TCHECK2(*bp
, addr_size
);
648 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
649 (void)printf(" REDIRECT %s", (char *)nla
);
650 opts_len
-= 4 + addr_size
;
653 case PGM_OPT_PARITY_PRM
:
655 (void)printf("[Bad OPT_PARITY_PRM option, length %u != 8]", opt_len
);
660 len
= EXTRACT_32BITS(bp
);
661 bp
+= sizeof(u_int32_t
);
662 (void)printf(" PARITY MAXTGS %u", len
);
666 case PGM_OPT_PARITY_GRP
:
668 (void)printf("[Bad OPT_PARITY_GRP option, length %u != 8]", opt_len
);
673 seq
= EXTRACT_32BITS(bp
);
674 bp
+= sizeof(u_int32_t
);
675 (void)printf(" PARITY GROUP %u", seq
);
679 case PGM_OPT_CURR_TGSIZE
:
681 (void)printf("[Bad OPT_CURR_TGSIZE option, length %u != 8]", opt_len
);
686 len
= EXTRACT_32BITS(bp
);
687 bp
+= sizeof(u_int32_t
);
688 (void)printf(" PARITY ATGS %u", len
);
692 case PGM_OPT_NBR_UNREACH
:
694 (void)printf("[Bad OPT_NBR_UNREACH option, length %u != 4]", opt_len
);
699 (void)printf(" NBR_UNREACH");
703 case PGM_OPT_PATH_NLA
:
704 (void)printf(" PATH_NLA [%d]", opt_len
);
711 (void)printf("[Bad OPT_SYN option, length %u != 4]", opt_len
);
716 (void)printf(" SYN");
722 (void)printf("[Bad OPT_FIN option, length %u != 4]", opt_len
);
727 (void)printf(" FIN");
733 (void)printf("[Bad OPT_RST option, length %u != 4]", opt_len
);
738 (void)printf(" RST");
750 (void)printf("[Bad OPT_CRQST option, length %u != 4]", opt_len
);
755 (void)printf(" CRQST");
759 case PGM_OPT_PGMCC_DATA
:
762 offset
= EXTRACT_32BITS(bp
);
763 bp
+= sizeof(u_int32_t
);
764 switch (EXTRACT_16BITS(bp
)) {
766 addr_size
= sizeof(struct in_addr
);
771 addr_size
= sizeof(struct in6_addr
);
779 bp
+= (2 * sizeof(u_int16_t
));
780 if (opt_len
!= 12 + addr_size
) {
781 (void)printf("[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len
);
784 TCHECK2(*bp
, addr_size
);
788 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
789 (void)printf(" PGMCC DATA %u %s", offset
, (char*)nla
);
793 case PGM_OPT_PGMCC_FEEDBACK
:
796 offset
= EXTRACT_32BITS(bp
);
797 bp
+= sizeof(u_int32_t
);
798 switch (EXTRACT_16BITS(bp
)) {
800 addr_size
= sizeof(struct in_addr
);
805 addr_size
= sizeof(struct in6_addr
);
813 bp
+= (2 * sizeof(u_int16_t
));
814 if (opt_len
!= 12 + addr_size
) {
815 (void)printf("[Bad OPT_PGMCC_FEEDBACK option, length %u != 12 + address size]", opt_len
);
818 TCHECK2(*bp
, addr_size
);
822 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
823 (void)printf(" PGMCC FEEDBACK %u %s", offset
, (char*)nla
);
828 (void)printf(" OPT_%02X [%d] ", opt_type
, opt_len
);
834 if (opt_type
& PGM_OPT_END
)
839 (void)printf(" [%u]", EXTRACT_16BITS(&pgm
->pgm_length
));
844 fputs("[|pgm]", stdout
);