git: c261510ef5fc - main - sockets: fix setsockopt(SO_RCVTIMEO) on a listening socket
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 08 Jul 2022 18:34:18 UTC
The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=c261510ef5fce9eaf4c30685c317c1f8ec415eda commit c261510ef5fce9eaf4c30685c317c1f8ec415eda Author: Gleb Smirnoff <glebius@FreeBSD.org> AuthorDate: 2022-07-08 18:22:53 +0000 Commit: Gleb Smirnoff <glebius@FreeBSD.org> CommitDate: 2022-07-08 18:33:24 +0000 sockets: fix setsockopt(SO_RCVTIMEO) on a listening socket MFC after: 3 weeks --- sys/kern/uipc_socket.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/sys/kern/uipc_socket.c b/sys/kern/uipc_socket.c index f25db7be1fd8..dac1373773fb 100644 --- a/sys/kern/uipc_socket.c +++ b/sys/kern/uipc_socket.c @@ -2967,7 +2967,7 @@ sosetopt(struct socket *so, struct sockopt *sopt) int error, optval; struct linger l; struct timeval tv; - sbintime_t val; + sbintime_t val, *valp; uint32_t val32; #ifdef MAC struct mac extmac; @@ -3106,14 +3106,14 @@ sosetopt(struct socket *so, struct sockopt *sopt) val = SBT_MAX; else val = tvtosbt(tv); - switch (sopt->sopt_name) { - case SO_SNDTIMEO: - so->so_snd.sb_timeo = val; - break; - case SO_RCVTIMEO: - so->so_rcv.sb_timeo = val; - break; - } + SOCK_LOCK(so); + valp = sopt->sopt_name == SO_SNDTIMEO ? + (SOLISTENING(so) ? &so->sol_sbsnd_timeo : + &so->so_snd.sb_timeo) : + (SOLISTENING(so) ? &so->sol_sbrcv_timeo : + &so->so_rcv.sb_timeo); + *valp = val; + SOCK_UNLOCK(so); break; case SO_LABEL: @@ -3295,8 +3295,13 @@ integer: case SO_SNDTIMEO: case SO_RCVTIMEO: + SOCK_LOCK(so); tv = sbttotv(sopt->sopt_name == SO_SNDTIMEO ? - so->so_snd.sb_timeo : so->so_rcv.sb_timeo); + (SOLISTENING(so) ? so->sol_sbsnd_timeo : + so->so_snd.sb_timeo) : + (SOLISTENING(so) ? so->sol_sbrcv_timeo : + so->so_rcv.sb_timeo)); + SOCK_UNLOCK(so); #ifdef COMPAT_FREEBSD32 if (SV_CURPROC_FLAG(SV_ILP32)) { struct timeval32 tv32;