1 /*
   2  * This file and its contents are supplied under the terms of the
   3  * Common Development and Distribution License ("CDDL"), version 1.0.
   4  * You may only use this file in accordance with the terms of version
   5  * 1.0 of the CDDL.
   6  *
   7  * A full copy of the text of the CDDL should have accompanied this
   8  * source.  A copy of the CDDL is also available via the Internet at
   9  * http://www.illumos.org/license/CDDL.
  10  */
  11 
  12 /*
  13  * Copyright 2013 David Hoeppner.  All rights reserved.
  14  */
  15 
  16 #pragma D depends_on module unix
  17 #pragma D depends_on provider sctp
  18 
  19 /*
  20  * SCTP connection states.
  21  */
  22 inline int32_t SCTP_STATE_IDLE = @SCTPS_IDLE@;
  23 #pragma D binding "1.9.2" SCTP_STATE_IDLE
  24 inline int32_t SCTP_STATE_BOUND = @SCTPS_BOUND@;
  25 #pragma D binding "1.9.2" SCTP_STATE_BOUND
  26 inline int32_t SCTP_STATE_LISTEN = @SCTPS_LISTEN@;
  27 #pragma D binding "1.9.2" SCTP_STATE_LISTEN
  28 inline int32_t SCTP_STATE_COOKIE_WAIT = @SCTPS_COOKIE_WAIT@;
  29 #pragma D binding "1.9.2" SCTP_STATE_COOKIE_WAIT
  30 inline int32_t SCTP_STATE_COOKIE_ECHOED = @SCTPS_COOKIE_ECHOED@;
  31 #pragma D binding "1.9.2" SCTP_STATE_COOKIE_ECHOED
  32 inline int32_t SCTP_STATE_ESTABLISHED = @SCTPS_ESTABLISHED@;
  33 #pragma D binding "1.9.2" SCTP_STATE_ESTABLISHED
  34 inline int32_t SCTP_STATE_SHUTDOWN_PENDING = @SCTPS_SHUTDOWN_PENDING@;
  35 #pragma D binding "1.9.2" SCTP_STATE_SHUTDOWN_PENDING
  36 inline int32_t SCTP_STATE_SHUTDOWN_SENT = @SCTPS_SHUTDOWN_SENT@;
  37 #pragma D binding "1.9.2" SCTP_STATE_SHUTDOWN_SENT
  38 inline int32_t SCTP_STATE_SHUTDOWN_RECEIVED = @SCTPS_SHUTDOWN_RECEIVED@;
  39 #pragma D binding "1.9.2" SCTP_STATE_SHUTDOWN_RECEIVED
  40 inline int32_t SCTP_STATE_SHUTDOWN_ACK_SENT = @SCTPS_SHUTDOWN_ACK_SENT@;
  41 #pragma D binding "1.9.2" SCTP_STATE_SHUTDOWN_ACK_SENT
  42 
  43 /*
  44  * Convert a SCTP state value to a string.
  45  */
  46 inline string sctp_state_string[int32_t state] =
  47         state == SCTP_STATE_IDLE ? "state-idle" :
  48         state == SCTP_STATE_BOUND ? "state-bound" :
  49         state == SCTP_STATE_LISTEN ? "state-listen" :
  50         state == SCTP_STATE_COOKIE_WAIT ? "state-cookie-wait" :
  51         state == SCTP_STATE_COOKIE_ECHOED ? "state-cookie-echoed" :
  52         state == SCTP_STATE_ESTABLISHED ? "state-established" :
  53         state == SCTP_STATE_SHUTDOWN_PENDING ? "state-shutdown-pending" :
  54         state == SCTP_STATE_SHUTDOWN_SENT ? "state-shutdown-sent" :
  55         state == SCTP_STATE_SHUTDOWN_RECEIVED ? "state-shutdown-received" :
  56         state == SCTP_STATE_SHUTDOWN_ACK_SENT ? "state-shutdown-ack-sent" :
  57         "<unknown>";
  58 #pragma D binding "1.9.2" sctp_state_string
  59 
  60 /*
  61  * sctpinfo is the SCTP header fields.
  62  */
  63 typedef struct sctpinfo {
  64         uint16_t        sctp_sport;     /* source port */
  65         uint16_t        sctp_dport;     /* destination port */
  66         uint32_t        sctp_verify;    /* verification tag */
  67         uint32_t        sctp_checksum;  /* headers + data checksum */
  68         sctp_chunk_hdr_t sctp_chunk_hdr;
  69         sctp_hdr_t      *sctp_hdr;      /* raw SCTP header */
  70 } sctpinfo_t;
  71 
  72 /*
  73  * sctpsinfo sctp state info.
  74  */
  75 typedef struct sctpsinfo {
  76         string  sctps_laddr;            /* local address */
  77         string  sctps_raddr;            /* remote address */
  78         int32_t sctps_state;            /* connection state */
  79 } sctpsinfo_t;
  80 
  81 #pragma D binding "1.9.2" translator
  82 translator sctpinfo_t < sctp_hdr_t *S > {
  83         sctp_sport = ntohs(S->sh_sport);
  84         sctp_dport = ntohs(S->sh_dport);
  85         sctp_verify = ntohl(S->sh_verf);
  86         sctp_checksum = ntohl(S->sh_chksum);
  87         sctp_hdr = S;
  88 };