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.3 2005-05-24 07:56:23 guy Exp $";
25 #include <tcpdump-stdinc.h>
31 #include "interface.h"
33 #include "addrtoname.h"
40 * PGM header (RFC 3208)
54 u_int32_t pgms_trailseq
;
55 u_int32_t pgms_leadseq
;
56 u_int16_t pgms_nla_afi
;
57 u_int16_t pgms_reserved
;
64 u_int16_t pgmn_source_afi
;
65 u_int16_t pgmn_reserved
;
66 u_int8_t pgmn_source
[0];
67 /* ... u_int16_t pgmn_group_afi */
68 /* ... u_int16_t pgmn_reserved2; */
69 /* ... u_int8_t pgmn_group[0]; */
76 u_int16_t pgmp_reserved
;
83 u_int16_t pgmp_subtype
;
84 u_int16_t pgmp_nla_afi
;
85 u_int16_t pgmp_reserved
;
92 u_int32_t pgmd_trailseq
;
96 typedef enum _pgm_type
{
97 PGM_SPM
= 0, /* source path message */
98 PGM_POLL
= 1, /* POLL Request */
99 PGM_POLR
= 2, /* POLL Response */
100 PGM_ODATA
= 4, /* original data */
101 PGM_RDATA
= 5, /* repair data */
102 PGM_NAK
= 8, /* NAK */
103 PGM_NULLNAK
= 9, /* Null NAK */
104 PGM_NCF
= 10, /* NAK Confirmation */
105 PGM_ACK
= 11, /* ACK for congestion control */
106 PGM_SPMR
= 12, /* SPM request */
110 #define PGM_OPT_BIT_PRESENT 0x01
111 #define PGM_OPT_BIT_NETWORK 0x02
112 #define PGM_OPT_BIT_VAR_PKTLEN 0x40
113 #define PGM_OPT_BIT_PARITY 0x80
115 #define PGM_OPT_LENGTH 0x00
116 #define PGM_OPT_FRAGMENT 0x01
117 #define PGM_OPT_NAK_LIST 0x02
118 #define PGM_OPT_JOIN 0x03
119 #define PGM_OPT_NAK_BO_IVL 0x04
120 #define PGM_OPT_NAK_BO_RNG 0x05
122 #define PGM_OPT_REDIRECT 0x07
123 #define PGM_OPT_PARITY_PRM 0x08
124 #define PGM_OPT_PARITY_GRP 0x09
125 #define PGM_OPT_CURR_TGSIZE 0x0A
126 #define PGM_OPT_NBR_UNREACH 0x0B
127 #define PGM_OPT_PATH_NLA 0x0C
129 #define PGM_OPT_SYN 0x0D
130 #define PGM_OPT_FIN 0x0E
131 #define PGM_OPT_RST 0x0F
132 #define PGM_OPT_CR 0x10
133 #define PGM_OPT_CRQST 0x11
135 #define PGM_OPT_MASK 0x7f
137 #define PGM_OPT_END 0x80 /* end of options marker */
139 #define PGM_MIN_OPT_LEN 4
147 pgm_print(register const u_char
*bp
, register u_int length
,
148 register const u_char
*bp2
)
150 register const struct pgm_header
*pgm
;
151 register const struct ip
*ip
;
153 u_int16_t sport
, dport
;
157 char nla_buf
[INET6_ADDRSTRLEN
];
159 register const struct ip6_hdr
*ip6
;
161 u_int8_t opt_type
, opt_len
, flags1
, flags2
;
162 u_int32_t seq
, opts_len
, len
, offset
;
164 pgm
= (struct pgm_header
*)bp
;
165 ip
= (struct ip
*)bp2
;
168 ip6
= (struct ip6_hdr
*)bp2
;
173 if (!TTEST(pgm
->pgm_dport
)) {
176 (void)printf("%s > %s: [|pgm]",
177 ip6addr_string(&ip6
->ip6_src
),
178 ip6addr_string(&ip6
->ip6_dst
));
183 (void)printf("%s > %s: [|pgm]",
184 ipaddr_string(&ip
->ip_src
),
185 ipaddr_string(&ip
->ip_dst
));
190 sport
= EXTRACT_16BITS(&pgm
->pgm_sport
);
191 dport
= EXTRACT_16BITS(&pgm
->pgm_dport
);
195 if (ip6
->ip6_nxt
== IPPROTO_PGM
) {
196 (void)printf("%s.%s > %s.%s: ",
197 ip6addr_string(&ip6
->ip6_src
),
198 tcpport_string(sport
),
199 ip6addr_string(&ip6
->ip6_dst
),
200 tcpport_string(dport
));
202 (void)printf("%s > %s: ",
203 tcpport_string(sport
), tcpport_string(dport
));
208 if (ip
->ip_p
== IPPROTO_PGM
) {
209 (void)printf("%s.%s > %s.%s: ",
210 ipaddr_string(&ip
->ip_src
),
211 tcpport_string(sport
),
212 ipaddr_string(&ip
->ip_dst
),
213 tcpport_string(dport
));
215 (void)printf("%s > %s: ",
216 tcpport_string(sport
), tcpport_string(dport
));
222 (void)printf("PGM, length %u", pgm
->pgm_length
);
227 if (length
> pgm
->pgm_length
)
228 length
= pgm
->pgm_length
;
230 (void)printf(" 0x%02x%02x%02x%02x%02x%02x ",
237 switch (pgm
->pgm_type
) {
241 spm
= (struct pgm_spm
*)(pgm
+ 1);
244 switch (EXTRACT_16BITS(&spm
->pgms_nla_afi
)) {
246 addr_size
= sizeof(struct in_addr
);
250 addr_size
= sizeof(struct in6_addr
);
257 bp
= (u_char
*) (spm
+ 1);
258 TCHECK2(*bp
, addr_size
);
262 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
263 (void)printf("SPM seq %u trail %u lead %u nla %s",
264 EXTRACT_32BITS(&spm
->pgms_seq
),
265 EXTRACT_32BITS(&spm
->pgms_trailseq
),
266 EXTRACT_32BITS(&spm
->pgms_leadseq
),
272 struct pgm_poll
*poll
;
274 poll
= (struct pgm_poll
*)(pgm
+ 1);
276 (void)printf("POLL seq %u round %u",
277 EXTRACT_32BITS(&poll
->pgmp_seq
),
278 EXTRACT_16BITS(&poll
->pgmp_round
));
279 bp
= (u_char
*) (poll
+ 1);
283 struct pgm_polr
*polr
;
284 u_int32_t ivl
, rnd
, mask
;
286 polr
= (struct pgm_polr
*)(pgm
+ 1);
289 switch (EXTRACT_16BITS(&polr
->pgmp_nla_afi
)) {
291 addr_size
= sizeof(struct in_addr
);
295 addr_size
= sizeof(struct in6_addr
);
302 bp
= (u_char
*) (polr
+ 1);
303 TCHECK2(*bp
, addr_size
);
307 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
309 TCHECK2(*bp
, sizeof(u_int32_t
));
310 ivl
= EXTRACT_32BITS(bp
);
311 bp
+= sizeof(u_int32_t
);
313 TCHECK2(*bp
, sizeof(u_int32_t
));
314 rnd
= EXTRACT_32BITS(bp
);
315 bp
+= sizeof(u_int32_t
);
317 TCHECK2(*bp
, sizeof(u_int32_t
));
318 mask
= EXTRACT_32BITS(bp
);
319 bp
+= sizeof(u_int32_t
);
321 (void)printf("POLR seq %u round %u nla %s ivl %u rnd 0x%08x "
322 "mask 0x%08x", EXTRACT_32BITS(&polr
->pgmp_seq
),
323 EXTRACT_16BITS(&polr
->pgmp_round
), nla_buf
, ivl
, rnd
, mask
);
327 struct pgm_data
*odata
;
329 odata
= (struct pgm_data
*)(pgm
+ 1);
331 (void)printf("ODATA trail %u seq %u",
332 EXTRACT_32BITS(&odata
->pgmd_trailseq
),
333 EXTRACT_32BITS(&odata
->pgmd_seq
));
334 bp
= (u_char
*) (odata
+ 1);
339 struct pgm_data
*rdata
;
341 rdata
= (struct pgm_data
*)(pgm
+ 1);
343 (void)printf("RDATA trail %u seq %u",
344 EXTRACT_32BITS(&rdata
->pgmd_trailseq
),
345 EXTRACT_32BITS(&rdata
->pgmd_seq
));
346 bp
= (u_char
*) (rdata
+ 1);
354 const void *source
, *group
;
355 int source_af
, group_af
;
356 char source_buf
[INET6_ADDRSTRLEN
], group_buf
[INET6_ADDRSTRLEN
];
358 nak
= (struct pgm_nak
*)(pgm
+ 1);
362 * Skip past the source, saving info along the way
363 * and stopping if we don't have enough.
365 switch (EXTRACT_16BITS(&nak
->pgmn_source_afi
)) {
367 addr_size
= sizeof(struct in_addr
);
371 addr_size
= sizeof(struct in6_addr
);
372 source_af
= AF_INET6
;
378 bp
= (u_char
*) (nak
+ 1);
379 TCHECK2(*bp
, addr_size
);
384 * Skip past the group, saving info along the way
385 * and stopping if we don't have enough.
387 switch (EXTRACT_16BITS(bp
)) {
389 addr_size
= sizeof(struct in_addr
);
393 addr_size
= sizeof(struct in6_addr
);
400 bp
+= (2 * sizeof(u_int16_t
));
401 TCHECK2(*bp
, addr_size
);
406 * Options decoding can go here.
408 inet_ntop(source_af
, source
, source_buf
, sizeof(source_buf
));
409 inet_ntop(group_af
, group
, group_buf
, sizeof(group_buf
));
410 switch (pgm
->pgm_type
) {
412 (void)printf("NAK ");
415 (void)printf("NNAK ");
418 (void)printf("NCF ");
423 (void)printf("(%s -> %s), seq %u",
424 source_buf
, group_buf
, EXTRACT_32BITS(&nak
->pgmn_seq
));
429 (void)printf("SPMR");
433 (void)printf("UNKNOWN type %0x02x", pgm
->pgm_type
);
437 if (pgm
->pgm_options
& PGM_OPT_BIT_PRESENT
) {
440 * make sure there's enough for the first option header
442 if (!TTEST2(*bp
, PGM_MIN_OPT_LEN
)) {
443 (void)printf("[|OPT]");
448 * That option header MUST be an OPT_LENGTH option
449 * (see the first paragraph of section 9.1 in RFC 3208).
452 if ((opt_type
& PGM_OPT_MASK
) != PGM_OPT_LENGTH
) {
453 (void)printf("[First option bad, should be PGM_OPT_LENGTH, is %u]", opt_type
& PGM_OPT_MASK
);
458 (void)printf("[Bad OPT_LENGTH option, length %u != 4]", opt_len
);
461 opts_len
= EXTRACT_16BITS(bp
);
463 (void)printf("[Bad total option length %u < 4]", opts_len
);
466 bp
+= sizeof(u_int16_t
);
467 (void)printf(" OPTS LEN %d", opts_len
);
471 if (opts_len
< PGM_MIN_OPT_LEN
) {
472 (void)printf("[Total option length leaves no room for final option]");
477 if (opt_len
< PGM_MIN_OPT_LEN
) {
478 (void)printf("[Bad option, length %u < %u]", opt_len
,
482 if (opts_len
< opt_len
) {
483 (void)printf("[Total option length leaves no room for final option]");
486 if (!TTEST2(*bp
, opt_len
- 2)) {
487 (void)printf(" [|OPT]");
491 switch (opt_type
& PGM_OPT_MASK
) {
494 (void)printf("[Bad OPT_LENGTH option, length %u != 4]", opt_len
);
497 (void)printf(" OPTS LEN (extra?) %d", EXTRACT_16BITS(bp
));
498 bp
+= sizeof(u_int16_t
);
502 case PGM_OPT_FRAGMENT
:
504 (void)printf("[Bad OPT_FRAGMENT option, length %u != 16]", opt_len
);
509 seq
= EXTRACT_32BITS(bp
);
510 bp
+= sizeof(u_int32_t
);
511 offset
= EXTRACT_32BITS(bp
);
512 bp
+= sizeof(u_int32_t
);
513 len
= EXTRACT_32BITS(bp
);
514 bp
+= sizeof(u_int32_t
);
515 (void)printf(" FRAG seq %u off %u len %u", seq
, offset
, len
);
519 case PGM_OPT_NAK_LIST
:
522 opt_len
-= sizeof(u_int32_t
); /* option header */
523 (void)printf(" NAK LIST");
525 if (opt_len
< sizeof(u_int32_t
)) {
526 (void)printf("[Option length not a multiple of 4]");
529 TCHECK2(*bp
, sizeof(u_int32_t
));
530 (void)printf(" %u", EXTRACT_32BITS(bp
));
531 bp
+= sizeof(u_int32_t
);
532 opt_len
-= sizeof(u_int32_t
);
533 opts_len
-= sizeof(u_int32_t
);
539 (void)printf("[Bad OPT_JOIN option, length %u != 8]", opt_len
);
544 seq
= EXTRACT_32BITS(bp
);
545 bp
+= sizeof(u_int32_t
);
546 (void)printf(" JOIN %u", seq
);
550 case PGM_OPT_NAK_BO_IVL
:
552 (void)printf("[Bad OPT_NAK_BO_IVL option, length %u != 12]", opt_len
);
557 offset
= EXTRACT_32BITS(bp
);
558 bp
+= sizeof(u_int32_t
);
559 seq
= EXTRACT_32BITS(bp
);
560 bp
+= sizeof(u_int32_t
);
561 (void)printf(" BACKOFF ivl %u ivlseq %u", offset
, seq
);
565 case PGM_OPT_NAK_BO_RNG
:
567 (void)printf("[Bad OPT_NAK_BO_RNG option, length %u != 12]", opt_len
);
572 offset
= EXTRACT_32BITS(bp
);
573 bp
+= sizeof(u_int32_t
);
574 seq
= EXTRACT_32BITS(bp
);
575 bp
+= sizeof(u_int32_t
);
576 (void)printf(" BACKOFF max %u min %u", offset
, seq
);
580 case PGM_OPT_REDIRECT
:
583 switch (EXTRACT_16BITS(bp
)) {
585 addr_size
= sizeof(struct in_addr
);
589 addr_size
= sizeof(struct in6_addr
);
596 bp
+= (2 * sizeof(u_int16_t
));
597 if (opt_len
!= 4 + addr_size
) {
598 (void)printf("[Bad OPT_REDIRECT option, length %u != 4 + address size]", opt_len
);
601 TCHECK2(*bp
, addr_size
);
605 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
606 (void)printf(" REDIRECT %s", (char *)nla
);
607 opts_len
-= 4 + addr_size
;
610 case PGM_OPT_PARITY_PRM
:
612 (void)printf("[Bad OPT_PARITY_PRM option, length %u != 8]", opt_len
);
617 len
= EXTRACT_32BITS(bp
);
618 bp
+= sizeof(u_int32_t
);
619 (void)printf(" PARITY MAXTGS %u", len
);
623 case PGM_OPT_PARITY_GRP
:
625 (void)printf("[Bad OPT_PARITY_GRP option, length %u != 8]", opt_len
);
630 seq
= EXTRACT_32BITS(bp
);
631 bp
+= sizeof(u_int32_t
);
632 (void)printf(" PARITY GROUP %u", seq
);
636 case PGM_OPT_CURR_TGSIZE
:
638 (void)printf("[Bad OPT_CURR_TGSIZE option, length %u != 8]", opt_len
);
643 len
= EXTRACT_32BITS(bp
);
644 bp
+= sizeof(u_int32_t
);
645 (void)printf(" PARITY ATGS %u", len
);
649 case PGM_OPT_NBR_UNREACH
:
651 (void)printf("[Bad OPT_NBR_UNREACH option, length %u != 4]", opt_len
);
656 (void)printf(" NBR_UNREACH");
660 case PGM_OPT_PATH_NLA
:
661 (void)printf(" PATH_NLA [%d]", opt_len
);
668 (void)printf("[Bad OPT_SYN option, length %u != 4]", opt_len
);
673 (void)printf(" SYN");
679 (void)printf("[Bad OPT_FIN option, length %u != 4]", opt_len
);
684 (void)printf(" FIN");
690 (void)printf("[Bad OPT_RST option, length %u != 4]", opt_len
);
695 (void)printf(" RST");
707 (void)printf("[Bad OPT_CRQST option, length %u != 4]", opt_len
);
712 (void)printf(" CRQST");
717 (void)printf(" OPT_%02X [%d] ", opt_type
, opt_len
);
723 if (opt_type
& PGM_OPT_END
)
728 (void)printf(" [%u]", EXTRACT_16BITS(&pgm
->pgm_length
));
733 fputs("[|pgm]", stdout
);