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