From 37654f9d78eafb0fa438f156e67683a3faa82a29 Mon Sep 17 00:00:00 2001 From: rwatson Date: Tue, 23 Nov 2004 15:59:43 +0000 Subject: Assert the tcbinfo write lock in tcp_new_isn(), as the tcbinfo lock protects access to the ISN state variables. Acquire the tcbinfo write lock in tcp_isn_tick() to synchronize timer-driven isn bumping. Staticize internal ISN variables since they're not used outside of tcp_subr.c. MFC after: 2 weeks --- sys/netinet/tcp_subr.c | 15 +++++++++++---- sys/netinet/tcp_timewait.c | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'sys/netinet') diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index f63cb5a..d54b6fa 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -1282,16 +1282,19 @@ tcp6_ctlinput(cmd, sa, d) * between seeding of isn_secret. This is normally set to zero, * as reseeding should not be necessary. * + * Locking of the global variables isn_secret, isn_last_reseed, isn_offset, + * isn_offset_old, and isn_ctx is performed using the TCP pcbinfo lock. In + * general, this means holding an exclusive (write) lock. */ #define ISN_BYTES_PER_SECOND 1048576 #define ISN_STATIC_INCREMENT 4096 #define ISN_RANDOM_INCREMENT (4096 - 1) -u_char isn_secret[32]; -int isn_last_reseed; -u_int32_t isn_offset, isn_offset_old; -MD5_CTX isn_ctx; +static u_char isn_secret[32]; +static int isn_last_reseed; +static u_int32_t isn_offset, isn_offset_old; +static MD5_CTX isn_ctx; tcp_seq tcp_new_isn(tp) @@ -1300,6 +1303,8 @@ tcp_new_isn(tp) u_int32_t md5_buffer[4]; tcp_seq new_isn; + INP_INFO_WLOCK_ASSERT(&tcbinfo); + /* Seed if this is the first use, reseed if requested. */ if ((isn_last_reseed == 0) || ((tcp_isn_reseed_interval > 0) && (((u_int)isn_last_reseed + (u_int)tcp_isn_reseed_interval*hz) @@ -1346,6 +1351,7 @@ tcp_isn_tick(xtp) { u_int32_t projected_offset; + INP_INFO_WLOCK(&tcbinfo); projected_offset = isn_offset_old + ISN_BYTES_PER_SECOND / hz; if (projected_offset > isn_offset) @@ -1353,6 +1359,7 @@ tcp_isn_tick(xtp) isn_offset_old = isn_offset; callout_reset(&isn_callout, 1, tcp_isn_tick, NULL); + INP_INFO_WUNLOCK(&tcbinfo); } /* diff --git a/sys/netinet/tcp_timewait.c b/sys/netinet/tcp_timewait.c index f63cb5a..d54b6fa 100644 --- a/sys/netinet/tcp_timewait.c +++ b/sys/netinet/tcp_timewait.c @@ -1282,16 +1282,19 @@ tcp6_ctlinput(cmd, sa, d) * between seeding of isn_secret. This is normally set to zero, * as reseeding should not be necessary. * + * Locking of the global variables isn_secret, isn_last_reseed, isn_offset, + * isn_offset_old, and isn_ctx is performed using the TCP pcbinfo lock. In + * general, this means holding an exclusive (write) lock. */ #define ISN_BYTES_PER_SECOND 1048576 #define ISN_STATIC_INCREMENT 4096 #define ISN_RANDOM_INCREMENT (4096 - 1) -u_char isn_secret[32]; -int isn_last_reseed; -u_int32_t isn_offset, isn_offset_old; -MD5_CTX isn_ctx; +static u_char isn_secret[32]; +static int isn_last_reseed; +static u_int32_t isn_offset, isn_offset_old; +static MD5_CTX isn_ctx; tcp_seq tcp_new_isn(tp) @@ -1300,6 +1303,8 @@ tcp_new_isn(tp) u_int32_t md5_buffer[4]; tcp_seq new_isn; + INP_INFO_WLOCK_ASSERT(&tcbinfo); + /* Seed if this is the first use, reseed if requested. */ if ((isn_last_reseed == 0) || ((tcp_isn_reseed_interval > 0) && (((u_int)isn_last_reseed + (u_int)tcp_isn_reseed_interval*hz) @@ -1346,6 +1351,7 @@ tcp_isn_tick(xtp) { u_int32_t projected_offset; + INP_INFO_WLOCK(&tcbinfo); projected_offset = isn_offset_old + ISN_BYTES_PER_SECOND / hz; if (projected_offset > isn_offset) @@ -1353,6 +1359,7 @@ tcp_isn_tick(xtp) isn_offset_old = isn_offset; callout_reset(&isn_callout, 1, tcp_isn_tick, NULL); + INP_INFO_WUNLOCK(&tcbinfo); } /* -- cgit v1.1