sockets: fix setsockopt(SO_RCVTIMEO) on a listening socket

MFC after:	3 weeks
This commit is contained in:
Gleb Smirnoff 2022-07-08 11:22:53 -07:00
parent 7f7a804ae0
commit c261510ef5

View File

@ -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 @@ sogetopt(struct socket *so, struct sockopt *sopt)
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;