| version 1.134.2.6, 2007/10/09 13:44:32 |
version 1.135, 2007/03/12 18:18:34 |
|
|
| /* $NetBSD$ */ |
/* $NetBSD$ */ |
| |
|
| /*- |
/*- |
| * Copyright (c) 2002, 2007 The NetBSD Foundation, Inc. |
* Copyright (c) 2002 The NetBSD Foundation, Inc. |
| * All rights reserved. |
* All rights reserved. |
| * |
* |
| * This code is derived from software contributed to The NetBSD Foundation |
* This code is derived from software contributed to The NetBSD Foundation |
| Line 79 __KERNEL_RCSID(0, "$NetBSD$"); |
|
| Line 79 __KERNEL_RCSID(0, "$NetBSD$"); |
|
| #include <sys/systm.h> |
#include <sys/systm.h> |
| #include <sys/proc.h> |
#include <sys/proc.h> |
| #include <sys/file.h> |
#include <sys/file.h> |
| #include <sys/filedesc.h> |
|
| #include <sys/malloc.h> |
#include <sys/malloc.h> |
| #include <sys/mbuf.h> |
#include <sys/mbuf.h> |
| #include <sys/domain.h> |
#include <sys/domain.h> |
| Line 93 __KERNEL_RCSID(0, "$NetBSD$"); |
|
| Line 92 __KERNEL_RCSID(0, "$NetBSD$"); |
|
| #include <sys/event.h> |
#include <sys/event.h> |
| #include <sys/poll.h> |
#include <sys/poll.h> |
| #include <sys/kauth.h> |
#include <sys/kauth.h> |
| #include <sys/mutex.h> |
|
| #include <sys/condvar.h> |
|
| |
|
| #include <uvm/uvm.h> |
#include <uvm/uvm.h> |
| |
|
| Line 104 POOL_INIT(socket_pool, sizeof(struct soc |
|
| Line 101 POOL_INIT(socket_pool, sizeof(struct soc |
|
| MALLOC_DEFINE(M_SOOPTS, "soopts", "socket options"); |
MALLOC_DEFINE(M_SOOPTS, "soopts", "socket options"); |
| MALLOC_DEFINE(M_SONAME, "soname", "socket name"); |
MALLOC_DEFINE(M_SONAME, "soname", "socket name"); |
| |
|
| extern const struct fileops socketops; |
|
| |
|
| extern int somaxconn; /* patchable (XXX sysctl) */ |
extern int somaxconn; /* patchable (XXX sysctl) */ |
| int somaxconn = SOMAXCONN; |
int somaxconn = SOMAXCONN; |
| |
|
| Line 141 int sock_loan_thresh = -1; |
|
| Line 136 int sock_loan_thresh = -1; |
|
| int sock_loan_thresh = 4096; |
int sock_loan_thresh = 4096; |
| #endif |
#endif |
| |
|
| static kmutex_t so_pendfree_lock; |
static struct simplelock so_pendfree_slock = SIMPLELOCK_INITIALIZER; |
| static struct mbuf *so_pendfree; |
static struct mbuf *so_pendfree; |
| |
|
| #ifndef SOMAXKVA |
#ifndef SOMAXKVA |
| Line 149 static struct mbuf *so_pendfree; |
|
| Line 144 static struct mbuf *so_pendfree; |
|
| #endif |
#endif |
| int somaxkva = SOMAXKVA; |
int somaxkva = SOMAXKVA; |
| static int socurkva; |
static int socurkva; |
| static kcondvar_t socurkva_cv; |
static int sokvawaiters; |
| |
|
| #define SOCK_LOAN_CHUNK 65536 |
#define SOCK_LOAN_CHUNK 65536 |
| |
|
| Line 159 static size_t sodopendfreel(void); |
|
| Line 154 static size_t sodopendfreel(void); |
|
| static vsize_t |
static vsize_t |
| sokvareserve(struct socket *so, vsize_t len) |
sokvareserve(struct socket *so, vsize_t len) |
| { |
{ |
| |
int s; |
| int error; |
int error; |
| |
|
| mutex_enter(&so_pendfree_lock); |
s = splvm(); |
| |
simple_lock(&so_pendfree_slock); |
| while (socurkva + len > somaxkva) { |
while (socurkva + len > somaxkva) { |
| size_t freed; |
size_t freed; |
| |
|
| Line 179 sokvareserve(struct socket *so, vsize_t |
|
| Line 176 sokvareserve(struct socket *so, vsize_t |
|
| continue; |
continue; |
| |
|
| SOSEND_COUNTER_INCR(&sosend_kvalimit); |
SOSEND_COUNTER_INCR(&sosend_kvalimit); |
| error = cv_wait_sig(&socurkva_cv, &so_pendfree_lock); |
sokvawaiters++; |
| |
error = ltsleep(&socurkva, PVM | PCATCH, "sokva", 0, |
| |
&so_pendfree_slock); |
| |
sokvawaiters--; |
| if (error) { |
if (error) { |
| len = 0; |
len = 0; |
| break; |
break; |
| } |
} |
| } |
} |
| socurkva += len; |
socurkva += len; |
| mutex_exit(&so_pendfree_lock); |
simple_unlock(&so_pendfree_slock); |
| |
splx(s); |
| return len; |
return len; |
| } |
} |
| |
|
| static void |
static void |
| sokvaunreserve(vsize_t len) |
sokvaunreserve(vsize_t len) |
| { |
{ |
| |
int s; |
| |
|
| mutex_enter(&so_pendfree_lock); |
s = splvm(); |
| |
simple_lock(&so_pendfree_slock); |
| socurkva -= len; |
socurkva -= len; |
| cv_broadcast(&socurkva_cv); |
if (sokvawaiters) |
| mutex_exit(&so_pendfree_lock); |
wakeup(&socurkva); |
| |
simple_unlock(&so_pendfree_slock); |
| |
splx(s); |
| } |
} |
| |
|
| /* |
/* |
| Line 282 sodoloanfree(struct vm_page **pgs, void |
|
| Line 287 sodoloanfree(struct vm_page **pgs, void |
|
| static size_t |
static size_t |
| sodopendfree() |
sodopendfree() |
| { |
{ |
| |
int s; |
| size_t rv; |
size_t rv; |
| |
|
| mutex_enter(&so_pendfree_lock); |
s = splvm(); |
| |
simple_lock(&so_pendfree_slock); |
| rv = sodopendfreel(); |
rv = sodopendfreel(); |
| mutex_exit(&so_pendfree_lock); |
simple_unlock(&so_pendfree_slock); |
| |
splx(s); |
| |
|
| return rv; |
return rv; |
| } |
} |
| |
|
| /* |
/* |
| * sodopendfreel: free mbufs on "pendfree" list. |
* sodopendfreel: free mbufs on "pendfree" list. |
| * unlock and relock so_pendfree_lock when freeing mbufs. |
* unlock and relock so_pendfree_slock when freeing mbufs. |
| * |
* |
| * => called with so_pendfree_lock held. |
* => called with so_pendfree_slock held. |
| |
* => called at splvm. |
| */ |
*/ |
| |
|
| static size_t |
static size_t |
| sodopendfreel() |
sodopendfreel() |
| { |
{ |
| struct mbuf *m, *next; |
|
| size_t rv = 0; |
size_t rv = 0; |
| |
|
| KASSERT(mutex_owned(&so_pendfree_lock)); |
LOCK_ASSERT(simple_lock_held(&so_pendfree_slock)); |
| |
|
| |
for (;;) { |
| |
struct mbuf *m; |
| |
struct mbuf *next; |
| |
|
| while (so_pendfree != NULL) { |
|
| m = so_pendfree; |
m = so_pendfree; |
| |
if (m == NULL) |
| |
break; |
| so_pendfree = NULL; |
so_pendfree = NULL; |
| mutex_exit(&so_pendfree_lock); |
simple_unlock(&so_pendfree_slock); |
| |
/* XXX splx */ |
| |
|
| for (; m != NULL; m = next) { |
for (; m != NULL; m = next) { |
| next = m->m_next; |
next = m->m_next; |
|
|
| sodoloanfree((m->m_flags & M_EXT_PAGES) ? |
sodoloanfree((m->m_flags & M_EXT_PAGES) ? |
| m->m_ext.ext_pgs : NULL, m->m_ext.ext_buf, |
m->m_ext.ext_pgs : NULL, m->m_ext.ext_buf, |
| m->m_ext.ext_size); |
m->m_ext.ext_size); |
| pool_cache_put(mb_cache, m); |
pool_cache_put(&mbpool_cache, m); |
| } |
} |
| |
|
| mutex_enter(&so_pendfree_lock); |
/* XXX splvm */ |
| |
simple_lock(&so_pendfree_slock); |
| } |
} |
| |
|
| return (rv); |
return (rv); |
|
|
| void |
void |
| soloanfree(struct mbuf *m, void *buf, size_t size, void *arg) |
soloanfree(struct mbuf *m, void *buf, size_t size, void *arg) |
| { |
{ |
| |
int s; |
| |
|
| if (m == NULL) { |
if (m == NULL) { |
| |
|
| Line 348 soloanfree(struct mbuf *m, void *buf, si |
|
| Line 364 soloanfree(struct mbuf *m, void *buf, si |
|
| * because we need to put kva back to kernel_map. |
* because we need to put kva back to kernel_map. |
| */ |
*/ |
| |
|
| mutex_enter(&so_pendfree_lock); |
s = splvm(); |
| |
simple_lock(&so_pendfree_slock); |
| m->m_next = so_pendfree; |
m->m_next = so_pendfree; |
| so_pendfree = m; |
so_pendfree = m; |
| cv_broadcast(&socurkva_cv); |
if (sokvawaiters) |
| mutex_exit(&so_pendfree_lock); |
wakeup(&socurkva); |
| |
simple_unlock(&so_pendfree_slock); |
| |
splx(s); |
| } |
} |
| |
|
| static long |
static long |
| Line 427 sokva_reclaim_callback(struct callback_e |
|
| Line 446 sokva_reclaim_callback(struct callback_e |
|
| return CALLBACK_CHAIN_CONTINUE; |
return CALLBACK_CHAIN_CONTINUE; |
| } |
} |
| |
|
| struct mbuf * |
|
| getsombuf(struct socket *so) |
|
| { |
|
| struct mbuf *m; |
|
| |
|
| m = m_get(M_WAIT, MT_SONAME); |
|
| MCLAIM(m, so->so_mowner); |
|
| return m; |
|
| } |
|
| |
|
| struct mbuf * |
|
| m_intopt(struct socket *so, int val) |
|
| { |
|
| struct mbuf *m; |
|
| |
|
| m = getsombuf(so); |
|
| m->m_len = sizeof(int); |
|
| *mtod(m, int *) = val; |
|
| return m; |
|
| } |
|
| |
|
| void |
void |
| soinit(void) |
soinit(void) |
| { |
{ |
| |
|
| mutex_init(&so_pendfree_lock, MUTEX_DRIVER, IPL_VM); |
|
| cv_init(&socurkva_cv, "sokva"); |
|
| |
|
| /* Set the initial adjusted socket buffer size. */ |
/* Set the initial adjusted socket buffer size. */ |
| if (sb_max_set(sb_max)) |
if (sb_max_set(sb_max)) |
| panic("bad initial sb_max value: %lu", sb_max); |
panic("bad initial sb_max value: %lu", sb_max); |
| Line 482 socreate(int dom, struct socket **aso, i |
|
| Line 477 socreate(int dom, struct socket **aso, i |
|
| error = kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET, |
error = kauth_authorize_network(l->l_cred, KAUTH_NETWORK_SOCKET, |
| KAUTH_REQ_NETWORK_SOCKET_OPEN, KAUTH_ARG(dom), KAUTH_ARG(type), |
KAUTH_REQ_NETWORK_SOCKET_OPEN, KAUTH_ARG(dom), KAUTH_ARG(type), |
| KAUTH_ARG(proto)); |
KAUTH_ARG(proto)); |
| if (error != 0) |
if (error) |
| return 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 == NULL) { |
if (prp == 0) { |
| /* no support for domain */ |
/* no support for domain */ |
| if (pffinddomain(dom) == 0) |
if (pffinddomain(dom) == 0) |
| return EAFNOSUPPORT; |
return (EAFNOSUPPORT); |
| /* no support for socket type */ |
/* no support for socket type */ |
| if (proto == 0 && type != 0) |
if (proto == 0 && type != 0) |
| return EPROTOTYPE; |
return (EPROTOTYPE); |
| return EPROTONOSUPPORT; |
return (EPROTONOSUPPORT); |
| } |
} |
| if (prp->pr_usrreq == NULL) |
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(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 516 socreate(int dom, struct socket **aso, i |
|
| Line 511 socreate(int dom, struct socket **aso, i |
|
| so->so_snd.sb_mowner = &prp->pr_domain->dom_mowner; |
so->so_snd.sb_mowner = &prp->pr_domain->dom_mowner; |
| so->so_mowner = &prp->pr_domain->dom_mowner; |
so->so_mowner = &prp->pr_domain->dom_mowner; |
| #endif |
#endif |
| selinit(&so->so_rcv.sb_sel); |
if (l != NULL) { |
| selinit(&so->so_snd.sb_sel); |
uid = kauth_cred_geteuid(l->l_cred); |
| uid = kauth_cred_geteuid(l->l_cred); |
} else { |
| |
uid = 0; |
| |
} |
| so->so_uidinfo = uid_find(uid); |
so->so_uidinfo = uid_find(uid); |
| error = (*prp->pr_usrreq)(so, PRU_ATTACH, NULL, |
error = (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0, |
| (struct mbuf *)(long)proto, NULL, l); |
(struct mbuf *)(long)proto, (struct mbuf *)0, l); |
| if (error != 0) { |
if (error) { |
| so->so_state |= SS_NOFDREF; |
so->so_state |= SS_NOFDREF; |
| sofree(so); |
sofree(so); |
| splx(s); |
splx(s); |
| return error; |
return (error); |
| } |
} |
| splx(s); |
splx(s); |
| *aso = so; |
*aso = so; |
| return 0; |
return (0); |
| } |
|
| |
|
| /* On success, write file descriptor to fdout and return zero. On |
|
| * failure, return non-zero; *fdout will be undefined. |
|
| */ |
|
| int |
|
| fsocreate(int domain, struct socket **sop, int type, int protocol, |
|
| struct lwp *l, int *fdout) |
|
| { |
|
| struct filedesc *fdp; |
|
| struct socket *so; |
|
| struct file *fp; |
|
| int fd, error; |
|
| |
|
| fdp = l->l_proc->p_fd; |
|
| /* falloc() will use the desciptor for us */ |
|
| if ((error = falloc(l, &fp, &fd)) != 0) |
|
| return (error); |
|
| fp->f_flag = FREAD|FWRITE; |
|
| fp->f_type = DTYPE_SOCKET; |
|
| fp->f_ops = &socketops; |
|
| error = socreate(domain, &so, type, protocol, l); |
|
| if (error != 0) { |
|
| FILE_UNUSE(fp, l); |
|
| fdremove(fdp, fd); |
|
| ffree(fp); |
|
| } else { |
|
| if (sop != NULL) |
|
| *sop = so; |
|
| fp->f_data = so; |
|
| FILE_SET_MATURE(fp); |
|
| FILE_UNUSE(fp, l); |
|
| *fdout = fd; |
|
| } |
|
| return error; |
|
| } |
} |
| |
|
| int |
int |
| Line 574 sobind(struct socket *so, struct mbuf *n |
|
| Line 536 sobind(struct socket *so, struct mbuf *n |
|
| int s, error; |
int s, error; |
| |
|
| s = splsoftnet(); |
s = splsoftnet(); |
| error = (*so->so_proto->pr_usrreq)(so, PRU_BIND, NULL, nam, NULL, l); |
error = (*so->so_proto->pr_usrreq)(so, PRU_BIND, (struct mbuf *)0, |
| |
nam, (struct mbuf *)0, l); |
| splx(s); |
splx(s); |
| return error; |
return (error); |
| } |
} |
| |
|
| int |
int |
| Line 585 solisten(struct socket *so, int backlog) |
|
| Line 548 solisten(struct socket *so, int backlog) |
|
| int s, error; |
int s, error; |
| |
|
| s = splsoftnet(); |
s = splsoftnet(); |
| error = (*so->so_proto->pr_usrreq)(so, PRU_LISTEN, NULL, |
error = (*so->so_proto->pr_usrreq)(so, PRU_LISTEN, (struct mbuf *)0, |
| NULL, NULL, NULL); |
(struct mbuf *)0, (struct mbuf *)0, (struct lwp *)0); |
| if (error != 0) { |
if (error) { |
| splx(s); |
splx(s); |
| return error; |
return (error); |
| } |
} |
| if (TAILQ_EMPTY(&so->so_q)) |
if (TAILQ_EMPTY(&so->so_q)) |
| so->so_options |= SO_ACCEPTCONN; |
so->so_options |= SO_ACCEPTCONN; |
| Line 597 solisten(struct socket *so, int backlog) |
|
| Line 560 solisten(struct socket *so, int backlog) |
|
| backlog = 0; |
backlog = 0; |
| so->so_qlimit = min(backlog, somaxconn); |
so->so_qlimit = min(backlog, somaxconn); |
| splx(s); |
splx(s); |
| return 0; |
return (0); |
| } |
} |
| |
|
| void |
void |
| Line 623 sofree(struct socket *so) |
|
| Line 586 sofree(struct socket *so) |
|
| RLIM_INFINITY); |
RLIM_INFINITY); |
| sbrelease(&so->so_snd, so); |
sbrelease(&so->so_snd, so); |
| sorflush(so); |
sorflush(so); |
| seldestroy(&so->so_rcv.sb_sel); |
|
| seldestroy(&so->so_snd.sb_sel); |
|
| pool_put(&socket_pool, so); |
pool_put(&socket_pool, so); |
| } |
} |
| |
|
| Line 675 soclose(struct socket *so) |
|
| Line 636 soclose(struct socket *so) |
|
| 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, |
| NULL, NULL, NULL, NULL); |
(struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0, |
| |
(struct lwp *)0); |
| if (error == 0) |
if (error == 0) |
| error = error2; |
error = error2; |
| } |
} |
| Line 694 soclose(struct socket *so) |
|
| Line 656 soclose(struct socket *so) |
|
| int |
int |
| soabort(struct socket *so) |
soabort(struct socket *so) |
| { |
{ |
| int error; |
|
| |
|
| KASSERT(so->so_head == NULL); |
return (*so->so_proto->pr_usrreq)(so, PRU_ABORT, (struct mbuf *)0, |
| error = (*so->so_proto->pr_usrreq)(so, PRU_ABORT, NULL, |
(struct mbuf *)0, (struct mbuf *)0, (struct lwp *)0); |
| NULL, NULL, NULL); |
|
| if (error) { |
|
| sofree(so); |
|
| } |
|
| return error; |
|
| } |
} |
| |
|
| int |
int |
| Line 718 soaccept(struct socket *so, struct mbuf |
|
| Line 674 soaccept(struct socket *so, struct mbuf |
|
| if ((so->so_state & SS_ISDISCONNECTED) == 0 || |
if ((so->so_state & SS_ISDISCONNECTED) == 0 || |
| (so->so_proto->pr_flags & PR_ABRTACPTDIS) == 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, |
| NULL, nam, NULL, NULL); |
(struct mbuf *)0, nam, (struct mbuf *)0, (struct lwp *)0); |
| else |
else |
| error = ECONNABORTED; |
error = ECONNABORTED; |
| |
|
| Line 746 soconnect(struct socket *so, struct mbuf |
|
| Line 702 soconnect(struct socket *so, struct mbuf |
|
| error = EISCONN; |
error = EISCONN; |
| else |
else |
| error = (*so->so_proto->pr_usrreq)(so, PRU_CONNECT, |
error = (*so->so_proto->pr_usrreq)(so, PRU_CONNECT, |
| NULL, nam, NULL, l); |
(struct mbuf *)0, nam, (struct mbuf *)0, l); |
| splx(s); |
splx(s); |
| return (error); |
return (error); |
| } |
} |
| Line 758 soconnect2(struct socket *so1, struct so |
|
| Line 714 soconnect2(struct socket *so1, struct so |
|
| |
|
| s = splsoftnet(); |
s = splsoftnet(); |
| error = (*so1->so_proto->pr_usrreq)(so1, PRU_CONNECT2, |
error = (*so1->so_proto->pr_usrreq)(so1, PRU_CONNECT2, |
| NULL, (struct mbuf *)so2, NULL, NULL); |
(struct mbuf *)0, (struct mbuf *)so2, (struct mbuf *)0, |
| |
(struct lwp *)0); |
| splx(s); |
splx(s); |
| return (error); |
return (error); |
| } |
} |
| Line 778 sodisconnect(struct socket *so) |
|
| Line 735 sodisconnect(struct socket *so) |
|
| goto bad; |
goto bad; |
| } |
} |
| error = (*so->so_proto->pr_usrreq)(so, PRU_DISCONNECT, |
error = (*so->so_proto->pr_usrreq)(so, PRU_DISCONNECT, |
| NULL, NULL, NULL, NULL); |
(struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0, |
| |
(struct lwp *)0); |
| bad: |
bad: |
| splx(s); |
splx(s); |
| sodopendfree(); |
sodopendfree(); |
| Line 891 sosend(struct socket *so, struct mbuf *a |
|
| Line 849 sosend(struct socket *so, struct mbuf *a |
|
| if (flags & MSG_EOR) |
if (flags & MSG_EOR) |
| top->m_flags |= M_EOR; |
top->m_flags |= M_EOR; |
| } else do { |
} else do { |
| if (top == NULL) { |
if (top == 0) { |
| m = m_gethdr(M_WAIT, MT_DATA); |
m = m_gethdr(M_WAIT, MT_DATA); |
| mlen = MHLEN; |
mlen = MHLEN; |
| m->m_pkthdr.len = 0; |
m->m_pkthdr.len = 0; |
| m->m_pkthdr.rcvif = NULL; |
m->m_pkthdr.rcvif = (struct ifnet *)0; |
| } else { |
} else { |
| m = m_get(M_WAIT, MT_DATA); |
m = m_get(M_WAIT, MT_DATA); |
| mlen = MLEN; |
mlen = MLEN; |
| Line 935 sosend(struct socket *so, struct mbuf *a |
|
| Line 893 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, void *), (int)len, uio); |
error = uiomove(mtod(m, void *), (int)len, |
| |
uio); |
| have_data: |
have_data: |
| resid = uio->uio_resid; |
resid = uio->uio_resid; |
| m->m_len = len; |
m->m_len = len; |
| *mp = m; |
*mp = m; |
| top->m_pkthdr.len += len; |
top->m_pkthdr.len += len; |
| if (error != 0) |
if (error) |
| goto release; |
goto release; |
| mp = &m->m_next; |
mp = &m->m_next; |
| if (resid <= 0) { |
if (resid <= 0) { |
| Line 970 sosend(struct socket *so, struct mbuf *a |
|
| Line 929 sosend(struct socket *so, struct mbuf *a |
|
| splx(s); |
splx(s); |
| |
|
| clen = 0; |
clen = 0; |
| control = NULL; |
control = 0; |
| top = NULL; |
top = 0; |
| mp = ⊤ |
mp = ⊤ |
| if (error != 0) |
if (error) |
| goto release; |
goto release; |
| } while (resid && space > 0); |
} while (resid && space > 0); |
| } while (resid); |
} while (resid); |
| Line 1020 soreceive(struct socket *so, struct mbuf |
|
| Line 979 soreceive(struct socket *so, struct mbuf |
|
| type = 0; |
type = 0; |
| orig_resid = uio->uio_resid; |
orig_resid = uio->uio_resid; |
| |
|
| if (paddr != NULL) |
if (paddr) |
| *paddr = NULL; |
*paddr = 0; |
| if (controlp != NULL) |
if (controlp) |
| *controlp = NULL; |
*controlp = 0; |
| if (flagsp != NULL) |
if (flagsp) |
| flags = *flagsp &~ MSG_EOR; |
flags = *flagsp &~ MSG_EOR; |
| else |
else |
| flags = 0; |
flags = 0; |
| Line 1035 soreceive(struct socket *so, struct mbuf |
|
| Line 994 soreceive(struct socket *so, struct mbuf |
|
| 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, |
| (struct mbuf *)(long)(flags & MSG_PEEK), NULL, l); |
(struct mbuf *)(long)(flags & MSG_PEEK), |
| |
(struct mbuf *)0, l); |
| if (error) |
if (error) |
| goto bad; |
goto bad; |
| do { |
do { |
| error = uiomove(mtod(m, void *), |
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 > 0 && error == 0 && m); |
} while (uio->uio_resid && error == 0 && m); |
| bad: |
bad: |
| if (m != NULL) |
if (m) |
| m_freem(m); |
m_freem(m); |
| return error; |
return (error); |
| } |
} |
| if (mp != NULL) |
if (mp) |
| *mp = NULL; |
*mp = (struct mbuf *)0; |
| if (so->so_state & SS_ISCONFIRMING && uio->uio_resid) |
if (so->so_state & SS_ISCONFIRMING && uio->uio_resid) |
| (*pr->pr_usrreq)(so, PRU_RCVD, NULL, NULL, NULL, l); |
(*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0, |
| |
(struct mbuf *)0, (struct mbuf *)0, l); |
| |
|
| 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(); |
| |
|
| m = so->so_rcv.sb_mb; |
m = so->so_rcv.sb_mb; |
| Line 1070 soreceive(struct socket *so, struct mbuf |
|
| Line 1031 soreceive(struct socket *so, struct mbuf |
|
| * we have to do the receive in sections, and thus risk returning |
* we have to do the receive in sections, and thus risk returning |
| * a short count if a timeout or signal occurs after we start. |
* a short count if a timeout or signal occurs after we start. |
| */ |
*/ |
| if (m == NULL || |
if (m == 0 || (((flags & MSG_DONTWAIT) == 0 && |
| ((flags & MSG_DONTWAIT) == 0 && |
so->so_rcv.sb_cc < uio->uio_resid) && |
| so->so_rcv.sb_cc < uio->uio_resid && |
(so->so_rcv.sb_cc < so->so_rcv.sb_lowat || |
| (so->so_rcv.sb_cc < so->so_rcv.sb_lowat || |
((flags & MSG_WAITALL) && uio->uio_resid <= so->so_rcv.sb_hiwat)) && |
| ((flags & MSG_WAITALL) && |
m->m_nextpkt == 0 && (pr->pr_flags & PR_ATOMIC) == 0)) { |
| uio->uio_resid <= so->so_rcv.sb_hiwat)) && |
|
| m->m_nextpkt == NULL && |
|
| (pr->pr_flags & PR_ATOMIC) == 0)) { |
|
| #ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
| if (m == NULL && so->so_rcv.sb_cc) |
if (m == 0 && so->so_rcv.sb_cc) |
| panic("receive 1"); |
panic("receive 1"); |
| #endif |
#endif |
| if (so->so_error) { |
if (so->so_error) { |
| if (m != NULL) |
if (m) |
| goto dontblock; |
goto dontblock; |
| error = so->so_error; |
error = so->so_error; |
| if ((flags & MSG_PEEK) == 0) |
if ((flags & MSG_PEEK) == 0) |
| Line 1091 soreceive(struct socket *so, struct mbuf |
|
| Line 1049 soreceive(struct socket *so, struct mbuf |
|
| goto release; |
goto release; |
| } |
} |
| if (so->so_state & SS_CANTRCVMORE) { |
if (so->so_state & SS_CANTRCVMORE) { |
| if (m != NULL) |
if (m) |
| goto dontblock; |
goto dontblock; |
| else |
else |
| goto release; |
goto release; |
| } |
} |
| for (; m != NULL; m = m->m_next) |
for (; m; m = m->m_next) |
| if (m->m_type == MT_OOBDATA || (m->m_flags & M_EOR)) { |
if (m->m_type == MT_OOBDATA || (m->m_flags & M_EOR)) { |
| m = so->so_rcv.sb_mb; |
m = so->so_rcv.sb_mb; |
| goto dontblock; |
goto dontblock; |
| Line 1117 soreceive(struct socket *so, struct mbuf |
|
| Line 1075 soreceive(struct socket *so, struct mbuf |
|
| sbunlock(&so->so_rcv); |
sbunlock(&so->so_rcv); |
| error = sbwait(&so->so_rcv); |
error = sbwait(&so->so_rcv); |
| splx(s); |
splx(s); |
| if (error != 0) |
if (error) |
| return error; |
return (error); |
| goto restart; |
goto restart; |
| } |
} |
| dontblock: |
dontblock: |
| Line 1127 soreceive(struct socket *so, struct mbuf |
|
| Line 1085 soreceive(struct socket *so, struct mbuf |
|
| * While we process the initial mbufs containing address and control |
* While we process the initial mbufs containing address and control |
| * info, we save a copy of m->m_nextpkt into nextrecord. |
* info, we save a copy of m->m_nextpkt into nextrecord. |
| */ |
*/ |
| if (l != NULL) |
if (l) |
| l->l_proc->p_stats->p_ru.ru_msgrcv++; |
l->l_proc->p_stats->p_ru.ru_msgrcv++; |
| KASSERT(m == so->so_rcv.sb_mb); |
KASSERT(m == so->so_rcv.sb_mb); |
| SBLASTRECORDCHK(&so->so_rcv, "soreceive 1"); |
SBLASTRECORDCHK(&so->so_rcv, "soreceive 1"); |
| Line 1146 soreceive(struct socket *so, struct mbuf |
|
| Line 1104 soreceive(struct socket *so, struct mbuf |
|
| } else { |
} else { |
| sbfree(&so->so_rcv, m); |
sbfree(&so->so_rcv, m); |
| mbuf_removed = 1; |
mbuf_removed = 1; |
| if (paddr != NULL) { |
if (paddr) { |
| *paddr = m; |
*paddr = m; |
| so->so_rcv.sb_mb = m->m_next; |
so->so_rcv.sb_mb = m->m_next; |
| m->m_next = NULL; |
m->m_next = 0; |
| m = so->so_rcv.sb_mb; |
m = so->so_rcv.sb_mb; |
| } else { |
} else { |
| MFREE(m, so->so_rcv.sb_mb); |
MFREE(m, so->so_rcv.sb_mb); |
| Line 1157 soreceive(struct socket *so, struct mbuf |
|
| Line 1115 soreceive(struct socket *so, struct mbuf |
|
| } |
} |
| } |
} |
| } |
} |
| while (m != NULL && m->m_type == MT_CONTROL && error == 0) { |
while (m && m->m_type == MT_CONTROL && error == 0) { |
| if (flags & MSG_PEEK) { |
if (flags & MSG_PEEK) { |
| if (controlp != NULL) |
if (controlp) |
| *controlp = m_copy(m, 0, m->m_len); |
*controlp = m_copy(m, 0, m->m_len); |
| m = m->m_next; |
m = m->m_next; |
| } else { |
} else { |
| sbfree(&so->so_rcv, m); |
sbfree(&so->so_rcv, m); |
| mbuf_removed = 1; |
mbuf_removed = 1; |
| if (controlp != NULL) { |
if (controlp) { |
| struct domain *dom = pr->pr_domain; |
struct domain *dom = pr->pr_domain; |
| if (dom->dom_externalize && l && |
if (dom->dom_externalize && l && |
| mtod(m, struct cmsghdr *)->cmsg_type == |
mtod(m, struct cmsghdr *)->cmsg_type == |
| Line 1173 soreceive(struct socket *so, struct mbuf |
|
| Line 1131 soreceive(struct socket *so, struct mbuf |
|
| error = (*dom->dom_externalize)(m, l); |
error = (*dom->dom_externalize)(m, l); |
| *controlp = m; |
*controlp = m; |
| so->so_rcv.sb_mb = m->m_next; |
so->so_rcv.sb_mb = m->m_next; |
| m->m_next = NULL; |
m->m_next = 0; |
| m = so->so_rcv.sb_mb; |
m = so->so_rcv.sb_mb; |
| } else { |
} else { |
| /* |
/* |
| Line 1187 soreceive(struct socket *so, struct mbuf |
|
| Line 1145 soreceive(struct socket *so, struct mbuf |
|
| m = so->so_rcv.sb_mb; |
m = so->so_rcv.sb_mb; |
| } |
} |
| } |
} |
| if (controlp != NULL) { |
if (controlp) { |
| orig_resid = 0; |
orig_resid = 0; |
| controlp = &(*controlp)->m_next; |
controlp = &(*controlp)->m_next; |
| } |
} |
| Line 1199 soreceive(struct socket *so, struct mbuf |
|
| Line 1157 soreceive(struct socket *so, struct mbuf |
|
| * the last packet on the chain (nextrecord == NULL) and we |
* the last packet on the chain (nextrecord == NULL) and we |
| * change m->m_nextpkt. |
* change m->m_nextpkt. |
| */ |
*/ |
| if (m != NULL) { |
if (m) { |
| if ((flags & MSG_PEEK) == 0) { |
if ((flags & MSG_PEEK) == 0) { |
| m->m_nextpkt = nextrecord; |
m->m_nextpkt = nextrecord; |
| /* |
/* |
| Line 1227 soreceive(struct socket *so, struct mbuf |
|
| Line 1185 soreceive(struct socket *so, struct mbuf |
|
| |
|
| moff = 0; |
moff = 0; |
| offset = 0; |
offset = 0; |
| while (m != NULL && uio->uio_resid > 0 && error == 0) { |
while (m && uio->uio_resid > 0 && error == 0) { |
| if (m->m_type == MT_OOBDATA) { |
if (m->m_type == MT_OOBDATA) { |
| if (type != MT_OOBDATA) |
if (type != MT_OOBDATA) |
| break; |
break; |
| Line 1251 soreceive(struct socket *so, struct mbuf |
|
| Line 1209 soreceive(struct socket *so, struct mbuf |
|
| * we must note any additions to the sockbuf when we |
* we must note any additions to the sockbuf when we |
| * block interrupts again. |
* block interrupts again. |
| */ |
*/ |
| if (mp == NULL) { |
if (mp == 0) { |
| 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, char *) + moff, (int)len, uio); |
error = uiomove(mtod(m, char *) + moff, (int)len, uio); |
| s = splsoftnet(); |
s = splsoftnet(); |
| if (error != 0) { |
if (error) { |
| /* |
/* |
| * If any part of the record has been removed |
* If any part of the record has been removed |
| * (such as the MT_SONAME mbuf, which will |
* (such as the MT_SONAME mbuf, which will |
| Line 1290 soreceive(struct socket *so, struct mbuf |
|
| Line 1248 soreceive(struct socket *so, struct mbuf |
|
| *mp = m; |
*mp = m; |
| mp = &m->m_next; |
mp = &m->m_next; |
| so->so_rcv.sb_mb = m = m->m_next; |
so->so_rcv.sb_mb = m = m->m_next; |
| *mp = NULL; |
*mp = (struct mbuf *)0; |
| } else { |
} else { |
| MFREE(m, so->so_rcv.sb_mb); |
MFREE(m, so->so_rcv.sb_mb); |
| m = so->so_rcv.sb_mb; |
m = so->so_rcv.sb_mb; |
| Line 1311 soreceive(struct socket *so, struct mbuf |
|
| Line 1269 soreceive(struct socket *so, struct mbuf |
|
| SBLASTRECORDCHK(&so->so_rcv, "soreceive 3"); |
SBLASTRECORDCHK(&so->so_rcv, "soreceive 3"); |
| SBLASTMBUFCHK(&so->so_rcv, "soreceive 3"); |
SBLASTMBUFCHK(&so->so_rcv, "soreceive 3"); |
| } |
} |
| } else if (flags & MSG_PEEK) |
} else { |
| moff += len; |
if (flags & MSG_PEEK) |
| else { |
moff += len; |
| if (mp != NULL) |
else { |
| *mp = m_copym(m, 0, len, M_WAIT); |
if (mp) |
| m->m_data += len; |
*mp = m_copym(m, 0, len, M_WAIT); |
| m->m_len -= len; |
m->m_data += len; |
| so->so_rcv.sb_cc -= len; |
m->m_len -= len; |
| |
so->so_rcv.sb_cc -= len; |
| |
} |
| } |
} |
| if (so->so_oobmark) { |
if (so->so_oobmark) { |
| if ((flags & MSG_PEEK) == 0) { |
if ((flags & MSG_PEEK) == 0) { |
| Line 1342 soreceive(struct socket *so, struct mbuf |
|
| Line 1302 soreceive(struct socket *so, struct mbuf |
|
| * with a short count but without error. |
* with a short count but without error. |
| * Keep sockbuf locked against other readers. |
* Keep sockbuf locked against other readers. |
| */ |
*/ |
| while (flags & MSG_WAITALL && m == NULL && uio->uio_resid > 0 && |
while (flags & MSG_WAITALL && m == 0 && uio->uio_resid > 0 && |
| !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; |
| Line 1359 soreceive(struct socket *so, struct mbuf |
|
| Line 1319 soreceive(struct socket *so, struct mbuf |
|
| */ |
*/ |
| if ((pr->pr_flags & PR_WANTRCVD) && so->so_pcb) |
if ((pr->pr_flags & PR_WANTRCVD) && so->so_pcb) |
| (*pr->pr_usrreq)(so, PRU_RCVD, |
(*pr->pr_usrreq)(so, PRU_RCVD, |
| NULL, (struct mbuf *)(long)flags, NULL, l); |
(struct mbuf *)0, |
| |
(struct mbuf *)(long)flags, |
| |
(struct mbuf *)0, l); |
| SBLASTRECORDCHK(&so->so_rcv, "soreceive sbwait 2"); |
SBLASTRECORDCHK(&so->so_rcv, "soreceive sbwait 2"); |
| SBLASTMBUFCHK(&so->so_rcv, "soreceive sbwait 2"); |
SBLASTMBUFCHK(&so->so_rcv, "soreceive sbwait 2"); |
| error = sbwait(&so->so_rcv); |
error = sbwait(&so->so_rcv); |
| if (error != 0) { |
if (error) { |
| sbunlock(&so->so_rcv); |
sbunlock(&so->so_rcv); |
| splx(s); |
splx(s); |
| return 0; |
return (0); |
| } |
} |
| if ((m = so->so_rcv.sb_mb) != NULL) |
if ((m = so->so_rcv.sb_mb) != NULL) |
| nextrecord = m->m_nextpkt; |
nextrecord = m->m_nextpkt; |
| Line 1379 soreceive(struct socket *so, struct mbuf |
|
| Line 1341 soreceive(struct socket *so, struct mbuf |
|
| (void) sbdroprecord(&so->so_rcv); |
(void) sbdroprecord(&so->so_rcv); |
| } |
} |
| if ((flags & MSG_PEEK) == 0) { |
if ((flags & MSG_PEEK) == 0) { |
| if (m == NULL) { |
if (m == 0) { |
| /* |
/* |
| * First part is an inline SB_EMPTY_FIXUP(). Second |
* First part is an inline SB_EMPTY_FIXUP(). Second |
| * part makes sure sb_lastrecord is up-to-date if |
* part makes sure sb_lastrecord is up-to-date if |
| Line 1395 soreceive(struct socket *so, struct mbuf |
|
| Line 1357 soreceive(struct socket *so, struct mbuf |
|
| SBLASTRECORDCHK(&so->so_rcv, "soreceive 4"); |
SBLASTRECORDCHK(&so->so_rcv, "soreceive 4"); |
| SBLASTMBUFCHK(&so->so_rcv, "soreceive 4"); |
SBLASTMBUFCHK(&so->so_rcv, "soreceive 4"); |
| if (pr->pr_flags & PR_WANTRCVD && so->so_pcb) |
if (pr->pr_flags & PR_WANTRCVD && so->so_pcb) |
| (*pr->pr_usrreq)(so, PRU_RCVD, NULL, |
(*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0, |
| (struct mbuf *)(long)flags, NULL, l); |
(struct mbuf *)(long)flags, (struct mbuf *)0, l); |
| } |
} |
| if (orig_resid == uio->uio_resid && orig_resid && |
if (orig_resid == uio->uio_resid && orig_resid && |
| (flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) { |
(flags & MSG_EOR) == 0 && (so->so_state & SS_CANTRCVMORE) == 0) { |
| Line 1405 soreceive(struct socket *so, struct mbuf |
|
| Line 1367 soreceive(struct socket *so, struct mbuf |
|
| goto restart; |
goto restart; |
| } |
} |
| |
|
| if (flagsp != NULL) |
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 |
| Line 1425 soshutdown(struct socket *so, int how) |
|
| Line 1387 soshutdown(struct socket *so, int how) |
|
| if (how == SHUT_RD || how == SHUT_RDWR) |
if (how == SHUT_RD || how == SHUT_RDWR) |
| sorflush(so); |
sorflush(so); |
| if (how == SHUT_WR || how == SHUT_RDWR) |
if (how == SHUT_WR || how == SHUT_RDWR) |
| return (*pr->pr_usrreq)(so, PRU_SHUTDOWN, NULL, |
return (*pr->pr_usrreq)(so, PRU_SHUTDOWN, (struct mbuf *)0, |
| NULL, NULL, NULL); |
(struct mbuf *)0, (struct mbuf *)0, (struct lwp *)0); |
| return 0; |
return (0); |
| } |
} |
| |
|
| void |
void |
| Line 1457 sorflush(struct socket *so) |
|
| Line 1419 sorflush(struct socket *so) |
|
| sbrelease(&asb, so); |
sbrelease(&asb, so); |
| } |
} |
| |
|
| static int |
int |
| sosetopt1(struct socket *so, int level, int optname, struct mbuf *m) |
sosetopt(struct socket *so, int level, int optname, struct mbuf *m0) |
| { |
{ |
| int optval, val; |
int error; |
| |
struct mbuf *m; |
| struct linger *l; |
struct linger *l; |
| struct sockbuf *sb; |
|
| struct timeval *tv; |
|
| |
|
| switch (optname) { |
error = 0; |
| |
m = m0; |
| case SO_LINGER: |
if (level != SOL_SOCKET) { |
| if (m == NULL || m->m_len != sizeof(struct linger)) |
if (so->so_proto && so->so_proto->pr_ctloutput) |
| return EINVAL; |
return ((*so->so_proto->pr_ctloutput) |
| l = mtod(m, struct linger *); |
(PRCO_SETOPT, so, level, optname, &m0)); |
| if (l->l_linger < 0 || l->l_linger > USHRT_MAX || |
error = ENOPROTOOPT; |
| l->l_linger > (INT_MAX / hz)) |
} else { |
| return EDOM; |
switch (optname) { |
| so->so_linger = l->l_linger; |
|
| if (l->l_onoff) |
|
| so->so_options |= SO_LINGER; |
|
| else |
|
| so->so_options &= ~SO_LINGER; |
|
| break; |
|
| |
|
| case SO_DEBUG: |
|
| case SO_KEEPALIVE: |
|
| case SO_DONTROUTE: |
|
| case SO_USELOOPBACK: |
|
| case SO_BROADCAST: |
|
| case SO_REUSEADDR: |
|
| case SO_REUSEPORT: |
|
| case SO_OOBINLINE: |
|
| case SO_TIMESTAMP: |
|
| if (m == NULL || m->m_len < sizeof(int)) |
|
| return EINVAL; |
|
| if (*mtod(m, int *)) |
|
| so->so_options |= optname; |
|
| else |
|
| so->so_options &= ~optname; |
|
| break; |
|
| |
|
| case SO_SNDBUF: |
|
| case SO_RCVBUF: |
|
| case SO_SNDLOWAT: |
|
| case SO_RCVLOWAT: |
|
| if (m == NULL || m->m_len < sizeof(int)) |
|
| return EINVAL; |
|
| |
|
| /* |
case SO_LINGER: |
| * Values < 1 make no sense for any of these |
if (m == NULL || m->m_len != sizeof(struct linger)) { |
| * options, so disallow them. |
error = EINVAL; |
| */ |
goto bad; |
| optval = *mtod(m, int *); |
} |
| if (optval < 1) |
l = mtod(m, struct linger *); |
| return EINVAL; |
if (l->l_linger < 0 || l->l_linger > USHRT_MAX || |
| |
l->l_linger > (INT_MAX / hz)) { |
| |
error = EDOM; |
| |
goto bad; |
| |
} |
| |
so->so_linger = l->l_linger; |
| |
if (l->l_onoff) |
| |
so->so_options |= SO_LINGER; |
| |
else |
| |
so->so_options &= ~SO_LINGER; |
| |
break; |
| |
|
| switch (optname) { |
case SO_DEBUG: |
| |
case SO_KEEPALIVE: |
| |
case SO_DONTROUTE: |
| |
case SO_USELOOPBACK: |
| |
case SO_BROADCAST: |
| |
case SO_REUSEADDR: |
| |
case SO_REUSEPORT: |
| |
case SO_OOBINLINE: |
| |
case SO_TIMESTAMP: |
| |
if (m == NULL || m->m_len < sizeof(int)) { |
| |
error = EINVAL; |
| |
goto bad; |
| |
} |
| |
if (*mtod(m, int *)) |
| |
so->so_options |= optname; |
| |
else |
| |
so->so_options &= ~optname; |
| |
break; |
| |
|
| case SO_SNDBUF: |
case SO_SNDBUF: |
| case SO_RCVBUF: |
case SO_RCVBUF: |
| sb = (optname == SO_SNDBUF) ? |
|
| &so->so_snd : &so->so_rcv; |
|
| if (sbreserve(sb, (u_long)optval, so) == 0) |
|
| return ENOBUFS; |
|
| sb->sb_flags &= ~SB_AUTOSIZE; |
|
| break; |
|
| |
|
| /* |
|
| * Make sure the low-water is never greater than |
|
| * the high-water. |
|
| */ |
|
| case SO_SNDLOWAT: |
case SO_SNDLOWAT: |
| so->so_snd.sb_lowat = |
|
| (optval > so->so_snd.sb_hiwat) ? |
|
| so->so_snd.sb_hiwat : optval; |
|
| break; |
|
| case SO_RCVLOWAT: |
case SO_RCVLOWAT: |
| so->so_rcv.sb_lowat = |
{ |
| (optval > so->so_rcv.sb_hiwat) ? |
int optval; |
| so->so_rcv.sb_hiwat : optval; |
|
| break; |
|
| } |
|
| break; |
|
| |
|
| case SO_SNDTIMEO: |
if (m == NULL || m->m_len < sizeof(int)) { |
| case SO_RCVTIMEO: |
error = EINVAL; |
| if (m == NULL || m->m_len < sizeof(*tv)) |
goto bad; |
| return EINVAL; |
} |
| tv = mtod(m, struct timeval *); |
|
| if (tv->tv_sec > (INT_MAX - tv->tv_usec / tick) / hz) |
|
| return EDOM; |
|
| val = tv->tv_sec * hz + tv->tv_usec / tick; |
|
| if (val == 0 && tv->tv_usec != 0) |
|
| val = 1; |
|
| |
|
| switch (optname) { |
/* |
| |
* Values < 1 make no sense for any of these |
| |
* options, so disallow them. |
| |
*/ |
| |
optval = *mtod(m, int *); |
| |
if (optval < 1) { |
| |
error = EINVAL; |
| |
goto bad; |
| |
} |
| |
|
| case SO_SNDTIMEO: |
switch (optname) { |
| so->so_snd.sb_timeo = val; |
|
| |
case SO_SNDBUF: |
| |
case SO_RCVBUF: |
| |
if (sbreserve(optname == SO_SNDBUF ? |
| |
&so->so_snd : &so->so_rcv, |
| |
(u_long) optval, so) == 0) { |
| |
error = ENOBUFS; |
| |
goto bad; |
| |
} |
| |
break; |
| |
|
| |
/* |
| |
* Make sure the low-water is never greater than |
| |
* the high-water. |
| |
*/ |
| |
case SO_SNDLOWAT: |
| |
so->so_snd.sb_lowat = |
| |
(optval > so->so_snd.sb_hiwat) ? |
| |
so->so_snd.sb_hiwat : optval; |
| |
break; |
| |
case SO_RCVLOWAT: |
| |
so->so_rcv.sb_lowat = |
| |
(optval > so->so_rcv.sb_hiwat) ? |
| |
so->so_rcv.sb_hiwat : optval; |
| |
break; |
| |
} |
| break; |
break; |
| |
} |
| |
|
| |
case SO_SNDTIMEO: |
| case SO_RCVTIMEO: |
case SO_RCVTIMEO: |
| so->so_rcv.sb_timeo = val; |
{ |
| break; |
struct timeval *tv; |
| } |
int val; |
| break; |
|
| |
|
| default: |
if (m == NULL || m->m_len < sizeof(*tv)) { |
| return ENOPROTOOPT; |
error = EINVAL; |
| } |
goto bad; |
| return 0; |
} |
| } |
tv = mtod(m, struct timeval *); |
| |
if (tv->tv_sec > (INT_MAX - tv->tv_usec / tick) / hz) { |
| |
error = EDOM; |
| |
goto bad; |
| |
} |
| |
val = tv->tv_sec * hz + tv->tv_usec / tick; |
| |
if (val == 0 && tv->tv_usec != 0) |
| |
val = 1; |
| |
|
| int |
switch (optname) { |
| sosetopt(struct socket *so, int level, int optname, struct mbuf *m) |
|
| { |
|
| int error, prerr; |
|
| |
|
| if (level == SOL_SOCKET) |
case SO_SNDTIMEO: |
| error = sosetopt1(so, level, optname, m); |
so->so_snd.sb_timeo = val; |
| else |
break; |
| error = ENOPROTOOPT; |
case SO_RCVTIMEO: |
| |
so->so_rcv.sb_timeo = val; |
| |
break; |
| |
} |
| |
break; |
| |
} |
| |
|
| if ((error == 0 || error == ENOPROTOOPT) && |
default: |
| so->so_proto != NULL && so->so_proto->pr_ctloutput != NULL) { |
error = ENOPROTOOPT; |
| /* give the protocol stack a shot */ |
break; |
| prerr = (*so->so_proto->pr_ctloutput)(PRCO_SETOPT, so, level, |
} |
| optname, &m); |
if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) { |
| if (prerr == 0) |
(void) ((*so->so_proto->pr_ctloutput) |
| error = 0; |
(PRCO_SETOPT, so, level, optname, &m0)); |
| else if (prerr != ENOPROTOOPT) |
m = NULL; /* freed by protocol */ |
| error = prerr; |
} |
| } else if (m != NULL) |
} |
| (void)m_free(m); |
bad: |
| return error; |
if (m) |
| |
(void) m_free(m); |
| |
return (error); |
| } |
} |
| |
|
| int |
int |
| Line 1816 sysctl_kern_somaxkva(SYSCTLFN_ARGS) |
|
| Line 1795 sysctl_kern_somaxkva(SYSCTLFN_ARGS) |
|
| { |
{ |
| int error, new_somaxkva; |
int error, new_somaxkva; |
| struct sysctlnode node; |
struct sysctlnode node; |
| |
int s; |
| |
|
| new_somaxkva = somaxkva; |
new_somaxkva = somaxkva; |
| node = *rnode; |
node = *rnode; |
| Line 1827 sysctl_kern_somaxkva(SYSCTLFN_ARGS) |
|
| Line 1807 sysctl_kern_somaxkva(SYSCTLFN_ARGS) |
|
| if (new_somaxkva < (16 * 1024 * 1024)) /* sanity */ |
if (new_somaxkva < (16 * 1024 * 1024)) /* sanity */ |
| return (EINVAL); |
return (EINVAL); |
| |
|
| mutex_enter(&so_pendfree_lock); |
s = splvm(); |
| |
simple_lock(&so_pendfree_slock); |
| somaxkva = new_somaxkva; |
somaxkva = new_somaxkva; |
| cv_broadcast(&socurkva_cv); |
wakeup(&socurkva); |
| mutex_exit(&so_pendfree_lock); |
simple_unlock(&so_pendfree_slock); |
| |
splx(s); |
| |
|
| return (error); |
return (error); |
| } |
} |