Conflicts:
acinclude.m4
config-win32.h
configure.ac
misc.c
thread.c
thread.h
- These conflicts was mainly due to feat_misc getting old
and mostly caused by the pthread clean-up patches in
feat_misc
Signed-off-by: David Sommerseth <dazo@users.sourceforge.net>
... | ... |
@@ -129,227 +129,3 @@ AC_DEFUN([TYPE_SOCKLEN_T], |
129 | 129 |
[#include <sys/types.h> |
130 | 130 |
#include <sys/socket.h>]) |
131 | 131 |
]) |
132 |
- |
|
133 |
-dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) |
|
134 |
-dnl |
|
135 |
-dnl This macro figures out how to build C programs using POSIX |
|
136 |
-dnl threads. It sets the PTHREAD_LIBS output variable to the threads |
|
137 |
-dnl library and linker flags, and the PTHREAD_CFLAGS output variable |
|
138 |
-dnl to any special C compiler flags that are needed. (The user can also |
|
139 |
-dnl force certain compiler flags/libs to be tested by setting these |
|
140 |
-dnl environment variables.) |
|
141 |
-dnl |
|
142 |
-dnl Also sets PTHREAD_CC to any special C compiler that is needed for |
|
143 |
-dnl multi-threaded programs (defaults to the value of CC otherwise). |
|
144 |
-dnl (This is necessary on AIX to use the special cc_r compiler alias.) |
|
145 |
-dnl |
|
146 |
-dnl If you are only building threads programs, you may wish to |
|
147 |
-dnl use these variables in your default LIBS, CFLAGS, and CC: |
|
148 |
-dnl |
|
149 |
-dnl LIBS="$PTHREAD_LIBS $LIBS" |
|
150 |
-dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS" |
|
151 |
-dnl CC="$PTHREAD_CC" |
|
152 |
-dnl |
|
153 |
-dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute |
|
154 |
-dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE |
|
155 |
-dnl to that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). |
|
156 |
-dnl |
|
157 |
-dnl ACTION-IF-FOUND is a list of shell commands to run if a threads |
|
158 |
-dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands |
|
159 |
-dnl to run it if it is not found. If ACTION-IF-FOUND is not specified, |
|
160 |
-dnl the default action will define HAVE_PTHREAD. |
|
161 |
-dnl |
|
162 |
-dnl Please let the authors know if this macro fails on any platform, |
|
163 |
-dnl or if you have any other suggestions or comments. This macro was |
|
164 |
-dnl based on work by SGJ on autoconf scripts for FFTW (www.fftw.org) |
|
165 |
-dnl (with help from M. Frigo), as well as ac_pthread and hb_pthread |
|
166 |
-dnl macros posted by AFC to the autoconf macro repository. We are also |
|
167 |
-dnl grateful for the helpful feedback of numerous users. |
|
168 |
-dnl |
|
169 |
-dnl @author Steven G. Johnson <stevenj@alum.mit.edu> and Alejandro Forero Cuervo <bachue@bachue.com> |
|
170 |
- |
|
171 |
-AC_DEFUN([ACX_PTHREAD], [ |
|
172 |
-AC_REQUIRE([AC_CANONICAL_HOST]) |
|
173 |
-acx_pthread_ok=no |
|
174 |
- |
|
175 |
-# We used to check for pthread.h first, but this fails if pthread.h |
|
176 |
-# requires special compiler flags (e.g. on True64 or Sequent). |
|
177 |
-# It gets checked for in the link test anyway. |
|
178 |
- |
|
179 |
-# First of all, check if the user has set any of the PTHREAD_LIBS, |
|
180 |
-# etcetera environment variables, and if threads linking works using |
|
181 |
-# them: |
|
182 |
-if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then |
|
183 |
- save_CFLAGS="$CFLAGS" |
|
184 |
- CFLAGS="$CFLAGS $PTHREAD_CFLAGS" |
|
185 |
- save_LIBS="$LIBS" |
|
186 |
- LIBS="$PTHREAD_LIBS $LIBS" |
|
187 |
- AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) |
|
188 |
- AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes) |
|
189 |
- AC_MSG_RESULT($acx_pthread_ok) |
|
190 |
- if test x"$acx_pthread_ok" = xno; then |
|
191 |
- PTHREAD_LIBS="" |
|
192 |
- PTHREAD_CFLAGS="" |
|
193 |
- fi |
|
194 |
- LIBS="$save_LIBS" |
|
195 |
- CFLAGS="$save_CFLAGS" |
|
196 |
-fi |
|
197 |
- |
|
198 |
-# We must check for the threads library under a number of different |
|
199 |
-# names; the ordering is very important because some systems |
|
200 |
-# (e.g. DEC) have both -lpthread and -lpthreads, where one of the |
|
201 |
-# libraries is broken (non-POSIX). |
|
202 |
- |
|
203 |
-# Create a list of thread flags to try. Items starting with a "-" are |
|
204 |
-# C compiler flags, and other items are library names, except for "none" |
|
205 |
-# which indicates that we try without any flags at all. |
|
206 |
- |
|
207 |
-acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt" |
|
208 |
- |
|
209 |
-# The ordering *is* (sometimes) important. Some notes on the |
|
210 |
-# individual items follow: |
|
211 |
- |
|
212 |
-# pthreads: AIX (must check this before -lpthread) |
|
213 |
-# none: in case threads are in libc; should be tried before -Kthread and |
|
214 |
-# other compiler flags to prevent continual compiler warnings |
|
215 |
-# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) |
|
216 |
-# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) |
|
217 |
-# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) |
|
218 |
-# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) |
|
219 |
-# -pthreads: Solaris/gcc |
|
220 |
-# -mthreads: Mingw32/gcc, Lynx/gcc |
|
221 |
-# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it |
|
222 |
-# doesn't hurt to check since this sometimes defines pthreads too; |
|
223 |
-# also defines -D_REENTRANT) |
|
224 |
-# pthread: Linux, etcetera |
|
225 |
-# --thread-safe: KAI C++ |
|
226 |
- |
|
227 |
-case "$host" in |
|
228 |
- *-*-solaris*) |
|
229 |
- |
|
230 |
- # On Solaris (at least, for some versions), libc contains stubbed |
|
231 |
- # (non-functional) versions of the pthreads routines, so link-based |
|
232 |
- # tests will erroneously succeed. (We need to link with -pthread or |
|
233 |
- # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather |
|
234 |
- # a function called by this macro, so we could check for that, but |
|
235 |
- # who knows whether they'll stub that too in a future libc.) So, |
|
236 |
- # we'll just look for -pthreads and -lpthread first: |
|
237 |
- |
|
238 |
- acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags" |
|
239 |
- ;; |
|
240 |
-esac |
|
241 |
- |
|
242 |
-if test x"$acx_pthread_ok" = xno; then |
|
243 |
-for flag in $acx_pthread_flags; do |
|
244 |
- |
|
245 |
- case $flag in |
|
246 |
- none) |
|
247 |
- AC_MSG_CHECKING([whether pthreads work without any flags]) |
|
248 |
- ;; |
|
249 |
- |
|
250 |
- -*) |
|
251 |
- AC_MSG_CHECKING([whether pthreads work with $flag]) |
|
252 |
- PTHREAD_CFLAGS="$flag" |
|
253 |
- ;; |
|
254 |
- |
|
255 |
- *) |
|
256 |
- AC_MSG_CHECKING([for the pthreads library -l$flag]) |
|
257 |
- PTHREAD_LIBS="-l$flag" |
|
258 |
- ;; |
|
259 |
- esac |
|
260 |
- |
|
261 |
- save_LIBS="$LIBS" |
|
262 |
- save_CFLAGS="$CFLAGS" |
|
263 |
- LIBS="$PTHREAD_LIBS $LIBS" |
|
264 |
- CFLAGS="$CFLAGS $PTHREAD_CFLAGS" |
|
265 |
- |
|
266 |
- # Check for various functions. We must include pthread.h, |
|
267 |
- # since some functions may be macros. (On the Sequent, we |
|
268 |
- # need a special flag -Kthread to make this header compile.) |
|
269 |
- # We check for pthread_join because it is in -lpthread on IRIX |
|
270 |
- # while pthread_create is in libc. We check for pthread_attr_init |
|
271 |
- # due to DEC craziness with -lpthreads. We check for |
|
272 |
- # pthread_cleanup_push because it is one of the few pthread |
|
273 |
- # functions on Solaris that doesn't have a non-functional libc stub. |
|
274 |
- # We try pthread_create on general principles. |
|
275 |
- AC_TRY_LINK([#include <pthread.h>], |
|
276 |
- [pthread_t th; pthread_join(th, 0); |
|
277 |
- pthread_attr_init(0); pthread_cleanup_push(0, 0); |
|
278 |
- pthread_create(0,0,0,0); pthread_cleanup_pop(0); ], |
|
279 |
- [acx_pthread_ok=yes]) |
|
280 |
- |
|
281 |
- LIBS="$save_LIBS" |
|
282 |
- CFLAGS="$save_CFLAGS" |
|
283 |
- |
|
284 |
- AC_MSG_RESULT($acx_pthread_ok) |
|
285 |
- if test "x$acx_pthread_ok" = xyes; then |
|
286 |
- break; |
|
287 |
- fi |
|
288 |
- |
|
289 |
- PTHREAD_LIBS="" |
|
290 |
- PTHREAD_CFLAGS="" |
|
291 |
-done |
|
292 |
-fi |
|
293 |
- |
|
294 |
-# Various other checks: |
|
295 |
-if test "x$acx_pthread_ok" = xyes; then |
|
296 |
- save_LIBS="$LIBS" |
|
297 |
- LIBS="$PTHREAD_LIBS $LIBS" |
|
298 |
- save_CFLAGS="$CFLAGS" |
|
299 |
- CFLAGS="$CFLAGS $PTHREAD_CFLAGS" |
|
300 |
- |
|
301 |
- # Detect AIX lossage: threads are created detached by default |
|
302 |
- # and the JOINABLE attribute has a nonstandard name (UNDETACHED). |
|
303 |
- AC_MSG_CHECKING([for joinable pthread attribute]) |
|
304 |
- AC_TRY_LINK([#include <pthread.h>], |
|
305 |
- [int attr=PTHREAD_CREATE_JOINABLE;], |
|
306 |
- ok=PTHREAD_CREATE_JOINABLE, ok=unknown) |
|
307 |
- if test x"$ok" = xunknown; then |
|
308 |
- AC_TRY_LINK([#include <pthread.h>], |
|
309 |
- [int attr=PTHREAD_CREATE_UNDETACHED;], |
|
310 |
- ok=PTHREAD_CREATE_UNDETACHED, ok=unknown) |
|
311 |
- fi |
|
312 |
- if test x"$ok" != xPTHREAD_CREATE_JOINABLE; then |
|
313 |
- AC_DEFINE(PTHREAD_CREATE_JOINABLE, $ok, |
|
314 |
- [Define to the necessary symbol if this constant |
|
315 |
- uses a non-standard name on your system.]) |
|
316 |
- fi |
|
317 |
- AC_MSG_RESULT(${ok}) |
|
318 |
- if test x"$ok" = xunknown; then |
|
319 |
- AC_MSG_WARN([we do not know how to create joinable pthreads]) |
|
320 |
- fi |
|
321 |
- |
|
322 |
- AC_MSG_CHECKING([if more special flags are required for pthreads]) |
|
323 |
- flag=no |
|
324 |
- case "$host" in |
|
325 |
- *-*-aix* | *-freebsd*) flag="-D_THREAD_SAFE";; |
|
326 |
- *-*-solaris* | alpha*-osf* | *linux*) flag="-D_REENTRANT";; |
|
327 |
- esac |
|
328 |
- AC_MSG_RESULT(${flag}) |
|
329 |
- if test "x$flag" != xno; then |
|
330 |
- PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" |
|
331 |
- fi |
|
332 |
- |
|
333 |
- LIBS="$save_LIBS" |
|
334 |
- CFLAGS="$save_CFLAGS" |
|
335 |
- |
|
336 |
- # More AIX lossage: must compile with cc_r |
|
337 |
- AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC}) |
|
338 |
-else |
|
339 |
- PTHREAD_CC="$CC" |
|
340 |
-fi |
|
341 |
- |
|
342 |
-AC_SUBST(PTHREAD_LIBS) |
|
343 |
-AC_SUBST(PTHREAD_CFLAGS) |
|
344 |
-AC_SUBST(PTHREAD_CC) |
|
345 |
- |
|
346 |
-# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: |
|
347 |
-if test x"$acx_pthread_ok" = xyes; then |
|
348 |
- ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) |
|
349 |
- : |
|
350 |
-else |
|
351 |
- acx_pthread_ok=no |
|
352 |
- $2 |
|
353 |
-fi |
|
354 |
- |
|
355 |
-])dnl ACX_PTHREAD |
... | ... |
@@ -28,7 +28,6 @@ |
28 | 28 |
#include "buffer.h" |
29 | 29 |
#include "error.h" |
30 | 30 |
#include "mtu.h" |
31 |
-#include "thread.h" |
|
32 | 31 |
|
33 | 32 |
#include "memdbg.h" |
34 | 33 |
|
... | ... |
@@ -299,10 +298,8 @@ gc_malloc (size_t size, bool clear, struct gc_arena *a) |
299 | 299 |
#endif |
300 | 300 |
check_malloc_return (e); |
301 | 301 |
ret = (char *) e + sizeof (struct gc_entry); |
302 |
- /*mutex_lock_static (L_GC_MALLOC);*/ |
|
303 | 302 |
e->next = a->list; |
304 | 303 |
a->list = e; |
305 |
- /*mutex_unlock_static (L_GC_MALLOC);*/ |
|
306 | 304 |
} |
307 | 305 |
else |
308 | 306 |
{ |
... | ... |
@@ -324,10 +321,8 @@ void |
324 | 324 |
x_gc_free (struct gc_arena *a) |
325 | 325 |
{ |
326 | 326 |
struct gc_entry *e; |
327 |
- /*mutex_lock_static (L_GC_MALLOC);*/ |
|
328 | 327 |
e = a->list; |
329 | 328 |
a->list = NULL; |
330 |
- /*mutex_unlock_static (L_GC_MALLOC);*/ |
|
331 | 329 |
|
332 | 330 |
while (e != NULL) |
333 | 331 |
{ |
... | ... |
@@ -158,12 +158,6 @@ AC_ARG_ENABLE(small, |
158 | 158 |
[SMALL="no"] |
159 | 159 |
) |
160 | 160 |
|
161 |
-AC_ARG_ENABLE(pthread, |
|
162 |
- [ --enable-pthread Enable pthread support (Experimental for OpenVPN 2.0)], |
|
163 |
- [PTHREAD="$enableval"], |
|
164 |
- [PTHREAD="no"] |
|
165 |
-) |
|
166 |
- |
|
167 | 161 |
AC_ARG_ENABLE(password-save, |
168 | 162 |
[ --enable-password-save Allow --askpass and --auth-user-pass passwords to be read from a file], |
169 | 163 |
[PASSWORD_SAVE="$enableval"], |
... | ... |
@@ -581,32 +575,6 @@ if test "$MEMCHECK" = "valgrind"; then |
581 | 581 |
fi |
582 | 582 |
|
583 | 583 |
dnl |
584 |
-dnl check for pthread library |
|
585 |
-dnl |
|
586 |
- |
|
587 |
-if test "$PTHREAD" = "yes"; then |
|
588 |
- AC_CHECKING([for pthread support]) |
|
589 |
- AC_MSG_RESULT([********* WARNING: pthread support is experimental for OpenVPN 2.0]) |
|
590 |
- ACX_PTHREAD( |
|
591 |
- [ |
|
592 |
- case "$host" in |
|
593 |
- *openbsd*) |
|
594 |
- AC_MSG_RESULT([WARNING: pthread support on OpenBSD is unstable!]) |
|
595 |
- CFLAGS="$CFLAGS -pthread" |
|
596 |
- ;; |
|
597 |
- esac |
|
598 |
- LIBS="$PTHREAD_LIBS $LIBS" |
|
599 |
- CFLAGS="$CFLAGS $PTHREAD_CFLAGS" |
|
600 |
- CC="$PTHREAD_CC" |
|
601 |
- AC_DEFINE(USE_PTHREAD, 1, [Use pthread-based multithreading]) |
|
602 |
- ], |
|
603 |
- [ |
|
604 |
- AC_MSG_RESULT([I don't know how to build with pthread support on this platform.]) |
|
605 |
- AC_MSG_ERROR([try ./configure --disable-pthread]) |
|
606 |
- ]) |
|
607 |
-fi |
|
608 |
- |
|
609 |
-dnl |
|
610 | 584 |
dnl check for dmalloc library |
611 | 585 |
dnl |
612 | 586 |
|
... | ... |
@@ -615,11 +583,7 @@ if test "$MEMCHECK" = "dmalloc"; then |
615 | 615 |
AC_CHECK_HEADER(dmalloc.h, |
616 | 616 |
[AC_CHECK_LIB(dmalloc, malloc, |
617 | 617 |
[ |
618 |
- if test "$PTHREAD" = "yes"; then |
|
619 |
- OPENVPN_ADD_LIBS(-ldmallocth) |
|
620 |
- else |
|
621 |
- OPENVPN_ADD_LIBS(-ldmalloc) |
|
622 |
- fi |
|
618 |
+ OPENVPN_ADD_LIBS(-ldmalloc) |
|
623 | 619 |
AC_DEFINE(DMALLOC, 1, [Use dmalloc memory debugging library]) |
624 | 620 |
], |
625 | 621 |
[AC_MSG_ERROR([dmalloc library not found.])] |
... | ... |
@@ -29,7 +29,6 @@ |
29 | 29 |
#include "crypto.h" |
30 | 30 |
#include "error.h" |
31 | 31 |
#include "misc.h" |
32 |
-#include "thread.h" |
|
33 | 32 |
|
34 | 33 |
#include "memdbg.h" |
35 | 34 |
|
... | ... |
@@ -1702,7 +1701,6 @@ prng_bytes (uint8_t *output, int len) |
1702 | 1702 |
{ |
1703 | 1703 |
EVP_MD_CTX ctx; |
1704 | 1704 |
const int md_size = EVP_MD_size (nonce_md); |
1705 |
- mutex_lock_static (L_PRNG); |
|
1706 | 1705 |
while (len > 0) |
1707 | 1706 |
{ |
1708 | 1707 |
unsigned int outlen = 0; |
... | ... |
@@ -1716,7 +1714,6 @@ prng_bytes (uint8_t *output, int len) |
1716 | 1716 |
output += blen; |
1717 | 1717 |
len -= blen; |
1718 | 1718 |
} |
1719 |
- mutex_unlock_static (L_PRNG); |
|
1720 | 1719 |
} |
1721 | 1720 |
else |
1722 | 1721 |
RAND_bytes (output, len); |
... | ... |
@@ -470,5 +470,7 @@ int SSL_CTX_use_CryptoAPI_certificate(SSL_CTX *ssl_ctx, const char *cert_prop) |
470 | 470 |
} |
471 | 471 |
|
472 | 472 |
#else |
473 |
+#ifdef _MSC_VER /* Dummy function needed to avoid empty file compiler warning in Microsoft VC */ |
|
473 | 474 |
static void dummy (void) {} |
475 |
+#endif |
|
474 | 476 |
#endif /* WIN32 */ |
... | ... |
@@ -26,7 +26,6 @@ |
26 | 26 |
|
27 | 27 |
#include "error.h" |
28 | 28 |
#include "buffer.h" |
29 |
-#include "thread.h" |
|
30 | 29 |
#include "misc.h" |
31 | 30 |
#include "win32.h" |
32 | 31 |
#include "socket.h" |
... | ... |
@@ -229,8 +228,6 @@ void x_msg (const unsigned int flags, const char *format, ...) |
229 | 229 |
|
230 | 230 |
gc_init (&gc); |
231 | 231 |
|
232 |
- mutex_lock_static (L_MSG); |
|
233 |
- |
|
234 | 232 |
m1 = (char *) gc_malloc (ERR_BUF_SIZE, false, &gc); |
235 | 233 |
m2 = (char *) gc_malloc (ERR_BUF_SIZE, false, &gc); |
236 | 234 |
|
... | ... |
@@ -330,22 +327,12 @@ void x_msg (const unsigned int flags, const char *format, ...) |
330 | 330 |
} |
331 | 331 |
else |
332 | 332 |
{ |
333 |
-#ifdef USE_PTHREAD |
|
334 |
- fprintf (fp, "%s [%d] %s%s%s%s", |
|
335 |
- time_string (0, 0, show_usec, &gc), |
|
336 |
- (int) openvpn_thread_self (), |
|
337 |
- prefix, |
|
338 |
- prefix_sep, |
|
339 |
- m1, |
|
340 |
- (flags&M_NOLF) ? "" : "\n"); |
|
341 |
-#else |
|
342 | 333 |
fprintf (fp, "%s %s%s%s%s", |
343 | 334 |
time_string (0, 0, show_usec, &gc), |
344 | 335 |
prefix, |
345 | 336 |
prefix_sep, |
346 | 337 |
m1, |
347 | 338 |
(flags&M_NOLF) ? "" : "\n"); |
348 |
-#endif |
|
349 | 339 |
} |
350 | 340 |
fflush(fp); |
351 | 341 |
++x_msg_line_num; |
... | ... |
@@ -355,8 +342,6 @@ void x_msg (const unsigned int flags, const char *format, ...) |
355 | 355 |
if (flags & M_FATAL) |
356 | 356 |
msg (M_INFO, "Exiting"); |
357 | 357 |
|
358 |
- mutex_unlock_static (L_MSG); |
|
359 |
- |
|
360 | 358 |
if (flags & M_FATAL) |
361 | 359 |
openvpn_exit (OPENVPN_EXIT_STATUS_ERROR); /* exit point */ |
362 | 360 |
|
... | ... |
@@ -653,10 +638,6 @@ x_check_status (int status, |
653 | 653 |
*/ |
654 | 654 |
const char *x_msg_prefix; /* GLOBAL */ |
655 | 655 |
|
656 |
-#ifdef USE_PTHREAD |
|
657 |
-pthread_key_t x_msg_prefix_key; /* GLOBAL */ |
|
658 |
-#endif |
|
659 |
- |
|
660 | 656 |
/* |
661 | 657 |
* Allow MSG to be redirected through a virtual_output object |
662 | 658 |
*/ |
... | ... |
@@ -664,26 +645,6 @@ pthread_key_t x_msg_prefix_key; /* GLOBAL */ |
664 | 664 |
const struct virtual_output *x_msg_virtual_output; /* GLOBAL */ |
665 | 665 |
|
666 | 666 |
/* |
667 |
- * Init thread-local variables |
|
668 |
- */ |
|
669 |
- |
|
670 |
-void |
|
671 |
-msg_thread_init (void) |
|
672 |
-{ |
|
673 |
-#ifdef USE_PTHREAD |
|
674 |
- ASSERT (!pthread_key_create (&x_msg_prefix_key, NULL)); |
|
675 |
-#endif |
|
676 |
-} |
|
677 |
- |
|
678 |
-void |
|
679 |
-msg_thread_uninit (void) |
|
680 |
-{ |
|
681 |
-#ifdef USE_PTHREAD |
|
682 |
- pthread_key_delete (x_msg_prefix_key); |
|
683 |
-#endif |
|
684 |
-} |
|
685 |
- |
|
686 |
-/* |
|
687 | 667 |
* Exiting. |
688 | 668 |
*/ |
689 | 669 |
|
... | ... |
@@ -26,7 +26,6 @@ |
26 | 26 |
#define ERROR_H |
27 | 27 |
|
28 | 28 |
#include "basic.h" |
29 |
-#include "thread.h" |
|
30 | 29 |
|
31 | 30 |
/* #define ABORT_ON_ERROR */ |
32 | 31 |
|
... | ... |
@@ -282,34 +281,18 @@ set_check_status_error_delay (unsigned int milliseconds) |
282 | 282 |
|
283 | 283 |
extern const char *x_msg_prefix; |
284 | 284 |
|
285 |
-#ifdef USE_PTHREAD |
|
286 |
-extern pthread_key_t x_msg_prefix_key; |
|
287 |
-#endif |
|
288 |
- |
|
289 | 285 |
void msg_thread_init (void); |
290 | 286 |
void msg_thread_uninit (void); |
291 | 287 |
|
292 | 288 |
static inline void |
293 | 289 |
msg_set_prefix (const char *prefix) |
294 | 290 |
{ |
295 |
-#ifdef USE_PTHREAD |
|
296 |
- if (openvpn_thread_enabled ()) |
|
297 |
- { |
|
298 |
- ASSERT (!pthread_setspecific (x_msg_prefix_key, prefix)); |
|
299 |
- } |
|
300 |
- else |
|
301 |
-#endif |
|
302 | 291 |
x_msg_prefix = prefix; |
303 | 292 |
} |
304 | 293 |
|
305 | 294 |
static inline const char * |
306 | 295 |
msg_get_prefix (void) |
307 | 296 |
{ |
308 |
-#ifdef USE_PTHREAD |
|
309 |
- if (openvpn_thread_enabled ()) |
|
310 |
- return (const char *) pthread_getspecific (x_msg_prefix_key); |
|
311 |
- else |
|
312 |
-#endif |
|
313 | 297 |
return x_msg_prefix; |
314 | 298 |
} |
315 | 299 |
|
... | ... |
@@ -454,7 +454,6 @@ encrypt_sign (struct context *c, bool comp_frag) |
454 | 454 |
*/ |
455 | 455 |
if (c->c2.tls_multi) |
456 | 456 |
{ |
457 |
- /*tls_mutex_lock (c->c2.tls_multi);*/ |
|
458 | 457 |
tls_pre_encrypt (c->c2.tls_multi, &c->c2.buf, &c->c2.crypto_options); |
459 | 458 |
} |
460 | 459 |
#endif |
... | ... |
@@ -482,7 +481,6 @@ encrypt_sign (struct context *c, bool comp_frag) |
482 | 482 |
if (c->c2.tls_multi) |
483 | 483 |
{ |
484 | 484 |
tls_post_encrypt (c->c2.tls_multi, &c->c2.buf); |
485 |
- /*tls_mutex_unlock (c->c2.tls_multi);*/ |
|
486 | 485 |
} |
487 | 486 |
#endif |
488 | 487 |
#endif |
... | ... |
@@ -801,7 +799,6 @@ process_incoming_link (struct context *c) |
801 | 801 |
* will load crypto_options with the correct encryption key |
802 | 802 |
* and return false. |
803 | 803 |
*/ |
804 |
- /*tls_mutex_lock (c->c2.tls_multi);*/ |
|
805 | 804 |
if (tls_pre_decrypt (c->c2.tls_multi, &c->c2.from, &c->c2.buf, &c->c2.crypto_options)) |
806 | 805 |
{ |
807 | 806 |
interval_action (&c->c2.tmp_int); |
... | ... |
@@ -824,13 +821,6 @@ process_incoming_link (struct context *c) |
824 | 824 |
/* authenticate and decrypt the incoming packet */ |
825 | 825 |
decrypt_status = openvpn_decrypt (&c->c2.buf, c->c2.buffers->decrypt_buf, &c->c2.crypto_options, &c->c2.frame); |
826 | 826 |
|
827 |
-#ifdef USE_SSL |
|
828 |
- if (c->c2.tls_multi) |
|
829 |
- { |
|
830 |
- /*tls_mutex_unlock (c->c2.tls_multi);*/ |
|
831 |
- } |
|
832 |
-#endif |
|
833 |
- |
|
834 | 827 |
if (!decrypt_status && link_socket_connection_oriented (c->c2.link_socket)) |
835 | 828 |
{ |
836 | 829 |
/* decryption errors are fatal in TCP mode */ |
... | ... |
@@ -718,8 +718,6 @@ init_static (void) |
718 | 718 |
void |
719 | 719 |
uninit_static (void) |
720 | 720 |
{ |
721 |
- openvpn_thread_cleanup (); |
|
722 |
- |
|
723 | 721 |
#ifdef USE_CRYPTO |
724 | 722 |
free_ssl_lib (); |
725 | 723 |
#endif |
... | ... |
@@ -3505,23 +3503,6 @@ close_context (struct context *c, int sig, unsigned int flags) |
3505 | 3505 |
|
3506 | 3506 |
#ifdef USE_CRYPTO |
3507 | 3507 |
|
3508 |
-static void |
|
3509 |
-test_malloc (void) |
|
3510 |
-{ |
|
3511 |
- int i, j; |
|
3512 |
- msg (M_INFO, "Multithreaded malloc test..."); |
|
3513 |
- for (i = 0; i < 25; ++i) |
|
3514 |
- { |
|
3515 |
- struct gc_arena gc = gc_new (); |
|
3516 |
- const int limit = get_random () & 0x03FF; |
|
3517 |
- for (j = 0; j < limit; ++j) |
|
3518 |
- { |
|
3519 |
- gc_malloc (get_random () & 0x03FF, false, &gc); |
|
3520 |
- } |
|
3521 |
- gc_free (&gc); |
|
3522 |
- } |
|
3523 |
-} |
|
3524 |
- |
|
3525 | 3508 |
/* |
3526 | 3509 |
* Do a loopback test |
3527 | 3510 |
* on the crypto subsystem. |
... | ... |
@@ -3531,50 +3512,19 @@ test_crypto_thread (void *arg) |
3531 | 3531 |
{ |
3532 | 3532 |
struct context *c = (struct context *) arg; |
3533 | 3533 |
const struct options *options = &c->options; |
3534 |
-#if defined(USE_PTHREAD) |
|
3535 |
- struct context *child = NULL; |
|
3536 |
- openvpn_thread_t child_id = 0; |
|
3537 |
-#endif |
|
3538 | 3534 |
|
3539 | 3535 |
ASSERT (options->test_crypto); |
3540 | 3536 |
init_verb_mute (c, IVM_LEVEL_1); |
3541 | 3537 |
context_init_1 (c); |
3542 | 3538 |
do_init_crypto_static (c, 0); |
3543 | 3539 |
|
3544 |
-#if defined(USE_PTHREAD) |
|
3545 |
- { |
|
3546 |
- if (c->first_time && options->n_threads > 1) |
|
3547 |
- { |
|
3548 |
- if (options->n_threads > 2) |
|
3549 |
- msg (M_FATAL, "ERROR: --test-crypto option only works with --threads set to 1 or 2"); |
|
3550 |
- openvpn_thread_init (); |
|
3551 |
- ALLOC_OBJ (child, struct context); |
|
3552 |
- context_clear (child); |
|
3553 |
- child->options = *options; |
|
3554 |
- options_detach (&child->options); |
|
3555 |
- child->first_time = false; |
|
3556 |
- child_id = openvpn_thread_create (test_crypto_thread, (void *) child); |
|
3557 |
- } |
|
3558 |
- } |
|
3559 |
-#endif |
|
3560 | 3540 |
frame_finalize_options (c, options); |
3561 | 3541 |
|
3562 |
-#if defined(USE_PTHREAD) |
|
3563 |
- if (options->n_threads == 2) |
|
3564 |
- test_malloc (); |
|
3565 |
-#endif |
|
3566 |
- |
|
3567 | 3542 |
test_crypto (&c->c2.crypto_options, &c->c2.frame); |
3568 | 3543 |
|
3569 | 3544 |
key_schedule_free (&c->c1.ks, true); |
3570 | 3545 |
packet_id_free (&c->c2.packet_id); |
3571 | 3546 |
|
3572 |
-#if defined(USE_PTHREAD) |
|
3573 |
- if (c->first_time && options->n_threads > 1) |
|
3574 |
- openvpn_thread_join (child_id); |
|
3575 |
- if (child) |
|
3576 |
- free (child); |
|
3577 |
-#endif |
|
3578 | 3547 |
context_gc_free (c); |
3579 | 3548 |
return NULL; |
3580 | 3549 |
} |
... | ... |
@@ -52,7 +52,6 @@ hash_init (const int n_buckets, |
52 | 52 |
{ |
53 | 53 |
struct hash_bucket *b = &h->buckets[i]; |
54 | 54 |
b->list = NULL; |
55 |
- mutex_init (&b->mutex); |
|
56 | 55 |
} |
57 | 56 |
return h; |
58 | 57 |
} |
... | ... |
@@ -66,7 +65,6 @@ hash_free (struct hash *hash) |
66 | 66 |
struct hash_bucket *b = &hash->buckets[i]; |
67 | 67 |
struct hash_element *he = b->list; |
68 | 68 |
|
69 |
- mutex_destroy (&b->mutex); |
|
70 | 69 |
while (he) |
71 | 70 |
{ |
72 | 71 |
struct hash_element *next = he->next; |
... | ... |
@@ -148,7 +146,6 @@ hash_add (struct hash *hash, const void *key, void *value, bool replace) |
148 | 148 |
|
149 | 149 |
hv = hash_value (hash, key); |
150 | 150 |
bucket = &hash->buckets[hv & hash->mask]; |
151 |
- mutex_lock (&bucket->mutex); |
|
152 | 151 |
|
153 | 152 |
if ((he = hash_lookup_fast (hash, bucket, key, hv))) /* already exists? */ |
154 | 153 |
{ |
... | ... |
@@ -164,18 +161,16 @@ hash_add (struct hash *hash, const void *key, void *value, bool replace) |
164 | 164 |
ret = true; |
165 | 165 |
} |
166 | 166 |
|
167 |
- mutex_unlock (&bucket->mutex); |
|
168 |
- |
|
169 | 167 |
return ret; |
170 | 168 |
} |
171 | 169 |
|
172 | 170 |
void |
173 |
-hash_remove_by_value (struct hash *hash, void *value, bool autolock) |
|
171 |
+hash_remove_by_value (struct hash *hash, void *value) |
|
174 | 172 |
{ |
175 | 173 |
struct hash_iterator hi; |
176 | 174 |
struct hash_element *he; |
177 | 175 |
|
178 |
- hash_iterator_init (hash, &hi, autolock); |
|
176 |
+ hash_iterator_init (hash, &hi); |
|
179 | 177 |
while ((he = hash_iterator_next (&hi))) |
180 | 178 |
{ |
181 | 179 |
if (he->value == value) |
... | ... |
@@ -226,7 +221,6 @@ void_ptr_compare_function (const void *key1, const void *key2) |
226 | 226 |
void |
227 | 227 |
hash_iterator_init_range (struct hash *hash, |
228 | 228 |
struct hash_iterator *hi, |
229 |
- bool autolock, |
|
230 | 229 |
int start_bucket, |
231 | 230 |
int end_bucket) |
232 | 231 |
{ |
... | ... |
@@ -238,7 +232,6 @@ hash_iterator_init_range (struct hash *hash, |
238 | 238 |
hi->hash = hash; |
239 | 239 |
hi->elem = NULL; |
240 | 240 |
hi->bucket = NULL; |
241 |
- hi->autolock = autolock; |
|
242 | 241 |
hi->last = NULL; |
243 | 242 |
hi->bucket_marked = false; |
244 | 243 |
hi->bucket_index_start = start_bucket; |
... | ... |
@@ -248,19 +241,14 @@ hash_iterator_init_range (struct hash *hash, |
248 | 248 |
|
249 | 249 |
void |
250 | 250 |
hash_iterator_init (struct hash *hash, |
251 |
- struct hash_iterator *hi, |
|
252 |
- bool autolock) |
|
251 |
+ struct hash_iterator *hi) |
|
253 | 252 |
{ |
254 |
- hash_iterator_init_range (hash, hi, autolock, 0, hash->n_buckets); |
|
253 |
+ hash_iterator_init_range (hash, hi, 0, hash->n_buckets); |
|
255 | 254 |
} |
256 | 255 |
|
257 | 256 |
static inline void |
258 | 257 |
hash_iterator_lock (struct hash_iterator *hi, struct hash_bucket *b) |
259 | 258 |
{ |
260 |
- if (hi->autolock) |
|
261 |
- { |
|
262 |
- mutex_lock (&b->mutex); |
|
263 |
- } |
|
264 | 259 |
hi->bucket = b; |
265 | 260 |
hi->last = NULL; |
266 | 261 |
hi->bucket_marked = false; |
... | ... |
@@ -276,10 +264,6 @@ hash_iterator_unlock (struct hash_iterator *hi) |
276 | 276 |
hash_remove_marked (hi->hash, hi->bucket); |
277 | 277 |
hi->bucket_marked = false; |
278 | 278 |
} |
279 |
- if (hi->autolock) |
|
280 |
- { |
|
281 |
- mutex_unlock (&hi->bucket->mutex); |
|
282 |
- } |
|
283 | 279 |
hi->bucket = NULL; |
284 | 280 |
hi->last = NULL; |
285 | 281 |
} |
... | ... |
@@ -40,7 +40,6 @@ |
40 | 40 |
/*#define LIST_TEST*/ |
41 | 41 |
|
42 | 42 |
#include "basic.h" |
43 |
-#include "thread.h" |
|
44 | 43 |
#include "buffer.h" |
45 | 44 |
|
46 | 45 |
#define hashsize(n) ((uint32_t)1<<(n)) |
... | ... |
@@ -56,7 +55,6 @@ struct hash_element |
56 | 56 |
|
57 | 57 |
struct hash_bucket |
58 | 58 |
{ |
59 |
- MUTEX_DEFINE (mutex); |
|
60 | 59 |
struct hash_element *list; |
61 | 60 |
}; |
62 | 61 |
|
... | ... |
@@ -90,7 +88,7 @@ bool hash_remove_fast (struct hash *hash, |
90 | 90 |
const void *key, |
91 | 91 |
uint32_t hv); |
92 | 92 |
|
93 |
-void hash_remove_by_value (struct hash *hash, void *value, bool autolock); |
|
93 |
+void hash_remove_by_value (struct hash *hash, void *value); |
|
94 | 94 |
|
95 | 95 |
struct hash_iterator |
96 | 96 |
{ |
... | ... |
@@ -100,18 +98,16 @@ struct hash_iterator |
100 | 100 |
struct hash_element *elem; |
101 | 101 |
struct hash_element *last; |
102 | 102 |
bool bucket_marked; |
103 |
- bool autolock; |
|
104 | 103 |
int bucket_index_start; |
105 | 104 |
int bucket_index_end; |
106 | 105 |
}; |
107 | 106 |
|
108 | 107 |
void hash_iterator_init_range (struct hash *hash, |
109 | 108 |
struct hash_iterator *hi, |
110 |
- bool autolock, |
|
111 | 109 |
int start_bucket, |
112 | 110 |
int end_bucket); |
113 | 111 |
|
114 |
-void hash_iterator_init (struct hash *hash, struct hash_iterator *iter, bool autolock); |
|
112 |
+void hash_iterator_init (struct hash *hash, struct hash_iterator *iter); |
|
115 | 113 |
struct hash_element *hash_iterator_next (struct hash_iterator *hi); |
116 | 114 |
void hash_iterator_delete_element (struct hash_iterator *hi); |
117 | 115 |
void hash_iterator_free (struct hash_iterator *hi); |
... | ... |
@@ -149,40 +145,21 @@ hash_bucket (struct hash *hash, uint32_t hv) |
149 | 149 |
return &hash->buckets[hv & hash->mask]; |
150 | 150 |
} |
151 | 151 |
|
152 |
-static inline void |
|
153 |
-hash_bucket_lock (struct hash_bucket *bucket) |
|
154 |
-{ |
|
155 |
- mutex_lock (&bucket->mutex); |
|
156 |
-} |
|
157 |
- |
|
158 |
-static inline void |
|
159 |
-hash_bucket_unlock (struct hash_bucket *bucket) |
|
160 |
-{ |
|
161 |
- mutex_unlock (&bucket->mutex); |
|
162 |
-} |
|
163 |
- |
|
164 | 152 |
static inline void * |
165 |
-hash_lookup_lock (struct hash *hash, const void *key, uint32_t hv) |
|
153 |
+hash_lookup (struct hash *hash, const void *key) |
|
166 | 154 |
{ |
167 | 155 |
void *ret = NULL; |
168 | 156 |
struct hash_element *he; |
157 |
+ uint32_t hv = hash_value (hash, key); |
|
169 | 158 |
struct hash_bucket *bucket = &hash->buckets[hv & hash->mask]; |
170 | 159 |
|
171 |
- mutex_lock (&bucket->mutex); |
|
172 | 160 |
he = hash_lookup_fast (hash, bucket, key, hv); |
173 | 161 |
if (he) |
174 | 162 |
ret = he->value; |
175 |
- mutex_unlock (&bucket->mutex); |
|
176 | 163 |
|
177 | 164 |
return ret; |
178 | 165 |
} |
179 | 166 |
|
180 |
-static inline void * |
|
181 |
-hash_lookup (struct hash *hash, const void *key) |
|
182 |
-{ |
|
183 |
- return hash_lookup_lock (hash, key, hash_value (hash, key)); |
|
184 |
-} |
|
185 |
- |
|
186 | 167 |
/* NOTE: assumes that key is not a duplicate */ |
187 | 168 |
static inline void |
188 | 169 |
hash_add_fast (struct hash *hash, |
... | ... |
@@ -211,9 +188,7 @@ hash_remove (struct hash *hash, const void *key) |
211 | 211 |
|
212 | 212 |
hv = hash_value (hash, key); |
213 | 213 |
bucket = &hash->buckets[hv & hash->mask]; |
214 |
- mutex_lock (&bucket->mutex); |
|
215 | 214 |
ret = hash_remove_fast (hash, bucket, key, hv); |
216 |
- mutex_unlock (&bucket->mutex); |
|
217 | 215 |
return ret; |
218 | 216 |
} |
219 | 217 |
|
... | ... |
@@ -38,7 +38,6 @@ mbuf_init (unsigned int size) |
38 | 38 |
{ |
39 | 39 |
struct mbuf_set *ret; |
40 | 40 |
ALLOC_OBJ_CLEAR (ret, struct mbuf_set); |
41 |
- mutex_init (&ret->mutex); |
|
42 | 41 |
ret->capacity = adjust_power_of_2 (size); |
43 | 42 |
ALLOC_ARRAY (ret->array, struct mbuf_item, ret->capacity); |
44 | 43 |
return ret; |
... | ... |
@@ -56,7 +55,6 @@ mbuf_free (struct mbuf_set *ms) |
56 | 56 |
mbuf_free_buf (item->buffer); |
57 | 57 |
} |
58 | 58 |
free (ms->array); |
59 |
- mutex_destroy (&ms->mutex); |
|
60 | 59 |
free (ms); |
61 | 60 |
} |
62 | 61 |
} |
... | ... |
@@ -89,11 +87,10 @@ void |
89 | 89 |
mbuf_add_item (struct mbuf_set *ms, const struct mbuf_item *item) |
90 | 90 |
{ |
91 | 91 |
ASSERT (ms); |
92 |
- mutex_lock (&ms->mutex); |
|
93 | 92 |
if (ms->len == ms->capacity) |
94 | 93 |
{ |
95 | 94 |
struct mbuf_item rm; |
96 |
- ASSERT (mbuf_extract_item (ms, &rm, false)); |
|
95 |
+ ASSERT (mbuf_extract_item (ms, &rm)); |
|
97 | 96 |
mbuf_free_buf (rm.buffer); |
98 | 97 |
msg (D_MULTI_DROPPED, "MBUF: mbuf packet dropped"); |
99 | 98 |
} |
... | ... |
@@ -104,17 +101,14 @@ mbuf_add_item (struct mbuf_set *ms, const struct mbuf_item *item) |
104 | 104 |
if (++ms->len > ms->max_queued) |
105 | 105 |
ms->max_queued = ms->len; |
106 | 106 |
++item->buffer->refcount; |
107 |
- mutex_unlock (&ms->mutex); |
|
108 | 107 |
} |
109 | 108 |
|
110 | 109 |
bool |
111 |
-mbuf_extract_item (struct mbuf_set *ms, struct mbuf_item *item, const bool lock) |
|
110 |
+mbuf_extract_item (struct mbuf_set *ms, struct mbuf_item *item) |
|
112 | 111 |
{ |
113 | 112 |
bool ret = false; |
114 | 113 |
if (ms) |
115 | 114 |
{ |
116 |
- if (lock) |
|
117 |
- mutex_lock (&ms->mutex); |
|
118 | 115 |
while (ms->len) |
119 | 116 |
{ |
120 | 117 |
*item = ms->array[ms->head]; |
... | ... |
@@ -126,8 +120,6 @@ mbuf_extract_item (struct mbuf_set *ms, struct mbuf_item *item, const bool lock) |
126 | 126 |
break; |
127 | 127 |
} |
128 | 128 |
} |
129 |
- if (lock) |
|
130 |
- mutex_unlock (&ms->mutex); |
|
131 | 129 |
} |
132 | 130 |
return ret; |
133 | 131 |
} |
... | ... |
@@ -139,7 +131,6 @@ mbuf_peek_dowork (struct mbuf_set *ms) |
139 | 139 |
if (ms) |
140 | 140 |
{ |
141 | 141 |
int i; |
142 |
- mutex_lock (&ms->mutex); |
|
143 | 142 |
for (i = 0; i < (int) ms->len; ++i) |
144 | 143 |
{ |
145 | 144 |
struct mbuf_item *item = &ms->array[MBUF_INDEX(ms->head, i, ms->capacity)]; |
... | ... |
@@ -149,7 +140,6 @@ mbuf_peek_dowork (struct mbuf_set *ms) |
149 | 149 |
break; |
150 | 150 |
} |
151 | 151 |
} |
152 |
- mutex_unlock (&ms->mutex); |
|
153 | 152 |
} |
154 | 153 |
return ret; |
155 | 154 |
} |
... | ... |
@@ -160,7 +150,6 @@ mbuf_dereference_instance (struct mbuf_set *ms, struct multi_instance *mi) |
160 | 160 |
if (ms) |
161 | 161 |
{ |
162 | 162 |
int i; |
163 |
- mutex_lock (&ms->mutex); |
|
164 | 163 |
for (i = 0; i < (int) ms->len; ++i) |
165 | 164 |
{ |
166 | 165 |
struct mbuf_item *item = &ms->array[MBUF_INDEX(ms->head, i, ms->capacity)]; |
... | ... |
@@ -172,7 +161,6 @@ mbuf_dereference_instance (struct mbuf_set *ms, struct multi_instance *mi) |
172 | 172 |
msg (D_MBUF, "MBUF: dereferenced queued packet"); |
173 | 173 |
} |
174 | 174 |
} |
175 |
- mutex_unlock (&ms->mutex); |
|
176 | 175 |
} |
177 | 176 |
} |
178 | 177 |
|
... | ... |
@@ -58,7 +58,6 @@ struct mbuf_item |
58 | 58 |
|
59 | 59 |
struct mbuf_set |
60 | 60 |
{ |
61 |
- MUTEX_DEFINE (mutex); |
|
62 | 61 |
unsigned int head; |
63 | 62 |
unsigned int len; |
64 | 63 |
unsigned int capacity; |
... | ... |
@@ -74,7 +73,7 @@ void mbuf_free_buf (struct mbuf_buffer *mb); |
74 | 74 |
|
75 | 75 |
void mbuf_add_item (struct mbuf_set *ms, const struct mbuf_item *item); |
76 | 76 |
|
77 |
-bool mbuf_extract_item (struct mbuf_set *ms, struct mbuf_item *item, const bool lock); |
|
77 |
+bool mbuf_extract_item (struct mbuf_set *ms, struct mbuf_item *item); |
|
78 | 78 |
|
79 | 79 |
void mbuf_dereference_instance (struct mbuf_set *ms, struct multi_instance *mi); |
80 | 80 |
|
... | ... |
@@ -29,7 +29,6 @@ |
29 | 29 |
#include "base64.h" |
30 | 30 |
#include "tun.h" |
31 | 31 |
#include "error.h" |
32 |
-#include "thread.h" |
|
33 | 32 |
#include "otime.h" |
34 | 33 |
#include "plugin.h" |
35 | 34 |
#include "options.h" |
... | ... |
@@ -639,9 +638,7 @@ strerror_ts (int errnum, struct gc_arena *gc) |
639 | 639 |
#ifdef HAVE_STRERROR |
640 | 640 |
struct buffer out = alloc_buf_gc (256, gc); |
641 | 641 |
|
642 |
- mutex_lock_static (L_STRERR); |
|
643 | 642 |
buf_printf (&out, "%s", openvpn_strerror (errnum, gc)); |
644 |
- mutex_unlock_static (L_STRERR); |
|
645 | 643 |
return BSTR (&out); |
646 | 644 |
#else |
647 | 645 |
return "[error string unavailable]"; |
... | ... |
@@ -779,18 +776,15 @@ struct env_set * |
779 | 779 |
env_set_create (struct gc_arena *gc) |
780 | 780 |
{ |
781 | 781 |
struct env_set *es; |
782 |
- mutex_lock_static (L_ENV_SET); |
|
783 | 782 |
ALLOC_OBJ_CLEAR_GC (es, struct env_set, gc); |
784 | 783 |
es->list = NULL; |
785 | 784 |
es->gc = gc; |
786 |
- mutex_unlock_static (L_ENV_SET); |
|
787 | 785 |
return es; |
788 | 786 |
} |
789 | 787 |
|
790 | 788 |
void |
791 | 789 |
env_set_destroy (struct env_set *es) |
792 | 790 |
{ |
793 |
- mutex_lock_static (L_ENV_SET); |
|
794 | 791 |
if (es && es->gc == NULL) |
795 | 792 |
{ |
796 | 793 |
struct env_item *e = es->list; |
... | ... |
@@ -803,7 +797,6 @@ env_set_destroy (struct env_set *es) |
803 | 803 |
} |
804 | 804 |
free (es); |
805 | 805 |
} |
806 |
- mutex_unlock_static (L_ENV_SET); |
|
807 | 806 |
} |
808 | 807 |
|
809 | 808 |
bool |
... | ... |
@@ -812,9 +805,7 @@ env_set_del (struct env_set *es, const char *str) |
812 | 812 |
bool ret; |
813 | 813 |
ASSERT (es); |
814 | 814 |
ASSERT (str); |
815 |
- mutex_lock_static (L_ENV_SET); |
|
816 | 815 |
ret = env_set_del_nolock (es, str); |
817 |
- mutex_unlock_static (L_ENV_SET); |
|
818 | 816 |
return ret; |
819 | 817 |
} |
820 | 818 |
|
... | ... |
@@ -823,9 +814,7 @@ env_set_add (struct env_set *es, const char *str) |
823 | 823 |
{ |
824 | 824 |
ASSERT (es); |
825 | 825 |
ASSERT (str); |
826 |
- mutex_lock_static (L_ENV_SET); |
|
827 | 826 |
env_set_add_nolock (es, str); |
828 |
- mutex_unlock_static (L_ENV_SET); |
|
829 | 827 |
} |
830 | 828 |
|
831 | 829 |
void |
... | ... |
@@ -838,7 +827,6 @@ env_set_print (int msglevel, const struct env_set *es) |
838 | 838 |
|
839 | 839 |
if (es) |
840 | 840 |
{ |
841 |
- mutex_lock_static (L_ENV_SET); |
|
842 | 841 |
e = es->list; |
843 | 842 |
i = 0; |
844 | 843 |
|
... | ... |
@@ -849,7 +837,6 @@ env_set_print (int msglevel, const struct env_set *es) |
849 | 849 |
++i; |
850 | 850 |
e = e->next; |
851 | 851 |
} |
852 |
- mutex_unlock_static (L_ENV_SET); |
|
853 | 852 |
} |
854 | 853 |
} |
855 | 854 |
} |
... | ... |
@@ -863,14 +850,12 @@ env_set_inherit (struct env_set *es, const struct env_set *src) |
863 | 863 |
|
864 | 864 |
if (src) |
865 | 865 |
{ |
866 |
- mutex_lock_static (L_ENV_SET); |
|
867 | 866 |
e = src->list; |
868 | 867 |
while (e) |
869 | 868 |
{ |
870 | 869 |
env_set_add_nolock (es, e->string); |
871 | 870 |
e = e->next; |
872 | 871 |
} |
873 |
- mutex_unlock_static (L_ENV_SET); |
|
874 | 872 |
} |
875 | 873 |
} |
876 | 874 |
|
... | ... |
@@ -882,7 +867,6 @@ env_set_add_to_environment (const struct env_set *es) |
882 | 882 |
struct gc_arena gc = gc_new (); |
883 | 883 |
const struct env_item *e; |
884 | 884 |
|
885 |
- mutex_lock_static (L_ENV_SET); |
|
886 | 885 |
e = es->list; |
887 | 886 |
|
888 | 887 |
while (e) |
... | ... |
@@ -895,7 +879,6 @@ env_set_add_to_environment (const struct env_set *es) |
895 | 895 |
|
896 | 896 |
e = e->next; |
897 | 897 |
} |
898 |
- mutex_unlock_static (L_ENV_SET); |
|
899 | 898 |
gc_free (&gc); |
900 | 899 |
} |
901 | 900 |
} |
... | ... |
@@ -908,7 +891,6 @@ env_set_remove_from_environment (const struct env_set *es) |
908 | 908 |
struct gc_arena gc = gc_new (); |
909 | 909 |
const struct env_item *e; |
910 | 910 |
|
911 |
- mutex_lock_static (L_ENV_SET); |
|
912 | 911 |
e = es->list; |
913 | 912 |
|
914 | 913 |
while (e) |
... | ... |
@@ -921,7 +903,6 @@ env_set_remove_from_environment (const struct env_set *es) |
921 | 921 |
|
922 | 922 |
e = e->next; |
923 | 923 |
} |
924 |
- mutex_unlock_static (L_ENV_SET); |
|
925 | 924 |
gc_free (&gc); |
926 | 925 |
} |
927 | 926 |
} |
... | ... |
@@ -1040,12 +1021,10 @@ setenv_str_ex (struct env_set *es, |
1040 | 1040 |
char *str = construct_name_value (name_tmp, val_tmp, NULL); |
1041 | 1041 |
int status; |
1042 | 1042 |
|
1043 |
- mutex_lock_static (L_PUTENV); |
|
1044 | 1043 |
status = putenv (str); |
1045 | 1044 |
/*msg (M_INFO, "PUTENV '%s'", str);*/ |
1046 | 1045 |
if (!status) |
1047 | 1046 |
manage_env (str); |
1048 |
- mutex_unlock_static (L_PUTENV); |
|
1049 | 1047 |
if (status) |
1050 | 1048 |
msg (M_WARN | M_ERRNO, "putenv('%s') failed", str); |
1051 | 1049 |
} |
... | ... |
@@ -1182,9 +1161,7 @@ create_temp_file (const char *directory, const char *prefix, struct gc_arena *gc |
1182 | 1182 |
const char *rndstr; |
1183 | 1183 |
|
1184 | 1184 |
++attempts; |
1185 |
- mutex_lock_static (L_CREATE_TEMP); |
|
1186 | 1185 |
++counter; |
1187 |
- mutex_unlock_static (L_CREATE_TEMP); |
|
1188 | 1186 |
|
1189 | 1187 |
prng_bytes (rndbytes, sizeof rndbytes); |
1190 | 1188 |
rndstr = format_hex_ex (rndbytes, sizeof rndbytes, 40, 0, NULL, gc); |
... | ... |
@@ -360,7 +360,6 @@ mroute_helper_init (int ageable_ttl_secs) |
360 | 360 |
{ |
361 | 361 |
struct mroute_helper *mh; |
362 | 362 |
ALLOC_OBJ_CLEAR (mh, struct mroute_helper); |
363 |
- /*mutex_init (&mh->mutex);*/ |
|
364 | 363 |
mh->ageable_ttl_secs = ageable_ttl_secs; |
365 | 364 |
return mh; |
366 | 365 |
} |
... | ... |
@@ -398,12 +397,10 @@ mroute_helper_add_iroute (struct mroute_helper *mh, const struct iroute *ir) |
398 | 398 |
if (ir->netbits >= 0) |
399 | 399 |
{ |
400 | 400 |
ASSERT (ir->netbits < MR_HELPER_NET_LEN); |
401 |
- mroute_helper_lock (mh); |
|
402 | 401 |
++mh->cache_generation; |
403 | 402 |
++mh->net_len_refcount[ir->netbits]; |
404 | 403 |
if (mh->net_len_refcount[ir->netbits] == 1) |
405 | 404 |
mroute_helper_regenerate (mh); |
406 |
- mroute_helper_unlock (mh); |
|
407 | 405 |
} |
408 | 406 |
} |
409 | 407 |
|
... | ... |
@@ -413,20 +410,17 @@ mroute_helper_del_iroute (struct mroute_helper *mh, const struct iroute *ir) |
413 | 413 |
if (ir->netbits >= 0) |
414 | 414 |
{ |
415 | 415 |
ASSERT (ir->netbits < MR_HELPER_NET_LEN); |
416 |
- mroute_helper_lock (mh); |
|
417 | 416 |
++mh->cache_generation; |
418 | 417 |
--mh->net_len_refcount[ir->netbits]; |
419 | 418 |
ASSERT (mh->net_len_refcount[ir->netbits] >= 0); |
420 | 419 |
if (!mh->net_len_refcount[ir->netbits]) |
421 | 420 |
mroute_helper_regenerate (mh); |
422 |
- mroute_helper_unlock (mh); |
|
423 | 421 |
} |
424 | 422 |
} |
425 | 423 |
|
426 | 424 |
void |
427 | 425 |
mroute_helper_free (struct mroute_helper *mh) |
428 | 426 |
{ |
429 |
- /*mutex_destroy (&mh->mutex);*/ |
|
430 | 427 |
free (mh); |
431 | 428 |
} |
432 | 429 |
|
... | ... |
@@ -91,7 +91,6 @@ struct mroute_addr { |
91 | 91 |
* Used to help maintain CIDR routing table. |
92 | 92 |
*/ |
93 | 93 |
struct mroute_helper { |
94 |
- /*MUTEX_DEFINE (mutex);*/ |
|
95 | 94 |
unsigned int cache_generation; /* incremented when route added */ |
96 | 95 |
int ageable_ttl_secs; /* host route cache entry time-to-live*/ |
97 | 96 |
int n_net_len; /* length of net_len array */ |
... | ... |
@@ -159,18 +158,6 @@ mroute_extract_addr_from_packet (struct mroute_addr *src, |
159 | 159 |
return ret; |
160 | 160 |
} |
161 | 161 |
|
162 |
-static inline void |
|
163 |
-mroute_helper_lock (struct mroute_helper *mh) |
|
164 |
-{ |
|
165 |
- /*mutex_lock (&mh->mutex);*/ |
|
166 |
-} |
|
167 |
- |
|
168 |
-static inline void |
|
169 |
-mroute_helper_unlock (struct mroute_helper *mh) |
|
170 |
-{ |
|
171 |
- /*mutex_unlock (&mh->mutex);*/ |
|
172 |
-} |
|
173 |
- |
|
174 | 162 |
static inline bool |
175 | 163 |
mroute_addr_equal (const struct mroute_addr *a1, const struct mroute_addr *a2) |
176 | 164 |
{ |
... | ... |
@@ -112,7 +112,6 @@ multi_create_instance_tcp (struct multi_context *m) |
112 | 112 |
const uint32_t hv = hash_value (hash, &mi->real); |
113 | 113 |
struct hash_bucket *bucket = hash_bucket (hash, hv); |
114 | 114 |
|
115 |
- hash_bucket_lock (bucket); |
|
116 | 115 |
he = hash_lookup_fast (hash, bucket, &mi->real, hv); |
117 | 116 |
|
118 | 117 |
if (he) |
... | ... |
@@ -128,8 +127,6 @@ multi_create_instance_tcp (struct multi_context *m) |
128 | 128 |
hash_add_fast (hash, bucket, &mi->real, hv, mi); |
129 | 129 |
|
130 | 130 |
mi->did_real_hash = true; |
131 |
- |
|
132 |
- hash_bucket_unlock (bucket); |
|
133 | 131 |
} |
134 | 132 |
|
135 | 133 |
#ifdef ENABLE_DEBUG |
... | ... |
@@ -264,7 +261,7 @@ multi_tcp_process_outgoing_link_ready (struct multi_context *m, struct multi_ins |
264 | 264 |
ASSERT (mi); |
265 | 265 |
|
266 | 266 |
/* extract from queue */ |
267 |
- if (mbuf_extract_item (mi->tcp_link_out_deferred, &item, true)) /* ciphertext IP packet */ |
|
267 |
+ if (mbuf_extract_item (mi->tcp_link_out_deferred, &item)) /* ciphertext IP packet */ |
|
268 | 268 |
{ |
269 | 269 |
dmsg (D_MULTI_TCP, "MULTI TCP: transmitting previously deferred packet"); |
270 | 270 |
|
... | ... |
@@ -51,7 +51,6 @@ multi_get_create_instance_udp (struct multi_context *m) |
51 | 51 |
const uint32_t hv = hash_value (hash, &real); |
52 | 52 |
struct hash_bucket *bucket = hash_bucket (hash, hv); |
53 | 53 |
|
54 |
- hash_bucket_lock (bucket); |
|
55 | 54 |
he = hash_lookup_fast (hash, bucket, &real, hv); |
56 | 55 |
|
57 | 56 |
if (he) |
... | ... |
@@ -81,8 +80,6 @@ multi_get_create_instance_udp (struct multi_context *m) |
81 | 81 |
} |
82 | 82 |
} |
83 | 83 |
|
84 |
- hash_bucket_unlock (bucket); |
|
85 |
- |
|
86 | 84 |
#ifdef ENABLE_DEBUG |
87 | 85 |
if (check_debug_level (D_MULTI_DEBUG)) |
88 | 86 |
{ |
... | ... |
@@ -146,7 +146,7 @@ multi_reap_range (const struct multi_context *m, |
146 | 146 |
} |
147 | 147 |
|
148 | 148 |
dmsg (D_MULTI_DEBUG, "MULTI: REAP range %d -> %d", start_bucket, end_bucket); |
149 |
- hash_iterator_init_range (m->vhash, &hi, true, start_bucket, end_bucket); |
|
149 |
+ hash_iterator_init_range (m->vhash, &hi, start_bucket, end_bucket); |
|
150 | 150 |
while ((he = hash_iterator_next (&hi)) != NULL) |
151 | 151 |
{ |
152 | 152 |
struct multi_route *r = (struct multi_route *) he->value; |
... | ... |
@@ -587,7 +587,7 @@ multi_uninit (struct multi_context *m) |
587 | 587 |
struct hash_iterator hi; |
588 | 588 |
struct hash_element *he; |
589 | 589 |
|
590 |
- hash_iterator_init (m->iter, &hi, true); |
|
590 |
+ hash_iterator_init (m->iter, &hi); |
|
591 | 591 |
while ((he = hash_iterator_next (&hi))) |
592 | 592 |
{ |
593 | 593 |
struct multi_instance *mi = (struct multi_instance *) he->value; |
... | ... |
@@ -633,7 +633,6 @@ multi_create_instance (struct multi_context *m, const struct mroute_addr *real) |
633 | 633 |
|
634 | 634 |
ALLOC_OBJ_CLEAR (mi, struct multi_instance); |
635 | 635 |
|
636 |
- mutex_init (&mi->mutex); |
|
637 | 636 |
mi->gc = gc_new (); |
638 | 637 |
multi_instance_inc_refcount (mi); |
639 | 638 |
mi->vaddr_handle = -1; |
... | ... |
@@ -724,7 +723,7 @@ multi_print_status (struct multi_context *m, struct status_output *so, const int |
724 | 724 |
status_printf (so, "OpenVPN CLIENT LIST"); |
725 | 725 |
status_printf (so, "Updated,%s", time_string (0, 0, false, &gc_top)); |
726 | 726 |
status_printf (so, "Common Name,Real Address,Bytes Received,Bytes Sent,Connected Since"); |
727 |
- hash_iterator_init (m->hash, &hi, true); |
|
727 |
+ hash_iterator_init (m->hash, &hi); |
|
728 | 728 |
while ((he = hash_iterator_next (&hi))) |
729 | 729 |
{ |
730 | 730 |
struct gc_arena gc = gc_new (); |
... | ... |
@@ -745,7 +744,7 @@ multi_print_status (struct multi_context *m, struct status_output *so, const int |
745 | 745 |
|
746 | 746 |
status_printf (so, "ROUTING TABLE"); |
747 | 747 |
status_printf (so, "Virtual Address,Common Name,Real Address,Last Ref"); |
748 |
- hash_iterator_init (m->vhash, &hi, true); |
|
748 |
+ hash_iterator_init (m->vhash, &hi); |
|
749 | 749 |
while ((he = hash_iterator_next (&hi))) |
750 | 750 |
{ |
751 | 751 |
struct gc_arena gc = gc_new (); |
... | ... |
@@ -788,7 +787,7 @@ multi_print_status (struct multi_context *m, struct status_output *so, const int |
788 | 788 |
status_printf (so, "TIME%c%s%c%u", sep, time_string (now, 0, false, &gc_top), sep, (unsigned int)now); |
789 | 789 |
status_printf (so, "HEADER%cCLIENT_LIST%cCommon Name%cReal Address%cVirtual Address%cBytes Received%cBytes Sent%cConnected Since%cConnected Since (time_t)", |
790 | 790 |
sep, sep, sep, sep, sep, sep, sep, sep); |
791 |
- hash_iterator_init (m->hash, &hi, true); |
|
791 |
+ hash_iterator_init (m->hash, &hi); |
|
792 | 792 |
while ((he = hash_iterator_next (&hi))) |
793 | 793 |
{ |
794 | 794 |
struct gc_arena gc = gc_new (); |
... | ... |
@@ -811,7 +810,7 @@ multi_print_status (struct multi_context *m, struct status_output *so, const int |
811 | 811 |
|
812 | 812 |
status_printf (so, "HEADER%cROUTING_TABLE%cVirtual Address%cCommon Name%cReal Address%cLast Ref%cLast Ref (time_t)", |
813 | 813 |
sep, sep, sep, sep, sep, sep); |
814 |
- hash_iterator_init (m->vhash, &hi, true); |
|
814 |
+ hash_iterator_init (m->vhash, &hi); |
|
815 | 815 |
while ((he = hash_iterator_next (&hi))) |
816 | 816 |
{ |
817 | 817 |
struct gc_arena gc = gc_new (); |
... | ... |
@@ -850,7 +849,7 @@ multi_print_status (struct multi_context *m, struct status_output *so, const int |
850 | 850 |
#ifdef PACKET_TRUNCATION_CHECK |
851 | 851 |
{ |
852 | 852 |
status_printf (so, "HEADER,ERRORS,Common Name,TUN Read Trunc,TUN Write Trunc,Pre-encrypt Trunc,Post-decrypt Trunc"); |
853 |
- hash_iterator_init (m->hash, &hi, true); |
|
853 |
+ hash_iterator_init (m->hash, &hi); |
|
854 | 854 |
while ((he = hash_iterator_next (&hi))) |
855 | 855 |
{ |
856 | 856 |
struct gc_arena gc = gc_new (); |
... | ... |
@@ -896,8 +895,6 @@ multi_learn_addr (struct multi_context *m, |
896 | 896 |
struct multi_route *oldroute = NULL; |
897 | 897 |
struct multi_instance *owner = NULL; |
898 | 898 |
|
899 |
- hash_bucket_lock (bucket); |
|
900 |
- |
|
901 | 899 |
/* if route currently exists, get the instance which owns it */ |
902 | 900 |
he = hash_lookup_fast (m->vhash, bucket, addr, hv); |
903 | 901 |
if (he) |
... | ... |
@@ -967,7 +964,6 @@ multi_learn_addr (struct multi_context *m, |
967 | 967 |
gc_free (&gc); |
968 | 968 |
} |
969 | 969 |
|
970 |
- hash_bucket_unlock (bucket); |
|
971 | 970 |
return owner; |
972 | 971 |
} |
973 | 972 |
|
... | ... |
@@ -1001,8 +997,6 @@ multi_get_instance_by_virtual_addr (struct multi_context *m, |
1001 | 1001 |
struct mroute_addr tryaddr; |
1002 | 1002 |
int i; |
1003 | 1003 |
|
1004 |
- mroute_helper_lock (rh); |
|
1005 |
- |
|
1006 | 1004 |
/* cycle through each CIDR length */ |
1007 | 1005 |
for (i = 0; i < rh->n_net_len; ++i) |
1008 | 1006 |
{ |
... | ... |
@@ -1023,8 +1017,6 @@ multi_get_instance_by_virtual_addr (struct multi_context *m, |
1023 | 1023 |
break; |
1024 | 1024 |
} |
1025 | 1025 |
} |
1026 |
- |
|
1027 |
- mroute_helper_unlock (rh); |
|
1028 | 1026 |
} |
1029 | 1027 |
|
1030 | 1028 |
#ifdef ENABLE_DEBUG |
... | ... |
@@ -1135,7 +1127,7 @@ multi_delete_dup (struct multi_context *m, struct multi_instance *new_mi) |
1135 | 1135 |
struct hash_element *he; |
1136 | 1136 |
int count = 0; |
1137 | 1137 |
|
1138 |
- hash_iterator_init (m->iter, &hi, true); |
|
1138 |
+ hash_iterator_init (m->iter, &hi); |
|
1139 | 1139 |
while ((he = hash_iterator_next (&hi))) |
1140 | 1140 |
{ |
1141 | 1141 |
struct multi_instance *mi = (struct multi_instance *) he->value; |
... | ... |
@@ -1781,7 +1773,7 @@ multi_bcast (struct multi_context *m, |
1781 | 1781 |
printf ("BCAST len=%d\n", BLEN (buf)); |
1782 | 1782 |
#endif |
1783 | 1783 |
mb = mbuf_alloc_buf (buf); |
1784 |
- hash_iterator_init (m->iter, &hi, true); |
|
1784 |
+ hash_iterator_init (m->iter, &hi); |
|
1785 | 1785 |
|
1786 | 1786 |
while ((he = hash_iterator_next (&hi))) |
1787 | 1787 |
{ |
... | ... |
@@ -2249,7 +2241,7 @@ multi_get_queue (struct mbuf_set *ms) |
2249 | 2249 |
{ |
2250 | 2250 |
struct mbuf_item item; |
2251 | 2251 |
|
2252 |
- if (mbuf_extract_item (ms, &item, true)) /* cleartext IP packet */ |
|
2252 |
+ if (mbuf_extract_item (ms, &item)) /* cleartext IP packet */ |
|
2253 | 2253 |
{ |
2254 | 2254 |
unsigned int pipv4_flags = PIPV4_PASSTOS; |
2255 | 2255 |
|
... | ... |
@@ -2475,7 +2467,7 @@ management_callback_kill_by_cn (void *arg, const char *del_cn) |
2475 | 2475 |
struct hash_element *he; |
2476 | 2476 |
int count = 0; |
2477 | 2477 |
|
2478 |
- hash_iterator_init (m->iter, &hi, true); |
|
2478 |
+ hash_iterator_init (m->iter, &hi); |
|
2479 | 2479 |
while ((he = hash_iterator_next (&hi))) |
2480 | 2480 |
{ |
2481 | 2481 |
struct multi_instance *mi = (struct multi_instance *) he->value; |
... | ... |
@@ -2509,7 +2501,7 @@ management_callback_kill_by_addr (void *arg, const in_addr_t addr, const int por |
2509 | 2509 |
saddr.sa.sin_port = htons (port); |
2510 | 2510 |
if (mroute_extract_openvpn_sockaddr (&maddr, &saddr, true)) |
2511 | 2511 |
{ |
2512 |
- hash_iterator_init (m->iter, &hi, true); |
|
2512 |
+ hash_iterator_init (m->iter, &hi); |
|
2513 | 2513 |
while ((he = hash_iterator_next (&hi))) |
2514 | 2514 |
{ |
2515 | 2515 |
struct multi_instance *mi = (struct multi_instance *) he->value; |
... | ... |
@@ -56,7 +56,6 @@ struct multi_reap |
56 | 56 |
struct multi_instance { |
57 | 57 |
struct schedule_entry se; /* this must be the first element of the structure */ |
58 | 58 |
struct gc_arena gc; |
59 |
- MUTEX_DEFINE (mutex); |
|
60 | 59 |
bool defined; |
61 | 60 |
bool halt; |
62 | 61 |
int refcount; |
... | ... |
@@ -274,7 +273,6 @@ multi_instance_dec_refcount (struct multi_instance *mi) |
274 | 274 |
if (--mi->refcount <= 0) |
275 | 275 |
{ |
276 | 276 |
gc_free (&mi->gc); |
277 |
- mutex_destroy (&mi->mutex); |
|
278 | 277 |
free (mi); |
279 | 278 |
} |
280 | 279 |
} |
... | ... |
@@ -460,9 +460,6 @@ struct context |
460 | 460 |
/* true on initial VPN iteration */ |
461 | 461 |
bool first_time; |
462 | 462 |
|
463 |
- /* used by multi-client code to lock the context */ |
|
464 |
- /*MUTEX_DEFINE (mutex);*/ |
|
465 |
- |
|
466 | 463 |
/* context modes */ |
467 | 464 |
# define CM_P2P 0 /* standalone point-to-point session or client */ |
468 | 465 |
# define CM_TOP 1 /* top level of a multi-client or point-to-multipoint server */ |
... | ... |
@@ -73,9 +73,6 @@ const char title_string[] = |
73 | 73 |
#ifdef PRODUCT_TAP_DEBUG |
74 | 74 |
" [TAPDBG]" |
75 | 75 |
#endif |
76 |
-#ifdef USE_PTHREAD |
|
77 |
- " [PTHREAD]" |
|
78 |
-#endif |
|
79 | 76 |
#ifdef ENABLE_PKCS11 |
80 | 77 |
" [PKCS11]" |
81 | 78 |
#endif |
... | ... |
@@ -300,13 +297,6 @@ static const char usage_message[] = |
300 | 300 |
"--suppress-timestamps : Don't log timestamps to stdout/stderr.\n" |
301 | 301 |
"--writepid file : Write main process ID to file.\n" |
302 | 302 |
"--nice n : Change process priority (>0 = lower, <0 = higher).\n" |
303 |
-#if 0 |
|
304 |
-#ifdef USE_PTHREAD |
|
305 |
- "--nice-work n : Change thread priority of work thread. The work\n" |
|
306 |
- " thread is used for background processing such as\n" |
|
307 |
- " RSA key number crunching.\n" |
|
308 |
-#endif |
|
309 |
-#endif |
|
310 | 303 |
"--echo [parms ...] : Echo parameters to log output.\n" |
311 | 304 |
"--verb n : Set output verbosity to n (default=%d):\n" |
312 | 305 |
" (Level 3 is recommended if you want a good summary\n" |
... | ... |
@@ -740,9 +730,6 @@ init_options (struct options *o, const bool init_gc) |
740 | 740 |
o->tuntap_options.dhcp_masq_offset = 0; /* use network address as internal DHCP server address */ |
741 | 741 |
o->route_method = ROUTE_METHOD_ADAPTIVE; |
742 | 742 |
#endif |
743 |
-#ifdef USE_PTHREAD |
|
744 |
- o->n_threads = 1; |
|
745 |
-#endif |
|
746 | 743 |
#if P2MP_SERVER |
747 | 744 |
o->real_hash_size = 256; |
748 | 745 |
o->virtual_hash_size = 256; |
... | ... |
@@ -892,9 +879,6 @@ is_persist_option (const struct options *o) |
892 | 892 |
|| o->persist_key |
893 | 893 |
|| o->persist_local_ip |
894 | 894 |
|| o->persist_remote_ip |
895 |
-#ifdef USE_PTHREAD |
|
896 |
- || o->n_threads >= 2 |
|
897 |
-#endif |
|
898 | 895 |
; |
899 | 896 |
} |
900 | 897 |
|
... | ... |
@@ -2971,6 +2955,7 @@ positive_atoi (const char *str) |
2971 | 2971 |
return i < 0 ? 0 : i; |
2972 | 2972 |
} |
2973 | 2973 |
|
2974 |
+#ifdef WIN32 /* This function is only used when compiling on Windows */ |
|
2974 | 2975 |
static unsigned int |
2975 | 2976 |
atou (const char *str) |
2976 | 2977 |
{ |
... | ... |
@@ -2978,6 +2963,7 @@ atou (const char *str) |
2978 | 2978 |
sscanf (str, "%u", &val); |
2979 | 2979 |
return val; |
2980 | 2980 |
} |
2981 |
+#endif |
|
2981 | 2982 |
|
2982 | 2983 |
static inline bool |
2983 | 2984 |
space (unsigned char c) |
... | ... |
@@ -4238,26 +4224,6 @@ add_option (struct options *options, |
4238 | 4238 |
goto err; |
4239 | 4239 |
#endif |
4240 | 4240 |
} |
4241 |
-#ifdef USE_PTHREAD |
|
4242 |
- else if (streq (p[0], "nice-work") && p[1]) |
|
4243 |
- { |
|
4244 |
- VERIFY_PERMISSION (OPT_P_NICE); |
|
4245 |
- options->nice_work = atoi (p[1]); |
|
4246 |
- } |
|
4247 |
- else if (streq (p[0], "threads") && p[1]) |
|
4248 |
- { |
|
4249 |
- int n_threads; |
|
4250 |
- |
|
4251 |
- VERIFY_PERMISSION (OPT_P_GENERAL); |
|
4252 |
- n_threads = positive_atoi (p[1]); |
|
4253 |
- if (n_threads < 1) |
|
4254 |
- { |
|
4255 |
- msg (msglevel, "--threads parameter must be at least 1"); |
|
4256 |
- goto err; |
|
4257 |
- } |
|
4258 |
- options->n_threads = n_threads; |
|
4259 |
- } |
|
4260 |
-#endif |
|
4261 | 4241 |
else if (streq (p[0], "shaper") && p[1]) |
4262 | 4242 |
{ |
4263 | 4243 |
#ifdef HAVE_GETTIMEOFDAY |
... | ... |
@@ -123,10 +123,8 @@ time_string (time_t t, int usec, bool show_usec, struct gc_arena *gc) |
123 | 123 |
} |
124 | 124 |
} |
125 | 125 |
|
126 |
- mutex_lock_static (L_CTIME); |
|
127 | 126 |
t = tv.tv_sec; |
128 | 127 |
buf_printf (&out, "%s", ctime(&t)); |
129 |
- mutex_unlock_static (L_CTIME); |
|
130 | 128 |
buf_rmtail (&out, '\n'); |
131 | 129 |
|
132 | 130 |
if (show_usec && tv.tv_usec) |
... | ... |
@@ -33,10 +33,6 @@ |
33 | 33 |
|
34 | 34 |
#include "memdbg.h" |
35 | 35 |
|
36 |
-#ifdef USE_PTHREAD |
|
37 |
-#error ENABLE_PERFORMANCE_METRICS is incompatible with USE_PTHREAD |
|
38 |
-#endif |
|
39 |
- |
|
40 | 36 |
static const char *metric_names[] = { |
41 | 37 |
"PERF_BIO_READ_PLAINTEXT", |
42 | 38 |
"PERF_BIO_WRITE_PLAINTEXT", |
... | ... |
@@ -291,5 +287,7 @@ perf_print_state (int lev) |
291 | 291 |
} |
292 | 292 |
|
293 | 293 |
#else |
294 |
+#ifdef _MSC_VER /* Dummy function needed to avoid empty file compiler warning in Microsoft VC */ |
|
294 | 295 |
static void dummy(void) {} |
295 | 296 |
#endif |
297 |
+#endif |
... | ... |
@@ -644,7 +644,7 @@ pf_cn_set_print (const struct pf_cn_set *s, const int lev) |
644 | 644 |
|
645 | 645 |
if (s->hash_table) |
646 | 646 |
{ |
647 |
- hash_iterator_init (s->hash_table, &hi, false); |
|
647 |
+ hash_iterator_init (s->hash_table, &hi); |
|
648 | 648 |
while ((he = hash_iterator_next (&hi))) |
649 | 649 |
{ |
650 | 650 |
struct pf_cn *e = (struct pf_cn *)he->value; |
... | ... |
@@ -558,8 +558,6 @@ plugin_call (const struct plugin_list *pl, |
558 | 558 |
bool error = false; |
559 | 559 |
bool deferred = false; |
560 | 560 |
|
561 |
- mutex_lock_static (L_PLUGIN); |
|
562 |
- |
|
563 | 561 |
setenv_del (es, "script_type"); |
564 | 562 |
envp = make_env_array (es, false, &gc); |
565 | 563 |
|
... | ... |
@@ -588,8 +586,6 @@ plugin_call (const struct plugin_list *pl, |
588 | 588 |
if (pr) |
589 | 589 |
pr->n = i; |
590 | 590 |
|
591 |
- mutex_unlock_static (L_PLUGIN); |
|
592 |
- |
|
593 | 591 |
gc_free (&gc); |
594 | 592 |
|
595 | 593 |
if (type == OPENVPN_PLUGIN_ENABLE_PF && success) |
... | ... |
@@ -234,18 +234,6 @@ port_share_sendmsg (const socket_descriptor_t sd, |
234 | 234 |
} |
235 | 235 |
} |
236 | 236 |
|
237 |
-static int |
|
238 |
-pc_list_len (struct proxy_connection *pc) |
|
239 |
-{ |
|
240 |
- int count = 0; |
|
241 |
- while (pc) |
|
242 |
- { |
|
243 |
- ++count; |
|
244 |
- pc = pc->next; |
|
245 |
- } |
|
246 |
- return count; |
|
247 |
-} |
|
248 |
- |
|
249 | 237 |
static void |
250 | 238 |
proxy_entry_close_sd (struct proxy_connection *pc, struct event_set *es) |
251 | 239 |
{ |
... | ... |
@@ -516,6 +516,7 @@ reliable_can_send (const struct reliable *rel) |
516 | 516 |
return n_current > 0 && !rel->hold; |
517 | 517 |
} |
518 | 518 |
|
519 |
+#ifdef EXPONENTIAL_BACKOFF |
|
519 | 520 |
/* return a unique point-in-time to trigger retry */ |
520 | 521 |
static time_t |
521 | 522 |
reliable_unique_retry (struct reliable *rel, time_t retry) |
... | ... |
@@ -535,6 +536,7 @@ reliable_unique_retry (struct reliable *rel, time_t retry) |
535 | 535 |
} |
536 | 536 |
return retry; |
537 | 537 |
} |
538 |
+#endif |
|
538 | 539 |
|
539 | 540 |
/* return next buffer to send to remote */ |
540 | 541 |
struct buffer * |
... | ... |
@@ -59,26 +59,6 @@ print_bypass_addresses (const struct route_bypass *rb) |
59 | 59 |
|
60 | 60 |
#endif |
61 | 61 |
|
62 |
-static bool |
|
63 |
-add_bypass_address (struct route_bypass *rb, const in_addr_t a) |
|
64 |
-{ |
|
65 |
- int i; |
|
66 |
- for (i = 0; i < rb->n_bypass; ++i) |
|
67 |
- { |
|
68 |
- if (a == rb->bypass[i]) /* avoid duplicates */ |
|
69 |
- return true; |
|
70 |
- } |
|
71 |
- if (rb->n_bypass < N_ROUTE_BYPASS) |
|
72 |
- { |
|
73 |
- rb->bypass[rb->n_bypass++] = a; |
|
74 |
- return true; |
|
75 |
- } |
|
76 |
- else |
|
77 |
- { |
|
78 |
- return false; |
|
79 |
- } |
|
80 |
-} |
|
81 |
- |
|
82 | 62 |
struct route_option_list * |
83 | 63 |
new_route_option_list (const int max_routes, struct gc_arena *a) |
84 | 64 |
{ |
... | ... |
@@ -2153,8 +2133,18 @@ netmask_to_netbits (const in_addr_t network, const in_addr_t netmask, int *netbi |
2153 | 2153 |
static void |
2154 | 2154 |
add_host_route_if_nonlocal (struct route_bypass *rb, const in_addr_t addr) |
2155 | 2155 |
{ |
2156 |
- if (test_local_addr(addr) == TLA_NONLOCAL && addr != 0 && addr != ~0) |
|
2157 |
- add_bypass_address (rb, addr); |
|
2156 |
+ if (test_local_addr(addr) == TLA_NONLOCAL && addr != 0 && addr != ~0) { |
|
2157 |
+ int i; |
|
2158 |
+ for (i = 0; i < rb->n_bypass; ++i) |
|
2159 |
+ { |
|
2160 |
+ if (addr == rb->bypass[i]) /* avoid duplicates */ |
|
2161 |
+ return; |
|
2162 |
+ } |
|
2163 |
+ if (rb->n_bypass < N_ROUTE_BYPASS) |
|
2164 |
+ { |
|
2165 |
+ rb->bypass[rb->n_bypass++] = addr; |
|
2166 |
+ } |
|
2167 |
+ } |
|
2158 | 2168 |
} |
2159 | 2169 |
|
2160 | 2170 |
static void |
... | ... |
@@ -363,24 +363,20 @@ schedule_init (void) |
363 | 363 |
struct schedule *s; |
364 | 364 |
|
365 | 365 |
ALLOC_OBJ_CLEAR (s, struct schedule); |
366 |
- mutex_init (&s->mutex); |
|
367 | 366 |
return s; |
368 | 367 |
} |
369 | 368 |
|
370 | 369 |
void |
371 | 370 |
schedule_free (struct schedule *s) |
372 | 371 |
{ |
373 |
- mutex_destroy (&s->mutex); |
|
374 | 372 |
free (s); |
375 | 373 |
} |
376 | 374 |
|
377 | 375 |
void |
378 | 376 |
schedule_remove_entry (struct schedule *s, struct schedule_entry *e) |
379 | 377 |
{ |
380 |
- mutex_lock (&s->mutex); |
|
381 | 378 |
s->earliest_wakeup = NULL; /* invalidate cache */ |
382 | 379 |
schedule_remove_node (s, e); |
383 |
- mutex_unlock (&s->mutex); |
|
384 | 380 |
} |
385 | 381 |
|
386 | 382 |
/* |
... | ... |
@@ -42,7 +42,6 @@ |
42 | 42 |
/*#define SCHEDULE_TEST*/ |
43 | 43 |
|
44 | 44 |
#include "otime.h" |
45 |
-#include "thread.h" |
|
46 | 45 |
#include "error.h" |
47 | 46 |
|
48 | 47 |
struct schedule_entry |
... | ... |
@@ -56,7 +55,6 @@ struct schedule_entry |
56 | 56 |
|
57 | 57 |
struct schedule |
58 | 58 |
{ |
59 |
- MUTEX_DEFINE (mutex); |
|
60 | 59 |
struct schedule_entry *earliest_wakeup; /* cached earliest wakeup */ |
61 | 60 |
struct schedule_entry *root; /* the root of the treap (btree) */ |
62 | 61 |
}; |
... | ... |
@@ -100,14 +98,12 @@ schedule_add_entry (struct schedule *s, |
100 | 100 |
const struct timeval *tv, |
101 | 101 |
unsigned int sigma) |
102 | 102 |
{ |
103 |
- mutex_lock (&s->mutex); |
|
104 | 103 |
if (!IN_TREE (e) || !sigma || !tv_within_sigma (tv, &e->tv, sigma)) |
105 | 104 |
{ |
106 | 105 |
e->tv = *tv; |
107 | 106 |
schedule_add_modify (s, e); |
108 | 107 |
s->earliest_wakeup = NULL; /* invalidate cache */ |
109 | 108 |
} |
110 |
- mutex_unlock (&s->mutex); |
|
111 | 109 |
} |
112 | 110 |
|
113 | 111 |
/* |
... | ... |
@@ -122,8 +118,6 @@ schedule_get_earliest_wakeup (struct schedule *s, |
122 | 122 |
{ |
123 | 123 |
struct schedule_entry *ret; |
124 | 124 |
|
125 |
- mutex_lock (&s->mutex); |
|
126 |
- |
|
127 | 125 |
/* cache result */ |
128 | 126 |
if (!s->earliest_wakeup) |
129 | 127 |
s->earliest_wakeup = schedule_find_least (s->root); |
... | ... |
@@ -131,8 +125,6 @@ schedule_get_earliest_wakeup (struct schedule *s, |
131 | 131 |
if (ret) |
132 | 132 |
*wakeup = ret->tv; |
133 | 133 |
|
134 |
- mutex_unlock (&s->mutex); |
|
135 |
- |
|
136 | 134 |
return ret; |
137 | 135 |
} |
138 | 136 |
|
... | ... |
@@ -185,15 +185,6 @@ signal_handler (const int signum) |
185 | 185 |
signal (signum, signal_handler); |
186 | 186 |
} |
187 | 187 |
|
188 |
-/* temporary signal handler, before we are fully initialized */ |
|
189 |
-static void |
|
190 |
-signal_handler_exit (const int signum) |
|
191 |
-{ |
|
192 |
- msg (M_FATAL, |
|
193 |
- "Signal %d (%s) received during initialization, exiting", |
|
194 |
- signum, signal_description (signum, NULL)); |
|
195 |
-} |
|
196 |
- |
|
197 | 188 |
#endif |
198 | 189 |
|
199 | 190 |
/* set handlers for unix signals */ |
... | ... |
@@ -26,7 +26,6 @@ |
26 | 26 |
|
27 | 27 |
#include "socket.h" |
28 | 28 |
#include "fdmisc.h" |
29 |
-#include "thread.h" |
|
30 | 29 |
#include "misc.h" |
31 | 30 |
#include "gremlin.h" |
32 | 31 |
#include "plugin.h" |
... | ... |
@@ -1965,10 +1964,8 @@ print_sockaddr_ex (const struct openvpn_sockaddr *addr, |
1965 | 1965 |
struct buffer out = alloc_buf_gc (64, gc); |
1966 | 1966 |
const int port = ntohs (addr->sa.sin_port); |
1967 | 1967 |
|
1968 |
- mutex_lock_static (L_INET_NTOA); |
|
1969 | 1968 |
if (!(flags & PS_DONT_SHOW_ADDR)) |
1970 | 1969 |
buf_printf (&out, "%s", (addr_defined (addr) ? inet_ntoa (addr->sa.sin_addr) : "[undef]")); |
1971 |
- mutex_unlock_static (L_INET_NTOA); |
|
1972 | 1970 |
|
1973 | 1971 |
if (((flags & PS_SHOW_PORT) || (addr_defined (addr) && (flags & PS_SHOW_PORT_IF_DEFINED))) |
1974 | 1972 |
&& port) |
... | ... |
@@ -2030,9 +2027,7 @@ print_in_addr_t (in_addr_t addr, unsigned int flags, struct gc_arena *gc) |
2030 | 2030 |
CLEAR (ia); |
2031 | 2031 |
ia.s_addr = (flags & IA_NET_ORDER) ? addr : htonl (addr); |
2032 | 2032 |
|
2033 |
- mutex_lock_static (L_INET_NTOA); |
|
2034 | 2033 |
buf_printf (&out, "%s", inet_ntoa (ia)); |
2035 |
- mutex_unlock_static (L_INET_NTOA); |
|
2036 | 2034 |
} |
2037 | 2035 |
return BSTR (&out); |
2038 | 2036 |
} |
... | ... |
@@ -2048,9 +2043,7 @@ setenv_sockaddr (struct env_set *es, const char *name_prefix, const struct openv |
2048 | 2048 |
else |
2049 | 2049 |
openvpn_snprintf (name_buf, sizeof (name_buf), "%s", name_prefix); |
2050 | 2050 |
|
2051 |
- mutex_lock_static (L_INET_NTOA); |
|
2052 | 2051 |
setenv_str (es, name_buf, inet_ntoa (addr->sa.sin_addr)); |
2053 |
- mutex_unlock_static (L_INET_NTOA); |
|
2054 | 2052 |
|
2055 | 2053 |
if ((flags & SA_IP_PORT) && addr->sa.sin_port) |
2056 | 2054 |
{ |
... | ... |
@@ -112,10 +112,17 @@ socks_username_password_auth (struct socks_proxy_info *p, |
112 | 112 |
ssize_t size; |
113 | 113 |
|
114 | 114 |
creds.defined = 0; |
115 |
- |
|
116 | 115 |
get_user_pass (&creds, p->authfile, UP_TYPE_SOCKS, GET_USER_PASS_MANAGEMENT); |
117 |
- snprintf (to_send, sizeof (to_send), "\x01%c%s%c%s", strlen(creds.username), |
|
118 |
- creds.username, strlen(creds.password), creds.password); |
|
116 |
+ |
|
117 |
+ if( !creds.username || (strlen(creds.username) > 255) |
|
118 |
+ || !creds.password || (strlen(creds.password) > 255) ) { |
|
119 |
+ msg (M_NONFATAL, |
|
120 |
+ "SOCKS username and/or password exceeds 255 characters. " |
|
121 |
+ "Authentication not possible."); |
|
122 |
+ return false; |
|
123 |
+ } |
|
124 |
+ snprintf (to_send, sizeof (to_send), "\x01%c%s%c%s", (int) strlen(creds.username), |
|
125 |
+ creds.username, (int) strlen(creds.password), creds.password); |
|
119 | 126 |
size = send (sd, to_send, strlen(to_send), MSG_NOSIGNAL); |
120 | 127 |
|
121 | 128 |
if (size != strlen (to_send)) |
... | ... |
@@ -43,7 +43,6 @@ |
43 | 43 |
#include "common.h" |
44 | 44 |
#include "integer.h" |
45 | 45 |
#include "socket.h" |
46 |
-#include "thread.h" |
|
47 | 46 |
#include "misc.h" |
48 | 47 |
#include "fdmisc.h" |
49 | 48 |
#include "interval.h" |
... | ... |
@@ -4041,8 +4040,6 @@ tls_process (struct tls_multi *multi, |
4041 | 4041 |
msg (D_TLS_DEBUG_LOW, "TLS: tls_process: killed expiring key"); |
4042 | 4042 |
} |
4043 | 4043 |
|
4044 |
- /*mutex_cycle (multi->mutex);*/ |
|
4045 |
- |
|
4046 | 4044 |
do |
4047 | 4045 |
{ |
4048 | 4046 |
update_time (); |
... | ... |
@@ -4329,7 +4326,6 @@ tls_process (struct tls_multi *multi, |
4329 | 4329 |
} |
4330 | 4330 |
} |
4331 | 4331 |
} |
4332 |
- /*mutex_cycle (multi->mutex);*/ |
|
4333 | 4332 |
} |
4334 | 4333 |
while (state_change); |
4335 | 4334 |
|
... | ... |
@@ -4483,7 +4479,6 @@ tls_multi_process (struct tls_multi *multi, |
4483 | 4483 |
reset_session (multi, session); |
4484 | 4484 |
} |
4485 | 4485 |
} |
4486 |
- /*mutex_cycle (multi->mutex);*/ |
|
4487 | 4486 |
} |
4488 | 4487 |
|
4489 | 4488 |
update_time (); |
... | ... |
@@ -42,7 +42,6 @@ |
42 | 42 |
#include "reliable.h" |
43 | 43 |
#include "socket.h" |
44 | 44 |
#include "mtu.h" |
45 |
-#include "thread.h" |
|
46 | 45 |
#include "options.h" |
47 | 46 |
#include "plugin.h" |
48 | 47 |
|
... | ... |
@@ -579,9 +578,6 @@ struct tls_session |
579 | 579 |
*/ |
580 | 580 |
struct tls_multi |
581 | 581 |
{ |
582 |
- /* used to coordinate access between main thread and TLS thread */ |
|
583 |
- /*MUTEX_PTR_DEFINE (mutex);*/ |
|
584 |
- |
|
585 | 582 |
/* const options and config info */ |
586 | 583 |
struct tls_options opt; |
587 | 584 |
|
... | ... |
@@ -540,24 +540,6 @@ socket_defined (const socket_descriptor_t sd) |
540 | 540 |
#define ENABLE_BUFFER_LIST |
541 | 541 |
|
542 | 542 |
/* |
543 |
- * Do we have pthread capability? |
|
544 |
- */ |
|
545 |
-#ifdef USE_PTHREAD |
|
546 |
-#if defined(USE_CRYPTO) && defined(USE_SSL) && P2MP |
|
547 |
-#include <pthread.h> |
|
548 |
-#else |
|
549 |
-#undef USE_PTHREAD |
|
550 |
-#endif |
|
551 |
-#endif |
|
552 |
- |
|
553 |
-/* |
|
554 |
- * Pthread support is currently experimental (and quite unfinished). |
|
555 |
- */ |
|
556 |
-#if 1 /* JYFIXME -- if defined, disable pthread */ |
|
557 |
-#undef USE_PTHREAD |
|
558 |
-#endif |
|
559 |
- |
|
560 |
-/* |
|
561 | 543 |
* Should we include OCC (options consistency check) code? |
562 | 544 |
*/ |
563 | 545 |
#ifndef ENABLE_SMALL |
564 | 546 |
deleted file mode 100644 |
... | ... |
@@ -1,156 +0,0 @@ |
1 |
-/* |
|
2 |
- * OpenVPN -- An application to securely tunnel IP networks |
|
3 |
- * over a single UDP port, with support for SSL/TLS-based |
|
4 |
- * session authentication and key exchange, |
|
5 |
- * packet encryption, packet authentication, and |
|
6 |
- * packet compression. |
|
7 |
- * |
|
8 |
- * Copyright (C) 2002-2010 OpenVPN Technologies, Inc. <sales@openvpn.net> |
|
9 |
- * |
|
10 |
- * This program is free software; you can redistribute it and/or modify |
|
11 |
- * it under the terms of the GNU General Public License version 2 |
|
12 |
- * as published by the Free Software Foundation. |
|
13 |
- * |
|
14 |
- * This program is distributed in the hope that it will be useful, |
|
15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
- * GNU General Public License for more details. |
|
18 |
- * |
|
19 |
- * You should have received a copy of the GNU General Public License |
|
20 |
- * along with this program (see the file COPYING included with this |
|
21 |
- * distribution); if not, write to the Free Software Foundation, Inc., |
|
22 |
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
- */ |
|
24 |
- |
|
25 |
-#include "syshead.h" |
|
26 |
- |
|
27 |
-#ifdef USE_PTHREAD |
|
28 |
- |
|
29 |
-#include "thread.h" |
|
30 |
-#include "buffer.h" |
|
31 |
-#include "common.h" |
|
32 |
-#include "error.h" |
|
33 |
-#include "crypto.h" |
|
34 |
- |
|
35 |
-#include "memdbg.h" |
|
36 |
- |
|
37 |
-static struct sparse_mutex *ssl_mutex; /* GLOBAL */ |
|
38 |
- |
|
39 |
-static void |
|
40 |
-ssl_pthreads_locking_callback (int mode, int type, char *file, int line) |
|
41 |
-{ |
|
42 |
- dmsg (D_OPENSSL_LOCK, "SSL LOCK thread=%4lu mode=%s lock=%s %s:%d", |
|
43 |
- CRYPTO_thread_id (), |
|
44 |
- (mode & CRYPTO_LOCK) ? "l" : "u", |
|
45 |
- (type & CRYPTO_READ) ? "r" : "w", file, line); |
|
46 |
- |
|
47 |
- if (mode & CRYPTO_LOCK) |
|
48 |
- pthread_mutex_lock (&ssl_mutex[type].mutex); |
|
49 |
- else |
|
50 |
- pthread_mutex_unlock (&ssl_mutex[type].mutex); |
|
51 |
-} |
|
52 |
- |
|
53 |
-static unsigned long |
|
54 |
-ssl_pthreads_thread_id (void) |
|
55 |
-{ |
|
56 |
- unsigned long ret; |
|
57 |
- |
|
58 |
- ret = (unsigned long) pthread_self (); |
|
59 |
- return ret; |
|
60 |
-} |
|
61 |
- |
|
62 |
-static void |
|
63 |
-ssl_thread_setup (void) |
|
64 |
-{ |
|
65 |
- int i; |
|
66 |
- |
|
67 |
-#error L_MSG needs to be initialized as a recursive mutex |
|
68 |
- |
|
69 |
- ssl_mutex = OPENSSL_malloc (CRYPTO_num_locks () * sizeof (struct sparse_mutex)); |
|
70 |
- for (i = 0; i < CRYPTO_num_locks (); i++) |
|
71 |
- pthread_mutex_init (&ssl_mutex[i].mutex, NULL); |
|
72 |
- |
|
73 |
- CRYPTO_set_id_callback ((unsigned long (*)(void)) ssl_pthreads_thread_id); |
|
74 |
- CRYPTO_set_locking_callback ((void (*)(int, int, const char*, int)) ssl_pthreads_locking_callback); |
|
75 |
-} |
|
76 |
- |
|
77 |
-static void |
|
78 |
-ssl_thread_cleanup (void) |
|
79 |
-{ |
|
80 |
- int i; |
|
81 |
- |
|
82 |
- dmsg (D_OPENSSL_LOCK, "SSL LOCK cleanup"); |
|
83 |
- CRYPTO_set_locking_callback (NULL); |
|
84 |
- for (i = 0; i < CRYPTO_num_locks (); i++) |
|
85 |
- pthread_mutex_destroy (&ssl_mutex[i].mutex); |
|
86 |
- OPENSSL_free (ssl_mutex); |
|
87 |
-} |
|
88 |
- |
|
89 |
-struct sparse_mutex mutex_array[N_MUTEXES]; /* GLOBAL */ |
|
90 |
-bool pthread_initialized; /* GLOBAL */ |
|
91 |
- |
|
92 |
-openvpn_thread_t |
|
93 |
-openvpn_thread_create (void *(*start_routine) (void *), void* arg) |
|
94 |
-{ |
|
95 |
- openvpn_thread_t ret; |
|
96 |
- ASSERT (pthread_initialized); |
|
97 |
- ASSERT (!pthread_create (&ret, NULL, start_routine, arg)); |
|
98 |
- dmsg (D_THREAD_DEBUG, "CREATE THREAD ID=%lu", (unsigned long)ret); |
|
99 |
- return ret; |
|
100 |
-} |
|
101 |
- |
|
102 |
-void |
|
103 |
-openvpn_thread_join (openvpn_thread_t id) |
|
104 |
-{ |
|
105 |
- ASSERT (pthread_initialized); |
|
106 |
- pthread_join (id, NULL); |
|
107 |
-} |
|
108 |
- |
|
109 |
-void |
|
110 |
-openvpn_thread_init () |
|
111 |
-{ |
|
112 |
- int i; |
|
113 |
- |
|
114 |
- ASSERT (!pthread_initialized); |
|
115 |
- |
|
116 |
- msg (M_INFO, "PTHREAD support initialized"); |
|
117 |
- |
|
118 |
- /* initialize OpenSSL library locking */ |
|
119 |
-#if defined(USE_CRYPTO) && defined(USE_SSL) |
|
120 |
- ssl_thread_setup(); |
|
121 |
-#endif |
|
122 |
- |
|
123 |
- /* initialize static mutexes */ |
|
124 |
- for (i = 0; i < N_MUTEXES; i++) |
|
125 |
- ASSERT (!pthread_mutex_init (&mutex_array[i].mutex, NULL)); |
|
126 |
- |
|
127 |
- msg_thread_init (); |
|
128 |
- |
|
129 |
- pthread_initialized = true; |
|
130 |
-} |
|
131 |
- |
|
132 |
-void |
|
133 |
-openvpn_thread_cleanup () |
|
134 |
-{ |
|
135 |
- if (pthread_initialized) |
|
136 |
- { |
|
137 |
- int i; |
|
138 |
- |
|
139 |
- pthread_initialized = false; |
|
140 |
- |
|
141 |
- /* cleanup OpenSSL library locking */ |
|
142 |
-#if defined(USE_CRYPTO) && defined(USE_SSL) |
|
143 |
- ssl_thread_cleanup(); |
|
144 |
-#endif |
|
145 |
- |
|
146 |
- /* destroy static mutexes */ |
|
147 |
- for (i = 0; i < N_MUTEXES; i++) |
|
148 |
- ASSERT (!pthread_mutex_destroy (&mutex_array[i].mutex)); |
|
149 |
- |
|
150 |
- msg_thread_uninit (); |
|
151 |
- } |
|
152 |
-} |
|
153 |
- |
|
154 |
-#else |
|
155 |
-static void dummy(void) {} |
|
156 |
-#endif |
157 | 1 |
deleted file mode 100644 |
... | ... |
@@ -1,235 +0,0 @@ |
1 |
-/* |
|
2 |
- * OpenVPN -- An application to securely tunnel IP networks |
|
3 |
- * over a single UDP port, with support for SSL/TLS-based |
|
4 |
- * session authentication and key exchange, |
|
5 |
- * packet encryption, packet authentication, and |
|
6 |
- * packet compression. |
|
7 |
- * |
|
8 |
- * Copyright (C) 2002-2010 OpenVPN Technologies, Inc. <sales@openvpn.net> |
|
9 |
- * |
|
10 |
- * This program is free software; you can redistribute it and/or modify |
|
11 |
- * it under the terms of the GNU General Public License version 2 |
|
12 |
- * as published by the Free Software Foundation. |
|
13 |
- * |
|
14 |
- * This program is distributed in the hope that it will be useful, |
|
15 |
- * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
- * GNU General Public License for more details. |
|
18 |
- * |
|
19 |
- * You should have received a copy of the GNU General Public License |
|
20 |
- * along with this program (see the file COPYING included with this |
|
21 |
- * distribution); if not, write to the Free Software Foundation, Inc., |
|
22 |
- * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
23 |
- */ |
|
24 |
- |
|
25 |
-#ifndef THREAD_H |
|
26 |
-#define THREAD_H |
|
27 |
- |
|
28 |
-#include "basic.h" |
|
29 |
-#include "common.h" |
|
30 |
- |
|
31 |
-/* |
|
32 |
- * OpenVPN static mutex locks, by mutex type |
|
33 |
- */ |
|
34 |
-#define L_UNUSED 0 |
|
35 |
-#define L_CTIME 1 |
|
36 |
-#define L_INET_NTOA 2 |
|
37 |
-#define L_MSG 3 |
|
38 |
-#define L_STRERR 4 |
|
39 |
-#define L_PUTENV 5 |
|
40 |
-#define L_PRNG 6 |
|
41 |
-#define L_GETTIMEOFDAY 7 |
|
42 |
-#define L_ENV_SET 8 |
|
43 |
-#define L_SYSTEM 9 |
|
44 |
-#define L_CREATE_TEMP 10 |
|
45 |
-#define L_PLUGIN 11 |
|
46 |
-#define N_MUTEXES 12 |
|
47 |
- |
|
48 |
-#ifdef USE_PTHREAD |
|
49 |
- |
|
50 |
-#define MAX_THREADS 50 |
|
51 |
- |
|
52 |
-#define CACHE_LINE_SIZE 128 |
|
53 |
- |
|
54 |
-/* |
|
55 |
- * Improve SMP performance by making sure that each |
|
56 |
- * mutex resides in its own cache line. |
|
57 |
- */ |
|
58 |
-struct sparse_mutex |
|
59 |
-{ |
|
60 |
- pthread_mutex_t mutex; |
|
61 |
- uint8_t dummy [CACHE_LINE_SIZE - sizeof (pthread_mutex_t)]; |
|
62 |
-}; |
|
63 |
- |
|
64 |
-typedef pthread_t openvpn_thread_t; |
|
65 |
- |
|
66 |
-extern bool pthread_initialized; |
|
67 |
- |
|
68 |
-extern struct sparse_mutex mutex_array[N_MUTEXES]; |
|
69 |
- |
|
70 |
-#define MUTEX_DEFINE(lock) pthread_mutex_t lock |
|
71 |
-#define MUTEX_PTR_DEFINE(lock) pthread_mutex_t *lock |
|
72 |
- |
|
73 |
-static inline bool |
|
74 |
-openvpn_thread_enabled (void) |
|
75 |
-{ |
|
76 |
- return pthread_initialized; |
|
77 |
-} |
|
78 |
- |
|
79 |
-static inline openvpn_thread_t |
|
80 |
-openvpn_thread_self (void) |
|
81 |
-{ |
|
82 |
- return pthread_initialized ? pthread_self() : 0; |
|
83 |
-} |
|
84 |
- |
|
85 |
-static inline void |
|
86 |
-mutex_init (pthread_mutex_t *mutex) |
|
87 |
-{ |
|
88 |
- if (mutex) |
|
89 |
- pthread_mutex_init (mutex, NULL); |
|
90 |
-} |
|
91 |
- |
|
92 |
-static inline void |
|
93 |
-mutex_destroy (pthread_mutex_t *mutex) |
|
94 |
-{ |
|
95 |
- if (mutex) |
|
96 |
- pthread_mutex_destroy (mutex); |
|
97 |
-} |
|
98 |
- |
|
99 |
-static inline void |
|
100 |
-mutex_lock (pthread_mutex_t *mutex) |
|
101 |
-{ |
|
102 |
- if (pthread_initialized && mutex) |
|
103 |
- pthread_mutex_lock (mutex); |
|
104 |
-} |
|
105 |
- |
|
106 |
-static inline bool |
|
107 |
-mutex_trylock (pthread_mutex_t *mutex) |
|
108 |
-{ |
|
109 |
- if (pthread_initialized && mutex) |
|
110 |
- return pthread_mutex_trylock (mutex) == 0; |
|
111 |
- else |
|
112 |
- return true; |
|
113 |
-} |
|
114 |
- |
|
115 |
-static inline void |
|
116 |
-mutex_unlock (pthread_mutex_t *mutex) |
|
117 |
-{ |
|
118 |
- if (pthread_initialized && mutex) |
|
119 |
- { |
|
120 |
- pthread_mutex_unlock (mutex); |
|
121 |
-#if 1 /* JYFIXME: if race conditions exist, make them more likely to occur */ |
|
122 |
- sleep (0); |
|
123 |
-#endif |
|
124 |
- } |
|
125 |
-} |
|
126 |
- |
|
127 |
-static inline void |
|
128 |
-mutex_cycle (pthread_mutex_t *mutex) |
|
129 |
-{ |
|
130 |
- if (pthread_initialized && mutex) |
|
131 |
- { |
|
132 |
- pthread_mutex_unlock (mutex); |
|
133 |
- sleep (0); |
|
134 |
- pthread_mutex_lock (mutex); |
|
135 |
- } |
|
136 |
-} |
|
137 |
- |
|
138 |
-static inline void |
|
139 |
-mutex_lock_static (int type) |
|
140 |
-{ |
|
141 |
- mutex_lock (&mutex_array[type].mutex); |
|
142 |
-} |
|
143 |
- |
|
144 |
-static inline void |
|
145 |
-mutex_unlock_static (int type) |
|
146 |
-{ |
|
147 |
- mutex_unlock (&mutex_array[type].mutex); |
|
148 |
-} |
|
149 |
- |
|
150 |
-static inline void |
|
151 |
-mutex_cycle_static (int type) |
|
152 |
-{ |
|
153 |
- mutex_cycle (&mutex_array[type].mutex); |
|
154 |
-} |
|
155 |
- |
|
156 |
-void openvpn_thread_init (void); |
|
157 |
-void openvpn_thread_cleanup (void); |
|
158 |
- |
|
159 |
-openvpn_thread_t openvpn_thread_create (void *(*start_routine) (void *), void* arg); |
|
160 |
-void openvpn_thread_join (openvpn_thread_t id); |
|
161 |
- |
|
162 |
-#else /* USE_PTHREAD */ |
|
163 |
- |
|
164 |
-typedef int openvpn_thread_t; |
|
165 |
- |
|
166 |
-#if defined(_MSC_VER) || PEDANTIC |
|
167 |
- |
|
168 |
-#define MUTEX_DEFINE(lock) int eat_semicolon |
|
169 |
-#define MUTEX_PTR_DEFINE(lock) int eat_semicolon |
|
170 |
- |
|
171 |
-#else |
|
172 |
- |
|
173 |
-#define MUTEX_DEFINE(lock) |
|
174 |
-#define MUTEX_PTR_DEFINE(lock) |
|
175 |
- |
|
176 |
-#endif |
|
177 |
- |
|
178 |
-#define mutex_init(m) |
|
179 |
-#define mutex_destroy(m) |
|
180 |
-#define mutex_lock(m) |
|
181 |
-#define mutex_trylock(m) (true) |
|
182 |
-#define mutex_unlock(m) |
|
183 |
-#define mutex_cycle(m) |
|
184 |
- |
|
185 |
-static inline bool |
|
186 |
-openvpn_thread_enabled (void) |
|
187 |
-{ |
|
188 |
- return false; |
|
189 |
-} |
|
190 |
- |
|
191 |
-static inline openvpn_thread_t |
|
192 |
-openvpn_thread_self (void) |
|
193 |
-{ |
|
194 |
- return 0; |
|
195 |
-} |
|
196 |
- |
|
197 |
-static inline void |
|
198 |
-openvpn_thread_init (void) |
|
199 |
-{ |
|
200 |
-} |
|
201 |
- |
|
202 |
-static inline void |
|
203 |
-openvpn_thread_cleanup (void) |
|
204 |
-{ |
|
205 |
-} |
|
206 |
- |
|
207 |
-static inline openvpn_thread_t |
|
208 |
-openvpn_thread_create (void *(*start_routine) (void *), void* arg) |
|
209 |
-{ |
|
210 |
- return 0; |
|
211 |
-} |
|
212 |
- |
|
213 |
-static inline void |
|
214 |
-work_thread_join (openvpn_thread_t id) |
|
215 |
-{ |
|
216 |
-} |
|
217 |
- |
|
218 |
-static inline void |
|
219 |
-mutex_lock_static (int type) |
|
220 |
-{ |
|
221 |
-} |
|
222 |
- |
|
223 |
-static inline void |
|
224 |
-mutex_unlock_static (int type) |
|
225 |
-{ |
|
226 |
-} |
|
227 |
- |
|
228 |
-static inline void |
|
229 |
-mutex_cycle_static (int type) |
|
230 |
-{ |
|
231 |
-} |
|
232 |
- |
|
233 |
-#endif /* USE_PTHREAD */ |
|
234 |
- |
|
235 |
-#endif /* THREAD_H */ |