From: Alexander Bluhm Subject: more tcp sysctl variables atomic To: tech@openbsd.org Date: Sat, 28 Dec 2024 15:25:14 +0100 Hi, These tcp sysctl variables are accessed independently. So it is easy to make read access atomic. ok? bluhm Index: netinet/tcp_input.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_input.c,v diff -u -p -r1.413 tcp_input.c --- netinet/tcp_input.c 26 Dec 2024 12:16:17 -0000 1.413 +++ netinet/tcp_input.c 28 Dec 2024 12:37:40 -0000 @@ -170,7 +170,7 @@ do { \ if (m && (m->m_flags & M_PKTHDR)) \ ifp = if_get(m->m_pkthdr.ph_ifidx); \ if (TCP_TIMER_ISARMED(tp, TCPT_DELACK) || \ - (tcp_ack_on_push && (tiflags) & TH_PUSH) || \ + (atomic_load_int(&tcp_ack_on_push) && (tiflags) & TH_PUSH) || \ (ifp && (ifp->if_flags & IFF_LOOPBACK))) \ tp->t_flags |= TF_ACKNOW; \ else \ @@ -2091,7 +2091,7 @@ dropwithreset_ratelim: * a port for which we have no socket. */ if (ppsratecheck(&tcp_rst_ppslim_last, &tcp_rst_ppslim_count, - tcp_rst_ppslim) == 0) { + atomic_load_int(&tcp_rst_ppslim)) == 0) { /* XXX stat */ goto drop; } @@ -3809,7 +3809,8 @@ syn_cache_add(struct sockaddr *src, stru ) { tb.pf = tp->pf; tb.sack_enable = tp->sack_enable; - tb.t_flags = tcp_do_rfc1323 ? (TF_REQ_SCALE|TF_REQ_TSTMP) : 0; + tb.t_flags = atomic_load_int(&tcp_do_rfc1323) ? + (TF_REQ_SCALE|TF_REQ_TSTMP) : 0; #ifdef TCP_SIGNATURE if (tp->t_flags & TF_SIGNATURE) tb.t_flags |= TF_SIGNATURE; Index: netinet/tcp_output.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_output.c,v diff -u -p -r1.147 tcp_output.c --- netinet/tcp_output.c 26 Dec 2024 12:16:17 -0000 1.147 +++ netinet/tcp_output.c 28 Dec 2024 12:43:47 -0000 @@ -348,7 +348,7 @@ again: txmaxseg = ulmin(so->so_snd.sb_hiwat / 2, tp->t_maxseg); if (len > txmaxseg) { - if (tcp_do_tso && + if (atomic_load_int(&tcp_do_tso) && tp->t_inpcb->inp_options == NULL && tp->t_inpcb->inp_outputopts6 == NULL && #ifdef TCP_SIGNATURE Index: netinet/tcp_subr.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_subr.c,v diff -u -p -r1.202 tcp_subr.c --- netinet/tcp_subr.c 26 Dec 2024 10:15:27 -0000 1.202 +++ netinet/tcp_subr.c 28 Dec 2024 12:32:02 -0000 @@ -443,8 +443,9 @@ tcp_newtcpcb(struct inpcb *inp, int wait for (i = 0; i < TCPT_NTIMERS; i++) TCP_TIMER_INIT(tp, i); - tp->sack_enable = tcp_do_sack; - tp->t_flags = tcp_do_rfc1323 ? (TF_REQ_SCALE|TF_REQ_TSTMP) : 0; + tp->sack_enable = atomic_load_int(&tcp_do_sack); + tp->t_flags = atomic_load_int(&tcp_do_rfc1323) ? + (TF_REQ_SCALE|TF_REQ_TSTMP) : 0; tp->t_inpcb = inp; /* * Init srtt to TCPTV_SRTTBASE (0), so we can tell that we have no Index: netinet/tcp_timer.c =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_timer.c,v diff -u -p -r1.77 tcp_timer.c --- netinet/tcp_timer.c 20 Dec 2024 21:30:17 -0000 1.77 +++ netinet/tcp_timer.c 28 Dec 2024 12:41:46 -0000 @@ -465,7 +465,7 @@ tcp_timer_keep(void *arg) tcpstat_inc(tcps_keeptimeo); if (TCPS_HAVEESTABLISHED(tp->t_state) == 0) goto dropit; - if ((tcp_always_keepalive || + if ((atomic_load_int(&tcp_always_keepalive) || tp->t_inpcb->inp_socket->so_options & SO_KEEPALIVE) && tp->t_state <= TCPS_CLOSING) { int maxidle; Index: netinet/tcp_timer.h =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_timer.h,v diff -u -p -r1.22 tcp_timer.h --- netinet/tcp_timer.h 20 Dec 2024 21:30:17 -0000 1.22 +++ netinet/tcp_timer.h 28 Dec 2024 12:42:07 -0000 @@ -155,7 +155,7 @@ extern const tcp_timer_func_t tcp_timer_ extern int tcp_delack_msecs; /* delayed ACK timeout in millisecs */ extern int tcptv_keep_init; -extern int tcp_always_keepalive; /* assume SO_KEEPALIVE is always set */ +extern int tcp_always_keepalive; /* [a] assume SO_KEEPALIVE always set */ extern int tcp_keepidle; /* time before keepalive probes begin */ extern int tcp_keepintvl; /* time between keepalive probes */ extern int tcp_maxidle; /* time to drop after starting probes */ Index: netinet/tcp_var.h =================================================================== RCS file: /data/mirror/openbsd/cvs/src/sys/netinet/tcp_var.h,v diff -u -p -r1.180 tcp_var.h --- netinet/tcp_var.h 26 Dec 2024 12:16:17 -0000 1.180 +++ netinet/tcp_var.h 28 Dec 2024 12:45:26 -0000 @@ -677,18 +677,18 @@ extern const struct pr_usrreqs tcp6_usrr extern struct pool tcpcb_pool; extern struct inpcbtable tcbtable, tcb6table; /* queue of active tcpcb's */ -extern int tcp_do_rfc1323; /* enabled/disabled? */ +extern int tcp_do_rfc1323; /* [a] enabled/disabled? */ extern const int tcprexmtthresh; extern int tcptv_keep_init; /* [N] time to keep alive initial SYN packet */ extern int tcp_mssdflt; /* [a] default maximum segment size */ -extern int tcp_rst_ppslim; /* maximum outgoing RST packet per second */ -extern int tcp_ack_on_push; /* ACK immediately on PUSH */ -extern int tcp_do_sack; /* SACK enabled/disabled */ +extern int tcp_rst_ppslim; /* [a] maximum outgoing RST packet per second */ +extern int tcp_ack_on_push; /* [a] ACK immediately on PUSH */ +extern int tcp_do_sack; /* [a] SACK enabled/disabled */ extern struct pool sackhl_pool; extern int tcp_sackhole_limit; /* max entries for tcp sack queues */ extern int tcp_do_ecn; /* RFC3168 ECN enabled/disabled? */ -extern int tcp_do_rfc3390; /* RFC3390 Increasing TCP's Initial Window */ -extern int tcp_do_tso; /* enable TSO for TCP output packets */ +extern int tcp_do_rfc3390; /* [a] RFC3390 Increasing TCP Initial Window */ +extern int tcp_do_tso; /* [a] enable TSO for TCP output packets */ extern struct pool tcpqe_pool; extern int tcp_reass_limit; /* max entries for tcp reass queues */