version 1.50.4.5, 2002/09/18 16:04:53 |
version 1.66.2.1, 2002/06/20 16:02:22 |
|
|
/* $NetBSD$ */ |
/* $NetBSD$ */ |
|
|
|
/*- |
|
* Copyright (c) 2002 The NetBSD Foundation, Inc. |
|
* All rights reserved. |
|
* |
|
* This code is derived from software contributed to The NetBSD Foundation |
|
* by Jason R. Thorpe of Wasabi Systems, Inc. |
|
* |
|
* Redistribution and use in source and binary forms, with or without |
|
* modification, are permitted provided that the following conditions |
|
* are met: |
|
* 1. Redistributions of source code must retain the above copyright |
|
* notice, this list of conditions and the following disclaimer. |
|
* 2. Redistributions in binary form must reproduce the above copyright |
|
* notice, this list of conditions and the following disclaimer in the |
|
* documentation and/or other materials provided with the distribution. |
|
* 3. All advertising materials mentioning features or use of this software |
|
* must display the following acknowledgement: |
|
* This product includes software developed by the NetBSD |
|
* Foundation, Inc. and its contributors. |
|
* 4. Neither the name of The NetBSD Foundation nor the names of its |
|
* contributors may be used to endorse or promote products derived |
|
* from this software without specific prior written permission. |
|
* |
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS |
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
|
* POSSIBILITY OF SUCH DAMAGE. |
|
*/ |
|
|
/* |
/* |
* Copyright (c) 1982, 1986, 1988, 1990, 1993 |
* Copyright (c) 1982, 1986, 1988, 1990, 1993 |
* The Regents of the University of California. All rights reserved. |
* The Regents of the University of California. All rights reserved. |
|
|
* @(#)uipc_socket.c 8.6 (Berkeley) 5/2/95 |
* @(#)uipc_socket.c 8.6 (Berkeley) 5/2/95 |
*/ |
*/ |
|
|
#include "opt_compat_sunos.h" |
#include <sys/cdefs.h> |
|
__KERNEL_RCSID(0, "$NetBSD$"); |
|
|
|
#include "opt_sock_counters.h" |
|
#include "opt_sosend_loan.h" |
|
|
#include <sys/param.h> |
#include <sys/param.h> |
#include <sys/systm.h> |
#include <sys/systm.h> |
|
|
#include <sys/resourcevar.h> |
#include <sys/resourcevar.h> |
#include <sys/pool.h> |
#include <sys/pool.h> |
|
|
struct pool socket_pool; |
#include <uvm/uvm.h> |
|
|
|
struct pool socket_pool; |
|
|
|
extern int somaxconn; /* patchable (XXX sysctl) */ |
|
int somaxconn = SOMAXCONN; |
|
|
|
#ifdef SOSEND_COUNTERS |
|
#include <sys/device.h> |
|
|
|
struct evcnt sosend_loan_big = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
|
NULL, "sosend", "loan big"); |
|
struct evcnt sosend_copy_big = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
|
NULL, "sosend", "copy big"); |
|
struct evcnt sosend_copy_small = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
|
NULL, "sosend", "copy small"); |
|
struct evcnt sosend_kvalimit = EVCNT_INITIALIZER(EVCNT_TYPE_MISC, |
|
NULL, "sosend", "kva limit"); |
|
|
|
#define SOSEND_COUNTER_INCR(ev) (ev)->ev_count++ |
|
|
|
#else |
|
|
|
#define SOSEND_COUNTER_INCR(ev) /* nothing */ |
|
|
extern int somaxconn; /* patchable (XXX sysctl) */ |
#endif /* SOSEND_COUNTERS */ |
int somaxconn = SOMAXCONN; |
|
|
|
void |
void |
soinit() |
soinit(void) |
{ |
{ |
|
|
pool_init(&socket_pool, sizeof(struct socket), 0, 0, 0, |
pool_init(&socket_pool, sizeof(struct socket), 0, 0, 0, |
"sockpl", 0, NULL, NULL, M_SOCKET); |
"sockpl", NULL); |
|
|
|
#ifdef SOSEND_COUNTERS |
|
evcnt_attach_static(&sosend_loan_big); |
|
evcnt_attach_static(&sosend_copy_big); |
|
evcnt_attach_static(&sosend_copy_small); |
|
evcnt_attach_static(&sosend_kvalimit); |
|
#endif /* SOSEND_COUNTERS */ |
|
} |
|
|
|
#ifdef SOSEND_LOAN |
|
int use_sosend_loan = 1; |
|
#else |
|
int use_sosend_loan = 0; |
|
#endif |
|
|
|
struct mbuf *so_pendfree; |
|
|
|
int somaxkva = 16 * 1024 * 1024; |
|
int socurkva; |
|
int sokvawaiters; |
|
|
|
#define SOCK_LOAN_THRESH 4096 |
|
#define SOCK_LOAN_CHUNK 65536 |
|
|
|
static void |
|
sodoloanfree(caddr_t buf, u_int size) |
|
{ |
|
struct vm_page **pgs; |
|
vaddr_t va, sva, eva; |
|
vsize_t len; |
|
paddr_t pa; |
|
int i, npgs; |
|
|
|
eva = round_page((vaddr_t) buf + size); |
|
sva = trunc_page((vaddr_t) buf); |
|
len = eva - sva; |
|
npgs = len >> PAGE_SHIFT; |
|
|
|
pgs = alloca(npgs * sizeof(*pgs)); |
|
|
|
for (i = 0, va = sva; va < eva; i++, va += PAGE_SIZE) { |
|
if (pmap_extract(pmap_kernel(), va, &pa) == FALSE) |
|
panic("sodoloanfree: va 0x%lx not mapped", va); |
|
pgs[i] = PHYS_TO_VM_PAGE(pa); |
|
} |
|
|
|
pmap_kremove(sva, len); |
|
pmap_update(pmap_kernel()); |
|
uvm_unloan(pgs, npgs, UVM_LOAN_TOPAGE); |
|
uvm_km_free(kernel_map, sva, len); |
|
socurkva -= len; |
|
if (sokvawaiters) |
|
wakeup(&socurkva); |
|
} |
|
|
|
static size_t |
|
sodopendfree(struct socket *so) |
|
{ |
|
struct mbuf *m; |
|
size_t rv = 0; |
|
int s; |
|
|
|
s = splvm(); |
|
|
|
for (;;) { |
|
m = so_pendfree; |
|
if (m == NULL) |
|
break; |
|
so_pendfree = m->m_next; |
|
splx(s); |
|
|
|
rv += m->m_ext.ext_size; |
|
sodoloanfree(m->m_ext.ext_buf, m->m_ext.ext_size); |
|
s = splvm(); |
|
pool_cache_put(&mbpool_cache, m); |
|
} |
|
|
|
for (;;) { |
|
m = so->so_pendfree; |
|
if (m == NULL) |
|
break; |
|
so->so_pendfree = m->m_next; |
|
splx(s); |
|
|
|
rv += m->m_ext.ext_size; |
|
sodoloanfree(m->m_ext.ext_buf, m->m_ext.ext_size); |
|
s = splvm(); |
|
pool_cache_put(&mbpool_cache, m); |
|
} |
|
|
|
splx(s); |
|
return (rv); |
|
} |
|
|
|
static void |
|
soloanfree(struct mbuf *m, caddr_t buf, u_int size, void *arg) |
|
{ |
|
struct socket *so = arg; |
|
int s; |
|
|
|
if (m == NULL) { |
|
sodoloanfree(buf, size); |
|
return; |
|
} |
|
|
|
s = splvm(); |
|
m->m_next = so->so_pendfree; |
|
so->so_pendfree = m; |
|
splx(s); |
|
if (sokvawaiters) |
|
wakeup(&socurkva); |
|
} |
|
|
|
static long |
|
sosend_loan(struct socket *so, struct uio *uio, struct mbuf *m, long space) |
|
{ |
|
struct iovec *iov = uio->uio_iov; |
|
vaddr_t sva, eva; |
|
vsize_t len; |
|
struct vm_page **pgs; |
|
vaddr_t lva, va; |
|
int npgs, s, i, error; |
|
|
|
if (uio->uio_segflg != UIO_USERSPACE) |
|
return (0); |
|
|
|
if (iov->iov_len < (size_t) space) |
|
space = iov->iov_len; |
|
if (space > SOCK_LOAN_CHUNK) |
|
space = SOCK_LOAN_CHUNK; |
|
|
|
eva = round_page((vaddr_t) iov->iov_base + space); |
|
sva = trunc_page((vaddr_t) iov->iov_base); |
|
len = eva - sva; |
|
npgs = len >> PAGE_SHIFT; |
|
|
|
while (socurkva + len > somaxkva) { |
|
if (sodopendfree(so)) |
|
continue; |
|
SOSEND_COUNTER_INCR(&sosend_kvalimit); |
|
s = splvm(); |
|
sokvawaiters++; |
|
(void) tsleep(&socurkva, PVM, "sokva", 0); |
|
sokvawaiters--; |
|
splx(s); |
|
} |
|
|
|
lva = uvm_km_valloc_wait(kernel_map, len); |
|
if (lva == 0) |
|
return (0); |
|
socurkva += len; |
|
|
|
pgs = alloca(npgs * sizeof(*pgs)); |
|
|
|
error = uvm_loan(&uio->uio_procp->p_vmspace->vm_map, sva, len, |
|
pgs, UVM_LOAN_TOPAGE); |
|
if (error) { |
|
uvm_km_free(kernel_map, lva, len); |
|
socurkva -= len; |
|
return (0); |
|
} |
|
|
|
for (i = 0, va = lva; i < npgs; i++, va += PAGE_SIZE) |
|
pmap_kenter_pa(va, VM_PAGE_TO_PHYS(pgs[i]), VM_PROT_READ); |
|
pmap_update(pmap_kernel()); |
|
|
|
lva += (vaddr_t) iov->iov_base & PAGE_MASK; |
|
|
|
MEXTADD(m, (caddr_t) lva, space, M_MBUF, soloanfree, so); |
|
|
|
uio->uio_resid -= space; |
|
/* uio_offset not updated, not set/used for write(2) */ |
|
uio->uio_iov->iov_base = (caddr_t) uio->uio_iov->iov_base + space; |
|
uio->uio_iov->iov_len -= space; |
|
if (uio->uio_iov->iov_len == 0) { |
|
uio->uio_iov++; |
|
uio->uio_iovcnt--; |
|
} |
|
|
|
return (space); |
} |
} |
|
|
/* |
/* |
|
|
*/ |
*/ |
/*ARGSUSED*/ |
/*ARGSUSED*/ |
int |
int |
socreate(dom, aso, type, proto) |
socreate(int dom, struct socket **aso, int type, int proto) |
int dom; |
{ |
struct socket **aso; |
struct proc *p; |
int type; |
struct protosw *prp; |
int proto; |
struct socket *so; |
{ |
int error, s; |
struct proc *p = curproc; /* XXX */ |
|
struct protosw *prp; |
|
struct socket *so; |
|
int error; |
|
int s; |
|
|
|
|
p = curproc; /* XXX */ |
if (proto) |
if (proto) |
prp = pffindproto(dom, proto, type); |
prp = pffindproto(dom, proto, type); |
else |
else |
Line 113 socreate(dom, aso, type, proto) |
|
Line 351 socreate(dom, aso, type, proto) |
|
splx(s); |
splx(s); |
return (error); |
return (error); |
} |
} |
#ifdef COMPAT_SUNOS |
|
{ |
|
extern struct emul emul_sunos; |
|
if (p->p_emul == &emul_sunos && type == SOCK_DGRAM) |
|
so->so_options |= SO_BROADCAST; |
|
} |
|
#endif |
|
splx(s); |
splx(s); |
*aso = so; |
*aso = so; |
return (0); |
return (0); |
} |
} |
|
|
int |
int |
sobind(so, nam, p) |
sobind(struct socket *so, struct mbuf *nam, struct proc *p) |
struct socket *so; |
|
struct mbuf *nam; |
|
struct proc *p; |
|
{ |
{ |
int s = splsoftnet(); |
int s, error; |
int error; |
|
|
|
|
s = splsoftnet(); |
error = (*so->so_proto->pr_usrreq)(so, PRU_BIND, (struct mbuf *)0, |
error = (*so->so_proto->pr_usrreq)(so, PRU_BIND, (struct mbuf *)0, |
nam, (struct mbuf *)0, p); |
nam, (struct mbuf *)0, p); |
splx(s); |
splx(s); |
Line 141 sobind(so, nam, p) |
|
Line 369 sobind(so, nam, p) |
|
} |
} |
|
|
int |
int |
solisten(so, backlog) |
solisten(struct socket *so, int backlog) |
struct socket *so; |
|
int backlog; |
|
{ |
{ |
int s = splsoftnet(), error; |
int s, error; |
|
|
|
s = splsoftnet(); |
error = (*so->so_proto->pr_usrreq)(so, PRU_LISTEN, (struct mbuf *)0, |
error = (*so->so_proto->pr_usrreq)(so, PRU_LISTEN, (struct mbuf *)0, |
(struct mbuf *)0, (struct mbuf *)0, (struct proc *)0); |
(struct mbuf *)0, (struct mbuf *)0, (struct proc *)0); |
if (error) { |
if (error) { |
splx(s); |
splx(s); |
return (error); |
return (error); |
} |
} |
if (so->so_q.tqh_first == NULL) |
if (TAILQ_EMPTY(&so->so_q)) |
so->so_options |= SO_ACCEPTCONN; |
so->so_options |= SO_ACCEPTCONN; |
if (backlog < 0) |
if (backlog < 0) |
backlog = 0; |
backlog = 0; |
Line 163 solisten(so, backlog) |
|
Line 390 solisten(so, backlog) |
|
} |
} |
|
|
void |
void |
sofree(so) |
sofree(struct socket *so) |
struct socket *so; |
|
{ |
{ |
|
struct mbuf *m; |
|
|
if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0) |
if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0) |
return; |
return; |
|
|
} |
} |
sbrelease(&so->so_snd); |
sbrelease(&so->so_snd); |
sorflush(so); |
sorflush(so); |
|
while ((m = so->so_pendfree) != NULL) { |
|
so->so_pendfree = m->m_next; |
|
m->m_next = so_pendfree; |
|
so_pendfree = m; |
|
} |
pool_put(&socket_pool, so); |
pool_put(&socket_pool, so); |
} |
} |
|
|
|
|
* Free socket when disconnect complete. |
* Free socket when disconnect complete. |
*/ |
*/ |
int |
int |
soclose(so) |
soclose(struct socket *so) |
struct socket *so; |
|
{ |
{ |
struct socket *so2; |
struct socket *so2; |
int s = splsoftnet(); /* conservative */ |
int s, error; |
int error = 0; |
|
|
|
|
error = 0; |
|
s = splsoftnet(); /* conservative */ |
if (so->so_options & SO_ACCEPTCONN) { |
if (so->so_options & SO_ACCEPTCONN) { |
while ((so2 = so->so_q0.tqh_first) != 0) { |
while ((so2 = TAILQ_FIRST(&so->so_q0)) != 0) { |
(void) soqremque(so2, 0); |
(void) soqremque(so2, 0); |
(void) soabort(so2); |
(void) soabort(so2); |
} |
} |
while ((so2 = so->so_q.tqh_first) != 0) { |
while ((so2 = TAILQ_FIRST(&so->so_q)) != 0) { |
(void) soqremque(so2, 1); |
(void) soqremque(so2, 1); |
(void) soabort(so2); |
(void) soabort(so2); |
} |
} |
|
|
} |
} |
} |
} |
} |
} |
drop: |
drop: |
if (so->so_pcb) { |
if (so->so_pcb) { |
int error2 = (*so->so_proto->pr_usrreq)(so, PRU_DETACH, |
int error2 = (*so->so_proto->pr_usrreq)(so, PRU_DETACH, |
(struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0, |
(struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0, |
|
|
if (error == 0) |
if (error == 0) |
error = error2; |
error = error2; |
} |
} |
discard: |
discard: |
if (so->so_state & SS_NOFDREF) |
if (so->so_state & SS_NOFDREF) |
panic("soclose: NOFDREF"); |
panic("soclose: NOFDREF"); |
so->so_state |= SS_NOFDREF; |
so->so_state |= SS_NOFDREF; |
|
|
* Must be called at splsoftnet... |
* Must be called at splsoftnet... |
*/ |
*/ |
int |
int |
soabort(so) |
soabort(struct socket *so) |
struct socket *so; |
|
{ |
{ |
|
|
return (*so->so_proto->pr_usrreq)(so, PRU_ABORT, (struct mbuf *)0, |
return (*so->so_proto->pr_usrreq)(so, PRU_ABORT, (struct mbuf *)0, |
|
|
} |
} |
|
|
int |
int |
soaccept(so, nam) |
soaccept(struct socket *so, struct mbuf *nam) |
struct socket *so; |
|
struct mbuf *nam; |
|
{ |
{ |
int s = splsoftnet(); |
int s, error; |
int error = 0; |
|
|
|
|
error = 0; |
|
s = splsoftnet(); |
if ((so->so_state & SS_NOFDREF) == 0) |
if ((so->so_state & SS_NOFDREF) == 0) |
panic("soaccept: !NOFDREF"); |
panic("soaccept: !NOFDREF"); |
so->so_state &= ~SS_NOFDREF; |
so->so_state &= ~SS_NOFDREF; |
if ((so->so_state & SS_ISDISCONNECTED) == 0) |
if ((so->so_state & SS_ISDISCONNECTED) == 0 || |
|
(so->so_proto->pr_flags & PR_ABRTACPTDIS) == 0) |
error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT, |
error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT, |
(struct mbuf *)0, nam, (struct mbuf *)0, (struct proc *)0); |
(struct mbuf *)0, nam, (struct mbuf *)0, (struct proc *)0); |
else |
else |
Line 278 soaccept(so, nam) |
|
Line 509 soaccept(so, nam) |
|
} |
} |
|
|
int |
int |
soconnect(so, nam) |
soconnect(struct socket *so, struct mbuf *nam) |
struct socket *so; |
|
struct mbuf *nam; |
|
{ |
{ |
struct proc *p = curproc; /* XXX */ |
struct proc *p; |
int s; |
int s, error; |
int error; |
|
|
|
|
p = curproc; /* XXX */ |
if (so->so_options & SO_ACCEPTCONN) |
if (so->so_options & SO_ACCEPTCONN) |
return (EOPNOTSUPP); |
return (EOPNOTSUPP); |
s = splsoftnet(); |
s = splsoftnet(); |
Line 307 soconnect(so, nam) |
|
Line 536 soconnect(so, nam) |
|
} |
} |
|
|
int |
int |
soconnect2(so1, so2) |
soconnect2(struct socket *so1, struct socket *so2) |
struct socket *so1; |
|
struct socket *so2; |
|
{ |
{ |
int s = splsoftnet(); |
int s, error; |
int error; |
|
|
|
|
s = splsoftnet(); |
error = (*so1->so_proto->pr_usrreq)(so1, PRU_CONNECT2, |
error = (*so1->so_proto->pr_usrreq)(so1, PRU_CONNECT2, |
(struct mbuf *)0, (struct mbuf *)so2, (struct mbuf *)0, |
(struct mbuf *)0, (struct mbuf *)so2, (struct mbuf *)0, |
(struct proc *)0); |
(struct proc *)0); |
Line 322 soconnect2(so1, so2) |
|
Line 549 soconnect2(so1, so2) |
|
} |
} |
|
|
int |
int |
sodisconnect(so) |
sodisconnect(struct socket *so) |
struct socket *so; |
|
{ |
{ |
int s = splsoftnet(); |
int s, error; |
int error; |
|
|
|
|
s = splsoftnet(); |
if ((so->so_state & SS_ISCONNECTED) == 0) { |
if ((so->so_state & SS_ISCONNECTED) == 0) { |
error = ENOTCONN; |
error = ENOTCONN; |
goto bad; |
goto bad; |
Line 339 sodisconnect(so) |
|
Line 565 sodisconnect(so) |
|
error = (*so->so_proto->pr_usrreq)(so, PRU_DISCONNECT, |
error = (*so->so_proto->pr_usrreq)(so, PRU_DISCONNECT, |
(struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0, |
(struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0, |
(struct proc *)0); |
(struct proc *)0); |
bad: |
bad: |
splx(s); |
splx(s); |
|
sodopendfree(so); |
return (error); |
return (error); |
} |
} |
|
|
|
|
* Data and control buffers are freed on return. |
* Data and control buffers are freed on return. |
*/ |
*/ |
int |
int |
sosend(so, addr, uio, top, control, flags) |
sosend(struct socket *so, struct mbuf *addr, struct uio *uio, struct mbuf *top, |
struct socket *so; |
struct mbuf *control, int flags) |
struct mbuf *addr; |
|
struct uio *uio; |
|
struct mbuf *top; |
|
struct mbuf *control; |
|
int flags; |
|
{ |
{ |
struct proc *p = curproc; /* XXX */ |
struct proc *p; |
struct mbuf **mp; |
struct mbuf **mp, *m; |
struct mbuf *m; |
long space, len, resid, clen, mlen; |
long space, len, resid; |
int error, s, dontroute, atomic; |
int clen = 0, error, s, dontroute, mlen; |
|
int atomic = sosendallatonce(so) || top; |
sodopendfree(so); |
|
|
|
p = curproc; /* XXX */ |
|
clen = 0; |
|
atomic = sosendallatonce(so) || top; |
if (uio) |
if (uio) |
resid = uio->uio_resid; |
resid = uio->uio_resid; |
else |
else |
Line 401 sosend(so, addr, uio, top, control, flag |
|
Line 626 sosend(so, addr, uio, top, control, flag |
|
clen = control->m_len; |
clen = control->m_len; |
#define snderr(errno) { error = errno; splx(s); goto release; } |
#define snderr(errno) { error = errno; splx(s); goto release; } |
|
|
restart: |
restart: |
if ((error = sblock(&so->so_snd, SBLOCKWAIT(flags))) != 0) |
if ((error = sblock(&so->so_snd, SBLOCKWAIT(flags))) != 0) |
goto out; |
goto out; |
do { |
do { |
|
|
MGET(m, M_WAIT, MT_DATA); |
MGET(m, M_WAIT, MT_DATA); |
mlen = MLEN; |
mlen = MLEN; |
} |
} |
|
if (use_sosend_loan && |
|
uio->uio_iov->iov_len >= SOCK_LOAN_THRESH && |
|
space >= SOCK_LOAN_THRESH && |
|
(len = sosend_loan(so, uio, m, |
|
space)) != 0) { |
|
SOSEND_COUNTER_INCR(&sosend_loan_big); |
|
space -= len; |
|
goto have_data; |
|
} |
if (resid >= MINCLSIZE && space >= MCLBYTES) { |
if (resid >= MINCLSIZE && space >= MCLBYTES) { |
|
SOSEND_COUNTER_INCR(&sosend_copy_big); |
MCLGET(m, M_WAIT); |
MCLGET(m, M_WAIT); |
if ((m->m_flags & M_EXT) == 0) |
if ((m->m_flags & M_EXT) == 0) |
goto nopages; |
goto nopages; |
mlen = MCLBYTES; |
mlen = MCLBYTES; |
#ifdef MAPPED_MBUFS |
|
len = min(MCLBYTES, resid); |
|
#else |
|
if (atomic && top == 0) { |
if (atomic && top == 0) { |
len = min(MCLBYTES - max_hdr, resid); |
len = lmin(MCLBYTES - max_hdr, |
|
resid); |
m->m_data += max_hdr; |
m->m_data += max_hdr; |
} else |
} else |
len = min(MCLBYTES, resid); |
len = lmin(MCLBYTES, resid); |
#endif |
|
space -= len; |
space -= len; |
} else { |
} else { |
nopages: |
nopages: |
len = min(min(mlen, resid), space); |
SOSEND_COUNTER_INCR(&sosend_copy_small); |
|
len = lmin(lmin(mlen, resid), space); |
space -= len; |
space -= len; |
/* |
/* |
* For datagram protocols, leave room |
* For datagram protocols, leave room |
|
|
if (atomic && top == 0 && len < mlen) |
if (atomic && top == 0 && len < mlen) |
MH_ALIGN(m, len); |
MH_ALIGN(m, len); |
} |
} |
error = uiomove(mtod(m, caddr_t), (int)len, uio); |
error = uiomove(mtod(m, caddr_t), (int)len, |
|
uio); |
|
have_data: |
resid = uio->uio_resid; |
resid = uio->uio_resid; |
m->m_len = len; |
m->m_len = len; |
*mp = m; |
*mp = m; |
|
|
} while (resid && space > 0); |
} while (resid && space > 0); |
} while (resid); |
} while (resid); |
|
|
release: |
release: |
sbunlock(&so->so_snd); |
sbunlock(&so->so_snd); |
out: |
out: |
if (top) |
if (top) |
m_freem(top); |
m_freem(top); |
if (control) |
if (control) |
|
|
* only for the count in uio_resid. |
* only for the count in uio_resid. |
*/ |
*/ |
int |
int |
soreceive(so, paddr, uio, mp0, controlp, flagsp) |
soreceive(struct socket *so, struct mbuf **paddr, struct uio *uio, |
struct socket *so; |
struct mbuf **mp0, struct mbuf **controlp, int *flagsp) |
struct mbuf **paddr; |
{ |
struct uio *uio; |
struct mbuf *m, **mp; |
struct mbuf **mp0; |
int flags, len, error, s, offset, moff, type, orig_resid; |
struct mbuf **controlp; |
struct protosw *pr; |
int *flagsp; |
struct mbuf *nextrecord; |
{ |
int mbuf_removed = 0; |
struct mbuf *m, **mp; |
|
int flags, len, error, s, offset; |
|
struct protosw *pr = so->so_proto; |
|
struct mbuf *nextrecord; |
|
int moff, type = 0; |
|
int orig_resid = uio->uio_resid; |
|
int mbuf_removed = 0; |
|
|
|
|
pr = so->so_proto; |
mp = mp0; |
mp = mp0; |
|
type = 0; |
|
orig_resid = uio->uio_resid; |
if (paddr) |
if (paddr) |
*paddr = 0; |
*paddr = 0; |
if (controlp) |
if (controlp) |
Line 580 soreceive(so, paddr, uio, mp0, controlp, |
|
Line 811 soreceive(so, paddr, uio, mp0, controlp, |
|
flags = *flagsp &~ MSG_EOR; |
flags = *flagsp &~ MSG_EOR; |
else |
else |
flags = 0; |
flags = 0; |
|
|
|
if ((flags & MSG_DONTWAIT) == 0) |
|
sodopendfree(so); |
|
|
if (flags & MSG_OOB) { |
if (flags & MSG_OOB) { |
m = m_get(M_WAIT, MT_DATA); |
m = m_get(M_WAIT, MT_DATA); |
error = (*pr->pr_usrreq)(so, PRU_RCVOOB, m, |
error = (*pr->pr_usrreq)(so, PRU_RCVOOB, m, |
Line 592 soreceive(so, paddr, uio, mp0, controlp, |
|
Line 827 soreceive(so, paddr, uio, mp0, controlp, |
|
(int) min(uio->uio_resid, m->m_len), uio); |
(int) min(uio->uio_resid, m->m_len), uio); |
m = m_free(m); |
m = m_free(m); |
} while (uio->uio_resid && error == 0 && m); |
} while (uio->uio_resid && error == 0 && m); |
bad: |
bad: |
if (m) |
if (m) |
m_freem(m); |
m_freem(m); |
return (error); |
return (error); |
|
|
(*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0, |
(*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0, |
(struct mbuf *)0, (struct mbuf *)0, (struct proc *)0); |
(struct mbuf *)0, (struct mbuf *)0, (struct proc *)0); |
|
|
restart: |
restart: |
if ((error = sblock(&so->so_rcv, SBLOCKWAIT(flags))) != 0) |
if ((error = sblock(&so->so_rcv, SBLOCKWAIT(flags))) != 0) |
return (error); |
return (error); |
s = splsoftnet(); |
s = splsoftnet(); |
|
|
return (error); |
return (error); |
goto restart; |
goto restart; |
} |
} |
dontblock: |
dontblock: |
#ifdef notyet /* XXXX */ |
#ifdef notyet /* XXXX */ |
if (uio->uio_procp) |
if (uio->uio_procp) |
uio->uio_procp->p_stats->p_ru.ru_msgrcv++; |
uio->uio_procp->p_stats->p_ru.ru_msgrcv++; |
|
|
!sosendallatonce(so) && !nextrecord) { |
!sosendallatonce(so) && !nextrecord) { |
if (so->so_error || so->so_state & SS_CANTRCVMORE) |
if (so->so_error || so->so_state & SS_CANTRCVMORE) |
break; |
break; |
|
/* |
|
* If we are peeking and the socket receive buffer is |
|
* full, stop since we can't get more data to peek at. |
|
*/ |
|
if ((flags & MSG_PEEK) && sbspace(&so->so_rcv) <= 0) |
|
break; |
|
/* |
|
* If we've drained the socket buffer, tell the |
|
* protocol in case it needs to do something to |
|
* get it filled again. |
|
*/ |
|
if ((pr->pr_flags & PR_WANTRCVD) && so->so_pcb) |
|
(*pr->pr_usrreq)(so, PRU_RCVD, |
|
(struct mbuf *)0, |
|
(struct mbuf *)(long)flags, |
|
(struct mbuf *)0, |
|
(struct proc *)0); |
error = sbwait(&so->so_rcv); |
error = sbwait(&so->so_rcv); |
if (error) { |
if (error) { |
sbunlock(&so->so_rcv); |
sbunlock(&so->so_rcv); |
|
|
|
|
if (flagsp) |
if (flagsp) |
*flagsp |= flags; |
*flagsp |= flags; |
release: |
release: |
sbunlock(&so->so_rcv); |
sbunlock(&so->so_rcv); |
splx(s); |
splx(s); |
return (error); |
return (error); |
} |
} |
|
|
int |
int |
soshutdown(so, how) |
soshutdown(struct socket *so, int how) |
struct socket *so; |
|
int how; |
|
{ |
{ |
struct protosw *pr = so->so_proto; |
struct protosw *pr; |
|
|
|
pr = so->so_proto; |
if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR)) |
if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR)) |
return (EINVAL); |
return (EINVAL); |
|
|
Line 896 soshutdown(so, how) |
|
Line 1147 soshutdown(so, how) |
|
} |
} |
|
|
void |
void |
sorflush(so) |
sorflush(struct socket *so) |
struct socket *so; |
|
{ |
{ |
struct sockbuf *sb = &so->so_rcv; |
struct sockbuf *sb, asb; |
struct protosw *pr = so->so_proto; |
struct protosw *pr; |
int s; |
int s; |
struct sockbuf asb; |
|
|
|
|
sb = &so->so_rcv; |
|
pr = so->so_proto; |
sb->sb_flags |= SB_NOINTR; |
sb->sb_flags |= SB_NOINTR; |
(void) sblock(sb, M_WAITOK); |
(void) sblock(sb, M_WAITOK); |
s = splimp(); |
s = splnet(); |
socantrcvmore(so); |
socantrcvmore(so); |
sbunlock(sb); |
sbunlock(sb); |
asb = *sb; |
asb = *sb; |
|
|
} |
} |
|
|
int |
int |
sosetopt(so, level, optname, m0) |
sosetopt(struct socket *so, int level, int optname, struct mbuf *m0) |
struct socket *so; |
|
int level, optname; |
|
struct mbuf *m0; |
|
{ |
{ |
int error = 0; |
int error; |
struct mbuf *m = m0; |
struct mbuf *m; |
|
|
|
error = 0; |
|
m = m0; |
if (level != SOL_SOCKET) { |
if (level != SOL_SOCKET) { |
if (so->so_proto && so->so_proto->pr_ctloutput) |
if (so->so_proto && so->so_proto->pr_ctloutput) |
return ((*so->so_proto->pr_ctloutput) |
return ((*so->so_proto->pr_ctloutput) |
Line 1052 sosetopt(so, level, optname, m0) |
|
Line 1302 sosetopt(so, level, optname, m0) |
|
m = NULL; /* freed by protocol */ |
m = NULL; /* freed by protocol */ |
} |
} |
} |
} |
bad: |
bad: |
if (m) |
if (m) |
(void) m_free(m); |
(void) m_free(m); |
return (error); |
return (error); |
} |
} |
|
|
int |
int |
sogetopt(so, level, optname, mp) |
sogetopt(struct socket *so, int level, int optname, struct mbuf **mp) |
struct socket *so; |
|
int level, optname; |
|
struct mbuf **mp; |
|
{ |
{ |
struct mbuf *m; |
struct mbuf *m; |
|
|
if (level != SOL_SOCKET) { |
if (level != SOL_SOCKET) { |
if (so->so_proto && so->so_proto->pr_ctloutput) { |
if (so->so_proto && so->so_proto->pr_ctloutput) { |
Line 1145 sogetopt(so, level, optname, mp) |
|
Line 1392 sogetopt(so, level, optname, mp) |
|
} |
} |
|
|
void |
void |
sohasoutofband(so) |
sohasoutofband(struct socket *so) |
struct socket *so; |
|
{ |
{ |
struct proc *p; |
struct proc *p; |
|
|