]> The Tcpdump Group git mirrors - tcpdump/blob - print-sctp.c
VTP: Add bounds checks
[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 const struct sctpHeader *sctpPktHdr;
497 const struct ip *ip;
498 const struct ip6_hdr *ip6;
499 const void *endPacketPtr;
500 u_short sourcePort, destPort;
501 int chunkCount;
502 const struct sctpChunkDesc *chunkDescPtr;
503 const void *nextChunk;
504 const char *sep;
505 int isforces = 0;
506
507
508 sctpPktHdr = (const struct sctpHeader*) bp;
509 endPacketPtr = (const u_char*)sctpPktHdr+sctpPacketLength;
510
511 if( (u_long) endPacketPtr > (u_long) ndo->ndo_snapend)
512 endPacketPtr = (const void *) ndo->ndo_snapend;
513 ip = (const struct ip *)bp2;
514 if (IP_V(ip) == 6)
515 ip6 = (const struct ip6_hdr *)bp2;
516 else
517 ip6 = NULL;
518 ND_TCHECK(*sctpPktHdr);
519
520 if (sctpPacketLength < sizeof(struct sctpHeader))
521 {
522 ND_PRINT((ndo, "truncated-sctp - %ld bytes missing!",
523 (long)sctpPacketLength-sizeof(struct sctpHeader)));
524 return;
525 }
526
527 /* sctpPacketLength -= sizeof(struct sctpHeader); packet length */
528 /* is now only as long as the payload */
529
530 sourcePort = EXTRACT_16BITS(&sctpPktHdr->source);
531 destPort = EXTRACT_16BITS(&sctpPktHdr->destination);
532
533 if (ip6) {
534 ND_PRINT((ndo, "%s.%d > %s.%d: sctp",
535 ip6addr_string(ndo, &ip6->ip6_src),
536 sourcePort,
537 ip6addr_string(ndo, &ip6->ip6_dst),
538 destPort));
539 } else
540 {
541 ND_PRINT((ndo, "%s.%d > %s.%d: sctp",
542 ipaddr_string(ndo, &ip->ip_src),
543 sourcePort,
544 ipaddr_string(ndo, &ip->ip_dst),
545 destPort));
546 }
547
548 if (isForCES_port(sourcePort)) {
549 ND_PRINT((ndo, "[%s]", tok2str(ForCES_channels, NULL, sourcePort)));
550 isforces = 1;
551 }
552 if (isForCES_port(destPort)) {
553 ND_PRINT((ndo, "[%s]", tok2str(ForCES_channels, NULL, destPort)));
554 isforces = 1;
555 }
556
557 if (ndo->ndo_vflag >= 2)
558 sep = "\n\t";
559 else
560 sep = " (";
561 /* cycle through all chunks, printing information on each one */
562 for (chunkCount = 0,
563 chunkDescPtr = (const struct sctpChunkDesc *)
564 ((const u_char*) sctpPktHdr + sizeof(struct sctpHeader));
565 chunkDescPtr != NULL &&
566 ( (const void *)
567 ((const u_char *) chunkDescPtr + sizeof(struct sctpChunkDesc))
568 <= endPacketPtr);
569
570 chunkDescPtr = (const struct sctpChunkDesc *) nextChunk, chunkCount++)
571 {
572 uint16_t chunkLength;
573 const u_char *chunkEnd;
574 uint16_t align;
575
576 ND_TCHECK(*chunkDescPtr);
577 chunkLength = EXTRACT_16BITS(&chunkDescPtr->chunkLength);
578 if (chunkLength < sizeof(*chunkDescPtr)) {
579 ND_PRINT((ndo, "%s%d) [Bad chunk length %u]", sep, chunkCount+1, chunkLength));
580 break;
581 }
582
583 ND_TCHECK2(*((const uint8_t *)chunkDescPtr), chunkLength);
584 chunkEnd = ((const u_char*)chunkDescPtr + chunkLength);
585
586 align=chunkLength % 4;
587 if (align != 0)
588 align = 4 - align;
589
590 nextChunk = (const void *) (chunkEnd + align);
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 const u_char *payloadPtr;
602 u_int payload_size;
603
604 if ((chunkDescPtr->chunkFlg & SCTP_DATA_UNORDERED)
605 == SCTP_DATA_UNORDERED)
606 ND_PRINT((ndo, "(U)"));
607
608 if ((chunkDescPtr->chunkFlg & SCTP_DATA_FIRST_FRAG)
609 == SCTP_DATA_FIRST_FRAG)
610 ND_PRINT((ndo, "(B)"));
611
612 if ((chunkDescPtr->chunkFlg & SCTP_DATA_LAST_FRAG)
613 == SCTP_DATA_LAST_FRAG)
614 ND_PRINT((ndo, "(E)"));
615
616 if( ((chunkDescPtr->chunkFlg & SCTP_DATA_UNORDERED)
617 == SCTP_DATA_UNORDERED)
618 ||
619 ((chunkDescPtr->chunkFlg & SCTP_DATA_FIRST_FRAG)
620 == SCTP_DATA_FIRST_FRAG)
621 ||
622 ((chunkDescPtr->chunkFlg & SCTP_DATA_LAST_FRAG)
623 == SCTP_DATA_LAST_FRAG) )
624 ND_PRINT((ndo, " "));
625
626 dataHdrPtr=(const struct sctpDataPart*)(chunkDescPtr+1);
627
628 ppid = EXTRACT_32BITS(&dataHdrPtr->payloadtype);
629 ND_PRINT((ndo, "[TSN: %u] ", EXTRACT_32BITS(&dataHdrPtr->TSN)));
630 ND_PRINT((ndo, "[SID: %u] ", EXTRACT_16BITS(&dataHdrPtr->streamId)));
631 ND_PRINT((ndo, "[SSEQ %u] ", EXTRACT_16BITS(&dataHdrPtr->sequence)));
632 ND_PRINT((ndo, "[PPID %s] ",
633 tok2str(PayloadProto_idents, "0x%x", ppid)));
634
635 if (!isforces) {
636 isforces = (ppid == SCTP_PPID_FORCES_HP) ||
637 (ppid == SCTP_PPID_FORCES_MP) ||
638 (ppid == SCTP_PPID_FORCES_LP);
639 }
640
641 payloadPtr = (const u_char *) (dataHdrPtr + 1);
642 if (EXTRACT_16BITS(&chunkDescPtr->chunkLength) <
643 sizeof(struct sctpDataPart) + sizeof(struct sctpChunkDesc) + 1) {
644 ND_PRINT((ndo, "bogus chunk length %u]", EXTRACT_16BITS(&chunkDescPtr->chunkLength)));
645 return;
646 }
647
648 payload_size = EXTRACT_16BITS(&chunkDescPtr->chunkLength) -
649 (sizeof(struct sctpDataPart) + sizeof(struct sctpChunkDesc));
650
651 if (isforces) {
652 forces_print(ndo, payloadPtr, payload_size);
653 } else if (ndo->ndo_vflag >= 2) { /* if verbose output is specified */
654 /* at the command line */
655 switch (ppid) {
656 case SCTP_PPID_M3UA :
657 m3ua_print(ndo, payloadPtr, payload_size);
658 break;
659 default:
660 ND_PRINT((ndo, "[Payload"));
661 if (!ndo->ndo_suppress_default_print) {
662 ND_PRINT((ndo, ":"));
663 ND_DEFAULTPRINT(payloadPtr, payload_size);
664 }
665 ND_PRINT((ndo, "]"));
666 break;
667 }
668 }
669 break;
670 }
671 case SCTP_INITIATION :
672 {
673 const struct sctpInitiation *init;
674
675 init=(const struct sctpInitiation*)(chunkDescPtr+1);
676 ND_PRINT((ndo, "[init tag: %u] ", EXTRACT_32BITS(&init->initTag)));
677 ND_PRINT((ndo, "[rwnd: %u] ", EXTRACT_32BITS(&init->rcvWindowCredit)));
678 ND_PRINT((ndo, "[OS: %u] ", EXTRACT_16BITS(&init->NumPreopenStreams)));
679 ND_PRINT((ndo, "[MIS: %u] ", EXTRACT_16BITS(&init->MaxInboundStreams)));
680 ND_PRINT((ndo, "[init TSN: %u] ", EXTRACT_32BITS(&init->initialTSN)));
681
682 #if(0) /* ALC you can add code for optional params here */
683 if( (init+1) < chunkEnd )
684 ND_PRINT((ndo, " @@@@@ UNFINISHED @@@@@@%s\n",
685 "Optional params present, but not printed."));
686 #endif
687 break;
688 }
689 case SCTP_INITIATION_ACK :
690 {
691 const struct sctpInitiation *init;
692
693 init=(const struct sctpInitiation*)(chunkDescPtr+1);
694 ND_PRINT((ndo, "[init tag: %u] ", EXTRACT_32BITS(&init->initTag)));
695 ND_PRINT((ndo, "[rwnd: %u] ", EXTRACT_32BITS(&init->rcvWindowCredit)));
696 ND_PRINT((ndo, "[OS: %u] ", EXTRACT_16BITS(&init->NumPreopenStreams)));
697 ND_PRINT((ndo, "[MIS: %u] ", EXTRACT_16BITS(&init->MaxInboundStreams)));
698 ND_PRINT((ndo, "[init TSN: %u] ", EXTRACT_32BITS(&init->initialTSN)));
699
700 #if(0) /* ALC you can add code for optional params here */
701 if( (init+1) < chunkEnd )
702 ND_PRINT((ndo, " @@@@@ UNFINISHED @@@@@@%s\n",
703 "Optional params present, but not printed."));
704 #endif
705 break;
706 }
707 case SCTP_SELECTIVE_ACK:
708 {
709 const struct sctpSelectiveAck *sack;
710 const struct sctpSelectiveFrag *frag;
711 int fragNo, tsnNo;
712 const u_char *dupTSN;
713
714 sack=(const struct sctpSelectiveAck*)(chunkDescPtr+1);
715 ND_PRINT((ndo, "[cum ack %u] ", EXTRACT_32BITS(&sack->highestConseqTSN)));
716 ND_PRINT((ndo, "[a_rwnd %u] ", EXTRACT_32BITS(&sack->updatedRwnd)));
717 ND_PRINT((ndo, "[#gap acks %u] ", EXTRACT_16BITS(&sack->numberOfdesc)));
718 ND_PRINT((ndo, "[#dup tsns %u] ", EXTRACT_16BITS(&sack->numDupTsns)));
719
720
721 /* print gaps */
722 for (frag = ( (const struct sctpSelectiveFrag *)
723 ((const struct sctpSelectiveAck *) sack+1)),
724 fragNo=0;
725 (const void *)frag < nextChunk && fragNo < EXTRACT_16BITS(&sack->numberOfdesc);
726 frag++, fragNo++)
727 ND_PRINT((ndo, "\n\t\t[gap ack block #%d: start = %u, end = %u] ",
728 fragNo+1,
729 EXTRACT_32BITS(&sack->highestConseqTSN) + EXTRACT_16BITS(&frag->fragmentStart),
730 EXTRACT_32BITS(&sack->highestConseqTSN) + EXTRACT_16BITS(&frag->fragmentEnd)));
731
732
733 /* print duplicate TSNs */
734 for (dupTSN = (const u_char *)frag, tsnNo=0;
735 (const void *) dupTSN < nextChunk && tsnNo<EXTRACT_16BITS(&sack->numDupTsns);
736 dupTSN += 4, tsnNo++)
737 ND_PRINT((ndo, "\n\t\t[dup TSN #%u: %u] ", tsnNo+1,
738 EXTRACT_32BITS(dupTSN)));
739
740 break;
741 }
742 }
743
744 if (ndo->ndo_vflag < 2)
745 sep = ", (";
746 }
747 return;
748
749 trunc:
750 ND_PRINT((ndo, "[|sctp]"));
751 }