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