diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -1755,7 +1755,7 @@ int isipv6; #endif /* INET6 */ int optlen, tlen, win, ulen; - bool incl_opts; + bool incl_opts, lock_upgraded; uint16_t port; int output_ret; @@ -2088,21 +2088,29 @@ TCP_PROBE3(debug__output, tp, th, m); if (flags & TH_RST) TCP_PROBE5(accept__refused, NULL, NULL, m, tp, nth); + lock_upgraded = false; + lgb = NULL; if ((tp != NULL) && (tp->t_logstate != TCP_LOG_STATE_OFF)) { union tcp_log_stackspecific log; struct timeval tv; - memset(&log.u_bbr, 0, sizeof(log.u_bbr)); - log.u_bbr.inhpts = tp->t_inpcb->inp_in_hpts; - log.u_bbr.ininput = tp->t_inpcb->inp_in_input; - log.u_bbr.flex8 = 4; - log.u_bbr.pkts_out = tp->t_maxseg; - log.u_bbr.timeStamp = tcp_get_usecs(&tv); - log.u_bbr.delivered = 0; - lgb = tcp_log_event_(tp, nth, NULL, NULL, TCP_LOG_OUT, ERRNO_UNK, - 0, &log, false, NULL, NULL, 0, &tv); - } else - lgb = NULL; + lock_upgraded = !INP_WLOCKED(inp) && INP_TRY_UPGRADE(inp); + /* + *`If we don't already own the write lock and can't upgrade, + * just don't log the event, but still send the response. + */ + if (INP_WLOCKED(inp)) { + memset(&log.u_bbr, 0, sizeof(log.u_bbr)); + log.u_bbr.inhpts = tp->t_inpcb->inp_in_hpts; + log.u_bbr.ininput = tp->t_inpcb->inp_in_input; + log.u_bbr.flex8 = 4; + log.u_bbr.pkts_out = tp->t_maxseg; + log.u_bbr.timeStamp = tcp_get_usecs(&tv); + log.u_bbr.delivered = 0; + lgb = tcp_log_event_(tp, nth, NULL, NULL, TCP_LOG_OUT, ERRNO_UNK, + 0, &log, false, NULL, NULL, 0, &tv); + } + } #ifdef INET6 if (isipv6) { @@ -2119,10 +2127,10 @@ output_ret = ip_output(m, NULL, NULL, 0, NULL, inp); } #endif - if (lgb) { + if (lgb != NULL) lgb->tlb_errno = output_ret; - lgb = NULL; - } + if (lock_upgraded) + INP_DOWNGRADE(inp); } /*