]> The Tcpdump Group git mirrors - tcpdump/blob - print-pgm.c
Use more the ND_TCHECK_1() macro
[tcpdump] / print-pgm.c
1 /*
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.
12 *
13 * Original code by Andy Heffernan (ahh@juniper.net)
14 */
15
16 /* \summary: Pragmatic General Multicast (PGM) printer */
17
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21
22 #include <netdissect-stdinc.h>
23
24 #include "netdissect.h"
25 #include "extract.h"
26 #include "addrtoname.h"
27 #include "addrtostr.h"
28
29 #include "ip.h"
30 #include "ip6.h"
31 #include "ipproto.h"
32 #include "af.h"
33
34 /*
35 * PGM header (RFC 3208)
36 */
37 struct pgm_header {
38 uint16_t pgm_sport;
39 uint16_t pgm_dport;
40 uint8_t pgm_type;
41 uint8_t pgm_options;
42 uint16_t pgm_sum;
43 uint8_t pgm_gsid[6];
44 uint16_t pgm_length;
45 };
46
47 struct pgm_spm {
48 uint32_t pgms_seq;
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]; */
54 /* ... options */
55 };
56
57 struct pgm_nak {
58 uint32_t pgmn_seq;
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]; */
65 /* ... options */
66 };
67
68 struct pgm_ack {
69 uint32_t pgma_rx_max_seq;
70 uint32_t pgma_bitmap;
71 /* ... options */
72 };
73
74 struct pgm_poll {
75 uint32_t pgmp_seq;
76 uint16_t pgmp_round;
77 uint16_t pgmp_reserved;
78 /* ... options */
79 };
80
81 struct pgm_polr {
82 uint32_t pgmp_seq;
83 uint16_t pgmp_round;
84 uint16_t pgmp_subtype;
85 uint16_t pgmp_nla_afi;
86 uint16_t pgmp_reserved;
87 /* ... uint8_t pgmp_nla[0]; */
88 /* ... options */
89 };
90
91 struct pgm_data {
92 uint32_t pgmd_seq;
93 uint32_t pgmd_trailseq;
94 /* ... options */
95 };
96
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 */
108 PGM_MAX = 255
109 } pgm_type;
110
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
115
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
122
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
129
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
135
136 #define PGM_OPT_PGMCC_DATA 0x12
137 #define PGM_OPT_PGMCC_FEEDBACK 0x13
138
139 #define PGM_OPT_MASK 0x7f
140
141 #define PGM_OPT_END 0x80 /* end of options marker */
142
143 #define PGM_MIN_OPT_LEN 4
144
145 void
146 pgm_print(netdissect_options *ndo,
147 register const u_char *bp, register u_int length,
148 register const u_char *bp2)
149 {
150 register const struct pgm_header *pgm;
151 register const struct ip *ip;
152 register char ch;
153 uint16_t sport, dport;
154 u_int nla_afnum;
155 char nla_buf[INET6_ADDRSTRLEN];
156 register const struct ip6_hdr *ip6;
157 uint8_t opt_type, opt_len;
158 uint32_t seq, opts_len, len, offset;
159
160 pgm = (const struct pgm_header *)bp;
161 ip = (const struct ip *)bp2;
162 if (IP_V(ip) == 6)
163 ip6 = (const struct ip6_hdr *)bp2;
164 else
165 ip6 = NULL;
166 ch = '\0';
167 if (!ND_TTEST(pgm->pgm_dport)) {
168 if (ip6) {
169 ND_PRINT((ndo, "%s > %s: [|pgm]",
170 ip6addr_string(ndo, &ip6->ip6_src),
171 ip6addr_string(ndo, &ip6->ip6_dst)));
172 } else {
173 ND_PRINT((ndo, "%s > %s: [|pgm]",
174 ipaddr_string(ndo, &ip->ip_src),
175 ipaddr_string(ndo, &ip->ip_dst)));
176 }
177 return;
178 }
179
180 sport = EXTRACT_BE_U_2(&pgm->pgm_sport);
181 dport = EXTRACT_BE_U_2(&pgm->pgm_dport);
182
183 if (ip6) {
184 if (ip6->ip6_nxt == IPPROTO_PGM) {
185 ND_PRINT((ndo, "%s.%s > %s.%s: ",
186 ip6addr_string(ndo, &ip6->ip6_src),
187 tcpport_string(ndo, sport),
188 ip6addr_string(ndo, &ip6->ip6_dst),
189 tcpport_string(ndo, dport)));
190 } else {
191 ND_PRINT((ndo, "%s > %s: ",
192 tcpport_string(ndo, sport), tcpport_string(ndo, dport)));
193 }
194 } else {
195 if (ip->ip_p == IPPROTO_PGM) {
196 ND_PRINT((ndo, "%s.%s > %s.%s: ",
197 ipaddr_string(ndo, &ip->ip_src),
198 tcpport_string(ndo, sport),
199 ipaddr_string(ndo, &ip->ip_dst),
200 tcpport_string(ndo, dport)));
201 } else {
202 ND_PRINT((ndo, "%s > %s: ",
203 tcpport_string(ndo, sport), tcpport_string(ndo, dport)));
204 }
205 }
206
207 ND_TCHECK(*pgm);
208
209 ND_PRINT((ndo, "PGM, length %u", EXTRACT_BE_U_2(&pgm->pgm_length)));
210
211 if (!ndo->ndo_vflag)
212 return;
213
214 ND_PRINT((ndo, " 0x%02x%02x%02x%02x%02x%02x ",
215 pgm->pgm_gsid[0],
216 pgm->pgm_gsid[1],
217 pgm->pgm_gsid[2],
218 pgm->pgm_gsid[3],
219 pgm->pgm_gsid[4],
220 pgm->pgm_gsid[5]));
221 switch (pgm->pgm_type) {
222 case PGM_SPM: {
223 const struct pgm_spm *spm;
224
225 spm = (const struct pgm_spm *)(pgm + 1);
226 ND_TCHECK(*spm);
227 bp = (const u_char *) (spm + 1);
228
229 switch (EXTRACT_BE_U_2(&spm->pgms_nla_afi)) {
230 case AFNUM_INET:
231 ND_TCHECK2(*bp, sizeof(struct in_addr));
232 addrtostr(bp, nla_buf, sizeof(nla_buf));
233 bp += sizeof(struct in_addr);
234 break;
235 case AFNUM_INET6:
236 ND_TCHECK2(*bp, sizeof(struct in6_addr));
237 addrtostr6(bp, nla_buf, sizeof(nla_buf));
238 bp += sizeof(struct in6_addr);
239 break;
240 default:
241 goto trunc;
242 break;
243 }
244
245 ND_PRINT((ndo, "SPM seq %u trail %u lead %u nla %s",
246 EXTRACT_BE_U_4(&spm->pgms_seq),
247 EXTRACT_BE_U_4(&spm->pgms_trailseq),
248 EXTRACT_BE_U_4(&spm->pgms_leadseq),
249 nla_buf));
250 break;
251 }
252
253 case PGM_POLL: {
254 const struct pgm_poll *poll_msg;
255
256 poll_msg = (const struct pgm_poll *)(pgm + 1);
257 ND_TCHECK(*poll_msg);
258 ND_PRINT((ndo, "POLL seq %u round %u",
259 EXTRACT_BE_U_4(&poll_msg->pgmp_seq),
260 EXTRACT_BE_U_2(&poll_msg->pgmp_round)));
261 bp = (const u_char *) (poll_msg + 1);
262 break;
263 }
264 case PGM_POLR: {
265 const struct pgm_polr *polr;
266 uint32_t ivl, rnd, mask;
267
268 polr = (const struct pgm_polr *)(pgm + 1);
269 ND_TCHECK(*polr);
270 bp = (const u_char *) (polr + 1);
271
272 switch (EXTRACT_BE_U_2(&polr->pgmp_nla_afi)) {
273 case AFNUM_INET:
274 ND_TCHECK2(*bp, sizeof(struct in_addr));
275 addrtostr(bp, nla_buf, sizeof(nla_buf));
276 bp += sizeof(struct in_addr);
277 break;
278 case AFNUM_INET6:
279 ND_TCHECK2(*bp, sizeof(struct in6_addr));
280 addrtostr6(bp, nla_buf, sizeof(nla_buf));
281 bp += sizeof(struct in6_addr);
282 break;
283 default:
284 goto trunc;
285 break;
286 }
287
288 ND_TCHECK2(*bp, sizeof(uint32_t));
289 ivl = EXTRACT_BE_U_4(bp);
290 bp += sizeof(uint32_t);
291
292 ND_TCHECK2(*bp, sizeof(uint32_t));
293 rnd = EXTRACT_BE_U_4(bp);
294 bp += sizeof(uint32_t);
295
296 ND_TCHECK2(*bp, sizeof(uint32_t));
297 mask = EXTRACT_BE_U_4(bp);
298 bp += sizeof(uint32_t);
299
300 ND_PRINT((ndo, "POLR seq %u round %u nla %s ivl %u rnd 0x%08x "
301 "mask 0x%08x", EXTRACT_BE_U_4(&polr->pgmp_seq),
302 EXTRACT_BE_U_2(&polr->pgmp_round), nla_buf, ivl, rnd, mask));
303 break;
304 }
305 case PGM_ODATA: {
306 const struct pgm_data *odata;
307
308 odata = (const struct pgm_data *)(pgm + 1);
309 ND_TCHECK(*odata);
310 ND_PRINT((ndo, "ODATA trail %u seq %u",
311 EXTRACT_BE_U_4(&odata->pgmd_trailseq),
312 EXTRACT_BE_U_4(&odata->pgmd_seq)));
313 bp = (const u_char *) (odata + 1);
314 break;
315 }
316
317 case PGM_RDATA: {
318 const struct pgm_data *rdata;
319
320 rdata = (const struct pgm_data *)(pgm + 1);
321 ND_TCHECK(*rdata);
322 ND_PRINT((ndo, "RDATA trail %u seq %u",
323 EXTRACT_BE_U_4(&rdata->pgmd_trailseq),
324 EXTRACT_BE_U_4(&rdata->pgmd_seq)));
325 bp = (const u_char *) (rdata + 1);
326 break;
327 }
328
329 case PGM_NAK:
330 case PGM_NULLNAK:
331 case PGM_NCF: {
332 const struct pgm_nak *nak;
333 char source_buf[INET6_ADDRSTRLEN], group_buf[INET6_ADDRSTRLEN];
334
335 nak = (const struct pgm_nak *)(pgm + 1);
336 ND_TCHECK(*nak);
337 bp = (const u_char *) (nak + 1);
338
339 /*
340 * Skip past the source, saving info along the way
341 * and stopping if we don't have enough.
342 */
343 switch (EXTRACT_BE_U_2(&nak->pgmn_source_afi)) {
344 case AFNUM_INET:
345 ND_TCHECK2(*bp, sizeof(struct in_addr));
346 addrtostr(bp, source_buf, sizeof(source_buf));
347 bp += sizeof(struct in_addr);
348 break;
349 case AFNUM_INET6:
350 ND_TCHECK2(*bp, sizeof(struct in6_addr));
351 addrtostr6(bp, source_buf, sizeof(source_buf));
352 bp += sizeof(struct in6_addr);
353 break;
354 default:
355 goto trunc;
356 break;
357 }
358
359 /*
360 * Skip past the group, saving info along the way
361 * and stopping if we don't have enough.
362 */
363 bp += (2 * sizeof(uint16_t));
364 ND_TCHECK_2(bp);
365 switch (EXTRACT_BE_U_2(bp)) {
366 case AFNUM_INET:
367 ND_TCHECK2(*bp, sizeof(struct in_addr));
368 addrtostr(bp, group_buf, sizeof(group_buf));
369 bp += sizeof(struct in_addr);
370 break;
371 case AFNUM_INET6:
372 ND_TCHECK2(*bp, sizeof(struct in6_addr));
373 addrtostr6(bp, group_buf, sizeof(group_buf));
374 bp += sizeof(struct in6_addr);
375 break;
376 default:
377 goto trunc;
378 break;
379 }
380
381 /*
382 * Options decoding can go here.
383 */
384 switch (pgm->pgm_type) {
385 case PGM_NAK:
386 ND_PRINT((ndo, "NAK "));
387 break;
388 case PGM_NULLNAK:
389 ND_PRINT((ndo, "NNAK "));
390 break;
391 case PGM_NCF:
392 ND_PRINT((ndo, "NCF "));
393 break;
394 default:
395 break;
396 }
397 ND_PRINT((ndo, "(%s -> %s), seq %u",
398 source_buf, group_buf, EXTRACT_BE_U_4(&nak->pgmn_seq)));
399 break;
400 }
401
402 case PGM_ACK: {
403 const struct pgm_ack *ack;
404
405 ack = (const struct pgm_ack *)(pgm + 1);
406 ND_TCHECK(*ack);
407 ND_PRINT((ndo, "ACK seq %u",
408 EXTRACT_BE_U_4(&ack->pgma_rx_max_seq)));
409 bp = (const u_char *) (ack + 1);
410 break;
411 }
412
413 case PGM_SPMR:
414 ND_PRINT((ndo, "SPMR"));
415 break;
416
417 default:
418 ND_PRINT((ndo, "UNKNOWN type 0x%02x", pgm->pgm_type));
419 break;
420
421 }
422 if (pgm->pgm_options & PGM_OPT_BIT_PRESENT) {
423
424 /*
425 * make sure there's enough for the first option header
426 */
427 if (!ND_TTEST2(*bp, PGM_MIN_OPT_LEN)) {
428 ND_PRINT((ndo, "[|OPT]"));
429 return;
430 }
431
432 /*
433 * That option header MUST be an OPT_LENGTH option
434 * (see the first paragraph of section 9.1 in RFC 3208).
435 */
436 opt_type = EXTRACT_U_1(bp);
437 bp++;
438 if ((opt_type & PGM_OPT_MASK) != PGM_OPT_LENGTH) {
439 ND_PRINT((ndo, "[First option bad, should be PGM_OPT_LENGTH, is %u]", opt_type & PGM_OPT_MASK));
440 return;
441 }
442 opt_len = EXTRACT_U_1(bp);
443 bp++;
444 if (opt_len != 4) {
445 ND_PRINT((ndo, "[Bad OPT_LENGTH option, length %u != 4]", opt_len));
446 return;
447 }
448 opts_len = EXTRACT_BE_U_2(bp);
449 if (opts_len < 4) {
450 ND_PRINT((ndo, "[Bad total option length %u < 4]", opts_len));
451 return;
452 }
453 bp += sizeof(uint16_t);
454 ND_PRINT((ndo, " OPTS LEN %d", opts_len));
455 opts_len -= 4;
456
457 while (opts_len) {
458 if (opts_len < PGM_MIN_OPT_LEN) {
459 ND_PRINT((ndo, "[Total option length leaves no room for final option]"));
460 return;
461 }
462 if (!ND_TTEST_2(bp)) {
463 ND_PRINT((ndo, " [|OPT]"));
464 return;
465 }
466 opt_type = EXTRACT_U_1(bp);
467 bp++;
468 opt_len = EXTRACT_U_1(bp);
469 bp++;
470 if (opt_len < PGM_MIN_OPT_LEN) {
471 ND_PRINT((ndo, "[Bad option, length %u < %u]", opt_len,
472 PGM_MIN_OPT_LEN));
473 break;
474 }
475 if (opts_len < opt_len) {
476 ND_PRINT((ndo, "[Total option length leaves no room for final option]"));
477 return;
478 }
479 if (!ND_TTEST2(*bp, opt_len - 2)) {
480 ND_PRINT((ndo, " [|OPT]"));
481 return;
482 }
483
484 switch (opt_type & PGM_OPT_MASK) {
485 case PGM_OPT_LENGTH:
486 #define PGM_OPT_LENGTH_LEN (2+2)
487 if (opt_len != PGM_OPT_LENGTH_LEN) {
488 ND_PRINT((ndo, "[Bad OPT_LENGTH option, length %u != %u]",
489 opt_len, PGM_OPT_LENGTH_LEN));
490 return;
491 }
492 ND_PRINT((ndo, " OPTS LEN (extra?) %d", EXTRACT_BE_U_2(bp)));
493 bp += 2;
494 opts_len -= PGM_OPT_LENGTH_LEN;
495 break;
496
497 case PGM_OPT_FRAGMENT:
498 #define PGM_OPT_FRAGMENT_LEN (2+2+4+4+4)
499 if (opt_len != PGM_OPT_FRAGMENT_LEN) {
500 ND_PRINT((ndo, "[Bad OPT_FRAGMENT option, length %u != %u]",
501 opt_len, PGM_OPT_FRAGMENT_LEN));
502 return;
503 }
504 bp += 2;
505 seq = EXTRACT_BE_U_4(bp);
506 bp += 4;
507 offset = EXTRACT_BE_U_4(bp);
508 bp += 4;
509 len = EXTRACT_BE_U_4(bp);
510 bp += 4;
511 ND_PRINT((ndo, " FRAG seq %u off %u len %u", seq, offset, len));
512 opts_len -= PGM_OPT_FRAGMENT_LEN;
513 break;
514
515 case PGM_OPT_NAK_LIST:
516 bp += 2;
517 opt_len -= 4; /* option header */
518 ND_PRINT((ndo, " NAK LIST"));
519 while (opt_len) {
520 if (opt_len < 4) {
521 ND_PRINT((ndo, "[Option length not a multiple of 4]"));
522 return;
523 }
524 ND_TCHECK_4(bp);
525 ND_PRINT((ndo, " %u", EXTRACT_BE_U_4(bp)));
526 bp += 4;
527 opt_len -= 4;
528 opts_len -= 4;
529 }
530 break;
531
532 case PGM_OPT_JOIN:
533 #define PGM_OPT_JOIN_LEN (2+2+4)
534 if (opt_len != PGM_OPT_JOIN_LEN) {
535 ND_PRINT((ndo, "[Bad OPT_JOIN option, length %u != %u]",
536 opt_len, PGM_OPT_JOIN_LEN));
537 return;
538 }
539 bp += 2;
540 seq = EXTRACT_BE_U_4(bp);
541 bp += 4;
542 ND_PRINT((ndo, " JOIN %u", seq));
543 opts_len -= PGM_OPT_JOIN_LEN;
544 break;
545
546 case PGM_OPT_NAK_BO_IVL:
547 #define PGM_OPT_NAK_BO_IVL_LEN (2+2+4+4)
548 if (opt_len != PGM_OPT_NAK_BO_IVL_LEN) {
549 ND_PRINT((ndo, "[Bad OPT_NAK_BO_IVL option, length %u != %u]",
550 opt_len, PGM_OPT_NAK_BO_IVL_LEN));
551 return;
552 }
553 bp += 2;
554 offset = EXTRACT_BE_U_4(bp);
555 bp += 4;
556 seq = EXTRACT_BE_U_4(bp);
557 bp += 4;
558 ND_PRINT((ndo, " BACKOFF ivl %u ivlseq %u", offset, seq));
559 opts_len -= PGM_OPT_NAK_BO_IVL_LEN;
560 break;
561
562 case PGM_OPT_NAK_BO_RNG:
563 #define PGM_OPT_NAK_BO_RNG_LEN (2+2+4+4)
564 if (opt_len != PGM_OPT_NAK_BO_RNG_LEN) {
565 ND_PRINT((ndo, "[Bad OPT_NAK_BO_RNG option, length %u != %u]",
566 opt_len, PGM_OPT_NAK_BO_RNG_LEN));
567 return;
568 }
569 bp += 2;
570 offset = EXTRACT_BE_U_4(bp);
571 bp += 4;
572 seq = EXTRACT_BE_U_4(bp);
573 bp += 4;
574 ND_PRINT((ndo, " BACKOFF max %u min %u", offset, seq));
575 opts_len -= PGM_OPT_NAK_BO_RNG_LEN;
576 break;
577
578 case PGM_OPT_REDIRECT:
579 #define PGM_OPT_REDIRECT_FIXED_LEN (2+2+2+2)
580 if (opt_len < PGM_OPT_REDIRECT_FIXED_LEN) {
581 ND_PRINT((ndo, "[Bad OPT_REDIRECT option, length %u < %u]",
582 opt_len, PGM_OPT_REDIRECT_FIXED_LEN));
583 return;
584 }
585 bp += 2;
586 nla_afnum = EXTRACT_BE_U_2(bp);
587 bp += 2+2;
588 switch (nla_afnum) {
589 case AFNUM_INET:
590 if (opt_len != PGM_OPT_REDIRECT_FIXED_LEN + sizeof(struct in_addr)) {
591 ND_PRINT((ndo, "[Bad OPT_REDIRECT option, length %u != %u + address size]",
592 opt_len, PGM_OPT_REDIRECT_FIXED_LEN));
593 return;
594 }
595 ND_TCHECK2(*bp, sizeof(struct in_addr));
596 addrtostr(bp, nla_buf, sizeof(nla_buf));
597 bp += sizeof(struct in_addr);
598 opts_len -= PGM_OPT_REDIRECT_FIXED_LEN + sizeof(struct in_addr);
599 break;
600 case AFNUM_INET6:
601 if (opt_len != PGM_OPT_REDIRECT_FIXED_LEN + sizeof(struct in6_addr)) {
602 ND_PRINT((ndo, "[Bad OPT_REDIRECT option, length %u != %u + address size]",
603 PGM_OPT_REDIRECT_FIXED_LEN, opt_len));
604 return;
605 }
606 ND_TCHECK2(*bp, sizeof(struct in6_addr));
607 addrtostr6(bp, nla_buf, sizeof(nla_buf));
608 bp += sizeof(struct in6_addr);
609 opts_len -= PGM_OPT_REDIRECT_FIXED_LEN + sizeof(struct in6_addr);
610 break;
611 default:
612 goto trunc;
613 break;
614 }
615
616 ND_PRINT((ndo, " REDIRECT %s", nla_buf));
617 break;
618
619 case PGM_OPT_PARITY_PRM:
620 #define PGM_OPT_PARITY_PRM_LEN (2+2+4)
621 if (opt_len != PGM_OPT_PARITY_PRM_LEN) {
622 ND_PRINT((ndo, "[Bad OPT_PARITY_PRM option, length %u != %u]",
623 opt_len, PGM_OPT_PARITY_PRM_LEN));
624 return;
625 }
626 bp += 2;
627 len = EXTRACT_BE_U_4(bp);
628 bp += 4;
629 ND_PRINT((ndo, " PARITY MAXTGS %u", len));
630 opts_len -= PGM_OPT_PARITY_PRM_LEN;
631 break;
632
633 case PGM_OPT_PARITY_GRP:
634 #define PGM_OPT_PARITY_GRP_LEN (2+2+4)
635 if (opt_len != PGM_OPT_PARITY_GRP_LEN) {
636 ND_PRINT((ndo, "[Bad OPT_PARITY_GRP option, length %u != %u]",
637 opt_len, PGM_OPT_PARITY_GRP_LEN));
638 return;
639 }
640 bp += 2;
641 seq = EXTRACT_BE_U_4(bp);
642 bp += 4;
643 ND_PRINT((ndo, " PARITY GROUP %u", seq));
644 opts_len -= PGM_OPT_PARITY_GRP_LEN;
645 break;
646
647 case PGM_OPT_CURR_TGSIZE:
648 #define PGM_OPT_CURR_TGSIZE_LEN (2+2+4)
649 if (opt_len != PGM_OPT_CURR_TGSIZE_LEN) {
650 ND_PRINT((ndo, "[Bad OPT_CURR_TGSIZE option, length %u != %u]",
651 opt_len, PGM_OPT_CURR_TGSIZE_LEN));
652 return;
653 }
654 bp += 2;
655 len = EXTRACT_BE_U_4(bp);
656 bp += 4;
657 ND_PRINT((ndo, " PARITY ATGS %u", len));
658 opts_len -= PGM_OPT_CURR_TGSIZE_LEN;
659 break;
660
661 case PGM_OPT_NBR_UNREACH:
662 #define PGM_OPT_NBR_UNREACH_LEN (2+2)
663 if (opt_len != PGM_OPT_NBR_UNREACH_LEN) {
664 ND_PRINT((ndo, "[Bad OPT_NBR_UNREACH option, length %u != %u]",
665 opt_len, PGM_OPT_NBR_UNREACH_LEN));
666 return;
667 }
668 bp += 2;
669 ND_PRINT((ndo, " NBR_UNREACH"));
670 opts_len -= PGM_OPT_NBR_UNREACH_LEN;
671 break;
672
673 case PGM_OPT_PATH_NLA:
674 ND_PRINT((ndo, " PATH_NLA [%d]", opt_len));
675 bp += opt_len;
676 opts_len -= opt_len;
677 break;
678
679 case PGM_OPT_SYN:
680 #define PGM_OPT_SYN_LEN (2+2)
681 if (opt_len != PGM_OPT_SYN_LEN) {
682 ND_PRINT((ndo, "[Bad OPT_SYN option, length %u != %u]",
683 opt_len, PGM_OPT_SYN_LEN));
684 return;
685 }
686 bp += 2;
687 ND_PRINT((ndo, " SYN"));
688 opts_len -= PGM_OPT_SYN_LEN;
689 break;
690
691 case PGM_OPT_FIN:
692 #define PGM_OPT_FIN_LEN (2+2)
693 if (opt_len != PGM_OPT_FIN_LEN) {
694 ND_PRINT((ndo, "[Bad OPT_FIN option, length %u != %u]",
695 opt_len, PGM_OPT_FIN_LEN));
696 return;
697 }
698 bp += 2;
699 ND_PRINT((ndo, " FIN"));
700 opts_len -= PGM_OPT_FIN_LEN;
701 break;
702
703 case PGM_OPT_RST:
704 #define PGM_OPT_RST_LEN (2+2)
705 if (opt_len != PGM_OPT_RST_LEN) {
706 ND_PRINT((ndo, "[Bad OPT_RST option, length %u != %u]",
707 opt_len, PGM_OPT_RST_LEN));
708 return;
709 }
710 bp += 2;
711 ND_PRINT((ndo, " RST"));
712 opts_len -= PGM_OPT_RST_LEN;
713 break;
714
715 case PGM_OPT_CR:
716 ND_PRINT((ndo, " CR"));
717 bp += opt_len;
718 opts_len -= opt_len;
719 break;
720
721 case PGM_OPT_CRQST:
722 #define PGM_OPT_CRQST_LEN (2+2)
723 if (opt_len != PGM_OPT_CRQST_LEN) {
724 ND_PRINT((ndo, "[Bad OPT_CRQST option, length %u != %u]",
725 opt_len, PGM_OPT_CRQST_LEN));
726 return;
727 }
728 bp += 2;
729 ND_PRINT((ndo, " CRQST"));
730 opts_len -= PGM_OPT_CRQST_LEN;
731 break;
732
733 case PGM_OPT_PGMCC_DATA:
734 #define PGM_OPT_PGMCC_DATA_FIXED_LEN (2+2+4+2+2)
735 if (opt_len < PGM_OPT_PGMCC_DATA_FIXED_LEN) {
736 ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u < %u]",
737 opt_len, PGM_OPT_PGMCC_DATA_FIXED_LEN));
738 return;
739 }
740 bp += 2;
741 offset = EXTRACT_BE_U_4(bp);
742 bp += 4;
743 nla_afnum = EXTRACT_BE_U_2(bp);
744 bp += 2+2;
745 switch (nla_afnum) {
746 case AFNUM_INET:
747 if (opt_len != PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(struct in_addr)) {
748 ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != %u + address size]",
749 opt_len, PGM_OPT_PGMCC_DATA_FIXED_LEN));
750 return;
751 }
752 ND_TCHECK2(*bp, sizeof(struct in_addr));
753 addrtostr(bp, nla_buf, sizeof(nla_buf));
754 bp += sizeof(struct in_addr);
755 opts_len -= PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(struct in_addr);
756 break;
757 case AFNUM_INET6:
758 if (opt_len != PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(struct in6_addr)) {
759 ND_PRINT((ndo, "[Bad OPT_PGMCC_DATA option, length %u != %u + address size]",
760 opt_len, PGM_OPT_PGMCC_DATA_FIXED_LEN));
761 return;
762 }
763 ND_TCHECK2(*bp, sizeof(struct in6_addr));
764 addrtostr6(bp, nla_buf, sizeof(nla_buf));
765 bp += sizeof(struct in6_addr);
766 opts_len -= PGM_OPT_PGMCC_DATA_FIXED_LEN + sizeof(struct in6_addr);
767 break;
768 default:
769 goto trunc;
770 break;
771 }
772
773 ND_PRINT((ndo, " PGMCC DATA %u %s", offset, nla_buf));
774 break;
775
776 case PGM_OPT_PGMCC_FEEDBACK:
777 #define PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN (2+2+4+2+2)
778 if (opt_len < PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN) {
779 ND_PRINT((ndo, "[Bad PGM_OPT_PGMCC_FEEDBACK option, length %u < %u]",
780 opt_len, PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN));
781 return;
782 }
783 bp += 2;
784 offset = EXTRACT_BE_U_4(bp);
785 bp += 4;
786 nla_afnum = EXTRACT_BE_U_2(bp);
787 bp += 2+2;
788 switch (nla_afnum) {
789 case AFNUM_INET:
790 if (opt_len != PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(struct in_addr)) {
791 ND_PRINT((ndo, "[Bad OPT_PGMCC_FEEDBACK option, length %u != %u + address size]",
792 opt_len, PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN));
793 return;
794 }
795 ND_TCHECK2(*bp, sizeof(struct in_addr));
796 addrtostr(bp, nla_buf, sizeof(nla_buf));
797 bp += sizeof(struct in_addr);
798 opts_len -= PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(struct in_addr);
799 break;
800 case AFNUM_INET6:
801 if (opt_len != PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(struct in6_addr)) {
802 ND_PRINT((ndo, "[Bad OPT_PGMCC_FEEDBACK option, length %u != %u + address size]",
803 opt_len, PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN));
804 return;
805 }
806 ND_TCHECK2(*bp, sizeof(struct in6_addr));
807 addrtostr6(bp, nla_buf, sizeof(nla_buf));
808 bp += sizeof(struct in6_addr);
809 opts_len -= PGM_OPT_PGMCC_FEEDBACK_FIXED_LEN + sizeof(struct in6_addr);
810 break;
811 default:
812 goto trunc;
813 break;
814 }
815
816 ND_PRINT((ndo, " PGMCC FEEDBACK %u %s", offset, nla_buf));
817 break;
818
819 default:
820 ND_PRINT((ndo, " OPT_%02X [%d] ", opt_type, opt_len));
821 bp += opt_len;
822 opts_len -= opt_len;
823 break;
824 }
825
826 if (opt_type & PGM_OPT_END)
827 break;
828 }
829 }
830
831 ND_PRINT((ndo, " [%u]", length));
832 if (ndo->ndo_packettype == PT_PGM_ZMTP1 &&
833 (pgm->pgm_type == PGM_ODATA || pgm->pgm_type == PGM_RDATA))
834 zmtp1_datagram_print(ndo, bp,
835 EXTRACT_BE_U_2(&pgm->pgm_length));
836
837 return;
838
839 trunc:
840 ND_PRINT((ndo, "[|pgm]"));
841 if (ch != '\0')
842 ND_PRINT((ndo, ">"));
843 }