]>
The Tcpdump Group git mirrors - tcpdump/blob - print-pgm.c
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>
22 #include "interface.h"
24 #include "addrtoname.h"
34 * PGM header (RFC 3208)
48 uint32_t pgms_trailseq
;
49 uint32_t pgms_leadseq
;
50 uint16_t pgms_nla_afi
;
51 uint16_t pgms_reserved
;
52 /* ... uint8_t pgms_nla[0]; */
58 uint16_t pgmn_source_afi
;
59 uint16_t pgmn_reserved
;
60 /* ... uint8_t pgmn_source[0]; */
61 /* ... uint16_t pgmn_group_afi */
62 /* ... uint16_t pgmn_reserved2; */
63 /* ... uint8_t pgmn_group[0]; */
68 uint32_t pgma_rx_max_seq
;
76 uint16_t pgmp_reserved
;
83 uint16_t pgmp_subtype
;
84 uint16_t pgmp_nla_afi
;
85 uint16_t pgmp_reserved
;
86 /* ... uint8_t pgmp_nla[0]; */
92 uint32_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_PGMCC_DATA 0x12
136 #define PGM_OPT_PGMCC_FEEDBACK 0x13
138 #define PGM_OPT_MASK 0x7f
140 #define PGM_OPT_END 0x80 /* end of options marker */
142 #define PGM_MIN_OPT_LEN 4
145 pgm_print(netdissect_options
*ndo
,
146 register const u_char
*bp
, register u_int length
,
147 register const u_char
*bp2
)
149 register const struct pgm_header
*pgm
;
150 register const struct ip
*ip
;
152 uint16_t sport
, dport
;
157 char nla_buf
[INET6_ADDRSTRLEN
];
158 register const struct ip6_hdr
*ip6
;
160 char nla_buf
[INET_ADDRSTRLEN
];
162 uint8_t opt_type
, opt_len
;
163 uint32_t seq
, opts_len
, len
, offset
;
165 pgm
= (const struct pgm_header
*)bp
;
166 ip
= (const struct ip
*)bp2
;
169 ip6
= (const struct ip6_hdr
*)bp2
;
174 ND_PRINT((ndo
, "Can't handle IPv6"));
179 if (!ND_TTEST(pgm
->pgm_dport
)) {
182 ND_PRINT((ndo
, "%s > %s: [|pgm]",
183 ip6addr_string(ndo
, &ip6
->ip6_src
),
184 ip6addr_string(ndo
, &ip6
->ip6_dst
)));
189 ND_PRINT((ndo
, "%s > %s: [|pgm]",
190 ipaddr_string(ndo
, &ip
->ip_src
),
191 ipaddr_string(ndo
, &ip
->ip_dst
)));
196 sport
= EXTRACT_16BITS(&pgm
->pgm_sport
);
197 dport
= EXTRACT_16BITS(&pgm
->pgm_dport
);
201 if (ip6
->ip6_nxt
== IPPROTO_PGM
) {
202 ND_PRINT((ndo
, "%s.%s > %s.%s: ",
203 ip6addr_string(ndo
, &ip6
->ip6_src
),
204 tcpport_string(ndo
, sport
),
205 ip6addr_string(ndo
, &ip6
->ip6_dst
),
206 tcpport_string(ndo
, dport
)));
208 ND_PRINT((ndo
, "%s > %s: ",
209 tcpport_string(ndo
, sport
), tcpport_string(ndo
, dport
)));
214 if (ip
->ip_p
== IPPROTO_PGM
) {
215 ND_PRINT((ndo
, "%s.%s > %s.%s: ",
216 ipaddr_string(ndo
, &ip
->ip_src
),
217 tcpport_string(ndo
, sport
),
218 ipaddr_string(ndo
, &ip
->ip_dst
),
219 tcpport_string(ndo
, dport
)));
221 ND_PRINT((ndo
, "%s > %s: ",
222 tcpport_string(ndo
, sport
), tcpport_string(ndo
, dport
)));
228 ND_PRINT((ndo
, "PGM, length %u", EXTRACT_16BITS(&pgm
->pgm_length
)));
233 ND_PRINT((ndo
, " 0x%02x%02x%02x%02x%02x%02x ",
240 switch (pgm
->pgm_type
) {
242 const struct pgm_spm
*spm
;
244 spm
= (const struct pgm_spm
*)(pgm
+ 1);
247 switch (EXTRACT_16BITS(&spm
->pgms_nla_afi
)) {
249 addr_size
= sizeof(struct in_addr
);
254 addr_size
= sizeof(struct in6_addr
);
262 bp
= (const u_char
*) (spm
+ 1);
263 ND_TCHECK2(*bp
, addr_size
);
267 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
268 ND_PRINT((ndo
, "SPM seq %u trail %u lead %u nla %s",
269 EXTRACT_32BITS(&spm
->pgms_seq
),
270 EXTRACT_32BITS(&spm
->pgms_trailseq
),
271 EXTRACT_32BITS(&spm
->pgms_leadseq
),
277 const struct pgm_poll
*poll
;
279 poll
= (const struct pgm_poll
*)(pgm
+ 1);
281 ND_PRINT((ndo
, "POLL seq %u round %u",
282 EXTRACT_32BITS(&poll
->pgmp_seq
),
283 EXTRACT_16BITS(&poll
->pgmp_round
)));
284 bp
= (const u_char
*) (poll
+ 1);
288 const struct pgm_polr
*polr
;
289 uint32_t ivl
, rnd
, mask
;
291 polr
= (const struct pgm_polr
*)(pgm
+ 1);
294 switch (EXTRACT_16BITS(&polr
->pgmp_nla_afi
)) {
296 addr_size
= sizeof(struct in_addr
);
301 addr_size
= sizeof(struct in6_addr
);
309 bp
= (const u_char
*) (polr
+ 1);
310 ND_TCHECK2(*bp
, addr_size
);
314 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
316 ND_TCHECK2(*bp
, sizeof(uint32_t));
317 ivl
= EXTRACT_32BITS(bp
);
318 bp
+= sizeof(uint32_t);
320 ND_TCHECK2(*bp
, sizeof(uint32_t));
321 rnd
= EXTRACT_32BITS(bp
);
322 bp
+= sizeof(uint32_t);
324 ND_TCHECK2(*bp
, sizeof(uint32_t));
325 mask
= EXTRACT_32BITS(bp
);
326 bp
+= sizeof(uint32_t);
328 ND_PRINT((ndo
, "POLR seq %u round %u nla %s ivl %u rnd 0x%08x "
329 "mask 0x%08x", EXTRACT_32BITS(&polr
->pgmp_seq
),
330 EXTRACT_16BITS(&polr
->pgmp_round
), nla_buf
, ivl
, rnd
, mask
));
334 const struct pgm_data
*odata
;
336 odata
= (const struct pgm_data
*)(pgm
+ 1);
338 ND_PRINT((ndo
, "ODATA trail %u seq %u",
339 EXTRACT_32BITS(&odata
->pgmd_trailseq
),
340 EXTRACT_32BITS(&odata
->pgmd_seq
)));
341 bp
= (const u_char
*) (odata
+ 1);
346 const struct pgm_data
*rdata
;
348 rdata
= (const struct pgm_data
*)(pgm
+ 1);
350 ND_PRINT((ndo
, "RDATA trail %u seq %u",
351 EXTRACT_32BITS(&rdata
->pgmd_trailseq
),
352 EXTRACT_32BITS(&rdata
->pgmd_seq
)));
353 bp
= (const u_char
*) (rdata
+ 1);
360 const struct pgm_nak
*nak
;
361 const void *source
, *group
;
362 int source_af
, group_af
;
364 char source_buf
[INET6_ADDRSTRLEN
], group_buf
[INET6_ADDRSTRLEN
];
366 char source_buf
[INET_ADDRSTRLEN
], group_buf
[INET_ADDRSTRLEN
];
369 nak
= (const struct pgm_nak
*)(pgm
+ 1);
373 * Skip past the source, saving info along the way
374 * and stopping if we don't have enough.
376 switch (EXTRACT_16BITS(&nak
->pgmn_source_afi
)) {
378 addr_size
= sizeof(struct in_addr
);
383 addr_size
= sizeof(struct in6_addr
);
384 source_af
= AF_INET6
;
391 bp
= (const u_char
*) (nak
+ 1);
392 ND_TCHECK2(*bp
, addr_size
);
397 * Skip past the group, saving info along the way
398 * and stopping if we don't have enough.
400 switch (EXTRACT_16BITS(bp
)) {
402 addr_size
= sizeof(struct in_addr
);
407 addr_size
= sizeof(struct in6_addr
);
415 bp
+= (2 * sizeof(uint16_t));
416 ND_TCHECK2(*bp
, addr_size
);
421 * Options decoding can go here.
423 inet_ntop(source_af
, source
, source_buf
, sizeof(source_buf
));
424 inet_ntop(group_af
, group
, group_buf
, sizeof(group_buf
));
425 switch (pgm
->pgm_type
) {
427 ND_PRINT((ndo
, "NAK "));
430 ND_PRINT((ndo
, "NNAK "));
433 ND_PRINT((ndo
, "NCF "));
438 ND_PRINT((ndo
, "(%s -> %s), seq %u",
439 source_buf
, group_buf
, EXTRACT_32BITS(&nak
->pgmn_seq
)));
444 const struct pgm_ack
*ack
;
446 ack
= (const struct pgm_ack
*)(pgm
+ 1);
448 ND_PRINT((ndo
, "ACK seq %u",
449 EXTRACT_32BITS(&ack
->pgma_rx_max_seq
)));
450 bp
= (const u_char
*) (ack
+ 1);
455 ND_PRINT((ndo
, "SPMR"));
459 ND_PRINT((ndo
, "UNKNOWN type 0x%02x", pgm
->pgm_type
));
463 if (pgm
->pgm_options
& PGM_OPT_BIT_PRESENT
) {
466 * make sure there's enough for the first option header
468 if (!ND_TTEST2(*bp
, PGM_MIN_OPT_LEN
)) {
469 ND_PRINT((ndo
, "[|OPT]"));
474 * That option header MUST be an OPT_LENGTH option
475 * (see the first paragraph of section 9.1 in RFC 3208).
478 if ((opt_type
& PGM_OPT_MASK
) != PGM_OPT_LENGTH
) {
479 ND_PRINT((ndo
, "[First option bad, should be PGM_OPT_LENGTH, is %u]", opt_type
& PGM_OPT_MASK
));
484 ND_PRINT((ndo
, "[Bad OPT_LENGTH option, length %u != 4]", opt_len
));
487 opts_len
= EXTRACT_16BITS(bp
);
489 ND_PRINT((ndo
, "[Bad total option length %u < 4]", opts_len
));
492 bp
+= sizeof(uint16_t);
493 ND_PRINT((ndo
, " OPTS LEN %d", opts_len
));
497 if (opts_len
< PGM_MIN_OPT_LEN
) {
498 ND_PRINT((ndo
, "[Total option length leaves no room for final option]"));
503 if (opt_len
< PGM_MIN_OPT_LEN
) {
504 ND_PRINT((ndo
, "[Bad option, length %u < %u]", opt_len
,
508 if (opts_len
< opt_len
) {
509 ND_PRINT((ndo
, "[Total option length leaves no room for final option]"));
512 if (!ND_TTEST2(*bp
, opt_len
- 2)) {
513 ND_PRINT((ndo
, " [|OPT]"));
517 switch (opt_type
& PGM_OPT_MASK
) {
520 ND_PRINT((ndo
, "[Bad OPT_LENGTH option, length %u != 4]", opt_len
));
523 ND_PRINT((ndo
, " OPTS LEN (extra?) %d", EXTRACT_16BITS(bp
)));
524 bp
+= sizeof(uint16_t);
528 case PGM_OPT_FRAGMENT
:
530 ND_PRINT((ndo
, "[Bad OPT_FRAGMENT option, length %u != 16]", opt_len
));
534 seq
= EXTRACT_32BITS(bp
);
535 bp
+= sizeof(uint32_t);
536 offset
= EXTRACT_32BITS(bp
);
537 bp
+= sizeof(uint32_t);
538 len
= EXTRACT_32BITS(bp
);
539 bp
+= sizeof(uint32_t);
540 ND_PRINT((ndo
, " FRAG seq %u off %u len %u", seq
, offset
, len
));
544 case PGM_OPT_NAK_LIST
:
546 opt_len
-= sizeof(uint32_t); /* option header */
547 ND_PRINT((ndo
, " NAK LIST"));
549 if (opt_len
< sizeof(uint32_t)) {
550 ND_PRINT((ndo
, "[Option length not a multiple of 4]"));
553 ND_TCHECK2(*bp
, sizeof(uint32_t));
554 ND_PRINT((ndo
, " %u", EXTRACT_32BITS(bp
)));
555 bp
+= sizeof(uint32_t);
556 opt_len
-= sizeof(uint32_t);
557 opts_len
-= sizeof(uint32_t);
563 ND_PRINT((ndo
, "[Bad OPT_JOIN option, length %u != 8]", opt_len
));
567 seq
= EXTRACT_32BITS(bp
);
568 bp
+= sizeof(uint32_t);
569 ND_PRINT((ndo
, " JOIN %u", seq
));
573 case PGM_OPT_NAK_BO_IVL
:
575 ND_PRINT((ndo
, "[Bad OPT_NAK_BO_IVL option, length %u != 12]", opt_len
));
579 offset
= EXTRACT_32BITS(bp
);
580 bp
+= sizeof(uint32_t);
581 seq
= EXTRACT_32BITS(bp
);
582 bp
+= sizeof(uint32_t);
583 ND_PRINT((ndo
, " BACKOFF ivl %u ivlseq %u", offset
, seq
));
587 case PGM_OPT_NAK_BO_RNG
:
589 ND_PRINT((ndo
, "[Bad OPT_NAK_BO_RNG option, length %u != 12]", opt_len
));
593 offset
= EXTRACT_32BITS(bp
);
594 bp
+= sizeof(uint32_t);
595 seq
= EXTRACT_32BITS(bp
);
596 bp
+= sizeof(uint32_t);
597 ND_PRINT((ndo
, " BACKOFF max %u min %u", offset
, seq
));
601 case PGM_OPT_REDIRECT
:
603 switch (EXTRACT_16BITS(bp
)) {
605 addr_size
= sizeof(struct in_addr
);
610 addr_size
= sizeof(struct in6_addr
);
618 bp
+= (2 * sizeof(uint16_t));
619 if (opt_len
!= 4 + addr_size
) {
620 ND_PRINT((ndo
, "[Bad OPT_REDIRECT option, length %u != 4 + address size]", opt_len
));
623 ND_TCHECK2(*bp
, addr_size
);
627 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
628 ND_PRINT((ndo
, " REDIRECT %s", nla_buf
));
629 opts_len
-= 4 + addr_size
;
632 case PGM_OPT_PARITY_PRM
:
634 ND_PRINT((ndo
, "[Bad OPT_PARITY_PRM option, length %u != 8]", opt_len
));
638 len
= EXTRACT_32BITS(bp
);
639 bp
+= sizeof(uint32_t);
640 ND_PRINT((ndo
, " PARITY MAXTGS %u", len
));
644 case PGM_OPT_PARITY_GRP
:
646 ND_PRINT((ndo
, "[Bad OPT_PARITY_GRP option, length %u != 8]", opt_len
));
650 seq
= EXTRACT_32BITS(bp
);
651 bp
+= sizeof(uint32_t);
652 ND_PRINT((ndo
, " PARITY GROUP %u", seq
));
656 case PGM_OPT_CURR_TGSIZE
:
658 ND_PRINT((ndo
, "[Bad OPT_CURR_TGSIZE option, length %u != 8]", opt_len
));
662 len
= EXTRACT_32BITS(bp
);
663 bp
+= sizeof(uint32_t);
664 ND_PRINT((ndo
, " PARITY ATGS %u", len
));
668 case PGM_OPT_NBR_UNREACH
:
670 ND_PRINT((ndo
, "[Bad OPT_NBR_UNREACH option, length %u != 4]", opt_len
));
674 ND_PRINT((ndo
, " NBR_UNREACH"));
678 case PGM_OPT_PATH_NLA
:
679 ND_PRINT((ndo
, " PATH_NLA [%d]", opt_len
));
686 ND_PRINT((ndo
, "[Bad OPT_SYN option, length %u != 4]", opt_len
));
690 ND_PRINT((ndo
, " SYN"));
696 ND_PRINT((ndo
, "[Bad OPT_FIN option, length %u != 4]", opt_len
));
700 ND_PRINT((ndo
, " FIN"));
706 ND_PRINT((ndo
, "[Bad OPT_RST option, length %u != 4]", opt_len
));
710 ND_PRINT((ndo
, " RST"));
715 ND_PRINT((ndo
, " CR"));
722 ND_PRINT((ndo
, "[Bad OPT_CRQST option, length %u != 4]", opt_len
));
726 ND_PRINT((ndo
, " CRQST"));
730 case PGM_OPT_PGMCC_DATA
:
732 offset
= EXTRACT_32BITS(bp
);
733 bp
+= sizeof(uint32_t);
734 switch (EXTRACT_16BITS(bp
)) {
736 addr_size
= sizeof(struct in_addr
);
741 addr_size
= sizeof(struct in6_addr
);
749 bp
+= (2 * sizeof(uint16_t));
750 if (opt_len
!= 12 + addr_size
) {
751 ND_PRINT((ndo
, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len
));
754 ND_TCHECK2(*bp
, addr_size
);
758 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
759 ND_PRINT((ndo
, " PGMCC DATA %u %s", offset
, nla_buf
));
763 case PGM_OPT_PGMCC_FEEDBACK
:
765 offset
= EXTRACT_32BITS(bp
);
766 bp
+= sizeof(uint32_t);
767 switch (EXTRACT_16BITS(bp
)) {
769 addr_size
= sizeof(struct in_addr
);
774 addr_size
= sizeof(struct in6_addr
);
782 bp
+= (2 * sizeof(uint16_t));
783 if (opt_len
!= 12 + addr_size
) {
784 ND_PRINT((ndo
, "[Bad OPT_PGMCC_FEEDBACK option, length %u != 12 + address size]", opt_len
));
787 ND_TCHECK2(*bp
, addr_size
);
791 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
792 ND_PRINT((ndo
, " PGMCC FEEDBACK %u %s", offset
, nla_buf
));
797 ND_PRINT((ndo
, " OPT_%02X [%d] ", opt_type
, opt_len
));
803 if (opt_type
& PGM_OPT_END
)
808 ND_PRINT((ndo
, " [%u]", length
));
809 if (ndo
->ndo_packettype
== PT_PGM_ZMTP1
&&
810 (pgm
->pgm_type
== PGM_ODATA
|| pgm
->pgm_type
== PGM_RDATA
))
811 zmtp1_print_datagram(ndo
, bp
, EXTRACT_16BITS(&pgm
->pgm_length
));
816 ND_PRINT((ndo
, "[|pgm]"));
818 ND_PRINT((ndo
, ">"));