xref: /freebsd/sys/dev/iscsi/icl_soft_proxy.c (revision 779f106a)
1257cbe34SEdward Tomasz Napierala /*-
2257cbe34SEdward Tomasz Napierala  * Copyright (c) 2012 The FreeBSD Foundation
3257cbe34SEdward Tomasz Napierala  * All rights reserved.
4257cbe34SEdward Tomasz Napierala  *
5257cbe34SEdward Tomasz Napierala  * This software was developed by Edward Tomasz Napierala under sponsorship
6257cbe34SEdward Tomasz Napierala  * from the FreeBSD Foundation.
7257cbe34SEdward Tomasz Napierala  *
8257cbe34SEdward Tomasz Napierala  * Redistribution and use in source and binary forms, with or without
9257cbe34SEdward Tomasz Napierala  * modification, are permitted provided that the following conditions
10257cbe34SEdward Tomasz Napierala  * are met:
11257cbe34SEdward Tomasz Napierala  * 1. Redistributions of source code must retain the above copyright
12257cbe34SEdward Tomasz Napierala  *    notice, this list of conditions and the following disclaimer.
13257cbe34SEdward Tomasz Napierala  * 2. Redistributions in binary form must reproduce the above copyright
14257cbe34SEdward Tomasz Napierala  *    notice, this list of conditions and the following disclaimer in the
15257cbe34SEdward Tomasz Napierala  *    documentation and/or other materials provided with the distribution.
16257cbe34SEdward Tomasz Napierala  *
17257cbe34SEdward Tomasz Napierala  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18257cbe34SEdward Tomasz Napierala  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19257cbe34SEdward Tomasz Napierala  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20257cbe34SEdward Tomasz Napierala  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21257cbe34SEdward Tomasz Napierala  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22257cbe34SEdward Tomasz Napierala  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23257cbe34SEdward Tomasz Napierala  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24257cbe34SEdward Tomasz Napierala  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25257cbe34SEdward Tomasz Napierala  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26257cbe34SEdward Tomasz Napierala  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27257cbe34SEdward Tomasz Napierala  * SUCH DAMAGE.
28257cbe34SEdward Tomasz Napierala  *
29257cbe34SEdward Tomasz Napierala  */
30257cbe34SEdward Tomasz Napierala /*-
31257cbe34SEdward Tomasz Napierala  * Copyright (c) 1982, 1986, 1989, 1990, 1993
32257cbe34SEdward Tomasz Napierala  *	The Regents of the University of California.  All rights reserved.
33257cbe34SEdward Tomasz Napierala  *
34257cbe34SEdward Tomasz Napierala  * sendfile(2) and related extensions:
35257cbe34SEdward Tomasz Napierala  * Copyright (c) 1998, David Greenman. All rights reserved.
36257cbe34SEdward Tomasz Napierala  *
37257cbe34SEdward Tomasz Napierala  * Redistribution and use in source and binary forms, with or without
38257cbe34SEdward Tomasz Napierala  * modification, are permitted provided that the following conditions
39257cbe34SEdward Tomasz Napierala  * are met:
40257cbe34SEdward Tomasz Napierala  * 1. Redistributions of source code must retain the above copyright
41257cbe34SEdward Tomasz Napierala  *    notice, this list of conditions and the following disclaimer.
42257cbe34SEdward Tomasz Napierala  * 2. Redistributions in binary form must reproduce the above copyright
43257cbe34SEdward Tomasz Napierala  *    notice, this list of conditions and the following disclaimer in the
44257cbe34SEdward Tomasz Napierala  *    documentation and/or other materials provided with the distribution.
45fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
46257cbe34SEdward Tomasz Napierala  *    may be used to endorse or promote products derived from this software
47257cbe34SEdward Tomasz Napierala  *    without specific prior written permission.
48257cbe34SEdward Tomasz Napierala  *
49257cbe34SEdward Tomasz Napierala  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
50257cbe34SEdward Tomasz Napierala  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
51257cbe34SEdward Tomasz Napierala  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
52257cbe34SEdward Tomasz Napierala  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
53257cbe34SEdward Tomasz Napierala  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
54257cbe34SEdward Tomasz Napierala  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
55257cbe34SEdward Tomasz Napierala  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
56257cbe34SEdward Tomasz Napierala  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
57257cbe34SEdward Tomasz Napierala  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
58257cbe34SEdward Tomasz Napierala  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
59257cbe34SEdward Tomasz Napierala  * SUCH DAMAGE.
60257cbe34SEdward Tomasz Napierala  *
61257cbe34SEdward Tomasz Napierala  *	@(#)uipc_syscalls.c	8.4 (Berkeley) 2/21/94
62257cbe34SEdward Tomasz Napierala  */
63257cbe34SEdward Tomasz Napierala 
64257cbe34SEdward Tomasz Napierala /*
65257cbe34SEdward Tomasz Napierala  * iSCSI Common Layer, kernel proxy part.
66257cbe34SEdward Tomasz Napierala  */
67257cbe34SEdward Tomasz Napierala 
68257cbe34SEdward Tomasz Napierala #ifdef ICL_KERNEL_PROXY
69257cbe34SEdward Tomasz Napierala 
70257cbe34SEdward Tomasz Napierala #include <sys/cdefs.h>
71257cbe34SEdward Tomasz Napierala __FBSDID("$FreeBSD$");
72257cbe34SEdward Tomasz Napierala 
73257cbe34SEdward Tomasz Napierala #include <sys/param.h>
74257cbe34SEdward Tomasz Napierala #include <sys/capsicum.h>
75257cbe34SEdward Tomasz Napierala #include <sys/condvar.h>
76257cbe34SEdward Tomasz Napierala #include <sys/conf.h>
77257cbe34SEdward Tomasz Napierala #include <sys/kernel.h>
78257cbe34SEdward Tomasz Napierala #include <sys/kthread.h>
79257cbe34SEdward Tomasz Napierala #include <sys/malloc.h>
80257cbe34SEdward Tomasz Napierala #include <sys/proc.h>
81257cbe34SEdward Tomasz Napierala #include <sys/socket.h>
82257cbe34SEdward Tomasz Napierala #include <sys/socketvar.h>
83257cbe34SEdward Tomasz Napierala #include <sys/sx.h>
84257cbe34SEdward Tomasz Napierala #include <sys/systm.h>
85257cbe34SEdward Tomasz Napierala #include <netinet/in.h>
86257cbe34SEdward Tomasz Napierala #include <netinet/tcp.h>
87257cbe34SEdward Tomasz Napierala 
88257cbe34SEdward Tomasz Napierala #include <dev/iscsi/icl.h>
89257cbe34SEdward Tomasz Napierala 
90257cbe34SEdward Tomasz Napierala struct icl_listen_sock {
91257cbe34SEdward Tomasz Napierala 	TAILQ_ENTRY(icl_listen_sock)	ils_next;
92257cbe34SEdward Tomasz Napierala 	struct icl_listen		*ils_listen;
93257cbe34SEdward Tomasz Napierala 	struct socket			*ils_socket;
94257cbe34SEdward Tomasz Napierala 	bool				ils_running;
95257cbe34SEdward Tomasz Napierala 	int				ils_id;
96257cbe34SEdward Tomasz Napierala };
97257cbe34SEdward Tomasz Napierala 
98257cbe34SEdward Tomasz Napierala struct icl_listen	{
99257cbe34SEdward Tomasz Napierala 	TAILQ_HEAD(, icl_listen_sock)	il_sockets;
100257cbe34SEdward Tomasz Napierala 	struct sx			il_lock;
101257cbe34SEdward Tomasz Napierala 	void				(*il_accept)(struct socket *,
102257cbe34SEdward Tomasz Napierala 					    struct sockaddr *, int);
103257cbe34SEdward Tomasz Napierala };
104257cbe34SEdward Tomasz Napierala 
105257cbe34SEdward Tomasz Napierala static MALLOC_DEFINE(M_ICL_PROXY, "ICL_PROXY", "iSCSI common layer proxy");
106257cbe34SEdward Tomasz Napierala 
107257cbe34SEdward Tomasz Napierala int
108257cbe34SEdward Tomasz Napierala icl_soft_proxy_connect(struct icl_conn *ic, int domain, int socktype,
109257cbe34SEdward Tomasz Napierala     int protocol, struct sockaddr *from_sa, struct sockaddr *to_sa)
110257cbe34SEdward Tomasz Napierala {
111257cbe34SEdward Tomasz Napierala 	struct socket *so;
112257cbe34SEdward Tomasz Napierala 	int error;
113257cbe34SEdward Tomasz Napierala 	int interrupted = 0;
114257cbe34SEdward Tomasz Napierala 
115257cbe34SEdward Tomasz Napierala 	error = socreate(domain, &so, socktype, protocol,
116257cbe34SEdward Tomasz Napierala 	    curthread->td_ucred, curthread);
117257cbe34SEdward Tomasz Napierala 	if (error != 0)
118257cbe34SEdward Tomasz Napierala 		return (error);
119257cbe34SEdward Tomasz Napierala 
120257cbe34SEdward Tomasz Napierala 	if (from_sa != NULL) {
121257cbe34SEdward Tomasz Napierala 		error = sobind(so, from_sa, curthread);
122257cbe34SEdward Tomasz Napierala 		if (error != 0) {
123257cbe34SEdward Tomasz Napierala 			soclose(so);
124257cbe34SEdward Tomasz Napierala 			return (error);
125257cbe34SEdward Tomasz Napierala 		}
126257cbe34SEdward Tomasz Napierala 	}
127257cbe34SEdward Tomasz Napierala 
128257cbe34SEdward Tomasz Napierala 	error = soconnect(so, to_sa, curthread);
129257cbe34SEdward Tomasz Napierala 	if (error != 0) {
130257cbe34SEdward Tomasz Napierala 		soclose(so);
131257cbe34SEdward Tomasz Napierala 		return (error);
132257cbe34SEdward Tomasz Napierala 	}
133257cbe34SEdward Tomasz Napierala 
134257cbe34SEdward Tomasz Napierala 	SOCK_LOCK(so);
135257cbe34SEdward Tomasz Napierala 	while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
136257cbe34SEdward Tomasz Napierala 		error = msleep(&so->so_timeo, SOCK_MTX(so), PSOCK | PCATCH,
137257cbe34SEdward Tomasz Napierala 		    "icl_connect", 0);
138257cbe34SEdward Tomasz Napierala 		if (error) {
139257cbe34SEdward Tomasz Napierala 			if (error == EINTR || error == ERESTART)
140257cbe34SEdward Tomasz Napierala 				interrupted = 1;
141257cbe34SEdward Tomasz Napierala 			break;
142257cbe34SEdward Tomasz Napierala 		}
143257cbe34SEdward Tomasz Napierala 	}
144257cbe34SEdward Tomasz Napierala 	if (error == 0) {
145257cbe34SEdward Tomasz Napierala 		error = so->so_error;
146257cbe34SEdward Tomasz Napierala 		so->so_error = 0;
147257cbe34SEdward Tomasz Napierala 	}
148257cbe34SEdward Tomasz Napierala 	SOCK_UNLOCK(so);
149257cbe34SEdward Tomasz Napierala 
150257cbe34SEdward Tomasz Napierala 	if (error != 0) {
151257cbe34SEdward Tomasz Napierala 		soclose(so);
152257cbe34SEdward Tomasz Napierala 		return (error);
153257cbe34SEdward Tomasz Napierala 	}
154257cbe34SEdward Tomasz Napierala 
155257cbe34SEdward Tomasz Napierala 	error = icl_soft_handoff_sock(ic, so);
156257cbe34SEdward Tomasz Napierala 	if (error != 0)
157257cbe34SEdward Tomasz Napierala 		soclose(so);
158257cbe34SEdward Tomasz Napierala 
159257cbe34SEdward Tomasz Napierala 	return (error);
160257cbe34SEdward Tomasz Napierala }
161257cbe34SEdward Tomasz Napierala 
162257cbe34SEdward Tomasz Napierala struct icl_listen *
163257cbe34SEdward Tomasz Napierala icl_listen_new(void (*accept_cb)(struct socket *, struct sockaddr *, int))
164257cbe34SEdward Tomasz Napierala {
165257cbe34SEdward Tomasz Napierala 	struct icl_listen *il;
166257cbe34SEdward Tomasz Napierala 
167257cbe34SEdward Tomasz Napierala 	il = malloc(sizeof(*il), M_ICL_PROXY, M_ZERO | M_WAITOK);
168257cbe34SEdward Tomasz Napierala 	TAILQ_INIT(&il->il_sockets);
169257cbe34SEdward Tomasz Napierala 	sx_init(&il->il_lock, "icl_listen");
170257cbe34SEdward Tomasz Napierala 	il->il_accept = accept_cb;
171257cbe34SEdward Tomasz Napierala 
172257cbe34SEdward Tomasz Napierala 	return (il);
173257cbe34SEdward Tomasz Napierala }
174257cbe34SEdward Tomasz Napierala 
175257cbe34SEdward Tomasz Napierala void
176257cbe34SEdward Tomasz Napierala icl_listen_free(struct icl_listen *il)
177257cbe34SEdward Tomasz Napierala {
178257cbe34SEdward Tomasz Napierala 	struct icl_listen_sock *ils;
179257cbe34SEdward Tomasz Napierala 
180257cbe34SEdward Tomasz Napierala 	sx_xlock(&il->il_lock);
181257cbe34SEdward Tomasz Napierala 	while (!TAILQ_EMPTY(&il->il_sockets)) {
182257cbe34SEdward Tomasz Napierala 		ils = TAILQ_FIRST(&il->il_sockets);
183257cbe34SEdward Tomasz Napierala 		while (ils->ils_running) {
184257cbe34SEdward Tomasz Napierala 			ICL_DEBUG("waiting for accept thread to terminate");
185257cbe34SEdward Tomasz Napierala 			sx_xunlock(&il->il_lock);
186779f106aSGleb Smirnoff 			SOLISTEN_LOCK(ils->ils_socket);
187779f106aSGleb Smirnoff 			ils->ils_socket->so_error = ENOTCONN;
188779f106aSGleb Smirnoff 			SOLISTEN_UNLOCK(ils->ils_socket);
189257cbe34SEdward Tomasz Napierala 			wakeup(&ils->ils_socket->so_timeo);
190257cbe34SEdward Tomasz Napierala 			pause("icl_unlisten", 1 * hz);
191257cbe34SEdward Tomasz Napierala 			sx_xlock(&il->il_lock);
192257cbe34SEdward Tomasz Napierala 		}
193257cbe34SEdward Tomasz Napierala 
194257cbe34SEdward Tomasz Napierala 		TAILQ_REMOVE(&il->il_sockets, ils, ils_next);
195257cbe34SEdward Tomasz Napierala 		soclose(ils->ils_socket);
196257cbe34SEdward Tomasz Napierala 		free(ils, M_ICL_PROXY);
197257cbe34SEdward Tomasz Napierala 	}
198257cbe34SEdward Tomasz Napierala 	sx_xunlock(&il->il_lock);
199257cbe34SEdward Tomasz Napierala 
200257cbe34SEdward Tomasz Napierala 	free(il, M_ICL_PROXY);
201257cbe34SEdward Tomasz Napierala }
202257cbe34SEdward Tomasz Napierala 
203257cbe34SEdward Tomasz Napierala /*
204779f106aSGleb Smirnoff  * XXX: Doing accept in a separate thread in each socket might not be the
205779f106aSGleb Smirnoff  * best way to do stuff, but it's pretty clean and debuggable - and you
206779f106aSGleb Smirnoff  * probably won't have hundreds of listening sockets anyway.
207257cbe34SEdward Tomasz Napierala  */
208257cbe34SEdward Tomasz Napierala static void
209257cbe34SEdward Tomasz Napierala icl_accept_thread(void *arg)
210257cbe34SEdward Tomasz Napierala {
211257cbe34SEdward Tomasz Napierala 	struct icl_listen_sock *ils;
212257cbe34SEdward Tomasz Napierala 	struct socket *head, *so;
213257cbe34SEdward Tomasz Napierala 	struct sockaddr *sa;
214257cbe34SEdward Tomasz Napierala 	int error;
215257cbe34SEdward Tomasz Napierala 
216257cbe34SEdward Tomasz Napierala 	ils = arg;
217257cbe34SEdward Tomasz Napierala 	head = ils->ils_socket;
218257cbe34SEdward Tomasz Napierala 
219257cbe34SEdward Tomasz Napierala 	ils->ils_running = true;
220257cbe34SEdward Tomasz Napierala 
221257cbe34SEdward Tomasz Napierala 	for (;;) {
222779f106aSGleb Smirnoff 		SOLISTEN_LOCK(head);
223779f106aSGleb Smirnoff 		error = solisten_dequeue(head, &so, 0);
224779f106aSGleb Smirnoff 		if (error == ENOTCONN) {
225779f106aSGleb Smirnoff 			/*
226779f106aSGleb Smirnoff 			 * XXXGL: ENOTCONN is our mark from icl_listen_free().
227779f106aSGleb Smirnoff 			 * Neither socket code, nor msleep(9) may return it.
228779f106aSGleb Smirnoff 			 */
229257cbe34SEdward Tomasz Napierala 			ICL_DEBUG("terminating");
230257cbe34SEdward Tomasz Napierala 			ils->ils_running = false;
231257cbe34SEdward Tomasz Napierala 			kthread_exit();
232257cbe34SEdward Tomasz Napierala 			return;
233257cbe34SEdward Tomasz Napierala 		}
234779f106aSGleb Smirnoff 		if (error) {
235779f106aSGleb Smirnoff 			ICL_WARN("solisten_dequeue error %d", error);
236257cbe34SEdward Tomasz Napierala 			continue;
237257cbe34SEdward Tomasz Napierala 		}
238257cbe34SEdward Tomasz Napierala 
239257cbe34SEdward Tomasz Napierala 		sa = NULL;
240257cbe34SEdward Tomasz Napierala 		error = soaccept(so, &sa);
241257cbe34SEdward Tomasz Napierala 		if (error != 0) {
242257cbe34SEdward Tomasz Napierala 			ICL_WARN("soaccept error %d", error);
243257cbe34SEdward Tomasz Napierala 			if (sa != NULL)
244257cbe34SEdward Tomasz Napierala 				free(sa, M_SONAME);
245257cbe34SEdward Tomasz Napierala 			soclose(so);
246257cbe34SEdward Tomasz Napierala 			continue;
247257cbe34SEdward Tomasz Napierala 		}
248257cbe34SEdward Tomasz Napierala 
249257cbe34SEdward Tomasz Napierala 		(ils->ils_listen->il_accept)(so, sa, ils->ils_id);
250257cbe34SEdward Tomasz Napierala 	}
251257cbe34SEdward Tomasz Napierala }
252257cbe34SEdward Tomasz Napierala 
253257cbe34SEdward Tomasz Napierala static int
254257cbe34SEdward Tomasz Napierala icl_listen_add_tcp(struct icl_listen *il, int domain, int socktype,
255257cbe34SEdward Tomasz Napierala     int protocol, struct sockaddr *sa, int portal_id)
256257cbe34SEdward Tomasz Napierala {
257257cbe34SEdward Tomasz Napierala 	struct icl_listen_sock *ils;
258257cbe34SEdward Tomasz Napierala 	struct socket *so;
259257cbe34SEdward Tomasz Napierala 	struct sockopt sopt;
260257cbe34SEdward Tomasz Napierala 	int error, one = 1;
261257cbe34SEdward Tomasz Napierala 
262257cbe34SEdward Tomasz Napierala 	error = socreate(domain, &so, socktype, protocol,
263257cbe34SEdward Tomasz Napierala 	    curthread->td_ucred, curthread);
264257cbe34SEdward Tomasz Napierala 	if (error != 0) {
265257cbe34SEdward Tomasz Napierala 		ICL_WARN("socreate failed with error %d", error);
266257cbe34SEdward Tomasz Napierala 		return (error);
267257cbe34SEdward Tomasz Napierala 	}
268257cbe34SEdward Tomasz Napierala 
269257cbe34SEdward Tomasz Napierala 	sopt.sopt_dir = SOPT_SET;
270257cbe34SEdward Tomasz Napierala 	sopt.sopt_level = SOL_SOCKET;
271257cbe34SEdward Tomasz Napierala 	sopt.sopt_name = SO_REUSEADDR;
272257cbe34SEdward Tomasz Napierala 	sopt.sopt_val = &one;
273257cbe34SEdward Tomasz Napierala 	sopt.sopt_valsize = sizeof(one);
274257cbe34SEdward Tomasz Napierala 	sopt.sopt_td = NULL;
275257cbe34SEdward Tomasz Napierala 	error = sosetopt(so, &sopt);
276257cbe34SEdward Tomasz Napierala 	if (error != 0) {
277257cbe34SEdward Tomasz Napierala 		ICL_WARN("failed to set SO_REUSEADDR with error %d", error);
278257cbe34SEdward Tomasz Napierala 		soclose(so);
279257cbe34SEdward Tomasz Napierala 		return (error);
280257cbe34SEdward Tomasz Napierala 	}
281257cbe34SEdward Tomasz Napierala 
282257cbe34SEdward Tomasz Napierala 	error = sobind(so, sa, curthread);
283257cbe34SEdward Tomasz Napierala 	if (error != 0) {
284257cbe34SEdward Tomasz Napierala 		ICL_WARN("sobind failed with error %d", error);
285257cbe34SEdward Tomasz Napierala 		soclose(so);
286257cbe34SEdward Tomasz Napierala 		return (error);
287257cbe34SEdward Tomasz Napierala 	}
288257cbe34SEdward Tomasz Napierala 
289257cbe34SEdward Tomasz Napierala 	error = solisten(so, -1, curthread);
290257cbe34SEdward Tomasz Napierala 	if (error != 0) {
291257cbe34SEdward Tomasz Napierala 		ICL_WARN("solisten failed with error %d", error);
292257cbe34SEdward Tomasz Napierala 		soclose(so);
293257cbe34SEdward Tomasz Napierala 		return (error);
294257cbe34SEdward Tomasz Napierala 	}
295257cbe34SEdward Tomasz Napierala 
296257cbe34SEdward Tomasz Napierala 	ils = malloc(sizeof(*ils), M_ICL_PROXY, M_ZERO | M_WAITOK);
297257cbe34SEdward Tomasz Napierala 	ils->ils_listen = il;
298257cbe34SEdward Tomasz Napierala 	ils->ils_socket = so;
299257cbe34SEdward Tomasz Napierala 	ils->ils_id = portal_id;
300257cbe34SEdward Tomasz Napierala 
301257cbe34SEdward Tomasz Napierala 	error = kthread_add(icl_accept_thread, ils, NULL, NULL, 0, 0, "iclacc");
302257cbe34SEdward Tomasz Napierala 	if (error != 0) {
303257cbe34SEdward Tomasz Napierala 		ICL_WARN("kthread_add failed with error %d", error);
304257cbe34SEdward Tomasz Napierala 		soclose(so);
305257cbe34SEdward Tomasz Napierala 		free(ils, M_ICL_PROXY);
306257cbe34SEdward Tomasz Napierala 
307257cbe34SEdward Tomasz Napierala 		return (error);
308257cbe34SEdward Tomasz Napierala 	}
309257cbe34SEdward Tomasz Napierala 
310257cbe34SEdward Tomasz Napierala 	sx_xlock(&il->il_lock);
311257cbe34SEdward Tomasz Napierala 	TAILQ_INSERT_TAIL(&il->il_sockets, ils, ils_next);
312257cbe34SEdward Tomasz Napierala 	sx_xunlock(&il->il_lock);
313257cbe34SEdward Tomasz Napierala 
314257cbe34SEdward Tomasz Napierala 	return (0);
315257cbe34SEdward Tomasz Napierala }
316257cbe34SEdward Tomasz Napierala 
317257cbe34SEdward Tomasz Napierala int
318257cbe34SEdward Tomasz Napierala icl_listen_add(struct icl_listen *il, bool rdma, int domain, int socktype,
319257cbe34SEdward Tomasz Napierala     int protocol, struct sockaddr *sa, int portal_id)
320257cbe34SEdward Tomasz Napierala {
321257cbe34SEdward Tomasz Napierala 
322257cbe34SEdward Tomasz Napierala 	if (rdma) {
323257cbe34SEdward Tomasz Napierala 		ICL_DEBUG("RDMA not supported");
324257cbe34SEdward Tomasz Napierala 		return (EOPNOTSUPP);
325257cbe34SEdward Tomasz Napierala 	}
326257cbe34SEdward Tomasz Napierala 
327257cbe34SEdward Tomasz Napierala 
328257cbe34SEdward Tomasz Napierala 	return (icl_listen_add_tcp(il, domain, socktype, protocol, sa,
329257cbe34SEdward Tomasz Napierala 	    portal_id));
330257cbe34SEdward Tomasz Napierala }
331257cbe34SEdward Tomasz Napierala 
332257cbe34SEdward Tomasz Napierala int
333257cbe34SEdward Tomasz Napierala icl_listen_remove(struct icl_listen *il, struct sockaddr *sa)
334257cbe34SEdward Tomasz Napierala {
335257cbe34SEdward Tomasz Napierala 
336257cbe34SEdward Tomasz Napierala 	/*
337257cbe34SEdward Tomasz Napierala 	 * XXX
338257cbe34SEdward Tomasz Napierala 	 */
339257cbe34SEdward Tomasz Napierala 
340257cbe34SEdward Tomasz Napierala 	return (EOPNOTSUPP);
341257cbe34SEdward Tomasz Napierala }
342257cbe34SEdward Tomasz Napierala 
343257cbe34SEdward Tomasz Napierala #endif /* ICL_KERNEL_PROXY */
344