]> The Tcpdump Group git mirrors - tcpdump/blob - print-sctp.c
gre: add support for MikroTik Ethernet-over-IP hack.
[tcpdump] / print-sctp.c
1 /* Copyright (c) 2001 NETLAB, Temple University
2 * Copyright (c) 2001 Protocol Engineering Lab, University of Delaware
3 *
4 * Jerry Heinz <gheinz@astro.temple.edu>
5 * John Fiore <jfiore@joda.cis.temple.edu>
6 * Armando L. Caro Jr. <acaro@cis.udel.edu>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 *
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * 3. Neither the name of the University nor of the Laboratory may be used
20 * to endorse or promote products derived from this software without
21 * specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36 /* \summary: Stream Control Transmission Protocol (SCTP) printer */
37
38 #ifdef HAVE_CONFIG_H
39 #include <config.h>
40 #endif
41
42 #include "netdissect-stdinc.h"
43
44 #define ND_LONGJMP_FROM_TCHECK
45 #include "netdissect.h"
46 #include "addrtoname.h"
47 #include "extract.h"
48 #include "ip.h"
49 #include "ip6.h"
50
51 /* Definitions from:
52 *
53 * SCTP reference Implementation Copyright (C) 1999 Cisco And Motorola
54 *
55 * Redistribution and use in source and binary forms, with or without
56 * modification, are permitted provided that the following conditions
57 * are met:
58 *
59 * 1. Redistributions of source code must retain the above copyright
60 * notice, this list of conditions and the following disclaimer.
61 *
62 * 2. Redistributions in binary form must reproduce the above copyright
63 * notice, this list of conditions and the following disclaimer in the
64 * documentation and/or other materials provided with the distribution.
65 *
66 * 3. Neither the name of Cisco nor of Motorola may be used
67 * to endorse or promote products derived from this software without
68 * specific prior written permission.
69 *
70 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
71 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
72 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
73 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
74 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
75 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
76 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
77 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
78 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
79 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
80 * SUCH DAMAGE.
81 *
82 * This file is part of the SCTP reference Implementation
83 *
84 *
85 * Please send any bug reports or fixes you make to one of the following email
86 * addresses:
87 *
88 * rstewar1@email.mot.com
89 * kmorneau@cisco.com
90 * qxie1@email.mot.com
91 *
92 * Any bugs reported given to us we will try to fix... any fixes shared will
93 * be incorporated into the next SCTP release.
94 */
95
96 /* The valid defines for all message
97 * types know to SCTP. 0 is reserved
98 */
99 #define SCTP_DATA 0x00
100 #define SCTP_INITIATION 0x01
101 #define SCTP_INITIATION_ACK 0x02
102 #define SCTP_SELECTIVE_ACK 0x03
103 #define SCTP_HEARTBEAT_REQUEST 0x04
104 #define SCTP_HEARTBEAT_ACK 0x05
105 #define SCTP_ABORT_ASSOCIATION 0x06
106 #define SCTP_SHUTDOWN 0x07
107 #define SCTP_SHUTDOWN_ACK 0x08
108 #define SCTP_OPERATION_ERR 0x09
109 #define SCTP_COOKIE_ECHO 0x0a
110 #define SCTP_COOKIE_ACK 0x0b
111 #define SCTP_ECN_ECHO 0x0c
112 #define SCTP_ECN_CWR 0x0d
113 #define SCTP_SHUTDOWN_COMPLETE 0x0e
114 #define SCTP_FORWARD_CUM_TSN 0xc0
115 #define SCTP_RELIABLE_CNTL 0xc1
116 #define SCTP_RELIABLE_CNTL_ACK 0xc2
117
118 static const struct tok sctp_chunkid_str[] = {
119 { SCTP_DATA, "DATA" },
120 { SCTP_INITIATION, "INIT" },
121 { SCTP_INITIATION_ACK, "INIT ACK" },
122 { SCTP_SELECTIVE_ACK, "SACK" },
123 { SCTP_HEARTBEAT_REQUEST, "HB REQ" },
124 { SCTP_HEARTBEAT_ACK, "HB ACK" },
125 { SCTP_ABORT_ASSOCIATION, "ABORT" },
126 { SCTP_SHUTDOWN, "SHUTDOWN" },
127 { SCTP_SHUTDOWN_ACK, "SHUTDOWN ACK" },
128 { SCTP_OPERATION_ERR, "OP ERR" },
129 { SCTP_COOKIE_ECHO, "COOKIE ECHO" },
130 { SCTP_COOKIE_ACK, "COOKIE ACK" },
131 { SCTP_ECN_ECHO, "ECN ECHO" },
132 { SCTP_ECN_CWR, "ECN CWR" },
133 { SCTP_SHUTDOWN_COMPLETE, "SHUTDOWN COMPLETE" },
134 { SCTP_FORWARD_CUM_TSN, "FOR CUM TSN" },
135 { SCTP_RELIABLE_CNTL, "REL CTRL" },
136 { SCTP_RELIABLE_CNTL_ACK, "REL CTRL ACK" },
137 { 0, NULL }
138 };
139
140 /* Data Chuck Specific Flags */
141 #define SCTP_DATA_FRAG_MASK 0x03
142 #define SCTP_DATA_MIDDLE_FRAG 0x00
143 #define SCTP_DATA_LAST_FRAG 0x01
144 #define SCTP_DATA_FIRST_FRAG 0x02
145 #define SCTP_DATA_NOT_FRAG 0x03
146 #define SCTP_DATA_UNORDERED 0x04
147
148 #define SCTP_ADDRMAX 60
149
150 #define CHAN_HP 6704
151 #define CHAN_MP 6705
152 #define CHAN_LP 6706
153
154 /* the sctp common header */
155
156 struct sctpHeader{
157 nd_uint16_t source;
158 nd_uint16_t destination;
159 nd_uint32_t verificationTag;
160 nd_uint32_t adler32;
161 };
162
163 /* various descriptor parsers */
164
165 struct sctpChunkDesc{
166 nd_uint8_t chunkID;
167 nd_uint8_t chunkFlg;
168 nd_uint16_t chunkLength;
169 };
170
171 struct sctpParamDesc{
172 nd_uint16_t paramType;
173 nd_uint16_t paramLength;
174 };
175
176
177 struct sctpRelChunkDesc{
178 struct sctpChunkDesc chk;
179 nd_uint32_t serialNumber;
180 };
181
182 struct sctpVendorSpecificParam {
183 struct sctpParamDesc p; /* type must be 0xfffe */
184 nd_uint32_t vendorId; /* vendor ID from RFC 1700 */
185 nd_uint16_t vendorSpecificType;
186 nd_uint16_t vendorSpecificLen;
187 };
188
189
190 /* Structures for the control parts */
191
192
193
194 /* Sctp association init request/ack */
195
196 /* this is used for init ack, too */
197 struct sctpInitiation{
198 nd_uint32_t initTag; /* tag of mine */
199 nd_uint32_t rcvWindowCredit; /* rwnd */
200 nd_uint16_t NumPreopenStreams; /* OS */
201 nd_uint16_t MaxInboundStreams; /* MIS */
202 nd_uint32_t initialTSN;
203 /* optional param's follow in sctpParamDesc form */
204 };
205
206 struct sctpV4IpAddress{
207 struct sctpParamDesc p; /* type is set to SCTP_IPV4_PARAM_TYPE, len=10 */
208 nd_ipv4 ipAddress;
209 };
210
211
212 struct sctpV6IpAddress{
213 struct sctpParamDesc p; /* type is set to SCTP_IPV6_PARAM_TYPE, len=22 */
214 nd_ipv6 ipAddress;
215 };
216
217 struct sctpDNSName{
218 struct sctpParamDesc param;
219 nd_byte name[1];
220 };
221
222
223 struct sctpCookiePreserve{
224 struct sctpParamDesc p; /* type is set to SCTP_COOKIE_PRESERVE, len=8 */
225 nd_uint32_t extraTime;
226 };
227
228
229 struct sctpTimeStamp{
230 nd_uint32_t ts_sec;
231 nd_uint32_t ts_usec;
232 };
233
234
235 /* this guy is for use when
236 * I have a initiate message gloming the
237 * things together.
238
239 */
240 struct sctpUnifiedInit{
241 struct sctpChunkDesc uh;
242 struct sctpInitiation initm;
243 };
244
245 struct sctpSendableInit{
246 struct sctpHeader mh;
247 struct sctpUnifiedInit msg;
248 };
249
250
251 /* Selective Acknowledgement
252 * has the following structure with
253 * a optional amount of trailing int's
254 * on the last part (based on the numberOfDesc
255 * field).
256 */
257
258 struct sctpSelectiveAck{
259 nd_uint32_t highestConseqTSN;
260 nd_uint32_t updatedRwnd;
261 nd_uint16_t numberOfdesc;
262 nd_uint16_t numDupTsns;
263 };
264
265 struct sctpSelectiveFrag{
266 nd_uint16_t fragmentStart;
267 nd_uint16_t fragmentEnd;
268 };
269
270
271 struct sctpUnifiedSack{
272 struct sctpChunkDesc uh;
273 struct sctpSelectiveAck sack;
274 };
275
276 /* for the abort and shutdown ACK
277 * we must carry the init tag in the common header. Just the
278 * common header is all that is needed with a chunk descriptor.
279 */
280 struct sctpUnifiedAbort{
281 struct sctpChunkDesc uh;
282 };
283
284 struct sctpUnifiedAbortLight{
285 struct sctpHeader mh;
286 struct sctpChunkDesc uh;
287 };
288
289 struct sctpUnifiedAbortHeavy{
290 struct sctpHeader mh;
291 struct sctpChunkDesc uh;
292 nd_uint16_t causeCode;
293 nd_uint16_t causeLen;
294 };
295
296 /* For the graceful shutdown we must carry
297 * the tag (in common header) and the highest consequitive acking value
298 */
299 struct sctpShutdown {
300 nd_uint32_t TSN_Seen;
301 };
302
303 struct sctpUnifiedShutdown{
304 struct sctpChunkDesc uh;
305 struct sctpShutdown shut;
306 };
307
308 /* in the unified message we add the trailing
309 * stream id since it is the only message
310 * that is defined as a operation error.
311 */
312 struct sctpOpErrorCause{
313 nd_uint16_t cause;
314 nd_uint16_t causeLen;
315 };
316
317 struct sctpUnifiedOpError{
318 struct sctpChunkDesc uh;
319 struct sctpOpErrorCause c;
320 };
321
322 struct sctpUnifiedStreamError{
323 struct sctpHeader mh;
324 struct sctpChunkDesc uh;
325 struct sctpOpErrorCause c;
326 nd_uint16_t strmNum;
327 nd_uint16_t reserved;
328 };
329
330 struct staleCookieMsg{
331 struct sctpHeader mh;
332 struct sctpChunkDesc uh;
333 struct sctpOpErrorCause c;
334 nd_uint32_t moretime;
335 };
336
337 /* the following is used in all sends
338 * where nothing is needed except the
339 * chunk/type i.e. shutdownAck Abort */
340
341 struct sctpUnifiedSingleMsg{
342 struct sctpHeader mh;
343 struct sctpChunkDesc uh;
344 };
345
346 struct sctpDataPart{
347 nd_uint32_t TSN;
348 nd_uint16_t streamId;
349 nd_uint16_t sequence;
350 nd_uint32_t payloadtype;
351 };
352
353 struct sctpUnifiedDatagram{
354 struct sctpChunkDesc uh;
355 struct sctpDataPart dp;
356 };
357
358 struct sctpECN_echo{
359 struct sctpChunkDesc uh;
360 nd_uint32_t Lowest_TSN;
361 };
362
363
364 struct sctpCWR{
365 struct sctpChunkDesc uh;
366 nd_uint32_t TSN_reduced_at;
367 };
368
369 static const struct tok ForCES_channels[] = {
370 { CHAN_HP, "ForCES HP" },
371 { CHAN_MP, "ForCES MP" },
372 { CHAN_LP, "ForCES LP" },
373 { 0, NULL }
374 };
375
376 /* data chunk's payload protocol identifiers */
377
378 #define SCTP_PPID_IUA 1
379 #define SCTP_PPID_M2UA 2
380 #define SCTP_PPID_M3UA 3
381 #define SCTP_PPID_SUA 4
382 #define SCTP_PPID_M2PA 5
383 #define SCTP_PPID_V5UA 6
384 #define SCTP_PPID_H248 7
385 #define SCTP_PPID_BICC 8
386 #define SCTP_PPID_TALI 9
387 #define SCTP_PPID_DUA 10
388 #define SCTP_PPID_ASAP 11
389 #define SCTP_PPID_ENRP 12
390 #define SCTP_PPID_H323 13
391 #define SCTP_PPID_QIPC 14
392 #define SCTP_PPID_SIMCO 15
393 #define SCTP_PPID_DDPSC 16
394 #define SCTP_PPID_DDPSSC 17
395 #define SCTP_PPID_S1AP 18
396 #define SCTP_PPID_RUA 19
397 #define SCTP_PPID_HNBAP 20
398 #define SCTP_PPID_FORCES_HP 21
399 #define SCTP_PPID_FORCES_MP 22
400 #define SCTP_PPID_FORCES_LP 23
401 #define SCTP_PPID_SBC_AP 24
402 #define SCTP_PPID_NBAP 25
403 /* 26 */
404 #define SCTP_PPID_X2AP 27
405
406 static const struct tok PayloadProto_idents[] = {
407 { SCTP_PPID_IUA, "ISDN Q.921" },
408 { SCTP_PPID_M2UA, "M2UA" },
409 { SCTP_PPID_M3UA, "M3UA" },
410 { SCTP_PPID_SUA, "SUA" },
411 { SCTP_PPID_M2PA, "M2PA" },
412 { SCTP_PPID_V5UA, "V5.2" },
413 { SCTP_PPID_H248, "H.248" },
414 { SCTP_PPID_BICC, "BICC" },
415 { SCTP_PPID_TALI, "TALI" },
416 { SCTP_PPID_DUA, "DUA" },
417 { SCTP_PPID_ASAP, "ASAP" },
418 { SCTP_PPID_ENRP, "ENRP" },
419 { SCTP_PPID_H323, "H.323" },
420 { SCTP_PPID_QIPC, "Q.IPC" },
421 { SCTP_PPID_SIMCO, "SIMCO" },
422 { SCTP_PPID_DDPSC, "DDPSC" },
423 { SCTP_PPID_DDPSSC, "DDPSSC" },
424 { SCTP_PPID_S1AP, "S1AP" },
425 { SCTP_PPID_RUA, "RUA" },
426 { SCTP_PPID_HNBAP, "HNBAP" },
427 { SCTP_PPID_FORCES_HP, "ForCES HP" },
428 { SCTP_PPID_FORCES_MP, "ForCES MP" },
429 { SCTP_PPID_FORCES_LP, "ForCES LP" },
430 { SCTP_PPID_SBC_AP, "SBc-AP" },
431 { SCTP_PPID_NBAP, "NBAP" },
432 /* 26 */
433 { SCTP_PPID_X2AP, "X2AP" },
434 { 0, NULL }
435 };
436
437
438 static int
439 isForCES_port(u_short Port)
440 {
441 if (Port == CHAN_HP)
442 return 1;
443 if (Port == CHAN_MP)
444 return 1;
445 if (Port == CHAN_LP)
446 return 1;
447
448 return 0;
449 }
450
451 void
452 sctp_print(netdissect_options *ndo,
453 const u_char *bp, /* beginning of sctp packet */
454 const u_char *bp2, /* beginning of enclosing */
455 u_int sctpPacketLength) /* sctp packet */
456 {
457 u_int sctpPacketLengthRemaining;
458 const struct sctpHeader *sctpPktHdr;
459 const struct ip *ip;
460 const struct ip6_hdr *ip6;
461 uint8_t chunkID;
462 u_short sourcePort, destPort;
463 u_int chunkCount;
464 const struct sctpChunkDesc *chunkDescPtr;
465 const char *sep;
466 int isforces = 0;
467
468 ndo->ndo_protocol = "sctp";
469 ND_ICHECKMSG_ZU("length", sctpPacketLength, <, sizeof(struct sctpHeader));
470 sctpPktHdr = (const struct sctpHeader*) bp;
471 ND_TCHECK_SIZE(sctpPktHdr);
472 sctpPacketLengthRemaining = sctpPacketLength;
473
474 sourcePort = GET_BE_U_2(sctpPktHdr->source);
475 destPort = GET_BE_U_2(sctpPktHdr->destination);
476
477 ip = (const struct ip *)bp2;
478 if (IP_V(ip) == 6)
479 ip6 = (const struct ip6_hdr *)bp2;
480 else
481 ip6 = NULL;
482
483 if (ip6) {
484 ND_PRINT("%s.%u > %s.%u: sctp",
485 GET_IP6ADDR_STRING(ip6->ip6_src),
486 sourcePort,
487 GET_IP6ADDR_STRING(ip6->ip6_dst),
488 destPort);
489 } else {
490 ND_PRINT("%s.%u > %s.%u: sctp",
491 GET_IPADDR_STRING(ip->ip_src),
492 sourcePort,
493 GET_IPADDR_STRING(ip->ip_dst),
494 destPort);
495 }
496
497 if (isForCES_port(sourcePort)) {
498 ND_PRINT("[%s]", tok2str(ForCES_channels, NULL, sourcePort));
499 isforces = 1;
500 }
501 if (isForCES_port(destPort)) {
502 ND_PRINT("[%s]", tok2str(ForCES_channels, NULL, destPort));
503 isforces = 1;
504 }
505
506 bp += sizeof(struct sctpHeader);
507 sctpPacketLengthRemaining -= sizeof(struct sctpHeader);
508
509 if (ndo->ndo_vflag >= 2)
510 sep = "\n\t";
511 else
512 sep = " (";
513 /* cycle through all chunks, printing information on each one */
514 for (chunkCount = 0, chunkDescPtr = (const struct sctpChunkDesc *)bp;
515 sctpPacketLengthRemaining != 0;
516 chunkCount++)
517 {
518 uint16_t chunkLength, chunkLengthRemaining;
519 uint16_t align;
520
521 chunkDescPtr = (const struct sctpChunkDesc *)bp;
522 if (sctpPacketLengthRemaining < sizeof(*chunkDescPtr)) {
523 ND_PRINT("%s%u) [chunk descriptor cut off at end of packet]", sep, chunkCount+1);
524 break;
525 }
526 ND_TCHECK_SIZE(chunkDescPtr);
527 chunkLength = GET_BE_U_2(chunkDescPtr->chunkLength);
528 if (chunkLength < sizeof(*chunkDescPtr)) {
529 ND_PRINT("%s%u) [Bad chunk length %u, < size of chunk descriptor]", sep, chunkCount+1, chunkLength);
530 break;
531 }
532 chunkLengthRemaining = chunkLength;
533
534 align = chunkLength % 4;
535 if (align != 0)
536 align = 4 - align;
537
538 if (sctpPacketLengthRemaining < align) {
539 ND_PRINT("%s%u) [Bad chunk length %u, > remaining data in packet]", sep, chunkCount+1, chunkLength);
540 break;
541 }
542
543 ND_TCHECK_LEN(bp, chunkLength);
544
545 bp += sizeof(*chunkDescPtr);
546 sctpPacketLengthRemaining -= sizeof(*chunkDescPtr);
547 chunkLengthRemaining -= sizeof(*chunkDescPtr);
548
549 ND_PRINT("%s%u) ", sep, chunkCount+1);
550 chunkID = GET_U_1(chunkDescPtr->chunkID);
551 ND_PRINT("[%s] ", tok2str(sctp_chunkid_str, "Unknown chunk type: 0x%x",
552 chunkID));
553 switch (chunkID) {
554 case SCTP_DATA :
555 {
556 const struct sctpDataPart *dataHdrPtr;
557 uint8_t chunkFlg;
558 uint32_t ppid;
559 uint16_t payload_size;
560
561 chunkFlg = GET_U_1(chunkDescPtr->chunkFlg);
562 if ((chunkFlg & SCTP_DATA_UNORDERED) == SCTP_DATA_UNORDERED)
563 ND_PRINT("(U)");
564
565 if ((chunkFlg & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG)
566 ND_PRINT("(B)");
567
568 if ((chunkFlg & SCTP_DATA_LAST_FRAG) == SCTP_DATA_LAST_FRAG)
569 ND_PRINT("(E)");
570
571 if( ((chunkFlg & SCTP_DATA_UNORDERED) == SCTP_DATA_UNORDERED) ||
572 ((chunkFlg & SCTP_DATA_FIRST_FRAG) == SCTP_DATA_FIRST_FRAG) ||
573 ((chunkFlg & SCTP_DATA_LAST_FRAG) == SCTP_DATA_LAST_FRAG) )
574 ND_PRINT(" ");
575
576 ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <,
577 sizeof(*dataHdrPtr));
578 dataHdrPtr=(const struct sctpDataPart*)bp;
579
580 ppid = GET_BE_U_4(dataHdrPtr->payloadtype);
581 ND_PRINT("[TSN: %u] ", GET_BE_U_4(dataHdrPtr->TSN));
582 ND_PRINT("[SID: %u] ", GET_BE_U_2(dataHdrPtr->streamId));
583 ND_PRINT("[SSEQ %u] ", GET_BE_U_2(dataHdrPtr->sequence));
584 ND_PRINT("[PPID %s] ",
585 tok2str(PayloadProto_idents, "0x%x", ppid));
586
587 if (!isforces) {
588 isforces = (ppid == SCTP_PPID_FORCES_HP) ||
589 (ppid == SCTP_PPID_FORCES_MP) ||
590 (ppid == SCTP_PPID_FORCES_LP);
591 }
592
593 bp += sizeof(*dataHdrPtr);
594 sctpPacketLengthRemaining -= sizeof(*dataHdrPtr);
595 chunkLengthRemaining -= sizeof(*dataHdrPtr);
596 ND_ICHECKMSG_U("chunk length", chunkLengthRemaining, ==, 0);
597 payload_size = chunkLengthRemaining;
598
599 if (isforces) {
600 forces_print(ndo, bp, payload_size);
601 /* ndo_protocol reassignment after forces_print() call */
602 ndo->ndo_protocol = "sctp";
603 } else if (ndo->ndo_vflag >= 2) { /* if verbose output is specified */
604 /* at the command line */
605 switch (ppid) {
606 case SCTP_PPID_M3UA :
607 m3ua_print(ndo, bp, payload_size);
608 /* ndo_protocol reassignment after m3ua_print() call */
609 ndo->ndo_protocol = "sctp";
610 break;
611 default:
612 ND_PRINT("[Payload");
613 if (!ndo->ndo_suppress_default_print) {
614 ND_PRINT(":");
615 ND_DEFAULTPRINT(bp, payload_size);
616 }
617 ND_PRINT("]");
618 break;
619 }
620 }
621 bp += payload_size;
622 sctpPacketLengthRemaining -= payload_size;
623 chunkLengthRemaining -= payload_size;
624 break;
625 }
626 case SCTP_INITIATION :
627 {
628 const struct sctpInitiation *init;
629
630 ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <,
631 sizeof(*init));
632 init=(const struct sctpInitiation*)bp;
633 ND_PRINT("[init tag: %u] ", GET_BE_U_4(init->initTag));
634 ND_PRINT("[rwnd: %u] ", GET_BE_U_4(init->rcvWindowCredit));
635 ND_PRINT("[OS: %u] ", GET_BE_U_2(init->NumPreopenStreams));
636 ND_PRINT("[MIS: %u] ", GET_BE_U_2(init->MaxInboundStreams));
637 ND_PRINT("[init TSN: %u] ", GET_BE_U_4(init->initialTSN));
638 bp += sizeof(*init);
639 sctpPacketLengthRemaining -= sizeof(*init);
640 chunkLengthRemaining -= sizeof(*init);
641
642 #if 0 /* ALC you can add code for optional params here */
643 if( chunkLengthRemaining != 0 )
644 ND_PRINT(" @@@@@ UNFINISHED @@@@@@%s\n",
645 "Optional params present, but not printed.");
646 #endif
647 bp += chunkLengthRemaining;
648 sctpPacketLengthRemaining -= chunkLengthRemaining;
649 chunkLengthRemaining = 0;
650 break;
651 }
652 case SCTP_INITIATION_ACK :
653 {
654 const struct sctpInitiation *init;
655
656 ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <,
657 sizeof(*init));
658 init=(const struct sctpInitiation*)bp;
659 ND_PRINT("[init tag: %u] ", GET_BE_U_4(init->initTag));
660 ND_PRINT("[rwnd: %u] ", GET_BE_U_4(init->rcvWindowCredit));
661 ND_PRINT("[OS: %u] ", GET_BE_U_2(init->NumPreopenStreams));
662 ND_PRINT("[MIS: %u] ", GET_BE_U_2(init->MaxInboundStreams));
663 ND_PRINT("[init TSN: %u] ", GET_BE_U_4(init->initialTSN));
664 bp += sizeof(*init);
665 sctpPacketLengthRemaining -= sizeof(*init);
666 chunkLengthRemaining -= sizeof(*init);
667
668 #if 0 /* ALC you can add code for optional params here */
669 if( chunkLengthRemaining != 0 )
670 ND_PRINT(" @@@@@ UNFINISHED @@@@@@%s\n",
671 "Optional params present, but not printed.");
672 #endif
673 bp += chunkLengthRemaining;
674 sctpPacketLengthRemaining -= chunkLengthRemaining;
675 chunkLengthRemaining = 0;
676 break;
677 }
678 case SCTP_SELECTIVE_ACK:
679 {
680 const struct sctpSelectiveAck *sack;
681 const struct sctpSelectiveFrag *frag;
682 u_int fragNo, tsnNo;
683 const u_char *dupTSN;
684
685 ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <,
686 sizeof(*sack));
687 sack=(const struct sctpSelectiveAck*)bp;
688 ND_PRINT("[cum ack %u] ", GET_BE_U_4(sack->highestConseqTSN));
689 ND_PRINT("[a_rwnd %u] ", GET_BE_U_4(sack->updatedRwnd));
690 ND_PRINT("[#gap acks %u] ", GET_BE_U_2(sack->numberOfdesc));
691 ND_PRINT("[#dup tsns %u] ", GET_BE_U_2(sack->numDupTsns));
692 bp += sizeof(*sack);
693 sctpPacketLengthRemaining -= sizeof(*sack);
694 chunkLengthRemaining -= sizeof(*sack);
695
696
697 /* print gaps */
698 for (fragNo=0;
699 chunkLengthRemaining != 0 && fragNo < GET_BE_U_2(sack->numberOfdesc);
700 bp += sizeof(*frag), sctpPacketLengthRemaining -= sizeof(*frag), chunkLengthRemaining -= sizeof(*frag), fragNo++) {
701 ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <,
702 sizeof(*frag));
703 frag = (const struct sctpSelectiveFrag *)bp;
704 ND_PRINT("\n\t\t[gap ack block #%u: start = %u, end = %u] ",
705 fragNo+1,
706 GET_BE_U_4(sack->highestConseqTSN) + GET_BE_U_2(frag->fragmentStart),
707 GET_BE_U_4(sack->highestConseqTSN) + GET_BE_U_2(frag->fragmentEnd));
708 }
709
710 /* print duplicate TSNs */
711 for (tsnNo=0;
712 chunkLengthRemaining != 0 && tsnNo<GET_BE_U_2(sack->numDupTsns);
713 bp += 4, sctpPacketLengthRemaining -= 4, chunkLengthRemaining -= 4, tsnNo++) {
714 ND_ICHECKMSG_U("chunk length", chunkLengthRemaining, <, 4);
715 dupTSN = (const u_char *)bp;
716 ND_PRINT("\n\t\t[dup TSN #%u: %u] ", tsnNo+1,
717 GET_BE_U_4(dupTSN));
718 }
719 break;
720 }
721 default :
722 {
723 bp += chunkLengthRemaining;
724 sctpPacketLengthRemaining -= chunkLengthRemaining;
725 chunkLengthRemaining = 0;
726 break;
727 }
728 }
729
730 /*
731 * Any extra stuff at the end of the chunk?
732 * XXX - report this?
733 */
734 bp += chunkLengthRemaining;
735 sctpPacketLengthRemaining -= chunkLengthRemaining;
736
737 if (ndo->ndo_vflag < 2)
738 sep = ", (";
739
740 if (align != 0) {
741 /*
742 * Fail if the alignment padding isn't in the captured data.
743 * Otherwise, skip it.
744 */
745 ND_TCHECK_LEN(bp, align);
746 bp += align;
747 sctpPacketLengthRemaining -= align;
748 }
749 }
750 return;
751 invalid:
752 nd_print_invalid(ndo);
753 }