aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Chagin <dchagin@FreeBSD.org>2023-08-19 18:55:23 +0000
committerDmitry Chagin <dchagin@FreeBSD.org>2023-08-19 18:55:23 +0000
commitda5a6738d589d748ddf93678767d1565558bddd9 (patch)
tree159e890fc87b2d1e644347f33c11f4aa3f7ce4dd
parent1095da75032b439d893c0947eda2f3738ecfe494 (diff)
downloadsrc-da5a6738d589d748ddf93678767d1565558bddd9.tar.gz
src-da5a6738d589d748ddf93678767d1565558bddd9.zip
linux(4): Allow in fd to be a socket in sendfile
In this case sendfile fallback is used. MFC after: 1 month
-rw-r--r--sys/compat/linux/linux_socket.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/sys/compat/linux/linux_socket.c b/sys/compat/linux/linux_socket.c
index 6c7cf12cf42e..67736ecc69f6 100644
--- a/sys/compat/linux/linux_socket.c
+++ b/sys/compat/linux/linux_socket.c
@@ -2381,16 +2381,24 @@ out:
* with FreeBSD sendfile.
*/
static bool
-is_stream_socket(struct file *fp)
+is_sendfile(struct file *fp, struct file *ofp)
{
struct socket *so;
/*
+ * FreeBSD sendfile() system call sends a regular file or
+ * shared memory object out a stream socket.
+ */
+ if ((fp->f_type != DTYPE_SHM && fp->f_type != DTYPE_VNODE) ||
+ (fp->f_type == DTYPE_VNODE &&
+ (fp->f_vnode == NULL || fp->f_vnode->v_type != VREG)))
+ return (false);
+ /*
* The socket must be a stream socket and connected.
*/
- if (fp->f_type != DTYPE_SOCKET)
+ if (ofp->f_type != DTYPE_SOCKET)
return (false);
- so = fp->f_data;
+ so = ofp->f_data;
if (so->so_type != SOCK_STREAM)
return (false);
/*
@@ -2556,7 +2564,7 @@ linux_sendfile_common(struct thread *td, l_int out, l_int in,
0);
} else {
sbytes = 0;
- if (is_stream_socket(ofp))
+ if (is_sendfile(fp, ofp))
error = sendfile_sendfile(td, fp, out, offset, count,
&sbytes);
else