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)
16 #include <sys/cdefs.h>
18 __RCSID("$NetBSD: print-pgm.c,v 1.6 2014/11/20 03:05:03 christos Exp $");
21 #define NETDISSECT_REWORKED
26 #include <tcpdump-stdinc.h>
28 #include "interface.h"
30 #include "addrtoname.h"
40 * PGM header (RFC 3208)
54 uint32_t pgms_trailseq
;
55 uint32_t pgms_leadseq
;
56 uint16_t pgms_nla_afi
;
57 uint16_t pgms_reserved
;
58 /* ... uint8_t pgms_nla[0]; */
64 uint16_t pgmn_source_afi
;
65 uint16_t pgmn_reserved
;
66 /* ... uint8_t pgmn_source[0]; */
67 /* ... uint16_t pgmn_group_afi */
68 /* ... uint16_t pgmn_reserved2; */
69 /* ... uint8_t pgmn_group[0]; */
74 uint32_t pgma_rx_max_seq
;
82 uint16_t pgmp_reserved
;
89 uint16_t pgmp_subtype
;
90 uint16_t pgmp_nla_afi
;
91 uint16_t pgmp_reserved
;
92 /* ... uint8_t pgmp_nla[0]; */
98 uint32_t pgmd_trailseq
;
102 typedef enum _pgm_type
{
103 PGM_SPM
= 0, /* source path message */
104 PGM_POLL
= 1, /* POLL Request */
105 PGM_POLR
= 2, /* POLL Response */
106 PGM_ODATA
= 4, /* original data */
107 PGM_RDATA
= 5, /* repair data */
108 PGM_NAK
= 8, /* NAK */
109 PGM_NULLNAK
= 9, /* Null NAK */
110 PGM_NCF
= 10, /* NAK Confirmation */
111 PGM_ACK
= 11, /* ACK for congestion control */
112 PGM_SPMR
= 12, /* SPM request */
116 #define PGM_OPT_BIT_PRESENT 0x01
117 #define PGM_OPT_BIT_NETWORK 0x02
118 #define PGM_OPT_BIT_VAR_PKTLEN 0x40
119 #define PGM_OPT_BIT_PARITY 0x80
121 #define PGM_OPT_LENGTH 0x00
122 #define PGM_OPT_FRAGMENT 0x01
123 #define PGM_OPT_NAK_LIST 0x02
124 #define PGM_OPT_JOIN 0x03
125 #define PGM_OPT_NAK_BO_IVL 0x04
126 #define PGM_OPT_NAK_BO_RNG 0x05
128 #define PGM_OPT_REDIRECT 0x07
129 #define PGM_OPT_PARITY_PRM 0x08
130 #define PGM_OPT_PARITY_GRP 0x09
131 #define PGM_OPT_CURR_TGSIZE 0x0A
132 #define PGM_OPT_NBR_UNREACH 0x0B
133 #define PGM_OPT_PATH_NLA 0x0C
135 #define PGM_OPT_SYN 0x0D
136 #define PGM_OPT_FIN 0x0E
137 #define PGM_OPT_RST 0x0F
138 #define PGM_OPT_CR 0x10
139 #define PGM_OPT_CRQST 0x11
141 #define PGM_OPT_PGMCC_DATA 0x12
142 #define PGM_OPT_PGMCC_FEEDBACK 0x13
144 #define PGM_OPT_MASK 0x7f
146 #define PGM_OPT_END 0x80 /* end of options marker */
148 #define PGM_MIN_OPT_LEN 4
151 pgm_print(netdissect_options
*ndo
,
152 register const u_char
*bp
, register u_int length
,
153 register const u_char
*bp2
)
155 register const struct pgm_header
*pgm
;
156 register const struct ip
*ip
;
158 uint16_t sport
, dport
;
163 char nla_buf
[INET6_ADDRSTRLEN
];
164 register const struct ip6_hdr
*ip6
;
166 char nla_buf
[INET_ADDRSTRLEN
];
168 uint8_t opt_type
, opt_len
;
169 uint32_t seq
, opts_len
, len
, offset
;
171 pgm
= (struct pgm_header
*)bp
;
172 ip
= (struct ip
*)bp2
;
175 ip6
= (struct ip6_hdr
*)bp2
;
180 ND_PRINT((ndo
, "Can't handle IPv6"));
185 if (!ND_TTEST(pgm
->pgm_dport
)) {
188 ND_PRINT((ndo
, "%s > %s: [|pgm]",
189 ip6addr_string(ndo
, &ip6
->ip6_src
),
190 ip6addr_string(ndo
, &ip6
->ip6_dst
)));
195 ND_PRINT((ndo
, "%s > %s: [|pgm]",
196 ipaddr_string(ndo
, &ip
->ip_src
),
197 ipaddr_string(ndo
, &ip
->ip_dst
)));
202 sport
= EXTRACT_16BITS(&pgm
->pgm_sport
);
203 dport
= EXTRACT_16BITS(&pgm
->pgm_dport
);
207 if (ip6
->ip6_nxt
== IPPROTO_PGM
) {
208 ND_PRINT((ndo
, "%s.%s > %s.%s: ",
209 ip6addr_string(ndo
, &ip6
->ip6_src
),
210 tcpport_string(sport
),
211 ip6addr_string(ndo
, &ip6
->ip6_dst
),
212 tcpport_string(dport
)));
214 ND_PRINT((ndo
, "%s > %s: ",
215 tcpport_string(sport
), tcpport_string(dport
)));
220 if (ip
->ip_p
== IPPROTO_PGM
) {
221 ND_PRINT((ndo
, "%s.%s > %s.%s: ",
222 ipaddr_string(ndo
, &ip
->ip_src
),
223 tcpport_string(sport
),
224 ipaddr_string(ndo
, &ip
->ip_dst
),
225 tcpport_string(dport
)));
227 ND_PRINT((ndo
, "%s > %s: ",
228 tcpport_string(sport
), tcpport_string(dport
)));
234 ND_PRINT((ndo
, "PGM, length %u", EXTRACT_16BITS(&pgm
->pgm_length
)));
239 ND_PRINT((ndo
, " 0x%02x%02x%02x%02x%02x%02x ",
246 switch (pgm
->pgm_type
) {
250 spm
= (struct pgm_spm
*)(pgm
+ 1);
253 switch (EXTRACT_16BITS(&spm
->pgms_nla_afi
)) {
255 addr_size
= sizeof(struct in_addr
);
260 addr_size
= sizeof(struct in6_addr
);
268 bp
= (u_char
*) (spm
+ 1);
269 ND_TCHECK2(*bp
, addr_size
);
273 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
274 ND_PRINT((ndo
, "SPM seq %u trail %u lead %u nla %s",
275 EXTRACT_32BITS(&spm
->pgms_seq
),
276 EXTRACT_32BITS(&spm
->pgms_trailseq
),
277 EXTRACT_32BITS(&spm
->pgms_leadseq
),
283 struct pgm_poll
*poll
;
285 poll
= (struct pgm_poll
*)(pgm
+ 1);
287 ND_PRINT((ndo
, "POLL seq %u round %u",
288 EXTRACT_32BITS(&poll
->pgmp_seq
),
289 EXTRACT_16BITS(&poll
->pgmp_round
)));
290 bp
= (u_char
*) (poll
+ 1);
294 struct pgm_polr
*polr
;
295 uint32_t ivl
, rnd
, mask
;
297 polr
= (struct pgm_polr
*)(pgm
+ 1);
300 switch (EXTRACT_16BITS(&polr
->pgmp_nla_afi
)) {
302 addr_size
= sizeof(struct in_addr
);
307 addr_size
= sizeof(struct in6_addr
);
315 bp
= (u_char
*) (polr
+ 1);
316 ND_TCHECK2(*bp
, addr_size
);
320 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
322 ND_TCHECK2(*bp
, sizeof(uint32_t));
323 ivl
= EXTRACT_32BITS(bp
);
324 bp
+= sizeof(uint32_t);
326 ND_TCHECK2(*bp
, sizeof(uint32_t));
327 rnd
= EXTRACT_32BITS(bp
);
328 bp
+= sizeof(uint32_t);
330 ND_TCHECK2(*bp
, sizeof(uint32_t));
331 mask
= EXTRACT_32BITS(bp
);
332 bp
+= sizeof(uint32_t);
334 ND_PRINT((ndo
, "POLR seq %u round %u nla %s ivl %u rnd 0x%08x "
335 "mask 0x%08x", EXTRACT_32BITS(&polr
->pgmp_seq
),
336 EXTRACT_16BITS(&polr
->pgmp_round
), nla_buf
, ivl
, rnd
, mask
));
340 struct pgm_data
*odata
;
342 odata
= (struct pgm_data
*)(pgm
+ 1);
344 ND_PRINT((ndo
, "ODATA trail %u seq %u",
345 EXTRACT_32BITS(&odata
->pgmd_trailseq
),
346 EXTRACT_32BITS(&odata
->pgmd_seq
)));
347 bp
= (u_char
*) (odata
+ 1);
352 struct pgm_data
*rdata
;
354 rdata
= (struct pgm_data
*)(pgm
+ 1);
356 ND_PRINT((ndo
, "RDATA trail %u seq %u",
357 EXTRACT_32BITS(&rdata
->pgmd_trailseq
),
358 EXTRACT_32BITS(&rdata
->pgmd_seq
)));
359 bp
= (u_char
*) (rdata
+ 1);
367 const void *source
, *group
;
368 int source_af
, group_af
;
370 char source_buf
[INET6_ADDRSTRLEN
], group_buf
[INET6_ADDRSTRLEN
];
372 char source_buf
[INET_ADDRSTRLEN
], group_buf
[INET_ADDRSTRLEN
];
375 nak
= (struct pgm_nak
*)(pgm
+ 1);
379 * Skip past the source, saving info along the way
380 * and stopping if we don't have enough.
382 switch (EXTRACT_16BITS(&nak
->pgmn_source_afi
)) {
384 addr_size
= sizeof(struct in_addr
);
389 addr_size
= sizeof(struct in6_addr
);
390 source_af
= AF_INET6
;
397 bp
= (u_char
*) (nak
+ 1);
398 ND_TCHECK2(*bp
, addr_size
);
403 * Skip past the group, saving info along the way
404 * and stopping if we don't have enough.
406 switch (EXTRACT_16BITS(bp
)) {
408 addr_size
= sizeof(struct in_addr
);
413 addr_size
= sizeof(struct in6_addr
);
421 bp
+= (2 * sizeof(uint16_t));
422 ND_TCHECK2(*bp
, addr_size
);
427 * Options decoding can go here.
429 inet_ntop(source_af
, source
, source_buf
, sizeof(source_buf
));
430 inet_ntop(group_af
, group
, group_buf
, sizeof(group_buf
));
431 switch (pgm
->pgm_type
) {
433 ND_PRINT((ndo
, "NAK "));
436 ND_PRINT((ndo
, "NNAK "));
439 ND_PRINT((ndo
, "NCF "));
444 ND_PRINT((ndo
, "(%s -> %s), seq %u",
445 source_buf
, group_buf
, EXTRACT_32BITS(&nak
->pgmn_seq
)));
452 ack
= (struct pgm_ack
*)(pgm
+ 1);
454 ND_PRINT((ndo
, "ACK seq %u",
455 EXTRACT_32BITS(&ack
->pgma_rx_max_seq
)));
456 bp
= (u_char
*) (ack
+ 1);
461 ND_PRINT((ndo
, "SPMR"));
465 ND_PRINT((ndo
, "UNKNOWN type 0x%02x", pgm
->pgm_type
));
469 if (pgm
->pgm_options
& PGM_OPT_BIT_PRESENT
) {
472 * make sure there's enough for the first option header
474 if (!ND_TTEST2(*bp
, PGM_MIN_OPT_LEN
)) {
475 ND_PRINT((ndo
, "[|OPT]"));
480 * That option header MUST be an OPT_LENGTH option
481 * (see the first paragraph of section 9.1 in RFC 3208).
484 if ((opt_type
& PGM_OPT_MASK
) != PGM_OPT_LENGTH
) {
485 ND_PRINT((ndo
, "[First option bad, should be PGM_OPT_LENGTH, is %u]", opt_type
& PGM_OPT_MASK
));
490 ND_PRINT((ndo
, "[Bad OPT_LENGTH option, length %u != 4]", opt_len
));
493 opts_len
= EXTRACT_16BITS(bp
);
495 ND_PRINT((ndo
, "[Bad total option length %u < 4]", opts_len
));
498 bp
+= sizeof(uint16_t);
499 ND_PRINT((ndo
, " OPTS LEN %d", opts_len
));
503 if (opts_len
< PGM_MIN_OPT_LEN
) {
504 ND_PRINT((ndo
, "[Total option length leaves no room for final option]"));
509 if (opt_len
< PGM_MIN_OPT_LEN
) {
510 ND_PRINT((ndo
, "[Bad option, length %u < %u]", opt_len
,
514 if (opts_len
< opt_len
) {
515 ND_PRINT((ndo
, "[Total option length leaves no room for final option]"));
518 if (!ND_TTEST2(*bp
, opt_len
- 2)) {
519 ND_PRINT((ndo
, " [|OPT]"));
523 switch (opt_type
& PGM_OPT_MASK
) {
526 ND_PRINT((ndo
, "[Bad OPT_LENGTH option, length %u != 4]", opt_len
));
529 ND_PRINT((ndo
, " OPTS LEN (extra?) %d", EXTRACT_16BITS(bp
)));
530 bp
+= sizeof(uint16_t);
534 case PGM_OPT_FRAGMENT
:
536 ND_PRINT((ndo
, "[Bad OPT_FRAGMENT option, length %u != 16]", opt_len
));
540 seq
= EXTRACT_32BITS(bp
);
541 bp
+= sizeof(uint32_t);
542 offset
= EXTRACT_32BITS(bp
);
543 bp
+= sizeof(uint32_t);
544 len
= EXTRACT_32BITS(bp
);
545 bp
+= sizeof(uint32_t);
546 ND_PRINT((ndo
, " FRAG seq %u off %u len %u", seq
, offset
, len
));
550 case PGM_OPT_NAK_LIST
:
552 opt_len
-= sizeof(uint32_t); /* option header */
553 ND_PRINT((ndo
, " NAK LIST"));
555 if (opt_len
< sizeof(uint32_t)) {
556 ND_PRINT((ndo
, "[Option length not a multiple of 4]"));
559 ND_TCHECK2(*bp
, sizeof(uint32_t));
560 ND_PRINT((ndo
, " %u", EXTRACT_32BITS(bp
)));
561 bp
+= sizeof(uint32_t);
562 opt_len
-= sizeof(uint32_t);
563 opts_len
-= sizeof(uint32_t);
569 ND_PRINT((ndo
, "[Bad OPT_JOIN option, length %u != 8]", opt_len
));
573 seq
= EXTRACT_32BITS(bp
);
574 bp
+= sizeof(uint32_t);
575 ND_PRINT((ndo
, " JOIN %u", seq
));
579 case PGM_OPT_NAK_BO_IVL
:
581 ND_PRINT((ndo
, "[Bad OPT_NAK_BO_IVL option, length %u != 12]", opt_len
));
585 offset
= EXTRACT_32BITS(bp
);
586 bp
+= sizeof(uint32_t);
587 seq
= EXTRACT_32BITS(bp
);
588 bp
+= sizeof(uint32_t);
589 ND_PRINT((ndo
, " BACKOFF ivl %u ivlseq %u", offset
, seq
));
593 case PGM_OPT_NAK_BO_RNG
:
595 ND_PRINT((ndo
, "[Bad OPT_NAK_BO_RNG option, length %u != 12]", opt_len
));
599 offset
= EXTRACT_32BITS(bp
);
600 bp
+= sizeof(uint32_t);
601 seq
= EXTRACT_32BITS(bp
);
602 bp
+= sizeof(uint32_t);
603 ND_PRINT((ndo
, " BACKOFF max %u min %u", offset
, seq
));
607 case PGM_OPT_REDIRECT
:
609 switch (EXTRACT_16BITS(bp
)) {
611 addr_size
= sizeof(struct in_addr
);
616 addr_size
= sizeof(struct in6_addr
);
624 bp
+= (2 * sizeof(uint16_t));
625 if (opt_len
!= 4 + addr_size
) {
626 ND_PRINT((ndo
, "[Bad OPT_REDIRECT option, length %u != 4 + address size]", opt_len
));
629 ND_TCHECK2(*bp
, addr_size
);
633 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
634 ND_PRINT((ndo
, " REDIRECT %s", (char *)nla
));
635 opts_len
-= 4 + addr_size
;
638 case PGM_OPT_PARITY_PRM
:
640 ND_PRINT((ndo
, "[Bad OPT_PARITY_PRM option, length %u != 8]", opt_len
));
644 len
= EXTRACT_32BITS(bp
);
645 bp
+= sizeof(uint32_t);
646 ND_PRINT((ndo
, " PARITY MAXTGS %u", len
));
650 case PGM_OPT_PARITY_GRP
:
652 ND_PRINT((ndo
, "[Bad OPT_PARITY_GRP option, length %u != 8]", opt_len
));
656 seq
= EXTRACT_32BITS(bp
);
657 bp
+= sizeof(uint32_t);
658 ND_PRINT((ndo
, " PARITY GROUP %u", seq
));
662 case PGM_OPT_CURR_TGSIZE
:
664 ND_PRINT((ndo
, "[Bad OPT_CURR_TGSIZE option, length %u != 8]", opt_len
));
668 len
= EXTRACT_32BITS(bp
);
669 bp
+= sizeof(uint32_t);
670 ND_PRINT((ndo
, " PARITY ATGS %u", len
));
674 case PGM_OPT_NBR_UNREACH
:
676 ND_PRINT((ndo
, "[Bad OPT_NBR_UNREACH option, length %u != 4]", opt_len
));
680 ND_PRINT((ndo
, " NBR_UNREACH"));
684 case PGM_OPT_PATH_NLA
:
685 ND_PRINT((ndo
, " PATH_NLA [%d]", opt_len
));
692 ND_PRINT((ndo
, "[Bad OPT_SYN option, length %u != 4]", opt_len
));
696 ND_PRINT((ndo
, " SYN"));
702 ND_PRINT((ndo
, "[Bad OPT_FIN option, length %u != 4]", opt_len
));
706 ND_PRINT((ndo
, " FIN"));
712 ND_PRINT((ndo
, "[Bad OPT_RST option, length %u != 4]", opt_len
));
716 ND_PRINT((ndo
, " RST"));
721 ND_PRINT((ndo
, " CR"));
728 ND_PRINT((ndo
, "[Bad OPT_CRQST option, length %u != 4]", opt_len
));
732 ND_PRINT((ndo
, " CRQST"));
736 case PGM_OPT_PGMCC_DATA
:
738 offset
= EXTRACT_32BITS(bp
);
739 bp
+= sizeof(uint32_t);
740 switch (EXTRACT_16BITS(bp
)) {
742 addr_size
= sizeof(struct in_addr
);
747 addr_size
= sizeof(struct in6_addr
);
755 bp
+= (2 * sizeof(uint16_t));
756 if (opt_len
!= 12 + addr_size
) {
757 ND_PRINT((ndo
, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len
));
760 ND_TCHECK2(*bp
, addr_size
);
764 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
765 ND_PRINT((ndo
, " PGMCC DATA %u %s", offset
, (char*)nla
));
769 case PGM_OPT_PGMCC_FEEDBACK
:
771 offset
= EXTRACT_32BITS(bp
);
772 bp
+= sizeof(uint32_t);
773 switch (EXTRACT_16BITS(bp
)) {
775 addr_size
= sizeof(struct in_addr
);
780 addr_size
= sizeof(struct in6_addr
);
788 bp
+= (2 * sizeof(uint16_t));
789 if (opt_len
!= 12 + addr_size
) {
790 ND_PRINT((ndo
, "[Bad OPT_PGMCC_FEEDBACK option, length %u != 12 + address size]", opt_len
));
793 ND_TCHECK2(*bp
, addr_size
);
797 inet_ntop(nla_af
, nla
, nla_buf
, sizeof(nla_buf
));
798 ND_PRINT((ndo
, " PGMCC FEEDBACK %u %s", offset
, (char*)nla
));
803 ND_PRINT((ndo
, " OPT_%02X [%d] ", opt_type
, opt_len
));
809 if (opt_type
& PGM_OPT_END
)
814 ND_PRINT((ndo
, " [%u]", length
));
815 if (ndo
->ndo_packettype
== PT_PGM_ZMTP1
&&
816 (pgm
->pgm_type
== PGM_ODATA
|| pgm
->pgm_type
== PGM_RDATA
))
817 zmtp1_print_datagram(ndo
, bp
, EXTRACT_16BITS(&pgm
->pgm_length
));
822 ND_PRINT((ndo
, "[|pgm]"));
824 ND_PRINT((ndo
, ">"));