1/*
2 * Copyright (c) 2013-2014 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 */
33inline int MPTCPS_CLOSED                = 0;
34#pragma D binding "1.0" MPTCPS_CLOSED
35inline int MPTCPS_LISTEN                = 1;
36#pragma D binding "1.0" MPTCPS_LISTEN
37inline int MPTCPS_ESTABLISHED           = 2;
38#pragma D binding "1.0" MPTCPS_ESTABLISHED
39inline int MPTCPS_CLOSE_WAIT            = 3;
40#pragma D binding "1.0" MPTCPS_CLOSE_WAIT
41inline int MPTCPS_FIN_WAIT_1            = 4;
42#pragma D binding "1.0" MPTCPS_FIN_WAIT_1
43inline int MPTCPS_CLOSING               = 5;
44#pragma D binding "1.0" MPTCPS_CLOSING
45inline int MPTCPS_LAST_ACK              = 6;
46#pragma D binding "1.0" MPTCPS_LAST_ACK
47inline int MPTCPS_FIN_WAIT_2            = 7;
48#pragma D binding "1.0" MPTCPS_FIN_WAIT_2
49inline int MPTCPS_TIME_WAIT             = 8;
50#pragma D binding "1.0" MPTCPS_TIME_WAIT
51inline int MPTCPS_FASTCLOSE_WAIT        = 9;
52#pragma D binding "1.0" MPTCPS_FASTCLOSE_WAIT
53inline int MPTCPS_TERMINATE		= 10;
54#pragma D binding "1.0" MPTCPS_TERMINATE
55
56typedef uint64_t mptcp_key_t;
57typedef uint32_t mptcp_token_t;
58
59typedef struct mptsinfo {
60	string		state;
61	uint32_t	flags;
62	uint32_t	vers;
63	uint32_t	error;
64	mptcp_key_t	localkey;
65	mptcp_key_t	remotekey;
66	mptcp_token_t	localtoken;
67	mptcp_token_t	remotetoken;
68	int		rxtshift;
69	uint32_t	rxtstart;
70	uint64_t	rtseq;
71	uint32_t	timervals;
72	uint32_t	timewait;
73	uint64_t	snduna;
74	uint64_t	sndnxt;
75	uint64_t	sndmax;
76	uint64_t	local_idsn;
77	uint32_t	sndwnd;
78	uint64_t	rcvnxt;
79	uint64_t	rcvatmark;
80	uint64_t	remote_idsn;
81	uint32_t	rcvwnd;
82	struct mptcb	*mptcb;
83} mptsinfo_t;
84
85#pragma D binding "1.0" translator
86translator mptsinfo_t < struct mptcb *T > {
87	state        = T->mpt_state == MPTCPS_CLOSED ? "state-closed" :
88		       T->mpt_state == MPTCPS_LISTEN ? "state-listen" :
89		       T->mpt_state == MPTCPS_ESTABLISHED ?
90		           "state-established" :
91		       T->mpt_state == MPTCPS_CLOSE_WAIT ? "state-close-wait" :
92		       T->mpt_state == MPTCPS_FIN_WAIT_1 ? "state-fin-wait-1" :
93		       T->mpt_state == MPTCPS_CLOSING ? "state-closing" :
94		       T->mpt_state == MPTCPS_LAST_ACK ? "state-last-ack" :
95		       T->mpt_state == MPTCPS_FIN_WAIT_2 ? "state-fin-wait-2" :
96		       T->mpt_state == MPTCPS_TIME_WAIT ? "state-time-wait" :
97		       T->mpt_state == MPTCPS_FASTCLOSE_WAIT ?
98		           "state-fastclose-wait" :
99		       T->mpt_state == MPTCPS_TERMINATE ?
100		           "state-terminate" :
101		       "<unknown>";
102	flags        = T->mpt_flags;
103	vers         = T->mpt_version;
104	error        = T->mpt_softerror;
105	localkey     = T->mpt_localkey ? *T->mpt_localkey : 0;
106	remotekey    = T->mpt_remotekey;
107	localtoken   = T->mpt_localtoken;
108	remotetoken  = T->mpt_remotetoken;
109	rxtshift     = T->mpt_rxtshift;
110	rxtstart     = T->mpt_rxtstart;
111	rtseq	     = T->mpt_rtseq;
112	timervals    = T->mpt_timer_vals;
113	timewait     = T->mpt_timewait;
114	snduna       = T->mpt_snduna;
115	sndnxt	     = T->mpt_sndnxt;
116	sndmax	     = T->mpt_sndmax;
117	local_idsn   = T->mpt_local_idsn;
118	sndwnd	     = T->mpt_sndwnd;
119	rcvnxt	     = T->mpt_rcvnxt;
120	rcvatmark    = T->mpt_rcvatmark;
121	remote_idsn  = T->mpt_remote_idsn;
122	rcvwnd       = T->mpt_rcvwnd;
123	mptcb	     = T;
124};
125
126/*
127 * Multipath Control Block.
128 */
129inline int MPPCB_STATE_INUSE	= 1;
130#pragma D binding "1.0" MPPCB_STATE_INUSE
131inline int MPPCB_STATE_DEAD	= 2;
132#pragma D binding "1.0" MPPCB_STATE_DEAD
133
134typedef struct mppsinfo {
135	string		state;
136	uint32_t	flags;
137	struct mppcb	*mppcb;
138} mppsinfo_t;
139
140#pragma D binding "1.0" translator
141translator mppsinfo_t < struct mppcb *T> {
142	state  = T ?
143	    T->mpp_state == MPPCB_STATE_INUSE ? "state-inuse" :
144	    T->mpp_state == MPPCB_STATE_DEAD ? "state-dead" :
145	    "<unknown>" : "<null>";
146	flags  = T->mpp_flags;
147	mppcb  = T;
148};
149
150/*
151 * MPTCP Session.
152 */
153typedef struct mptsesinfo {
154	uint16_t	numflows;
155	uint16_t	nummpcapflows;
156	connid_t	connid_last;
157	uint8_t		flags;
158	struct mptses	*mptses;
159} mptsesinfo_t;
160
161#pragma D binding "1.0" translator
162translator mptsesinfo_t < struct mptses *T > {
163	numflows      = T->mpte_numflows;
164	nummpcapflows = T->mpte_nummpcapflows;
165	connid_last   = T->mpte_connid_last;
166	flags         = T->mpte_flags;
167	mptses	      = T;
168};
169
170/*
171 * MPTCP Subflow.
172 */
173inline int MPTSF_ATTACHED       = 0x00001;
174#pragma D binding "1.0" MPTSF_ATTACHED
175inline int MPTSF_CONNECTING     = 0x00002;
176#pragma D binding "1.0" MPTSF_CONNECTING
177inline int MPTSF_CONNECT_PENDING= 0x00004;
178#pragma D binding "1.0" MPTSF_CONNECT_PENDING
179inline int MPTSF_CONNECTED      = 0x00008;
180#pragma D binding "1.0" MPTSF_CONNECTED
181inline int MPTSF_DISCONNECTING  = 0x00010;
182#pragma D binding "1.0" MPTSF_DISCONNECTING
183inline int MPTSF_DISCONNECTED   = 0x00020;
184#pragma D binding "1.0" MPTSF_DISCONNECTED
185inline int MPTSF_MP_CAPABLE     = 0x00040;
186#pragma D binding "1.0" MPTSF_MP_CAPABLE
187inline int MPTSF_MP_READY       = 0x00080;
188#pragma D binding "1.0" MPTSF_MP_READY
189inline int MPTSF_MP_DEGRADED    = 0x00100;
190#pragma D binding "1.0" MPTSF_MP_DEGRADED
191inline int MPTSF_SUSPENDED      = 0x00200;
192#pragma D binding "1.0" MPTSF_SUSPENDED
193inline int MPTSF_BOUND_IF       = 0x00400;
194#pragma D binding "1.0" MPTSF_BOUND_IF
195inline int MPTSF_BOUND_IP       = 0x00800;
196#pragma D binding "1.0" MPTSF_BOUND_IP
197inline int MPTSF_BOUND_PORT     = 0x01000;
198#pragma D binding "1.0" MPTSF_BOUND_PORT
199inline int MPTSF_PREFERRED      = 0x02000;
200#pragma D binding "1.0" MPTSF_PREFERRED
201inline int MPTSF_SOPT_OLDVAL    = 0x04000;
202#pragma D binding "1.0" MPTSF_SOPT_OLDVAL
203inline int MPTSF_SOPT_INPROG    = 0x08000;
204#pragma D binding "1.0" MPTSF_SOPT_INPROG
205inline int MPTSF_DELETEOK       = 0x10000;
206#pragma D binding "1.0" MPTSF_DELETEOK
207inline int MPTSF_FAILINGOVER    = 0x20000;
208#pragma D binding "1.0" MPTSF_FAILINGOVER
209inline int MPTSF_ACTIVE         = 0x40000;
210#pragma D binding "1.0" MPTSF_ACTIVE
211inline int MPTSF_MPCAP_CTRSET   = 0x80000;
212#pragma D binding "1.0" MPTSF_MPCAP_CTRSET
213inline int MPTSF_FASTJ_SEND	= 0x100000;
214#pragma D binding "1.0" MPTSF_FASTJ_SEND
215
216typedef struct mptsubinfo {
217	uint32_t	flags;
218	uint32_t	evctl;
219	uint32_t	family;
220	connid_t	connid;
221	uint32_t	rank;
222	int32_t		error;
223	uint64_t	sndnxt;
224	struct mptsub	*mptsub;
225} mptsubinfo_t;
226
227#pragma D binding "1.0" translator
228translator mptsubinfo_t < struct mptsub *T > {
229	flags   = T->mpts_flags;
230	evctl   = T->mpts_evctl;
231	family  = T->mpts_family;
232	connid  = T->mpts_connid;
233	rank    = T->mpts_rank;
234	error   = T->mpts_soerror;
235	sndnxt  = T->mpts_sndnxt;
236	mptsub  = T;
237};
238