mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-27 13:53:31 +01:00
Raise libevent dependency to 2.0.10-stable or newer
Only some very ancient distributions don't ship with Libevent 2 anymore, even the oldest supported Ubuntu LTS version has it. This allows us to get rid of a lot of compat code.
This commit is contained in:
parent
ec6ea66240
commit
265e40b481
@ -176,7 +176,7 @@ coverage-html-full: all
|
||||
genhtml --branch-coverage -o "$(HTML_COVER_DIR)" "$(HTML_COVER_DIR)/lcov.info"
|
||||
|
||||
# Avoid strlcpy.c, strlcat.c, aes.c, OpenBSD_malloc_Linux.c, sha256.c,
|
||||
# eventdns.[hc], tinytest*.[ch]
|
||||
# tinytest*.[ch]
|
||||
check-spaces:
|
||||
$(top_srcdir)/scripts/maint/checkSpace.pl -C \
|
||||
$(top_srcdir)/src/common/*.[ch] \
|
||||
|
59
configure.ac
59
configure.ac
@ -481,7 +481,7 @@ TOR_SEARCH_LIBRARY(libevent, $trylibeventdir, [-levent $STATIC_LIBEVENT_FLAGS $T
|
||||
#endif
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <event.h>], [
|
||||
#include <event2/event.h>], [
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
@ -500,21 +500,10 @@ save_CPPFLAGS="$CPPFLAGS"
|
||||
LIBS="-levent $STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $LIBS"
|
||||
LDFLAGS="$TOR_LDFLAGS_libevent $LDFLAGS"
|
||||
CPPFLAGS="$TOR_CPPFLAGS_libevent $CPPFLAGS"
|
||||
AC_CHECK_FUNCS([event_get_version_number \
|
||||
evutil_secure_rng_set_urandom_device_file \
|
||||
evutil_secure_rng_init \
|
||||
])
|
||||
AC_CHECK_MEMBERS([struct event.min_heap_idx], , ,
|
||||
[#include <event.h>
|
||||
])
|
||||
|
||||
AC_CHECK_HEADERS(event2/event.h event2/dns.h event2/bufferevent_ssl.h)
|
||||
AC_CHECK_FUNCS([evutil_secure_rng_set_urandom_device_file])
|
||||
|
||||
LIBS="$STATIC_LIBEVENT_FLAGS $TOR_LIB_WS32 $save_LIBS"
|
||||
|
||||
AM_CONDITIONAL(USE_EXTERNAL_EVDNS,
|
||||
test "x$ac_cv_header_event2_dns_h" = "xyes")
|
||||
|
||||
if test "$enable_static_libevent" = "yes"; then
|
||||
if test "$tor_cv_library_libevent_dir" = "(system)"; then
|
||||
AC_MSG_ERROR("You must specify an explicit --with-libevent-dir=x option when using --enable-static-libevent")
|
||||
@ -541,32 +530,34 @@ LIBS="$save_LIBS"
|
||||
LDFLAGS="$save_LDFLAGS"
|
||||
CPPFLAGS="$save_CPPFLAGS"
|
||||
|
||||
dnl This isn't the best test for Libevent 2.0.3-alpha. Once it's released,
|
||||
dnl we can do much better.
|
||||
if test "$enable_bufferevents" = "yes"; then
|
||||
if test "$ac_cv_header_event2_bufferevent_ssl_h" != "yes"; then
|
||||
AC_MSG_ERROR([You've asked for bufferevent support, but you're using a version of Libevent without SSL support. This won't work. We need Libevent 2.0.8-rc or later, and you don't seem to even have Libevent 2.0.3-alpha.])
|
||||
else
|
||||
|
||||
CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
|
||||
|
||||
# Check for the right version. First see if version detection works.
|
||||
AC_MSG_CHECKING([whether we can detect the Libevent version])
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
dnl Check that libevent is at least at version 2.0.10, the first stable
|
||||
dnl release of its series
|
||||
CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
|
||||
AC_MSG_CHECKING([whether Libevent is new enough])
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
#include <event2/event.h>
|
||||
#if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 10
|
||||
#if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000a00
|
||||
#error
|
||||
int x = y(zz);
|
||||
#else
|
||||
int x = 1;
|
||||
#endif
|
||||
])], [event_version_number_works=yes; AC_MSG_RESULT([yes]) ],
|
||||
[event_version_number_works=no; AC_MSG_RESULT([no])])
|
||||
if test "$event_version_number_works" != "yes"; then
|
||||
AC_MSG_WARN([Version detection on Libevent seems broken. Your Libevent installation is probably screwed up or very old.])
|
||||
else
|
||||
AC_MSG_CHECKING([whether Libevent is new enough for bufferevents])
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
])], [ AC_MSG_RESULT([yes]) ],
|
||||
[ AC_MSG_RESULT([no])
|
||||
AC_MSG_ERROR([Libevent is not new enough. We require 2.0.10-stable or later]) ] )
|
||||
|
||||
LIBS="$save_LIBS"
|
||||
LDFLAGS="$save_LDFLAGS"
|
||||
CPPFLAGS="$save_CPPFLAGS"
|
||||
|
||||
dnl bufferents require version 2.0.13
|
||||
if test "$enable_bufferevents" = "yes"; then
|
||||
AC_CHECK_HEADERS(event2/bufferevent_ssl.h)
|
||||
|
||||
CPPFLAGS="$CPPFLAGS $TOR_CPPFLAGS_libevent"
|
||||
|
||||
AC_MSG_CHECKING([whether Libevent is new enough for bufferevents])
|
||||
AC_COMPILE_IFELSE([AC_LANG_SOURCE([
|
||||
#include <event2/event.h>
|
||||
#if !defined(LIBEVENT_VERSION_NUMBER) || LIBEVENT_VERSION_NUMBER < 0x02000d00
|
||||
#error
|
||||
@ -577,8 +568,6 @@ int x = 1;
|
||||
])], [ AC_MSG_RESULT([yes]) ],
|
||||
[ AC_MSG_RESULT([no])
|
||||
AC_MSG_ERROR([Libevent does not seem new enough to support bufferevents. We require 2.0.13-stable or later]) ] )
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
LIBS="$save_LIBS"
|
||||
|
@ -33,8 +33,6 @@
|
||||
# files that we've snarfed in from somebody else, whose C we do no intend
|
||||
# to document for them.
|
||||
SKIP_FILES = [ "OpenBSD_malloc_Linux.c",
|
||||
"eventdns.c",
|
||||
"eventdns.h",
|
||||
"strlcat.c",
|
||||
"strlcpy.c",
|
||||
"sha256.c",
|
||||
|
@ -19,15 +19,11 @@
|
||||
#include "util.h"
|
||||
#include "torlog.h"
|
||||
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#include <event2/event.h>
|
||||
#include <event2/thread.h>
|
||||
#ifdef USE_BUFFEREVENTS
|
||||
#include <event2/bufferevent.h>
|
||||
#endif
|
||||
#else
|
||||
#include <event.h>
|
||||
#endif
|
||||
|
||||
/** A string which, if it appears in a libevent log, should be ignored. */
|
||||
static const char *suppress_msg = NULL;
|
||||
@ -69,6 +65,7 @@ configure_libevent_logging(void)
|
||||
{
|
||||
event_set_log_callback(libevent_logging_callback);
|
||||
}
|
||||
|
||||
/** Ignore any libevent log message that contains <b>msg</b>. */
|
||||
void
|
||||
suppress_libevent_log_msg(const char *msg)
|
||||
@ -76,44 +73,6 @@ suppress_libevent_log_msg(const char *msg)
|
||||
suppress_msg = msg;
|
||||
}
|
||||
|
||||
#ifndef HAVE_EVENT2_EVENT_H
|
||||
/** Work-alike replacement for event_new() on pre-Libevent-2.0 systems. */
|
||||
struct event *
|
||||
tor_event_new(struct event_base *base, int sock, short what,
|
||||
void (*cb)(int, short, void *), void *arg)
|
||||
{
|
||||
struct event *e = tor_malloc_zero(sizeof(struct event));
|
||||
event_set(e, sock, what, cb, arg);
|
||||
if (! base)
|
||||
base = tor_libevent_get_base();
|
||||
event_base_set(base, e);
|
||||
return e;
|
||||
}
|
||||
/** Work-alike replacement for evtimer_new() on pre-Libevent-2.0 systems. */
|
||||
struct event *
|
||||
tor_evtimer_new(struct event_base *base,
|
||||
void (*cb)(int, short, void *), void *arg)
|
||||
{
|
||||
return tor_event_new(base, -1, 0, cb, arg);
|
||||
}
|
||||
/** Work-alike replacement for evsignal_new() on pre-Libevent-2.0 systems. */
|
||||
struct event *
|
||||
tor_evsignal_new(struct event_base * base, int sig,
|
||||
void (*cb)(int, short, void *), void *arg)
|
||||
{
|
||||
return tor_event_new(base, sig, EV_SIGNAL|EV_PERSIST, cb, arg);
|
||||
}
|
||||
/** Work-alike replacement for event_free() on pre-Libevent-2.0 systems,
|
||||
* except tolerate tor_event_free(NULL). */
|
||||
void
|
||||
tor_event_free(struct event *ev)
|
||||
{
|
||||
if (ev == NULL)
|
||||
return;
|
||||
event_del(ev);
|
||||
tor_free(ev);
|
||||
}
|
||||
#else
|
||||
/* Wrapper for event_free() that tolerates tor_event_free(NULL) */
|
||||
void
|
||||
tor_event_free(struct event *ev)
|
||||
@ -122,7 +81,6 @@ tor_event_free(struct event *ev)
|
||||
return;
|
||||
event_free(ev);
|
||||
}
|
||||
#endif
|
||||
|
||||
/** Global event base for use by the main thread. */
|
||||
static struct event_base *the_event_base = NULL;
|
||||
@ -158,7 +116,6 @@ tor_libevent_initialize(tor_libevent_cfg *torcfg)
|
||||
/* some paths below don't use torcfg, so avoid unused variable warnings */
|
||||
(void)torcfg;
|
||||
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
{
|
||||
int attempts = 0;
|
||||
int using_threads;
|
||||
@ -190,16 +147,12 @@ tor_libevent_initialize(tor_libevent_cfg *torcfg)
|
||||
event_config_set_flag(cfg, EVENT_BASE_FLAG_NOLOCK);
|
||||
}
|
||||
|
||||
#if defined(LIBEVENT_VERSION_NUMBER) && LIBEVENT_VERSION_NUMBER >= V(2,0,7)
|
||||
if (torcfg->num_cpus > 0)
|
||||
event_config_set_num_cpus_hint(cfg, torcfg->num_cpus);
|
||||
#endif
|
||||
|
||||
#if LIBEVENT_VERSION_NUMBER >= V(2,0,9)
|
||||
/* We can enable changelist support with epoll, since we don't give
|
||||
* Libevent any dup'd fds. This lets us avoid some syscalls. */
|
||||
event_config_set_flag(cfg, EVENT_BASE_FLAG_EPOLL_USE_CHANGELIST);
|
||||
#endif
|
||||
|
||||
the_event_base = event_base_new_with_config(cfg);
|
||||
|
||||
@ -223,9 +176,6 @@ tor_libevent_initialize(tor_libevent_cfg *torcfg)
|
||||
goto retry;
|
||||
}
|
||||
}
|
||||
#else
|
||||
the_event_base = event_init();
|
||||
#endif
|
||||
|
||||
if (!the_event_base) {
|
||||
/* LCOV_EXCL_START */
|
||||
@ -255,62 +205,7 @@ tor_libevent_get_base, (void))
|
||||
const char *
|
||||
tor_libevent_get_method(void)
|
||||
{
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
return event_base_get_method(the_event_base);
|
||||
#else
|
||||
return event_get_method();
|
||||
#endif
|
||||
}
|
||||
|
||||
/** Return the le_version_t for the version of libevent specified in the
|
||||
* string <b>v</b>. If the version is very new or uses an unrecognized
|
||||
* version, format, return LE_OTHER. */
|
||||
STATIC le_version_t
|
||||
tor_decode_libevent_version(const char *v)
|
||||
{
|
||||
unsigned major, minor, patchlevel;
|
||||
char c, e, extra;
|
||||
int fields;
|
||||
|
||||
/* Try the new preferred "1.4.11-stable" format.
|
||||
* Also accept "1.4.14b-stable". */
|
||||
fields = tor_sscanf(v, "%u.%u.%u%c%c", &major, &minor, &patchlevel, &c, &e);
|
||||
if (fields == 3 ||
|
||||
((fields == 4 || fields == 5 ) && (c == '-' || c == '_')) ||
|
||||
(fields == 5 && TOR_ISALPHA(c) && (e == '-' || e == '_'))) {
|
||||
return V(major,minor,patchlevel);
|
||||
}
|
||||
|
||||
/* Try the old "1.3e" format. */
|
||||
fields = tor_sscanf(v, "%u.%u%c%c", &major, &minor, &c, &extra);
|
||||
if (fields == 3 && TOR_ISALPHA(c)) {
|
||||
return V_OLD(major, minor, c);
|
||||
} else if (fields == 2) {
|
||||
return V(major, minor, 0);
|
||||
}
|
||||
|
||||
return LE_OTHER;
|
||||
}
|
||||
|
||||
/** Return an integer representing the binary interface of a Libevent library.
|
||||
* Two different versions with different numbers are sure not to be binary
|
||||
* compatible. Two different versions with the same numbers have a decent
|
||||
* chance of binary compatibility.*/
|
||||
STATIC int
|
||||
le_versions_compatibility(le_version_t v)
|
||||
{
|
||||
if (v == LE_OTHER)
|
||||
return 0;
|
||||
if (v < V_OLD(1,0,'c'))
|
||||
return 1;
|
||||
else if (v < V(1,4,0))
|
||||
return 2;
|
||||
else if (v < V(1,4,99))
|
||||
return 3;
|
||||
else if (v < V(2,0,1))
|
||||
return 4;
|
||||
else /* Everything 2.0 and later should be compatible. */
|
||||
return 5;
|
||||
}
|
||||
|
||||
/** Return a string representation of the version of the currently running
|
||||
@ -321,101 +216,14 @@ tor_libevent_get_version_str(void)
|
||||
return event_get_version();
|
||||
}
|
||||
|
||||
#if defined(LIBEVENT_VERSION)
|
||||
#define HEADER_VERSION LIBEVENT_VERSION
|
||||
#elif defined(_EVENT_VERSION)
|
||||
#define HEADER_VERSION _EVENT_VERSION
|
||||
#endif
|
||||
|
||||
/** Return a string representation of the version of Libevent that was used
|
||||
* at compilation time. */
|
||||
const char *
|
||||
tor_libevent_get_header_version_str(void)
|
||||
{
|
||||
return HEADER_VERSION;
|
||||
return LIBEVENT_VERSION;
|
||||
}
|
||||
|
||||
/** See whether the headers we were built against differ from the library we
|
||||
* linked against so much that we're likely to crash. If so, warn the
|
||||
* user. */
|
||||
void
|
||||
tor_check_libevent_header_compatibility(void)
|
||||
{
|
||||
(void) le_versions_compatibility;
|
||||
(void) tor_decode_libevent_version;
|
||||
|
||||
/* In libevent versions before 2.0, it's hard to keep binary compatibility
|
||||
* between upgrades, and unpleasant to detect when the version we compiled
|
||||
* against is unlike the version we have linked against. Here's how. */
|
||||
#if defined(HEADER_VERSION)
|
||||
/* We have a header-file version and a function-call version. Easy. */
|
||||
if (strcmp(HEADER_VERSION, event_get_version())) {
|
||||
le_version_t v1, v2;
|
||||
int compat1 = -1, compat2 = -1;
|
||||
int verybad;
|
||||
v1 = tor_decode_libevent_version(HEADER_VERSION);
|
||||
v2 = tor_decode_libevent_version(event_get_version());
|
||||
compat1 = le_versions_compatibility(v1);
|
||||
compat2 = le_versions_compatibility(v2);
|
||||
|
||||
verybad = compat1 != compat2;
|
||||
|
||||
tor_log(verybad ? LOG_WARN : LOG_NOTICE,
|
||||
LD_GENERAL, "We were compiled with headers from version %s "
|
||||
"of Libevent, but we're using a Libevent library that says it's "
|
||||
"version %s.", HEADER_VERSION, event_get_version());
|
||||
if (verybad)
|
||||
log_warn(LD_GENERAL, "This will almost certainly make Tor crash.");
|
||||
else
|
||||
log_info(LD_GENERAL, "I think these versions are binary-compatible.");
|
||||
}
|
||||
#else
|
||||
/* event_get_version but no _EVENT_VERSION. We might be in 1.4.0-beta or
|
||||
earlier, where that's normal. To see whether we were compiled with an
|
||||
earlier version, let's see whether the struct event defines MIN_HEAP_IDX.
|
||||
*/
|
||||
#ifdef HAVE_STRUCT_EVENT_MIN_HEAP_IDX
|
||||
/* The header files are 1.4.0-beta or later. If the version is not
|
||||
* 1.4.0-beta, we are incompatible. */
|
||||
{
|
||||
if (strcmp(event_get_version(), "1.4.0-beta")) {
|
||||
log_warn(LD_GENERAL, "It's a little hard to tell, but you seem to have "
|
||||
"Libevent 1.4.0-beta header files, whereas you have linked "
|
||||
"against Libevent %s. This will probably make Tor crash.",
|
||||
event_get_version());
|
||||
}
|
||||
}
|
||||
#else
|
||||
/* Our headers are 1.3e or earlier. If the library version is not 1.4.x or
|
||||
later, we're probably fine. */
|
||||
{
|
||||
const char *v = event_get_version();
|
||||
if ((v[0] == '1' && v[2] == '.' && v[3] > '3') || v[0] > '1') {
|
||||
log_warn(LD_GENERAL, "It's a little hard to tell, but you seem to have "
|
||||
"Libevent header file from 1.3e or earlier, whereas you have "
|
||||
"linked against Libevent %s. This will probably make Tor "
|
||||
"crash.", event_get_version());
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Your libevent is ancient. */
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
If possible, we're going to try to use Libevent's periodic timer support,
|
||||
since it does a pretty good job of making sure that periodic events get
|
||||
called exactly M seconds apart, rather than starting each one exactly M
|
||||
seconds after the time that the last one was run.
|
||||
*/
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#define HAVE_PERIODIC
|
||||
#define PERIODIC_FLAGS EV_PERSIST
|
||||
#else
|
||||
#define PERIODIC_FLAGS 0
|
||||
#endif
|
||||
|
||||
/** Represents a timer that's run every N microseconds by Libevent. */
|
||||
struct periodic_timer_t {
|
||||
/** Underlying event used to implement this periodic event. */
|
||||
@ -424,11 +232,6 @@ struct periodic_timer_t {
|
||||
void (*cb)(struct periodic_timer_t *, void *);
|
||||
/** User-supplied data for the callback */
|
||||
void *data;
|
||||
#ifndef HAVE_PERIODIC
|
||||
/** If Libevent doesn't know how to invoke events every N microseconds,
|
||||
* we'll need to remember the timeout interval here. */
|
||||
struct timeval tv;
|
||||
#endif
|
||||
};
|
||||
|
||||
/** Libevent callback to implement a periodic event. */
|
||||
@ -438,10 +241,6 @@ periodic_timer_cb(evutil_socket_t fd, short what, void *arg)
|
||||
periodic_timer_t *timer = arg;
|
||||
(void) what;
|
||||
(void) fd;
|
||||
#ifndef HAVE_PERIODIC
|
||||
/** reschedule the event as needed. */
|
||||
event_add(timer->ev, &timer->tv);
|
||||
#endif
|
||||
timer->cb(timer, timer->data);
|
||||
}
|
||||
|
||||
@ -459,16 +258,13 @@ periodic_timer_new(struct event_base *base,
|
||||
tor_assert(tv);
|
||||
tor_assert(cb);
|
||||
timer = tor_malloc_zero(sizeof(periodic_timer_t));
|
||||
if (!(timer->ev = tor_event_new(base, -1, PERIODIC_FLAGS,
|
||||
if (!(timer->ev = tor_event_new(base, -1, EV_PERSIST,
|
||||
periodic_timer_cb, timer))) {
|
||||
tor_free(timer);
|
||||
return NULL;
|
||||
}
|
||||
timer->cb = cb;
|
||||
timer->data = data;
|
||||
#ifndef HAVE_PERIODIC
|
||||
memcpy(&timer->tv, tv, sizeof(struct timeval));
|
||||
#endif
|
||||
event_add(timer->ev, (struct timeval *)tv); /*drop const for old libevent*/
|
||||
return timer;
|
||||
}
|
||||
@ -539,7 +335,6 @@ int
|
||||
tor_init_libevent_rng(void)
|
||||
{
|
||||
int rv = 0;
|
||||
#ifdef HAVE_EVUTIL_SECURE_RNG_INIT
|
||||
char buf[256];
|
||||
if (evutil_secure_rng_init() < 0) {
|
||||
rv = -1;
|
||||
@ -547,7 +342,6 @@ tor_init_libevent_rng(void)
|
||||
crypto_rand(buf, 32);
|
||||
evutil_secure_rng_add_bytes(buf, 32);
|
||||
evutil_secure_rng_get_bytes(buf, sizeof(buf));
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -15,32 +15,17 @@ struct ev_token_bucket_cfg;
|
||||
struct bufferevent_rate_limit_group;
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#include <event2/util.h>
|
||||
#elif !defined(EVUTIL_SOCKET_DEFINED)
|
||||
#define EVUTIL_SOCKET_DEFINED
|
||||
#define evutil_socket_t int
|
||||
#endif
|
||||
|
||||
void configure_libevent_logging(void);
|
||||
void suppress_libevent_log_msg(const char *msg);
|
||||
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#define tor_event_new event_new
|
||||
#define tor_evtimer_new evtimer_new
|
||||
#define tor_evsignal_new evsignal_new
|
||||
#define tor_evdns_add_server_port(sock, tcp, cb, data) \
|
||||
evdns_add_server_port_with_base(tor_libevent_get_base(), \
|
||||
(sock),(tcp),(cb),(data));
|
||||
#else
|
||||
struct event *tor_event_new(struct event_base * base, evutil_socket_t sock,
|
||||
short what, void (*cb)(evutil_socket_t, short, void *), void *arg);
|
||||
struct event *tor_evtimer_new(struct event_base * base,
|
||||
void (*cb)(evutil_socket_t, short, void *), void *arg);
|
||||
struct event *tor_evsignal_new(struct event_base * base, int sig,
|
||||
void (*cb)(evutil_socket_t, short, void *), void *arg);
|
||||
#define tor_evdns_add_server_port evdns_add_server_port
|
||||
#endif
|
||||
|
||||
void tor_event_free(struct event *ev);
|
||||
|
||||
@ -99,9 +84,7 @@ void tor_gettimeofday_cached_monotonic(struct timeval *tv);
|
||||
byte is unused.
|
||||
|
||||
This is equivalent to the format of LIBEVENT_VERSION_NUMBER on Libevent
|
||||
2.0.1 or later. For versions of Libevent before 1.4.0, which followed the
|
||||
format of "1.0, 1.0a, 1.0b", we define 1.0 to be equivalent to 1.0.0, 1.0a
|
||||
to be equivalent to 1.0.1, and so on.
|
||||
2.0.1 or later.
|
||||
*/
|
||||
typedef uint32_t le_version_t;
|
||||
|
||||
@ -109,23 +92,10 @@ typedef uint32_t le_version_t;
|
||||
/** Macros: returns the number of a libevent version as a le_version_t */
|
||||
#define V(major, minor, patch) \
|
||||
(((major) << 24) | ((minor) << 16) | ((patch) << 8))
|
||||
#define V_OLD(major, minor, patch) \
|
||||
V((major), (minor), (patch)-'a'+1)
|
||||
/** @} */
|
||||
|
||||
/** Represetns a version of libevent so old we can't figure out what version
|
||||
* it is. */
|
||||
#define LE_OLD V(0,0,0)
|
||||
/** Represents a version of libevent so weird we can't figure out what version
|
||||
* it is. */
|
||||
#define LE_OTHER V(0,0,99)
|
||||
|
||||
STATIC void
|
||||
libevent_logging_callback(int severity, const char *msg);
|
||||
STATIC le_version_t
|
||||
tor_decode_libevent_version(const char *v);
|
||||
STATIC int
|
||||
le_versions_compatibility(le_version_t v);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -10,11 +10,7 @@
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#include <event2/event.h>
|
||||
#else
|
||||
#include <event.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SIGNAL_H
|
||||
#include <signal.h>
|
||||
@ -164,11 +160,7 @@ tor_validate_process_specifier(const char *process_spec,
|
||||
}
|
||||
|
||||
/* XXXX we should use periodic_timer_new() for this stuff */
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#define PERIODIC_TIMER_FLAGS EV_PERSIST
|
||||
#else
|
||||
#define PERIODIC_TIMER_FLAGS (0)
|
||||
#endif
|
||||
|
||||
/* DOCDOC poll_interval_tv */
|
||||
static struct timeval poll_interval_tv = {15, 0};
|
||||
@ -331,10 +323,6 @@ tor_process_monitor_poll_cb(evutil_socket_t unused1, short unused2,
|
||||
|
||||
if (its_dead_jim) {
|
||||
procmon->cb(procmon->cb_arg);
|
||||
#ifndef HAVE_EVENT2_EVENT_H
|
||||
} else {
|
||||
evtimer_add(procmon->e, &poll_interval_tv);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
@ -38,11 +38,7 @@
|
||||
#include "torlog.h"
|
||||
#include "util.h"
|
||||
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#include <event2/event.h>
|
||||
#else
|
||||
#include <event.h>
|
||||
#endif
|
||||
|
||||
struct timeout_cb {
|
||||
timer_cb_fn_t cb;
|
||||
|
@ -11,13 +11,6 @@ strlcpy.c
|
||||
for strcat and strcpy. These are nonstandard, and some libc
|
||||
implementations refuse to add them for religious reasons.
|
||||
|
||||
eventdns.[ch]
|
||||
|
||||
A fork of Libevent's DNS implementation, used by Tor when Libevent
|
||||
2.0 or later is not available. Once Libevent 2.0 is required, we
|
||||
should throw this away; it has diverged from evdns.[ch], and is
|
||||
no longer easily mergeable.
|
||||
|
||||
ht.h
|
||||
|
||||
An implementation of a hash table in the style of Niels Provos's
|
||||
|
3514
src/ext/eventdns.c
3514
src/ext/eventdns.c
File diff suppressed because it is too large
Load Diff
@ -1,337 +0,0 @@
|
||||
|
||||
/*
|
||||
* The original DNS code is due to Adam Langley with heavy
|
||||
* modifications by Nick Mathewson. Adam put his DNS software in the
|
||||
* public domain. You can find his original copyright below. Please,
|
||||
* aware that the code as part of libevent is governed by the 3-clause
|
||||
* BSD license above.
|
||||
*
|
||||
* This software is Public Domain. To view a copy of the public domain dedication,
|
||||
* visit http://creativecommons.org/licenses/publicdomain/ or send a letter to
|
||||
* Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
|
||||
*
|
||||
* I ask and expect, but do not require, that all derivative works contain an
|
||||
* attribution similar to:
|
||||
* Parts developed by Adam Langley <agl@imperialviolet.org>
|
||||
*
|
||||
* You may wish to replace the word "Parts" with something else depending on
|
||||
* the amount of original code.
|
||||
*
|
||||
* (Derivative works does not include programs which link against, run or include
|
||||
* the source verbatim in their source distributions)
|
||||
*/
|
||||
|
||||
/*
|
||||
* Welcome, gentle reader
|
||||
*
|
||||
* Async DNS lookups are really a whole lot harder than they should be,
|
||||
* mostly stemming from the fact that the libc resolver has never been
|
||||
* very good at them. Before you use this library you should see if libc
|
||||
* can do the job for you with the modern async call getaddrinfo_a
|
||||
* (see http://www.imperialviolet.org/page25.html#e498). Otherwise,
|
||||
* please continue.
|
||||
*
|
||||
* This code is based on libevent and you must call event_init before
|
||||
* any of the APIs in this file. You must also seed the OpenSSL random
|
||||
* source if you are using OpenSSL for ids (see below).
|
||||
*
|
||||
* This library is designed to be included and shipped with your source
|
||||
* code. You statically link with it. You should also test for the
|
||||
* existence of strtok_r and define HAVE_STRTOK_R if you have it.
|
||||
*
|
||||
* The DNS protocol requires a good source of id numbers and these
|
||||
* numbers should be unpredictable for spoofing reasons. There are
|
||||
* three methods for generating them here and you must define exactly
|
||||
* one of them. In increasing order of preference:
|
||||
*
|
||||
* DNS_USE_GETTIMEOFDAY_FOR_ID:
|
||||
* Using the bottom 16 bits of the usec result from gettimeofday. This
|
||||
* is a pretty poor solution but should work anywhere.
|
||||
* DNS_USE_CPU_CLOCK_FOR_ID:
|
||||
* Using the bottom 16 bits of the nsec result from the CPU's time
|
||||
* counter. This is better, but may not work everywhere. Requires
|
||||
* POSIX realtime support and you'll need to link against -lrt on
|
||||
* glibc systems at least.
|
||||
* DNS_USE_OPENSSL_FOR_ID:
|
||||
* Uses the OpenSSL RAND_bytes call to generate the data. You must
|
||||
* have seeded the pool before making any calls to this library.
|
||||
*
|
||||
* The library keeps track of the state of nameservers and will avoid
|
||||
* them when they go down. Otherwise it will round robin between them.
|
||||
*
|
||||
* Quick start guide:
|
||||
* #include "evdns.h"
|
||||
* void callback(int result, char type, int count, int ttl,
|
||||
* void *addresses, void *arg);
|
||||
* evdns_resolv_conf_parse(DNS_OPTIONS_ALL, "/etc/resolv.conf");
|
||||
* evdns_resolve("www.hostname.com", 0, callback, NULL);
|
||||
*
|
||||
* When the lookup is complete the callback function is called. The
|
||||
* first argument will be one of the DNS_ERR_* defines in evdns.h.
|
||||
* Hopefully it will be DNS_ERR_NONE, in which case type will be
|
||||
* DNS_IPv4_A, count will be the number of IP addresses, ttl is the time
|
||||
* which the data can be cached for (in seconds), addresses will point
|
||||
* to an array of uint32_t's and arg will be whatever you passed to
|
||||
* evdns_resolve.
|
||||
*
|
||||
* Searching:
|
||||
*
|
||||
* In order for this library to be a good replacement for glibc's resolver it
|
||||
* supports searching. This involves setting a list of default domains, in
|
||||
* which names will be queried for. The number of dots in the query name
|
||||
* determines the order in which this list is used.
|
||||
*
|
||||
* Searching appears to be a single lookup from the point of view of the API,
|
||||
* although many DNS queries may be generated from a single call to
|
||||
* evdns_resolve. Searching can also drastically slow down the resolution
|
||||
* of names.
|
||||
*
|
||||
* To disable searching:
|
||||
* 1. Never set it up. If you never call evdns_resolv_conf_parse or
|
||||
* evdns_search_add then no searching will occur.
|
||||
*
|
||||
* 2. If you do call evdns_resolv_conf_parse then don't pass
|
||||
* DNS_OPTION_SEARCH (or DNS_OPTIONS_ALL, which implies it).
|
||||
*
|
||||
* 3. When calling evdns_resolve, pass the DNS_QUERY_NO_SEARCH flag.
|
||||
*
|
||||
* The order of searches depends on the number of dots in the name. If the
|
||||
* number is greater than the ndots setting then the names is first tried
|
||||
* globally. Otherwise each search domain is appended in turn.
|
||||
*
|
||||
* The ndots setting can either be set from a resolv.conf, or by calling
|
||||
* evdns_search_ndots_set.
|
||||
*
|
||||
* For example, with ndots set to 1 (the default) and a search domain list of
|
||||
* ["myhome.net"]:
|
||||
* Query: www
|
||||
* Order: www.myhome.net, www.
|
||||
*
|
||||
* Query: www.abc
|
||||
* Order: www.abc., www.abc.myhome.net
|
||||
*
|
||||
* API reference:
|
||||
*
|
||||
* int evdns_nameserver_add(uint32_t address)
|
||||
* Add a nameserver. The address should be an IP address in
|
||||
* network byte order. The type of address is chosen so that
|
||||
* it matches in_addr.s_addr.
|
||||
* Returns non-zero on error.
|
||||
*
|
||||
* int evdns_nameserver_ip_add(const char *ip_as_string)
|
||||
* This wraps the above function by parsing a string as an IP
|
||||
* address and adds it as a nameserver.
|
||||
* Returns non-zero on error
|
||||
*
|
||||
* int evdns_resolve(const char *name, int flags,
|
||||
* evdns_callback_type callback,
|
||||
* void *ptr)
|
||||
* Resolve a name. The name parameter should be a DNS name.
|
||||
* The flags parameter should be 0, or DNS_QUERY_NO_SEARCH
|
||||
* which disables searching for this query. (see defn of
|
||||
* searching above).
|
||||
*
|
||||
* The callback argument is a function which is called when
|
||||
* this query completes and ptr is an argument which is passed
|
||||
* to that callback function.
|
||||
*
|
||||
* Returns non-zero on error
|
||||
*
|
||||
* void evdns_search_clear()
|
||||
* Clears the list of search domains
|
||||
*
|
||||
* void evdns_search_add(const char *domain)
|
||||
* Add a domain to the list of search domains
|
||||
*
|
||||
* void evdns_search_ndots_set(int ndots)
|
||||
* Set the number of dots which, when found in a name, causes
|
||||
* the first query to be without any search domain.
|
||||
*
|
||||
* int evdns_count_nameservers(void)
|
||||
* Return the number of configured nameservers (not necessarily the
|
||||
* number of running nameservers). This is useful for double-checking
|
||||
* whether our calls to the various nameserver configuration functions
|
||||
* have been successful.
|
||||
*
|
||||
* int evdns_clear_nameservers_and_suspend(void)
|
||||
* Remove all currently configured nameservers, and suspend all pending
|
||||
* resolves. Resolves will not necessarily be re-attempted until
|
||||
* evdns_resume() is called.
|
||||
*
|
||||
* int evdns_resume(void)
|
||||
* Re-attempt resolves left in limbo after an earlier call to
|
||||
* evdns_clear_nameservers_and_suspend().
|
||||
*
|
||||
* int evdns_config_windows_nameservers(void)
|
||||
* Attempt to configure a set of nameservers based on platform settings on
|
||||
* a win32 host. Preferentially tries to use GetNetworkParams; if that fails,
|
||||
* looks in the registry. Returns 0 on success, nonzero on failure.
|
||||
*
|
||||
* int evdns_resolv_conf_parse(int flags, const char *filename)
|
||||
* Parse a resolv.conf like file from the given filename.
|
||||
*
|
||||
* See the man page for resolv.conf for the format of this file.
|
||||
* The flags argument determines what information is parsed from
|
||||
* this file:
|
||||
* DNS_OPTION_SEARCH - domain, search and ndots options
|
||||
* DNS_OPTION_NAMESERVERS - nameserver lines
|
||||
* DNS_OPTION_MISC - timeout and attempts options
|
||||
* DNS_OPTIONS_ALL - all of the above
|
||||
* The following directives are not parsed from the file:
|
||||
* sortlist, rotate, no-check-names, inet6, debug
|
||||
*
|
||||
* Returns non-zero on error:
|
||||
* 0 no errors
|
||||
* 1 failed to open file
|
||||
* 2 failed to stat file
|
||||
* 3 file too large
|
||||
* 4 out of memory
|
||||
* 5 short read from file
|
||||
* 6 no nameservers in file
|
||||
*
|
||||
* Internals:
|
||||
*
|
||||
* Requests are kept in two queues. The first is the inflight queue. In
|
||||
* this queue requests have an allocated transaction id and nameserver.
|
||||
* They will soon be transmitted if they haven't already been.
|
||||
*
|
||||
* The second is the waiting queue. The size of the inflight ring is
|
||||
* limited and all other requests wait in waiting queue for space. This
|
||||
* bounds the number of concurrent requests so that we don't flood the
|
||||
* nameserver. Several algorithms require a full walk of the inflight
|
||||
* queue and so bounding its size keeps thing going nicely under huge
|
||||
* (many thousands of requests) loads.
|
||||
*
|
||||
* If a nameserver loses too many requests it is considered down and we
|
||||
* try not to use it. After a while we send a probe to that nameserver
|
||||
* (a lookup for google.com) and, if it replies, we consider it working
|
||||
* again. If the nameserver fails a probe we wait longer to try again
|
||||
* with the next probe.
|
||||
*/
|
||||
|
||||
#ifndef TOR_EVENTDNS_H
|
||||
#define TOR_EVENTDNS_H
|
||||
|
||||
/* Error codes 0-5 are as described in RFC 1035. */
|
||||
#define DNS_ERR_NONE 0
|
||||
/* The name server was unable to interpret the query */
|
||||
#define DNS_ERR_FORMAT 1
|
||||
/* The name server was unable to process this query due to a problem with the
|
||||
* name server */
|
||||
#define DNS_ERR_SERVERFAILED 2
|
||||
/* The domain name does not exist */
|
||||
#define DNS_ERR_NOTEXIST 3
|
||||
/* The name server does not support the requested kind of query */
|
||||
#define DNS_ERR_NOTIMPL 4
|
||||
/* The name server refuses to reform the specified operation for policy
|
||||
* reasons */
|
||||
#define DNS_ERR_REFUSED 5
|
||||
/* The reply was truncated or ill-formated */
|
||||
#define DNS_ERR_TRUNCATED 65
|
||||
/* An unknown error occurred */
|
||||
#define DNS_ERR_UNKNOWN 66
|
||||
/* Communication with the server timed out */
|
||||
#define DNS_ERR_TIMEOUT 67
|
||||
/* The request was canceled because the DNS subsystem was shut down. */
|
||||
#define DNS_ERR_SHUTDOWN 68
|
||||
|
||||
#define DNS_IPv4_A 1
|
||||
#define DNS_PTR 2
|
||||
#define DNS_IPv6_AAAA 3
|
||||
|
||||
#define DNS_QUERY_NO_SEARCH 1
|
||||
|
||||
#define DNS_OPTION_SEARCH 1
|
||||
#define DNS_OPTION_NAMESERVERS 2
|
||||
#define DNS_OPTION_MISC 4
|
||||
#define DNS_OPTIONS_ALL 7
|
||||
|
||||
/*
|
||||
* The callback that contains the results from a lookup.
|
||||
* - type is either DNS_IPv4_A or DNS_IPv6_AAAA or DNS_PTR
|
||||
* - count contains the number of addresses of form type
|
||||
* - ttl is the number of seconds the resolution may be cached for.
|
||||
* - addresses needs to be cast according to type
|
||||
*/
|
||||
typedef void (*evdns_callback_type) (int result, char type, int count, int ttl, void *addresses, void *arg);
|
||||
|
||||
int evdns_init(void);
|
||||
void evdns_shutdown(int fail_requests);
|
||||
const char *evdns_err_to_string(int err);
|
||||
int evdns_nameserver_add(uint32_t address);
|
||||
int evdns_count_nameservers(void);
|
||||
int evdns_clear_nameservers_and_suspend(void);
|
||||
int evdns_resume(void);
|
||||
int evdns_nameserver_ip_add(const char *ip_as_string);
|
||||
int evdns_nameserver_sockaddr_add(const struct sockaddr *sa, socklen_t len);
|
||||
void evdns_set_default_outgoing_bind_address(const struct sockaddr *addr, socklen_t addrlen);
|
||||
int evdns_resolve_ipv4(const char *name, int flags, evdns_callback_type callback, void *ptr);
|
||||
int evdns_resolve_ipv6(const char *name, int flags, evdns_callback_type callback, void *ptr);
|
||||
struct in_addr;
|
||||
struct in6_addr;
|
||||
int evdns_resolve_reverse(const struct in_addr *in, int flags, evdns_callback_type callback, void *ptr);
|
||||
int evdns_resolve_reverse_ipv6(const struct in6_addr *in, int flags, evdns_callback_type callback, void *ptr);
|
||||
int evdns_set_option(const char *option, const char *val, int flags);
|
||||
int evdns_resolv_conf_parse(int flags, const char *);
|
||||
#ifdef _WIN32
|
||||
int evdns_config_windows_nameservers(void);
|
||||
#endif
|
||||
void evdns_search_clear(void);
|
||||
void evdns_search_add(const char *domain);
|
||||
void evdns_search_ndots_set(const int ndots);
|
||||
|
||||
typedef void (*evdns_debug_log_fn_type)(int is_warning, const char *msg);
|
||||
void evdns_set_log_fn(evdns_debug_log_fn_type fn);
|
||||
|
||||
void evdns_set_transaction_id_fn(uint16_t (*fn)(void));
|
||||
void evdns_set_random_bytes_fn(void (*fn)(char *, size_t));
|
||||
|
||||
#define DNS_NO_SEARCH 1
|
||||
|
||||
/* Structures and functions used to implement a DNS server. */
|
||||
|
||||
struct evdns_server_request {
|
||||
int flags;
|
||||
int nquestions;
|
||||
struct evdns_server_question **questions;
|
||||
};
|
||||
struct evdns_server_question {
|
||||
int type;
|
||||
int dns_question_class;
|
||||
char name[1];
|
||||
};
|
||||
typedef void (*evdns_request_callback_fn_type)(struct evdns_server_request *, void *);
|
||||
#define EVDNS_ANSWER_SECTION 0
|
||||
#define EVDNS_AUTHORITY_SECTION 1
|
||||
#define EVDNS_ADDITIONAL_SECTION 2
|
||||
|
||||
#define EVDNS_TYPE_A 1
|
||||
#define EVDNS_TYPE_NS 2
|
||||
#define EVDNS_TYPE_CNAME 5
|
||||
#define EVDNS_TYPE_SOA 6
|
||||
#define EVDNS_TYPE_PTR 12
|
||||
#define EVDNS_TYPE_MX 15
|
||||
#define EVDNS_TYPE_TXT 16
|
||||
#define EVDNS_TYPE_AAAA 28
|
||||
|
||||
#define EVDNS_QTYPE_AXFR 252
|
||||
#define EVDNS_QTYPE_ALL 255
|
||||
|
||||
#define EVDNS_CLASS_INET 1
|
||||
|
||||
struct evdns_server_port *evdns_add_server_port(tor_socket_t socket, int is_tcp, evdns_request_callback_fn_type callback, void *user_data);
|
||||
void evdns_close_server_port(struct evdns_server_port *port);
|
||||
|
||||
int evdns_server_request_add_reply(struct evdns_server_request *req, int section, const char *name, int type, int class, int ttl, int datalen, int is_name, const char *data);
|
||||
int evdns_server_request_add_a_reply(struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl);
|
||||
int evdns_server_request_add_aaaa_reply(struct evdns_server_request *req, const char *name, int n, const void *addrs, int ttl);
|
||||
int evdns_server_request_add_ptr_reply(struct evdns_server_request *req, struct in_addr *in, const char *inaddr_name, const char *hostname, int ttl);
|
||||
int evdns_server_request_add_cname_reply(struct evdns_server_request *req, const char *name, const char *cname, int ttl);
|
||||
|
||||
struct sockaddr;
|
||||
int evdns_server_request_get_requesting_addr(struct evdns_server_request *req, struct sockaddr *sa, int addr_len);
|
||||
|
||||
int evdns_server_request_respond(struct evdns_server_request *req, int err);
|
||||
int evdns_server_request_drop(struct evdns_server_request *req);
|
||||
|
||||
#endif // !EVENTDNS_H
|
@ -5,7 +5,6 @@ EXTRA_DIST += src/ext/README
|
||||
|
||||
EXTHEADERS = \
|
||||
src/ext/ht.h \
|
||||
src/ext/eventdns.h \
|
||||
src/ext/tinytest.h \
|
||||
src/ext/tor_readpassphrase.h \
|
||||
src/ext/strlcat.c \
|
||||
|
@ -7204,8 +7204,6 @@ init_libevent(const or_options_t *options)
|
||||
*/
|
||||
suppress_libevent_log_msg("Function not implemented");
|
||||
|
||||
tor_check_libevent_header_compatibility();
|
||||
|
||||
memset(&cfg, 0, sizeof(cfg));
|
||||
cfg.disable_iocp = options->DisableIOCP;
|
||||
cfg.num_cpus = get_num_cpus(options);
|
||||
|
@ -51,11 +51,7 @@
|
||||
#include <sys/resource.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#include <event2/event.h>
|
||||
#else
|
||||
#include <event.h>
|
||||
#endif
|
||||
|
||||
#include "crypto_s2k.h"
|
||||
#include "procmon.h"
|
||||
|
@ -23,11 +23,7 @@
|
||||
#include "router.h"
|
||||
#include "workqueue.h"
|
||||
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#include <event2/event.h>
|
||||
#else
|
||||
#include <event.h>
|
||||
#endif
|
||||
|
||||
static void queue_pending_tasks(void);
|
||||
|
||||
|
72
src/or/dns.c
72
src/or/dns.c
@ -27,61 +27,8 @@
|
||||
#include "router.h"
|
||||
#include "ht.h"
|
||||
#include "sandbox.h"
|
||||
#ifdef HAVE_EVENT2_DNS_H
|
||||
#include <event2/event.h>
|
||||
#include <event2/dns.h>
|
||||
#else
|
||||
#include <event.h>
|
||||
#include "eventdns.h"
|
||||
#ifndef HAVE_EVDNS_SET_DEFAULT_OUTGOING_BIND_ADDRESS
|
||||
#define HAVE_EVDNS_SET_DEFAULT_OUTGOING_BIND_ADDRESS
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_EVENT2_DNS_H
|
||||
struct evdns_base;
|
||||
struct evdns_request;
|
||||
#define evdns_base_new(x,y) tor_malloc(1)
|
||||
#define evdns_base_clear_nameservers_and_suspend(base) \
|
||||
evdns_clear_nameservers_and_suspend()
|
||||
#define evdns_base_search_clear(base) evdns_search_clear()
|
||||
#define evdns_base_set_default_outgoing_bind_address(base, a, len) \
|
||||
evdns_set_default_outgoing_bind_address((a),(len))
|
||||
#define evdns_base_resolv_conf_parse(base, options, fname) \
|
||||
evdns_resolv_conf_parse((options), (fname))
|
||||
#define evdns_base_count_nameservers(base) \
|
||||
evdns_count_nameservers()
|
||||
#define evdns_base_resume(base) \
|
||||
evdns_resume()
|
||||
#define evdns_base_config_windows_nameservers(base) \
|
||||
evdns_config_windows_nameservers()
|
||||
#define evdns_base_set_option_(base, opt, val) \
|
||||
evdns_set_option((opt),(val),DNS_OPTIONS_ALL)
|
||||
/* Note: our internal eventdns.c, plus Libevent 1.4, used a 1 return to
|
||||
* signify failure to launch a resolve. Libevent 2.0 uses a -1 return to
|
||||
* signify a failure on a resolve, though if we're on Libevent 2.0, we should
|
||||
* have event2/dns.h and never hit these macros. Regardless, 0 is success. */
|
||||
#define evdns_base_resolve_ipv4(base, addr, options, cb, ptr) \
|
||||
((evdns_resolve_ipv4((addr), (options), (cb), (ptr))!=0) \
|
||||
? NULL : ((void*)1))
|
||||
#define evdns_base_resolve_ipv6(base, addr, options, cb, ptr) \
|
||||
((evdns_resolve_ipv6((addr), (options), (cb), (ptr))!=0) \
|
||||
? NULL : ((void*)1))
|
||||
#define evdns_base_resolve_reverse(base, addr, options, cb, ptr) \
|
||||
((evdns_resolve_reverse((addr), (options), (cb), (ptr))!=0) \
|
||||
? NULL : ((void*)1))
|
||||
#define evdns_base_resolve_reverse_ipv6(base, addr, options, cb, ptr) \
|
||||
((evdns_resolve_reverse_ipv6((addr), (options), (cb), (ptr))!=0) \
|
||||
? NULL : ((void*)1))
|
||||
|
||||
#elif defined(LIBEVENT_VERSION_NUMBER) && LIBEVENT_VERSION_NUMBER < 0x02000303
|
||||
#define evdns_base_set_option_(base, opt, val) \
|
||||
evdns_base_set_option((base), (opt),(val),DNS_OPTIONS_ALL)
|
||||
|
||||
#else
|
||||
#define evdns_base_set_option_ evdns_base_set_option
|
||||
|
||||
#endif
|
||||
|
||||
/** How long will we wait for an answer from the resolver before we decide
|
||||
* that the resolver is wedged? */
|
||||
@ -1373,23 +1320,6 @@ configure_nameservers(int force)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_EVDNS_SET_DEFAULT_OUTGOING_BIND_ADDRESS
|
||||
if (! tor_addr_is_null(&options->OutboundBindAddressIPv4_)) {
|
||||
int socklen;
|
||||
struct sockaddr_storage ss;
|
||||
socklen = tor_addr_to_sockaddr(&options->OutboundBindAddressIPv4_, 0,
|
||||
(struct sockaddr *)&ss, sizeof(ss));
|
||||
if (socklen <= 0) {
|
||||
log_warn(LD_BUG, "Couldn't convert outbound bind address to sockaddr."
|
||||
" Ignoring.");
|
||||
} else {
|
||||
evdns_base_set_default_outgoing_bind_address(the_evdns_base,
|
||||
(struct sockaddr *)&ss,
|
||||
socklen);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
evdns_set_log_fn(evdns_log_cb);
|
||||
if (conf_fname) {
|
||||
log_debug(LD_FS, "stat()ing %s", conf_fname);
|
||||
@ -1454,7 +1384,7 @@ configure_nameservers(int force)
|
||||
}
|
||||
#endif
|
||||
|
||||
#define SET(k,v) evdns_base_set_option_(the_evdns_base, (k), (v))
|
||||
#define SET(k,v) evdns_base_set_option(the_evdns_base, (k), (v))
|
||||
|
||||
if (evdns_base_count_nameservers(the_evdns_base) == 1) {
|
||||
SET("max-timeouts:", "16");
|
||||
|
@ -17,14 +17,10 @@
|
||||
#include "control.h"
|
||||
#include "main.h"
|
||||
#include "policies.h"
|
||||
#ifdef HAVE_EVENT2_DNS_H
|
||||
#include <event2/dns.h>
|
||||
#include <event2/dns_compat.h>
|
||||
/* XXXX this implies we want an improved evdns */
|
||||
#include <event2/dns_struct.h>
|
||||
#else
|
||||
#include "eventdns.h"
|
||||
#endif
|
||||
|
||||
/** Helper function: called by evdns whenever the client sends a request to our
|
||||
* DNSPort. We need to eventually answer the request <b>req</b>.
|
||||
|
@ -17,12 +17,6 @@ endif
|
||||
|
||||
EXTRA_DIST+= src/or/ntmain.c src/or/Makefile.nmake
|
||||
|
||||
if USE_EXTERNAL_EVDNS
|
||||
evdns_source=
|
||||
else
|
||||
evdns_source=src/ext/eventdns.c
|
||||
endif
|
||||
|
||||
LIBTOR_A_SOURCES = \
|
||||
src/or/addressmap.c \
|
||||
src/or/buffers.c \
|
||||
@ -86,7 +80,6 @@ LIBTOR_A_SOURCES = \
|
||||
src/or/status.c \
|
||||
src/or/torcert.c \
|
||||
src/or/onion_ntor.c \
|
||||
$(evdns_source) \
|
||||
$(tor_platform_source)
|
||||
|
||||
src_or_libtor_a_SOURCES = $(LIBTOR_A_SOURCES)
|
||||
|
@ -69,11 +69,7 @@
|
||||
#include "memarea.h"
|
||||
#include "sandbox.h"
|
||||
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#include <event2/event.h>
|
||||
#else
|
||||
#include <event.h>
|
||||
#endif
|
||||
|
||||
#ifdef USE_BUFFEREVENTS
|
||||
#include <event2/bufferevent.h>
|
||||
|
@ -16,11 +16,7 @@
|
||||
#include "main.h"
|
||||
#include "ntmain.h"
|
||||
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#include <event2/event.h>
|
||||
#else
|
||||
#include <event.h>
|
||||
#endif
|
||||
|
||||
#include <windows.h>
|
||||
#define GENSRV_SERVICENAME "tor"
|
||||
|
@ -12,11 +12,7 @@
|
||||
#include "config.h"
|
||||
#include "periodic.h"
|
||||
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#include <event2/event.h>
|
||||
#else
|
||||
#include <event.h>
|
||||
#endif
|
||||
|
||||
/** We disable any interval greater than this number of seconds, on the
|
||||
* grounds that it is probably an absolute time mistakenly passed in as a
|
||||
|
@ -15,11 +15,7 @@
|
||||
#define SCHEDULER_PRIVATE_
|
||||
#include "scheduler.h"
|
||||
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#include <event2/event.h>
|
||||
#else
|
||||
#include <event.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Scheduler high/low watermarks
|
||||
|
@ -7,11 +7,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#include <event2/event.h>
|
||||
#else
|
||||
#include <event.h>
|
||||
#endif
|
||||
|
||||
#include "compat.h"
|
||||
#include "compat_libevent.h"
|
||||
|
@ -9,15 +9,11 @@
|
||||
|
||||
#include "compat_libevent.h"
|
||||
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#include <event2/event.h>
|
||||
#include <event2/thread.h>
|
||||
#ifdef USE_BUFFEREVENTS
|
||||
#include <event2/bufferevent.h>
|
||||
#endif
|
||||
#else
|
||||
#include <event.h>
|
||||
#endif
|
||||
|
||||
#include "log_test_helpers.h"
|
||||
|
||||
@ -106,98 +102,6 @@ test_compat_libevent_logging_callback(void *ignored)
|
||||
teardown_capture_of_logs(previous_log);
|
||||
}
|
||||
|
||||
static void
|
||||
test_compat_libevent_le_versions_compatibility(void *ignored)
|
||||
{
|
||||
(void)ignored;
|
||||
int res;
|
||||
|
||||
res = le_versions_compatibility(LE_OTHER);
|
||||
tt_int_op(res, OP_EQ, 0);
|
||||
|
||||
res = le_versions_compatibility(V_OLD(0,9,'c'));
|
||||
tt_int_op(res, OP_EQ, 1);
|
||||
|
||||
res = le_versions_compatibility(V(1,3,98));
|
||||
tt_int_op(res, OP_EQ, 2);
|
||||
|
||||
res = le_versions_compatibility(V(1,4,98));
|
||||
tt_int_op(res, OP_EQ, 3);
|
||||
|
||||
res = le_versions_compatibility(V(1,5,0));
|
||||
tt_int_op(res, OP_EQ, 4);
|
||||
|
||||
res = le_versions_compatibility(V(2,0,0));
|
||||
tt_int_op(res, OP_EQ, 4);
|
||||
|
||||
res = le_versions_compatibility(V(2,0,2));
|
||||
tt_int_op(res, OP_EQ, 5);
|
||||
|
||||
done:
|
||||
(void)0;
|
||||
}
|
||||
|
||||
static void
|
||||
test_compat_libevent_tor_decode_libevent_version(void *ignored)
|
||||
{
|
||||
(void)ignored;
|
||||
le_version_t res;
|
||||
|
||||
res = tor_decode_libevent_version("SOMETHING WRONG");
|
||||
tt_int_op(res, OP_EQ, LE_OTHER);
|
||||
|
||||
res = tor_decode_libevent_version("1.4.11");
|
||||
tt_int_op(res, OP_EQ, V(1,4,11));
|
||||
|
||||
res = tor_decode_libevent_version("1.4.12b-stable");
|
||||
tt_int_op(res, OP_EQ, V(1,4,12));
|
||||
|
||||
res = tor_decode_libevent_version("1.4.17b_stable");
|
||||
tt_int_op(res, OP_EQ, V(1,4,17));
|
||||
|
||||
res = tor_decode_libevent_version("1.4.12!stable");
|
||||
tt_int_op(res, OP_EQ, LE_OTHER);
|
||||
|
||||
res = tor_decode_libevent_version("1.4.12b!stable");
|
||||
tt_int_op(res, OP_EQ, LE_OTHER);
|
||||
|
||||
res = tor_decode_libevent_version("1.4.13-");
|
||||
tt_int_op(res, OP_EQ, V(1,4,13));
|
||||
|
||||
res = tor_decode_libevent_version("1.4.14_");
|
||||
tt_int_op(res, OP_EQ, V(1,4,14));
|
||||
|
||||
res = tor_decode_libevent_version("1.4.15c-");
|
||||
tt_int_op(res, OP_EQ, V(1,4,15));
|
||||
|
||||
res = tor_decode_libevent_version("1.4.16c_");
|
||||
tt_int_op(res, OP_EQ, V(1,4,16));
|
||||
|
||||
res = tor_decode_libevent_version("1.4.17-s");
|
||||
tt_int_op(res, OP_EQ, V(1,4,17));
|
||||
|
||||
res = tor_decode_libevent_version("1.5");
|
||||
tt_int_op(res, OP_EQ, V(1,5,0));
|
||||
|
||||
res = tor_decode_libevent_version("1.2");
|
||||
tt_int_op(res, OP_EQ, V(1,2,0));
|
||||
|
||||
res = tor_decode_libevent_version("1.2-");
|
||||
tt_int_op(res, OP_EQ, LE_OTHER);
|
||||
|
||||
res = tor_decode_libevent_version("1.6e");
|
||||
tt_int_op(res, OP_EQ, V_OLD(1,6,'e'));
|
||||
|
||||
done:
|
||||
(void)0;
|
||||
}
|
||||
|
||||
#if defined(LIBEVENT_VERSION)
|
||||
#define HEADER_VERSION LIBEVENT_VERSION
|
||||
#elif defined(_EVENT_VERSION)
|
||||
#define HEADER_VERSION _EVENT_VERSION
|
||||
#endif
|
||||
|
||||
static void
|
||||
test_compat_libevent_header_version(void *ignored)
|
||||
{
|
||||
@ -205,7 +109,7 @@ test_compat_libevent_header_version(void *ignored)
|
||||
const char *res;
|
||||
|
||||
res = tor_libevent_get_header_version_str();
|
||||
tt_str_op(res, OP_EQ, HEADER_VERSION);
|
||||
tt_str_op(res, OP_EQ, LIBEVENT_VERSION);
|
||||
|
||||
done:
|
||||
(void)0;
|
||||
@ -214,10 +118,6 @@ test_compat_libevent_header_version(void *ignored)
|
||||
struct testcase_t compat_libevent_tests[] = {
|
||||
{ "logging_callback", test_compat_libevent_logging_callback,
|
||||
TT_FORK, NULL, NULL },
|
||||
{ "le_versions_compatibility",
|
||||
test_compat_libevent_le_versions_compatibility, 0, NULL, NULL },
|
||||
{ "tor_decode_libevent_version",
|
||||
test_compat_libevent_tor_decode_libevent_version, 0, NULL, NULL },
|
||||
{ "header_version", test_compat_libevent_header_version, 0, NULL, NULL },
|
||||
END_OF_TESTCASES
|
||||
};
|
||||
|
@ -5,12 +5,7 @@
|
||||
|
||||
#include "orconfig.h"
|
||||
|
||||
/* Libevent stuff */
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#include <event2/event.h>
|
||||
#else
|
||||
#include <event.h>
|
||||
#endif
|
||||
|
||||
#define TOR_CHANNEL_INTERNAL_
|
||||
#define CHANNEL_PRIVATE_
|
||||
@ -90,9 +85,7 @@ mock_event_free_all(void)
|
||||
static void
|
||||
mock_event_init(void)
|
||||
{
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
struct event_config *cfg = NULL;
|
||||
#endif
|
||||
|
||||
tt_ptr_op(mock_event_base, ==, NULL);
|
||||
|
||||
@ -102,7 +95,6 @@ mock_event_init(void)
|
||||
*/
|
||||
|
||||
if (!mock_event_base) {
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
cfg = event_config_new();
|
||||
#if LIBEVENT_VERSION_NUMBER >= V(2,0,9)
|
||||
/* We can enable changelist support with epoll, since we don't give
|
||||
@ -111,9 +103,6 @@ mock_event_init(void)
|
||||
#endif
|
||||
mock_event_base = event_base_new_with_config(cfg);
|
||||
event_config_free(cfg);
|
||||
#else
|
||||
mock_event_base = event_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
tt_assert(mock_event_base != NULL);
|
||||
|
@ -12,11 +12,7 @@
|
||||
#include "compat_libevent.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#ifdef HAVE_EVENT2_EVENT_H
|
||||
#include <event2/event.h>
|
||||
#else
|
||||
#include <event.h>
|
||||
#endif
|
||||
|
||||
#define MAX_INFLIGHT (1<<16)
|
||||
|
||||
|
@ -226,9 +226,7 @@
|
||||
#define HAVE_STRUCT_IN6_ADDR
|
||||
#define RSHIFT_DOES_SIGN_EXTEND
|
||||
#define FLEXIBLE_ARRAY_MEMBER 0
|
||||
#define HAVE_EVENT2_EVENT_H
|
||||
#define SHARE_DATADIR ""
|
||||
#define HAVE_EVENT2_DNS_H
|
||||
#define USE_CURVE25519_DONNA
|
||||
|
||||
#define ENUM_VALS_ARE_SIGNED 1
|
||||
|
Loading…
Reference in New Issue
Block a user