35 #include <sys/cdefs.h>
38 #include "opt_capsicum.h"
40 #include "opt_inet6.h"
42 #include "opt_compat.h"
43 #include "opt_ktrace.h"
45 #include <sys/param.h>
46 #include <sys/systm.h>
47 #include <sys/capability.h>
48 #include <sys/kernel.h>
50 #include <sys/mutex.h>
51 #include <sys/sysproto.h>
52 #include <sys/malloc.h>
53 #include <sys/filedesc.h>
54 #include <sys/event.h>
56 #include <sys/fcntl.h>
58 #include <sys/filio.h>
60 #include <sys/mount.h>
62 #include <sys/protosw.h>
63 #include <sys/sf_buf.h>
64 #include <sys/sysent.h>
65 #include <sys/socket.h>
66 #include <sys/socketvar.h>
67 #include <sys/signalvar.h>
68 #include <sys/syscallsubr.h>
69 #include <sys/sysctl.h>
71 #include <sys/vnode.h>
73 #include <sys/ktrace.h>
76 #include <compat/compat32bit/compat32bit_util.h>
81 #include <security/audit/audit.h>
82 #include <security/mac/mac_framework.h>
85 #include <vm/vm_param.h>
86 #include <vm/vm_object.h>
87 #include <vm/vm_page.h>
88 #include <vm/vm_pageout.h>
89 #include <vm/vm_kern.h>
90 #include <vm/vm_extern.h>
92 #if defined(INET) || defined(INET6)
94 #include <netinet/sctp.h>
95 #include <netinet/sctp_peeloff.h>
103 #define SOCK_CLOEXEC 0x10000000
104 #define SOCK_NONBLOCK 0x20000000
106 static int sendit(
struct thread *td,
int s,
struct msghdr *mp,
int flags);
107 static int recvit(
struct thread *td,
int s,
struct msghdr *mp,
void *namelenp);
109 static int accept1(
struct thread *td,
struct accept_args *uap,
int compat);
110 static int do_sendfile(
struct thread *td,
struct sendfile_args *uap,
int compat);
111 static int getsockname1(
struct thread *td,
struct getsockname_args *uap,
113 static int getpeername1(
struct thread *td,
struct getpeername_args *uap,
124 "Maximum number of sendfile(2) sf_bufs available");
126 "Number of sendfile(2) sf_bufs at peak usage");
128 "Number of sendfile(2) sf_bufs in use");
137 struct file **fpp, u_int *fflagp)
141 struct file *fp_fromcap;
146 if ((fdp == NULL) || ((fp =
fget_unlocked(fdp, fd)) == NULL))
155 fdrop(fp, curthread);
158 if (fp != fp_fromcap) {
160 fdrop(fp, curthread);
164 if (fp->f_type != DTYPE_SOCKET) {
165 fdrop(fp, curthread);
169 *fflagp = fp->f_flag;
177 #if defined(COMPAT_43)
178 #define COMPAT_OLDSOCK
190 struct filedesc *fdp;
193 int fd, error,
type, oflag, fflag;
195 AUDIT_ARG_SOCKET(uap->domain, uap->type, uap->protocol);
201 type &= ~SOCK_CLOEXEC;
205 type &= ~SOCK_NONBLOCK;
210 error = mac_socket_check_create(td->td_ucred, uap->domain, type,
215 fdp = td->td_proc->p_fd;
216 error =
falloc(td, &fp, &fd, oflag);
220 error =
socreate(uap->domain, &so, type, uap->protocol,
226 if ((fflag & FNONBLOCK) != 0)
227 (void) fo_ioctl(fp, FIONBIO, &fflag, td->td_ucred, td);
228 td->td_retval[0] =
fd;
247 if ((error =
getsockaddr(&sa, uap->name, uap->namelen)) != 0)
266 error =
getsock_cap(td->td_proc->p_fd, fd, CAP_BIND, &fp, NULL);
271 if (KTRPOINT(td, KTR_STRUCT))
275 error = mac_socket_check_bind(td->td_ucred, so, sa);
278 error =
sobind(so, sa, td);
296 AUDIT_ARG_FD(uap->s);
297 error =
getsock_cap(td->td_proc->p_fd, uap->s, CAP_LISTEN, &fp, NULL);
301 error = mac_socket_check_listen(td->td_ucred, so);
304 error =
solisten(so, uap->backlog, td);
323 struct sockaddr *
name;
328 if (uap->name == NULL)
329 return (
kern_accept(td, uap->s, NULL, NULL, NULL));
331 error = copyin(uap->anamelen, &namelen, sizeof (namelen));
335 error =
kern_accept(td, uap->s, &name, &namelen, &fp);
342 (void) copyout(&namelen,
343 uap->anamelen,
sizeof(*uap->anamelen));
347 if (error == 0 && name != NULL) {
348 #ifdef COMPAT_OLDSOCK
350 ((
struct osockaddr *)name)->sa_family =
353 error = copyout(name, uap->name, namelen);
356 error = copyout(&namelen, uap->anamelen,
359 fdclose(td->td_proc->p_fd, fp, td->td_retval[0], td);
361 free(name, M_SONAME);
367 socklen_t *namelen,
struct file **fp)
369 struct filedesc *fdp;
370 struct file *headfp, *nfp = NULL;
371 struct sockaddr *sa = NULL;
373 struct socket *head, *so;
386 fdp = td->td_proc->p_fd;
387 error =
getsock_cap(fdp, s, CAP_ACCEPT, &headfp, &fflag);
390 head = headfp->f_data;
391 if ((head->so_options & SO_ACCEPTCONN) == 0) {
396 error = mac_socket_check_accept(td->td_ucred, head);
400 error =
falloc(td, &nfp, &fd, 0);
404 if ((head->so_state & SS_NBIO) && TAILQ_EMPTY(&head->so_comp)) {
409 while (TAILQ_EMPTY(&head->so_comp) && head->so_error == 0) {
410 if (head->so_rcv.sb_state & SBS_CANTRCVMORE) {
411 head->so_error = ECONNABORTED;
414 error = msleep(&head->so_timeo, &
accept_mtx, PSOCK | PCATCH,
421 if (head->so_error) {
422 error = head->so_error;
427 so = TAILQ_FIRST(&head->so_comp);
428 KASSERT(!(so->so_qstate & SQ_INCOMP), (
"accept1: so SQ_INCOMP"));
429 KASSERT(so->so_qstate & SQ_COMP, (
"accept1: so not SQ_COMP"));
439 TAILQ_REMOVE(&head->so_comp, so, so_list);
441 so->so_state |= (head->so_state & SS_NBIO);
442 so->so_qstate &= ~SQ_COMP;
449 td->td_retval[0] =
fd;
452 KNOTE_UNLOCKED(&head->so_rcv.sb_sel.si_note, 0);
454 pgid =
fgetown(&head->so_sigio);
460 tmp = fflag & FNONBLOCK;
461 (void) fo_ioctl(nfp, FIONBIO, &tmp, td->td_ucred, td);
462 tmp = fflag & FASYNC;
463 (void) fo_ioctl(nfp, FIOASYNC, &tmp, td->td_ucred, td);
482 if (*namelen > sa->sa_len)
483 *namelen = sa->sa_len;
485 if (KTRPOINT(td, KTR_STRUCT))
523 struct accept_args *uap;
529 #ifdef COMPAT_OLDSOCK
533 struct accept_args *uap;
575 error =
getsock_cap(td->td_proc->p_fd, fd, CAP_CONNECT, &fp, NULL);
579 if (so->so_state & SS_ISCONNECTING) {
584 if (KTRPOINT(td, KTR_STRUCT))
588 error = mac_socket_check_connect(td->td_ucred, so, sa);
595 if ((so->so_state & SS_NBIO) && (so->so_state & SS_ISCONNECTING)) {
600 while ((so->so_state & SS_ISCONNECTING) && so->so_error == 0) {
601 error = msleep(&so->so_timeo, SOCK_MTX(so), PSOCK | PCATCH,
604 if (error == EINTR || error == ERESTART)
610 error = so->so_error;
616 so->so_state &= ~SS_ISCONNECTING;
617 if (error == ERESTART)
628 struct filedesc *fdp = td->td_proc->p_fd;
629 struct file *fp1, *fp2;
630 struct socket *so1, *so2;
631 int fd, error, oflag, fflag;
633 AUDIT_ARG_SOCKET(domain, type, protocol);
638 type &= ~SOCK_CLOEXEC;
642 type &= ~SOCK_NONBLOCK;
647 error = mac_socket_check_create(td->td_ucred, domain, type,
652 error =
socreate(domain, &so1, type, protocol, td->td_ucred, td);
655 error =
socreate(domain, &so2, type, protocol, td->td_ucred, td);
659 error =
falloc(td, &fp1, &fd, oflag);
664 error =
falloc(td, &fp2, &fd, oflag);
672 if (type == SOCK_DGRAM) {
680 finit(fp1, FREAD | FWRITE | fflag, DTYPE_SOCKET, fp1->f_data,
682 finit(fp2, FREAD | FWRITE | fflag, DTYPE_SOCKET, fp2->f_data,
684 if ((fflag & FNONBLOCK) != 0) {
685 (void) fo_ioctl(fp1, FIONBIO, &fflag, td->td_ucred, td);
686 (void) fo_ioctl(fp2, FIONBIO, &fflag, td->td_ucred, td);
715 error = copyout(sv, uap->rsv, 2 *
sizeof(
int));
730 struct mbuf *control;
734 #ifdef CAPABILITY_MODE
735 if (IN_CAPABILITY_MODE(td) && (mp->msg_name != NULL))
739 if (mp->msg_name != NULL) {
740 error =
getsockaddr(&to, mp->msg_name, mp->msg_namelen);
750 if (mp->msg_control) {
751 if (mp->msg_controllen <
sizeof(
struct cmsghdr)
752 #ifdef COMPAT_OLDSOCK
753 && mp->msg_flags != MSG_COMPAT
759 error =
sockargs(&control, mp->msg_control,
760 mp->msg_controllen, MT_CONTROL);
763 #ifdef COMPAT_OLDSOCK
764 if (mp->msg_flags == MSG_COMPAT) {
767 M_PREPEND(control,
sizeof(*cm), M_WAIT);
768 cm = mtod(control,
struct cmsghdr *);
769 cm->cmsg_len = control->m_len;
770 cm->cmsg_level = SOL_SOCKET;
771 cm->cmsg_type = SCM_RIGHTS;
778 error =
kern_sendit(td, s, mp, flags, control, UIO_USERSPACE);
792 struct mbuf *control;
803 struct uio *ktruio = NULL;
808 if (mp->msg_name != NULL)
809 rights |= CAP_CONNECT;
810 error =
getsock_cap(td->td_proc->p_fd, s, rights, &fp, NULL);
813 so = (
struct socket *)fp->f_data;
816 if (mp->msg_name != NULL && KTRPOINT(td, KTR_STRUCT))
817 ktrsockaddr(mp->msg_name);
820 if (mp->msg_name != NULL) {
821 error = mac_socket_check_connect(td->td_ucred, so,
826 error = mac_socket_check_send(td->td_ucred, so);
831 auio.uio_iov = mp->msg_iov;
832 auio.uio_iovcnt = mp->msg_iovlen;
833 auio.uio_segflg = segflg;
834 auio.uio_rw = UIO_WRITE;
839 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
840 if ((auio.uio_resid += iov->iov_len) < 0) {
846 if (KTRPOINT(td, KTR_GENIO))
849 len = auio.uio_resid;
850 error =
sosend(so, mp->msg_name, &auio, 0, control, flags, td);
852 if (auio.uio_resid != len && (error == ERESTART ||
853 error == EINTR || error == EWOULDBLOCK))
856 if (error == EPIPE && !(so->so_options & SO_NOSIGPIPE) &&
857 !(flags & MSG_NOSIGNAL)) {
858 PROC_LOCK(td->td_proc);
860 PROC_UNLOCK(td->td_proc);
864 td->td_retval[0] = len - auio.uio_resid;
866 if (ktruio != NULL) {
867 ktruio->uio_resid = td->td_retval[0];
868 ktrgenio(s, UIO_WRITE, ktruio, error);
892 msg.msg_name = uap->to;
893 msg.msg_namelen = uap->tolen;
897 #ifdef COMPAT_OLDSOCK
900 aiov.iov_base = uap->buf;
901 aiov.iov_len = uap->len;
902 error =
sendit(td, uap->s, &msg, uap->flags);
906 #ifdef COMPAT_OLDSOCK
925 aiov.iov_base = uap->buf;
926 aiov.iov_len = uap->len;
929 error =
sendit(td, uap->s, &msg, uap->flags);
946 error = copyin(uap->msg, &msg, sizeof (
struct omsghdr));
949 error =
copyiniov(msg.msg_iov, msg.msg_iovlen, &iov, EMSGSIZE);
953 msg.msg_flags = MSG_COMPAT;
954 error =
sendit(td, uap->s, &msg, uap->flags);
973 error = copyin(uap->msg, &msg, sizeof (msg));
976 error =
copyiniov(msg.msg_iov, msg.msg_iovlen, &iov, EMSGSIZE);
980 #ifdef COMPAT_OLDSOCK
983 error =
sendit(td, uap->s, &msg, uap->flags);
993 enum uio_seg fromseg;
994 struct mbuf **controlp;
1001 struct mbuf *m, *control = 0;
1005 struct sockaddr *fromsa = 0;
1007 struct uio *ktruio = NULL;
1010 if (controlp != NULL)
1014 error =
getsock_cap(td->td_proc->p_fd, s, CAP_READ, &fp, NULL);
1020 error = mac_socket_check_receive(td->td_ucred, so);
1027 auio.uio_iov = mp->msg_iov;
1028 auio.uio_iovcnt = mp->msg_iovlen;
1029 auio.uio_segflg = UIO_USERSPACE;
1030 auio.uio_rw = UIO_READ;
1032 auio.uio_offset = 0;
1035 for (i = 0; i < mp->msg_iovlen; i++, iov++) {
1036 if ((auio.uio_resid += iov->iov_len) < 0) {
1042 if (KTRPOINT(td, KTR_GENIO))
1045 len = auio.uio_resid;
1046 error =
soreceive(so, &fromsa, &auio, (
struct mbuf **)0,
1047 (mp->msg_control || controlp) ? &control : (
struct mbuf **)0,
1050 if (auio.uio_resid != len && (error == ERESTART ||
1051 error == EINTR || error == EWOULDBLOCK))
1055 if (ktruio != NULL) {
1056 ktruio->uio_resid = len - auio.uio_resid;
1057 ktrgenio(s, UIO_READ, ktruio, error);
1062 td->td_retval[0] = len - auio.uio_resid;
1064 len = mp->msg_namelen;
1065 if (len <= 0 || fromsa == 0)
1069 len = MIN(len, fromsa->sa_len);
1070 #ifdef COMPAT_OLDSOCK
1071 if (mp->msg_flags & MSG_COMPAT)
1072 ((
struct osockaddr *)fromsa)->sa_family =
1075 if (fromseg == UIO_USERSPACE) {
1076 error = copyout(fromsa, mp->msg_name,
1081 bcopy(fromsa, mp->msg_name, len);
1083 mp->msg_namelen = len;
1085 if (mp->msg_control && controlp == NULL) {
1086 #ifdef COMPAT_OLDSOCK
1094 if (control && mp->msg_flags & MSG_COMPAT) {
1095 if (mtod(control,
struct cmsghdr *)->cmsg_level !=
1097 mtod(control,
struct cmsghdr *)->cmsg_type !=
1099 mp->msg_controllen = 0;
1102 control->m_len -=
sizeof (
struct cmsghdr);
1103 control->m_data +=
sizeof (
struct cmsghdr);
1106 len = mp->msg_controllen;
1108 mp->msg_controllen = 0;
1109 ctlbuf = mp->msg_control;
1111 while (m && len > 0) {
1112 unsigned int tocopy;
1114 if (len >= m->m_len)
1117 mp->msg_flags |= MSG_CTRUNC;
1121 if ((error = copyout(mtod(m, caddr_t),
1122 ctlbuf, tocopy)) != 0)
1129 mp->msg_controllen = ctlbuf - (caddr_t)mp->msg_control;
1134 if (fromsa && KTRPOINT(td, KTR_STRUCT))
1135 ktrsockaddr(fromsa);
1138 free(fromsa, M_SONAME);
1140 if (error == 0 && controlp != NULL)
1141 *controlp = control;
1157 error =
kern_recvit(td, s, mp, UIO_USERSPACE, NULL);
1161 error = copyout(&mp->msg_namelen, namelenp, sizeof (socklen_t));
1162 #ifdef COMPAT_OLDSOCK
1163 if (mp->msg_flags & MSG_COMPAT)
1173 struct recvfrom_args
1186 if (uap->fromlenaddr) {
1187 error = copyin(uap->fromlenaddr,
1188 &msg.msg_namelen, sizeof (msg.msg_namelen));
1192 msg.msg_namelen = 0;
1194 msg.msg_name = uap->from;
1195 msg.msg_iov = &aiov;
1197 aiov.iov_base = uap->buf;
1198 aiov.iov_len = uap->len;
1199 msg.msg_control = 0;
1200 msg.msg_flags = uap->flags;
1201 error =
recvit(td, uap->s, &msg, uap->fromlenaddr);
1206 #ifdef COMPAT_OLDSOCK
1210 struct recvfrom_args *uap;
1213 uap->flags |= MSG_COMPAT;
1218 #ifdef COMPAT_OLDSOCK
1234 msg.msg_namelen = 0;
1235 msg.msg_iov = &aiov;
1237 aiov.iov_base = uap->buf;
1238 aiov.iov_len = uap->len;
1239 msg.msg_control = 0;
1240 msg.msg_flags = uap->flags;
1241 error =
recvit(td, uap->s, &msg, NULL);
1253 struct orecvmsg_args
1263 error = copyin(uap->msg, &msg, sizeof (
struct omsghdr));
1266 error =
copyiniov(msg.msg_iov, msg.msg_iovlen, &iov, EMSGSIZE);
1269 msg.msg_flags = uap->flags | MSG_COMPAT;
1271 error =
recvit(td, uap->s, &msg, &uap->msg->msg_namelen);
1272 if (msg.msg_controllen && error == 0)
1273 error = copyout(&msg.msg_controllen,
1274 &uap->msg->msg_accrightslen, sizeof (
int));
1290 struct iovec *uiov, *iov;
1293 error = copyin(uap->msg, &msg, sizeof (msg));
1296 error =
copyiniov(msg.msg_iov, msg.msg_iovlen, &iov, EMSGSIZE);
1299 msg.msg_flags = uap->flags;
1300 #ifdef COMPAT_OLDSOCK
1301 msg.msg_flags &= ~MSG_COMPAT;
1305 error =
recvit(td, uap->s, &msg, NULL);
1308 error = copyout(&msg, uap->msg,
sizeof(msg));
1318 struct shutdown_args
1327 AUDIT_ARG_FD(uap->s);
1328 error =
getsock_cap(td->td_proc->p_fd, uap->s, CAP_SHUTDOWN, &fp,
1342 struct setsockopt_args
1352 uap->val, UIO_USERSPACE, uap->valsize));
1362 enum uio_seg valseg;
1368 struct sockopt sopt;
1370 if (val == NULL && valsize != 0)
1372 if ((
int)valsize < 0)
1375 sopt.sopt_dir = SOPT_SET;
1376 sopt.sopt_level =
level;
1377 sopt.sopt_name =
name;
1378 sopt.sopt_val = val;
1379 sopt.sopt_valsize = valsize;
1385 sopt.sopt_td = NULL;
1388 panic(
"kern_setsockopt called with bad valseg");
1392 error =
getsock_cap(td->td_proc->p_fd, s, CAP_SETSOCKOPT, &fp, NULL);
1405 struct getsockopt_args
1417 error = copyin(uap->avalsize, &valsize, sizeof (valsize));
1423 uap->val, UIO_USERSPACE, &valsize);
1426 error = copyout(&valsize, uap->avalsize, sizeof (valsize));
1441 enum uio_seg valseg;
1447 struct sockopt sopt;
1451 if ((
int)*valsize < 0)
1454 sopt.sopt_dir = SOPT_GET;
1455 sopt.sopt_level =
level;
1456 sopt.sopt_name =
name;
1457 sopt.sopt_val = val;
1458 sopt.sopt_valsize = (size_t)*valsize;
1464 sopt.sopt_td = NULL;
1467 panic(
"kern_getsockopt called with bad valseg");
1471 error =
getsock_cap(td->td_proc->p_fd, s, CAP_GETSOCKOPT, &fp, NULL);
1475 *valsize = sopt.sopt_valsize;
1488 struct getsockname_args
1495 struct sockaddr *sa;
1499 error = copyin(uap->alen, &len,
sizeof(len));
1508 #ifdef COMPAT_OLDSOCK
1510 ((
struct osockaddr *)sa)->sa_family = sa->sa_family;
1512 error = copyout(sa, uap->asa, (u_int)len);
1516 error = copyout(&len, uap->alen,
sizeof(len));
1533 error =
getsock_cap(td->td_proc->p_fd, fd, CAP_GETSOCKNAME, &fp, NULL);
1538 CURVNET_SET(so->so_vnet);
1539 error = (*so->so_proto->pr_usrreqs->pru_sockaddr)(so, sa);
1546 len = MIN(*alen, (*sa)->sa_len);
1549 if (KTRPOINT(td, KTR_STRUCT))
1555 free(*sa, M_SONAME);
1564 struct getsockname_args *uap;
1570 #ifdef COMPAT_OLDSOCK
1572 ogetsockname(td, uap)
1574 struct getsockname_args *uap;
1588 struct getpeername_args
1595 struct sockaddr *sa;
1599 error = copyin(uap->alen, &len, sizeof (len));
1608 #ifdef COMPAT_OLDSOCK
1610 ((
struct osockaddr *)sa)->sa_family = sa->sa_family;
1612 error = copyout(sa, uap->asa, (u_int)len);
1616 error = copyout(&len, uap->alen,
sizeof(len));
1633 error =
getsock_cap(td->td_proc->p_fd, fd, CAP_GETPEERNAME, &fp, NULL);
1637 if ((so->so_state & (SS_ISCONNECTED|SS_ISCONFIRMING)) == 0) {
1642 CURVNET_SET(so->so_vnet);
1643 error = (*so->so_proto->pr_usrreqs->pru_peeraddr)(so, sa);
1650 len = MIN(*alen, (*sa)->sa_len);
1653 if (KTRPOINT(td, KTR_STRUCT))
1658 free(*sa, M_SONAME);
1669 struct getpeername_args *uap;
1675 #ifdef COMPAT_OLDSOCK
1677 ogetpeername(td, uap)
1679 struct ogetpeername_args *uap;
1683 return (
getpeername1(td, (
struct getpeername_args *)uap, 1));
1693 struct sockaddr *sa;
1697 if ((u_int)buflen > MLEN) {
1698 #ifdef COMPAT_OLDSOCK
1699 if (type == MT_SONAME && (u_int)buflen <= 112)
1703 if ((u_int)buflen > MCLBYTES)
1706 m = m_get(M_WAIT, type);
1707 if ((u_int)buflen > MLEN)
1710 error = copyin(buf, mtod(m, caddr_t), (u_int)buflen);
1715 if (type == MT_SONAME) {
1716 sa = mtod(m,
struct sockaddr *);
1718 #if defined(COMPAT_OLDSOCK) && BYTE_ORDER != BIG_ENDIAN
1719 if (sa->sa_family == 0 && sa->sa_len < AF_MAX)
1720 sa->sa_family = sa->sa_len;
1722 sa->sa_len = buflen;
1730 struct sockaddr **namp;
1734 struct sockaddr *sa;
1737 if (len > SOCK_MAXADDRLEN)
1738 return (ENAMETOOLONG);
1739 if (len < offsetof(
struct sockaddr, sa_data[0]))
1741 sa =
malloc(len, M_SONAME, M_WAITOK);
1742 error = copyin(uaddr, sa, len);
1746 #if defined(COMPAT_OLDSOCK) && BYTE_ORDER != BIG_ENDIAN
1747 if (sa->sa_family == 0 && sa->sa_len < AF_MAX)
1748 sa->sa_family = sa->sa_len;
1756 #include <sys/condvar.h>
1773 m = sf_buf_page(args);
1776 vm_page_unwire(m, 0);
1782 if (m->wire_count == 0 && m->object == NULL)
1788 mtx_lock(&sfs->
mtx);
1789 KASSERT(sfs->
count> 0, (
"Sendfile sync botchup count == 0"));
1790 if (--sfs->
count == 0)
1792 mtx_unlock(&sfs->
mtx);
1816 struct sf_hdtr hdtr;
1817 struct uio *hdr_uio, *trl_uio;
1820 hdr_uio = trl_uio = NULL;
1822 if (uap->hdtr != NULL) {
1823 error = copyin(uap->hdtr, &hdtr,
sizeof(hdtr));
1826 if (hdtr.headers != NULL) {
1827 error =
copyinuio(hdtr.headers, hdtr.hdr_cnt, &hdr_uio);
1831 if (hdtr.trailers != NULL) {
1832 error =
copyinuio(hdtr.trailers, hdtr.trl_cnt, &trl_uio);
1842 free(hdr_uio, M_IOV);
1844 free(trl_uio, M_IOV);
1848 #ifdef COMPAT_FREEBSD4
1850 freebsd4_sendfile(
struct thread *td,
struct freebsd4_sendfile_args *uap)
1852 struct sendfile_args args;
1856 args.offset = uap->offset;
1857 args.nbytes = uap->nbytes;
1858 args.hdtr = uap->hdtr;
1859 args.sbytes = uap->sbytes;
1860 args.flags = uap->flags;
1868 struct uio *hdr_uio,
struct uio *trl_uio,
int compat)
1870 struct file *sock_fp;
1872 struct vm_object *obj = NULL;
1873 struct socket *so = NULL;
1874 struct mbuf *m = NULL;
1878 off_t off, xfsize, fsbytes = 0, sbytes = 0, rem = 0;
1879 int error, hdrlen = 0, mnw = 0;
1890 AUDIT_ARG_FD(uap->fd);
1891 if ((error =
fgetvp_read(td, uap->fd, CAP_READ, &vp)) != 0)
1893 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
1894 vn_lock(vp, LK_SHARED | LK_RETRY);
1895 if (vp->v_type == VREG) {
1896 bsize = vp->v_mount->mnt_stat.f_iosize;
1897 if (uap->nbytes == 0) {
1898 error = VOP_GETATTR(vp, &va, td->td_ucred);
1901 VFS_UNLOCK_GIANT(vfslocked);
1916 VM_OBJECT_LOCK(obj);
1917 if ((obj->flags & OBJ_DEAD) == 0) {
1918 vm_object_reference_locked(obj);
1919 VM_OBJECT_UNLOCK(obj);
1921 VM_OBJECT_UNLOCK(obj);
1928 VFS_UNLOCK_GIANT(vfslocked);
1933 if (uap->offset < 0) {
1942 if ((error =
getsock_cap(td->td_proc->p_fd, uap->s, CAP_WRITE,
1943 &sock_fp, NULL)) != 0)
1945 so = sock_fp->f_data;
1946 if (so->so_type != SOCK_STREAM) {
1950 if ((so->so_state & SS_ISCONNECTED) == 0) {
1959 if (uap->flags & SF_MNOWAIT)
1962 if (uap->flags & SF_SYNC) {
1963 sfs =
malloc(
sizeof *sfs, M_TEMP, M_WAITOK | M_ZERO);
1969 error = mac_socket_check_send(td->td_ucred, so);
1975 if (hdr_uio != NULL) {
1976 hdr_uio->uio_td = td;
1977 hdr_uio->uio_rw = UIO_WRITE;
1978 if (hdr_uio->uio_resid > 0) {
1985 if (uap->nbytes > hdr_uio->uio_resid)
1986 uap->nbytes -= hdr_uio->uio_resid;
1990 m =
m_uiotombuf(hdr_uio, (mnw ? M_NOWAIT : M_WAITOK),
1993 error = mnw ? EAGAIN : ENOBUFS;
2006 (void)
sblock(&so->so_snd, SBL_WAIT | SBL_NOINTR);
2019 for (off = uap->offset; ; ) {
2025 if ((uap->nbytes != 0 && uap->nbytes == fsbytes) ||
2026 (uap->nbytes == 0 && va.va_size == fsbytes))
2050 SOCKBUF_LOCK(&so->so_snd);
2051 if (so->so_snd.sb_lowat < so->so_snd.sb_hiwat / 2)
2052 so->so_snd.sb_lowat = so->so_snd.sb_hiwat / 2;
2054 if (so->so_snd.sb_state & SBS_CANTSENDMORE) {
2056 SOCKBUF_UNLOCK(&so->so_snd);
2058 }
else if (so->so_error) {
2059 error = so->so_error;
2061 SOCKBUF_UNLOCK(&so->so_snd);
2064 space = sbspace(&so->so_snd);
2067 space < so->so_snd.sb_lowat)) {
2068 if (so->so_state & SS_NBIO) {
2069 SOCKBUF_UNLOCK(&so->so_snd);
2079 error =
sbwait(&so->so_snd);
2086 SOCKBUF_UNLOCK(&so->so_snd);
2091 SOCKBUF_UNLOCK(&so->so_snd);
2100 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
2101 error = vn_lock(vp, LK_SHARED);
2103 VFS_UNLOCK_GIANT(vfslocked);
2106 error = VOP_GETATTR(vp, &va, td->td_ucred);
2107 if (error != 0 || off >= va.va_size) {
2109 VFS_UNLOCK_GIANT(vfslocked);
2112 VFS_UNLOCK_GIANT(vfslocked);
2118 while (space > loopbytes) {
2128 pgoff = (vm_offset_t)(off & PAGE_MASK);
2129 rem = va.va_size - uap->offset;
2130 if (uap->nbytes != 0)
2131 rem = omin(rem, uap->nbytes);
2132 rem -= fsbytes + loopbytes;
2133 xfsize = omin(PAGE_SIZE - pgoff, rem);
2134 xfsize = omin(space - loopbytes, xfsize);
2144 pindex = OFF_TO_IDX(off);
2145 VM_OBJECT_LOCK(obj);
2146 pg = vm_page_grab(obj, pindex, VM_ALLOC_NOBUSY |
2147 VM_ALLOC_NORMAL | VM_ALLOC_WIRED | VM_ALLOC_RETRY);
2156 if (pg->valid && vm_page_is_valid(pg, pgoff, xfsize))
2157 VM_OBJECT_UNLOCK(obj);
2160 else if (uap->flags & SF_NODISKIO)
2165 VM_OBJECT_UNLOCK(obj);
2174 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
2175 error =
vn_rdwr(UIO_READ, vp, NULL, MAXBSIZE,
2176 trunc_page(off), UIO_NOCOPY, IO_NODELOCKED |
2177 IO_VMIO | ((MAXBSIZE / bsize) << IO_SEQSHIFT),
2178 td->td_ucred, NOCRED, &resid, td);
2179 VFS_UNLOCK_GIANT(vfslocked);
2181 VM_OBJECT_LOCK(obj);
2186 vm_page_unwire(pg, 0);
2192 if (pg->wire_count == 0 && pg->valid == 0 &&
2193 pg->busy == 0 && !(pg->oflags & VPO_BUSY))
2196 VM_OBJECT_UNLOCK(obj);
2197 if (error == EAGAIN)
2211 sf = sf_buf_alloc(pg, (mnw || m != NULL) ? SFB_NOWAIT :
2216 vm_page_unwire(pg, 0);
2217 KASSERT(pg->object != NULL,
2218 (
"kern_sendfile: object disappeared"));
2221 error = (mnw ? EAGAIN : EINTR);
2229 m0 = m_get((mnw ? M_NOWAIT : M_WAITOK), MT_DATA);
2231 error = (mnw ? EAGAIN : ENOBUFS);
2235 MEXTADD(m0, sf_buf_kva(sf), PAGE_SIZE,
sf_buf_mext,
2236 sfs, sf, M_RDONLY, EXT_SFBUF);
2237 m0->m_data = (
char *)sf_buf_kva(sf) + pgoff;
2244 m_last(m)->m_next = m0;
2250 loopbytes += xfsize;
2254 mtx_lock(&sfs->
mtx);
2256 mtx_unlock(&sfs->
mtx);
2267 SOCKBUF_LOCK(&so->so_snd);
2268 if (so->so_snd.sb_state & SBS_CANTSENDMORE) {
2270 SOCKBUF_UNLOCK(&so->so_snd);
2273 SOCKBUF_UNLOCK(&so->so_snd);
2274 CURVNET_SET(so->so_vnet);
2276 err = (*so->so_proto->pr_usrreqs->pru_send)
2277 (so, 0, m, NULL, NULL, td);
2295 }
else if (error == 0)
2310 if (trl_uio != NULL) {
2314 sbytes += td->td_retval[0];
2326 td->td_retval[0] = 0;
2328 if (uap->sbytes != NULL) {
2329 copyout(&sbytes, uap->sbytes,
sizeof(off_t));
2332 vm_object_deallocate(obj);
2334 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
2336 VFS_UNLOCK_GIANT(vfslocked);
2344 mtx_lock(&sfs->
mtx);
2345 if (sfs->
count != 0)
2346 cv_wait(&sfs->
cv, &sfs->
mtx);
2347 KASSERT(sfs->
count == 0, (
"sendfile sync still busy"));
2353 if (error == ERESTART)
2368 struct sctp_peeloff_args
2373 #if (defined(INET) || defined(INET6)) && defined(SCTP)
2374 struct filedesc *fdp;
2375 struct file *nfp = NULL;
2377 struct socket *head, *so;
2381 fdp = td->td_proc->p_fd;
2382 AUDIT_ARG_FD(uap->sd);
2383 error =
fgetsock(td, uap->sd, CAP_PEELOFF, &head, &fflag);
2386 if (head->so_proto->pr_protocol != IPPROTO_SCTP) {
2390 error = sctp_can_peel_off(head, (sctp_assoc_t)uap->name);
2399 error =
falloc(td, &nfp, &fd, 0);
2402 td->td_retval[0] =
fd;
2404 CURVNET_SET(head->so_vnet);
2421 TAILQ_REMOVE(&head->so_comp, so, so_list);
2423 so->so_state |= (head->so_state & SS_NBIO);
2424 so->so_state &= ~SS_NOFDREF;
2425 so->so_qstate &= ~SQ_COMP;
2429 error = sctp_do_peeloff(head, so, (sctp_assoc_t)uap->name);
2432 if (head->so_sigio != NULL)
2454 return (EOPNOTSUPP);
2461 struct sctp_generic_sendmsg_args
2471 #if (defined(INET) || defined(INET6)) && defined(SCTP)
2472 struct sctp_sndrcvinfo sinfo, *u_sinfo = NULL;
2474 struct file *fp = NULL;
2476 struct sockaddr *to = NULL;
2478 struct uio *ktruio = NULL;
2481 struct iovec iov[1];
2482 cap_rights_t rights;
2485 error = copyin(uap->sinfo, &sinfo, sizeof (sinfo));
2498 rights |= CAP_CONNECT;
2501 AUDIT_ARG_FD(uap->sd);
2502 error =
getsock_cap(td->td_proc->p_fd, uap->sd, rights, &fp, NULL);
2506 if (to && (KTRPOINT(td, KTR_STRUCT)))
2510 iov[0].iov_base = uap->msg;
2511 iov[0].iov_len = uap->mlen;
2513 so = (
struct socket *)fp->f_data;
2514 if (so->so_proto->pr_protocol != IPPROTO_SCTP) {
2519 error = mac_socket_check_send(td->td_ucred, so);
2525 auio.uio_iovcnt = 1;
2526 auio.uio_segflg = UIO_USERSPACE;
2527 auio.uio_rw = UIO_WRITE;
2529 auio.uio_offset = 0;
2531 len = auio.uio_resid = uap->mlen;
2532 CURVNET_SET(so->so_vnet);
2533 error = sctp_lower_sosend(so, to, &auio,
2534 (
struct mbuf *)NULL, (
struct mbuf *)NULL,
2535 uap->flags, u_sinfo, td);
2538 if (auio.uio_resid != len && (error == ERESTART ||
2539 error == EINTR || error == EWOULDBLOCK))
2542 if (error == EPIPE && !(so->so_options & SO_NOSIGPIPE) &&
2543 !(uap->flags & MSG_NOSIGNAL)) {
2544 PROC_LOCK(td->td_proc);
2546 PROC_UNLOCK(td->td_proc);
2550 td->td_retval[0] = len - auio.uio_resid;
2552 if (ktruio != NULL) {
2553 ktruio->uio_resid = td->td_retval[0];
2554 ktrgenio(uap->sd, UIO_WRITE, ktruio, error);
2565 return (EOPNOTSUPP);
2572 struct sctp_generic_sendmsg_iov_args
2582 #if (defined(INET) || defined(INET6)) && defined(SCTP)
2583 struct sctp_sndrcvinfo sinfo, *u_sinfo = NULL;
2585 struct file *fp = NULL;
2588 struct sockaddr *to = NULL;
2590 struct uio *ktruio = NULL;
2593 struct iovec *iov, *tiov;
2594 cap_rights_t rights;
2597 error = copyin(uap->sinfo, &sinfo, sizeof (sinfo));
2609 rights |= CAP_CONNECT;
2612 AUDIT_ARG_FD(uap->sd);
2613 error =
getsock_cap(td->td_proc->p_fd, uap->sd, rights, &fp, NULL);
2618 if (SV_CURPROC_FLAG(SV_ILP32))
2619 error = compat32bit_copyiniov((
struct iovec32 *)uap->iov,
2620 uap->iovlen, &iov, EMSGSIZE);
2623 error =
copyiniov(uap->iov, uap->iovlen, &iov, EMSGSIZE);
2627 if (to && (KTRPOINT(td, KTR_STRUCT)))
2631 so = (
struct socket *)fp->f_data;
2632 if (so->so_proto->pr_protocol != IPPROTO_SCTP) {
2637 error = mac_socket_check_send(td->td_ucred, so);
2643 auio.uio_iovcnt = uap->iovlen;
2644 auio.uio_segflg = UIO_USERSPACE;
2645 auio.uio_rw = UIO_WRITE;
2647 auio.uio_offset = 0;
2650 for (i = 0; i <uap->iovlen; i++, tiov++) {
2651 if ((auio.uio_resid += tiov->iov_len) < 0) {
2656 len = auio.uio_resid;
2657 CURVNET_SET(so->so_vnet);
2658 error = sctp_lower_sosend(so, to, &auio,
2659 (
struct mbuf *)NULL, (
struct mbuf *)NULL,
2660 uap->flags, u_sinfo, td);
2663 if (auio.uio_resid != len && (error == ERESTART ||
2664 error == EINTR || error == EWOULDBLOCK))
2667 if (error == EPIPE && !(so->so_options & SO_NOSIGPIPE) &&
2668 !(uap->flags & MSG_NOSIGNAL)) {
2669 PROC_LOCK(td->td_proc);
2671 PROC_UNLOCK(td->td_proc);
2675 td->td_retval[0] = len - auio.uio_resid;
2677 if (ktruio != NULL) {
2678 ktruio->uio_resid = td->td_retval[0];
2679 ktrgenio(uap->sd, UIO_WRITE, ktruio, error);
2692 return (EOPNOTSUPP);
2699 struct sctp_generic_recvmsg_args
2709 #if (defined(INET) || defined(INET6)) && defined(SCTP)
2710 uint8_t sockbufstore[256];
2712 struct iovec *iov, *tiov;
2713 struct sctp_sndrcvinfo sinfo;
2715 struct file *fp = NULL;
2716 struct sockaddr *fromsa;
2722 struct uio *ktruio = NULL;
2725 AUDIT_ARG_FD(uap->sd);
2726 error =
getsock_cap(td->td_proc->p_fd, uap->sd, CAP_READ, &fp, NULL);
2731 if (SV_CURPROC_FLAG(SV_ILP32))
2732 error = compat32bit_copyiniov((
struct iovec32 *)uap->iov,
2733 uap->iovlen, &iov, EMSGSIZE);
2736 error =
copyiniov(uap->iov, uap->iovlen, &iov, EMSGSIZE);
2741 if (so->so_proto->pr_protocol != IPPROTO_SCTP) {
2746 error = mac_socket_check_receive(td->td_ucred, so);
2752 if (uap->fromlenaddr) {
2753 error = copyin(uap->fromlenaddr,
2754 &fromlen, sizeof (fromlen));
2761 if (uap->msg_flags) {
2762 error = copyin(uap->msg_flags, &msg_flags, sizeof (
int));
2770 auio.uio_iovcnt = uap->iovlen;
2771 auio.uio_segflg = UIO_USERSPACE;
2772 auio.uio_rw = UIO_READ;
2774 auio.uio_offset = 0;
2777 for (i = 0; i <uap->iovlen; i++, tiov++) {
2778 if ((auio.uio_resid += tiov->iov_len) < 0) {
2783 len = auio.uio_resid;
2784 fromsa = (
struct sockaddr *)sockbufstore;
2787 if (KTRPOINT(td, KTR_GENIO))
2790 memset(&sinfo, 0,
sizeof(
struct sctp_sndrcvinfo));
2791 CURVNET_SET(so->so_vnet);
2792 error = sctp_sorecvmsg(so, &auio, (
struct mbuf **)NULL,
2793 fromsa, fromlen, &msg_flags,
2794 (
struct sctp_sndrcvinfo *)&sinfo, 1);
2797 if (auio.uio_resid != len && (error == ERESTART ||
2798 error == EINTR || error == EWOULDBLOCK))
2802 error = copyout(&sinfo, uap->sinfo, sizeof (sinfo));
2805 if (ktruio != NULL) {
2806 ktruio->uio_resid = len - auio.uio_resid;
2807 ktrgenio(uap->sd, UIO_READ, ktruio, error);
2812 td->td_retval[0] = len - auio.uio_resid;
2814 if (fromlen && uap->from) {
2816 if (len <= 0 || fromsa == 0)
2819 len = MIN(len, fromsa->sa_len);
2820 error = copyout(fromsa, uap->from, (
size_t)len);
2824 error = copyout(&len, uap->fromlenaddr, sizeof (socklen_t));
2830 if (KTRPOINT(td, KTR_STRUCT))
2831 ktrsockaddr(fromsa);
2833 if (uap->msg_flags) {
2834 error = copyout(&msg_flags, uap->msg_flags, sizeof (
int));
2847 return (EOPNOTSUPP);
static int sendit(struct thread *td, int s, struct msghdr *mp, int flags)
int kern_recvit(struct thread *td, int s, struct msghdr *mp, enum uio_seg fromseg, struct mbuf **controlp)
struct uio * cloneuio(struct uio *uiop)
pid_t fgetown(struct sigio **sigiop)
int fsetown(pid_t pgid, struct sigio **sigiop)
static int getsock_cap(struct filedesc *fdp, int fd, cap_rights_t rights, struct file **fpp, u_int *fflagp)
int kern_close(struct thread *td, int fd)
int sys_getsockopt(struct thread *td, struct getsockopt_args *uap)
int getsockaddr(struct sockaddr **namp, caddr_t uaddr, size_t len)
struct file * fget_unlocked(struct filedesc *fdp, int fd)
int kern_setsockopt(struct thread *td, int s, int level, int name, void *val, enum uio_seg valseg, socklen_t valsize)
static int getsockname1(struct thread *td, struct getsockname_args *uap, int compat)
void * malloc(unsigned long size, struct malloc_type *mtp, int flags)
void sbunlock(struct sockbuf *sb)
int sys_getsockname(struct thread *td, struct getsockname_args *uap)
void cv_destroy(struct cv *cvp)
int sbwait(struct sockbuf *sb)
int cap_funwrap(struct file *fp_cap, cap_rights_t rights, struct file **fpp)
void panic(const char *fmt,...)
int kern_getsockopt(struct thread *td, int s, int level, int name, void *val, enum uio_seg valseg, socklen_t *valsize)
int sys_sctp_generic_sendmsg_iov(struct thread *td, struct sctp_generic_sendmsg_iov_args *uap)
void sf_buf_mext(void *addr, void *args)
struct mbuf * m_uiotombuf(struct uio *uio, int how, int len, int align, int flags)
int kern_getpeername(struct thread *td, int fd, struct sockaddr **sa, socklen_t *alen)
int sys_connect(struct thread *td, struct connect_args *uap)
int soaccept(struct socket *so, struct sockaddr **nam)
void m_freem(struct mbuf *mb)
int falloc(struct thread *td, struct file **resultfp, int *resultfd, int flags)
int solisten(struct socket *so, int backlog, struct thread *td)
int sys_socket(struct thread *td, struct socket_args *uap)
int sosetopt(struct socket *so, struct sockopt *sopt)
int kern_bind(struct thread *td, int fd, struct sockaddr *sa)
void cv_signal(struct cv *cvp)
int copyiniov(struct iovec *iovp, u_int iovcnt, struct iovec **iov, int error)
int sobind(struct socket *so, struct sockaddr *nam, struct thread *td)
int sockargs(struct mbuf **mp, caddr_t buf, int buflen, int type)
int sys_sctp_generic_sendmsg(struct thread *td, struct sctp_generic_sendmsg_args *uap)
int sys_getpeername(struct thread *td, struct getpeername_args *uap)
SYSCTL_INT(_kern_ipc, OID_AUTO, nsfbufs, CTLFLAG_RDTUN,&nsfbufs, 0,"Maximum number of sendfile(2) sf_bufs available")
struct socket * sonewconn(struct socket *head, int connstatus)
int soconnect(struct socket *so, struct sockaddr *nam, struct thread *td)
int sblock(struct sockbuf *sb, int flags)
int kern_socketpair(struct thread *td, int domain, int type, int protocol, int *rsv)
int sys_sendmsg(struct thread *td, struct sendmsg_args *uap)
int kern_connect(struct thread *td, int fd, struct sockaddr *sa)
int kern_accept(struct thread *td, int s, struct sockaddr **name, socklen_t *namelen, struct file **fp)
void fputsock(struct socket *so)
void tdsignal(struct thread *td, int sig)
int sys_setsockopt(struct thread *td, struct setsockopt_args *uap)
static int accept1(struct thread *td, struct accept_args *uap, int compat)
int soconnect2(struct socket *so1, struct socket *so2)
int vn_rdwr(enum uio_rw rw, struct vnode *vp, void *base, int len, off_t offset, enum uio_seg segflg, int ioflg, struct ucred *active_cred, struct ucred *file_cred, ssize_t *aresid, struct thread *td)
int sys_bind(struct thread *td, struct bind_args *uap)
int sys_sendfile(struct thread *td, struct sendfile_args *uap)
void fdclose(struct filedesc *fdp, struct file *fp, int idx, struct thread *td)
void cv_init(struct cv *cvp, const char *desc)
int kern_getsockname(struct thread *td, int fd, struct sockaddr **sa, socklen_t *alen)
int sys_sctp_peeloff(struct thread *td, struct sctp_peeloff_args *uap)
int sys_socketpair(struct thread *td, struct socketpair_args *uap)
int soshutdown(struct socket *so, int how)
int sosend(struct socket *so, struct sockaddr *addr, struct uio *uio, struct mbuf *top, struct mbuf *control, int flags, struct thread *td)
void free(void *addr, struct malloc_type *mtp)
static int recvit(struct thread *td, int s, struct msghdr *mp, void *namelenp)
static int getpeername1(struct thread *td, struct getpeername_args *uap, int compat)
int fgetsock(struct thread *td, int fd, cap_rights_t rights, struct socket **spp, u_int *fflagp)
int copyinuio(struct iovec *iovp, u_int iovcnt, struct uio **uiop)
static int do_sendfile(struct thread *td, struct sendfile_args *uap, int compat)
void finit(struct file *fp, u_int flag, short type, void *data, struct fileops *ops)
int sys_recvfrom(struct thread *td, struct recvfrom_args *uap)
int sogetopt(struct socket *so, struct sockopt *sopt)
int sys_shutdown(struct thread *td, struct shutdown_args *uap)
void mtx_init(struct mtx *m, const char *name, const char *type, int opts)
int sys_sendto(struct thread *td, struct sendto_args *uap)
void vrele(struct vnode *vp)
int soclose(struct socket *so)
int kern_writev(struct thread *td, int fd, struct uio *auio)
u_int m_length(struct mbuf *m0, struct mbuf **last)
int sys_listen(struct thread *td, struct listen_args *uap)
int fgetvp_read(struct thread *td, int fd, cap_rights_t rights, struct vnode **vpp)
int kern_sendfile(struct thread *td, struct sendfile_args *uap, struct uio *hdr_uio, struct uio *trl_uio, int compat)
int socreate(int dom, struct socket **aso, int type, int proto, struct ucred *cred, struct thread *td)
int kern_sendit(struct thread *td, int s, struct msghdr *mp, int flags, struct mbuf *control, enum uio_seg segflg)
int sys_sctp_generic_recvmsg(struct thread *td, struct sctp_generic_recvmsg_args *uap)
void mtx_destroy(struct mtx *m)
int sys_recvmsg(struct thread *td, struct recvmsg_args *uap)
int soreceive(struct socket *so, struct sockaddr **psa, struct uio *uio, struct mbuf **mp0, struct mbuf **controlp, int *flagsp)
int sys_accept(struct thread *td, struct accept_args *uap)
const struct cf_level * level