Deleted Added
full compact
uipc_socket.c (109439) uipc_socket.c (109623)
1/*
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94
1/*
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 17 unchanged lines hidden (view full) ---

26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * @(#)uipc_socket.c 8.3 (Berkeley) 4/15/94
34 * $FreeBSD: head/sys/kern/uipc_socket.c 109439 2003-01-17 19:20:00Z tmm $
34 * $FreeBSD: head/sys/kern/uipc_socket.c 109623 2003-01-21 08:56:16Z alfred $
35 */
36
37#include "opt_inet.h"
38#include "opt_mac.h"
39#include "opt_zero.h"
40
41#include <sys/param.h>
42#include <sys/systm.h>

--- 89 unchanged lines hidden (view full) ---

132{
133 struct socket *so;
134#ifdef MAC
135 int error;
136#endif
137 int flag;
138
139 if (waitok == 1)
35 */
36
37#include "opt_inet.h"
38#include "opt_mac.h"
39#include "opt_zero.h"
40
41#include <sys/param.h>
42#include <sys/systm.h>

--- 89 unchanged lines hidden (view full) ---

132{
133 struct socket *so;
134#ifdef MAC
135 int error;
136#endif
137 int flag;
138
139 if (waitok == 1)
140 flag = M_WAITOK;
140 flag = 0;
141 else
142 flag = M_NOWAIT;
143 flag |= M_ZERO;
144 so = uma_zalloc(socket_zone, flag);
145 if (so) {
146#ifdef MAC
147 error = mac_init_socket(so, flag);
148 if (error != 0) {

--- 328 unchanged lines hidden (view full) ---

477 goto bad;
478 }
479 error = (*so->so_proto->pr_usrreqs->pru_disconnect)(so);
480bad:
481 splx(s);
482 return (error);
483}
484
141 else
142 flag = M_NOWAIT;
143 flag |= M_ZERO;
144 so = uma_zalloc(socket_zone, flag);
145 if (so) {
146#ifdef MAC
147 error = mac_init_socket(so, flag);
148 if (error != 0) {

--- 328 unchanged lines hidden (view full) ---

477 goto bad;
478 }
479 error = (*so->so_proto->pr_usrreqs->pru_disconnect)(so);
480bad:
481 splx(s);
482 return (error);
483}
484
485#define SBLOCKWAIT(f) (((f) & MSG_DONTWAIT) ? M_NOWAIT : M_WAITOK)
485#define SBLOCKWAIT(f) (((f) & MSG_DONTWAIT) ? M_NOWAIT : 0)
486/*
487 * Send on a socket.
488 * If send must go all at once and message is larger than
489 * send buffering, then hard error.
490 * Lock against other senders.
491 * If must go all at once and not enough room now, then
492 * inform user that this would block and do nothing.
493 * Otherwise, if nonblocking, send as much as possible.

--- 127 unchanged lines hidden (view full) ---

621 resid = 0;
622 if (flags & MSG_EOR)
623 top->m_flags |= M_EOR;
624 } else do {
625#ifdef ZERO_COPY_SOCKETS
626 cow_send = 0;
627#endif /* ZERO_COPY_SOCKETS */
628 if (top == 0) {
486/*
487 * Send on a socket.
488 * If send must go all at once and message is larger than
489 * send buffering, then hard error.
490 * Lock against other senders.
491 * If must go all at once and not enough room now, then
492 * inform user that this would block and do nothing.
493 * Otherwise, if nonblocking, send as much as possible.

--- 127 unchanged lines hidden (view full) ---

621 resid = 0;
622 if (flags & MSG_EOR)
623 top->m_flags |= M_EOR;
624 } else do {
625#ifdef ZERO_COPY_SOCKETS
626 cow_send = 0;
627#endif /* ZERO_COPY_SOCKETS */
628 if (top == 0) {
629 MGETHDR(m, M_TRYWAIT, MT_DATA);
629 MGETHDR(m, 0, MT_DATA);
630 if (m == NULL) {
631 error = ENOBUFS;
632 goto release;
633 }
634 mlen = MHLEN;
635 m->m_pkthdr.len = 0;
636 m->m_pkthdr.rcvif = (struct ifnet *)0;
637 } else {
630 if (m == NULL) {
631 error = ENOBUFS;
632 goto release;
633 }
634 mlen = MHLEN;
635 m->m_pkthdr.len = 0;
636 m->m_pkthdr.rcvif = (struct ifnet *)0;
637 } else {
638 MGET(m, M_TRYWAIT, MT_DATA);
638 MGET(m, 0, MT_DATA);
639 if (m == NULL) {
640 error = ENOBUFS;
641 goto release;
642 }
643 mlen = MLEN;
644 }
645 if (resid >= MINCLSIZE) {
646#ifdef ZERO_COPY_SOCKETS

--- 5 unchanged lines hidden (view full) ---

652 if (!((vm_offset_t)
653 uio->uio_iov->iov_base & PAGE_MASK)){
654 so_zerocp_stats.align_ok++;
655 cow_send = socow_setup(m, uio);
656 }
657 }
658 if (!cow_send){
659#endif /* ZERO_COPY_SOCKETS */
639 if (m == NULL) {
640 error = ENOBUFS;
641 goto release;
642 }
643 mlen = MLEN;
644 }
645 if (resid >= MINCLSIZE) {
646#ifdef ZERO_COPY_SOCKETS

--- 5 unchanged lines hidden (view full) ---

652 if (!((vm_offset_t)
653 uio->uio_iov->iov_base & PAGE_MASK)){
654 so_zerocp_stats.align_ok++;
655 cow_send = socow_setup(m, uio);
656 }
657 }
658 if (!cow_send){
659#endif /* ZERO_COPY_SOCKETS */
660 MCLGET(m, M_TRYWAIT);
660 MCLGET(m, 0);
661 if ((m->m_flags & M_EXT) == 0)
662 goto nopages;
663 mlen = MCLBYTES;
664 len = min(min(mlen, resid), space);
665 } else {
666#ifdef ZERO_COPY_SOCKETS
667 len = PAGE_SIZE;
668 }

--- 114 unchanged lines hidden (view full) ---

783 *psa = 0;
784 if (controlp)
785 *controlp = 0;
786 if (flagsp)
787 flags = *flagsp &~ MSG_EOR;
788 else
789 flags = 0;
790 if (flags & MSG_OOB) {
661 if ((m->m_flags & M_EXT) == 0)
662 goto nopages;
663 mlen = MCLBYTES;
664 len = min(min(mlen, resid), space);
665 } else {
666#ifdef ZERO_COPY_SOCKETS
667 len = PAGE_SIZE;
668 }

--- 114 unchanged lines hidden (view full) ---

783 *psa = 0;
784 if (controlp)
785 *controlp = 0;
786 if (flagsp)
787 flags = *flagsp &~ MSG_EOR;
788 else
789 flags = 0;
790 if (flags & MSG_OOB) {
791 m = m_get(M_TRYWAIT, MT_DATA);
791 m = m_get(0, MT_DATA);
792 if (m == NULL)
793 return (ENOBUFS);
794 error = (*pr->pr_usrreqs->pru_rcvoob)(so, m, flags & MSG_PEEK);
795 if (error)
796 goto bad;
797 do {
798#ifdef ZERO_COPY_SOCKETS
799 if (so_zero_copy_receive) {

--- 220 unchanged lines hidden (view full) ---

1020 if (m)
1021 m->m_nextpkt = nextrecord;
1022 }
1023 } else {
1024 if (flags & MSG_PEEK)
1025 moff += len;
1026 else {
1027 if (mp)
792 if (m == NULL)
793 return (ENOBUFS);
794 error = (*pr->pr_usrreqs->pru_rcvoob)(so, m, flags & MSG_PEEK);
795 if (error)
796 goto bad;
797 do {
798#ifdef ZERO_COPY_SOCKETS
799 if (so_zero_copy_receive) {

--- 220 unchanged lines hidden (view full) ---

1020 if (m)
1021 m->m_nextpkt = nextrecord;
1022 }
1023 } else {
1024 if (flags & MSG_PEEK)
1025 moff += len;
1026 else {
1027 if (mp)
1028 *mp = m_copym(m, 0, len, M_TRYWAIT);
1028 *mp = m_copym(m, 0, len, 0);
1029 m->m_data += len;
1030 m->m_len -= len;
1031 so->so_rcv.sb_cc -= len;
1032 }
1033 }
1034 if (so->so_oobmark) {
1035 if ((flags & MSG_PEEK) == 0) {
1036 so->so_oobmark -= len;

--- 86 unchanged lines hidden (view full) ---

1123 register struct socket *so;
1124{
1125 register struct sockbuf *sb = &so->so_rcv;
1126 register struct protosw *pr = so->so_proto;
1127 register int s;
1128 struct sockbuf asb;
1129
1130 sb->sb_flags |= SB_NOINTR;
1029 m->m_data += len;
1030 m->m_len -= len;
1031 so->so_rcv.sb_cc -= len;
1032 }
1033 }
1034 if (so->so_oobmark) {
1035 if ((flags & MSG_PEEK) == 0) {
1036 so->so_oobmark -= len;

--- 86 unchanged lines hidden (view full) ---

1123 register struct socket *so;
1124{
1125 register struct sockbuf *sb = &so->so_rcv;
1126 register struct protosw *pr = so->so_proto;
1127 register int s;
1128 struct sockbuf asb;
1129
1130 sb->sb_flags |= SB_NOINTR;
1131 (void) sblock(sb, M_WAITOK);
1131 (void) sblock(sb, 0);
1132 s = splimp();
1133 socantrcvmore(so);
1134 sbunlock(sb);
1135 asb = *sb;
1136 bzero(sb, sizeof (*sb));
1137 splx(s);
1138 if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose)
1139 (*pr->pr_domain->dom_dispose)(asb.sb_mb);

--- 35 unchanged lines hidden (view full) ---

1175 }
1176 /* adding a filter */
1177 /* must remove previous filter first */
1178 if (af != NULL) {
1179 error = EINVAL;
1180 goto out;
1181 }
1182 /* don't put large objects on the kernel stack */
1132 s = splimp();
1133 socantrcvmore(so);
1134 sbunlock(sb);
1135 asb = *sb;
1136 bzero(sb, sizeof (*sb));
1137 splx(s);
1138 if (pr->pr_flags & PR_RIGHTS && pr->pr_domain->dom_dispose)
1139 (*pr->pr_domain->dom_dispose)(asb.sb_mb);

--- 35 unchanged lines hidden (view full) ---

1175 }
1176 /* adding a filter */
1177 /* must remove previous filter first */
1178 if (af != NULL) {
1179 error = EINVAL;
1180 goto out;
1181 }
1182 /* don't put large objects on the kernel stack */
1183 MALLOC(afap, struct accept_filter_arg *, sizeof(*afap), M_TEMP, M_WAITOK);
1183 MALLOC(afap, struct accept_filter_arg *, sizeof(*afap), M_TEMP, 0);
1184 error = sooptcopyin(sopt, afap, sizeof *afap, sizeof *afap);
1185 afap->af_name[sizeof(afap->af_name)-1] = '\0';
1186 afap->af_arg[sizeof(afap->af_arg)-1] = '\0';
1187 if (error)
1188 goto out;
1189 afp = accept_filt_get(afap->af_name);
1190 if (afp == NULL) {
1191 error = ENOENT;
1192 goto out;
1193 }
1184 error = sooptcopyin(sopt, afap, sizeof *afap, sizeof *afap);
1185 afap->af_name[sizeof(afap->af_name)-1] = '\0';
1186 afap->af_arg[sizeof(afap->af_arg)-1] = '\0';
1187 if (error)
1188 goto out;
1189 afp = accept_filt_get(afap->af_name);
1190 if (afp == NULL) {
1191 error = ENOENT;
1192 goto out;
1193 }
1194 MALLOC(af, struct so_accf *, sizeof(*af), M_ACCF, M_WAITOK | M_ZERO);
1194 MALLOC(af, struct so_accf *, sizeof(*af), M_ACCF, M_ZERO);
1195 if (afp->accf_create != NULL) {
1196 if (afap->af_name[0] != '\0') {
1197 int len = strlen(afap->af_name) + 1;
1198
1195 if (afp->accf_create != NULL) {
1196 if (afap->af_name[0] != '\0') {
1197 int len = strlen(afap->af_name) + 1;
1198
1199 MALLOC(af->so_accept_filter_str, char *, len, M_ACCF, M_WAITOK);
1199 MALLOC(af->so_accept_filter_str, char *, len, M_ACCF, 0);
1200 strcpy(af->so_accept_filter_str, afap->af_name);
1201 }
1202 af->so_accept_filter_arg = afp->accf_create(so, afap->af_arg);
1203 if (af->so_accept_filter_arg == NULL) {
1204 FREE(af->so_accept_filter_str, M_ACCF);
1205 FREE(af, M_ACCF);
1206 so->so_accf = NULL;
1207 error = EINVAL;

--- 265 unchanged lines hidden (view full) ---

1473 return (ENOPROTOOPT);
1474 } else {
1475 switch (sopt->sopt_name) {
1476#ifdef INET
1477 case SO_ACCEPTFILTER:
1478 if ((so->so_options & SO_ACCEPTCONN) == 0)
1479 return (EINVAL);
1480 MALLOC(afap, struct accept_filter_arg *, sizeof(*afap),
1200 strcpy(af->so_accept_filter_str, afap->af_name);
1201 }
1202 af->so_accept_filter_arg = afp->accf_create(so, afap->af_arg);
1203 if (af->so_accept_filter_arg == NULL) {
1204 FREE(af->so_accept_filter_str, M_ACCF);
1205 FREE(af, M_ACCF);
1206 so->so_accf = NULL;
1207 error = EINVAL;

--- 265 unchanged lines hidden (view full) ---

1473 return (ENOPROTOOPT);
1474 } else {
1475 switch (sopt->sopt_name) {
1476#ifdef INET
1477 case SO_ACCEPTFILTER:
1478 if ((so->so_options & SO_ACCEPTCONN) == 0)
1479 return (EINVAL);
1480 MALLOC(afap, struct accept_filter_arg *, sizeof(*afap),
1481 M_TEMP, M_WAITOK | M_ZERO);
1481 M_TEMP, M_ZERO);
1482 if ((so->so_options & SO_ACCEPTFILTER) != 0) {
1483 strcpy(afap->af_name, so->so_accf->so_accept_filter->accf_name);
1484 if (so->so_accf->so_accept_filter_str != NULL)
1485 strcpy(afap->af_arg, so->so_accf->so_accept_filter_str);
1486 }
1487 error = sooptcopyout(sopt, afap, sizeof(*afap));
1488 FREE(afap, M_TEMP);
1489 break;

--- 86 unchanged lines hidden (view full) ---

1576
1577/* XXX; prepare mbuf for (__FreeBSD__ < 3) routines. */
1578int
1579soopt_getm(struct sockopt *sopt, struct mbuf **mp)
1580{
1581 struct mbuf *m, *m_prev;
1582 int sopt_size = sopt->sopt_valsize;
1583
1482 if ((so->so_options & SO_ACCEPTFILTER) != 0) {
1483 strcpy(afap->af_name, so->so_accf->so_accept_filter->accf_name);
1484 if (so->so_accf->so_accept_filter_str != NULL)
1485 strcpy(afap->af_arg, so->so_accf->so_accept_filter_str);
1486 }
1487 error = sooptcopyout(sopt, afap, sizeof(*afap));
1488 FREE(afap, M_TEMP);
1489 break;

--- 86 unchanged lines hidden (view full) ---

1576
1577/* XXX; prepare mbuf for (__FreeBSD__ < 3) routines. */
1578int
1579soopt_getm(struct sockopt *sopt, struct mbuf **mp)
1580{
1581 struct mbuf *m, *m_prev;
1582 int sopt_size = sopt->sopt_valsize;
1583
1584 MGET(m, sopt->sopt_td ? M_TRYWAIT : M_DONTWAIT, MT_DATA);
1584 MGET(m, sopt->sopt_td ? 0 : M_NOWAIT, MT_DATA);
1585 if (m == 0)
1586 return ENOBUFS;
1587 if (sopt_size > MLEN) {
1585 if (m == 0)
1586 return ENOBUFS;
1587 if (sopt_size > MLEN) {
1588 MCLGET(m, sopt->sopt_td ? M_TRYWAIT : M_DONTWAIT);
1588 MCLGET(m, sopt->sopt_td ? 0 : M_NOWAIT);
1589 if ((m->m_flags & M_EXT) == 0) {
1590 m_free(m);
1591 return ENOBUFS;
1592 }
1593 m->m_len = min(MCLBYTES, sopt_size);
1594 } else {
1595 m->m_len = min(MLEN, sopt_size);
1596 }
1597 sopt_size -= m->m_len;
1598 *mp = m;
1599 m_prev = m;
1600
1601 while (sopt_size) {
1589 if ((m->m_flags & M_EXT) == 0) {
1590 m_free(m);
1591 return ENOBUFS;
1592 }
1593 m->m_len = min(MCLBYTES, sopt_size);
1594 } else {
1595 m->m_len = min(MLEN, sopt_size);
1596 }
1597 sopt_size -= m->m_len;
1598 *mp = m;
1599 m_prev = m;
1600
1601 while (sopt_size) {
1602 MGET(m, sopt->sopt_td ? M_TRYWAIT : M_DONTWAIT, MT_DATA);
1602 MGET(m, sopt->sopt_td ? 0 : M_NOWAIT, MT_DATA);
1603 if (m == 0) {
1604 m_freem(*mp);
1605 return ENOBUFS;
1606 }
1607 if (sopt_size > MLEN) {
1603 if (m == 0) {
1604 m_freem(*mp);
1605 return ENOBUFS;
1606 }
1607 if (sopt_size > MLEN) {
1608 MCLGET(m, sopt->sopt_td ? M_TRYWAIT : M_DONTWAIT);
1608 MCLGET(m, sopt->sopt_td ? 0 : M_NOWAIT);
1609 if ((m->m_flags & M_EXT) == 0) {
1610 m_freem(*mp);
1611 return ENOBUFS;
1612 }
1613 m->m_len = min(MCLBYTES, sopt_size);
1614 } else {
1615 m->m_len = min(MLEN, sopt_size);
1616 }

--- 237 unchanged lines hidden ---
1609 if ((m->m_flags & M_EXT) == 0) {
1610 m_freem(*mp);
1611 return ENOBUFS;
1612 }
1613 m->m_len = min(MCLBYTES, sopt_size);
1614 } else {
1615 m->m_len = min(MLEN, sopt_size);
1616 }

--- 237 unchanged lines hidden ---