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