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)
20 #include <tcpdump-stdinc.h>
26 #include "interface.h"
28 #include "addrtoname.h"
37 * PGM header (RFC 3208)
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]; */
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]; */
71 u_int32_t pgma_rx_max_seq
;
72 u_int32_t pgma_bitmap
;
79 u_int16_t pgmp_reserved
;
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]; */
95 u_int32_t pgmd_trailseq
;
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 */
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
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
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
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
138 #define PGM_OPT_PGMCC_DATA 0x12
139 #define PGM_OPT_PGMCC_FEEDBACK 0x13
141 #define PGM_OPT_MASK 0x7f
143 #define PGM_OPT_END 0x80 /* end of options marker */
145 #define PGM_MIN_OPT_LEN 4
153 pgm_print(register const u_char
*bp
, register u_int length
,
154 register const u_char
*bp2
)
156 register const struct pgm_header
*pgm
;
157 register const struct ip
*ip
;
159 u_int16_t sport
, dport
;
164 char nla_buf
[INET6_ADDRSTRLEN
];
165 register const struct ip6_hdr
*ip6
;
167 char nla_buf
[INET_ADDRSTRLEN
];
169 u_int8_t opt_type
, opt_len
;
170 u_int32_t seq
, opts_len
, len
, offset
;
172 pgm
= (struct pgm_header
*)bp
;
173 ip
= (struct ip
*)bp2
;
176 ip6
= (struct ip6_hdr
*)bp2
;
181 (void)printf("Can't handle IPv6");
186 if (!TTEST(pgm
->pgm_dport
)) {
189 (void)printf("%s > %s: [|pgm]",
190 ip6addr_string(&ip6
->ip6_src
),
191 ip6addr_string(&ip6
->ip6_dst
));
196 (void)printf("%s > %s: [|pgm]",
197 ipaddr_string(&ip
->ip_src
),
198 ipaddr_string(&ip
->ip_dst
));
203 sport
= EXTRACT_16BITS(&pgm
->pgm_sport
);
204 dport
= EXTRACT_16BITS(&pgm
->pgm_dport
);
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
));
215 (void)printf("%s > %s: ",
216 tcpport_string(sport
), tcpport_string(dport
));
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
));
228 (void)printf("%s > %s: ",
229 tcpport_string(sport
), tcpport_string(dport
));
235 (void)printf("PGM, length %u", EXTRACT_16BITS(&pgm
->pgm_length
));
240 (void)printf(" 0x%02x%02x%02x%02x%02x%02x ",
247 switch (pgm
->pgm_type
) {
251 spm
= (struct pgm_spm
*)(pgm
+ 1);
254 switch (EXTRACT_16BITS(&spm
->pgms_nla_afi
)) {
256 addr_size
= sizeof(struct in_addr
);
261 addr_size
= sizeof(struct in6_addr
);
269 bp
= (u_char
*) (spm
+ 1);
270 TCHECK2(*bp
, addr_size
);
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
),
284 struct pgm_poll
*poll
;
286 poll
= (struct pgm_poll
*)(pgm
+ 1);
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);
295 struct pgm_polr
*polr
;
296 u_int32_t ivl
, rnd
, mask
;
298 polr
= (struct pgm_polr
*)(pgm
+ 1);
301 switch (EXTRACT_16BITS(&polr
->pgmp_nla_afi
)) {
303 addr_size
= sizeof(struct in_addr
);
308 addr_size
= sizeof(struct in6_addr
);
316 bp
= (u_char
*) (polr
+ 1);
317 TCHECK2(*bp
, addr_size
);
321 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
323 TCHECK2(*bp
, sizeof(u_int32_t
));
324 ivl
= EXTRACT_32BITS(bp
);
325 bp
+= sizeof(u_int32_t
);
327 TCHECK2(*bp
, sizeof(u_int32_t
));
328 rnd
= EXTRACT_32BITS(bp
);
329 bp
+= sizeof(u_int32_t
);
331 TCHECK2(*bp
, sizeof(u_int32_t
));
332 mask
= EXTRACT_32BITS(bp
);
333 bp
+= sizeof(u_int32_t
);
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
);
341 struct pgm_data
*odata
;
343 odata
= (struct pgm_data
*)(pgm
+ 1);
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);
353 struct pgm_data
*rdata
;
355 rdata
= (struct pgm_data
*)(pgm
+ 1);
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);
368 const void *source
, *group
;
369 int source_af
, group_af
;
371 char source_buf
[INET6_ADDRSTRLEN
], group_buf
[INET6_ADDRSTRLEN
];
373 char source_buf
[INET_ADDRSTRLEN
], group_buf
[INET_ADDRSTRLEN
];
376 nak
= (struct pgm_nak
*)(pgm
+ 1);
380 * Skip past the source, saving info along the way
381 * and stopping if we don't have enough.
383 switch (EXTRACT_16BITS(&nak
->pgmn_source_afi
)) {
385 addr_size
= sizeof(struct in_addr
);
390 addr_size
= sizeof(struct in6_addr
);
391 source_af
= AF_INET6
;
398 bp
= (u_char
*) (nak
+ 1);
399 TCHECK2(*bp
, addr_size
);
404 * Skip past the group, saving info along the way
405 * and stopping if we don't have enough.
407 switch (EXTRACT_16BITS(bp
)) {
409 addr_size
= sizeof(struct in_addr
);
414 addr_size
= sizeof(struct in6_addr
);
422 bp
+= (2 * sizeof(u_int16_t
));
423 TCHECK2(*bp
, addr_size
);
428 * Options decoding can go here.
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
) {
434 (void)printf("NAK ");
437 (void)printf("NNAK ");
440 (void)printf("NCF ");
445 (void)printf("(%s -> %s), seq %u",
446 source_buf
, group_buf
, EXTRACT_32BITS(&nak
->pgmn_seq
));
453 ack
= (struct pgm_ack
*)(pgm
+ 1);
455 (void)printf("ACK seq %u",
456 EXTRACT_32BITS(&ack
->pgma_rx_max_seq
));
457 bp
= (u_char
*) (ack
+ 1);
462 (void)printf("SPMR");
466 (void)printf("UNKNOWN type 0x%02x", pgm
->pgm_type
);
470 if (pgm
->pgm_options
& PGM_OPT_BIT_PRESENT
) {
473 * make sure there's enough for the first option header
475 if (!TTEST2(*bp
, PGM_MIN_OPT_LEN
)) {
476 (void)printf("[|OPT]");
481 * That option header MUST be an OPT_LENGTH option
482 * (see the first paragraph of section 9.1 in RFC 3208).
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
);
491 (void)printf("[Bad OPT_LENGTH option, length %u != 4]", opt_len
);
494 opts_len
= EXTRACT_16BITS(bp
);
496 (void)printf("[Bad total option length %u < 4]", opts_len
);
499 bp
+= sizeof(u_int16_t
);
500 (void)printf(" OPTS LEN %d", opts_len
);
504 if (opts_len
< PGM_MIN_OPT_LEN
) {
505 (void)printf("[Total option length leaves no room for final option]");
510 if (opt_len
< PGM_MIN_OPT_LEN
) {
511 (void)printf("[Bad option, length %u < %u]", opt_len
,
515 if (opts_len
< opt_len
) {
516 (void)printf("[Total option length leaves no room for final option]");
519 if (!TTEST2(*bp
, opt_len
- 2)) {
520 (void)printf(" [|OPT]");
524 switch (opt_type
& PGM_OPT_MASK
) {
527 (void)printf("[Bad OPT_LENGTH option, length %u != 4]", opt_len
);
530 (void)printf(" OPTS LEN (extra?) %d", EXTRACT_16BITS(bp
));
531 bp
+= sizeof(u_int16_t
);
535 case PGM_OPT_FRAGMENT
:
537 (void)printf("[Bad OPT_FRAGMENT option, length %u != 16]", opt_len
);
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
);
551 case PGM_OPT_NAK_LIST
:
553 opt_len
-= sizeof(u_int32_t
); /* option header */
554 (void)printf(" NAK LIST");
556 if (opt_len
< sizeof(u_int32_t
)) {
557 (void)printf("[Option length not a multiple of 4]");
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
);
570 (void)printf("[Bad OPT_JOIN option, length %u != 8]", opt_len
);
574 seq
= EXTRACT_32BITS(bp
);
575 bp
+= sizeof(u_int32_t
);
576 (void)printf(" JOIN %u", seq
);
580 case PGM_OPT_NAK_BO_IVL
:
582 (void)printf("[Bad OPT_NAK_BO_IVL option, length %u != 12]", opt_len
);
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
);
594 case PGM_OPT_NAK_BO_RNG
:
596 (void)printf("[Bad OPT_NAK_BO_RNG option, length %u != 12]", opt_len
);
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
);
608 case PGM_OPT_REDIRECT
:
610 switch (EXTRACT_16BITS(bp
)) {
612 addr_size
= sizeof(struct in_addr
);
617 addr_size
= sizeof(struct in6_addr
);
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
);
630 TCHECK2(*bp
, addr_size
);
634 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
635 (void)printf(" REDIRECT %s", (char *)nla
);
636 opts_len
-= 4 + addr_size
;
639 case PGM_OPT_PARITY_PRM
:
641 (void)printf("[Bad OPT_PARITY_PRM option, length %u != 8]", opt_len
);
645 len
= EXTRACT_32BITS(bp
);
646 bp
+= sizeof(u_int32_t
);
647 (void)printf(" PARITY MAXTGS %u", len
);
651 case PGM_OPT_PARITY_GRP
:
653 (void)printf("[Bad OPT_PARITY_GRP option, length %u != 8]", opt_len
);
657 seq
= EXTRACT_32BITS(bp
);
658 bp
+= sizeof(u_int32_t
);
659 (void)printf(" PARITY GROUP %u", seq
);
663 case PGM_OPT_CURR_TGSIZE
:
665 (void)printf("[Bad OPT_CURR_TGSIZE option, length %u != 8]", opt_len
);
669 len
= EXTRACT_32BITS(bp
);
670 bp
+= sizeof(u_int32_t
);
671 (void)printf(" PARITY ATGS %u", len
);
675 case PGM_OPT_NBR_UNREACH
:
677 (void)printf("[Bad OPT_NBR_UNREACH option, length %u != 4]", opt_len
);
681 (void)printf(" NBR_UNREACH");
685 case PGM_OPT_PATH_NLA
:
686 (void)printf(" PATH_NLA [%d]", opt_len
);
693 (void)printf("[Bad OPT_SYN option, length %u != 4]", opt_len
);
697 (void)printf(" SYN");
703 (void)printf("[Bad OPT_FIN option, length %u != 4]", opt_len
);
707 (void)printf(" FIN");
713 (void)printf("[Bad OPT_RST option, length %u != 4]", opt_len
);
717 (void)printf(" RST");
729 (void)printf("[Bad OPT_CRQST option, length %u != 4]", opt_len
);
733 (void)printf(" CRQST");
737 case PGM_OPT_PGMCC_DATA
:
739 offset
= EXTRACT_32BITS(bp
);
740 bp
+= sizeof(u_int32_t
);
741 switch (EXTRACT_16BITS(bp
)) {
743 addr_size
= sizeof(struct in_addr
);
748 addr_size
= sizeof(struct in6_addr
);
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
);
761 TCHECK2(*bp
, addr_size
);
765 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
766 (void)printf(" PGMCC DATA %u %s", offset
, (char*)nla
);
770 case PGM_OPT_PGMCC_FEEDBACK
:
772 offset
= EXTRACT_32BITS(bp
);
773 bp
+= sizeof(u_int32_t
);
774 switch (EXTRACT_16BITS(bp
)) {
776 addr_size
= sizeof(struct in_addr
);
781 addr_size
= sizeof(struct in6_addr
);
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
);
794 TCHECK2(*bp
, addr_size
);
798 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
799 (void)printf(" PGMCC FEEDBACK %u %s", offset
, (char*)nla
);
804 (void)printf(" OPT_%02X [%d] ", opt_type
, opt_len
);
810 if (opt_type
& PGM_OPT_END
)
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
));
823 fputs("[|pgm]", stdout
);