1*1e88cc8bSMichael Tuexen /* 2*1e88cc8bSMichael Tuexen * CDDL HEADER START 3*1e88cc8bSMichael Tuexen * 4*1e88cc8bSMichael Tuexen * The contents of this file are subject to the terms of the 5*1e88cc8bSMichael Tuexen * Common Development and Distribution License (the "License"). 6*1e88cc8bSMichael Tuexen * You may not use this file except in compliance with the License. 7*1e88cc8bSMichael Tuexen * 8*1e88cc8bSMichael Tuexen * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*1e88cc8bSMichael Tuexen * or http://www.opensolaris.org/os/licensing. 10*1e88cc8bSMichael Tuexen * See the License for the specific language governing permissions 11*1e88cc8bSMichael Tuexen * and limitations under the License. 12*1e88cc8bSMichael Tuexen * 13*1e88cc8bSMichael Tuexen * When distributing Covered Code, include this CDDL HEADER in each 14*1e88cc8bSMichael Tuexen * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*1e88cc8bSMichael Tuexen * If applicable, add the following below this CDDL HEADER, with the 16*1e88cc8bSMichael Tuexen * fields enclosed by brackets "[]" replaced with your own identifying 17*1e88cc8bSMichael Tuexen * information: Portions Copyright [yyyy] [name of copyright owner] 18*1e88cc8bSMichael Tuexen * 19*1e88cc8bSMichael Tuexen * CDDL HEADER END 20*1e88cc8bSMichael Tuexen */ 21*1e88cc8bSMichael Tuexen /* 22*1e88cc8bSMichael Tuexen * Copyright (c) 2018 Michael Tuexen <tuexen@FreeBSD.org> 23*1e88cc8bSMichael Tuexen */ 24*1e88cc8bSMichael Tuexen 25*1e88cc8bSMichael Tuexen #pragma D depends_on library ip.d 26*1e88cc8bSMichael Tuexen #pragma D depends_on library socket.d 27*1e88cc8bSMichael Tuexen #pragma D depends_on module kernel 28*1e88cc8bSMichael Tuexen #pragma D depends_on provider sctp 29*1e88cc8bSMichael Tuexen 30*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_MASK 31*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_MASK = 0x0000007f; 32*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_SHUTDOWN_PENDING 33*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_SHUTDOWN_PENDING = 0x00000080; 34*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_CLOSED_SOCKET 35*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_CLOSED_SOCKET = 0x00000100; 36*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_ABOUT_TO_BE_FREED 37*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_ABOUT_TO_BE_FREED = 0x00000200; 38*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_ABOUT_TO_BE_FREED 39*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_PARTIAL_MSG_LEFT = 0x00000400; 40*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_PARTIAL_MSG_LEFT 41*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_WAS_ABORTED = 0x00000800; 42*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_IN_ACCEPT_QUEUE 43*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_IN_ACCEPT_QUEUE = 0x00001000; 44*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_BOUND 45*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_BOUND = 0x00001000; 46*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_EMPTY 47*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_EMPTY = 0x00000000; 48*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_CLOSED 49*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_CLOSED = 0x00000000; 50*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_INUSE 51*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_INUSE = 0x00000001; 52*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_COOKIE_WAIT 53*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_COOKIE_WAIT = 0x00000002; 54*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_COOKIE_ECHOED 55*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_COOKIE_ECHOED = 0x00000004; 56*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_ESTABLISHED 57*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_ESTABLISHED = 0x00000008; 58*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_OPEN 59*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_OPEN = 0x00000008; 60*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_SHUTDOWN_SENT 61*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_SHUTDOWN_SENT = 0x00000010; 62*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_SHUTDOWN_RECEIVED 63*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_SHUTDOWN_RECEIVED = 0x00000020; 64*1e88cc8bSMichael Tuexen #pragma D binding "1.13" SCTP_STATE_SHUTDOWN_ACK_SENT 65*1e88cc8bSMichael Tuexen inline int32_t SCTP_STATE_SHUTDOWN_ACK_SENT = 0x00000040; 66*1e88cc8bSMichael Tuexen 67*1e88cc8bSMichael Tuexen /* SCTP association state strings. */ 68*1e88cc8bSMichael Tuexen #pragma D binding "1.13" sctp_state_string 69*1e88cc8bSMichael Tuexen inline string sctp_state_string[int32_t state] = 70*1e88cc8bSMichael Tuexen state & SCTP_STATE_ABOUT_TO_BE_FREED ? "state-closed" : 71*1e88cc8bSMichael Tuexen state & SCTP_STATE_SHUTDOWN_PENDING ? "state-shutdown-pending" : 72*1e88cc8bSMichael Tuexen (state & SCTP_STATE_MASK) == SCTP_STATE_EMPTY ? "state-closed" : 73*1e88cc8bSMichael Tuexen (state & SCTP_STATE_MASK) == SCTP_STATE_INUSE ? "state-closed" : 74*1e88cc8bSMichael Tuexen (state & SCTP_STATE_MASK) == SCTP_STATE_COOKIE_WAIT ? "state-cookie-wait" : 75*1e88cc8bSMichael Tuexen (state & SCTP_STATE_MASK) == SCTP_STATE_COOKIE_ECHOED ? "state-cookie-echoed" : 76*1e88cc8bSMichael Tuexen (state & SCTP_STATE_MASK) == SCTP_STATE_OPEN ? "state-established" : 77*1e88cc8bSMichael Tuexen (state & SCTP_STATE_MASK) == SCTP_STATE_SHUTDOWN_SENT ? "state-shutdown-sent" : 78*1e88cc8bSMichael Tuexen (state & SCTP_STATE_MASK) == SCTP_STATE_SHUTDOWN_RECEIVED ? "state-shutdown-received" : 79*1e88cc8bSMichael Tuexen (state & SCTP_STATE_MASK) == SCTP_STATE_SHUTDOWN_ACK_SENT ? "state-shutdown-ack-sent" : 80*1e88cc8bSMichael Tuexen "<unknown>"; 81*1e88cc8bSMichael Tuexen 82*1e88cc8bSMichael Tuexen /* 83*1e88cc8bSMichael Tuexen * sctpsinfo contains stable SCTP details. 84*1e88cc8bSMichael Tuexen */ 85*1e88cc8bSMichael Tuexen typedef struct sctpsinfo { 86*1e88cc8bSMichael Tuexen uintptr_t sctps_addr; /* pointer to struct sctp_tcb */ 87*1e88cc8bSMichael Tuexen int sctps_num_raddrs; /* number of remote addresses */ 88*1e88cc8bSMichael Tuexen uintptr_t sctps_raddrs; /* pointer to struct sctp_nets */ 89*1e88cc8bSMichael Tuexen int sctps_num_laddrs; /* number of local addresses */ 90*1e88cc8bSMichael Tuexen uintptr_t sctps_laddrs; /* pointer to struct sctp_laddr */ 91*1e88cc8bSMichael Tuexen uint16_t sctps_lport; /* local port */ 92*1e88cc8bSMichael Tuexen uint16_t sctps_rport; /* remote port */ 93*1e88cc8bSMichael Tuexen string sctps_laddr; /* local address, as a string */ 94*1e88cc8bSMichael Tuexen string sctps_raddr; /* remote address, as a string */ 95*1e88cc8bSMichael Tuexen int32_t sctps_state; 96*1e88cc8bSMichael Tuexen } sctpsinfo_t; 97*1e88cc8bSMichael Tuexen 98*1e88cc8bSMichael Tuexen /* 99*1e88cc8bSMichael Tuexen * sctplsinfo provides the old SCTP state for state changes. 100*1e88cc8bSMichael Tuexen */ 101*1e88cc8bSMichael Tuexen typedef struct sctplsinfo { 102*1e88cc8bSMichael Tuexen int32_t sctps_state; /* previous SCTP state */ 103*1e88cc8bSMichael Tuexen } sctplsinfo_t; 104*1e88cc8bSMichael Tuexen 105*1e88cc8bSMichael Tuexen /* 106*1e88cc8bSMichael Tuexen * sctpinfo is the SCTP header fields. 107*1e88cc8bSMichael Tuexen */ 108*1e88cc8bSMichael Tuexen typedef struct sctpinfo { 109*1e88cc8bSMichael Tuexen uint16_t sctp_sport; /* source port */ 110*1e88cc8bSMichael Tuexen uint16_t sctp_dport; /* destination port */ 111*1e88cc8bSMichael Tuexen uint32_t sctp_verify; /* verification tag */ 112*1e88cc8bSMichael Tuexen uint32_t sctp_checksum; /* CRC32C of the SCTP packet */ 113*1e88cc8bSMichael Tuexen struct sctphdr *sctp_hdr; /* raw SCTP header */ 114*1e88cc8bSMichael Tuexen } sctpinfo_t; 115*1e88cc8bSMichael Tuexen 116*1e88cc8bSMichael Tuexen #pragma D binding "1.13" translator 117*1e88cc8bSMichael Tuexen translator csinfo_t < struct sctp_tcb *p > { 118*1e88cc8bSMichael Tuexen cs_addr = NULL; 119*1e88cc8bSMichael Tuexen cs_cid = (uint64_t)p; 120*1e88cc8bSMichael Tuexen cs_pid = 0; 121*1e88cc8bSMichael Tuexen cs_zoneid = 0; 122*1e88cc8bSMichael Tuexen }; 123*1e88cc8bSMichael Tuexen 124*1e88cc8bSMichael Tuexen #pragma D binding "1.13" translator 125*1e88cc8bSMichael Tuexen translator sctpsinfo_t < struct sctp_tcb *p > { 126*1e88cc8bSMichael Tuexen sctps_addr = (uintptr_t)p; 127*1e88cc8bSMichael Tuexen sctps_num_raddrs = p == NULL ? -1 : p->asoc.numnets; 128*1e88cc8bSMichael Tuexen sctps_raddrs = p == NULL ? NULL : (uintptr_t)(p->asoc.nets.tqh_first); 129*1e88cc8bSMichael Tuexen sctps_num_laddrs = p == NULL ? -1 : 130*1e88cc8bSMichael Tuexen p->sctp_ep == NULL ? -1 : 131*1e88cc8bSMichael Tuexen p->sctp_ep->laddr_count; 132*1e88cc8bSMichael Tuexen sctps_laddrs = p == NULL ? NULL : 133*1e88cc8bSMichael Tuexen p->sctp_ep == NULL ? NULL : 134*1e88cc8bSMichael Tuexen (uintptr_t)(p->sctp_ep->sctp_addr_list.lh_first); 135*1e88cc8bSMichael Tuexen sctps_lport = p == NULL ? 0 : 136*1e88cc8bSMichael Tuexen p->sctp_ep == NULL ? 0 : 137*1e88cc8bSMichael Tuexen ntohs(p->sctp_ep->ip_inp.inp.inp_inc.inc_ie.ie_lport); 138*1e88cc8bSMichael Tuexen sctps_rport = p == NULL ? 0 : ntohs(p->rport); 139*1e88cc8bSMichael Tuexen sctps_laddr = p == NULL ? "<unknown>" : 140*1e88cc8bSMichael Tuexen p->asoc.primary_destination == NULL ? "<unknown>" : 141*1e88cc8bSMichael Tuexen p->asoc.primary_destination->ro._s_addr == NULL ? "<unknown>" : 142*1e88cc8bSMichael Tuexen p->asoc.primary_destination->ro._s_addr->address.sa.sa_family == AF_INET ? 143*1e88cc8bSMichael Tuexen inet_ntoa(&p->asoc.primary_destination->ro._s_addr->address.sin.sin_addr.s_addr) : 144*1e88cc8bSMichael Tuexen p->asoc.primary_destination->ro._s_addr->address.sa.sa_family == AF_INET6 ? 145*1e88cc8bSMichael Tuexen inet_ntoa6(&p->asoc.primary_destination->ro._s_addr->address.sin6.sin6_addr) : 146*1e88cc8bSMichael Tuexen "<unknown>"; 147*1e88cc8bSMichael Tuexen sctps_raddr = p == NULL ? "<unknown>" : 148*1e88cc8bSMichael Tuexen p->asoc.primary_destination == NULL ? "<unknown>" : 149*1e88cc8bSMichael Tuexen p->asoc.primary_destination->ro._l_addr.sa.sa_family == AF_INET ? 150*1e88cc8bSMichael Tuexen inet_ntoa(&p->asoc.primary_destination->ro._l_addr.sin.sin_addr.s_addr) : 151*1e88cc8bSMichael Tuexen p->asoc.primary_destination->ro._l_addr.sa.sa_family == AF_INET6 ? 152*1e88cc8bSMichael Tuexen inet_ntoa6(&p->asoc.primary_destination->ro._l_addr.sin6.sin6_addr) : 153*1e88cc8bSMichael Tuexen "<unknown>"; 154*1e88cc8bSMichael Tuexen sctps_state = p == NULL ? SCTP_STATE_CLOSED : p->asoc.state; 155*1e88cc8bSMichael Tuexen }; 156*1e88cc8bSMichael Tuexen 157*1e88cc8bSMichael Tuexen #pragma D binding "1.13" translator 158*1e88cc8bSMichael Tuexen translator sctpinfo_t < struct sctphdr *p > { 159*1e88cc8bSMichael Tuexen sctp_sport = p == NULL ? 0 : ntohs(p->src_port); 160*1e88cc8bSMichael Tuexen sctp_dport = p == NULL ? 0 : ntohs(p->dest_port); 161*1e88cc8bSMichael Tuexen sctp_verify = p == NULL ? 0 : ntohl(p->v_tag); 162*1e88cc8bSMichael Tuexen sctp_checksum = p == NULL ? 0 : ntohl(p->checksum); 163*1e88cc8bSMichael Tuexen sctp_hdr = p; 164*1e88cc8bSMichael Tuexen }; 165*1e88cc8bSMichael Tuexen 166*1e88cc8bSMichael Tuexen #pragma D binding "1.13" translator 167*1e88cc8bSMichael Tuexen translator sctplsinfo_t < int state > { 168*1e88cc8bSMichael Tuexen sctps_state = state; 169*1e88cc8bSMichael Tuexen }; 170