4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that: (1) source code
6 * distributions retain the above copyright notice and this paragraph
7 * in its entirety, and (2) distributions including binary code include
8 * the above copyright notice and this paragraph in its entirety in
9 * the documentation or other materials provided with the distribution.
10 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
11 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
12 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
13 * FOR A PARTICULAR PURPOSE.
15 * Original code by Andy Heffernan (ahh@juniper.net)
18 #include <sys/cdefs.h>
21 static const char rcsid
[] _U_
=
22 "@(#) Header: /tcpdump/master/tcpdump/print-pgm.c,v 1.1.2.5 2005/06/07 22:06:16 guy Exp";
24 __RCSID("$NetBSD: tcpdump2rcsid.ex,v 1.1 2001/06/25 20:09:58 itojun Exp $");
32 #include <tcpdump-stdinc.h>
38 #include "interface.h"
40 #include "addrtoname.h"
49 * PGM header (RFC 3208)
63 u_int32_t pgms_trailseq
;
64 u_int32_t pgms_leadseq
;
65 u_int16_t pgms_nla_afi
;
66 u_int16_t pgms_reserved
;
67 /* ... u_int8_t pgms_nla[0]; */
73 u_int16_t pgmn_source_afi
;
74 u_int16_t pgmn_reserved
;
75 /* ... u_int8_t pgmn_source[0]; */
76 /* ... u_int16_t pgmn_group_afi */
77 /* ... u_int16_t pgmn_reserved2; */
78 /* ... u_int8_t pgmn_group[0]; */
85 u_int16_t pgmp_reserved
;
92 u_int16_t pgmp_subtype
;
93 u_int16_t pgmp_nla_afi
;
94 u_int16_t pgmp_reserved
;
95 /* ... u_int8_t pgmp_nla[0]; */
101 u_int32_t pgmd_trailseq
;
105 typedef enum _pgm_type
{
106 PGM_SPM
= 0, /* source path message */
107 PGM_POLL
= 1, /* POLL Request */
108 PGM_POLR
= 2, /* POLL Response */
109 PGM_ODATA
= 4, /* original data */
110 PGM_RDATA
= 5, /* repair data */
111 PGM_NAK
= 8, /* NAK */
112 PGM_NULLNAK
= 9, /* Null NAK */
113 PGM_NCF
= 10, /* NAK Confirmation */
114 PGM_ACK
= 11, /* ACK for congestion control */
115 PGM_SPMR
= 12, /* SPM request */
119 #define PGM_OPT_BIT_PRESENT 0x01
120 #define PGM_OPT_BIT_NETWORK 0x02
121 #define PGM_OPT_BIT_VAR_PKTLEN 0x40
122 #define PGM_OPT_BIT_PARITY 0x80
124 #define PGM_OPT_LENGTH 0x00
125 #define PGM_OPT_FRAGMENT 0x01
126 #define PGM_OPT_NAK_LIST 0x02
127 #define PGM_OPT_JOIN 0x03
128 #define PGM_OPT_NAK_BO_IVL 0x04
129 #define PGM_OPT_NAK_BO_RNG 0x05
131 #define PGM_OPT_REDIRECT 0x07
132 #define PGM_OPT_PARITY_PRM 0x08
133 #define PGM_OPT_PARITY_GRP 0x09
134 #define PGM_OPT_CURR_TGSIZE 0x0A
135 #define PGM_OPT_NBR_UNREACH 0x0B
136 #define PGM_OPT_PATH_NLA 0x0C
138 #define PGM_OPT_SYN 0x0D
139 #define PGM_OPT_FIN 0x0E
140 #define PGM_OPT_RST 0x0F
141 #define PGM_OPT_CR 0x10
142 #define PGM_OPT_CRQST 0x11
144 #define PGM_OPT_MASK 0x7f
146 #define PGM_OPT_END 0x80 /* end of options marker */
148 #define PGM_MIN_OPT_LEN 4
156 pgm_print(register const u_char
*bp
, register u_int length
,
157 register const u_char
*bp2
)
159 register const struct pgm_header
*pgm
;
160 register const struct ip
*ip
;
162 u_int16_t sport
, dport
;
167 char nla_buf
[INET6_ADDRSTRLEN
];
168 register const struct ip6_hdr
*ip6
;
170 char nla_buf
[INET_ADDRSTRLEN
];
172 u_int8_t opt_type
, opt_len
, flags1
, flags2
;
173 u_int32_t seq
, opts_len
, len
, offset
;
175 pgm
= (struct pgm_header
*)bp
;
176 ip
= (struct ip
*)bp2
;
179 ip6
= (struct ip6_hdr
*)bp2
;
184 (void)printf("Can't handle IPv6");
189 if (!TTEST(pgm
->pgm_dport
)) {
192 (void)printf("%s > %s: [|pgm]",
193 ip6addr_string(&ip6
->ip6_src
),
194 ip6addr_string(&ip6
->ip6_dst
));
199 (void)printf("%s > %s: [|pgm]",
200 ipaddr_string(&ip
->ip_src
),
201 ipaddr_string(&ip
->ip_dst
));
206 sport
= EXTRACT_16BITS(&pgm
->pgm_sport
);
207 dport
= EXTRACT_16BITS(&pgm
->pgm_dport
);
211 if (ip6
->ip6_nxt
== IPPROTO_PGM
) {
212 (void)printf("%s.%s > %s.%s: ",
213 ip6addr_string(&ip6
->ip6_src
),
214 tcpport_string(sport
),
215 ip6addr_string(&ip6
->ip6_dst
),
216 tcpport_string(dport
));
218 (void)printf("%s > %s: ",
219 tcpport_string(sport
), tcpport_string(dport
));
224 if (ip
->ip_p
== IPPROTO_PGM
) {
225 (void)printf("%s.%s > %s.%s: ",
226 ipaddr_string(&ip
->ip_src
),
227 tcpport_string(sport
),
228 ipaddr_string(&ip
->ip_dst
),
229 tcpport_string(dport
));
231 (void)printf("%s > %s: ",
232 tcpport_string(sport
), tcpport_string(dport
));
238 (void)printf("PGM, length %u", pgm
->pgm_length
);
243 if (length
> pgm
->pgm_length
)
244 length
= pgm
->pgm_length
;
246 (void)printf(" 0x%02x%02x%02x%02x%02x%02x ",
253 switch (pgm
->pgm_type
) {
257 spm
= (struct pgm_spm
*)(pgm
+ 1);
260 switch (EXTRACT_16BITS(&spm
->pgms_nla_afi
)) {
262 addr_size
= sizeof(struct in_addr
);
267 addr_size
= sizeof(struct in6_addr
);
275 bp
= (u_char
*) (spm
+ 1);
276 TCHECK2(*bp
, addr_size
);
280 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
281 (void)printf("SPM seq %u trail %u lead %u nla %s",
282 EXTRACT_32BITS(&spm
->pgms_seq
),
283 EXTRACT_32BITS(&spm
->pgms_trailseq
),
284 EXTRACT_32BITS(&spm
->pgms_leadseq
),
290 struct pgm_poll
*poll
;
292 poll
= (struct pgm_poll
*)(pgm
+ 1);
294 (void)printf("POLL seq %u round %u",
295 EXTRACT_32BITS(&poll
->pgmp_seq
),
296 EXTRACT_16BITS(&poll
->pgmp_round
));
297 bp
= (u_char
*) (poll
+ 1);
301 struct pgm_polr
*polr
;
302 u_int32_t ivl
, rnd
, mask
;
304 polr
= (struct pgm_polr
*)(pgm
+ 1);
307 switch (EXTRACT_16BITS(&polr
->pgmp_nla_afi
)) {
309 addr_size
= sizeof(struct in_addr
);
314 addr_size
= sizeof(struct in6_addr
);
322 bp
= (u_char
*) (polr
+ 1);
323 TCHECK2(*bp
, addr_size
);
327 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
329 TCHECK2(*bp
, sizeof(u_int32_t
));
330 ivl
= EXTRACT_32BITS(bp
);
331 bp
+= sizeof(u_int32_t
);
333 TCHECK2(*bp
, sizeof(u_int32_t
));
334 rnd
= EXTRACT_32BITS(bp
);
335 bp
+= sizeof(u_int32_t
);
337 TCHECK2(*bp
, sizeof(u_int32_t
));
338 mask
= EXTRACT_32BITS(bp
);
339 bp
+= sizeof(u_int32_t
);
341 (void)printf("POLR seq %u round %u nla %s ivl %u rnd 0x%08x "
342 "mask 0x%08x", EXTRACT_32BITS(&polr
->pgmp_seq
),
343 EXTRACT_16BITS(&polr
->pgmp_round
), nla_buf
, ivl
, rnd
, mask
);
347 struct pgm_data
*odata
;
349 odata
= (struct pgm_data
*)(pgm
+ 1);
351 (void)printf("ODATA trail %u seq %u",
352 EXTRACT_32BITS(&odata
->pgmd_trailseq
),
353 EXTRACT_32BITS(&odata
->pgmd_seq
));
354 bp
= (u_char
*) (odata
+ 1);
359 struct pgm_data
*rdata
;
361 rdata
= (struct pgm_data
*)(pgm
+ 1);
363 (void)printf("RDATA trail %u seq %u",
364 EXTRACT_32BITS(&rdata
->pgmd_trailseq
),
365 EXTRACT_32BITS(&rdata
->pgmd_seq
));
366 bp
= (u_char
*) (rdata
+ 1);
374 const void *source
, *group
;
375 int source_af
, group_af
;
377 char source_buf
[INET6_ADDRSTRLEN
], group_buf
[INET6_ADDRSTRLEN
];
379 char source_buf
[INET_ADDRSTRLEN
], group_buf
[INET_ADDRSTRLEN
];
382 nak
= (struct pgm_nak
*)(pgm
+ 1);
386 * Skip past the source, saving info along the way
387 * and stopping if we don't have enough.
389 switch (EXTRACT_16BITS(&nak
->pgmn_source_afi
)) {
391 addr_size
= sizeof(struct in_addr
);
396 addr_size
= sizeof(struct in6_addr
);
397 source_af
= AF_INET6
;
404 bp
= (u_char
*) (nak
+ 1);
405 TCHECK2(*bp
, addr_size
);
410 * Skip past the group, saving info along the way
411 * and stopping if we don't have enough.
413 switch (EXTRACT_16BITS(bp
)) {
415 addr_size
= sizeof(struct in_addr
);
420 addr_size
= sizeof(struct in6_addr
);
428 bp
+= (2 * sizeof(u_int16_t
));
429 TCHECK2(*bp
, addr_size
);
434 * Options decoding can go here.
436 inet_ntop(source_af
, source
, source_buf
, sizeof(source_buf
));
437 inet_ntop(group_af
, group
, group_buf
, sizeof(group_buf
));
438 switch (pgm
->pgm_type
) {
440 (void)printf("NAK ");
443 (void)printf("NNAK ");
446 (void)printf("NCF ");
451 (void)printf("(%s -> %s), seq %u",
452 source_buf
, group_buf
, EXTRACT_32BITS(&nak
->pgmn_seq
));
457 (void)printf("SPMR");
461 (void)printf("UNKNOWN type %0x02x", pgm
->pgm_type
);
465 if (pgm
->pgm_options
& PGM_OPT_BIT_PRESENT
) {
468 * make sure there's enough for the first option header
470 if (!TTEST2(*bp
, PGM_MIN_OPT_LEN
)) {
471 (void)printf("[|OPT]");
476 * That option header MUST be an OPT_LENGTH option
477 * (see the first paragraph of section 9.1 in RFC 3208).
480 if ((opt_type
& PGM_OPT_MASK
) != PGM_OPT_LENGTH
) {
481 (void)printf("[First option bad, should be PGM_OPT_LENGTH, is %u]", opt_type
& PGM_OPT_MASK
);
486 (void)printf("[Bad OPT_LENGTH option, length %u != 4]", opt_len
);
489 opts_len
= EXTRACT_16BITS(bp
);
491 (void)printf("[Bad total option length %u < 4]", opts_len
);
494 bp
+= sizeof(u_int16_t
);
495 (void)printf(" OPTS LEN %d", opts_len
);
499 if (opts_len
< PGM_MIN_OPT_LEN
) {
500 (void)printf("[Total option length leaves no room for final option]");
505 if (opt_len
< PGM_MIN_OPT_LEN
) {
506 (void)printf("[Bad option, length %u < %u]", opt_len
,
510 if (opts_len
< opt_len
) {
511 (void)printf("[Total option length leaves no room for final option]");
514 if (!TTEST2(*bp
, opt_len
- 2)) {
515 (void)printf(" [|OPT]");
519 switch (opt_type
& PGM_OPT_MASK
) {
522 (void)printf("[Bad OPT_LENGTH option, length %u != 4]", opt_len
);
525 (void)printf(" OPTS LEN (extra?) %d", EXTRACT_16BITS(bp
));
526 bp
+= sizeof(u_int16_t
);
530 case PGM_OPT_FRAGMENT
:
532 (void)printf("[Bad OPT_FRAGMENT option, length %u != 16]", opt_len
);
537 seq
= EXTRACT_32BITS(bp
);
538 bp
+= sizeof(u_int32_t
);
539 offset
= EXTRACT_32BITS(bp
);
540 bp
+= sizeof(u_int32_t
);
541 len
= EXTRACT_32BITS(bp
);
542 bp
+= sizeof(u_int32_t
);
543 (void)printf(" FRAG seq %u off %u len %u", seq
, offset
, len
);
547 case PGM_OPT_NAK_LIST
:
550 opt_len
-= sizeof(u_int32_t
); /* option header */
551 (void)printf(" NAK LIST");
553 if (opt_len
< sizeof(u_int32_t
)) {
554 (void)printf("[Option length not a multiple of 4]");
557 TCHECK2(*bp
, sizeof(u_int32_t
));
558 (void)printf(" %u", EXTRACT_32BITS(bp
));
559 bp
+= sizeof(u_int32_t
);
560 opt_len
-= sizeof(u_int32_t
);
561 opts_len
-= sizeof(u_int32_t
);
567 (void)printf("[Bad OPT_JOIN option, length %u != 8]", opt_len
);
572 seq
= EXTRACT_32BITS(bp
);
573 bp
+= sizeof(u_int32_t
);
574 (void)printf(" JOIN %u", seq
);
578 case PGM_OPT_NAK_BO_IVL
:
580 (void)printf("[Bad OPT_NAK_BO_IVL option, length %u != 12]", opt_len
);
585 offset
= EXTRACT_32BITS(bp
);
586 bp
+= sizeof(u_int32_t
);
587 seq
= EXTRACT_32BITS(bp
);
588 bp
+= sizeof(u_int32_t
);
589 (void)printf(" BACKOFF ivl %u ivlseq %u", offset
, seq
);
593 case PGM_OPT_NAK_BO_RNG
:
595 (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
:
611 switch (EXTRACT_16BITS(bp
)) {
613 addr_size
= sizeof(struct in_addr
);
618 addr_size
= sizeof(struct in6_addr
);
626 bp
+= (2 * sizeof(u_int16_t
));
627 if (opt_len
!= 4 + addr_size
) {
628 (void)printf("[Bad OPT_REDIRECT option, length %u != 4 + address size]", opt_len
);
631 TCHECK2(*bp
, addr_size
);
635 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
636 (void)printf(" REDIRECT %s", (char *)nla
);
637 opts_len
-= 4 + addr_size
;
640 case PGM_OPT_PARITY_PRM
:
642 (void)printf("[Bad OPT_PARITY_PRM option, length %u != 8]", opt_len
);
647 len
= EXTRACT_32BITS(bp
);
648 bp
+= sizeof(u_int32_t
);
649 (void)printf(" PARITY MAXTGS %u", len
);
653 case PGM_OPT_PARITY_GRP
:
655 (void)printf("[Bad OPT_PARITY_GRP option, length %u != 8]", opt_len
);
660 seq
= EXTRACT_32BITS(bp
);
661 bp
+= sizeof(u_int32_t
);
662 (void)printf(" PARITY GROUP %u", seq
);
666 case PGM_OPT_CURR_TGSIZE
:
668 (void)printf("[Bad OPT_CURR_TGSIZE option, length %u != 8]", opt_len
);
673 len
= EXTRACT_32BITS(bp
);
674 bp
+= sizeof(u_int32_t
);
675 (void)printf(" PARITY ATGS %u", len
);
679 case PGM_OPT_NBR_UNREACH
:
681 (void)printf("[Bad OPT_NBR_UNREACH option, length %u != 4]", opt_len
);
686 (void)printf(" NBR_UNREACH");
690 case PGM_OPT_PATH_NLA
:
691 (void)printf(" PATH_NLA [%d]", opt_len
);
698 (void)printf("[Bad OPT_SYN option, length %u != 4]", opt_len
);
703 (void)printf(" SYN");
709 (void)printf("[Bad OPT_FIN option, length %u != 4]", opt_len
);
714 (void)printf(" FIN");
720 (void)printf("[Bad OPT_RST option, length %u != 4]", opt_len
);
725 (void)printf(" RST");
737 (void)printf("[Bad OPT_CRQST option, length %u != 4]", opt_len
);
742 (void)printf(" CRQST");
747 (void)printf(" OPT_%02X [%d] ", opt_type
, opt_len
);
753 if (opt_type
& PGM_OPT_END
)
758 (void)printf(" [%u]", EXTRACT_16BITS(&pgm
->pgm_length
));
763 fputs("[|pgm]", stdout
);