From cdc389ef3d1aa9ef28ffdbe36894eba8f6de357e Mon Sep 17 00:00:00 2001 From: Emery Hemingway Date: Thu, 22 Feb 2018 13:38:53 +0100 Subject: [PATCH] Port of ldns and drill Drill is a DNS utility inspired by dig. https://www.nlnetlabs.nl/projects/ldns/ Fix #99 --- include/ldns/config.h | 224 ++++++++++++++++++++++++++++++++++++++ lib/import/import-ldns.mk | 3 + lib/mk/ldns.mk | 13 +++ ports/ldns.hash | 1 + ports/ldns.port | 50 +++++++++ run/drill.run | 101 +++++++++++++++++ src/app/drill/target.mk | 11 ++ src/lib/ldns/getproto.cc | 14 +++ 8 files changed, 417 insertions(+) create mode 100644 include/ldns/config.h create mode 100644 lib/import/import-ldns.mk create mode 100644 lib/mk/ldns.mk create mode 100644 ports/ldns.hash create mode 100644 ports/ldns.port create mode 100644 run/drill.run create mode 100644 src/app/drill/target.mk create mode 100644 src/lib/ldns/getproto.cc diff --git a/include/ldns/config.h b/include/ldns/config.h new file mode 100644 index 0000000..3d7f896 --- /dev/null +++ b/include/ldns/config.h @@ -0,0 +1,224 @@ +/* configure vomit from linux */ + +#define HAVE_ARPA_INET_H 1 +#define HAVE_ATTR_FORMAT 1 +#define HAVE_ATTR_UNUSED 1 +#define HAVE_BZERO 1 +#define HAVE_CALLOC 1 +#define HAVE_CTIME_R 1 +#define HAVE_DANE_CA_FILE 0 +#define HAVE_DANE_CA_PATH 0 +#define HAVE_DECL_NID_SECP384R1 1 +#define HAVE_DECL_NID_X9_62_PRIME256V1 1 +#define HAVE_DLFCN_H 1 +#define HAVE_ENGINE_LOAD_CRYPTODEV 1 +#define HAVE_EVP_DSS1 1 +#define HAVE_EVP_PKEY_BASE_ID 1 +#define HAVE_EVP_PKEY_KEYGEN 1 +#define HAVE_EVP_SHA256 1 +#define HAVE_EVP_SHA384 1 +#define HAVE_EVP_SHA512 1 +#define HAVE_FCNTL 1 +#define HAVE_GETADDRINFO 1 +#define HAVE_GETOPT_H 1 +#define HAVE_GMTIME_R 1 +#define HAVE_HMAC_UPDATE 1 +#define HAVE_INET_ATON 1 +#define HAVE_INET_NTOP 1 +#define HAVE_INET_PTON 1 +#define HAVE_INTTYPES_H 1 +#define HAVE_ISASCII 1 +#define HAVE_ISBLANK 1 +#define HAVE_LOCALTIME_R 1 +#define HAVE_MALLOC 1 +#define HAVE_MEMMOVE 1 +#define HAVE_MEMORY_H 1 +#define HAVE_MEMSET 1 +#define HAVE_NETDB_H 1 +#define HAVE_NETINET_IN_H 1 +#define HAVE_OPENSSL_ERR_H 1 +#define HAVE_OPENSSL_RAND_H 1 +#define HAVE_OPENSSL_SSL_H 1 +#define HAVE_POLL 1 +#define HAVE_RANDOM 1 +#define HAVE_REALLOC 1 +#define HAVE_SLEEP 1 +#define HAVE_SNPRINTF 1 +#define HAVE_SSL /**/ +#define HAVE_STDARG_H 1 +#define HAVE_STDBOOL_H 1 +#define HAVE_STDINT_H 1 +#define HAVE_STDLIB_H 1 +#define HAVE_STRINGS_H 1 +#define HAVE_STRING_H 1 +#define HAVE_STRTOUL 1 +#define HAVE_SYS_MOUNT_H 1 +#define HAVE_SYS_PARAM_H 1 +#define HAVE_SYS_SOCKET_H 1 +#define HAVE_SYS_STAT_H 1 +#define HAVE_SYS_TYPES_H 1 +#define HAVE_TIMEGM 1 +#define HAVE_TIME_H 1 +#define HAVE_UNISTD_H 1 +#define HAVE__BOOL 1 +#define LT_OBJDIR ".libs/" +#define PACKAGE_BUGREPORT "libdns@nlnetlabs.nl" +#define PACKAGE_NAME "ldns" +#define PACKAGE_STRING "ldns" +#define PACKAGE_TARNAME "libdns" +#define PACKAGE_URL "" +#define PACKAGE_VERSION "" +#define RRTYPE_OPENPGPKEY /**/ +#define SIZEOF_TIME_T 8 +#define STDC_HEADERS 1 +#define SYSCONFDIR sysconfdir +#define USE_DANE 1 +#define USE_DANE_VERIFY 1 +#define USE_DSA 1 +#define USE_ECDSA 1 +#define USE_GOST 1 +#define USE_SHA2 1 +#ifndef _ALL_SOURCE +# define _ALL_SOURCE 1 +#endif +#ifndef _GNU_SOURCE +# define _GNU_SOURCE 1 +#endif +#ifndef _POSIX_PTHREAD_SEMANTICS +# define _POSIX_PTHREAD_SEMANTICS 1 +#endif +#ifndef _TANDEM_SOURCE +# define _TANDEM_SOURCE 1 +#endif +#ifndef __EXTENSIONS__ +# define __EXTENSIONS__ 1 +#endif +#define WINVER 0x0502 +#if defined AC_APPLE_UNIVERSAL_BUILD +# if defined __BIG_ENDIAN__ +# define WORDS_BIGENDIAN 1 +# endif +#else +# ifndef WORDS_BIGENDIAN +# endif +#endif +#ifndef __cplusplus +#endif +#include +#include +#include +#include +#ifndef LITTLE_ENDIAN +#define LITTLE_ENDIAN 1234 +#endif +#ifndef BIG_ENDIAN +#define BIG_ENDIAN 4321 +#endif +#ifndef BYTE_ORDER +#ifdef WORDS_BIGENDIAN +#define BYTE_ORDER BIG_ENDIAN +#else +#define BYTE_ORDER LITTLE_ENDIAN +#endif /* WORDS_BIGENDIAN */ +#endif /* BYTE_ORDER */ +#if STDC_HEADERS +#include +#include +#endif +#ifdef HAVE_STDINT_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_NETINET_IN_H +#include +#endif +#ifdef HAVE_ARPA_INET_H +#include +#endif +#ifdef HAVE_WINSOCK2_H +#include +#endif +#ifdef HAVE_WS2TCPIP_H +#include +#endif +#ifdef HAVE_WINSOCK2_H +#define FD_SET_T (u_int) +#else +#define FD_SET_T +#endif +#ifdef __cplusplus +extern "C" { +#endif +int ldns_b64_ntop(uint8_t const *src, size_t srclength, + char *target, size_t targsize); +static inline size_t ldns_b64_ntop_calculate_size(size_t srcsize) +{ + return ((((srcsize + 2) / 3) * 4) + 1); +} +int ldns_b64_pton(char const *src, uint8_t *target, size_t targsize); +static inline size_t ldns_b64_pton_calculate_size(size_t srcsize) +{ + return (((((srcsize + 3) / 4) * 3)) + 1); +} +int ldns_dname_compare_v(const void *a, const void *b); +#ifndef HAVE_SLEEP +#define sleep(x) Sleep((x)*1000) +#endif +#ifndef HAVE_RANDOM +#define srandom(x) srand(x) +#define random(x) rand(x) +#endif +#ifndef HAVE_TIMEGM +#include +time_t timegm (struct tm *tm); +#endif /* !TIMEGM */ +#ifndef HAVE_GMTIME_R +struct tm *gmtime_r(const time_t *timep, struct tm *result); +#endif +#ifndef HAVE_LOCALTIME_R +struct tm *localtime_r(const time_t *timep, struct tm *result); +#endif +#ifndef HAVE_ISBLANK +int isblank(int c); +#endif /* !HAVE_ISBLANK */ +#ifndef HAVE_ISASCII +int isascii(int c); +#endif /* !HAVE_ISASCII */ +#ifndef HAVE_SNPRINTF +#include +int snprintf (char *str, size_t count, const char *fmt, ...); +int vsnprintf (char *str, size_t count, const char *fmt, va_list arg); +#endif /* HAVE_SNPRINTF */ +#ifndef HAVE_INET_PTON +int inet_pton(int af, const char* src, void* dst); +#endif /* HAVE_INET_PTON */ +#ifndef HAVE_INET_NTOP +const char *inet_ntop(int af, const void *src, char *dst, size_t size); +#endif +#ifndef HAVE_INET_ATON +int inet_aton(const char *cp, struct in_addr *addr); +#endif +#ifndef HAVE_MEMMOVE +void *memmove(void *dest, const void *src, size_t n); +#endif +#ifndef HAVE_STRLCPY +size_t strlcpy(char *dst, const char *src, size_t siz); +#endif +#ifdef USE_WINSOCK +#define SOCK_INVALID INVALID_SOCKET +#define close_socket(_s) do { if (_s > SOCK_INVALID) {closesocket(_s); _s = SOCK_INVALID;} } while(0) +#else +#define SOCK_INVALID -1 +#define close_socket(_s) do { if (_s > SOCK_INVALID) {close(_s); _s = SOCK_INVALID;} } while(0) +#endif +#ifdef __cplusplus +} +#endif +#ifndef HAVE_GETADDRINFO +#include "compat/fake-rfc2553.h" +#endif +#ifndef HAVE_STRTOUL +#define strtoul (unsigned long)strtol +#endif diff --git a/lib/import/import-ldns.mk b/lib/import/import-ldns.mk new file mode 100644 index 0000000..ea2217f --- /dev/null +++ b/lib/import/import-ldns.mk @@ -0,0 +1,3 @@ +LDNS_PORT_DIR := $(call select_from_ports,ldns) +INC_DIR += $(LDNS_PORT_DIR)/include +CC_DEF += -DLDNS_TRUST_ANCHOR_FILE=\"/etc/unbound/root.key\" diff --git a/lib/mk/ldns.mk b/lib/mk/ldns.mk new file mode 100644 index 0000000..91d382d --- /dev/null +++ b/lib/mk/ldns.mk @@ -0,0 +1,13 @@ +include $(REP_DIR)/lib/import/import-ldns.mk +LDNS_SRC_DIR := $(LDNS_PORT_DIR)/src/lib/ldns + +LIBS += libc libssl + +SRC_LDNS_C := $(notdir $(wildcard $(LDNS_SRC_DIR)/*.c)) + +SRC_C += $(filter-out linktest.c,$(SRC_LDNS_C)) +SRC_C += $(notdir $(wildcard $(LDNS_SRC_DIR)/compat/b64*.c)) +SRC_CC += getproto.cc + +vpath %.c $(LDNS_SRC_DIR) $(LDNS_SRC_DIR)/compat +vpath %.cc $(REP_DIR)/src/lib/ldns diff --git a/ports/ldns.hash b/ports/ldns.hash new file mode 100644 index 0000000..4552f73 --- /dev/null +++ b/ports/ldns.hash @@ -0,0 +1 @@ +42e260601f199b0a24d9312918601fc97cb65cdb diff --git a/ports/ldns.port b/ports/ldns.port new file mode 100644 index 0000000..7811e9b --- /dev/null +++ b/ports/ldns.port @@ -0,0 +1,50 @@ +LICENSE = BSD +DOWNLOADS = ldns.archive +VERSION = 1.7.0 + +URL(ldns) := https://www.nlnetlabs.nl/downloads/ldns/ldns-$(VERSION).tar.gz +SHA(ldns) := ceeeccf8a27e61a854762737f6ee02f44662c1b8 +DIR(ldns) := src/lib/ldns + +DIRS := include/ldns +DIR_CONTENT(include/ldns) = src/lib/ldns/ldns/*.h + +default: include/ldns/common.h include/ldns/net.h include/ldns/util.h + +include/ldns/common.h: src/lib/ldns/ldns/common.h.in + @$(MSG_GENERATE)$(notdir $@) + $(VERBOSE)mkdir -p include/ldns + $(VERBOSE)sed \ + -e 's/@ldns_build_config_have_ssl@/1/' \ + -e 's/@ldns_build_config_have_inttypes_h@/1/' \ + -e 's/@ldns_build_config_have_attr_format@/1/' \ + -e 's/@ldns_build_config_have_attr_unused@/1/' \ + -e 's/@ldns_build_config_have_socklen_t@/1/' \ + -e 's/@ldns_build_config_use_dane@/1/' \ + -e 's/@ldns_build_config_have_b32_pton@/0/' \ + -e 's/@ldns_build_config_have_b32_ntop@/0/' \ + $< > $@ + +include/ldns/net.h: src/lib/ldns/ldns/net.h.in + @$(MSG_GENERATE)$(notdir $@) + $(VERBOSE)mkdir -p include/ldns + $(VERBOSE)sed \ + -e 's?@include_sys_socket_h@?#include ?' \ + $< > $@ + +include/ldns/util.h: src/lib/ldns/ldns/util.h.in + @$(MSG_GENERATE)$(notdir $@) + $(VERBOSE)mkdir -p include/ldns + $(VERBOSE)sed \ + -e 's?@include_inttypes_h@?#include ?' \ + -e 's?@include_systypes_h@?#include ?' \ + -e 's?@include_unistd_h@?#include ?' \ + -e 's?@PACKAGE_VERSION@?$(VERSION)?' \ + -e 's?@LDNS_VERSION_MAJOR@?1?' \ + -e 's?@LDNS_VERSION_MINOR@?7?' \ + -e 's?@LDNS_VERSION_MICRO@?0?' \ + $< > $@ + +src/lib/ldns/ldns/common.h.in: $(DOWNLOADS) +src/lib/ldns/ldns/net.h.in: $(DOWNLOADS) +src/lib/ldns/ldns/util.h.in: $(DOWNLOADS) diff --git a/run/drill.run b/run/drill.run new file mode 100644 index 0000000..af23d76 --- /dev/null +++ b/run/drill.run @@ -0,0 +1,101 @@ +if {[have_spec linux]} { + puts "The [run_name] scenario requires QEMU networking." + exit 1 +} + +source ${genode_dir}/repos/base/run/platform_drv.inc + +set build_components { + core init + app/drill + drivers/timer + drivers/nic + drivers/rtc + lib/vfs/jitterentropy +} + +append_platform_drv_build_components + +build $build_components + +create_boot_directory + +append config { + + + + + + + + + + + + + + + } + +append_platform_drv_config + +append config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +} + +install_config $config + +set boot_modules { + core init ld.lib.so + drill + libc.lib.so + libcrypto.lib.so + libm.lib.so + libssl.lib.so + posix.lib.so + rtc_drv + timer + vfs_jitterentropy.lib.so + vfs_lxip.lib.so lxip.lib.so +} + +# platform-specific modules +append_platform_drv_boot_modules +lappend boot_modules [nic_drv_binary] + +build_boot_image $boot_modules + +append qemu_args " -nographic -net nic,model=e1000 -net user -net dump,file=[run_dir]/dump.pcap" + +run_genode_until {child "drill" exited with exit value 0.*\n} 120 diff --git a/src/app/drill/target.mk b/src/app/drill/target.mk new file mode 100644 index 0000000..694bed5 --- /dev/null +++ b/src/app/drill/target.mk @@ -0,0 +1,11 @@ +TARGET = drill + +LIBS += base libc posix ldns libssl libcrypto + +DRILL_SRC_DIR += $(call select_from_ports,ldns)/src/lib/ldns/drill + +INC_DIR += $(REP_DIR)/include/ldns + +SRC_C += $(notdir $(wildcard $(DRILL_SRC_DIR)/*.c)) + +vpath %.c $(DRILL_SRC_DIR) diff --git a/src/lib/ldns/getproto.cc b/src/lib/ldns/getproto.cc new file mode 100644 index 0000000..1a98de9 --- /dev/null +++ b/src/lib/ldns/getproto.cc @@ -0,0 +1,14 @@ +#include + +#include +#include + +struct protoent *getprotobynumber(int proto) +{ + static protoent pe; + + Genode::error(__func__, "(", proto, ") not implemented"); + + Genode::memset(&pe, 0x00, sizeof(pe)); + return &pe; +}