]> The Tcpdump Group git mirrors - tcpdump/blobdiff - print-sctp.c
Makefile.in: don't remove configure and config.h.in in make distclean.
[tcpdump] / print-sctp.c
index 9384a93d2847db82f76e468291ccea278471c8bf..cc5bee4ff6f4ebab7cb871e62bd433017dbd2fca 100644 (file)
@@ -41,6 +41,7 @@
 
 #include "netdissect-stdinc.h"
 
 
 #include "netdissect-stdinc.h"
 
+#define ND_LONGJMP_FROM_TCHECK
 #include "netdissect.h"
 #include "addrtoname.h"
 #include "extract.h"
 #include "netdissect.h"
 #include "addrtoname.h"
 #include "extract.h"
@@ -451,7 +452,7 @@ void
 sctp_print(netdissect_options *ndo,
           const u_char *bp,        /* beginning of sctp packet */
           const u_char *bp2,       /* beginning of enclosing */
 sctp_print(netdissect_options *ndo,
           const u_char *bp,        /* beginning of sctp packet */
           const u_char *bp2,       /* beginning of enclosing */
-          u_int sctpPacketLength)  /* ip packet */
+          u_int sctpPacketLength)  /* sctp packet */
 {
   u_int sctpPacketLengthRemaining;
   const struct sctpHeader *sctpPktHdr;
 {
   u_int sctpPacketLengthRemaining;
   const struct sctpHeader *sctpPktHdr;
@@ -465,12 +466,7 @@ sctp_print(netdissect_options *ndo,
   int isforces = 0;
 
   ndo->ndo_protocol = "sctp";
   int isforces = 0;
 
   ndo->ndo_protocol = "sctp";
-  if (sctpPacketLength < sizeof(struct sctpHeader))
-    {
-      ND_PRINT("truncated-sctp - %ld bytes missing!",
-                  (long)(sizeof(struct sctpHeader) - sctpPacketLength));
-      return;
-    }
+  ND_ICHECKMSG_ZU("length", sctpPacketLength, <, sizeof(struct sctpHeader));
   sctpPktHdr = (const struct sctpHeader*) bp;
   ND_TCHECK_SIZE(sctpPktHdr);
   sctpPacketLengthRemaining = sctpPacketLength;
   sctpPktHdr = (const struct sctpHeader*) bp;
   ND_TCHECK_SIZE(sctpPktHdr);
   sctpPacketLengthRemaining = sctpPacketLength;
@@ -486,16 +482,15 @@ sctp_print(netdissect_options *ndo,
 
   if (ip6) {
     ND_PRINT("%s.%u > %s.%u: sctp",
 
   if (ip6) {
     ND_PRINT("%s.%u > %s.%u: sctp",
-      ip6addr_string(ndo, ip6->ip6_src),
+      GET_IP6ADDR_STRING(ip6->ip6_src),
       sourcePort,
       sourcePort,
-      ip6addr_string(ndo, ip6->ip6_dst),
+      GET_IP6ADDR_STRING(ip6->ip6_dst),
       destPort);
       destPort);
-  } else
-  {
+  } else {
     ND_PRINT("%s.%u > %s.%u: sctp",
     ND_PRINT("%s.%u > %s.%u: sctp",
-      ipaddr_string(ndo, ip->ip_src),
+      GET_IPADDR_STRING(ip->ip_src),
       sourcePort,
       sourcePort,
-      ipaddr_string(ndo, ip->ip_dst),
+      GET_IPADDR_STRING(ip->ip_dst),
       destPort);
   }
 
       destPort);
   }
 
@@ -579,10 +574,8 @@ sctp_print(netdissect_options *ndo,
                ((chunkFlg & SCTP_DATA_LAST_FRAG) == SCTP_DATA_LAST_FRAG) )
              ND_PRINT(" ");
 
                ((chunkFlg & SCTP_DATA_LAST_FRAG) == SCTP_DATA_LAST_FRAG) )
              ND_PRINT(" ");
 
-           if (chunkLengthRemaining < sizeof(*dataHdrPtr)) {
-               ND_PRINT("bogus chunk length %u]", chunkLength);
-               return;
-           }
+           ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <,
+                           sizeof(*dataHdrPtr));
            dataHdrPtr=(const struct sctpDataPart*)bp;
 
            ppid = GET_BE_U_4(dataHdrPtr->payloadtype);
            dataHdrPtr=(const struct sctpDataPart*)bp;
 
            ppid = GET_BE_U_4(dataHdrPtr->payloadtype);
@@ -601,11 +594,8 @@ sctp_print(netdissect_options *ndo,
            bp += sizeof(*dataHdrPtr);
            sctpPacketLengthRemaining -= sizeof(*dataHdrPtr);
            chunkLengthRemaining -= sizeof(*dataHdrPtr);
            bp += sizeof(*dataHdrPtr);
            sctpPacketLengthRemaining -= sizeof(*dataHdrPtr);
            chunkLengthRemaining -= sizeof(*dataHdrPtr);
+           ND_ICHECKMSG_U("chunk length", chunkLengthRemaining, ==, 0);
            payload_size = chunkLengthRemaining;
            payload_size = chunkLengthRemaining;
-           if (payload_size == 0) {
-               ND_PRINT("bogus chunk length %u]", chunkLength);
-               return;
-           }
 
            if (isforces) {
                forces_print(ndo, bp, payload_size);
 
            if (isforces) {
                forces_print(ndo, bp, payload_size);
@@ -638,10 +628,8 @@ sctp_print(netdissect_options *ndo,
          {
            const struct sctpInitiation *init;
 
          {
            const struct sctpInitiation *init;
 
-           if (chunkLengthRemaining < sizeof(*init)) {
-               ND_PRINT("bogus chunk length %u]", chunkLength);
-               return;
-           }
+           ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <,
+                           sizeof(*init));
            init=(const struct sctpInitiation*)bp;
            ND_PRINT("[init tag: %u] ", GET_BE_U_4(init->initTag));
            ND_PRINT("[rwnd: %u] ", GET_BE_U_4(init->rcvWindowCredit));
            init=(const struct sctpInitiation*)bp;
            ND_PRINT("[init tag: %u] ", GET_BE_U_4(init->initTag));
            ND_PRINT("[rwnd: %u] ", GET_BE_U_4(init->rcvWindowCredit));
@@ -666,10 +654,8 @@ sctp_print(netdissect_options *ndo,
          {
            const struct sctpInitiation *init;
 
          {
            const struct sctpInitiation *init;
 
-           if (chunkLengthRemaining < sizeof(*init)) {
-               ND_PRINT("bogus chunk length %u]", chunkLength);
-               return;
-           }
+           ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <,
+                           sizeof(*init));
            init=(const struct sctpInitiation*)bp;
            ND_PRINT("[init tag: %u] ", GET_BE_U_4(init->initTag));
            ND_PRINT("[rwnd: %u] ", GET_BE_U_4(init->rcvWindowCredit));
            init=(const struct sctpInitiation*)bp;
            ND_PRINT("[init tag: %u] ", GET_BE_U_4(init->initTag));
            ND_PRINT("[rwnd: %u] ", GET_BE_U_4(init->rcvWindowCredit));
@@ -697,10 +683,8 @@ sctp_print(netdissect_options *ndo,
            u_int fragNo, tsnNo;
            const u_char *dupTSN;
 
            u_int fragNo, tsnNo;
            const u_char *dupTSN;
 
-           if (chunkLengthRemaining < sizeof(*sack)) {
-             ND_PRINT("bogus chunk length %u]", chunkLength);
-             return;
-           }
+           ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <,
+                           sizeof(*sack));
            sack=(const struct sctpSelectiveAck*)bp;
            ND_PRINT("[cum ack %u] ", GET_BE_U_4(sack->highestConseqTSN));
            ND_PRINT("[a_rwnd %u] ", GET_BE_U_4(sack->updatedRwnd));
            sack=(const struct sctpSelectiveAck*)bp;
            ND_PRINT("[cum ack %u] ", GET_BE_U_4(sack->highestConseqTSN));
            ND_PRINT("[a_rwnd %u] ", GET_BE_U_4(sack->updatedRwnd));
@@ -715,10 +699,8 @@ sctp_print(netdissect_options *ndo,
            for (fragNo=0;
                 chunkLengthRemaining != 0 && fragNo < GET_BE_U_2(sack->numberOfdesc);
                 bp += sizeof(*frag), sctpPacketLengthRemaining -= sizeof(*frag), chunkLengthRemaining -= sizeof(*frag), fragNo++) {
            for (fragNo=0;
                 chunkLengthRemaining != 0 && fragNo < GET_BE_U_2(sack->numberOfdesc);
                 bp += sizeof(*frag), sctpPacketLengthRemaining -= sizeof(*frag), chunkLengthRemaining -= sizeof(*frag), fragNo++) {
-             if (chunkLengthRemaining < sizeof(*frag)) {
-               ND_PRINT("bogus chunk length %u]", chunkLength);
-               return;
-             }
+             ND_ICHECKMSG_ZU("chunk length", chunkLengthRemaining, <,
+                           sizeof(*frag));
              frag = (const struct sctpSelectiveFrag *)bp;
              ND_PRINT("\n\t\t[gap ack block #%u: start = %u, end = %u] ",
                     fragNo+1,
              frag = (const struct sctpSelectiveFrag *)bp;
              ND_PRINT("\n\t\t[gap ack block #%u: start = %u, end = %u] ",
                     fragNo+1,
@@ -730,10 +712,7 @@ sctp_print(netdissect_options *ndo,
            for (tsnNo=0;
                 chunkLengthRemaining != 0 && tsnNo<GET_BE_U_2(sack->numDupTsns);
                 bp += 4, sctpPacketLengthRemaining -= 4, chunkLengthRemaining -= 4, tsnNo++) {
            for (tsnNo=0;
                 chunkLengthRemaining != 0 && tsnNo<GET_BE_U_2(sack->numDupTsns);
                 bp += 4, sctpPacketLengthRemaining -= 4, chunkLengthRemaining -= 4, tsnNo++) {
-             if (chunkLengthRemaining < 4) {
-               ND_PRINT("bogus chunk length %u]", chunkLength);
-               return;
-             }
+             ND_ICHECKMSG_U("chunk length", chunkLengthRemaining, <, 4);
              dupTSN = (const u_char *)bp;
              ND_PRINT("\n\t\t[dup TSN #%u: %u] ", tsnNo+1,
                       GET_BE_U_4(dupTSN));
              dupTSN = (const u_char *)bp;
              ND_PRINT("\n\t\t[dup TSN #%u: %u] ", tsnNo+1,
                       GET_BE_U_4(dupTSN));
@@ -770,7 +749,6 @@ sctp_print(netdissect_options *ndo,
       }
     }
     return;
       }
     }
     return;
-
-trunc:
-    nd_print_trunc(ndo);
+invalid:
+    nd_print_invalid(ndo);
 }
 }