| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: keysock.c,v 1.52 2009/03/18 16:00:23 cegger Exp $ */ | | 1 | /* $NetBSD: keysock.c,v 1.53 2009/05/09 11:36:17 mlelstv Exp $ */ |
2 | /* $KAME: keysock.c,v 1.32 2003/08/22 05:45:08 itojun Exp $ */ | | 2 | /* $KAME: keysock.c,v 1.32 2003/08/22 05:45:08 itojun Exp $ */ |
3 | | | 3 | |
4 | /* | | 4 | /* |
5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. | | 5 | * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. |
6 | * All rights reserved. | | 6 | * All rights reserved. |
7 | * | | 7 | * |
8 | * Redistribution and use in source and binary forms, with or without | | 8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | | 9 | * modification, are permitted provided that the following conditions |
10 | * are met: | | 10 | * are met: |
11 | * 1. Redistributions of source code must retain the above copyright | | 11 | * 1. Redistributions of source code must retain the above copyright |
12 | * notice, this list of conditions and the following disclaimer. | | 12 | * notice, this list of conditions and the following disclaimer. |
13 | * 2. Redistributions in binary form must reproduce the above copyright | | 13 | * 2. Redistributions in binary form must reproduce the above copyright |
14 | * notice, this list of conditions and the following disclaimer in the | | 14 | * notice, this list of conditions and the following disclaimer in the |
| @@ -21,27 +21,27 @@ | | | @@ -21,27 +21,27 @@ |
21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE | | 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE |
24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | | 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | | 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | | 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | | 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
30 | * SUCH DAMAGE. | | 30 | * SUCH DAMAGE. |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | #include <sys/cdefs.h> | | 33 | #include <sys/cdefs.h> |
34 | __KERNEL_RCSID(0, "$NetBSD: keysock.c,v 1.52 2009/03/18 16:00:23 cegger Exp $"); | | 34 | __KERNEL_RCSID(0, "$NetBSD: keysock.c,v 1.53 2009/05/09 11:36:17 mlelstv Exp $"); |
35 | | | 35 | |
36 | #include "opt_inet.h" | | 36 | #include "opt_inet.h" |
37 | | | 37 | |
38 | /* This code has derived from sys/net/rtsock.c on FreeBSD2.2.5 */ | | 38 | /* This code has derived from sys/net/rtsock.c on FreeBSD2.2.5 */ |
39 | | | 39 | |
40 | #include <sys/param.h> | | 40 | #include <sys/param.h> |
41 | #include <sys/systm.h> | | 41 | #include <sys/systm.h> |
42 | #include <sys/kernel.h> | | 42 | #include <sys/kernel.h> |
43 | #include <sys/mbuf.h> | | 43 | #include <sys/mbuf.h> |
44 | #include <sys/socket.h> | | 44 | #include <sys/socket.h> |
45 | #include <sys/socketvar.h> | | 45 | #include <sys/socketvar.h> |
46 | #include <sys/domain.h> | | 46 | #include <sys/domain.h> |
47 | #include <sys/protosw.h> | | 47 | #include <sys/protosw.h> |
| @@ -67,47 +67,48 @@ struct sockaddr key_src = { .sa_len = 2, | | | @@ -67,47 +67,48 @@ struct sockaddr key_src = { .sa_len = 2, |
67 | | | 67 | |
68 | static int key_receive(struct socket *, struct mbuf **, struct uio *, | | 68 | static int key_receive(struct socket *, struct mbuf **, struct uio *, |
69 | struct mbuf **, struct mbuf **, int *); | | 69 | struct mbuf **, struct mbuf **, int *); |
70 | | | 70 | |
71 | static int key_sendup0(struct rawcb *, struct mbuf *, int, int); | | 71 | static int key_sendup0(struct rawcb *, struct mbuf *, int, int); |
72 | | | 72 | |
73 | static int | | 73 | static int |
74 | key_receive(struct socket *so, struct mbuf **paddr, struct uio *uio, | | 74 | key_receive(struct socket *so, struct mbuf **paddr, struct uio *uio, |
75 | struct mbuf **mp0, struct mbuf **controlp, int *flagsp) | | 75 | struct mbuf **mp0, struct mbuf **controlp, int *flagsp) |
76 | { | | 76 | { |
77 | struct rawcb *rp = sotorawcb(so); | | 77 | struct rawcb *rp = sotorawcb(so); |
78 | struct keycb *kp = (struct keycb *)rp; | | 78 | struct keycb *kp = (struct keycb *)rp; |
79 | int error; | | 79 | int error; |
80 | int s; | | | |
81 | | | 80 | |
82 | error = (*kp->kp_receive)(so, paddr, uio, mp0, controlp, flagsp); | | 81 | error = (*kp->kp_receive)(so, paddr, uio, mp0, controlp, flagsp); |
83 | | | 82 | |
84 | /* | | 83 | /* |
85 | * now we might have enough receive buffer space. | | 84 | * now we might have enough receive buffer space. |
86 | * pull packets from kp_queue as many as possible. | | 85 | * pull packets from kp_queue as many as possible. |
87 | */ | | 86 | */ |
88 | s = splsoftnet(); | | 87 | mutex_enter(softnet_lock); |
| | | 88 | KERNEL_LOCK(1, NULL); |
89 | while (/*CONSTCOND*/ 1) { | | 89 | while (/*CONSTCOND*/ 1) { |
90 | struct mbuf *m; | | 90 | struct mbuf *m; |
91 | | | 91 | |
92 | m = kp->kp_queue; | | 92 | m = kp->kp_queue; |
93 | if (m == NULL || sbspace(&so->so_rcv) < m->m_pkthdr.len) | | 93 | if (m == NULL || sbspace(&so->so_rcv) < m->m_pkthdr.len) |
94 | break; | | 94 | break; |
95 | kp->kp_queue = m->m_nextpkt; | | 95 | kp->kp_queue = m->m_nextpkt; |
96 | m->m_nextpkt = NULL; /* safety */ | | 96 | m->m_nextpkt = NULL; /* safety */ |
97 | if (key_sendup0(rp, m, 0, 1)) | | 97 | if (key_sendup0(rp, m, 0, 1)) |
98 | break; | | 98 | break; |
99 | } | | 99 | } |
100 | splx(s); | | 100 | KERNEL_UNLOCK_ONE(NULL); |
| | | 101 | mutex_exit(softnet_lock); |
101 | | | 102 | |
102 | return error; | | 103 | return error; |
103 | } | | 104 | } |
104 | | | 105 | |
105 | /* | | 106 | /* |
106 | * key_usrreq() | | 107 | * key_usrreq() |
107 | * derived from net/rtsock.c:route_usrreq() | | 108 | * derived from net/rtsock.c:route_usrreq() |
108 | */ | | 109 | */ |
109 | int | | 110 | int |
110 | key_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct mbuf *control, struct lwp *l) | | 111 | key_usrreq(struct socket *so, int req, struct mbuf *m, struct mbuf *nam, struct mbuf *control, struct lwp *l) |
111 | { | | 112 | { |
112 | int error = 0; | | 113 | int error = 0; |
113 | struct keycb *kp = (struct keycb *)sotorawcb(so); | | 114 | struct keycb *kp = (struct keycb *)sotorawcb(so); |