version 1.41, 1999/01/20 09:15:41 |
version 1.48.2.1, 2000/11/20 18:09:14 |
|
|
|
|
struct pool socket_pool; |
struct pool socket_pool; |
|
|
|
extern int somaxconn; /* patchable (XXX sysctl) */ |
|
int somaxconn = SOMAXCONN; |
|
|
void |
void |
soinit() |
soinit() |
{ |
{ |
|
|
socreate(dom, aso, type, proto) |
socreate(dom, aso, type, proto) |
int dom; |
int dom; |
struct socket **aso; |
struct socket **aso; |
register int type; |
int type; |
int proto; |
int proto; |
{ |
{ |
struct proc *p = curproc; /* XXX */ |
struct proc *p = curproc; /* XXX */ |
register struct protosw *prp; |
struct protosw *prp; |
register struct socket *so; |
struct socket *so; |
register int error; |
int error; |
int s; |
int s; |
|
|
if (proto) |
if (proto) |
Line 100 socreate(dom, aso, type, proto) |
|
Line 103 socreate(dom, aso, type, proto) |
|
so->so_proto = prp; |
so->so_proto = prp; |
so->so_send = sosend; |
so->so_send = sosend; |
so->so_receive = soreceive; |
so->so_receive = soreceive; |
|
if (p != 0) |
|
so->so_uid = p->p_ucred->cr_uid; |
error = (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0, |
error = (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0, |
(struct mbuf *)(long)proto, (struct mbuf *)0, p); |
(struct mbuf *)(long)proto, (struct mbuf *)0, p); |
if (error) { |
if (error) { |
|
|
|
|
int |
int |
solisten(so, backlog) |
solisten(so, backlog) |
register struct socket *so; |
struct socket *so; |
int backlog; |
int backlog; |
{ |
{ |
int s = splsoftnet(), error; |
int s = splsoftnet(), error; |
Line 152 solisten(so, backlog) |
|
Line 157 solisten(so, backlog) |
|
so->so_options |= SO_ACCEPTCONN; |
so->so_options |= SO_ACCEPTCONN; |
if (backlog < 0) |
if (backlog < 0) |
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 |
sofree(so) |
sofree(so) |
register struct socket *so; |
struct socket *so; |
{ |
{ |
|
|
/* |
if (so->so_pcb || (so->so_state & SS_NOFDREF) == 0) |
* We must not decommission a socket that's on the accept(2) queue. |
|
* If we do, then accept(2) may hang even after select(2) indicated |
|
* that the listening socket was ready. |
|
*/ |
|
if (so->so_pcb || so->so_head || (so->so_state & SS_NOFDREF) == 0) |
|
return; |
return; |
|
if (so->so_head) { |
|
/* |
|
* We must not decommission a socket that's on the accept(2) |
|
* queue. If we do, then accept(2) may hang after select(2) |
|
* indicated that the listening socket was ready. |
|
*/ |
|
if (!soqremque(so, 0)) |
|
return; |
|
} |
sbrelease(&so->so_snd); |
sbrelease(&so->so_snd); |
sorflush(so); |
sorflush(so); |
pool_put(&socket_pool, so); |
pool_put(&socket_pool, so); |
|
|
*/ |
*/ |
int |
int |
soclose(so) |
soclose(so) |
register struct socket *so; |
struct socket *so; |
{ |
{ |
struct socket *so2; |
struct socket *so2; |
int s = splsoftnet(); /* conservative */ |
int 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 = so->so_q0.tqh_first) != 0) { |
so2->so_head = 0; |
(void) soqremque(so2, 0); |
(void) soabort(so2); |
(void) soabort(so2); |
} |
} |
while ((so2 = so->so_q.tqh_first) != 0) { |
while ((so2 = so->so_q.tqh_first) != 0) { |
so2->so_head = 0; |
(void) soqremque(so2, 1); |
(void) soabort(so2); |
(void) soabort(so2); |
} |
} |
} |
} |
|
|
|
|
int |
int |
soaccept(so, nam) |
soaccept(so, nam) |
register struct socket *so; |
struct socket *so; |
struct mbuf *nam; |
struct mbuf *nam; |
{ |
{ |
int s = splsoftnet(); |
int s = splsoftnet(); |
Line 269 soaccept(so, nam) |
|
Line 278 soaccept(so, nam) |
|
|
|
int |
int |
soconnect(so, nam) |
soconnect(so, nam) |
register struct socket *so; |
struct socket *so; |
struct mbuf *nam; |
struct mbuf *nam; |
{ |
{ |
struct proc *p = curproc; /* XXX */ |
struct proc *p = curproc; /* XXX */ |
Line 298 soconnect(so, nam) |
|
Line 307 soconnect(so, nam) |
|
|
|
int |
int |
soconnect2(so1, so2) |
soconnect2(so1, so2) |
register struct socket *so1; |
struct socket *so1; |
struct socket *so2; |
struct socket *so2; |
{ |
{ |
int s = splsoftnet(); |
int s = splsoftnet(); |
Line 313 soconnect2(so1, so2) |
|
Line 322 soconnect2(so1, so2) |
|
|
|
int |
int |
sodisconnect(so) |
sodisconnect(so) |
register struct socket *so; |
struct socket *so; |
{ |
{ |
int s = splsoftnet(); |
int s = splsoftnet(); |
int error; |
int error; |
|
|
*/ |
*/ |
int |
int |
sosend(so, addr, uio, top, control, flags) |
sosend(so, addr, uio, top, control, flags) |
register struct socket *so; |
struct socket *so; |
struct mbuf *addr; |
struct mbuf *addr; |
struct uio *uio; |
struct uio *uio; |
struct mbuf *top; |
struct mbuf *top; |
Line 363 sosend(so, addr, uio, top, control, flag |
|
Line 372 sosend(so, addr, uio, top, control, flag |
|
{ |
{ |
struct proc *p = curproc; /* XXX */ |
struct proc *p = curproc; /* XXX */ |
struct mbuf **mp; |
struct mbuf **mp; |
register struct mbuf *m; |
struct mbuf *m; |
register long space, len, resid; |
long space, len, resid; |
int clen = 0, error, s, dontroute, mlen; |
int clen = 0, error, s, dontroute, mlen; |
int atomic = sosendallatonce(so) || top; |
int atomic = sosendallatonce(so) || top; |
|
|
|
|
s = splsoftnet(); |
s = splsoftnet(); |
if (so->so_state & SS_CANTSENDMORE) |
if (so->so_state & SS_CANTSENDMORE) |
snderr(EPIPE); |
snderr(EPIPE); |
if (so->so_error) |
if (so->so_error) { |
snderr(so->so_error); |
error = so->so_error; |
|
so->so_error = 0; |
|
splx(s); |
|
goto release; |
|
} |
if ((so->so_state & SS_ISCONNECTED) == 0) { |
if ((so->so_state & SS_ISCONNECTED) == 0) { |
if (so->so_proto->pr_flags & PR_CONNREQUIRED) { |
if (so->so_proto->pr_flags & PR_CONNREQUIRED) { |
if ((so->so_state & SS_ISCONFIRMING) == 0 && |
if ((so->so_state & SS_ISCONFIRMING) == 0 && |
|
|
mp = ⊤ |
mp = ⊤ |
space -= clen; |
space -= clen; |
do { |
do { |
if (uio == NULL) { |
if (uio == NULL) { |
/* |
/* |
* Data is prepackaged in "top". |
* Data is prepackaged in "top". |
*/ |
*/ |
resid = 0; |
resid = 0; |
if (flags & MSG_EOR) |
if (flags & MSG_EOR) |
top->m_flags |= M_EOR; |
top->m_flags |= M_EOR; |
} else do { |
} else do { |
if (top == 0) { |
if (top == 0) { |
MGETHDR(m, M_WAIT, MT_DATA); |
MGETHDR(m, M_WAIT, MT_DATA); |
mlen = MHLEN; |
mlen = MHLEN; |
m->m_pkthdr.len = 0; |
m->m_pkthdr.len = 0; |
m->m_pkthdr.rcvif = (struct ifnet *)0; |
m->m_pkthdr.rcvif = (struct ifnet *)0; |
} else { |
} else { |
MGET(m, M_WAIT, MT_DATA); |
MGET(m, M_WAIT, MT_DATA); |
mlen = MLEN; |
mlen = MLEN; |
} |
} |
if (resid >= MINCLSIZE && space >= MCLBYTES) { |
if (resid >= MINCLSIZE && space >= MCLBYTES) { |
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 |
#ifdef MAPPED_MBUFS |
len = min(MCLBYTES, resid); |
|
#else |
|
if (atomic && top == 0) { |
|
len = min(MCLBYTES - max_hdr, resid); |
|
m->m_data += max_hdr; |
|
} else |
|
len = min(MCLBYTES, resid); |
len = min(MCLBYTES, resid); |
|
#else |
|
if (atomic && top == 0) { |
|
len = min(MCLBYTES - max_hdr, resid); |
|
m->m_data += max_hdr; |
|
} else |
|
len = min(MCLBYTES, resid); |
#endif |
#endif |
space -= len; |
space -= len; |
} else { |
} else { |
nopages: |
nopages: |
len = min(min(mlen, resid), space); |
len = min(min(mlen, resid), space); |
space -= len; |
space -= len; |
/* |
/* |
* For datagram protocols, leave room |
* For datagram protocols, leave room |
* for protocol headers in first mbuf. |
* for protocol headers in first mbuf. |
*/ |
*/ |
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); |
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) |
|
goto release; |
|
mp = &m->m_next; |
|
if (resid <= 0) { |
|
if (flags & MSG_EOR) |
|
top->m_flags |= M_EOR; |
|
break; |
|
} |
|
} while (space > 0 && atomic); |
|
|
|
s = splsoftnet(); |
|
|
|
if (so->so_state & SS_CANTSENDMORE) |
|
snderr(EPIPE); |
|
|
|
if (dontroute) |
|
so->so_options |= SO_DONTROUTE; |
|
if (resid > 0) |
|
so->so_state |= SS_MORETOCOME; |
|
error = (*so->so_proto->pr_usrreq)(so, |
|
(flags & MSG_OOB) ? PRU_SENDOOB : PRU_SEND, |
|
top, addr, control, p); |
|
if (dontroute) |
|
so->so_options &= ~SO_DONTROUTE; |
|
if (resid > 0) |
|
so->so_state &= ~SS_MORETOCOME; |
|
splx(s); |
|
|
|
clen = 0; |
|
control = 0; |
|
top = 0; |
|
mp = ⊤ |
if (error) |
if (error) |
goto release; |
goto release; |
mp = &m->m_next; |
|
if (resid <= 0) { |
|
if (flags & MSG_EOR) |
|
top->m_flags |= M_EOR; |
|
break; |
|
} |
|
} while (space > 0 && atomic); |
|
if (dontroute) |
|
so->so_options |= SO_DONTROUTE; |
|
if (resid > 0) |
|
so->so_state |= SS_MORETOCOME; |
|
s = splsoftnet(); /* XXX */ |
|
error = (*so->so_proto->pr_usrreq)(so, |
|
(flags & MSG_OOB) ? PRU_SENDOOB : PRU_SEND, |
|
top, addr, control, p); |
|
splx(s); |
|
if (dontroute) |
|
so->so_options &= ~SO_DONTROUTE; |
|
if (resid > 0) |
|
so->so_state &= ~SS_MORETOCOME; |
|
clen = 0; |
|
control = 0; |
|
top = 0; |
|
mp = ⊤ |
|
if (error) |
|
goto release; |
|
} while (resid && space > 0); |
} while (resid && space > 0); |
} while (resid); |
} while (resid); |
|
|
|
|
*/ |
*/ |
int |
int |
soreceive(so, paddr, uio, mp0, controlp, flagsp) |
soreceive(so, paddr, uio, mp0, controlp, flagsp) |
register struct socket *so; |
struct socket *so; |
struct mbuf **paddr; |
struct mbuf **paddr; |
struct uio *uio; |
struct uio *uio; |
struct mbuf **mp0; |
struct mbuf **mp0; |
struct mbuf **controlp; |
struct mbuf **controlp; |
int *flagsp; |
int *flagsp; |
{ |
{ |
register struct mbuf *m, **mp; |
struct mbuf *m, **mp; |
register int flags, len, error, s, offset; |
int flags, len, error, s, offset; |
struct protosw *pr = so->so_proto; |
struct protosw *pr = so->so_proto; |
struct mbuf *nextrecord; |
struct mbuf *nextrecord; |
int moff, type = 0; |
int moff, type = 0; |
|
|
if (pr->pr_domain->dom_externalize && |
if (pr->pr_domain->dom_externalize && |
mtod(m, struct cmsghdr *)->cmsg_type == |
mtod(m, struct cmsghdr *)->cmsg_type == |
SCM_RIGHTS) |
SCM_RIGHTS) |
error = (*pr->pr_domain->dom_externalize)(m); |
error = (*pr->pr_domain->dom_externalize)(m); |
*controlp = m; |
*controlp = m; |
so->so_rcv.sb_mb = m->m_next; |
so->so_rcv.sb_mb = m->m_next; |
m->m_next = 0; |
m->m_next = 0; |
Line 856 soshutdown(so, how) |
|
Line 875 soshutdown(so, how) |
|
|
|
void |
void |
sorflush(so) |
sorflush(so) |
register struct socket *so; |
struct socket *so; |
{ |
{ |
register struct sockbuf *sb = &so->so_rcv; |
struct sockbuf *sb = &so->so_rcv; |
register struct protosw *pr = so->so_proto; |
struct protosw *pr = so->so_proto; |
register int s; |
int s; |
struct sockbuf asb; |
struct sockbuf asb; |
|
|
sb->sb_flags |= SB_NOINTR; |
sb->sb_flags |= SB_NOINTR; |
|
|
|
|
int |
int |
sosetopt(so, level, optname, m0) |
sosetopt(so, level, optname, m0) |
register struct socket *so; |
struct socket *so; |
int level, optname; |
int level, optname; |
struct mbuf *m0; |
struct mbuf *m0; |
{ |
{ |
int error = 0; |
int error = 0; |
register struct mbuf *m = m0; |
struct mbuf *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) |
|
|
|
|
int |
int |
sogetopt(so, level, optname, mp) |
sogetopt(so, level, optname, mp) |
register struct socket *so; |
struct socket *so; |
int level, optname; |
int level, optname; |
struct mbuf **mp; |
struct mbuf **mp; |
{ |
{ |
register 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 1105 sogetopt(so, level, optname, mp) |
|
Line 1124 sogetopt(so, level, optname, mp) |
|
|
|
void |
void |
sohasoutofband(so) |
sohasoutofband(so) |
register struct socket *so; |
struct socket *so; |
{ |
{ |
struct proc *p; |
struct proc *p; |
|
|