version 1.141.2.2, 2007/11/08 11:00:10 |
version 1.155, 2008/03/21 21:55:00 |
|
|
/* $NetBSD$ */ |
/* $NetBSD$ */ |
|
|
/*- |
/*- |
* Copyright (c) 2002, 2007 The NetBSD Foundation, Inc. |
* Copyright (c) 2002, 2007, 2008 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 280 sodoloanfree(struct vm_page **pgs, void |
|
Line 280 sodoloanfree(struct vm_page **pgs, void |
|
} |
} |
|
|
static size_t |
static size_t |
sodopendfree() |
sodopendfree(void) |
{ |
{ |
size_t rv; |
size_t rv; |
|
|
|
|
*/ |
*/ |
|
|
static size_t |
static size_t |
sodopendfreel() |
sodopendfreel(void) |
{ |
{ |
struct mbuf *m, *next; |
struct mbuf *m, *next; |
size_t rv = 0; |
size_t rv = 0; |
Line 428 sokva_reclaim_callback(struct callback_e |
|
Line 428 sokva_reclaim_callback(struct callback_e |
|
} |
} |
|
|
struct mbuf * |
struct mbuf * |
getsombuf(struct socket *so) |
getsombuf(struct socket *so, int type) |
{ |
{ |
struct mbuf *m; |
struct mbuf *m; |
|
|
m = m_get(M_WAIT, MT_SONAME); |
m = m_get(M_WAIT, type); |
MCLAIM(m, so->so_mowner); |
MCLAIM(m, so->so_mowner); |
return m; |
return m; |
} |
} |
Line 442 m_intopt(struct socket *so, int val) |
|
Line 442 m_intopt(struct socket *so, int val) |
|
{ |
{ |
struct mbuf *m; |
struct mbuf *m; |
|
|
m = getsombuf(so); |
m = getsombuf(so, MT_SOOPTS); |
m->m_len = sizeof(int); |
m->m_len = sizeof(int); |
*mtod(m, int *) = val; |
*mtod(m, int *) = val; |
return m; |
return m; |
|
|
soinit(void) |
soinit(void) |
{ |
{ |
|
|
mutex_init(&so_pendfree_lock, MUTEX_DRIVER, IPL_VM); |
mutex_init(&so_pendfree_lock, MUTEX_DEFAULT, IPL_VM); |
cv_init(&socurkva_cv, "sokva"); |
cv_init(&socurkva_cv, "sokva"); |
|
|
/* Set the initial adjusted socket buffer size. */ |
/* Set the initial adjusted socket buffer size. */ |
|
|
fsocreate(int domain, struct socket **sop, int type, int protocol, |
fsocreate(int domain, struct socket **sop, int type, int protocol, |
struct lwp *l, int *fdout) |
struct lwp *l, int *fdout) |
{ |
{ |
struct filedesc *fdp; |
|
struct socket *so; |
struct socket *so; |
struct file *fp; |
struct file *fp; |
int fd, error; |
int fd, error; |
|
|
fdp = l->l_proc->p_fd; |
if ((error = fd_allocfile(&fp, &fd)) != 0) |
/* falloc() will use the desciptor for us */ |
|
if ((error = falloc(l, &fp, &fd)) != 0) |
|
return (error); |
return (error); |
fp->f_flag = FREAD|FWRITE; |
fp->f_flag = FREAD|FWRITE; |
fp->f_type = DTYPE_SOCKET; |
fp->f_type = DTYPE_SOCKET; |
fp->f_ops = &socketops; |
fp->f_ops = &socketops; |
error = socreate(domain, &so, type, protocol, l); |
error = socreate(domain, &so, type, protocol, l); |
if (error != 0) { |
if (error != 0) { |
FILE_UNUSE(fp, l); |
fd_abort(curproc, fp, fd); |
fdremove(fdp, fd); |
|
ffree(fp); |
|
} else { |
} else { |
if (sop != NULL) |
if (sop != NULL) |
*sop = so; |
*sop = so; |
fp->f_data = so; |
fp->f_data = so; |
FILE_SET_MATURE(fp); |
fd_affix(curproc, fp, fd); |
FILE_UNUSE(fp, l); |
|
*fdout = fd; |
*fdout = fd; |
} |
} |
return error; |
return error; |
Line 580 sobind(struct socket *so, struct mbuf *n |
|
Line 574 sobind(struct socket *so, struct mbuf *n |
|
} |
} |
|
|
int |
int |
solisten(struct socket *so, int backlog) |
solisten(struct socket *so, int backlog, struct lwp *l) |
{ |
{ |
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, NULL, |
NULL, NULL, NULL); |
NULL, NULL, l); |
if (error != 0) { |
if (error != 0) { |
splx(s); |
splx(s); |
return error; |
return error; |
Line 660 soclose(struct socket *so) |
|
Line 654 soclose(struct socket *so) |
|
goto drop; |
goto drop; |
} |
} |
if (so->so_options & SO_LINGER) { |
if (so->so_options & SO_LINGER) { |
if ((so->so_state & SS_ISDISCONNECTING) && |
if ((so->so_state & SS_ISDISCONNECTING) && so->so_nbio) |
(so->so_state & SS_NBIO)) |
|
goto drop; |
goto drop; |
while (so->so_state & SS_ISCONNECTED) { |
while (so->so_state & SS_ISCONNECTED) { |
error = tsleep((void *)&so->so_timeo, |
error = tsleep((void *)&so->so_timeo, |
Line 870 sosend(struct socket *so, struct mbuf *a |
|
Line 863 sosend(struct socket *so, struct mbuf *a |
|
snderr(EMSGSIZE); |
snderr(EMSGSIZE); |
if (space < resid + clen && |
if (space < resid + clen && |
(atomic || space < so->so_snd.sb_lowat || space < clen)) { |
(atomic || space < so->so_snd.sb_lowat || space < clen)) { |
if (so->so_state & SS_NBIO) |
if (so->so_nbio) |
snderr(EWOULDBLOCK); |
snderr(EWOULDBLOCK); |
sbunlock(&so->so_snd); |
sbunlock(&so->so_snd); |
error = sbwait(&so->so_snd); |
error = sbwait(&so->so_snd); |
Line 1010 soreceive(struct socket *so, struct mbuf |
|
Line 1003 soreceive(struct socket *so, struct mbuf |
|
{ |
{ |
struct lwp *l = curlwp; |
struct lwp *l = curlwp; |
struct mbuf *m, **mp; |
struct mbuf *m, **mp; |
int flags, len, error, s, offset, moff, type, orig_resid; |
int atomic, flags, len, error, s, offset, moff, type, orig_resid; |
const struct protosw *pr; |
const struct protosw *pr; |
struct mbuf *nextrecord; |
struct mbuf *nextrecord; |
int mbuf_removed = 0; |
int mbuf_removed = 0; |
|
const struct domain *dom; |
|
|
pr = so->so_proto; |
pr = so->so_proto; |
|
atomic = pr->pr_flags & PR_ATOMIC; |
|
dom = pr->pr_domain; |
mp = mp0; |
mp = mp0; |
type = 0; |
type = 0; |
orig_resid = uio->uio_resid; |
orig_resid = uio->uio_resid; |
Line 1076 soreceive(struct socket *so, struct mbuf |
|
Line 1072 soreceive(struct socket *so, struct mbuf |
|
(so->so_rcv.sb_cc < so->so_rcv.sb_lowat || |
(so->so_rcv.sb_cc < so->so_rcv.sb_lowat || |
((flags & MSG_WAITALL) && |
((flags & MSG_WAITALL) && |
uio->uio_resid <= so->so_rcv.sb_hiwat)) && |
uio->uio_resid <= so->so_rcv.sb_hiwat)) && |
m->m_nextpkt == NULL && |
m->m_nextpkt == NULL && !atomic)) { |
(pr->pr_flags & PR_ATOMIC) == 0)) { |
|
#ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
if (m == NULL && so->so_rcv.sb_cc) |
if (m == NULL && so->so_rcv.sb_cc) |
panic("receive 1"); |
panic("receive 1"); |
Line 1108 soreceive(struct socket *so, struct mbuf |
|
Line 1103 soreceive(struct socket *so, struct mbuf |
|
} |
} |
if (uio->uio_resid == 0) |
if (uio->uio_resid == 0) |
goto release; |
goto release; |
if ((so->so_state & SS_NBIO) || (flags & MSG_DONTWAIT)) { |
if (so->so_nbio || (flags & MSG_DONTWAIT)) { |
error = EWOULDBLOCK; |
error = EWOULDBLOCK; |
goto release; |
goto release; |
} |
} |
Line 1166 soreceive(struct socket *so, struct mbuf |
|
Line 1161 soreceive(struct socket *so, struct mbuf |
|
sbfree(&so->so_rcv, m); |
sbfree(&so->so_rcv, m); |
mbuf_removed = 1; |
mbuf_removed = 1; |
if (controlp != NULL) { |
if (controlp != NULL) { |
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 == |
SCM_RIGHTS) |
SCM_RIGHTS) |
Line 1180 soreceive(struct socket *so, struct mbuf |
|
Line 1174 soreceive(struct socket *so, struct mbuf |
|
* Dispose of any SCM_RIGHTS message that went |
* Dispose of any SCM_RIGHTS message that went |
* through the read path rather than recv. |
* through the read path rather than recv. |
*/ |
*/ |
if (pr->pr_domain->dom_dispose && |
if (dom->dom_dispose && |
mtod(m, struct cmsghdr *)->cmsg_type == SCM_RIGHTS) |
mtod(m, struct cmsghdr *)->cmsg_type == SCM_RIGHTS) |
(*pr->pr_domain->dom_dispose)(m); |
(*dom->dom_dispose)(m); |
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 1269 soreceive(struct socket *so, struct mbuf |
|
Line 1263 soreceive(struct socket *so, struct mbuf |
|
* This avoids a later panic("receive 1a") |
* This avoids a later panic("receive 1a") |
* when compiled with DIAGNOSTIC. |
* when compiled with DIAGNOSTIC. |
*/ |
*/ |
if (m && mbuf_removed |
if (m && mbuf_removed && atomic) |
&& (pr->pr_flags & PR_ATOMIC)) |
|
(void) sbdroprecord(&so->so_rcv); |
(void) sbdroprecord(&so->so_rcv); |
|
|
goto release; |
goto release; |
Line 1373 soreceive(struct socket *so, struct mbuf |
|
Line 1366 soreceive(struct socket *so, struct mbuf |
|
} |
} |
} |
} |
|
|
if (m && pr->pr_flags & PR_ATOMIC) { |
if (m && atomic) { |
flags |= MSG_TRUNC; |
flags |= MSG_TRUNC; |
if ((flags & MSG_PEEK) == 0) |
if ((flags & MSG_PEEK) == 0) |
(void) sbdroprecord(&so->so_rcv); |
(void) sbdroprecord(&so->so_rcv); |
Line 1683 sogetopt(struct socket *so, int level, i |
|
Line 1676 sogetopt(struct socket *so, int level, i |
|
void |
void |
sohasoutofband(struct socket *so) |
sohasoutofband(struct socket *so) |
{ |
{ |
|
|
fownsignal(so->so_pgid, SIGURG, POLL_PRI, POLLPRI|POLLRDBAND, so); |
fownsignal(so->so_pgid, SIGURG, POLL_PRI, POLLPRI|POLLRDBAND, so); |
selwakeup(&so->so_rcv.sb_sel); |
selnotify(&so->so_rcv.sb_sel, POLLPRI | POLLRDBAND, 0); |
} |
} |
|
|
static void |
static void |
Line 1692 filt_sordetach(struct knote *kn) |
|
Line 1686 filt_sordetach(struct knote *kn) |
|
{ |
{ |
struct socket *so; |
struct socket *so; |
|
|
so = (struct socket *)kn->kn_fp->f_data; |
so = ((file_t *)kn->kn_obj)->f_data; |
SLIST_REMOVE(&so->so_rcv.sb_sel.sel_klist, kn, knote, kn_selnext); |
SLIST_REMOVE(&so->so_rcv.sb_sel.sel_klist, kn, knote, kn_selnext); |
if (SLIST_EMPTY(&so->so_rcv.sb_sel.sel_klist)) |
if (SLIST_EMPTY(&so->so_rcv.sb_sel.sel_klist)) |
so->so_rcv.sb_flags &= ~SB_KNOTE; |
so->so_rcv.sb_flags &= ~SB_KNOTE; |
Line 1704 filt_soread(struct knote *kn, long hint) |
|
Line 1698 filt_soread(struct knote *kn, long hint) |
|
{ |
{ |
struct socket *so; |
struct socket *so; |
|
|
so = (struct socket *)kn->kn_fp->f_data; |
so = ((file_t *)kn->kn_obj)->f_data; |
kn->kn_data = so->so_rcv.sb_cc; |
kn->kn_data = so->so_rcv.sb_cc; |
if (so->so_state & SS_CANTRCVMORE) { |
if (so->so_state & SS_CANTRCVMORE) { |
kn->kn_flags |= EV_EOF; |
kn->kn_flags |= EV_EOF; |
Line 1723 filt_sowdetach(struct knote *kn) |
|
Line 1717 filt_sowdetach(struct knote *kn) |
|
{ |
{ |
struct socket *so; |
struct socket *so; |
|
|
so = (struct socket *)kn->kn_fp->f_data; |
so = ((file_t *)kn->kn_obj)->f_data; |
SLIST_REMOVE(&so->so_snd.sb_sel.sel_klist, kn, knote, kn_selnext); |
SLIST_REMOVE(&so->so_snd.sb_sel.sel_klist, kn, knote, kn_selnext); |
if (SLIST_EMPTY(&so->so_snd.sb_sel.sel_klist)) |
if (SLIST_EMPTY(&so->so_snd.sb_sel.sel_klist)) |
so->so_snd.sb_flags &= ~SB_KNOTE; |
so->so_snd.sb_flags &= ~SB_KNOTE; |
Line 1735 filt_sowrite(struct knote *kn, long hint |
|
Line 1729 filt_sowrite(struct knote *kn, long hint |
|
{ |
{ |
struct socket *so; |
struct socket *so; |
|
|
so = (struct socket *)kn->kn_fp->f_data; |
so = ((file_t *)kn->kn_obj)->f_data; |
kn->kn_data = sbspace(&so->so_snd); |
kn->kn_data = sbspace(&so->so_snd); |
if (so->so_state & SS_CANTSENDMORE) { |
if (so->so_state & SS_CANTSENDMORE) { |
kn->kn_flags |= EV_EOF; |
kn->kn_flags |= EV_EOF; |
Line 1758 filt_solisten(struct knote *kn, long hin |
|
Line 1752 filt_solisten(struct knote *kn, long hin |
|
{ |
{ |
struct socket *so; |
struct socket *so; |
|
|
so = (struct socket *)kn->kn_fp->f_data; |
so = ((file_t *)kn->kn_obj)->f_data; |
|
|
/* |
/* |
* Set kn_data to number of incoming connections, not |
* Set kn_data to number of incoming connections, not |
Line 1781 soo_kqfilter(struct file *fp, struct kno |
|
Line 1775 soo_kqfilter(struct file *fp, struct kno |
|
struct socket *so; |
struct socket *so; |
struct sockbuf *sb; |
struct sockbuf *sb; |
|
|
so = (struct socket *)kn->kn_fp->f_data; |
so = ((file_t *)kn->kn_obj)->f_data; |
switch (kn->kn_filter) { |
switch (kn->kn_filter) { |
case EVFILT_READ: |
case EVFILT_READ: |
if (so->so_options & SO_ACCEPTCONN) |
if (so->so_options & SO_ACCEPTCONN) |
Line 1795 soo_kqfilter(struct file *fp, struct kno |
|
Line 1789 soo_kqfilter(struct file *fp, struct kno |
|
sb = &so->so_snd; |
sb = &so->so_snd; |
break; |
break; |
default: |
default: |
return (1); |
return (EINVAL); |
} |
} |
SLIST_INSERT_HEAD(&sb->sb_sel.sel_klist, kn, kn_selnext); |
SLIST_INSERT_HEAD(&sb->sb_sel.sel_klist, kn, kn_selnext); |
sb->sb_flags |= SB_KNOTE; |
sb->sb_flags |= SB_KNOTE; |
return (0); |
return (0); |
} |
} |
|
|
|
static int |
|
sodopoll(struct socket *so, int events) |
|
{ |
|
int revents; |
|
|
|
revents = 0; |
|
|
|
if (events & (POLLIN | POLLRDNORM)) |
|
if (soreadable(so)) |
|
revents |= events & (POLLIN | POLLRDNORM); |
|
|
|
if (events & (POLLOUT | POLLWRNORM)) |
|
if (sowritable(so)) |
|
revents |= events & (POLLOUT | POLLWRNORM); |
|
|
|
if (events & (POLLPRI | POLLRDBAND)) |
|
if (so->so_oobmark || (so->so_state & SS_RCVATMARK)) |
|
revents |= events & (POLLPRI | POLLRDBAND); |
|
|
|
return revents; |
|
} |
|
|
|
int |
|
sopoll(struct socket *so, int events) |
|
{ |
|
int revents = 0; |
|
int s; |
|
|
|
if ((revents = sodopoll(so, events)) != 0) |
|
return revents; |
|
|
|
KERNEL_LOCK(1, curlwp); |
|
s = splsoftnet(); |
|
|
|
if ((revents = sodopoll(so, events)) == 0) { |
|
if (events & (POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND)) { |
|
selrecord(curlwp, &so->so_rcv.sb_sel); |
|
so->so_rcv.sb_flags |= SB_SEL; |
|
} |
|
|
|
if (events & (POLLOUT | POLLWRNORM)) { |
|
selrecord(curlwp, &so->so_snd.sb_sel); |
|
so->so_snd.sb_flags |= SB_SEL; |
|
} |
|
} |
|
|
|
splx(s); |
|
KERNEL_UNLOCK_ONE(curlwp); |
|
|
|
return revents; |
|
} |
|
|
|
|
#include <sys/sysctl.h> |
#include <sys/sysctl.h> |
|
|
static int sysctl_kern_somaxkva(SYSCTLFN_PROTO); |
static int sysctl_kern_somaxkva(SYSCTLFN_PROTO); |