| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: sockin.c,v 1.2 2008/10/15 11:43:38 pooka Exp $ */ | | 1 | /* $NetBSD: sockin.c,v 1.3 2008/10/16 13:36:06 pooka Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2008 Antti Kantee. All Rights Reserved. | | 4 | * Copyright (c) 2008 Antti Kantee. All Rights Reserved. |
5 | * | | 5 | * |
6 | * Redistribution and use in source and binary forms, with or without | | 6 | * Redistribution and use in source and binary forms, with or without |
7 | * modification, are permitted provided that the following conditions | | 7 | * modification, are permitted provided that the following conditions |
8 | * are met: | | 8 | * are met: |
9 | * 1. Redistributions of source code must retain the above copyright | | 9 | * 1. Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. | | 10 | * notice, this list of conditions and the following disclaimer. |
11 | * 2. Redistributions in binary form must reproduce the above copyright | | 11 | * 2. Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the | | 12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. | | 13 | * documentation and/or other materials provided with the distribution. |
14 | * | | 14 | * |
| @@ -88,27 +88,27 @@ struct domain sockindomain = { | | | @@ -88,27 +88,27 @@ struct domain sockindomain = { |
88 | .dom_ifdetach = NULL, | | 88 | .dom_ifdetach = NULL, |
89 | .dom_ifqueues = { NULL }, | | 89 | .dom_ifqueues = { NULL }, |
90 | .dom_link = { NULL }, | | 90 | .dom_link = { NULL }, |
91 | .dom_mowner = MOWNER_INIT("",""), | | 91 | .dom_mowner = MOWNER_INIT("",""), |
92 | .dom_rtcache = { NULL }, | | 92 | .dom_rtcache = { NULL }, |
93 | .dom_sockaddr_cmp = NULL | | 93 | .dom_sockaddr_cmp = NULL |
94 | }; | | 94 | }; |
95 | | | 95 | |
96 | /* only for testing */ | | 96 | /* only for testing */ |
97 | #if 0 | | 97 | #if 0 |
98 | #define SOCKIN_NOTHREAD | | 98 | #define SOCKIN_NOTHREAD |
99 | #endif | | 99 | #endif |
100 | | | 100 | |
101 | #define SO2S(so) ((int)(so->so_internal)) | | 101 | #define SO2S(so) ((intptr_t)(so->so_internal)) |
102 | #define SOCKIN_SBSIZE 65536 | | 102 | #define SOCKIN_SBSIZE 65536 |
103 | | | 103 | |
104 | static void | | 104 | static void |
105 | sockin_process(struct socket *so) | | 105 | sockin_process(struct socket *so) |
106 | { | | 106 | { |
107 | struct sockaddr_in from; | | 107 | struct sockaddr_in from; |
108 | struct iovec io; | | 108 | struct iovec io; |
109 | struct msghdr rmsg; | | 109 | struct msghdr rmsg; |
110 | struct mbuf *m; | | 110 | struct mbuf *m; |
111 | ssize_t n; | | 111 | ssize_t n; |
112 | size_t plen; | | 112 | size_t plen; |
113 | int error; | | 113 | int error; |
114 | | | 114 | |
| @@ -261,43 +261,43 @@ sockin_usrreq(struct socket *so, int req | | | @@ -261,43 +261,43 @@ sockin_usrreq(struct socket *so, int req |
261 | | | 261 | |
262 | su = kmem_alloc(sizeof(*su), KM_NOSLEEP); | | 262 | su = kmem_alloc(sizeof(*su), KM_NOSLEEP); |
263 | if (!su) { | | 263 | if (!su) { |
264 | error = ENOMEM; | | 264 | error = ENOMEM; |
265 | break; | | 265 | break; |
266 | } | | 266 | } |
267 | | | 267 | |
268 | news = rumpuser_net_socket(PF_INET, so->so_proto->pr_type, | | 268 | news = rumpuser_net_socket(PF_INET, so->so_proto->pr_type, |
269 | 0, &error); | | 269 | 0, &error); |
270 | if (news == -1) { | | 270 | if (news == -1) { |
271 | kmem_free(su, sizeof(*su)); | | 271 | kmem_free(su, sizeof(*su)); |
272 | break; | | 272 | break; |
273 | } | | 273 | } |
274 | so->so_internal = (void *)news; | | 274 | so->so_internal = (void *)(intptr_t)news; |
275 | su->su_so = so; | | 275 | su->su_so = so; |
276 | | | 276 | |
277 | mutex_enter(&su_mtx); | | 277 | mutex_enter(&su_mtx); |
278 | LIST_INSERT_HEAD(&su_ent, su, su_entries); | | 278 | LIST_INSERT_HEAD(&su_ent, su, su_entries); |
279 | nsock++; | | 279 | nsock++; |
280 | rebuild = true; | | 280 | rebuild = true; |
281 | mutex_exit(&su_mtx); | | 281 | mutex_exit(&su_mtx); |
282 | break; | | 282 | break; |
283 | } | | 283 | } |
284 | | | 284 | |
285 | case PRU_CONNECT: | | 285 | case PRU_CONNECT: |
286 | /* don't bother to connect udp sockets, always sendmsg */ | | 286 | /* don't bother to connect udp sockets, always sendmsg */ |
287 | if (so->so_proto->pr_type == SOCK_DGRAM) | | 287 | if (so->so_proto->pr_type == SOCK_DGRAM) |
288 | break; | | 288 | break; |
289 | | | 289 | |
290 | rv = rumpuser_net_connect((int)so->so_internal, | | 290 | rv = rumpuser_net_connect(SO2S(so), |
291 | mtod(nam, struct sockaddr *), sizeof(struct sockaddr_in), | | 291 | mtod(nam, struct sockaddr *), sizeof(struct sockaddr_in), |
292 | &error); | | 292 | &error); |
293 | if (rv == 0) | | 293 | if (rv == 0) |
294 | soisconnected(so); | | 294 | soisconnected(so); |
295 | break; | | 295 | break; |
296 | | | 296 | |
297 | case PRU_SEND: | | 297 | case PRU_SEND: |
298 | { | | 298 | { |
299 | struct sockaddr *saddr; | | 299 | struct sockaddr *saddr; |
300 | struct msghdr mhdr; | | 300 | struct msghdr mhdr; |
301 | struct iovec iov[16]; | | 301 | struct iovec iov[16]; |
302 | struct mbuf *m2; | | 302 | struct mbuf *m2; |
303 | size_t tot; | | 303 | size_t tot; |
| @@ -306,27 +306,27 @@ sockin_usrreq(struct socket *so, int req | | | @@ -306,27 +306,27 @@ sockin_usrreq(struct socket *so, int req |
306 | memset(&mhdr, 0, sizeof(mhdr)); | | 306 | memset(&mhdr, 0, sizeof(mhdr)); |
307 | | | 307 | |
308 | tot = 0; | | 308 | tot = 0; |
309 | for (i = 0, m2 = m; m2; m2 = m2->m_next, i++) { | | 309 | for (i = 0, m2 = m; m2; m2 = m2->m_next, i++) { |
310 | if (i > 16) | | 310 | if (i > 16) |
311 | panic("lazy bum"); | | 311 | panic("lazy bum"); |
312 | iov[i].iov_base = m2->m_data; | | 312 | iov[i].iov_base = m2->m_data; |
313 | iov[i].iov_len = m2->m_len; | | 313 | iov[i].iov_len = m2->m_len; |
314 | tot += m2->m_len; | | 314 | tot += m2->m_len; |
315 | | | 315 | |
316 | } | | 316 | } |
317 | mhdr.msg_iov = iov; | | 317 | mhdr.msg_iov = iov; |
318 | mhdr.msg_iovlen = i; | | 318 | mhdr.msg_iovlen = i; |
319 | s = (int)so->so_internal; | | 319 | s = SO2S(so); |
320 | | | 320 | |
321 | if (so->so_proto->pr_type == SOCK_DGRAM) { | | 321 | if (so->so_proto->pr_type == SOCK_DGRAM) { |
322 | saddr = mtod(nam, struct sockaddr *); | | 322 | saddr = mtod(nam, struct sockaddr *); |
323 | mhdr.msg_name = saddr; | | 323 | mhdr.msg_name = saddr; |
324 | mhdr.msg_namelen = saddr->sa_len; | | 324 | mhdr.msg_namelen = saddr->sa_len; |
325 | } | | 325 | } |
326 | | | 326 | |
327 | rumpuser_net_sendmsg(s, &mhdr, 0, &error); | | 327 | rumpuser_net_sendmsg(s, &mhdr, 0, &error); |
328 | | | 328 | |
329 | m_freem(m); | | 329 | m_freem(m); |
330 | m_freem(control); | | 330 | m_freem(control); |
331 | #ifdef SOCKIN_NOTHREAD | | 331 | #ifdef SOCKIN_NOTHREAD |
332 | /* this assumes too many things to list.. buthey, testing */ | | 332 | /* this assumes too many things to list.. buthey, testing */ |