mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Removing the --disable-nbdns config option.
- Asynchronous DNS resolver support assumed by default - HAVE_ASYNC_DNS, HAVE_NB_DNS, and USE_NB_DNS preprocessor definitions removed - In the process, I added FindBIND and CheckNameserCompat CMake modules
This commit is contained in:
parent
13569aaab7
commit
570ee48cd9
11 changed files with 111 additions and 86 deletions
|
@ -37,16 +37,16 @@ set(ENABLE_DEBUG false
|
|||
set(ENABLE_PERFTOOLS false
|
||||
CACHE STRING "use Google's perftools" FORCE)
|
||||
|
||||
set(USE_NB_DNS true
|
||||
CACHE BOOL "Use non-blocking DNS support" FORCE)
|
||||
|
||||
##
|
||||
## Configure Dependencies for Non-Standard Paths
|
||||
##
|
||||
|
||||
# Uncomment to specific a custom prefix containing the OpenSSL installation.
|
||||
# Uncomment to specify a custom prefix containing the OpenSSL installation.
|
||||
#set(OPENSSL_ROOT_DIR path/to/your/openssl)
|
||||
|
||||
# Uncomment to specify a custom prefix containing the BIND installation.
|
||||
#set(BIND_ROOT_DIR path/to/your/bind)
|
||||
|
||||
# Uncomment to specify a custom prefix that contains the libpcap installation.
|
||||
#set(PCAP_ROOT path/to/your/pcap)
|
||||
|
||||
|
@ -59,7 +59,6 @@ set(USE_NB_DNS true
|
|||
# TODO: more dependencies:
|
||||
# Flex
|
||||
# Bison
|
||||
# BIND8
|
||||
# Perl?
|
||||
# BinPAC
|
||||
#
|
||||
|
|
|
@ -43,11 +43,13 @@ file(STRINGS "${CMAKE_SOURCE_DIR}/VERSION" VERSION LIMIT_COUNT 1)
|
|||
find_package(FLEX REQUIRED)
|
||||
find_package(BISON REQUIRED)
|
||||
find_package(PCAP REQUIRED)
|
||||
include_directories(BEFORE ${PCAP_INCLUDE_DIR})
|
||||
find_package(OpenSSL REQUIRED)
|
||||
include_directories(BEFORE ${OPENSSL_INCLUDE_DIR})
|
||||
find_package(BIND REQUIRED)
|
||||
include_directories(BEFORE
|
||||
${PCAP_INCLUDE_DIR}
|
||||
${OPENSSL_INCLUDE_DIR}
|
||||
${BIND_INCLUDE_DIR})
|
||||
|
||||
# TODO: find bind8 lib?
|
||||
# TODO: optional libmagic
|
||||
# TODO: optional libGeoIP
|
||||
# TODO: optional libz
|
||||
|
@ -64,12 +66,8 @@ include(CheckHeaders)
|
|||
include(CheckFunctions)
|
||||
include(MiscTests)
|
||||
include(PCAPTests)
|
||||
#TODO: use/integrate find_package(OpenSSL)
|
||||
include(OpenSSLTests)
|
||||
|
||||
#TODO: NB_DNS tests
|
||||
set(HAVE_NB_DNS ${USE_NB_DNS})
|
||||
set(HAVE_ASYNC_DNS ${USE_NB_DNS}) #TODO: should make consistent w/ HAVE_NB_DNS
|
||||
include(CheckNameserCompat)
|
||||
|
||||
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/config.h)
|
||||
|
|
21
cmake/CheckNameserCompat.cmake
Normal file
21
cmake/CheckNameserCompat.cmake
Normal file
|
@ -0,0 +1,21 @@
|
|||
include(CheckCSourcecompiles)
|
||||
|
||||
# Check whether the namser compatibility header is required
|
||||
# This can be the case on the Darwin platform
|
||||
|
||||
check_c_source_compiles("
|
||||
#include <arpa/nameser.h>
|
||||
int main() { HEADER *hdr; int d = NS_IN6ADDRSZ; return 0; }"
|
||||
have_nameser_header)
|
||||
|
||||
if (NOT have_nameser_header)
|
||||
check_c_source_compiles("
|
||||
#include <arpa/nameser.h>
|
||||
#include <arpa/nameser_compat.h>
|
||||
int main() { HEADER *hdr; int d = NS_IN6ADDRSZ; return 0; }"
|
||||
NEED_NAMESER_COMPAT_H)
|
||||
if (NOT NEED_NAMESER_COMPAT_H)
|
||||
message(FATAL_ERROR
|
||||
"Asynchronous DNS support compatibility check failed.")
|
||||
endif ()
|
||||
endif ()
|
77
cmake/FindBIND.cmake
Normal file
77
cmake/FindBIND.cmake
Normal file
|
@ -0,0 +1,77 @@
|
|||
# - Try to find libpcap include dirs and libraries
|
||||
#
|
||||
# Usage of this module as follows:
|
||||
#
|
||||
# find_package(BIND)
|
||||
#
|
||||
# Variables used by this module, they can change the default behaviour and need
|
||||
# to be set before calling find_package:
|
||||
#
|
||||
# BIND_ROOT_DIR Set this variable to the root installation of BIND
|
||||
# if the module has problems finding the proper
|
||||
# installation path.
|
||||
#
|
||||
# Variables defined by this module:
|
||||
#
|
||||
# BIND_FOUND System has BIND, include and library dirs found
|
||||
# BIND_INCLUDE_DIR The BIND include directories.
|
||||
# BIND_LIBRARIES All BIND libraries found.
|
||||
# BIND_LIBRARY The BIND library required for ns_inittab and
|
||||
# res_mkquery symbols.
|
||||
|
||||
find_path(BIND_ROOT_DIR
|
||||
NAMES include/resolv.h
|
||||
)
|
||||
mark_as_advanced(BIND_ROOT_DIR)
|
||||
|
||||
if (BIND_ROOT_DIR)
|
||||
set(BIND_INCLUDE_DIR ${BIND_ROOT_DIR}/include)
|
||||
endif ()
|
||||
|
||||
find_library(BIND_LIBRARIES
|
||||
NAMES resolv bind
|
||||
HINTS ${BIND_ROOT_DIR}/lib
|
||||
)
|
||||
|
||||
include(CheckCSourceCompiles)
|
||||
|
||||
# Find which library has the res_mkquery and ns_initparse symbols
|
||||
set(CMAKE_REQUIRED_INCLUDES ${BIND_INCLUDE_DIR})
|
||||
foreach (bindlib ${BIND_LIBRARIES})
|
||||
set(CMAKE_REQUIRED_LIBRARIES ${bindlib})
|
||||
|
||||
check_c_source_compiles("
|
||||
#include <arpa/nameser.h>
|
||||
int main() {
|
||||
ns_initparse(0, 0, 0);
|
||||
return 0;
|
||||
}
|
||||
" ns_initparse_works)
|
||||
|
||||
check_c_source_compiles("
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <resolv.h>
|
||||
int main() {
|
||||
int (*p)() = res_mkquery;
|
||||
}
|
||||
" res_mkquery_works)
|
||||
|
||||
unset(CMAKE_REQUIRED_LIBRARIES)
|
||||
|
||||
if (ns_initparse_works AND res_mkquery_works)
|
||||
set(BIND_LIBRARY ${bindlib})
|
||||
break ()
|
||||
endif ()
|
||||
endforeach ()
|
||||
unset(CMAKE_REQUIRED_INCLUDES)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(BIND DEFAULT_MSG
|
||||
BIND_LIBRARY
|
||||
BIND_INCLUDE_DIR
|
||||
)
|
||||
|
||||
mark_as_advanced(BIND_LIBRARIES BIND_LIBRARY BIND_INCLUDE_DIR)
|
|
@ -6,29 +6,6 @@ elseif (${CMAKE_SYSTEM_NAME} MATCHES "OpenBSD")
|
|||
set(USE_NMALLOC true)
|
||||
|
||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
|
||||
if (USE_NB_DNS)
|
||||
include(CheckCSourceCompiles)
|
||||
check_c_source_compiles("
|
||||
#include <arpa/nameser.h>
|
||||
int main() {
|
||||
HEADER *hdr; int d = NS_IN6ADDRSZ; return 0;
|
||||
}
|
||||
" ns_header_defined)
|
||||
if (NOT ns_header_defined)
|
||||
check_c_source_compiles("
|
||||
#include <arpa/nameser.h>
|
||||
#include <arpa/nameser_compat.h>
|
||||
int main() {
|
||||
HEADER *hdr; int d = NS_IN6ADDRSZ; return 0;
|
||||
}
|
||||
" NEED_NAMESER_COMPAT_H)
|
||||
if (NOT NEED_NAMESER_COMPAT_H)
|
||||
message(WARNING "Darwin nameser compatibility check failed."
|
||||
"Non-blocking DNS support disabled.")
|
||||
set(USE_NB_DNS false)
|
||||
endif ()
|
||||
endif ()
|
||||
endif ()
|
||||
|
||||
elseif (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
|
||||
set(HAVE_LINUX true)
|
||||
|
|
|
@ -38,9 +38,6 @@
|
|||
/* Define if you have the <memory.h> header file. */
|
||||
#cmakedefine HAVE_MEMORY_H
|
||||
|
||||
/* async dns support */
|
||||
#cmakedefine HAVE_NB_DNS
|
||||
|
||||
/* Define if you have the <netinet/ether.h> header file. */
|
||||
#cmakedefine HAVE_NETINET_ETHER_H
|
||||
|
||||
|
|
|
@ -189,9 +189,7 @@ endforeach(binpact)
|
|||
|
||||
########### next target ###############
|
||||
|
||||
if (HAVE_NB_DNS)
|
||||
set(dns_SRCS nb_dns.c nb_dns.h)
|
||||
endif ()
|
||||
set(dns_SRCS nb_dns.c nb_dns.h)
|
||||
|
||||
set(openssl_SRCS X509.cc SSLCiphers.cc SSLInterpreter.cc SSLProxy.cc
|
||||
SSLv2.cc SSLv3.cc SSLv3Automaton.cc)
|
||||
|
@ -382,10 +380,10 @@ add_dependencies(bro make_dbg_constants)
|
|||
|
||||
target_link_libraries(bro
|
||||
m
|
||||
resolv
|
||||
binpac_lib
|
||||
${PCAP_LIBRARY}
|
||||
${OPENSSL_LIBRARIES}
|
||||
${BIND_LIBRARY}
|
||||
)
|
||||
|
||||
install(TARGETS bro DESTINATION bin)
|
||||
|
|
|
@ -53,9 +53,7 @@ public:
|
|||
const char* ReqHost() const { return host; }
|
||||
uint32 ReqAddr() const { return addr; }
|
||||
|
||||
#ifdef HAVE_NB_DNS
|
||||
int MakeRequest(nb_dns_info* nb_dns);
|
||||
#endif
|
||||
int RequestPending() const { return request_pending; }
|
||||
void RequestDone() { request_pending = 0; }
|
||||
|
||||
|
@ -66,7 +64,6 @@ protected:
|
|||
int request_pending;
|
||||
};
|
||||
|
||||
#ifdef HAVE_NB_DNS
|
||||
int DNS_Mgr_Request::MakeRequest(nb_dns_info* nb_dns)
|
||||
{
|
||||
if ( ! nb_dns )
|
||||
|
@ -80,7 +77,6 @@ int DNS_Mgr_Request::MakeRequest(nb_dns_info* nb_dns)
|
|||
else
|
||||
return nb_dns_addr_request(nb_dns, addr, (void*) this, err) >= 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
class DNS_Mapping {
|
||||
public:
|
||||
|
@ -350,13 +346,11 @@ DNS_Mgr::DNS_Mgr(DNS_MgrMode arg_mode)
|
|||
host_mappings.SetDeleteFunc(DNS_Mgr_mapping_delete_func);
|
||||
addr_mappings.SetDeleteFunc(DNS_Mgr_mapping_delete_func);
|
||||
|
||||
#ifdef HAVE_NB_DNS
|
||||
char err[NB_DNS_ERRSIZE];
|
||||
nb_dns = nb_dns_init(err);
|
||||
|
||||
if ( ! nb_dns )
|
||||
warn(fmt("problem initializing NB-DNS: %s", err));
|
||||
#endif
|
||||
|
||||
dns_mapping_valid = dns_mapping_unverified = dns_mapping_new_name =
|
||||
dns_mapping_lost_name = dns_mapping_name_changed =
|
||||
|
@ -372,10 +366,8 @@ DNS_Mgr::DNS_Mgr(DNS_MgrMode arg_mode)
|
|||
|
||||
DNS_Mgr::~DNS_Mgr()
|
||||
{
|
||||
#ifdef HAVE_NB_DNS
|
||||
if ( nb_dns )
|
||||
nb_dns_finish(nb_dns);
|
||||
#endif
|
||||
|
||||
delete [] cache_name;
|
||||
delete [] dir;
|
||||
|
@ -410,14 +402,12 @@ bool DNS_Mgr::Init()
|
|||
|
||||
did_init = 1;
|
||||
|
||||
#ifdef HAVE_NB_DNS
|
||||
io_sources.Register(this, true);
|
||||
|
||||
// We never set idle to false, having the main loop only calling us from
|
||||
// time to time. If we're issuing more DNS requests than we can handle
|
||||
// in this way, we are having problems anyway ...
|
||||
idle = true;
|
||||
#endif
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -531,7 +521,6 @@ void DNS_Mgr::Resolve()
|
|||
|
||||
int i;
|
||||
|
||||
#ifdef HAVE_NB_DNS
|
||||
int first_req = 0;
|
||||
int num_pending = min(requests.length(), MAX_PENDING_REQUESTS);
|
||||
int last_req = num_pending - 1;
|
||||
|
@ -597,7 +586,6 @@ void DNS_Mgr::Resolve()
|
|||
--num_pending;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// All done with the list of requests.
|
||||
for ( i = requests.length() - 1; i >= 0; --i )
|
||||
|
@ -860,7 +848,6 @@ TableVal* DNS_Mgr::LookupNameInCache(string name)
|
|||
return d->AddrsSet();
|
||||
}
|
||||
|
||||
#ifdef HAVE_NB_DNS
|
||||
void DNS_Mgr::AsyncLookupAddr(dns_mgr_addr_type host, LookupCallback* callback)
|
||||
{
|
||||
if ( ! did_init )
|
||||
|
@ -956,13 +943,10 @@ void DNS_Mgr::IssueAsyncRequests()
|
|||
++asyncs_pending;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void DNS_Mgr::GetFds(int* read, int* write, int* except)
|
||||
{
|
||||
#ifdef HAVE_NB_DNS
|
||||
*read = nb_dns_fd(nb_dns);
|
||||
#endif
|
||||
}
|
||||
|
||||
double DNS_Mgr::NextTimestamp(double* network_time)
|
||||
|
@ -971,7 +955,6 @@ double DNS_Mgr::NextTimestamp(double* network_time)
|
|||
return asyncs_timeouts.size() ? timer_mgr->Time() : -1.0;
|
||||
}
|
||||
|
||||
#ifdef HAVE_NB_DNS
|
||||
void DNS_Mgr::CheckAsyncAddrRequest(dns_mgr_addr_type addr, bool timeout)
|
||||
{
|
||||
// Note that this code is a mirror of that for CheckAsyncHostRequest.
|
||||
|
@ -1030,13 +1013,9 @@ void DNS_Mgr::CheckAsyncHostRequest(const char* host, bool timeout)
|
|||
// eventually times out.
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void DNS_Mgr::Process()
|
||||
{
|
||||
#ifndef HAVE_NB_DNS
|
||||
internal_error("DNS_Mgr::Process(): should never be reached");
|
||||
#else
|
||||
|
||||
while ( asyncs_timeouts.size() > 0 )
|
||||
{
|
||||
|
@ -1084,9 +1063,8 @@ void DNS_Mgr::Process()
|
|||
|
||||
IssueAsyncRequests();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef HAVE_NB_DNS
|
||||
|
||||
int DNS_Mgr::AnswerAvailable(int timeout)
|
||||
{
|
||||
int fd = nb_dns_fd(nb_dns);
|
||||
|
@ -1116,4 +1094,3 @@ int DNS_Mgr::AnswerAvailable(int timeout)
|
|||
|
||||
return status;
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -79,10 +79,8 @@ public:
|
|||
virtual void Timeout() = 0;
|
||||
};
|
||||
|
||||
#ifdef HAVE_NB_DNS
|
||||
void AsyncLookupAddr(dns_mgr_addr_type host, LookupCallback* callback);
|
||||
void AsyncLookupName(string name, LookupCallback* callback);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
friend class LookupCallback;
|
||||
|
@ -102,7 +100,6 @@ protected:
|
|||
void LoadCache(FILE* f);
|
||||
void Save(FILE* f, PDict(DNS_Mapping)& m);
|
||||
|
||||
#ifdef HAVE_NB_DNS
|
||||
// Selects on the fd to see if there is an answer available (timeout is
|
||||
// secs). Returns 0 on timeout, -1 on EINTR, and 1 if answer is ready.
|
||||
int AnswerAvailable(int timeout);
|
||||
|
@ -115,8 +112,6 @@ protected:
|
|||
void CheckAsyncAddrRequest(dns_mgr_addr_type addr, bool timeout);
|
||||
void CheckAsyncHostRequest(const char* host, bool timeout);
|
||||
|
||||
#endif
|
||||
|
||||
// IOSource interface.
|
||||
virtual void GetFds(int* read, int* write, int* except);
|
||||
virtual double NextTimestamp(double* network_time);
|
||||
|
|
10
src/bro.bif
10
src/bro.bif
|
@ -2808,10 +2808,6 @@ private:
|
|||
# function result. Therefore, they can only be called inside a when-condition.
|
||||
function lookup_addr%(host: addr%) : string
|
||||
%{
|
||||
#ifndef HAVE_NB_DNS
|
||||
run_time("lookup_addr(): not configured for asynchronous DNS lookups");
|
||||
return new StringVal("<error>");
|
||||
#else
|
||||
// FIXME: Is should be easy to adapt the function to synchronous
|
||||
// lookups if we're reading a trace.
|
||||
Trigger* trigger = frame->GetTrigger();
|
||||
|
@ -2839,15 +2835,10 @@ function lookup_addr%(host: addr%) : string
|
|||
new LookupHostCallback(trigger, frame->GetCall(), true));
|
||||
#endif
|
||||
return 0;
|
||||
#endif
|
||||
%}
|
||||
|
||||
function lookup_hostname%(host: string%) : addr_set
|
||||
%{
|
||||
#ifndef HAVE_NB_DNS
|
||||
run_time("lookup_hostname(): not configured for asynchronous DNS lookups");
|
||||
return new StringVal("<error>");
|
||||
#else
|
||||
// FIXME: Is should be easy to adapt the function to synchronous
|
||||
// lookups if we're reading a trace.
|
||||
Trigger* trigger = frame->GetTrigger();
|
||||
|
@ -2864,7 +2855,6 @@ function lookup_hostname%(host: string%) : addr_set
|
|||
dns_mgr->AsyncLookupName(host->CheckString(),
|
||||
new LookupHostCallback(trigger, frame->GetCall(), false));
|
||||
return 0;
|
||||
#endif
|
||||
%}
|
||||
|
||||
# Stop Bro's packet processing.
|
||||
|
|
|
@ -406,11 +406,7 @@ int main(int argc, char** argv)
|
|||
|
||||
enum DNS_MgrMode dns_type = DNS_DEFAULT;
|
||||
|
||||
#ifdef HAVE_NB_DNS
|
||||
dns_type = getenv("BRO_DNS_FAKE") ? DNS_FAKE : DNS_DEFAULT;
|
||||
#else
|
||||
dns_type = DNS_FAKE;
|
||||
#endif
|
||||
|
||||
RETSIGTYPE (*oldhandler)(int);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue