aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorQuentin Thébault <quentin.thebault@defenso.fr>2025-08-28 08:19:41 +0000
committerWarner Losh <imp@FreeBSD.org>2025-09-12 16:24:38 +0000
commit9fadaee7ecce02ab11cfbb18ea63b9bf1fb11bfc (patch)
tree7aa7a01eda701241e9708cdfdca93fa1b3aadb7d
parent593d432e5852a254eeef83a8b1762492bb08668e (diff)
ng_device: enable setting the device to non-blocking mode
Return success when FIONBIO or FIOASYNC ioctl are received in order to support being set to non-blocking through fcntl(2). We return an error on FIOASYNC with non-zero data argument since we do not support O_ASYNC. Signed-off-by: Quentin Thébault <quentin.thebault@defenso.fr> Reviewed by: imp, jhb Pull Request: https://github.com/freebsd/freebsd-src/pull/1827
-rw-r--r--sys/netgraph/ng_device.c41
1 files changed, 34 insertions, 7 deletions
diff --git a/sys/netgraph/ng_device.c b/sys/netgraph/ng_device.c
index 79cae9933a5a..eca3a916a59f 100644
--- a/sys/netgraph/ng_device.c
+++ b/sys/netgraph/ng_device.c
@@ -38,20 +38,21 @@
#endif
#include <sys/param.h>
+#include <sys/systm.h>
#include <sys/conf.h>
+#include <sys/epoch.h>
+#include <sys/fcntl.h>
+#include <sys/filio.h>
#include <sys/ioccom.h>
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/poll.h>
#include <sys/proc.h>
-#include <sys/epoch.h>
#include <sys/queue.h>
#include <sys/socket.h>
#include <sys/syslog.h>
-#include <sys/systm.h>
#include <sys/uio.h>
-#include <sys/fcntl.h>
#include <net/ethernet.h>
#include <net/if.h>
@@ -135,9 +136,7 @@ static d_close_t ngdclose;
static d_open_t ngdopen;
static d_read_t ngdread;
static d_write_t ngdwrite;
-#if 0
static d_ioctl_t ngdioctl;
-#endif
static d_poll_t ngdpoll;
static struct cdevsw ngd_cdevsw = {
@@ -146,9 +145,7 @@ static struct cdevsw ngd_cdevsw = {
.d_close = ngdclose,
.d_read = ngdread,
.d_write = ngdwrite,
-#if 0
.d_ioctl = ngdioctl,
-#endif
.d_poll = ngdpoll,
.d_name = NG_DEVICE_DEVNAME,
};
@@ -397,6 +394,36 @@ ngdclose(struct cdev *dev, int flag, int mode, struct thread *td)
return(0);
}
+/*
+ * Process IOCTLs
+ *
+ * At this stage we only return success on FIONBIO to allow setting the device
+ * as non-blocking.
+ *
+ */
+static int
+ngdioctl(struct cdev *dev, u_long cmd, caddr_t data, int flag,
+ struct thread *td)
+{
+ int error;
+
+ switch (cmd) {
+ case FIONBIO:
+ error = 0;
+ break;
+ case FIOASYNC:
+ if (*(int *)data != 0)
+ error = EINVAL;
+ else
+ error = 0;
+ break;
+ default:
+ error = ENOTTY;
+ }
+
+ return (error);
+}
+
#if 0 /*
* The ioctl is transformed into netgraph control message.
* We do not process them, yet.