git: c3276e02beab - main - sockets: make shutdown(2) how argument a enum
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 16 Jan 2024 18:31:32 UTC
The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=c3276e02beab825824e3147b31af33af66298430 commit c3276e02beab825824e3147b31af33af66298430 Author: Gleb Smirnoff <glebius@FreeBSD.org> AuthorDate: 2024-01-16 18:26:10 +0000 Commit: Gleb Smirnoff <glebius@FreeBSD.org> CommitDate: 2024-01-16 18:26:27 +0000 sockets: make shutdown(2) how argument a enum Reviwed by: tuexen Differential Revision: https://reviews.freebsd.org/D43412 --- sys/kern/uipc_socket.c | 5 +---- sys/kern/uipc_syscalls.c | 3 +++ sys/sys/socket.h | 8 +++++--- sys/sys/socketvar.h | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index 3409a7085df6..919879e86e21 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -2964,14 +2964,11 @@ soreceive(struct socket *so, struct sockaddr **psa, struct uio *uio, } int -soshutdown(struct socket *so, int how) +soshutdown(struct socket *so, enum shutdown_how how) { struct protosw *pr; int error, soerror_enotconn; - if (!(how == SHUT_RD || how == SHUT_WR || how == SHUT_RDWR)) - return (EINVAL); - soerror_enotconn = 0; SOCK_LOCK(so); if ((so->so_state & diff --git a/sys/kern/uipc_syscalls.c b/sys/kern/uipc_syscalls.c index e46fdef84fc9..366698054bce 100644 --- a/sys/kern/uipc_syscalls.c +++ b/sys/kern/uipc_syscalls.c @@ -1172,6 +1172,9 @@ kern_shutdown(struct thread *td, int s, int how) struct file *fp; int error; + if (__predict_false(how < SHUT_RD || how > SHUT_RDWR)) + return (EINVAL); + AUDIT_ARG_FD(s); error = getsock(td, s, &cap_shutdown_rights, &fp); if (error == 0) { diff --git a/sys/sys/socket.h b/sys/sys/socket.h index 23762ec3b78f..9e78281e5dd2 100644 --- a/sys/sys/socket.h +++ b/sys/sys/socket.h @@ -627,9 +627,11 @@ struct omsghdr { /* * howto arguments for shutdown(2), specified by Posix.1g. */ -#define SHUT_RD 0 /* shut down the reading side */ -#define SHUT_WR 1 /* shut down the writing side */ -#define SHUT_RDWR 2 /* shut down both sides */ +enum shutdown_how { + SHUT_RD = 0, /* shut down the reading side */ + SHUT_WR, /* shut down the writing side */ + SHUT_RDWR /* shut down both sides */ +}; #if __BSD_VISIBLE /* for SCTP */ diff --git a/sys/sys/socketvar.h b/sys/sys/socketvar.h index ae7baa87d202..19ca52177d17 100644 --- a/sys/sys/socketvar.h +++ b/sys/sys/socketvar.h @@ -434,6 +434,7 @@ struct mbuf; struct sockaddr; struct ucred; struct uio; +enum shutdown_how; /* Return values for socket upcalls. */ #define SU_OK 0 @@ -512,7 +513,7 @@ int sosend_dgram(struct socket *so, struct sockaddr *addr, int sosend_generic(struct socket *so, struct sockaddr *addr, struct uio *uio, struct mbuf *top, struct mbuf *control, int flags, struct thread *td); -int soshutdown(struct socket *so, int how); +int soshutdown(struct socket *so, enum shutdown_how); void soupcall_clear(struct socket *, sb_which); void soupcall_set(struct socket *, sb_which, so_upcall_t, void *); void solisten_upcall_set(struct socket *, so_upcall_t, void *);