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", EXTRACT_16BITS(&pgm
->pgm_length
));
245 (void)printf(" 0x%02x%02x%02x%02x%02x%02x ",
252 switch (pgm
->pgm_type
) {
256 spm
= (struct pgm_spm
*)(pgm
+ 1);
259 switch (EXTRACT_16BITS(&spm
->pgms_nla_afi
)) {
261 addr_size
= sizeof(struct in_addr
);
266 addr_size
= sizeof(struct in6_addr
);
274 bp
= (u_char
*) (spm
+ 1);
275 TCHECK2(*bp
, addr_size
);
279 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
280 (void)printf("SPM seq %u trail %u lead %u nla %s",
281 EXTRACT_32BITS(&spm
->pgms_seq
),
282 EXTRACT_32BITS(&spm
->pgms_trailseq
),
283 EXTRACT_32BITS(&spm
->pgms_leadseq
),
289 struct pgm_poll
*poll
;
291 poll
= (struct pgm_poll
*)(pgm
+ 1);
293 (void)printf("POLL seq %u round %u",
294 EXTRACT_32BITS(&poll
->pgmp_seq
),
295 EXTRACT_16BITS(&poll
->pgmp_round
));
296 bp
= (u_char
*) (poll
+ 1);
300 struct pgm_polr
*polr
;
301 u_int32_t ivl
, rnd
, mask
;
303 polr
= (struct pgm_polr
*)(pgm
+ 1);
306 switch (EXTRACT_16BITS(&polr
->pgmp_nla_afi
)) {
308 addr_size
= sizeof(struct in_addr
);
313 addr_size
= sizeof(struct in6_addr
);
321 bp
= (u_char
*) (polr
+ 1);
322 TCHECK2(*bp
, addr_size
);
326 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
328 TCHECK2(*bp
, sizeof(u_int32_t
));
329 ivl
= EXTRACT_32BITS(bp
);
330 bp
+= sizeof(u_int32_t
);
332 TCHECK2(*bp
, sizeof(u_int32_t
));
333 rnd
= EXTRACT_32BITS(bp
);
334 bp
+= sizeof(u_int32_t
);
336 TCHECK2(*bp
, sizeof(u_int32_t
));
337 mask
= EXTRACT_32BITS(bp
);
338 bp
+= sizeof(u_int32_t
);
340 (void)printf("POLR seq %u round %u nla %s ivl %u rnd 0x%08x "
341 "mask 0x%08x", EXTRACT_32BITS(&polr
->pgmp_seq
),
342 EXTRACT_16BITS(&polr
->pgmp_round
), nla_buf
, ivl
, rnd
, mask
);
346 struct pgm_data
*odata
;
348 odata
= (struct pgm_data
*)(pgm
+ 1);
350 (void)printf("ODATA trail %u seq %u",
351 EXTRACT_32BITS(&odata
->pgmd_trailseq
),
352 EXTRACT_32BITS(&odata
->pgmd_seq
));
353 bp
= (u_char
*) (odata
+ 1);
358 struct pgm_data
*rdata
;
360 rdata
= (struct pgm_data
*)(pgm
+ 1);
362 (void)printf("RDATA trail %u seq %u",
363 EXTRACT_32BITS(&rdata
->pgmd_trailseq
),
364 EXTRACT_32BITS(&rdata
->pgmd_seq
));
365 bp
= (u_char
*) (rdata
+ 1);
373 const void *source
, *group
;
374 int source_af
, group_af
;
376 char source_buf
[INET6_ADDRSTRLEN
], group_buf
[INET6_ADDRSTRLEN
];
378 char source_buf
[INET_ADDRSTRLEN
], group_buf
[INET_ADDRSTRLEN
];
381 nak
= (struct pgm_nak
*)(pgm
+ 1);
385 * Skip past the source, saving info along the way
386 * and stopping if we don't have enough.
388 switch (EXTRACT_16BITS(&nak
->pgmn_source_afi
)) {
390 addr_size
= sizeof(struct in_addr
);
395 addr_size
= sizeof(struct in6_addr
);
396 source_af
= AF_INET6
;
403 bp
= (u_char
*) (nak
+ 1);
404 TCHECK2(*bp
, addr_size
);
409 * Skip past the group, saving info along the way
410 * and stopping if we don't have enough.
412 switch (EXTRACT_16BITS(bp
)) {
414 addr_size
= sizeof(struct in_addr
);
419 addr_size
= sizeof(struct in6_addr
);
427 bp
+= (2 * sizeof(u_int16_t
));
428 TCHECK2(*bp
, addr_size
);
433 * Options decoding can go here.
435 inet_ntop(source_af
, source
, source_buf
, sizeof(source_buf
));
436 inet_ntop(group_af
, group
, group_buf
, sizeof(group_buf
));
437 switch (pgm
->pgm_type
) {
439 (void)printf("NAK ");
442 (void)printf("NNAK ");
445 (void)printf("NCF ");
450 (void)printf("(%s -> %s), seq %u",
451 source_buf
, group_buf
, EXTRACT_32BITS(&nak
->pgmn_seq
));
458 ack
= (struct pgm_ack
*)(pgm
+ 1);
460 (void)printf("ACK seq %u",
461 EXTRACT_32BITS(&ack
->pgma_rx_max_seq
));
462 bp
= (u_char
*) (ack
+ 1);
467 (void)printf("SPMR");
471 (void)printf("UNKNOWN type 0x%02x", pgm
->pgm_type
);
475 if (pgm
->pgm_options
& PGM_OPT_BIT_PRESENT
) {
478 * make sure there's enough for the first option header
480 if (!TTEST2(*bp
, PGM_MIN_OPT_LEN
)) {
481 (void)printf("[|OPT]");
486 * That option header MUST be an OPT_LENGTH option
487 * (see the first paragraph of section 9.1 in RFC 3208).
490 if ((opt_type
& PGM_OPT_MASK
) != PGM_OPT_LENGTH
) {
491 (void)printf("[First option bad, should be PGM_OPT_LENGTH, is %u]", opt_type
& PGM_OPT_MASK
);
496 (void)printf("[Bad OPT_LENGTH option, length %u != 4]", opt_len
);
499 opts_len
= EXTRACT_16BITS(bp
);
501 (void)printf("[Bad total option length %u < 4]", opts_len
);
504 bp
+= sizeof(u_int16_t
);
505 (void)printf(" OPTS LEN %d", opts_len
);
509 if (opts_len
< PGM_MIN_OPT_LEN
) {
510 (void)printf("[Total option length leaves no room for final option]");
515 if (opt_len
< PGM_MIN_OPT_LEN
) {
516 (void)printf("[Bad option, length %u < %u]", opt_len
,
520 if (opts_len
< opt_len
) {
521 (void)printf("[Total option length leaves no room for final option]");
524 if (!TTEST2(*bp
, opt_len
- 2)) {
525 (void)printf(" [|OPT]");
529 switch (opt_type
& PGM_OPT_MASK
) {
532 (void)printf("[Bad OPT_LENGTH option, length %u != 4]", opt_len
);
535 (void)printf(" OPTS LEN (extra?) %d", EXTRACT_16BITS(bp
));
536 bp
+= sizeof(u_int16_t
);
540 case PGM_OPT_FRAGMENT
:
542 (void)printf("[Bad OPT_FRAGMENT option, length %u != 16]", opt_len
);
547 seq
= EXTRACT_32BITS(bp
);
548 bp
+= sizeof(u_int32_t
);
549 offset
= EXTRACT_32BITS(bp
);
550 bp
+= sizeof(u_int32_t
);
551 len
= EXTRACT_32BITS(bp
);
552 bp
+= sizeof(u_int32_t
);
553 (void)printf(" FRAG seq %u off %u len %u", seq
, offset
, len
);
557 case PGM_OPT_NAK_LIST
:
560 opt_len
-= sizeof(u_int32_t
); /* option header */
561 (void)printf(" NAK LIST");
563 if (opt_len
< sizeof(u_int32_t
)) {
564 (void)printf("[Option length not a multiple of 4]");
567 TCHECK2(*bp
, sizeof(u_int32_t
));
568 (void)printf(" %u", EXTRACT_32BITS(bp
));
569 bp
+= sizeof(u_int32_t
);
570 opt_len
-= sizeof(u_int32_t
);
571 opts_len
-= sizeof(u_int32_t
);
577 (void)printf("[Bad OPT_JOIN option, length %u != 8]", opt_len
);
582 seq
= EXTRACT_32BITS(bp
);
583 bp
+= sizeof(u_int32_t
);
584 (void)printf(" JOIN %u", seq
);
588 case PGM_OPT_NAK_BO_IVL
:
590 (void)printf("[Bad OPT_NAK_BO_IVL option, length %u != 12]", opt_len
);
595 offset
= EXTRACT_32BITS(bp
);
596 bp
+= sizeof(u_int32_t
);
597 seq
= EXTRACT_32BITS(bp
);
598 bp
+= sizeof(u_int32_t
);
599 (void)printf(" BACKOFF ivl %u ivlseq %u", offset
, seq
);
603 case PGM_OPT_NAK_BO_RNG
:
605 (void)printf("[Bad OPT_NAK_BO_RNG option, length %u != 12]", opt_len
);
610 offset
= EXTRACT_32BITS(bp
);
611 bp
+= sizeof(u_int32_t
);
612 seq
= EXTRACT_32BITS(bp
);
613 bp
+= sizeof(u_int32_t
);
614 (void)printf(" BACKOFF max %u min %u", offset
, seq
);
618 case PGM_OPT_REDIRECT
:
621 switch (EXTRACT_16BITS(bp
)) {
623 addr_size
= sizeof(struct in_addr
);
628 addr_size
= sizeof(struct in6_addr
);
636 bp
+= (2 * sizeof(u_int16_t
));
637 if (opt_len
!= 4 + addr_size
) {
638 (void)printf("[Bad OPT_REDIRECT option, length %u != 4 + address size]", opt_len
);
641 TCHECK2(*bp
, addr_size
);
645 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
646 (void)printf(" REDIRECT %s", (char *)nla
);
647 opts_len
-= 4 + addr_size
;
650 case PGM_OPT_PARITY_PRM
:
652 (void)printf("[Bad OPT_PARITY_PRM option, length %u != 8]", opt_len
);
657 len
= EXTRACT_32BITS(bp
);
658 bp
+= sizeof(u_int32_t
);
659 (void)printf(" PARITY MAXTGS %u", len
);
663 case PGM_OPT_PARITY_GRP
:
665 (void)printf("[Bad OPT_PARITY_GRP option, length %u != 8]", opt_len
);
670 seq
= EXTRACT_32BITS(bp
);
671 bp
+= sizeof(u_int32_t
);
672 (void)printf(" PARITY GROUP %u", seq
);
676 case PGM_OPT_CURR_TGSIZE
:
678 (void)printf("[Bad OPT_CURR_TGSIZE option, length %u != 8]", opt_len
);
683 len
= EXTRACT_32BITS(bp
);
684 bp
+= sizeof(u_int32_t
);
685 (void)printf(" PARITY ATGS %u", len
);
689 case PGM_OPT_NBR_UNREACH
:
691 (void)printf("[Bad OPT_NBR_UNREACH option, length %u != 4]", opt_len
);
696 (void)printf(" NBR_UNREACH");
700 case PGM_OPT_PATH_NLA
:
701 (void)printf(" PATH_NLA [%d]", opt_len
);
708 (void)printf("[Bad OPT_SYN option, length %u != 4]", opt_len
);
713 (void)printf(" SYN");
719 (void)printf("[Bad OPT_FIN option, length %u != 4]", opt_len
);
724 (void)printf(" FIN");
730 (void)printf("[Bad OPT_RST option, length %u != 4]", opt_len
);
735 (void)printf(" RST");
747 (void)printf("[Bad OPT_CRQST option, length %u != 4]", opt_len
);
752 (void)printf(" CRQST");
756 case PGM_OPT_PGMCC_DATA
:
759 offset
= EXTRACT_32BITS(bp
);
760 bp
+= sizeof(u_int32_t
);
761 switch (EXTRACT_16BITS(bp
)) {
763 addr_size
= sizeof(struct in_addr
);
768 addr_size
= sizeof(struct in6_addr
);
776 bp
+= (2 * sizeof(u_int16_t
));
777 if (opt_len
!= 12 + addr_size
) {
778 (void)printf("[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len
);
781 TCHECK2(*bp
, addr_size
);
785 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
786 (void)printf(" PGMCC DATA %u %s", offset
, (char*)nla
);
790 case PGM_OPT_PGMCC_FEEDBACK
:
793 offset
= EXTRACT_32BITS(bp
);
794 bp
+= sizeof(u_int32_t
);
795 switch (EXTRACT_16BITS(bp
)) {
797 addr_size
= sizeof(struct in_addr
);
802 addr_size
= sizeof(struct in6_addr
);
810 bp
+= (2 * sizeof(u_int16_t
));
811 if (opt_len
!= 12 + addr_size
) {
812 (void)printf("[Bad OPT_PGMCC_FEEDBACK option, length %u != 12 + address size]", opt_len
);
815 TCHECK2(*bp
, addr_size
);
819 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
820 (void)printf(" PGMCC FEEDBACK %u %s", offset
, (char*)nla
);
825 (void)printf(" OPT_%02X [%d] ", opt_type
, opt_len
);
831 if (opt_type
& PGM_OPT_END
)
836 (void)printf(" [%u]", length
);
841 fputs("[|pgm]", stdout
);