1 /* 2 * Copyright (c) 2013-2017 Apple Computer, Inc. All Rights Reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23 24 #pragma D depends_on library darwin.d 25 #pragma D depends_on library socket.d 26 #pragma D depends_on module mach_kernel 27 #pragma D depends_on provider mptcp 28 #pragma D depends_on provider ip 29 30 /* 31 * MPTCP Protocol Control Block. 32 */ 33 inline int MPTCPS_CLOSED = 0; 34 #pragma D binding "1.0" MPTCPS_CLOSED 35 inline int MPTCPS_LISTEN = 1; 36 #pragma D binding "1.0" MPTCPS_LISTEN 37 inline int MPTCPS_ESTABLISHED = 2; 38 #pragma D binding "1.0" MPTCPS_ESTABLISHED 39 inline int MPTCPS_CLOSE_WAIT = 3; 40 #pragma D binding "1.0" MPTCPS_CLOSE_WAIT 41 inline int MPTCPS_FIN_WAIT_1 = 4; 42 #pragma D binding "1.0" MPTCPS_FIN_WAIT_1 43 inline int MPTCPS_CLOSING = 5; 44 #pragma D binding "1.0" MPTCPS_CLOSING 45 inline int MPTCPS_LAST_ACK = 6; 46 #pragma D binding "1.0" MPTCPS_LAST_ACK 47 inline int MPTCPS_FIN_WAIT_2 = 7; 48 #pragma D binding "1.0" MPTCPS_FIN_WAIT_2 49 inline int MPTCPS_TIME_WAIT = 8; 50 #pragma D binding "1.0" MPTCPS_TIME_WAIT 51 inline int MPTCPS_TERMINATE = 10; 52 #pragma D binding "1.0" MPTCPS_TERMINATE 53 54 typedef struct mptsinfo { 55 string state; 56 uint32_t flags; 57 uint32_t vers; 58 uint32_t error; 59 mptcp_key_t localkey; 60 mptcp_key_t remotekey; 61 mptcp_token_t localtoken; 62 mptcp_token_t remotetoken; 63 int rxtshift; 64 uint32_t rxtstart; 65 uint64_t rtseq; 66 uint32_t timervals; 67 uint32_t timewait; 68 uint64_t snduna; 69 uint64_t sndnxt; 70 uint64_t sndmax; 71 uint64_t local_idsn; 72 uint32_t sndwnd; 73 uint64_t rcvnxt; 74 uint64_t remote_idsn; 75 uint32_t rcvwnd; 76 struct mptcb *mptcb; 77 } mptsinfo_t; 78 79 #pragma D binding "1.0" translator 80 translator mptsinfo_t < struct mptcb *T > { 81 state = T->mpt_state == MPTCPS_CLOSED ? "state-closed" : 82 T->mpt_state == MPTCPS_LISTEN ? "state-listen" : 83 T->mpt_state == MPTCPS_ESTABLISHED ? 84 "state-established" : 85 T->mpt_state == MPTCPS_CLOSE_WAIT ? "state-close-wait" : 86 T->mpt_state == MPTCPS_FIN_WAIT_1 ? "state-fin-wait-1" : 87 T->mpt_state == MPTCPS_CLOSING ? "state-closing" : 88 T->mpt_state == MPTCPS_LAST_ACK ? "state-last-ack" : 89 T->mpt_state == MPTCPS_FIN_WAIT_2 ? "state-fin-wait-2" : 90 T->mpt_state == MPTCPS_TIME_WAIT ? "state-time-wait" : 91 T->mpt_state == MPTCPS_TERMINATE ? 92 "state-terminate" : 93 "<unknown>"; 94 flags = T->mpt_flags; 95 vers = T->mpt_version; 96 error = T->mpt_softerror; 97 localkey = T->mpt_localkey; 98 remotekey = T->mpt_remotekey; 99 localtoken = T->mpt_localtoken; 100 remotetoken = T->mpt_remotetoken; 101 rxtshift = T->mpt_rxtshift; 102 rxtstart = T->mpt_rxtstart; 103 rtseq = T->mpt_rtseq; 104 timervals = T->mpt_timer_vals; 105 timewait = T->mpt_timewait; 106 snduna = T->mpt_snduna; 107 sndnxt = T->mpt_sndnxt; 108 sndmax = T->mpt_sndmax; 109 local_idsn = T->mpt_local_idsn; 110 sndwnd = T->mpt_sndwnd; 111 rcvnxt = T->mpt_rcvnxt; 112 remote_idsn = T->mpt_remote_idsn; 113 rcvwnd = T->mpt_rcvwnd; 114 mptcb = T; 115 }; 116 117 /* 118 * Multipath Control Block. 119 */ 120 inline int MPPCB_STATE_INUSE = 1; 121 #pragma D binding "1.0" MPPCB_STATE_INUSE 122 inline int MPPCB_STATE_DEAD = 2; 123 #pragma D binding "1.0" MPPCB_STATE_DEAD 124 125 typedef struct mppsinfo { 126 string state; 127 uint32_t flags; 128 struct mppcb *mppcb; 129 } mppsinfo_t; 130 131 #pragma D binding "1.0" translator 132 translator mppsinfo_t < struct mppcb *T> { 133 state = T ? 134 T->mpp_state == MPPCB_STATE_INUSE ? "state-inuse" : 135 T->mpp_state == MPPCB_STATE_DEAD ? "state-dead" : 136 "<unknown>" : "<null>"; 137 flags = T->mpp_flags; 138 mppcb = T; 139 }; 140 141 /* 142 * MPTCP Session. 143 */ 144 typedef struct mptsesinfo { 145 uint16_t numflows; 146 uint16_t nummpcapflows; 147 sae_connid_t connid_last; 148 uint8_t flags; 149 struct mptses *mptses; 150 } mptsesinfo_t; 151 152 #pragma D binding "1.0" translator 153 translator mptsesinfo_t < struct mptses *T > { 154 numflows = T->mpte_numflows; 155 nummpcapflows = T->mpte_nummpcapflows; 156 connid_last = T->mpte_connid_last; 157 flags = T->mpte_flags; 158 mptses = T; 159 }; 160 161 /* 162 * MPTCP Subflow. 163 */ 164 inline int MPTSF_CONNECTING = 0x00002; 165 #pragma D binding "1.0" MPTSF_CONNECTING 166 inline int MPTSF_CONNECT_PENDING= 0x00004; 167 #pragma D binding "1.0" MPTSF_CONNECT_PENDING 168 inline int MPTSF_CONNECTED = 0x00008; 169 #pragma D binding "1.0" MPTSF_CONNECTED 170 inline int MPTSF_DISCONNECTING = 0x00010; 171 #pragma D binding "1.0" MPTSF_DISCONNECTING 172 inline int MPTSF_DISCONNECTED = 0x00020; 173 #pragma D binding "1.0" MPTSF_DISCONNECTED 174 inline int MPTSF_MP_CAPABLE = 0x00040; 175 #pragma D binding "1.0" MPTSF_MP_CAPABLE 176 inline int MPTSF_MP_READY = 0x00080; 177 #pragma D binding "1.0" MPTSF_MP_READY 178 inline int MPTSF_MP_DEGRADED = 0x00100; 179 #pragma D binding "1.0" MPTSF_MP_DEGRADED 180 inline int MPTSF_SUSPENDED = 0x00200; 181 #pragma D binding "1.0" MPTSF_SUSPENDED 182 inline int MPTSF_BOUND_IF = 0x00400; 183 #pragma D binding "1.0" MPTSF_BOUND_IF 184 inline int MPTSF_BOUND_IP = 0x00800; 185 #pragma D binding "1.0" MPTSF_BOUND_IP 186 inline int MPTSF_BOUND_PORT = 0x01000; 187 #pragma D binding "1.0" MPTSF_BOUND_PORT 188 inline int MPTSF_PREFERRED = 0x02000; 189 #pragma D binding "1.0" MPTSF_PREFERRED 190 inline int MPTSF_SOPT_OLDVAL = 0x04000; 191 #pragma D binding "1.0" MPTSF_SOPT_OLDVAL 192 inline int MPTSF_SOPT_INPROG = 0x08000; 193 #pragma D binding "1.0" MPTSF_SOPT_INPROG 194 inline int MPTSF_DELETEOK = 0x10000; 195 #pragma D binding "1.0" MPTSF_DELETEOK 196 inline int MPTSF_FAILINGOVER = 0x20000; 197 #pragma D binding "1.0" MPTSF_FAILINGOVER 198 inline int MPTSF_ACTIVE = 0x40000; 199 #pragma D binding "1.0" MPTSF_ACTIVE 200 inline int MPTSF_MPCAP_CTRSET = 0x80000; 201 #pragma D binding "1.0" MPTSF_MPCAP_CTRSET 202 203 typedef struct mptsubinfo { 204 uint32_t flags; 205 uint32_t evctl; 206 sae_connid_t connid; 207 uint32_t rank; 208 struct mptsub *mptsub; 209 } mptsubinfo_t; 210 211 #pragma D binding "1.0" translator 212 translator mptsubinfo_t < struct mptsub *T > { 213 flags = T->mpts_flags; 214 evctl = T->mpts_evctl; 215 connid = T->mpts_connid; 216 mptsub = T; 217 }; 218