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 #define NETDISSECT_REWORKED
21 #include <tcpdump-stdinc.h>
23 #include "interface.h"
25 #include "addrtoname.h"
35 * PGM header (RFC 3208)
49 uint32_t pgms_trailseq;
50 uint32_t pgms_leadseq;
51 uint16_t pgms_nla_afi;
52 uint16_t pgms_reserved;
53 /* ... uint8_t pgms_nla[0]; */
59 uint16_t pgmn_source_afi;
60 uint16_t pgmn_reserved;
61 /* ... uint8_t pgmn_source[0]; */
62 /* ... uint16_t pgmn_group_afi */
63 /* ... uint16_t pgmn_reserved2; */
64 /* ... uint8_t pgmn_group[0]; */
69 uint32_t pgma_rx_max_seq;
77 uint16_t pgmp_reserved;
84 uint16_t pgmp_subtype;
85 uint16_t pgmp_nla_afi;
86 uint16_t pgmp_reserved;
87 /* ... uint8_t pgmp_nla[0]; */
93 uint32_t pgmd_trailseq;
97 typedef enum _pgm_type {
98 PGM_SPM = 0, /* source path message */
99 PGM_POLL = 1, /* POLL Request */
100 PGM_POLR = 2, /* POLL Response */
101 PGM_ODATA = 4, /* original data */
102 PGM_RDATA = 5, /* repair data */
103 PGM_NAK = 8, /* NAK */
104 PGM_NULLNAK = 9, /* Null NAK */
105 PGM_NCF = 10, /* NAK Confirmation */
106 PGM_ACK = 11, /* ACK for congestion control */
107 PGM_SPMR = 12, /* SPM request */
111 #define PGM_OPT_BIT_PRESENT 0x01
112 #define PGM_OPT_BIT_NETWORK 0x02
113 #define PGM_OPT_BIT_VAR_PKTLEN 0x40
114 #define PGM_OPT_BIT_PARITY 0x80
116 #define PGM_OPT_LENGTH 0x00
117 #define PGM_OPT_FRAGMENT 0x01
118 #define PGM_OPT_NAK_LIST 0x02
119 #define PGM_OPT_JOIN 0x03
120 #define PGM_OPT_NAK_BO_IVL 0x04
121 #define PGM_OPT_NAK_BO_RNG 0x05
123 #define PGM_OPT_REDIRECT 0x07
124 #define PGM_OPT_PARITY_PRM 0x08
125 #define PGM_OPT_PARITY_GRP 0x09
126 #define PGM_OPT_CURR_TGSIZE 0x0A
127 #define PGM_OPT_NBR_UNREACH 0x0B
128 #define PGM_OPT_PATH_NLA 0x0C
130 #define PGM_OPT_SYN 0x0D
131 #define PGM_OPT_FIN 0x0E
132 #define PGM_OPT_RST 0x0F
133 #define PGM_OPT_CR 0x10
134 #define PGM_OPT_CRQST 0x11
136 #define PGM_OPT_PGMCC_DATA 0x12
137 #define PGM_OPT_PGMCC_FEEDBACK 0x13
139 #define PGM_OPT_MASK 0x7f
141 #define PGM_OPT_END 0x80 /* end of options marker */
143 #define PGM_MIN_OPT_LEN 4
146 pgm_print(netdissect_options *ndo,
147 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 uint16_t sport, dport;
158 char nla_buf[INET6_ADDRSTRLEN];
159 register const struct ip6_hdr *ip6;
161 char nla_buf[INET_ADDRSTRLEN];
163 uint8_t opt_type, opt_len;
164 uint32_t seq, opts_len, len, offset;
166 pgm = (struct pgm_header *)bp;
167 ip = (struct ip *)bp2;
170 ip6 = (struct ip6_hdr *)bp2;
175 ND_PRINT((ndo, "Can't handle IPv6"));
180 if (!ND_TTEST(pgm->pgm_dport)) {
183 ND_PRINT((ndo, "%s > %s: [|pgm]",
184 ip6addr_string(ndo, &ip6->ip6_src),
185 ip6addr_string(ndo, &ip6->ip6_dst)));
190 ND_PRINT((ndo, "%s > %s: [|pgm]",
191 ipaddr_string(ndo, &ip->ip_src),
192 ipaddr_string(ndo, &ip->ip_dst)));
197 sport = EXTRACT_16BITS(&pgm->pgm_sport);
198 dport = EXTRACT_16BITS(&pgm->pgm_dport);
202 if (ip6->ip6_nxt == IPPROTO_PGM) {
203 ND_PRINT((ndo, "%s.%s > %s.%s: ",
204 ip6addr_string(ndo, &ip6->ip6_src),
205 tcpport_string(sport),
206 ip6addr_string(ndo, &ip6->ip6_dst),
207 tcpport_string(dport)));
209 ND_PRINT((ndo, "%s > %s: ",
210 tcpport_string(sport), tcpport_string(dport)));
215 if (ip->ip_p == IPPROTO_PGM) {
216 ND_PRINT((ndo, "%s.%s > %s.%s: ",
217 ipaddr_string(ndo, &ip->ip_src),
218 tcpport_string(sport),
219 ipaddr_string(ndo, &ip->ip_dst),
220 tcpport_string(dport)));
222 ND_PRINT((ndo, "%s > %s: ",
223 tcpport_string(sport), tcpport_string(dport)));
229 ND_PRINT((ndo, "PGM, length %u", EXTRACT_16BITS(&pgm->pgm_length)));
234 ND_PRINT((ndo, " 0x%02x%02x%02x%02x%02x%02x ",
241 switch (pgm->pgm_type) {
245 spm = (struct pgm_spm *)(pgm + 1);
248 switch (EXTRACT_16BITS(&spm->pgms_nla_afi)) {
250 addr_size = sizeof(struct in_addr);
255 addr_size = sizeof(struct in6_addr);
263 bp = (u_char *) (spm + 1);
264 ND_TCHECK2(*bp, addr_size);
268 inet_ntop(nla_af, nla, nla_buf, sizeof(nla_buf));
269 ND_PRINT((ndo, "SPM seq %u trail %u lead %u nla %s",
270 EXTRACT_32BITS(&spm->pgms_seq),
271 EXTRACT_32BITS(&spm->pgms_trailseq),
272 EXTRACT_32BITS(&spm->pgms_leadseq),
278 struct pgm_poll *poll;
280 poll = (struct pgm_poll *)(pgm + 1);
282 ND_PRINT((ndo, "POLL seq %u round %u",
283 EXTRACT_32BITS(&poll->pgmp_seq),
284 EXTRACT_16BITS(&poll->pgmp_round)));
285 bp = (u_char *) (poll + 1);
289 struct pgm_polr *polr;
290 uint32_t ivl, rnd, mask;
292 polr = (struct pgm_polr *)(pgm + 1);
295 switch (EXTRACT_16BITS(&polr->pgmp_nla_afi)) {
297 addr_size = sizeof(struct in_addr);
302 addr_size = sizeof(struct in6_addr);
310 bp = (u_char *) (polr + 1);
311 ND_TCHECK2(*bp, addr_size);
315 inet_ntop(nla_af, nla, nla_buf, sizeof(nla_buf));
317 ND_TCHECK2(*bp, sizeof(uint32_t));
318 ivl = EXTRACT_32BITS(bp);
319 bp += sizeof(uint32_t);
321 ND_TCHECK2(*bp, sizeof(uint32_t));
322 rnd = EXTRACT_32BITS(bp);
323 bp += sizeof(uint32_t);
325 ND_TCHECK2(*bp, sizeof(uint32_t));
326 mask = EXTRACT_32BITS(bp);
327 bp += sizeof(uint32_t);
329 ND_PRINT((ndo, "POLR seq %u round %u nla %s ivl %u rnd 0x%08x "
330 "mask 0x%08x", EXTRACT_32BITS(&polr->pgmp_seq),
331 EXTRACT_16BITS(&polr->pgmp_round), nla_buf, ivl, rnd, mask));
335 struct pgm_data *odata;
337 odata = (struct pgm_data *)(pgm + 1);
339 ND_PRINT((ndo, "ODATA trail %u seq %u",
340 EXTRACT_32BITS(&odata->pgmd_trailseq),
341 EXTRACT_32BITS(&odata->pgmd_seq)));
342 bp = (u_char *) (odata + 1);
347 struct pgm_data *rdata;
349 rdata = (struct pgm_data *)(pgm + 1);
351 ND_PRINT((ndo, "RDATA trail %u seq %u",
352 EXTRACT_32BITS(&rdata->pgmd_trailseq),
353 EXTRACT_32BITS(&rdata->pgmd_seq)));
354 bp = (u_char *) (rdata + 1);
362 const void *source, *group;
363 int source_af, group_af;
365 char source_buf[INET6_ADDRSTRLEN], group_buf[INET6_ADDRSTRLEN];
367 char source_buf[INET_ADDRSTRLEN], group_buf[INET_ADDRSTRLEN];
370 nak = (struct pgm_nak *)(pgm + 1);
374 * Skip past the source, saving info along the way
375 * and stopping if we don't have enough.
377 switch (EXTRACT_16BITS(&nak->pgmn_source_afi)) {
379 addr_size = sizeof(struct in_addr);
384 addr_size = sizeof(struct in6_addr);
385 source_af = AF_INET6;
392 bp = (u_char *) (nak + 1);
393 ND_TCHECK2(*bp, addr_size);
398 * Skip past the group, saving info along the way
399 * and stopping if we don't have enough.
401 switch (EXTRACT_16BITS(bp)) {
403 addr_size = sizeof(struct in_addr);
408 addr_size = sizeof(struct in6_addr);
416 bp += (2 * sizeof(uint16_t));
417 ND_TCHECK2(*bp, addr_size);
422 * Options decoding can go here.
424 inet_ntop(source_af, source, source_buf, sizeof(source_buf));
425 inet_ntop(group_af, group, group_buf, sizeof(group_buf));
426 switch (pgm->pgm_type) {
428 ND_PRINT((ndo, "NAK "));
431 ND_PRINT((ndo, "NNAK "));
434 ND_PRINT((ndo, "NCF "));
439 ND_PRINT((ndo, "(%s -> %s), seq %u",
440 source_buf, group_buf, EXTRACT_32BITS(&nak->pgmn_seq)));
447 ack = (struct pgm_ack *)(pgm + 1);
449 ND_PRINT((ndo, "ACK seq %u",
450 EXTRACT_32BITS(&ack->pgma_rx_max_seq)));
451 bp = (u_char *) (ack + 1);
456 ND_PRINT((ndo, "SPMR"));
460 ND_PRINT((ndo, "UNKNOWN type 0x%02x", pgm->pgm_type));
464 if (pgm->pgm_options & PGM_OPT_BIT_PRESENT) {
467 * make sure there's enough for the first option header
469 if (!ND_TTEST2(*bp, PGM_MIN_OPT_LEN)) {
470 ND_PRINT((ndo, "[|OPT]"));
475 * That option header MUST be an OPT_LENGTH option
476 * (see the first paragraph of section 9.1 in RFC 3208).
479 if ((opt_type & PGM_OPT_MASK) != PGM_OPT_LENGTH) {
480 ND_PRINT((ndo, "[First option bad, should be PGM_OPT_LENGTH, is %u]", opt_type & PGM_OPT_MASK));
485 ND_PRINT((ndo, "[Bad OPT_LENGTH option, length %u != 4]", opt_len));
488 opts_len = EXTRACT_16BITS(bp);
490 ND_PRINT((ndo, "[Bad total option length %u < 4]", opts_len));
493 bp += sizeof(uint16_t);
494 ND_PRINT((ndo, " OPTS LEN %d", opts_len));
498 if (opts_len < PGM_MIN_OPT_LEN) {
499 ND_PRINT((ndo, "[Total option length leaves no room for final option]"));
504 if (opt_len < PGM_MIN_OPT_LEN) {
505 ND_PRINT((ndo, "[Bad option, length %u < %u]", opt_len,
509 if (opts_len < opt_len) {
510 ND_PRINT((ndo, "[Total option length leaves no room for final option]"));
513 if (!ND_TTEST2(*bp, opt_len - 2)) {
514 ND_PRINT((ndo, " [|OPT]"));
518 switch (opt_type & PGM_OPT_MASK) {
521 ND_PRINT((ndo, "[Bad OPT_LENGTH option, length %u != 4]", opt_len));
524 ND_PRINT((ndo, " OPTS LEN (extra?) %d", EXTRACT_16BITS(bp)));
525 bp += sizeof(uint16_t);
529 case PGM_OPT_FRAGMENT:
531 ND_PRINT((ndo, "[Bad OPT_FRAGMENT option, length %u != 16]", opt_len));
535 seq = EXTRACT_32BITS(bp);
536 bp += sizeof(uint32_t);
537 offset = EXTRACT_32BITS(bp);
538 bp += sizeof(uint32_t);
539 len = EXTRACT_32BITS(bp);
540 bp += sizeof(uint32_t);
541 ND_PRINT((ndo, " FRAG seq %u off %u len %u", seq, offset, len));
545 case PGM_OPT_NAK_LIST:
547 opt_len -= sizeof(uint32_t); /* option header */
548 ND_PRINT((ndo, " NAK LIST"));
550 if (opt_len < sizeof(uint32_t)) {
551 ND_PRINT((ndo, "[Option length not a multiple of 4]"));
554 ND_TCHECK2(*bp, sizeof(uint32_t));
555 ND_PRINT((ndo, " %u", EXTRACT_32BITS(bp)));
556 bp += sizeof(uint32_t);
557 opt_len -= sizeof(uint32_t);
558 opts_len -= sizeof(uint32_t);
564 ND_PRINT((ndo, "[Bad OPT_JOIN option, length %u != 8]", opt_len));
568 seq = EXTRACT_32BITS(bp);
569 bp += sizeof(uint32_t);
570 ND_PRINT((ndo, " JOIN %u", seq));
574 case PGM_OPT_NAK_BO_IVL:
576 ND_PRINT((ndo, "[Bad OPT_NAK_BO_IVL option, length %u != 12]", opt_len));
580 offset = EXTRACT_32BITS(bp);
581 bp += sizeof(uint32_t);
582 seq = EXTRACT_32BITS(bp);
583 bp += sizeof(uint32_t);
584 ND_PRINT((ndo, " BACKOFF ivl %u ivlseq %u", offset, seq));
588 case PGM_OPT_NAK_BO_RNG:
590 ND_PRINT((ndo, "[Bad OPT_NAK_BO_RNG option, length %u != 12]", opt_len));
594 offset = EXTRACT_32BITS(bp);
595 bp += sizeof(uint32_t);
596 seq = EXTRACT_32BITS(bp);
597 bp += sizeof(uint32_t);
598 ND_PRINT((ndo, " BACKOFF max %u min %u", offset, seq));
602 case PGM_OPT_REDIRECT:
604 switch (EXTRACT_16BITS(bp)) {
606 addr_size = sizeof(struct in_addr);
611 addr_size = sizeof(struct in6_addr);
619 bp += (2 * sizeof(uint16_t));
620 if (opt_len != 4 + addr_size) {
621 ND_PRINT((ndo, "[Bad OPT_REDIRECT option, length %u != 4 + address size]", opt_len));
624 ND_TCHECK2(*bp, addr_size);
628 inet_ntop(nla_af, nla, nla_buf, sizeof(nla_buf));
629 ND_PRINT((ndo, " REDIRECT %s", (char *)nla));
630 opts_len -= 4 + addr_size;
633 case PGM_OPT_PARITY_PRM:
635 ND_PRINT((ndo, "[Bad OPT_PARITY_PRM option, length %u != 8]", opt_len));
639 len = EXTRACT_32BITS(bp);
640 bp += sizeof(uint32_t);
641 ND_PRINT((ndo, " PARITY MAXTGS %u", len));
645 case PGM_OPT_PARITY_GRP:
647 ND_PRINT((ndo, "[Bad OPT_PARITY_GRP option, length %u != 8]", opt_len));
651 seq = EXTRACT_32BITS(bp);
652 bp += sizeof(uint32_t);
653 ND_PRINT((ndo, " PARITY GROUP %u", seq));
657 case PGM_OPT_CURR_TGSIZE:
659 ND_PRINT((ndo, "[Bad OPT_CURR_TGSIZE option, length %u != 8]", opt_len));
663 len = EXTRACT_32BITS(bp);
664 bp += sizeof(uint32_t);
665 ND_PRINT((ndo, " PARITY ATGS %u", len));
669 case PGM_OPT_NBR_UNREACH:
671 ND_PRINT((ndo, "[Bad OPT_NBR_UNREACH option, length %u != 4]", opt_len));
675 ND_PRINT((ndo, " NBR_UNREACH"));
679 case PGM_OPT_PATH_NLA:
680 ND_PRINT((ndo, " PATH_NLA [%d]", opt_len));
687 ND_PRINT((ndo, "[Bad OPT_SYN option, length %u != 4]", opt_len));
691 ND_PRINT((ndo, " SYN"));
697 ND_PRINT((ndo, "[Bad OPT_FIN option, length %u != 4]", opt_len));
701 ND_PRINT((ndo, " FIN"));
707 ND_PRINT((ndo, "[Bad OPT_RST option, length %u != 4]", opt_len));
711 ND_PRINT((ndo, " RST"));
716 ND_PRINT((ndo, " CR"));
723 ND_PRINT((ndo, "[Bad OPT_CRQST option, length %u != 4]", opt_len));
727 ND_PRINT((ndo, " CRQST"));
731 case PGM_OPT_PGMCC_DATA:
733 offset = EXTRACT_32BITS(bp);
734 bp += sizeof(uint32_t);
735 switch (EXTRACT_16BITS(bp)) {
737 addr_size = sizeof(struct in_addr);
742 addr_size = sizeof(struct in6_addr);
750 bp += (2 * sizeof(uint16_t));
751 if (opt_len != 12 + addr_size) {
752 ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != 12 + address size]", opt_len));
755 ND_TCHECK2(*bp, addr_size);
759 inet_ntop(nla_af, nla, nla_buf, sizeof(nla_buf));
760 ND_PRINT((ndo, " PGMCC DATA %u %s", offset, (char*)nla));
764 case PGM_OPT_PGMCC_FEEDBACK:
766 offset = EXTRACT_32BITS(bp);
767 bp += sizeof(uint32_t);
768 switch (EXTRACT_16BITS(bp)) {
770 addr_size = sizeof(struct in_addr);
775 addr_size = sizeof(struct in6_addr);
783 bp += (2 * sizeof(uint16_t));
784 if (opt_len != 12 + addr_size) {
785 ND_PRINT((ndo, "[Bad OPT_PGMCC_FEEDBACK option, length %u != 12 + address size]", opt_len));
788 ND_TCHECK2(*bp, addr_size);
792 inet_ntop(nla_af, nla, nla_buf, sizeof(nla_buf));
793 ND_PRINT((ndo, " PGMCC FEEDBACK %u %s", offset, (char*)nla));
798 ND_PRINT((ndo, " OPT_%02X [%d] ", opt_type, opt_len));
804 if (opt_type & PGM_OPT_END)
809 ND_PRINT((ndo, " [%u]", length));
810 if (ndo->ndo_packettype == PT_PGM_ZMTP1 &&
811 (pgm->pgm_type == PGM_ODATA || pgm->pgm_type == PGM_RDATA))
812 zmtp1_print_datagram(ndo, bp, EXTRACT_16BITS(&pgm->pgm_length));
817 ND_PRINT((ndo, "[|pgm]"));
819 ND_PRINT((ndo, ">"));