version 1.115.6.1, 2006/04/22 11:39:59 |
version 1.132.2.2, 2007/03/12 05:58:45 |
Line 91 __KERNEL_RCSID(0, "$NetBSD$"); |
|
Line 91 __KERNEL_RCSID(0, "$NetBSD$"); |
|
#include <sys/pool.h> |
#include <sys/pool.h> |
#include <sys/event.h> |
#include <sys/event.h> |
#include <sys/poll.h> |
#include <sys/poll.h> |
|
#include <sys/kauth.h> |
|
|
#include <uvm/uvm.h> |
#include <uvm/uvm.h> |
|
|
Line 126 EVCNT_ATTACH_STATIC(sosend_kvalimit); |
|
Line 127 EVCNT_ATTACH_STATIC(sosend_kvalimit); |
|
|
|
#endif /* SOSEND_COUNTERS */ |
#endif /* SOSEND_COUNTERS */ |
|
|
void |
static struct callback_entry sokva_reclaimerentry; |
soinit(void) |
|
{ |
|
|
|
/* Set the initial adjusted socket buffer size. */ |
|
if (sb_max_set(sb_max)) |
|
panic("bad initial sb_max value: %lu", sb_max); |
|
|
|
} |
|
|
|
#ifdef SOSEND_NO_LOAN |
#ifdef SOSEND_NO_LOAN |
int use_sosend_loan = 0; |
int sock_loan_thresh = -1; |
#else |
#else |
int use_sosend_loan = 1; |
int sock_loan_thresh = 4096; |
#endif |
#endif |
|
|
static struct simplelock so_pendfree_slock = SIMPLELOCK_INITIALIZER; |
static struct simplelock so_pendfree_slock = SIMPLELOCK_INITIALIZER; |
Line 152 int somaxkva = SOMAXKVA; |
|
Line 145 int somaxkva = SOMAXKVA; |
|
static int socurkva; |
static int socurkva; |
static int sokvawaiters; |
static int sokvawaiters; |
|
|
#define SOCK_LOAN_THRESH 4096 |
|
#define SOCK_LOAN_CHUNK 65536 |
#define SOCK_LOAN_CHUNK 65536 |
|
|
static size_t sodopendfree(void); |
static size_t sodopendfree(void); |
Line 263 sokvafree(vaddr_t sva, vsize_t len) |
|
Line 255 sokvafree(vaddr_t sva, vsize_t len) |
|
} |
} |
|
|
static void |
static void |
sodoloanfree(struct vm_page **pgs, caddr_t buf, size_t size) |
sodoloanfree(struct vm_page **pgs, void *buf, size_t size) |
{ |
{ |
vaddr_t va, sva, eva; |
vaddr_t va, sva, eva; |
vsize_t len; |
vsize_t len; |
Line 279 sodoloanfree(struct vm_page **pgs, caddr |
|
Line 271 sodoloanfree(struct vm_page **pgs, caddr |
|
pgs = alloca(npgs * sizeof(*pgs)); |
pgs = alloca(npgs * sizeof(*pgs)); |
|
|
for (i = 0, va = sva; va < eva; i++, va += PAGE_SIZE) { |
for (i = 0, va = sva; va < eva; i++, va += PAGE_SIZE) { |
if (pmap_extract(pmap_kernel(), va, &pa) == FALSE) |
if (pmap_extract(pmap_kernel(), va, &pa) == false) |
panic("sodoloanfree: va 0x%lx not mapped", va); |
panic("sodoloanfree: va 0x%lx not mapped", va); |
pgs[i] = PHYS_TO_VM_PAGE(pa); |
pgs[i] = PHYS_TO_VM_PAGE(pa); |
} |
} |
|
|
} |
} |
|
|
void |
void |
soloanfree(struct mbuf *m, caddr_t buf, size_t size, void *arg) |
soloanfree(struct mbuf *m, void *buf, size_t size, void *arg) |
{ |
{ |
int s; |
int s; |
|
|
Line 424 sosend_loan(struct socket *so, struct ui |
|
Line 416 sosend_loan(struct socket *so, struct ui |
|
|
|
lva += (vaddr_t) iov->iov_base & PAGE_MASK; |
lva += (vaddr_t) iov->iov_base & PAGE_MASK; |
|
|
MEXTADD(m, (caddr_t) lva, space, M_MBUF, soloanfree, so); |
MEXTADD(m, (void *) lva, space, M_MBUF, soloanfree, so); |
m->m_flags |= M_EXT_PAGES | M_EXT_ROMAP; |
m->m_flags |= M_EXT_PAGES | M_EXT_ROMAP; |
|
|
uio->uio_resid -= space; |
uio->uio_resid -= space; |
/* uio_offset not updated, not set/used for write(2) */ |
/* 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_base = (char *)uio->uio_iov->iov_base + space; |
uio->uio_iov->iov_len -= space; |
uio->uio_iov->iov_len -= space; |
if (uio->uio_iov->iov_len == 0) { |
if (uio->uio_iov->iov_len == 0) { |
uio->uio_iov++; |
uio->uio_iov++; |
Line 439 sosend_loan(struct socket *so, struct ui |
|
Line 431 sosend_loan(struct socket *so, struct ui |
|
return (space); |
return (space); |
} |
} |
|
|
|
static int |
|
sokva_reclaim_callback(struct callback_entry *ce, void *obj, void *arg) |
|
{ |
|
|
|
KASSERT(ce == &sokva_reclaimerentry); |
|
KASSERT(obj == NULL); |
|
|
|
sodopendfree(); |
|
if (!vm_map_starved_p(kernel_map)) { |
|
return CALLBACK_CHAIN_ABORT; |
|
} |
|
return CALLBACK_CHAIN_CONTINUE; |
|
} |
|
|
|
void |
|
soinit(void) |
|
{ |
|
|
|
/* Set the initial adjusted socket buffer size. */ |
|
if (sb_max_set(sb_max)) |
|
panic("bad initial sb_max value: %lu", sb_max); |
|
|
|
callback_register(&vm_map_to_kernel(kernel_map)->vmk_reclaim_callback, |
|
&sokva_reclaimerentry, NULL, sokva_reclaim_callback); |
|
} |
|
|
/* |
/* |
* Socket operation routines. |
* Socket operation routines. |
* These routines are called by the routines in |
* These routines are called by the routines in |
Line 455 socreate(int dom, struct socket **aso, i |
|
Line 473 socreate(int dom, struct socket **aso, i |
|
uid_t uid; |
uid_t uid; |
int error, s; |
int error, s; |
|
|
|
error = kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET, |
|
KAUTH_REQ_NETWORK_SOCKET_OPEN, KAUTH_ARG(dom), KAUTH_ARG(type), |
|
KAUTH_ARG(proto)); |
|
if (error) |
|
return (error); |
|
|
if (proto) |
if (proto) |
prp = pffindproto(dom, proto, type); |
prp = pffindproto(dom, proto, type); |
else |
else |
prp = pffindtype(dom, type); |
prp = pffindtype(dom, type); |
if (prp == 0 || prp->pr_usrreq == 0) |
if (prp == 0) { |
|
/* no support for domain */ |
|
if (pffinddomain(dom) == 0) |
|
return (EAFNOSUPPORT); |
|
/* no support for socket type */ |
|
if (proto == 0 && type != 0) |
|
return (EPROTOTYPE); |
|
return (EPROTONOSUPPORT); |
|
} |
|
if (prp->pr_usrreq == 0) |
return (EPROTONOSUPPORT); |
return (EPROTONOSUPPORT); |
if (prp->pr_type != type) |
if (prp->pr_type != type) |
return (EPROTOTYPE); |
return (EPROTOTYPE); |
s = splsoftnet(); |
s = splsoftnet(); |
so = pool_get(&socket_pool, PR_WAITOK); |
so = pool_get(&socket_pool, PR_WAITOK); |
memset((caddr_t)so, 0, sizeof(*so)); |
memset((void *)so, 0, sizeof(*so)); |
TAILQ_INIT(&so->so_q0); |
TAILQ_INIT(&so->so_q0); |
TAILQ_INIT(&so->so_q); |
TAILQ_INIT(&so->so_q); |
so->so_type = type; |
so->so_type = type; |
Line 478 socreate(int dom, struct socket **aso, i |
|
Line 511 socreate(int dom, struct socket **aso, i |
|
so->so_mowner = &prp->pr_domain->dom_mowner; |
so->so_mowner = &prp->pr_domain->dom_mowner; |
#endif |
#endif |
if (l != NULL) { |
if (l != NULL) { |
uid = l->l_proc->p_ucred->cr_uid; |
uid = kauth_cred_geteuid(l->l_cred); |
} else { |
} else { |
uid = 0; |
uid = 0; |
} |
} |
Line 591 soclose(struct socket *so) |
|
Line 624 soclose(struct socket *so) |
|
(so->so_state & SS_NBIO)) |
(so->so_state & SS_NBIO)) |
goto drop; |
goto drop; |
while (so->so_state & SS_ISCONNECTED) { |
while (so->so_state & SS_ISCONNECTED) { |
error = tsleep((caddr_t)&so->so_timeo, |
error = tsleep((void *)&so->so_timeo, |
PSOCK | PCATCH, netcls, |
PSOCK | PCATCH, netcls, |
so->so_linger * hz); |
so->so_linger * hz); |
if (error) |
if (error) |
Line 825 sosend(struct socket *so, struct mbuf *a |
|
Line 858 sosend(struct socket *so, struct mbuf *a |
|
mlen = MLEN; |
mlen = MLEN; |
} |
} |
MCLAIM(m, so->so_snd.sb_mowner); |
MCLAIM(m, so->so_snd.sb_mowner); |
if (use_sosend_loan && |
if (sock_loan_thresh >= 0 && |
uio->uio_iov->iov_len >= SOCK_LOAN_THRESH && |
uio->uio_iov->iov_len >= sock_loan_thresh && |
space >= SOCK_LOAN_THRESH && |
space >= sock_loan_thresh && |
(len = sosend_loan(so, uio, m, |
(len = sosend_loan(so, uio, m, |
space)) != 0) { |
space)) != 0) { |
SOSEND_COUNTER_INCR(&sosend_loan_big); |
SOSEND_COUNTER_INCR(&sosend_loan_big); |
Line 859 sosend(struct socket *so, struct mbuf *a |
|
Line 892 sosend(struct socket *so, struct mbuf *a |
|
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, |
error = uiomove(mtod(m, void *), (int)len, |
uio); |
uio); |
have_data: |
have_data: |
resid = uio->uio_resid; |
resid = uio->uio_resid; |
Line 965 soreceive(struct socket *so, struct mbuf |
|
Line 998 soreceive(struct socket *so, struct mbuf |
|
if (error) |
if (error) |
goto bad; |
goto bad; |
do { |
do { |
error = uiomove(mtod(m, caddr_t), |
error = uiomove(mtod(m, void *), |
(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); |
Line 1179 soreceive(struct socket *so, struct mbuf |
|
Line 1212 soreceive(struct socket *so, struct mbuf |
|
SBLASTRECORDCHK(&so->so_rcv, "soreceive uiomove"); |
SBLASTRECORDCHK(&so->so_rcv, "soreceive uiomove"); |
SBLASTMBUFCHK(&so->so_rcv, "soreceive uiomove"); |
SBLASTMBUFCHK(&so->so_rcv, "soreceive uiomove"); |
splx(s); |
splx(s); |
error = uiomove(mtod(m, caddr_t) + moff, (int)len, uio); |
error = uiomove(mtod(m, char *) + moff, (int)len, uio); |
s = splsoftnet(); |
s = splsoftnet(); |
if (error) { |
if (error) { |
/* |
/* |
Line 1390 sosetopt(struct socket *so, int level, i |
|
Line 1423 sosetopt(struct socket *so, int level, i |
|
{ |
{ |
int error; |
int error; |
struct mbuf *m; |
struct mbuf *m; |
|
struct linger *l; |
|
|
error = 0; |
error = 0; |
m = m0; |
m = m0; |
Line 1406 sosetopt(struct socket *so, int level, i |
|
Line 1440 sosetopt(struct socket *so, int level, i |
|
error = EINVAL; |
error = EINVAL; |
goto bad; |
goto bad; |
} |
} |
if (mtod(m, struct linger *)->l_linger < 0 || |
l = mtod(m, struct linger *); |
mtod(m, struct linger *)->l_linger > (INT_MAX / hz)) { |
if (l->l_linger < 0 || l->l_linger > USHRT_MAX || |
|
l->l_linger > (INT_MAX / hz)) { |
error = EDOM; |
error = EDOM; |
goto bad; |
goto bad; |
} |
} |
so->so_linger = mtod(m, struct linger *)->l_linger; |
so->so_linger = l->l_linger; |
/* fall thru... */ |
if (l->l_onoff) |
|
so->so_options |= SO_LINGER; |
|
else |
|
so->so_options &= ~SO_LINGER; |
|
break; |
|
|
case SO_DEBUG: |
case SO_DEBUG: |
case SO_KEEPALIVE: |
case SO_KEEPALIVE: |
Line 1552 sogetopt(struct socket *so, int level, i |
|
Line 1591 sogetopt(struct socket *so, int level, i |
|
case SO_LINGER: |
case SO_LINGER: |
m->m_len = sizeof(struct linger); |
m->m_len = sizeof(struct linger); |
mtod(m, struct linger *)->l_onoff = |
mtod(m, struct linger *)->l_onoff = |
so->so_options & SO_LINGER; |
(so->so_options & SO_LINGER) ? 1 : 0; |
mtod(m, struct linger *)->l_linger = so->so_linger; |
mtod(m, struct linger *)->l_linger = so->so_linger; |
break; |
break; |
|
|
Line 1565 sogetopt(struct socket *so, int level, i |
|
Line 1604 sogetopt(struct socket *so, int level, i |
|
case SO_BROADCAST: |
case SO_BROADCAST: |
case SO_OOBINLINE: |
case SO_OOBINLINE: |
case SO_TIMESTAMP: |
case SO_TIMESTAMP: |
*mtod(m, int *) = so->so_options & optname; |
*mtod(m, int *) = (so->so_options & optname) ? 1 : 0; |
break; |
break; |
|
|
case SO_TYPE: |
case SO_TYPE: |