]>
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 <netdissect-stdinc.h>
22 #include "netdissect.h"
24 #include "addrtoname.h"
25 #include "addrtostr.h"
33 * PGM header (RFC 3208)
47 uint32_t pgms_trailseq
;
48 uint32_t pgms_leadseq
;
49 uint16_t pgms_nla_afi
;
50 uint16_t pgms_reserved
;
51 /* ... uint8_t pgms_nla[0]; */
57 uint16_t pgmn_source_afi
;
58 uint16_t pgmn_reserved
;
59 /* ... uint8_t pgmn_source[0]; */
60 /* ... uint16_t pgmn_group_afi */
61 /* ... uint16_t pgmn_reserved2; */
62 /* ... uint8_t pgmn_group[0]; */
67 uint32_t pgma_rx_max_seq
;
75 uint16_t pgmp_reserved
;
82 uint16_t pgmp_subtype
;
83 uint16_t pgmp_nla_afi
;
84 uint16_t pgmp_reserved
;
85 /* ... uint8_t pgmp_nla[0]; */
91 uint32_t pgmd_trailseq
;
95 typedef enum _pgm_type
{
96 PGM_SPM
= 0, /* source path message */
97 PGM_POLL
= 1, /* POLL Request */
98 PGM_POLR
= 2, /* POLL Response */
99 PGM_ODATA
= 4, /* original data */
100 PGM_RDATA
= 5, /* repair data */
101 PGM_NAK
= 8, /* NAK */
102 PGM_NULLNAK
= 9, /* Null NAK */
103 PGM_NCF
= 10, /* NAK Confirmation */
104 PGM_ACK
= 11, /* ACK for congestion control */
105 PGM_SPMR
= 12, /* SPM request */
109 #define PGM_OPT_BIT_PRESENT 0x01
110 #define PGM_OPT_BIT_NETWORK 0x02
111 #define PGM_OPT_BIT_VAR_PKTLEN 0x40
112 #define PGM_OPT_BIT_PARITY 0x80
114 #define PGM_OPT_LENGTH 0x00
115 #define PGM_OPT_FRAGMENT 0x01
116 #define PGM_OPT_NAK_LIST 0x02
117 #define PGM_OPT_JOIN 0x03
118 #define PGM_OPT_NAK_BO_IVL 0x04
119 #define PGM_OPT_NAK_BO_RNG 0x05
121 #define PGM_OPT_REDIRECT 0x07
122 #define PGM_OPT_PARITY_PRM 0x08
123 #define PGM_OPT_PARITY_GRP 0x09
124 #define PGM_OPT_CURR_TGSIZE 0x0A
125 #define PGM_OPT_NBR_UNREACH 0x0B
126 #define PGM_OPT_PATH_NLA 0x0C
128 #define PGM_OPT_SYN 0x0D
129 #define PGM_OPT_FIN 0x0E
130 #define PGM_OPT_RST 0x0F
131 #define PGM_OPT_CR 0x10
132 #define PGM_OPT_CRQST 0x11
134 #define PGM_OPT_PGMCC_DATA 0x12
135 #define PGM_OPT_PGMCC_FEEDBACK 0x13
137 #define PGM_OPT_MASK 0x7f
139 #define PGM_OPT_END 0x80 /* end of options marker */
141 #define PGM_MIN_OPT_LEN 4
144 pgm_print(netdissect_options
*ndo
,
145 register const u_char
*bp
, register u_int length
,
146 register const u_char
*bp2
)
148 register const struct pgm_header
*pgm
;
149 register const struct ip
*ip
;
151 uint16_t sport
, dport
;
153 char nla_buf
[INET6_ADDRSTRLEN
];
154 register const struct ip6_hdr
*ip6
;
155 uint8_t opt_type
, opt_len
;
156 uint32_t seq
, opts_len
, len
, offset
;
158 pgm
= (const struct pgm_header
*)bp
;
159 ip
= (const struct ip
*)bp2
;
161 ip6
= (const struct ip6_hdr
*)bp2
;
165 if (!ND_TTEST(pgm
->pgm_dport
)) {
167 ND_PRINT((ndo
, "%s > %s: [|pgm]",
168 ip6addr_string(ndo
, &ip6
->ip6_src
),
169 ip6addr_string(ndo
, &ip6
->ip6_dst
)));
172 ND_PRINT((ndo
, "%s > %s: [|pgm]",
173 ipaddr_string(ndo
, &ip
->ip_src
),
174 ipaddr_string(ndo
, &ip
->ip_dst
)));
179 sport
= EXTRACT_16BITS(&pgm
->pgm_sport
);
180 dport
= EXTRACT_16BITS(&pgm
->pgm_dport
);
183 if (ip6
->ip6_nxt
== IPPROTO_PGM
) {
184 ND_PRINT((ndo
, "%s.%s > %s.%s: ",
185 ip6addr_string(ndo
, &ip6
->ip6_src
),
186 tcpport_string(ndo
, sport
),
187 ip6addr_string(ndo
, &ip6
->ip6_dst
),
188 tcpport_string(ndo
, dport
)));
190 ND_PRINT((ndo
, "%s > %s: ",
191 tcpport_string(ndo
, sport
), tcpport_string(ndo
, dport
)));
194 if (ip
->ip_p
== IPPROTO_PGM
) {
195 ND_PRINT((ndo
, "%s.%s > %s.%s: ",
196 ipaddr_string(ndo
, &ip
->ip_src
),
197 tcpport_string(ndo
, sport
),
198 ipaddr_string(ndo
, &ip
->ip_dst
),
199 tcpport_string(ndo
, dport
)));
201 ND_PRINT((ndo
, "%s > %s: ",
202 tcpport_string(ndo
, sport
), tcpport_string(ndo
, dport
)));
208 ND_PRINT((ndo
, "PGM, length %u", EXTRACT_16BITS(&pgm
->pgm_length
)));
213 ND_PRINT((ndo
, " 0x%02x%02x%02x%02x%02x%02x ",
220 switch (pgm
->pgm_type
) {
222 const struct pgm_spm
*spm
;
224 spm
= (const struct pgm_spm
*)(pgm
+ 1);
226 bp
= (const u_char
*) (spm
+ 1);
228 switch (EXTRACT_16BITS(&spm
->pgms_nla_afi
)) {
230 ND_TCHECK2(*bp
, sizeof(struct in_addr
));
231 addrtostr(bp
, nla_buf
, sizeof(nla_buf
));
232 bp
+= sizeof(struct in_addr
);
235 ND_TCHECK2(*bp
, sizeof(struct in6_addr
));
236 addrtostr6(bp
, nla_buf
, sizeof(nla_buf
));
237 bp
+= sizeof(struct in6_addr
);
244 ND_PRINT((ndo
, "SPM seq %u trail %u lead %u nla %s",
245 EXTRACT_32BITS(&spm
->pgms_seq
),
246 EXTRACT_32BITS(&spm
->pgms_trailseq
),
247 EXTRACT_32BITS(&spm
->pgms_leadseq
),
253 const struct pgm_poll
*poll_msg
;
255 poll_msg
= (const struct pgm_poll
*)(pgm
+ 1);
256 ND_TCHECK(*poll_msg
);
257 ND_PRINT((ndo
, "POLL seq %u round %u",
258 EXTRACT_32BITS(&poll_msg
->pgmp_seq
),
259 EXTRACT_16BITS(&poll_msg
->pgmp_round
)));
260 bp
= (const u_char
*) (poll_msg
+ 1);
264 const struct pgm_polr
*polr
;
265 uint32_t ivl
, rnd
, mask
;
267 polr
= (const struct pgm_polr
*)(pgm
+ 1);
269 bp
= (const u_char
*) (polr
+ 1);
271 switch (EXTRACT_16BITS(&polr
->pgmp_nla_afi
)) {
273 ND_TCHECK2(*bp
, sizeof(struct in_addr
));
274 addrtostr(bp
, nla_buf
, sizeof(nla_buf
));
275 bp
+= sizeof(struct in_addr
);
278 ND_TCHECK2(*bp
, sizeof(struct in6_addr
));
279 addrtostr6(bp
, nla_buf
, sizeof(nla_buf
));
280 bp
+= sizeof(struct in6_addr
);
287 ND_TCHECK2(*bp
, sizeof(uint32_t));
288 ivl
= EXTRACT_32BITS(bp
);
289 bp
+= sizeof(uint32_t);
291 ND_TCHECK2(*bp
, sizeof(uint32_t));
292 rnd
= EXTRACT_32BITS(bp
);
293 bp
+= sizeof(uint32_t);
295 ND_TCHECK2(*bp
, sizeof(uint32_t));
296 mask
= EXTRACT_32BITS(bp
);
297 bp
+= sizeof(uint32_t);
299 ND_PRINT((ndo
, "POLR seq %u round %u nla %s ivl %u rnd 0x%08x "
300 "mask 0x%08x", EXTRACT_32BITS(&polr
->pgmp_seq
),
301 EXTRACT_16BITS(&polr
->pgmp_round
), nla_buf
, ivl
, rnd
, mask
));
305 const struct pgm_data
*odata
;
307 odata
= (const struct pgm_data
*)(pgm
+ 1);
309 ND_PRINT((ndo
, "ODATA trail %u seq %u",
310 EXTRACT_32BITS(&odata
->pgmd_trailseq
),
311 EXTRACT_32BITS(&odata
->pgmd_seq
)));
312 bp
= (const u_char
*) (odata
+ 1);
317 const struct pgm_data
*rdata
;
319 rdata
= (const struct pgm_data
*)(pgm
+ 1);
321 ND_PRINT((ndo
, "RDATA trail %u seq %u",
322 EXTRACT_32BITS(&rdata
->pgmd_trailseq
),
323 EXTRACT_32BITS(&rdata
->pgmd_seq
)));
324 bp
= (const u_char
*) (rdata
+ 1);
331 const struct pgm_nak
*nak
;
332 char source_buf
[INET6_ADDRSTRLEN
], group_buf
[INET6_ADDRSTRLEN
];
334 nak
= (const struct pgm_nak
*)(pgm
+ 1);
336 bp
= (const u_char
*) (nak
+ 1);
339 * Skip past the source, saving info along the way
340 * and stopping if we don't have enough.
342 switch (EXTRACT_16BITS(&nak
->pgmn_source_afi
)) {
344 ND_TCHECK2(*bp
, sizeof(struct in_addr
));
345 addrtostr(bp
, source_buf
, sizeof(source_buf
));
346 bp
+= sizeof(struct in_addr
);
349 ND_TCHECK2(*bp
, sizeof(struct in6_addr
));
350 addrtostr6(bp
, source_buf
, sizeof(source_buf
));
351 bp
+= sizeof(struct in6_addr
);
359 * Skip past the group, saving info along the way
360 * and stopping if we don't have enough.
362 bp
+= (2 * sizeof(uint16_t));
363 switch (EXTRACT_16BITS(bp
)) {
365 ND_TCHECK2(*bp
, sizeof(struct in_addr
));
366 addrtostr(bp
, group_buf
, sizeof(group_buf
));
367 bp
+= sizeof(struct in_addr
);
370 ND_TCHECK2(*bp
, sizeof(struct in6_addr
));
371 addrtostr6(bp
, group_buf
, sizeof(group_buf
));
372 bp
+= sizeof(struct in6_addr
);
380 * Options decoding can go here.
382 switch (pgm
->pgm_type
) {
384 ND_PRINT((ndo
, "NAK "));
387 ND_PRINT((ndo
, "NNAK "));
390 ND_PRINT((ndo
, "NCF "));
395 ND_PRINT((ndo
, "(%s -> %s), seq %u",
396 source_buf
, group_buf
, EXTRACT_32BITS(&nak
->pgmn_seq
)));
401 const struct pgm_ack
*ack
;
403 ack
= (const struct pgm_ack
*)(pgm
+ 1);
405 ND_PRINT((ndo
, "ACK seq %u",
406 EXTRACT_32BITS(&ack
->pgma_rx_max_seq
)));
407 bp
= (const u_char
*) (ack
+ 1);
412 ND_PRINT((ndo
, "SPMR"));
416 ND_PRINT((ndo
, "UNKNOWN type 0x%02x", pgm
->pgm_type
));
420 if (pgm
->pgm_options
& PGM_OPT_BIT_PRESENT
) {
423 * make sure there's enough for the first option header
425 if (!ND_TTEST2(*bp
, PGM_MIN_OPT_LEN
)) {
426 ND_PRINT((ndo
, "[|OPT]"));
431 * That option header MUST be an OPT_LENGTH option
432 * (see the first paragraph of section 9.1 in RFC 3208).
435 if ((opt_type
& PGM_OPT_MASK
) != PGM_OPT_LENGTH
) {
436 ND_PRINT((ndo
, "[First option bad, should be PGM_OPT_LENGTH, is %u]", opt_type
& PGM_OPT_MASK
));
441 ND_PRINT((ndo
, "[Bad OPT_LENGTH option, length %u != 4]", opt_len
));
444 opts_len
= EXTRACT_16BITS(bp
);
446 ND_PRINT((ndo
, "[Bad total option length %u < 4]", opts_len
));
449 bp
+= sizeof(uint16_t);
450 ND_PRINT((ndo
, " OPTS LEN %d", opts_len
));
454 if (opts_len
< PGM_MIN_OPT_LEN
) {
455 ND_PRINT((ndo
, "[Total option length leaves no room for final option]"));
460 if (opt_len
< PGM_MIN_OPT_LEN
) {
461 ND_PRINT((ndo
, "[Bad option, length %u < %u]", opt_len
,
465 if (opts_len
< opt_len
) {
466 ND_PRINT((ndo
, "[Total option length leaves no room for final option]"));
469 if (!ND_TTEST2(*bp
, opt_len
- 2)) {
470 ND_PRINT((ndo
, " [|OPT]"));
474 switch (opt_type
& PGM_OPT_MASK
) {
477 ND_PRINT((ndo
, "[Bad OPT_LENGTH option, length %u != 4]", opt_len
));
480 ND_PRINT((ndo
, " OPTS LEN (extra?) %d", EXTRACT_16BITS(bp
)));
481 bp
+= sizeof(uint16_t);
485 case PGM_OPT_FRAGMENT
:
487 ND_PRINT((ndo
, "[Bad OPT_FRAGMENT option, length %u != 16]", opt_len
));
491 seq
= EXTRACT_32BITS(bp
);
492 bp
+= sizeof(uint32_t);
493 offset
= EXTRACT_32BITS(bp
);
494 bp
+= sizeof(uint32_t);
495 len
= EXTRACT_32BITS(bp
);
496 bp
+= sizeof(uint32_t);
497 ND_PRINT((ndo
, " FRAG seq %u off %u len %u", seq
, offset
, len
));
501 case PGM_OPT_NAK_LIST
:
503 opt_len
-= sizeof(uint32_t); /* option header */
504 ND_PRINT((ndo
, " NAK LIST"));
506 if (opt_len
< sizeof(uint32_t)) {
507 ND_PRINT((ndo
, "[Option length not a multiple of 4]"));
510 ND_TCHECK2(*bp
, sizeof(uint32_t));
511 ND_PRINT((ndo
, " %u", EXTRACT_32BITS(bp
)));
512 bp
+= sizeof(uint32_t);
513 opt_len
-= sizeof(uint32_t);
514 opts_len
-= sizeof(uint32_t);
520 ND_PRINT((ndo
, "[Bad OPT_JOIN option, length %u != 8]", opt_len
));
524 seq
= EXTRACT_32BITS(bp
);
525 bp
+= sizeof(uint32_t);
526 ND_PRINT((ndo
, " JOIN %u", seq
));
530 case PGM_OPT_NAK_BO_IVL
:
532 ND_PRINT((ndo
, "[Bad OPT_NAK_BO_IVL option, length %u != 12]", opt_len
));
536 offset
= EXTRACT_32BITS(bp
);
537 bp
+= sizeof(uint32_t);
538 seq
= EXTRACT_32BITS(bp
);
539 bp
+= sizeof(uint32_t);
540 ND_PRINT((ndo
, " BACKOFF ivl %u ivlseq %u", offset
, seq
));
544 case PGM_OPT_NAK_BO_RNG
:
546 ND_PRINT((ndo
, "[Bad OPT_NAK_BO_RNG option, length %u != 12]", opt_len
));
550 offset
= EXTRACT_32BITS(bp
);
551 bp
+= sizeof(uint32_t);
552 seq
= EXTRACT_32BITS(bp
);
553 bp
+= sizeof(uint32_t);
554 ND_PRINT((ndo
, " BACKOFF max %u min %u", offset
, seq
));
558 case PGM_OPT_REDIRECT
:
560 nla_afnum
= EXTRACT_16BITS(bp
);
561 bp
+= (2 * sizeof(uint16_t));
564 if (opt_len
!= 4 + sizeof(struct in_addr
)) {
565 ND_PRINT((ndo
, "[Bad OPT_REDIRECT option, length %u != 4 + address size]", opt_len
));
568 ND_TCHECK2(*bp
, sizeof(struct in_addr
));
569 addrtostr(bp
, nla_buf
, sizeof(nla_buf
));
570 bp
+= sizeof(struct in_addr
);
571 opts_len
-= 4 + sizeof(struct in_addr
);
574 if (opt_len
!= 4 + sizeof(struct in6_addr
)) {
575 ND_PRINT((ndo
, "[Bad OPT_REDIRECT option, length %u != 4 + address size]", opt_len
));
578 ND_TCHECK2(*bp
, sizeof(struct in6_addr
));
579 addrtostr6(bp
, nla_buf
, sizeof(nla_buf
));
580 bp
+= sizeof(struct in6_addr
);
581 opts_len
-= 4 + sizeof(struct in6_addr
);
588 ND_PRINT((ndo
, " REDIRECT %s", nla_buf
));
591 case PGM_OPT_PARITY_PRM
:
593 ND_PRINT((ndo
, "[Bad OPT_PARITY_PRM option, length %u != 8]", opt_len
));
597 len
= EXTRACT_32BITS(bp
);
598 bp
+= sizeof(uint32_t);
599 ND_PRINT((ndo
, " PARITY MAXTGS %u", len
));
603 case PGM_OPT_PARITY_GRP
:
605 ND_PRINT((ndo
, "[Bad OPT_PARITY_GRP option, length %u != 8]", opt_len
));
609 seq
= EXTRACT_32BITS(bp
);
610 bp
+= sizeof(uint32_t);
611 ND_PRINT((ndo
, " PARITY GROUP %u", seq
));
615 case PGM_OPT_CURR_TGSIZE
:
617 ND_PRINT((ndo
, "[Bad OPT_CURR_TGSIZE option, length %u != 8]", opt_len
));
621 len
= EXTRACT_32BITS(bp
);
622 bp
+= sizeof(uint32_t);
623 ND_PRINT((ndo
, " PARITY ATGS %u", len
));
627 case PGM_OPT_NBR_UNREACH
:
629 ND_PRINT((ndo
, "[Bad OPT_NBR_UNREACH option, length %u != 4]", opt_len
));
633 ND_PRINT((ndo
, " NBR_UNREACH"));
637 case PGM_OPT_PATH_NLA
:
638 ND_PRINT((ndo
, " PATH_NLA [%d]", opt_len
));
645 ND_PRINT((ndo
, "[Bad OPT_SYN option, length %u != 4]", opt_len
));
649 ND_PRINT((ndo
, " SYN"));
655 ND_PRINT((ndo
, "[Bad OPT_FIN option, length %u != 4]", opt_len
));
659 ND_PRINT((ndo
, " FIN"));
665 ND_PRINT((ndo
, "[Bad OPT_RST option, length %u != 4]", opt_len
));
669 ND_PRINT((ndo
, " RST"));
674 ND_PRINT((ndo
, " CR"));
681 ND_PRINT((ndo
, "[Bad OPT_CRQST option, length %u != 4]", opt_len
));
685 ND_PRINT((ndo
, " CRQST"));
689 case PGM_OPT_PGMCC_DATA
:
691 offset
= EXTRACT_32BITS(bp
);
692 bp
+= sizeof(uint32_t);
693 nla_afnum
= EXTRACT_16BITS(bp
);
694 bp
+= (2 * sizeof(uint16_t));
697 if (opt_len
!= 12 + sizeof(struct in_addr
)) {
698 ND_PRINT((ndo
, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len
));
701 ND_TCHECK2(*bp
, sizeof(struct in_addr
));
702 addrtostr(bp
, nla_buf
, sizeof(nla_buf
));
703 bp
+= sizeof(struct in_addr
);
704 opts_len
-= 12 + sizeof(struct in_addr
);
707 if (opt_len
!= 12 + sizeof(struct in6_addr
)) {
708 ND_PRINT((ndo
, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len
));
711 ND_TCHECK2(*bp
, sizeof(struct in6_addr
));
712 addrtostr6(bp
, nla_buf
, sizeof(nla_buf
));
713 bp
+= sizeof(struct in6_addr
);
714 opts_len
-= 12 + sizeof(struct in6_addr
);
721 ND_PRINT((ndo
, " PGMCC DATA %u %s", offset
, nla_buf
));
724 case PGM_OPT_PGMCC_FEEDBACK
:
726 offset
= EXTRACT_32BITS(bp
);
727 bp
+= sizeof(uint32_t);
728 nla_afnum
= EXTRACT_16BITS(bp
);
729 bp
+= (2 * sizeof(uint16_t));
732 if (opt_len
!= 12 + sizeof(struct in_addr
)) {
733 ND_PRINT((ndo
, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len
));
736 ND_TCHECK2(*bp
, sizeof(struct in_addr
));
737 addrtostr(bp
, nla_buf
, sizeof(nla_buf
));
738 bp
+= sizeof(struct in_addr
);
739 opts_len
-= 12 + sizeof(struct in_addr
);
742 if (opt_len
!= 12 + sizeof(struct in6_addr
)) {
743 ND_PRINT((ndo
, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len
));
746 ND_TCHECK2(*bp
, sizeof(struct in6_addr
));
747 addrtostr6(bp
, nla_buf
, sizeof(nla_buf
));
748 bp
+= sizeof(struct in6_addr
);
749 opts_len
-= 12 + sizeof(struct in6_addr
);
756 ND_PRINT((ndo
, " PGMCC FEEDBACK %u %s", offset
, nla_buf
));
760 ND_PRINT((ndo
, " OPT_%02X [%d] ", opt_type
, opt_len
));
766 if (opt_type
& PGM_OPT_END
)
771 ND_PRINT((ndo
, " [%u]", length
));
772 if (ndo
->ndo_packettype
== PT_PGM_ZMTP1
&&
773 (pgm
->pgm_type
== PGM_ODATA
|| pgm
->pgm_type
== PGM_RDATA
))
774 zmtp1_print_datagram(ndo
, bp
, EXTRACT_16BITS(&pgm
->pgm_length
));
779 ND_PRINT((ndo
, "[|pgm]"));
781 ND_PRINT((ndo
, ">"));