2 * Copyright (c) 1982, 1986, 1989, 1990, 1993
3 * The Regents of the University of California. All rights reserved.
5 * sendfile(2) and related extensions:
6 * Copyright (c) 1998, David Greenman. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * @(#)uipc_syscalls.c 8.4 (Berkeley) 2/21/94
33 * $FreeBSD: src/sys/kern/uipc_syscalls.c,v 1.65.2.17 2003/04/04 17:11:16 tegge Exp $
36 #include "opt_ktrace.h"
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/kernel.h>
41 #include <sys/sysmsg.h>
42 #include <sys/malloc.h>
43 #include <sys/filedesc.h>
44 #include <sys/event.h>
46 #include <sys/fcntl.h>
48 #include <sys/filio.h>
49 #include <sys/kern_syscall.h>
51 #include <sys/protosw.h>
52 #include <sys/sfbuf.h>
53 #include <sys/socket.h>
54 #include <sys/socketvar.h>
55 #include <sys/socketops.h>
57 #include <sys/vnode.h>
59 #include <sys/mount.h>
62 #include <sys/ktrace.h>
65 #include <vm/vm_object.h>
66 #include <vm/vm_page.h>
67 #include <vm/vm_pageout.h>
68 #include <vm/vm_kern.h>
69 #include <vm/vm_extern.h>
70 #include <sys/file2.h>
71 #include <sys/signalvar.h>
72 #include <sys/serialize.h>
74 #include <sys/thread2.h>
75 #include <sys/msgport2.h>
76 #include <sys/socketvar2.h>
77 #include <net/netmsg2.h>
78 #include <vm/vm_page2.h>
80 extern int use_soaccept_pred_fast
;
81 extern int use_sendfile_async
;
82 extern int use_soconnect_async
;
85 * System call interface to the socket abstraction.
88 extern struct fileops socketops
;
91 * socket_args(int domain, int type, int protocol)
94 kern_socket(int domain
, int type
, int protocol
, int *res
)
96 struct thread
*td
= curthread
;
97 struct filedesc
*fdp
= td
->td_proc
->p_fd
;
104 KKASSERT(td
->td_lwp
);
106 if (type
& SOCK_NONBLOCK
) {
107 type
&= ~SOCK_NONBLOCK
;
110 if (type
& SOCK_CLOEXEC
) {
111 type
&= ~SOCK_CLOEXEC
;
115 error
= falloc(td
->td_lwp
, &fp
, &fd
);
118 error
= socreate(domain
, &so
, type
, protocol
, td
);
120 fsetfd(fdp
, NULL
, fd
);
122 fp
->f_type
= DTYPE_SOCKET
;
123 fp
->f_flag
= FREAD
| FWRITE
| fflags
;
124 fp
->f_ops
= &socketops
;
126 if (oflags
& O_CLOEXEC
)
127 fdp
->fd_files
[fd
].fileflags
|= UF_EXCLOSE
;
139 sys_socket(struct sysmsg
*sysmsg
, const struct socket_args
*uap
)
143 error
= kern_socket(uap
->domain
, uap
->type
, uap
->protocol
,
144 &sysmsg
->sysmsg_iresult
);
150 kern_bind(int s
, struct sockaddr
*sa
)
152 struct thread
*td
= curthread
;
156 error
= holdsock(td
, s
, &fp
);
159 error
= sobind((struct socket
*)fp
->f_data
, sa
, td
);
166 * bind_args(int s, caddr_t name, int namelen)
171 sys_bind(struct sysmsg
*sysmsg
, const struct bind_args
*uap
)
176 error
= getsockaddr(&sa
, uap
->name
, uap
->namelen
);
179 if (!prison_remote_ip(curthread
, sa
)) {
183 error
= kern_bind(uap
->s
, sa
);
190 kern_listen(int s
, int backlog
)
192 struct thread
*td
= curthread
;
196 error
= holdsock(td
, s
, &fp
);
199 error
= solisten((struct socket
*)fp
->f_data
, backlog
, td
);
206 * listen_args(int s, int backlog)
211 sys_listen(struct sysmsg
*sysmsg
, const struct listen_args
*uap
)
215 error
= kern_listen(uap
->s
, uap
->backlog
);
220 * Returns the accepted socket as well.
222 * NOTE! The sockets sitting on so_comp/so_incomp might have 0 refs, the
223 * pool token is absolutely required to avoid a sofree() race,
224 * as well as to avoid tailq handling races.
227 soaccept_predicate(struct netmsg_so_notify
*msg
)
229 struct socket
*head
= msg
->base
.nm_so
;
232 if (head
->so_error
!= 0) {
233 msg
->base
.lmsg
.ms_error
= head
->so_error
;
236 lwkt_getpooltoken(head
);
237 if (!TAILQ_EMPTY(&head
->so_comp
)) {
238 /* Abuse nm_so field as copy in/copy out parameter. XXX JH */
239 so
= TAILQ_FIRST(&head
->so_comp
);
240 KKASSERT((so
->so_state
& (SS_INCOMP
| SS_COMP
)) == SS_COMP
);
241 TAILQ_REMOVE(&head
->so_comp
, so
, so_list
);
243 soclrstate(so
, SS_COMP
);
246 * Keep a reference before clearing the so_head
247 * to avoid racing socket close in netisr.
252 lwkt_relpooltoken(head
);
254 msg
->base
.lmsg
.ms_error
= 0;
255 msg
->base
.nm_so
= so
;
258 lwkt_relpooltoken(head
);
259 if (head
->so_state
& SS_CANTRCVMORE
) {
260 msg
->base
.lmsg
.ms_error
= ECONNABORTED
;
263 if (msg
->nm_fflags
& FNONBLOCK
) {
264 msg
->base
.lmsg
.ms_error
= EWOULDBLOCK
;
272 * The second argument to kern_accept() is a handle to a struct sockaddr.
273 * This allows kern_accept() to return a pointer to an allocated struct
274 * sockaddr which must be freed later with FREE(). The caller must
275 * initialize *name to NULL.
278 kern_accept(int s
, int fflags
, struct sockaddr
**name
, int *namelen
, int *res
,
281 struct thread
*td
= curthread
;
282 struct filedesc
*fdp
= td
->td_proc
->p_fd
;
283 struct file
*lfp
= NULL
;
284 struct file
*nfp
= NULL
;
286 struct socket
*head
, *so
;
287 struct netmsg_so_notify msg
;
289 u_int fflag
; /* type must match fp->f_flag */
293 if (name
&& namelen
&& *namelen
< 0)
296 error
= holdsock(td
, s
, &lfp
);
300 error
= falloc(td
->td_lwp
, &nfp
, &fd
);
301 if (error
) { /* Probably ran out of file descriptors. */
305 head
= (struct socket
*)lfp
->f_data
;
306 if ((head
->so_options
& SO_ACCEPTCONN
) == 0) {
311 if (fflags
& O_FBLOCKING
)
312 fflags
|= lfp
->f_flag
& ~FNONBLOCK
;
313 else if (fflags
& O_FNONBLOCKING
)
314 fflags
|= lfp
->f_flag
| FNONBLOCK
;
316 fflags
= lfp
->f_flag
;
318 if (use_soaccept_pred_fast
) {
321 /* Initialize necessary parts for soaccept_predicate() */
322 netmsg_init(&msg
.base
, head
, &netisr_apanic_rport
, 0, NULL
);
323 msg
.nm_fflags
= fflags
;
325 lwkt_getpooltoken(head
);
326 pred
= soaccept_predicate(&msg
);
327 lwkt_relpooltoken(head
);
330 error
= msg
.base
.lmsg
.ms_error
;
338 /* optimize for uniprocessor case later XXX JH */
339 netmsg_init_abortable(&msg
.base
, head
, &curthread
->td_msgport
,
340 0, netmsg_so_notify
, netmsg_so_notify_doabort
);
341 msg
.nm_predicate
= soaccept_predicate
;
342 msg
.nm_fflags
= fflags
;
343 msg
.nm_etype
= NM_REVENT
;
344 error
= lwkt_domsg(head
->so_port
, &msg
.base
.lmsg
, PCATCH
);
350 * At this point we have the connection that's ready to be accepted.
352 * NOTE! soaccept_predicate() ref'd so for us, and soaccept() expects
353 * to eat the ref and turn it into a descriptor.
359 /* connection has been removed from the listen queue */
360 KNOTE(&head
->so_rcv
.ssb_kq
.ki_note
, 0);
362 if (sockflags
& SOCK_KERN_NOINHERIT
) {
363 fflag
&= ~(FASYNC
| FNONBLOCK
);
364 if (sockflags
& SOCK_NONBLOCK
)
367 if (head
->so_sigio
!= NULL
)
368 fsetown(fgetown(&head
->so_sigio
), &so
->so_sigio
);
371 nfp
->f_type
= DTYPE_SOCKET
;
373 nfp
->f_ops
= &socketops
;
375 /* Sync socket async state with file flags */
376 tmp
= fflag
& FASYNC
;
377 fo_ioctl(nfp
, FIOASYNC
, (caddr_t
)&tmp
, td
->td_ucred
, NULL
);
380 if (so
->so_faddr
!= NULL
) {
384 soaccept_generic(so
);
387 error
= soaccept(so
, &sa
);
391 * Set the returned name and namelen as applicable. Set the returned
392 * namelen to 0 for older code which might ignore the return value
396 if (sa
&& name
&& namelen
) {
397 if (*namelen
> sa
->sa_len
)
398 *namelen
= sa
->sa_len
;
408 * If an error occured clear the reserved descriptor, else associate
411 * Note that *res is normally ignored if an error is returned but
412 * a syscall message will still have access to the result code.
415 fsetfd(fdp
, NULL
, fd
);
417 if (sockflags
& SOCK_CLOEXEC
)
418 fdp
->fd_files
[fd
].fileflags
|= UF_EXCLOSE
;
420 fsetfd(fdp
, nfp
, fd
);
429 * accept(int s, caddr_t name, int *anamelen)
434 sys_accept(struct sysmsg
*sysmsg
, const struct accept_args
*uap
)
436 struct sockaddr
*sa
= NULL
;
441 error
= copyin(uap
->anamelen
, &sa_len
, sizeof(sa_len
));
445 error
= kern_accept(uap
->s
, 0, &sa
, &sa_len
,
446 &sysmsg
->sysmsg_iresult
, 0);
449 prison_local_ip(curthread
, sa
);
450 error
= copyout(sa
, uap
->name
, sa_len
);
453 error
= copyout(&sa_len
, uap
->anamelen
,
454 sizeof(*uap
->anamelen
));
459 error
= kern_accept(uap
->s
, 0, NULL
, 0,
460 &sysmsg
->sysmsg_iresult
, 0);
466 * extaccept(int s, int fflags, caddr_t name, int *anamelen)
471 sys_extaccept(struct sysmsg
*sysmsg
, const struct extaccept_args
*uap
)
473 struct sockaddr
*sa
= NULL
;
476 int fflags
= uap
->flags
& O_FMASK
;
479 error
= copyin(uap
->anamelen
, &sa_len
, sizeof(sa_len
));
483 error
= kern_accept(uap
->s
, fflags
, &sa
, &sa_len
,
484 &sysmsg
->sysmsg_iresult
, 0);
487 prison_local_ip(curthread
, sa
);
488 error
= copyout(sa
, uap
->name
, sa_len
);
491 error
= copyout(&sa_len
, uap
->anamelen
,
492 sizeof(*uap
->anamelen
));
497 error
= kern_accept(uap
->s
, fflags
, NULL
, 0,
498 &sysmsg
->sysmsg_iresult
, 0);
504 * accept4(int s, caddr_t name, int *anamelen, int flags)
509 sys_accept4(struct sysmsg
*sysmsg
, const struct accept4_args
*uap
)
511 struct sockaddr
*sa
= NULL
;
516 if (uap
->flags
& ~(SOCK_NONBLOCK
| SOCK_CLOEXEC
))
518 sockflags
= uap
->flags
| SOCK_KERN_NOINHERIT
;
521 error
= copyin(uap
->anamelen
, &sa_len
, sizeof(sa_len
));
525 error
= kern_accept(uap
->s
, 0, &sa
, &sa_len
,
526 &sysmsg
->sysmsg_iresult
, sockflags
);
529 prison_local_ip(curthread
, sa
);
530 error
= copyout(sa
, uap
->name
, sa_len
);
533 error
= copyout(&sa_len
, uap
->anamelen
,
534 sizeof(*uap
->anamelen
));
539 error
= kern_accept(uap
->s
, 0, NULL
, 0,
540 &sysmsg
->sysmsg_iresult
, sockflags
);
546 * Returns TRUE if predicate satisfied.
549 soconnected_predicate(struct netmsg_so_notify
*msg
)
551 struct socket
*so
= msg
->base
.nm_so
;
553 /* check predicate */
554 if (!(so
->so_state
& SS_ISCONNECTING
) || so
->so_error
!= 0) {
555 msg
->base
.lmsg
.ms_error
= so
->so_error
;
563 kern_connect(int s
, int fflags
, struct sockaddr
*sa
)
565 struct thread
*td
= curthread
;
568 int error
, interrupted
= 0;
570 error
= holdsock(td
, s
, &fp
);
573 so
= (struct socket
*)fp
->f_data
;
575 if (fflags
& O_FBLOCKING
)
576 /* fflags &= ~FNONBLOCK; */;
577 else if (fflags
& O_FNONBLOCKING
)
582 if (so
->so_state
& SS_ISCONNECTING
) {
586 error
= soconnect(so
, sa
, td
, use_soconnect_async
? FALSE
: TRUE
);
589 if ((fflags
& FNONBLOCK
) && (so
->so_state
& SS_ISCONNECTING
)) {
593 if ((so
->so_state
& SS_ISCONNECTING
) && so
->so_error
== 0) {
594 struct netmsg_so_notify msg
;
596 netmsg_init_abortable(&msg
.base
, so
,
597 &curthread
->td_msgport
,
600 netmsg_so_notify_doabort
);
601 msg
.nm_predicate
= soconnected_predicate
;
602 msg
.nm_etype
= NM_REVENT
;
603 error
= lwkt_domsg(so
->so_port
, &msg
.base
.lmsg
, PCATCH
);
604 if (error
== EINTR
|| error
== ERESTART
)
608 error
= so
->so_error
;
613 soclrstate(so
, SS_ISCONNECTING
);
614 if (error
== ERESTART
)
623 * connect_args(int s, caddr_t name, int namelen)
628 sys_connect(struct sysmsg
*sysmsg
, const struct connect_args
*uap
)
633 error
= getsockaddr(&sa
, uap
->name
, uap
->namelen
);
636 if (!prison_remote_ip(curthread
, sa
)) {
640 error
= kern_connect(uap
->s
, 0, sa
);
647 * connect_args(int s, int fflags, caddr_t name, int namelen)
652 sys_extconnect(struct sysmsg
*sysmsg
, const struct extconnect_args
*uap
)
656 int fflags
= uap
->flags
& O_FMASK
;
658 error
= getsockaddr(&sa
, uap
->name
, uap
->namelen
);
661 if (!prison_remote_ip(curthread
, sa
)) {
665 error
= kern_connect(uap
->s
, fflags
, sa
);
672 kern_socketpair(int domain
, int type
, int protocol
, int *sv
)
674 struct thread
*td
= curthread
;
675 struct filedesc
*fdp
;
676 struct file
*fp1
, *fp2
;
677 struct socket
*so1
, *so2
;
678 struct ucred
*cred
= curthread
->td_ucred
;
683 if (type
& SOCK_NONBLOCK
) {
684 type
&= ~SOCK_NONBLOCK
;
687 if (type
& SOCK_CLOEXEC
) {
688 type
&= ~SOCK_CLOEXEC
;
692 fdp
= td
->td_proc
->p_fd
;
693 error
= socreate(domain
, &so1
, type
, protocol
, td
);
696 error
= socreate(domain
, &so2
, type
, protocol
, td
);
699 error
= falloc(td
->td_lwp
, &fp1
, &fd1
);
704 error
= falloc(td
->td_lwp
, &fp2
, &fd2
);
709 error
= soconnect2(so1
, so2
, cred
);
712 if (type
== SOCK_DGRAM
) {
714 * Datagram socket connection is asymmetric.
716 error
= soconnect2(so2
, so1
, cred
);
720 fp1
->f_type
= fp2
->f_type
= DTYPE_SOCKET
;
721 fp1
->f_flag
= fp2
->f_flag
= FREAD
|FWRITE
|fflags
;
722 fp1
->f_ops
= fp2
->f_ops
= &socketops
;
723 if (oflags
& O_CLOEXEC
) {
724 fdp
->fd_files
[fd1
].fileflags
|= UF_EXCLOSE
;
725 fdp
->fd_files
[fd2
].fileflags
|= UF_EXCLOSE
;
727 fsetfd(fdp
, fp1
, fd1
);
728 fsetfd(fdp
, fp2
, fd2
);
733 fsetfd(fdp
, NULL
, fd2
);
736 fsetfd(fdp
, NULL
, fd1
);
739 (void)soclose(so2
, 0);
741 (void)soclose(so1
, 0);
746 * socketpair(int domain, int type, int protocol, int *rsv)
749 sys_socketpair(struct sysmsg
*sysmsg
, const struct socketpair_args
*uap
)
753 error
= kern_socketpair(uap
->domain
, uap
->type
, uap
->protocol
, sockv
);
756 error
= copyout(sockv
, uap
->rsv
, sizeof(sockv
));
759 kern_close(sockv
[0]);
760 kern_close(sockv
[1]);
768 kern_sendmsg(int s
, struct sockaddr
*sa
, struct uio
*auio
,
769 struct mbuf
*control
, int flags
, size_t *res
)
771 struct thread
*td
= curthread
;
772 struct lwp
*lp
= td
->td_lwp
;
773 struct proc
*p
= td
->td_proc
;
779 struct iovec
*ktriov
= NULL
;
783 error
= holdsock(td
, s
, &fp
);
787 if (KTRPOINT(td
, KTR_GENIO
)) {
788 int iovlen
= auio
->uio_iovcnt
* sizeof (struct iovec
);
790 ktriov
= kmalloc(iovlen
, M_TEMP
, M_WAITOK
);
791 bcopy((caddr_t
)auio
->uio_iov
, (caddr_t
)ktriov
, iovlen
);
795 len
= auio
->uio_resid
;
796 so
= (struct socket
*)fp
->f_data
;
797 if ((flags
& (MSG_FNONBLOCKING
|MSG_FBLOCKING
)) == 0) {
798 if (fp
->f_flag
& FNONBLOCK
)
799 flags
|= MSG_FNONBLOCKING
;
801 error
= so_pru_sosend(so
, sa
, auio
, NULL
, control
, flags
, td
);
803 if (auio
->uio_resid
!= len
&& (error
== ERESTART
||
804 error
== EINTR
|| error
== EWOULDBLOCK
))
806 if (error
== EPIPE
&& !(flags
& MSG_NOSIGNAL
) &&
807 !(so
->so_options
& SO_NOSIGPIPE
))
808 lwpsignal(p
, lp
, SIGPIPE
);
811 if (ktriov
!= NULL
) {
813 ktruio
.uio_iov
= ktriov
;
814 ktruio
.uio_resid
= len
- auio
->uio_resid
;
815 ktrgenio(lp
, s
, UIO_WRITE
, &ktruio
, error
);
817 kfree(ktriov
, M_TEMP
);
821 *res
= len
- auio
->uio_resid
;
828 * sendto_args(int s, caddr_t buf, size_t len, int flags, caddr_t to, int tolen)
833 sys_sendto(struct sysmsg
*sysmsg
, const struct sendto_args
*uap
)
835 struct thread
*td
= curthread
;
838 struct sockaddr
*sa
= NULL
;
842 error
= getsockaddr(&sa
, uap
->to
, uap
->tolen
);
845 if (!prison_remote_ip(curthread
, sa
)) {
850 aiov
.iov_base
= uap
->buf
;
851 aiov
.iov_len
= uap
->len
;
852 auio
.uio_iov
= &aiov
;
855 auio
.uio_resid
= uap
->len
;
856 auio
.uio_segflg
= UIO_USERSPACE
;
857 auio
.uio_rw
= UIO_WRITE
;
860 error
= kern_sendmsg(uap
->s
, sa
, &auio
, NULL
, uap
->flags
,
861 &sysmsg
->sysmsg_szresult
);
869 * sendmsg_args(int s, caddr_t msg, int flags)
874 sys_sendmsg(struct sysmsg
*sysmsg
, const struct sendmsg_args
*uap
)
876 struct thread
*td
= curthread
;
879 struct iovec aiov
[UIO_SMALLIOV
], *iov
= NULL
;
880 struct sockaddr
*sa
= NULL
;
881 struct mbuf
*control
= NULL
;
884 error
= copyin(uap
->msg
, (caddr_t
)&msg
, sizeof(msg
));
889 * Conditionally copyin msg.msg_name.
892 error
= getsockaddr(&sa
, msg
.msg_name
, msg
.msg_namelen
);
895 if (!prison_remote_ip(curthread
, sa
)) {
904 error
= iovec_copyin(msg
.msg_iov
, &iov
, aiov
, msg
.msg_iovlen
,
909 auio
.uio_iovcnt
= msg
.msg_iovlen
;
911 auio
.uio_segflg
= UIO_USERSPACE
;
912 auio
.uio_rw
= UIO_WRITE
;
916 * Conditionally copyin msg.msg_control.
918 if (msg
.msg_control
) {
919 if (msg
.msg_controllen
< sizeof(struct cmsghdr
) ||
920 msg
.msg_controllen
> MLEN
) {
924 control
= m_get(M_WAITOK
, MT_CONTROL
);
925 if (control
== NULL
) {
929 control
->m_len
= msg
.msg_controllen
;
930 error
= copyin(msg
.msg_control
, mtod(control
, caddr_t
),
938 error
= kern_sendmsg(uap
->s
, sa
, &auio
, control
, uap
->flags
,
939 &sysmsg
->sysmsg_szresult
);
942 iovec_free(&iov
, aiov
);
950 * kern_recvmsg() takes a handle to sa and control. If the handle is non-
951 * null, it returns a dynamically allocated struct sockaddr and an mbuf.
952 * Don't forget to FREE() and m_free() these if they are returned.
955 kern_recvmsg(int s
, struct sockaddr
**sa
, struct uio
*auio
,
956 struct mbuf
**control
, int *flags
, size_t *res
)
958 struct thread
*td
= curthread
;
965 struct iovec
*ktriov
= NULL
;
969 error
= holdsock(td
, s
, &fp
);
973 if (KTRPOINT(td
, KTR_GENIO
)) {
974 int iovlen
= auio
->uio_iovcnt
* sizeof (struct iovec
);
976 ktriov
= kmalloc(iovlen
, M_TEMP
, M_WAITOK
);
977 bcopy(auio
->uio_iov
, ktriov
, iovlen
);
981 len
= auio
->uio_resid
;
982 so
= (struct socket
*)fp
->f_data
;
984 if (flags
== NULL
|| (*flags
& (MSG_FNONBLOCKING
|MSG_FBLOCKING
)) == 0) {
985 if (fp
->f_flag
& FNONBLOCK
) {
987 *flags
|= MSG_FNONBLOCKING
;
989 lflags
= MSG_FNONBLOCKING
;
995 error
= so_pru_soreceive(so
, sa
, auio
, NULL
, control
, flags
);
997 if (auio
->uio_resid
!= len
&& (error
== ERESTART
||
998 error
== EINTR
|| error
== EWOULDBLOCK
))
1002 if (ktriov
!= NULL
) {
1004 ktruio
.uio_iov
= ktriov
;
1005 ktruio
.uio_resid
= len
- auio
->uio_resid
;
1006 ktrgenio(td
->td_lwp
, s
, UIO_READ
, &ktruio
, error
);
1008 kfree(ktriov
, M_TEMP
);
1012 *res
= len
- auio
->uio_resid
;
1019 * recvfrom_args(int s, caddr_t buf, size_t len, int flags,
1020 * caddr_t from, int *fromlenaddr)
1025 sys_recvfrom(struct sysmsg
*sysmsg
, const struct recvfrom_args
*uap
)
1027 struct thread
*td
= curthread
;
1030 struct sockaddr
*sa
= NULL
;
1034 if (uap
->from
&& uap
->fromlenaddr
) {
1035 error
= copyin(uap
->fromlenaddr
, &fromlen
, sizeof(fromlen
));
1043 aiov
.iov_base
= uap
->buf
;
1044 aiov
.iov_len
= uap
->len
;
1045 auio
.uio_iov
= &aiov
;
1046 auio
.uio_iovcnt
= 1;
1047 auio
.uio_offset
= 0;
1048 auio
.uio_resid
= uap
->len
;
1049 auio
.uio_segflg
= UIO_USERSPACE
;
1050 auio
.uio_rw
= UIO_READ
;
1054 error
= kern_recvmsg(uap
->s
, uap
->from
? &sa
: NULL
, &auio
, NULL
,
1055 &flags
, &sysmsg
->sysmsg_szresult
);
1057 if (error
== 0 && uap
->from
) {
1058 /* note: sa may still be NULL */
1060 fromlen
= MIN(fromlen
, sa
->sa_len
);
1061 prison_local_ip(curthread
, sa
);
1062 error
= copyout(sa
, uap
->from
, fromlen
);
1067 error
= copyout(&fromlen
, uap
->fromlenaddr
,
1072 kfree(sa
, M_SONAME
);
1078 * recvmsg_args(int s, struct msghdr *msg, int flags)
1083 sys_recvmsg(struct sysmsg
*sysmsg
, const struct recvmsg_args
*uap
)
1085 struct thread
*td
= curthread
;
1088 struct iovec aiov
[UIO_SMALLIOV
], *iov
= NULL
;
1089 struct mbuf
*m
, *control
= NULL
;
1090 struct sockaddr
*sa
= NULL
;
1092 socklen_t
*ufromlenp
, *ucontrollenp
;
1093 int error
, fromlen
, controllen
, len
, flags
, *uflagsp
;
1096 * This copyin handles everything except the iovec.
1098 error
= copyin(uap
->msg
, &msg
, sizeof(msg
));
1102 if (msg
.msg_name
&& msg
.msg_namelen
< 0)
1104 if (msg
.msg_control
&& msg
.msg_controllen
< 0)
1107 ufromlenp
= (socklen_t
*)((caddr_t
)uap
->msg
+ offsetof(struct msghdr
,
1109 ucontrollenp
= (socklen_t
*)((caddr_t
)uap
->msg
+ offsetof(struct msghdr
,
1111 uflagsp
= (int *)((caddr_t
)uap
->msg
+ offsetof(struct msghdr
,
1117 error
= iovec_copyin(msg
.msg_iov
, &iov
, aiov
, msg
.msg_iovlen
,
1122 auio
.uio_iovcnt
= msg
.msg_iovlen
;
1123 auio
.uio_offset
= 0;
1124 auio
.uio_segflg
= UIO_USERSPACE
;
1125 auio
.uio_rw
= UIO_READ
;
1130 error
= kern_recvmsg(uap
->s
,
1131 (msg
.msg_name
? &sa
: NULL
), &auio
,
1132 (msg
.msg_control
? &control
: NULL
), &flags
,
1133 &sysmsg
->sysmsg_szresult
);
1136 * Conditionally copyout the name and populate the namelen field.
1138 if (error
== 0 && msg
.msg_name
) {
1139 /* note: sa may still be NULL */
1141 fromlen
= MIN(msg
.msg_namelen
, sa
->sa_len
);
1142 prison_local_ip(curthread
, sa
);
1143 error
= copyout(sa
, msg
.msg_name
, fromlen
);
1148 error
= copyout(&fromlen
, ufromlenp
,
1149 sizeof(*ufromlenp
));
1153 * Copyout msg.msg_control and msg.msg_controllen.
1155 if (error
== 0 && msg
.msg_control
) {
1156 len
= msg
.msg_controllen
;
1158 ctlbuf
= (caddr_t
)msg
.msg_control
;
1160 while(m
&& len
> 0) {
1161 unsigned int tocopy
;
1163 if (len
>= m
->m_len
) {
1166 msg
.msg_flags
|= MSG_CTRUNC
;
1170 error
= copyout(mtod(m
, caddr_t
), ctlbuf
, tocopy
);
1178 controllen
= ctlbuf
- (caddr_t
)msg
.msg_control
;
1179 error
= copyout(&controllen
, ucontrollenp
,
1180 sizeof(*ucontrollenp
));
1184 error
= copyout(&flags
, uflagsp
, sizeof(*uflagsp
));
1188 kfree(sa
, M_SONAME
);
1189 iovec_free(&iov
, aiov
);
1196 * If sopt->sopt_td == NULL, then sopt->sopt_val is treated as an
1197 * in kernel pointer instead of a userland pointer. This allows us
1198 * to manipulate socket options in the emulation code.
1201 kern_setsockopt(int s
, struct sockopt
*sopt
)
1203 struct thread
*td
= curthread
;
1207 if (sopt
->sopt_val
== NULL
&& sopt
->sopt_valsize
!= 0)
1209 if (sopt
->sopt_val
!= NULL
&& sopt
->sopt_valsize
== 0)
1211 if (sopt
->sopt_valsize
> SOMAXOPT_SIZE
) /* unsigned */
1214 error
= holdsock(td
, s
, &fp
);
1218 error
= sosetopt((struct socket
*)fp
->f_data
, sopt
);
1225 * setsockopt_args(int s, int level, int name, caddr_t val, int valsize)
1230 sys_setsockopt(struct sysmsg
*sysmsg
, const struct setsockopt_args
*uap
)
1232 struct thread
*td
= curthread
;
1233 struct sockopt sopt
;
1236 sopt
.sopt_level
= uap
->level
;
1237 sopt
.sopt_name
= uap
->name
;
1238 sopt
.sopt_valsize
= uap
->valsize
;
1240 sopt
.sopt_val
= NULL
;
1242 if (sopt
.sopt_valsize
> SOMAXOPT_SIZE
) /* unsigned */
1245 sopt
.sopt_val
= kmalloc(sopt
.sopt_valsize
, M_TEMP
, M_WAITOK
);
1246 error
= copyin(uap
->val
, sopt
.sopt_val
, sopt
.sopt_valsize
);
1251 error
= kern_setsockopt(uap
->s
, &sopt
);
1254 kfree(sopt
.sopt_val
, M_TEMP
);
1259 * If sopt->sopt_td == NULL, then sopt->sopt_val is treated as an
1260 * in kernel pointer instead of a userland pointer. This allows us
1261 * to manipulate socket options in the emulation code.
1264 kern_getsockopt(int s
, struct sockopt
*sopt
)
1266 struct thread
*td
= curthread
;
1270 if (sopt
->sopt_val
== NULL
&& sopt
->sopt_valsize
!= 0)
1272 if (sopt
->sopt_val
!= NULL
&& sopt
->sopt_valsize
== 0)
1275 error
= holdsock(td
, s
, &fp
);
1279 error
= sogetopt((struct socket
*)fp
->f_data
, sopt
);
1286 * getsockopt_args(int s, int level, int name, caddr_t val, int *avalsize)
1291 sys_getsockopt(struct sysmsg
*sysmsg
, const struct getsockopt_args
*uap
)
1293 struct thread
*td
= curthread
;
1294 struct sockopt sopt
;
1295 int error
, valsize
, valszmax
, mflag
= 0;
1298 error
= copyin(uap
->avalsize
, &valsize
, sizeof(valsize
));
1305 sopt
.sopt_level
= uap
->level
;
1306 sopt
.sopt_name
= uap
->name
;
1307 sopt
.sopt_valsize
= valsize
;
1309 sopt
.sopt_val
= NULL
;
1311 if (td
->td_proc
->p_ucred
->cr_uid
== 0) {
1312 valszmax
= SOMAXOPT_SIZE0
;
1315 valszmax
= SOMAXOPT_SIZE
;
1317 if (sopt
.sopt_valsize
> valszmax
) /* unsigned */
1320 sopt
.sopt_val
= kmalloc(sopt
.sopt_valsize
, M_TEMP
,
1322 if (sopt
.sopt_val
== NULL
)
1324 error
= copyin(uap
->val
, sopt
.sopt_val
, sopt
.sopt_valsize
);
1329 error
= kern_getsockopt(uap
->s
, &sopt
);
1332 valsize
= sopt
.sopt_valsize
;
1333 error
= copyout(&valsize
, uap
->avalsize
, sizeof(valsize
));
1337 error
= copyout(sopt
.sopt_val
, uap
->val
, sopt
.sopt_valsize
);
1340 kfree(sopt
.sopt_val
, M_TEMP
);
1345 * The second argument to kern_getsockname() is a handle to a struct sockaddr.
1346 * This allows kern_getsockname() to return a pointer to an allocated struct
1347 * sockaddr which must be freed later with FREE(). The caller must
1348 * initialize *name to NULL.
1351 kern_getsockname(int s
, struct sockaddr
**name
, int *namelen
)
1353 struct thread
*td
= curthread
;
1356 struct sockaddr
*sa
= NULL
;
1359 error
= holdsock(td
, s
, &fp
);
1366 so
= (struct socket
*)fp
->f_data
;
1367 error
= so_pru_sockaddr(so
, &sa
);
1372 *namelen
= MIN(*namelen
, sa
->sa_len
);
1382 * getsockname_args(int fdes, caddr_t asa, int *alen)
1389 sys_getsockname(struct sysmsg
*sysmsg
, const struct getsockname_args
*uap
)
1391 struct sockaddr
*sa
= NULL
;
1392 struct sockaddr satmp
;
1393 int error
, sa_len_in
, sa_len_out
;
1395 error
= copyin(uap
->alen
, &sa_len_in
, sizeof(sa_len_in
));
1399 sa_len_out
= sa_len_in
;
1400 error
= kern_getsockname(uap
->fdes
, &sa
, &sa_len_out
);
1404 prison_local_ip(curthread
, sa
);
1405 error
= copyout(sa
, uap
->asa
, sa_len_out
);
1408 * unnamed uipc sockets don't bother storing
1409 * sockaddr, simulate an AF_LOCAL sockaddr.
1411 sa_len_out
= sizeof(satmp
);
1412 if (sa_len_out
> sa_len_in
)
1413 sa_len_out
= sa_len_in
;
1416 bzero(&satmp
, sizeof(satmp
));
1417 satmp
.sa_len
= sa_len_out
;
1418 satmp
.sa_family
= AF_LOCAL
;
1419 error
= copyout(&satmp
, uap
->asa
, sa_len_out
);
1422 if (error
== 0 && sa_len_out
!= sa_len_in
)
1423 error
= copyout(&sa_len_out
, uap
->alen
, sizeof(*uap
->alen
));
1425 kfree(sa
, M_SONAME
);
1430 * The second argument to kern_getpeername() is a handle to a struct sockaddr.
1431 * This allows kern_getpeername() to return a pointer to an allocated struct
1432 * sockaddr which must be freed later with FREE(). The caller must
1433 * initialize *name to NULL.
1436 kern_getpeername(int s
, struct sockaddr
**name
, int *namelen
)
1438 struct thread
*td
= curthread
;
1441 struct sockaddr
*sa
= NULL
;
1444 error
= holdsock(td
, s
, &fp
);
1451 so
= (struct socket
*)fp
->f_data
;
1452 if ((so
->so_state
& (SS_ISCONNECTED
|SS_ISCONFIRMING
)) == 0) {
1456 error
= so_pru_peeraddr(so
, &sa
);
1461 *namelen
= MIN(*namelen
, sa
->sa_len
);
1471 * getpeername_args(int fdes, caddr_t asa, int *alen)
1473 * Get name of peer for connected socket.
1478 sys_getpeername(struct sysmsg
*sysmsg
, const struct getpeername_args
*uap
)
1480 struct sockaddr
*sa
= NULL
;
1483 error
= copyin(uap
->alen
, &sa_len
, sizeof(sa_len
));
1487 error
= kern_getpeername(uap
->fdes
, &sa
, &sa_len
);
1490 prison_local_ip(curthread
, sa
);
1491 error
= copyout(sa
, uap
->asa
, sa_len
);
1494 error
= copyout(&sa_len
, uap
->alen
, sizeof(*uap
->alen
));
1496 kfree(sa
, M_SONAME
);
1501 getsockaddr(struct sockaddr
**namp
, caddr_t uaddr
, size_t len
)
1503 struct sockaddr
*sa
;
1507 if (len
> SOCK_MAXADDRLEN
)
1508 return ENAMETOOLONG
;
1509 if (len
< offsetof(struct sockaddr
, sa_data
[0]))
1511 sa
= kmalloc(len
, M_SONAME
, M_WAITOK
);
1512 error
= copyin(uaddr
, sa
, len
);
1514 kfree(sa
, M_SONAME
);
1523 * Detach a mapped page and release resources back to the system.
1524 * We must release our wiring and if the object is ripped out
1525 * from under the vm_page we become responsible for freeing the
1531 sf_buf_mfree(void *arg
)
1533 struct sf_buf
*sf
= arg
;
1536 m
= sf_buf_page(sf
);
1537 if (sf_buf_free(sf
)) {
1538 /* sf invalid now */
1539 vm_page_sbusy_drop(m
);
1541 if (m
->object
== NULL
&&
1542 m
->wire_count
== 0 &&
1543 (m
->flags
& PG_NEED_COMMIT
) == 0) {
1554 * int sendfile(int fd, int s, off_t offset, size_t nbytes,
1555 * struct sf_hdtr *hdtr, off_t *sbytes, int flags)
1557 * Send a file specified by 'fd' and starting at 'offset' to a socket
1558 * specified by 's'. Send only 'nbytes' of the file or until EOF if
1559 * nbytes == 0. Optionally add a header and/or trailer to the socket
1560 * output. If specified, write the total number of bytes sent into *sbytes.
1562 * In FreeBSD kern/uipc_syscalls.c,v 1.103, a bug was fixed that caused
1563 * the headers to count against the remaining bytes to be sent from
1564 * the file descriptor. We may wish to implement a compatibility syscall
1570 sys_sendfile(struct sysmsg
*sysmsg
, const struct sendfile_args
*uap
)
1572 struct thread
*td
= curthread
;
1574 struct vnode
*vp
= NULL
;
1575 struct sf_hdtr hdtr
;
1576 struct iovec aiov
[UIO_SMALLIOV
], *iov
= NULL
;
1578 struct mbuf
*mheader
= NULL
;
1581 off_t hdtr_size
= 0;
1586 * Do argument checking. Must be a regular file in, stream
1587 * type and connected socket out, positive offset.
1589 fp
= holdfp(td
, uap
->fd
, FREAD
);
1593 if (fp
->f_type
!= DTYPE_VNODE
) {
1597 vp
= (struct vnode
*)fp
->f_data
;
1599 dropfp(td
, uap
->fd
, fp
);
1602 * If specified, get the pointer to the sf_hdtr struct for
1603 * any headers/trailers.
1606 error
= copyin(uap
->hdtr
, &hdtr
, sizeof(hdtr
));
1613 error
= iovec_copyin(hdtr
.headers
, &iov
, aiov
,
1614 hdtr
.hdr_cnt
, &hbytes
);
1618 auio
.uio_iovcnt
= hdtr
.hdr_cnt
;
1619 auio
.uio_offset
= 0;
1620 auio
.uio_segflg
= UIO_USERSPACE
;
1621 auio
.uio_rw
= UIO_WRITE
;
1623 auio
.uio_resid
= hbytes
;
1625 mheader
= m_uiomove(&auio
);
1627 iovec_free(&iov
, aiov
);
1628 if (mheader
== NULL
)
1633 error
= kern_sendfile(vp
, uap
->s
, uap
->offset
, uap
->nbytes
, mheader
,
1634 &sbytes
, uap
->flags
);
1639 * Send trailers. Wimp out and use writev(2).
1641 if (uap
->hdtr
!= NULL
&& hdtr
.trailers
!= NULL
) {
1642 error
= iovec_copyin(hdtr
.trailers
, &iov
, aiov
,
1643 hdtr
.trl_cnt
, &auio
.uio_resid
);
1647 auio
.uio_iovcnt
= hdtr
.trl_cnt
;
1648 auio
.uio_offset
= 0;
1649 auio
.uio_segflg
= UIO_USERSPACE
;
1650 auio
.uio_rw
= UIO_WRITE
;
1653 tbytes
= 0; /* avoid gcc warnings */
1654 error
= kern_sendmsg(uap
->s
, NULL
, &auio
, NULL
, 0, &tbytes
);
1656 iovec_free(&iov
, aiov
);
1659 hdtr_size
+= tbytes
; /* trailer bytes successfully sent */
1665 if (uap
->sbytes
!= NULL
) {
1666 sbytes
+= hdtr_size
;
1667 copyout(&sbytes
, uap
->sbytes
, sizeof(off_t
));
1673 kern_sendfile(struct vnode
*vp
, int sfd
, off_t offset
, size_t nbytes
,
1674 struct mbuf
*mheader
, off_t
*sbytes
, int flags
)
1676 struct thread
*td
= curthread
;
1677 struct vm_object
*obj
;
1680 struct mbuf
*m
, *mp
;
1683 off_t off
, xfsize
, xbytes
;
1687 if (vp
->v_type
!= VREG
) {
1691 if ((obj
= vp
->v_object
) == NULL
) {
1695 error
= holdsock(td
, sfd
, &fp
);
1698 so
= (struct socket
*)fp
->f_data
;
1699 if (so
->so_type
!= SOCK_STREAM
) {
1703 if ((so
->so_state
& SS_ISCONNECTED
) == 0) {
1713 * preallocation is required for asynchronous passing of mbufs,
1714 * otherwise we can wind up building up an infinite number of
1715 * mbufs during the asynchronous latency.
1717 if ((so
->so_snd
.ssb_flags
& (SSB_PREALLOC
| SSB_STOPSUPP
)) == 0) {
1726 * Protect against multiple writers to the socket.
1727 * We need at least a shared lock on the VM object
1729 ssb_lock(&so
->so_snd
, M_WAITOK
);
1730 vm_object_hold_shared(obj
);
1733 * Loop through the pages in the file, starting with the requested
1734 * offset. Get a file page (do I/O if necessary), map the file page
1735 * into an sf_buf, attach an mbuf header to the sf_buf, and queue
1738 for (off
= offset
; ;
1739 off
+= xfsize
, *sbytes
+= xfsize
+ hbytes
, xbytes
+= xfsize
) {
1745 pindex
= OFF_TO_IDX(off
);
1750 * Calculate the amount to transfer. Not to exceed a page,
1751 * the EOF, or the passed in nbytes.
1753 xfsize
= vp
->v_filesize
- off
;
1754 if (xfsize
> PAGE_SIZE
)
1756 pgoff
= (vm_offset_t
)(off
& PAGE_MASK
);
1757 if (PAGE_SIZE
- pgoff
< xfsize
)
1758 xfsize
= PAGE_SIZE
- pgoff
;
1759 if (nbytes
&& xfsize
> (nbytes
- xbytes
))
1760 xfsize
= nbytes
- xbytes
;
1764 * Optimize the non-blocking case by looking at the socket space
1765 * before going to the extra work of constituting the sf_buf.
1767 if (so
->so_snd
.ssb_flags
& SSB_PREALLOC
)
1768 space
= ssb_space_prealloc(&so
->so_snd
);
1770 space
= ssb_space(&so
->so_snd
);
1772 if ((fp
->f_flag
& FNONBLOCK
) && space
<= 0) {
1773 if (so
->so_state
& SS_CANTSENDMORE
)
1781 * Attempt to look up the page.
1783 * Try to find the data using a shared vm_object token and
1784 * vm_page_lookup_sbusy_try() first.
1786 * If data is missing, use a UIO_NOCOPY VOP_READ to load
1787 * the missing data and loop back up. We avoid all sorts
1788 * of problems by not trying to hold onto the page during
1791 * NOTE: The soft-busy will temporary block filesystem
1792 * truncation operations when a file is removed
1793 * while the sendfile is running.
1795 pg
= vm_page_lookup_sbusy_try(obj
, pindex
, pgoff
, xfsize
);
1801 if (++loops
> 100000) {
1802 kprintf("sendfile: VOP operation failed "
1803 "to retain page\n");
1808 vm_object_drop(obj
);
1809 bsize
= vp
->v_mount
->mnt_stat
.f_iosize
;
1810 auio
.uio_iov
= &aiov
;
1811 auio
.uio_iovcnt
= 1;
1813 aiov
.iov_len
= MAXBSIZE
;
1814 auio
.uio_resid
= MAXBSIZE
;
1815 auio
.uio_offset
= trunc_page(off
);
1816 auio
.uio_segflg
= UIO_NOCOPY
;
1817 auio
.uio_rw
= UIO_READ
;
1820 vn_lock(vp
, LK_SHARED
| LK_RETRY
);
1821 error
= VOP_READ_FP(vp
, &auio
,
1822 IO_VMIO
| ((MAXBSIZE
/ bsize
) << 16),
1825 vm_object_hold_shared(obj
);
1833 * Get a sendfile buf. We usually wait as long as necessary,
1834 * but this wait can be interrupted.
1836 if ((sf
= sf_buf_alloc(pg
)) == NULL
) {
1837 vm_page_sbusy_drop(pg
);
1838 /* vm_page_try_to_free(pg); */
1844 * Get an mbuf header and set it up as having external storage.
1846 MGETHDR(m
, M_WAITOK
, MT_DATA
);
1849 vm_page_sbusy_drop(pg
);
1850 /* vm_page_try_to_free(pg); */
1855 m
->m_ext
.ext_free
= sf_buf_mfree
;
1856 m
->m_ext
.ext_ref
= sf_buf_ref
;
1857 m
->m_ext
.ext_arg
= sf
;
1858 m
->m_ext
.ext_buf
= (void *)sf_buf_kva(sf
);
1859 m
->m_ext
.ext_size
= PAGE_SIZE
;
1860 m
->m_data
= (char *)sf_buf_kva(sf
) + pgoff
;
1861 m
->m_flags
|= M_EXT
;
1862 m
->m_pkthdr
.len
= m
->m_len
= xfsize
;
1863 KKASSERT((m
->m_flags
& (M_EXT_CLUSTER
)) == 0);
1865 if (mheader
!= NULL
) {
1866 hbytes
= mheader
->m_pkthdr
.len
;
1867 mheader
->m_pkthdr
.len
+= m
->m_pkthdr
.len
;
1876 * Add the buffer to the socket buffer chain.
1881 * Make sure that the socket is still able to take more data.
1882 * CANTSENDMORE being true usually means that the connection
1883 * was closed. so_error is true when an error was sensed after
1885 * The state is checked after the page mapping and buffer
1886 * allocation above since those operations may block and make
1887 * any socket checks stale. From this point forward, nothing
1888 * blocks before the pru_send (or more accurately, any blocking
1889 * results in a loop back to here to re-check).
1891 if ((so
->so_state
& SS_CANTSENDMORE
) || so
->so_error
) {
1892 if (so
->so_state
& SS_CANTSENDMORE
) {
1895 error
= so
->so_error
;
1903 * Wait for socket space to become available. We do this just
1904 * after checking the connection state above in order to avoid
1905 * a race condition with ssb_wait().
1907 if (so
->so_snd
.ssb_flags
& SSB_PREALLOC
)
1908 space
= ssb_space_prealloc(&so
->so_snd
);
1910 space
= ssb_space(&so
->so_snd
);
1912 if (space
< m
->m_pkthdr
.len
&& space
< so
->so_snd
.ssb_lowat
) {
1913 if (fp
->f_flag
& FNONBLOCK
) {
1919 error
= ssb_wait(&so
->so_snd
);
1921 * An error from ssb_wait usually indicates that we've
1922 * been interrupted by a signal. If we've sent anything
1923 * then return bytes sent, otherwise return the error.
1933 if (so
->so_snd
.ssb_flags
& SSB_PREALLOC
) {
1934 for (mp
= m
; mp
!= NULL
; mp
= mp
->m_next
)
1935 ssb_preallocstream(&so
->so_snd
, mp
);
1937 if (use_sendfile_async
)
1938 error
= so_pru_senda(so
, 0, m
, NULL
, NULL
, td
);
1940 error
= so_pru_send(so
, 0, m
, NULL
, NULL
, td
);
1946 if (mheader
!= NULL
) {
1947 *sbytes
+= mheader
->m_pkthdr
.len
;
1949 if (so
->so_snd
.ssb_flags
& SSB_PREALLOC
) {
1950 for (mp
= mheader
; mp
!= NULL
; mp
= mp
->m_next
)
1951 ssb_preallocstream(&so
->so_snd
, mp
);
1953 if (use_sendfile_async
)
1954 error
= so_pru_senda(so
, 0, mheader
, NULL
, NULL
, td
);
1956 error
= so_pru_send(so
, 0, mheader
, NULL
, NULL
, td
);
1961 vm_object_drop(obj
);
1962 ssb_unlock(&so
->so_snd
);
1964 dropfp(td
, sfd
, fp
);
1966 if (mheader
!= NULL
)