version 1.8, 1993/11/05 23:00:27 |
version 1.28.4.1, 1997/08/28 00:12:14 |
|
|
|
/* $NetBSD$ */ |
|
|
/* |
/* |
* Copyright (c) 1982, 1986, 1988, 1990 Regents of the University of California. |
* Copyright (c) 1982, 1986, 1988, 1990, 1993 |
* All rights reserved. |
* The Regents of the University of California. All rights reserved. |
* |
* |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* modification, are permitted provided that the following conditions |
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
* |
* |
* from: @(#)uipc_socket.c 7.28 (Berkeley) 5/4/91 |
* @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94 |
* $Id$ |
|
*/ |
*/ |
|
|
#include "param.h" |
#include <sys/param.h> |
#include "systm.h" |
#include <sys/systm.h> |
#include "proc.h" |
#include <sys/proc.h> |
#include "file.h" |
#include <sys/file.h> |
#include "malloc.h" |
#include <sys/malloc.h> |
#include "mbuf.h" |
#include <sys/mbuf.h> |
#include "domain.h" |
#include <sys/domain.h> |
#include "kernel.h" |
#include <sys/kernel.h> |
#include "select.h" |
#include <sys/protosw.h> |
#include "protosw.h" |
#include <sys/socket.h> |
#include "socket.h" |
#include <sys/socketvar.h> |
#include "socketvar.h" |
#include <sys/signalvar.h> |
#include "resourcevar.h" |
#include <sys/resourcevar.h> |
|
|
/* |
/* |
* Socket operation routines. |
* Socket operation routines. |
|
|
/*ARGSUSED*/ |
/*ARGSUSED*/ |
int |
int |
socreate(dom, aso, type, proto) |
socreate(dom, aso, type, proto) |
|
int dom; |
struct socket **aso; |
struct socket **aso; |
register int type; |
register int type; |
int proto; |
int proto; |
Line 71 socreate(dom, aso, type, proto) |
|
Line 73 socreate(dom, aso, type, proto) |
|
prp = pffindproto(dom, proto, type); |
prp = pffindproto(dom, proto, type); |
else |
else |
prp = pffindtype(dom, type); |
prp = pffindtype(dom, type); |
if (!prp || !prp->pr_usrreq) |
if (prp == 0 || prp->pr_usrreq == 0) |
return (EPROTONOSUPPORT); |
return (EPROTONOSUPPORT); |
if (prp->pr_type != type) |
if (prp->pr_type != type) |
return (EPROTOTYPE); |
return (EPROTOTYPE); |
MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_WAIT); |
MALLOC(so, struct socket *, sizeof(*so), M_SOCKET, M_WAIT); |
bzero((caddr_t)so, sizeof(*so)); |
bzero((caddr_t)so, sizeof(*so)); |
so->so_type = type; |
so->so_type = type; |
if (p->p_ucred->cr_uid == 0) |
|
so->so_state = SS_PRIV; |
|
so->so_proto = prp; |
so->so_proto = prp; |
error = |
error = (*prp->pr_usrreq)(so, PRU_ATTACH, (struct mbuf *)0, |
(*prp->pr_usrreq)(so, PRU_ATTACH, |
(struct mbuf *)(long)proto, (struct mbuf *)0, p); |
(struct mbuf *)0, (struct mbuf *)proto, (struct mbuf *)0); |
|
if (error) { |
if (error) { |
so->so_state |= SS_NOFDREF; |
so->so_state |= SS_NOFDREF; |
sofree(so); |
sofree(so); |
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 |
*aso = so; |
*aso = so; |
return (0); |
return (0); |
} |
} |
|
|
struct socket *so; |
struct socket *so; |
struct mbuf *nam; |
struct mbuf *nam; |
{ |
{ |
int s = splnet(); |
struct proc *p = curproc; /* XXX */ |
|
int s = splsoftnet(); |
int error; |
int error; |
|
|
error = |
error = (*so->so_proto->pr_usrreq)(so, PRU_BIND, (struct mbuf *)0, |
(*so->so_proto->pr_usrreq)(so, PRU_BIND, |
nam, (struct mbuf *)0, p); |
(struct mbuf *)0, nam, (struct mbuf *)0); |
|
splx(s); |
splx(s); |
return (error); |
return (error); |
} |
} |
Line 113 solisten(so, backlog) |
|
Line 119 solisten(so, backlog) |
|
register struct socket *so; |
register struct socket *so; |
int backlog; |
int backlog; |
{ |
{ |
int s = splnet(), error; |
int s = splsoftnet(), error; |
|
|
error = |
error = (*so->so_proto->pr_usrreq)(so, PRU_LISTEN, (struct mbuf *)0, |
(*so->so_proto->pr_usrreq)(so, PRU_LISTEN, |
(struct mbuf *)0, (struct mbuf *)0, (struct proc *)0); |
(struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0); |
|
if (error) { |
if (error) { |
splx(s); |
splx(s); |
return (error); |
return (error); |
Line 131 solisten(so, backlog) |
|
Line 136 solisten(so, backlog) |
|
return (0); |
return (0); |
} |
} |
|
|
int |
void |
sofree(so) |
sofree(so) |
register struct socket *so; |
register struct socket *so; |
{ |
{ |
|
|
soclose(so) |
soclose(so) |
register struct socket *so; |
register struct socket *so; |
{ |
{ |
int s = splnet(); /* conservative */ |
int s = splsoftnet(); /* conservative */ |
int error = 0; |
int error = 0; |
|
|
if (so->so_options & SO_ACCEPTCONN) { |
if (so->so_options & SO_ACCEPTCONN) { |
|
|
if ((so->so_state & SS_ISDISCONNECTING) && |
if ((so->so_state & SS_ISDISCONNECTING) && |
(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) { |
if (error = tsleep((caddr_t)&so->so_timeo, |
error = tsleep((caddr_t)&so->so_timeo, |
PSOCK | PCATCH, netcls, so->so_linger)) |
PSOCK | PCATCH, netcls, |
|
so->so_linger); |
|
if (error) |
break; |
break; |
|
} |
} |
} |
} |
} |
drop: |
drop: |
if (so->so_pcb) { |
if (so->so_pcb) { |
int error2 = |
int error2 = (*so->so_proto->pr_usrreq)(so, PRU_DETACH, |
(*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); |
(struct proc *)0); |
if (error == 0) |
if (error == 0) |
error = error2; |
error = error2; |
} |
} |
|
|
} |
} |
|
|
/* |
/* |
* Must be called at splnet... |
* Must be called at splsoftnet... |
*/ |
*/ |
int |
int |
soabort(so) |
soabort(so) |
struct socket *so; |
struct socket *so; |
{ |
{ |
|
|
return ( |
return (*so->so_proto->pr_usrreq)(so, PRU_ABORT, (struct mbuf *)0, |
(*so->so_proto->pr_usrreq)(so, PRU_ABORT, |
(struct mbuf *)0, (struct mbuf *)0, (struct proc *)0); |
(struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0)); |
|
} |
} |
|
|
int |
int |
Line 219 soaccept(so, nam) |
|
Line 226 soaccept(so, nam) |
|
register struct socket *so; |
register struct socket *so; |
struct mbuf *nam; |
struct mbuf *nam; |
{ |
{ |
int s = splnet(); |
int s = splsoftnet(); |
int error; |
int error; |
|
|
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; |
error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT, |
error = (*so->so_proto->pr_usrreq)(so, PRU_ACCEPT, (struct mbuf *)0, |
(struct mbuf *)0, nam, (struct mbuf *)0); |
nam, (struct mbuf *)0, (struct proc *)0); |
splx(s); |
splx(s); |
return (error); |
return (error); |
} |
} |
Line 236 soconnect(so, nam) |
|
Line 243 soconnect(so, nam) |
|
register struct socket *so; |
register struct socket *so; |
struct mbuf *nam; |
struct mbuf *nam; |
{ |
{ |
|
struct proc *p = curproc; /* XXX */ |
int s; |
int s; |
int error; |
int error; |
|
|
if (so->so_options & SO_ACCEPTCONN) |
if (so->so_options & SO_ACCEPTCONN) |
return (EOPNOTSUPP); |
return (EOPNOTSUPP); |
s = splnet(); |
s = splsoftnet(); |
/* |
/* |
* If protocol is connection-based, can only connect once. |
* If protocol is connection-based, can only connect once. |
* Otherwise, if connected, try to disconnect first. |
* Otherwise, if connected, try to disconnect first. |
Line 254 soconnect(so, nam) |
|
Line 262 soconnect(so, nam) |
|
error = EISCONN; |
error = EISCONN; |
else |
else |
error = (*so->so_proto->pr_usrreq)(so, PRU_CONNECT, |
error = (*so->so_proto->pr_usrreq)(so, PRU_CONNECT, |
(struct mbuf *)0, nam, (struct mbuf *)0); |
(struct mbuf *)0, nam, (struct mbuf *)0, p); |
splx(s); |
splx(s); |
return (error); |
return (error); |
} |
} |
Line 264 soconnect2(so1, so2) |
|
Line 272 soconnect2(so1, so2) |
|
register struct socket *so1; |
register struct socket *so1; |
struct socket *so2; |
struct socket *so2; |
{ |
{ |
int s = splnet(); |
int s = splsoftnet(); |
int error; |
int error; |
|
|
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); |
splx(s); |
splx(s); |
return (error); |
return (error); |
} |
} |
|
|
sodisconnect(so) |
sodisconnect(so) |
register struct socket *so; |
register struct socket *so; |
{ |
{ |
int s = splnet(); |
int s = splsoftnet(); |
int error; |
int error; |
|
|
if ((so->so_state & SS_ISCONNECTED) == 0) { |
if ((so->so_state & SS_ISCONNECTED) == 0) { |
Line 289 sodisconnect(so) |
|
Line 298 sodisconnect(so) |
|
goto bad; |
goto bad; |
} |
} |
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); |
bad: |
bad: |
splx(s); |
splx(s); |
return (error); |
return (error); |
} |
} |
|
|
|
#define SBLOCKWAIT(f) (((f) & MSG_DONTWAIT) ? M_NOWAIT : M_WAITOK) |
/* |
/* |
* Send on a socket. |
* Send on a socket. |
* If send must go all at once and message is larger than |
* If send must go all at once and message is larger than |
Line 339 sosend(so, addr, uio, top, control, flag |
|
Line 350 sosend(so, addr, uio, top, control, flag |
|
* of space and resid. On the other hand, a negative resid |
* of space and resid. On the other hand, a negative resid |
* causes us to loop sending 0-length segments to the protocol. |
* causes us to loop sending 0-length segments to the protocol. |
*/ |
*/ |
if (resid < 0) |
if (resid < 0) { |
return (EINVAL); |
error = EINVAL; |
|
goto out; |
|
} |
dontroute = |
dontroute = |
(flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 && |
(flags & MSG_DONTROUTE) && (so->so_options & SO_DONTROUTE) == 0 && |
(so->so_proto->pr_flags & PR_ATOMIC); |
(so->so_proto->pr_flags & PR_ATOMIC); |
Line 350 sosend(so, addr, uio, top, control, flag |
|
Line 363 sosend(so, addr, uio, top, control, flag |
|
#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)) |
if ((error = sblock(&so->so_snd, SBLOCKWAIT(flags))) != 0) |
goto out; |
goto out; |
do { |
do { |
s = splnet(); |
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) |
|
|
space = sbspace(&so->so_snd); |
space = sbspace(&so->so_snd); |
if (flags & MSG_OOB) |
if (flags & MSG_OOB) |
space += 1024; |
space += 1024; |
if (space < resid + clen && |
if ((atomic && resid > so->so_snd.sb_hiwat) || |
|
clen > so->so_snd.sb_hiwat) |
|
snderr(EMSGSIZE); |
|
if (space < resid + clen && uio && |
(atomic || space < so->so_snd.sb_lowat || space < clen)) { |
(atomic || space < so->so_snd.sb_lowat || space < clen)) { |
if (atomic && resid > so->so_snd.sb_hiwat || |
|
clen > so->so_snd.sb_hiwat) |
|
snderr(EMSGSIZE); |
|
if (so->so_state & SS_NBIO) |
if (so->so_state & SS_NBIO) |
snderr(EWOULDBLOCK); |
snderr(EWOULDBLOCK); |
sbunlock(&so->so_snd); |
sbunlock(&so->so_snd); |
|
|
MGET(m, M_WAIT, MT_DATA); |
MGET(m, M_WAIT, MT_DATA); |
mlen = MLEN; |
mlen = MLEN; |
} |
} |
if (resid >= MINCLSIZE) { |
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; |
len = min(min(mlen, resid), space); |
#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); |
|
#endif |
|
space -= len; |
} else { |
} else { |
nopages: |
nopages: |
len = min(min(mlen, resid), space); |
len = min(min(mlen, resid), space); |
|
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); |
} |
} |
space -= 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; |
|
|
} while (space > 0 && atomic); |
} while (space > 0 && atomic); |
if (dontroute) |
if (dontroute) |
so->so_options |= SO_DONTROUTE; |
so->so_options |= SO_DONTROUTE; |
s = splnet(); /* XXX */ |
s = splsoftnet(); /* XXX */ |
error = (*so->so_proto->pr_usrreq)(so, |
error = (*so->so_proto->pr_usrreq)(so, |
(flags & MSG_OOB) ? PRU_SENDOOB : PRU_SEND, |
(flags & MSG_OOB) ? PRU_SENDOOB : PRU_SEND, |
top, addr, control); |
top, addr, control, p); |
splx(s); |
splx(s); |
if (dontroute) |
if (dontroute) |
so->so_options &= ~SO_DONTROUTE; |
so->so_options &= ~SO_DONTROUTE; |
Line 488 soreceive(so, paddr, uio, mp0, controlp, |
|
Line 510 soreceive(so, paddr, uio, mp0, controlp, |
|
struct mbuf **controlp; |
struct mbuf **controlp; |
int *flagsp; |
int *flagsp; |
{ |
{ |
struct proc *p = curproc; /* XXX */ |
|
register struct mbuf *m, **mp; |
register struct mbuf *m, **mp; |
register int flags, len, error, s, offset; |
register 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; |
int moff, type = 0; |
int orig_resid = uio->uio_resid; |
int orig_resid = uio->uio_resid; |
|
|
mp = mp0; |
mp = mp0; |
Line 507 soreceive(so, paddr, uio, mp0, controlp, |
|
Line 528 soreceive(so, paddr, uio, mp0, controlp, |
|
flags = 0; |
flags = 0; |
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, |
error = (*pr->pr_usrreq)(so, PRU_RCVOOB, m, |
m, (struct mbuf *)(flags & MSG_PEEK), (struct mbuf *)0); |
(struct mbuf *)(long)(flags & MSG_PEEK), (struct mbuf *)0, |
|
(struct proc *)0); |
if (error) |
if (error) |
goto bad; |
goto bad; |
do { |
do { |
|
|
*mp = (struct mbuf *)0; |
*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, (struct mbuf *)0, |
(*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0, |
(struct mbuf *)0, (struct mbuf *)0); |
(struct mbuf *)0, (struct mbuf *)0, (struct proc *)0); |
|
|
restart: |
restart: |
if (error = sblock(&so->so_rcv)) |
if ((error = sblock(&so->so_rcv, SBLOCKWAIT(flags))) != 0) |
return (error); |
return (error); |
s = splnet(); |
s = splsoftnet(); |
|
|
m = so->so_rcv.sb_mb; |
m = so->so_rcv.sb_mb; |
/* |
/* |
* If we have less data than requested, block awaiting more |
* If we have less data than requested, block awaiting more |
* (subject to any timeout) if: |
* (subject to any timeout) if: |
* 1. the current count is less than the low water mark, or |
* 1. the current count is less than the low water mark, |
* 2. MSG_WAITALL is set, and it is possible to do the entire |
* 2. MSG_WAITALL is set, and it is possible to do the entire |
* receive operation at once if we block (resid <= hiwat). |
* receive operation at once if we block (resid <= hiwat), or |
|
* 3. MSG_DONTWAIT is not set. |
* If MSG_WAITALL is set but resid is larger than the receive buffer, |
* If MSG_WAITALL is set but resid is larger than the receive buffer, |
* 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. |
*/ |
*/ |
while (m == 0 || so->so_rcv.sb_cc < uio->uio_resid && |
if (m == 0 || (((flags & MSG_DONTWAIT) == 0 && |
|
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) && uio->uio_resid <= so->so_rcv.sb_hiwat)) && |
m->m_nextpkt == 0 && (pr->pr_flags & PR_ATOMIC) == 0) { |
m->m_nextpkt == 0 && (pr->pr_flags & PR_ATOMIC) == 0)) { |
#ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
if (m == 0 && 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) |
if (m) |
break; |
goto dontblock; |
error = so->so_error; |
error = so->so_error; |
if ((flags & MSG_PEEK) == 0) |
if ((flags & MSG_PEEK) == 0) |
so->so_error = 0; |
so->so_error = 0; |
|
|
} |
} |
if (so->so_state & SS_CANTRCVMORE) { |
if (so->so_state & SS_CANTRCVMORE) { |
if (m) |
if (m) |
break; |
goto dontblock; |
else |
else |
goto release; |
goto release; |
} |
} |
|
|
} |
} |
if (uio->uio_resid == 0) |
if (uio->uio_resid == 0) |
goto release; |
goto release; |
if (so->so_state & SS_NBIO) { |
if ((so->so_state & SS_NBIO) || (flags & MSG_DONTWAIT)) { |
error = EWOULDBLOCK; |
error = EWOULDBLOCK; |
goto release; |
goto release; |
} |
} |
|
|
goto restart; |
goto restart; |
} |
} |
dontblock: |
dontblock: |
p->p_stats->p_ru.ru_msgrcv++; |
#ifdef notyet /* XXXX */ |
|
if (uio->uio_procp) |
|
uio->uio_procp->p_stats->p_ru.ru_msgrcv++; |
|
#endif |
nextrecord = m->m_nextpkt; |
nextrecord = m->m_nextpkt; |
if (pr->pr_flags & PR_ADDR) { |
if (pr->pr_flags & PR_ADDR) { |
#ifdef DIAGNOSTIC |
#ifdef DIAGNOSTIC |
|
|
if (mp == 0) { |
if (mp == 0) { |
splx(s); |
splx(s); |
error = uiomove(mtod(m, caddr_t) + moff, (int)len, uio); |
error = uiomove(mtod(m, caddr_t) + moff, (int)len, uio); |
s = splnet(); |
s = splsoftnet(); |
} else |
} else |
uio->uio_resid -= len; |
uio->uio_resid -= len; |
if (len == m->m_len - moff) { |
if (len == m->m_len - moff) { |
|
|
splx(s); |
splx(s); |
return (0); |
return (0); |
} |
} |
if (m = so->so_rcv.sb_mb) |
if ((m = so->so_rcv.sb_mb) != NULL) |
nextrecord = m->m_nextpkt; |
nextrecord = m->m_nextpkt; |
} |
} |
} |
} |
|
|
so->so_rcv.sb_mb = nextrecord; |
so->so_rcv.sb_mb = nextrecord; |
if (pr->pr_flags & PR_WANTRCVD && so->so_pcb) |
if (pr->pr_flags & PR_WANTRCVD && so->so_pcb) |
(*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0, |
(*pr->pr_usrreq)(so, PRU_RCVD, (struct mbuf *)0, |
(struct mbuf *)flags, (struct mbuf *)0, |
(struct mbuf *)(long)flags, (struct mbuf *)0, |
(struct mbuf *)0); |
(struct proc *)0); |
} |
} |
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) { |
|
|
return (error); |
return (error); |
} |
} |
|
|
|
int |
soshutdown(so, how) |
soshutdown(so, how) |
register struct socket *so; |
register struct socket *so; |
register int how; |
register int how; |
Line 786 soshutdown(so, how) |
|
Line 814 soshutdown(so, how) |
|
if (how & FREAD) |
if (how & FREAD) |
sorflush(so); |
sorflush(so); |
if (how & FWRITE) |
if (how & FWRITE) |
return ((*pr->pr_usrreq)(so, PRU_SHUTDOWN, |
return (*pr->pr_usrreq)(so, PRU_SHUTDOWN, (struct mbuf *)0, |
(struct mbuf *)0, (struct mbuf *)0, (struct mbuf *)0)); |
(struct mbuf *)0, (struct mbuf *)0, (struct proc *)0); |
return (0); |
return (0); |
} |
} |
|
|
|
void |
sorflush(so) |
sorflush(so) |
register struct socket *so; |
register struct socket *so; |
{ |
{ |
|
|
struct sockbuf asb; |
struct sockbuf asb; |
|
|
sb->sb_flags |= SB_NOINTR; |
sb->sb_flags |= SB_NOINTR; |
(void) sblock(sb); |
(void) sblock(sb, M_WAITOK); |
s = splimp(); |
s = splimp(); |
socantrcvmore(so); |
socantrcvmore(so); |
sbunlock(sb); |
sbunlock(sb); |
|
|
sbrelease(&asb); |
sbrelease(&asb); |
} |
} |
|
|
|
int |
sosetopt(so, level, optname, m0) |
sosetopt(so, level, optname, m0) |
register struct socket *so; |
register struct socket *so; |
int level, optname; |
int level, optname; |
Line 842 sosetopt(so, level, optname, m0) |
|
Line 872 sosetopt(so, level, optname, m0) |
|
case SO_USELOOPBACK: |
case SO_USELOOPBACK: |
case SO_BROADCAST: |
case SO_BROADCAST: |
case SO_REUSEADDR: |
case SO_REUSEADDR: |
|
case SO_REUSEPORT: |
case SO_OOBINLINE: |
case SO_OOBINLINE: |
|
case SO_TIMESTAMP: |
if (m == NULL || m->m_len < sizeof (int)) { |
if (m == NULL || m->m_len < sizeof (int)) { |
error = EINVAL; |
error = EINVAL; |
goto bad; |
goto bad; |
Line 857 sosetopt(so, level, optname, m0) |
|
Line 889 sosetopt(so, level, optname, m0) |
|
case SO_RCVBUF: |
case SO_RCVBUF: |
case SO_SNDLOWAT: |
case SO_SNDLOWAT: |
case SO_RCVLOWAT: |
case SO_RCVLOWAT: |
|
{ |
|
int optval; |
|
|
if (m == NULL || m->m_len < sizeof (int)) { |
if (m == NULL || m->m_len < sizeof (int)) { |
error = EINVAL; |
error = EINVAL; |
goto bad; |
goto bad; |
} |
} |
|
|
|
/* |
|
* Values < 1 make no sense for any of these |
|
* options, so disallow them. |
|
*/ |
|
optval = *mtod(m, int *); |
|
if (optval < 1) { |
|
error = EINVAL; |
|
goto bad; |
|
} |
|
|
switch (optname) { |
switch (optname) { |
|
|
case SO_SNDBUF: |
case SO_SNDBUF: |
case SO_RCVBUF: |
case SO_RCVBUF: |
if (sbreserve(optname == SO_SNDBUF ? |
if (sbreserve(optname == SO_SNDBUF ? |
&so->so_snd : &so->so_rcv, |
&so->so_snd : &so->so_rcv, |
(u_long) *mtod(m, int *)) == 0) { |
(u_long) optval) == 0) { |
error = ENOBUFS; |
error = ENOBUFS; |
goto bad; |
goto bad; |
} |
} |
break; |
break; |
|
|
|
/* |
|
* Make sure the low-water is never greater than |
|
* the high-water. |
|
*/ |
case SO_SNDLOWAT: |
case SO_SNDLOWAT: |
so->so_snd.sb_lowat = *mtod(m, int *); |
so->so_snd.sb_lowat = |
|
(optval > so->so_snd.sb_hiwat) ? |
|
so->so_snd.sb_hiwat : optval; |
break; |
break; |
case SO_RCVLOWAT: |
case SO_RCVLOWAT: |
so->so_rcv.sb_lowat = *mtod(m, int *); |
so->so_rcv.sb_lowat = |
|
(optval > so->so_rcv.sb_hiwat) ? |
|
so->so_rcv.sb_hiwat : optval; |
break; |
break; |
} |
} |
break; |
break; |
|
} |
|
|
case SO_SNDTIMEO: |
case SO_SNDTIMEO: |
case SO_RCVTIMEO: |
case SO_RCVTIMEO: |
Line 893 sosetopt(so, level, optname, m0) |
|
Line 948 sosetopt(so, level, optname, m0) |
|
goto bad; |
goto bad; |
} |
} |
tv = mtod(m, struct timeval *); |
tv = mtod(m, struct timeval *); |
if (tv->tv_sec > SHRT_MAX / hz - hz) { |
if (tv->tv_sec * hz + tv->tv_usec / tick > SHRT_MAX) { |
error = EDOM; |
error = EDOM; |
goto bad; |
goto bad; |
} |
} |
Line 915 sosetopt(so, level, optname, m0) |
|
Line 970 sosetopt(so, level, optname, m0) |
|
error = ENOPROTOOPT; |
error = ENOPROTOOPT; |
break; |
break; |
} |
} |
|
if (error == 0 && so->so_proto && so->so_proto->pr_ctloutput) { |
|
(void) ((*so->so_proto->pr_ctloutput) |
|
(PRCO_SETOPT, so, level, optname, &m0)); |
|
m = NULL; /* freed by protocol */ |
|
} |
} |
} |
bad: |
bad: |
if (m) |
if (m) |
|
|
return (error); |
return (error); |
} |
} |
|
|
|
int |
sogetopt(so, level, optname, mp) |
sogetopt(so, level, optname, mp) |
register struct socket *so; |
register struct socket *so; |
int level, optname; |
int level, optname; |
Line 953 sogetopt(so, level, optname, mp) |
|
Line 1014 sogetopt(so, level, optname, mp) |
|
case SO_DEBUG: |
case SO_DEBUG: |
case SO_KEEPALIVE: |
case SO_KEEPALIVE: |
case SO_REUSEADDR: |
case SO_REUSEADDR: |
|
case SO_REUSEPORT: |
case SO_BROADCAST: |
case SO_BROADCAST: |
case SO_OOBINLINE: |
case SO_OOBINLINE: |
|
case SO_TIMESTAMP: |
*mtod(m, int *) = so->so_options & optname; |
*mtod(m, int *) = so->so_options & optname; |
break; |
break; |
|
|
Line 992 sogetopt(so, level, optname, mp) |
|
Line 1055 sogetopt(so, level, optname, mp) |
|
m->m_len = sizeof(struct timeval); |
m->m_len = sizeof(struct timeval); |
mtod(m, struct timeval *)->tv_sec = val / hz; |
mtod(m, struct timeval *)->tv_sec = val / hz; |
mtod(m, struct timeval *)->tv_usec = |
mtod(m, struct timeval *)->tv_usec = |
(val % hz) / tick; |
(val % hz) * tick; |
break; |
break; |
} |
} |
|
|
Line 1005 sogetopt(so, level, optname, mp) |
|
Line 1068 sogetopt(so, level, optname, mp) |
|
} |
} |
} |
} |
|
|
|
void |
sohasoutofband(so) |
sohasoutofband(so) |
register struct socket *so; |
register struct socket *so; |
{ |
{ |