version 1.134.2.6, 2007/10/09 13:44:32 |
version 1.142, 2007/09/19 04:33:43 |
|
|
{ |
{ |
struct mbuf *m, *next; |
struct mbuf *m, *next; |
size_t rv = 0; |
size_t rv = 0; |
|
int s; |
|
|
KASSERT(mutex_owned(&so_pendfree_lock)); |
KASSERT(mutex_owned(&so_pendfree_lock)); |
|
|
|
|
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); |
s = splvm(); |
|
pool_cache_put(&mbpool_cache, m); |
|
splx(s); |
} |
} |
|
|
mutex_enter(&so_pendfree_lock); |
mutex_enter(&so_pendfree_lock); |
Line 516 socreate(int dom, struct socket **aso, i |
|
Line 519 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); |
|
selinit(&so->so_snd.sb_sel); |
|
uid = kauth_cred_geteuid(l->l_cred); |
uid = kauth_cred_geteuid(l->l_cred); |
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, NULL, |
Line 623 sofree(struct socket *so) |
|
Line 624 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 891 sosend(struct socket *so, struct mbuf *a |
|
Line 890 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; |
Line 935 sosend(struct socket *so, struct mbuf *a |
|
Line 934 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 970 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 1020 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 1042 soreceive(struct socket *so, struct mbuf |
|
Line 1042 soreceive(struct socket *so, struct mbuf |
|
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 = NULL; |
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, NULL, NULL, NULL, 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 1070 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 1088 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 1114 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 1124 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 1143 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 1154 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 1170 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 1184 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 1196 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 1224 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 1248 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 1311 soreceive(struct socket *so, struct mbuf |
|
Line 1308 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 1341 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 1363 soreceive(struct socket *so, struct mbuf |
|
Line 1362 soreceive(struct socket *so, struct mbuf |
|
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 1378 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 1405 soreceive(struct socket *so, struct mbuf |
|
Line 1404 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 1427 soshutdown(struct socket *so, int how) |
|
Line 1426 soshutdown(struct socket *so, int how) |
|
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, NULL, |
NULL, NULL, NULL); |
NULL, NULL, NULL); |
return 0; |
return (0); |
} |
} |
|
|
void |
void |