Use arc4random() for dns transaction ids where available. Patch taken from OpenBSD

svn:r1528
This commit is contained in:
Nick Mathewson 2009-11-15 18:59:48 +00:00
parent c79a45e009
commit e2b2de79bf
3 changed files with 14 additions and 4 deletions

View File

@ -44,6 +44,7 @@ Changes in 2.0.3-alpha:
o Make EV_PERSIST timeouts more accurate: schedule the next event based on the scheduled time of the previous event, not based on the current time. o Make EV_PERSIST timeouts more accurate: schedule the next event based on the scheduled time of the previous event, not based on the current time.
o Allow http.c to handle cases where getaddrinfo returns an IPv6 address. Patch from Ryan Phillips. o Allow http.c to handle cases where getaddrinfo returns an IPv6 address. Patch from Ryan Phillips.
o Fix a problem with excessive memory allocation when using multiple event priorities. o Fix a problem with excessive memory allocation when using multiple event priorities.
o Default to using arc4random for DNS transaction IDs on systems that have it.
Changes in 2.0.2-alpha: Changes in 2.0.2-alpha:

View File

@ -176,14 +176,16 @@ AC_C_INLINE
AC_HEADER_TIME AC_HEADER_TIME
dnl Checks for library functions. dnl Checks for library functions.
AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r strsep getaddrinfo getnameinfo strlcpy inet_ntop inet_pton signal sigaction strtoll inet_aton pipe eventfd sendfile mmap splice) AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r strsep getaddrinfo getnameinfo strlcpy inet_ntop inet_pton signal sigaction strtoll inet_aton pipe eventfd sendfile mmap splice arc4random)
AC_CHECK_SIZEOF(long) AC_CHECK_SIZEOF(long)
if test "x$ac_cv_func_clock_gettime" = "xyes"; then if test "x$ac_cv_func_arc4random" = "xyes" ; then
AC_DEFINE(DNS_USE_CPU_CLOCK_FOR_ID, 1, [Define if clock_gettime is available in libc]) AC_DEFINE(DNS_USE_ARC4RANDOM_FOR_ID, 1, [Define if we should use arc4random to generate dns transation IDs])
elif test "x$ac_cv_func_clock_gettime" = "xyes"; then
AC_DEFINE(DNS_USE_CPU_CLOCK_FOR_ID, 1, [Define if we should use clock_gettime to generate dns transation IDs])
else else
AC_DEFINE(DNS_USE_GETTIMEOFDAY_FOR_ID, 1, [Define is no secure id variant is available]) AC_DEFINE(DNS_USE_GETTIMEOFDAY_FOR_ID, 1, [Define if s no secure id variant is available])
fi fi
AC_MSG_CHECKING(for F_SETFD in fcntl.h) AC_MSG_CHECKING(for F_SETFD in fcntl.h)

View File

@ -45,12 +45,14 @@
#ifndef _EVENT_DNS_USE_GETTIMEOFDAY_FOR_ID #ifndef _EVENT_DNS_USE_GETTIMEOFDAY_FOR_ID
#ifndef _EVENT_DNS_USE_OPENSSL_FOR_ID #ifndef _EVENT_DNS_USE_OPENSSL_FOR_ID
#ifndef _EVENT_DNS_USE_FTIME_FOR_ID #ifndef _EVENT_DNS_USE_FTIME_FOR_ID
#ifndef _EVENT_DNS_USE_ARC4RANDOM_FOR_ID
#error Must configure at least one id generation method. #error Must configure at least one id generation method.
#error Please see the documentation. #error Please see the documentation.
#endif #endif
#endif #endif
#endif #endif
#endif #endif
#endif
/* #define _POSIX_C_SOURCE 200507 */ /* #define _POSIX_C_SOURCE 200507 */
#define _GNU_SOURCE #define _GNU_SOURCE
@ -1204,6 +1206,11 @@ default_transaction_id_fn(void)
abort(); abort();
} }
#endif #endif
#ifdef _EVENT_DNS_USE_ARC4RANDOM_FOR_ID
trans_id = arc4random() & 0xffff;
#endif
return trans_id; return trans_id;
} }