summaryrefslogtreecommitdiffhomepage
path: root/CMakeLists.txt
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-10-21 00:18:55 +0200
committerJo-Philipp Wich <jo@mein.io>2021-10-22 20:22:00 +0200
commitc9e68bb8f6830b053537b2fc62b78172bd815ff2 (patch)
tree81ede93b7307d742caf3e4cfcd7053accd6d5e34 /CMakeLists.txt
parent9041e2403d98fdb54206c23bd684a7da6fb63026 (diff)
lib: introduce resolver library
This adds a simple, UDP-only DNS resolver library mimicking the operation of the extended busybox nslookup applet. Simply querying a domain name will perform A + AAAA resolving by default: # ucode -mresolv -Rs 'printf("%.J\n", resolv.query("example.com"))' { "example.com": { "A": [ "93.184.216.34" ], "AAAA": [ "2606:2800:220:1:248:1893:25c8:1946" ] } } Passing IP addresses will automatically perform PTR requests: # ucode -mresolv -Rs 'printf("%.J\n", resolv.query("8.8.8.8"))' { "8.8.8.8.in-addr.arpa": { "PTR": [ "dns.google" ] } } # ucode -mresolv -Rs 'printf("%.J\n", resolv.query("2001:4860:4860::8888"))' { "8.8.8.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.6.8.4.0.6.8.4.1.0.0.2.ip6.arpa": { "PTR": [ "dns.google" ] } } Additional options for query type and nameserver selection can be passed via a second optional options dictionary: # ucode -mresolv -Rs 'printf("%.J\n", resolv.query([ "openwrt.org", "example.org", "doesnotexist.tld" ], { type: [ "A", "AAAA", "MX" ], nameserver: [ "1.1.1.1", "8.8.4.4" ], timeout: 5000, retries: 2, edns_maxsize: 4096 }))' { "openwrt.org": { "A": [ "139.59.209.225" ], "MX": [ [ 10, "util-01.infra.openwrt.org" ] ], "AAAA": [ "2a03:b0c0:3:d0::1af1:1" ] }, "example.org": { "A": [ "93.184.216.34" ], "AAAA": [ "2606:2800:220:1:248:1893:25c8:1946" ], "MX": [ [ 0, "." ] ] }, "doesnotexist.tld": { "rcode": "NXDOMAIN" } } Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'CMakeLists.txt')
-rw-r--r--CMakeLists.txt15
1 files changed, 15 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f993019..e5fb58a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -19,6 +19,7 @@ OPTION(UBUS_SUPPORT "Ubus plugin support" ON)
OPTION(UCI_SUPPORT "UCI plugin support" ON)
OPTION(RTNL_SUPPORT "Route Netlink plugin support" ON)
OPTION(NL80211_SUPPORT "Wireless Netlink plugin support" ON)
+OPTION(RESOLV_SUPPORT "NS resolve plugin support" ON)
OPTION(LEGACY_SUPPORT "Support deprecated syntax features" ON)
@@ -136,6 +137,20 @@ IF(NL80211_SUPPORT)
TARGET_LINK_LIBRARIES(nl80211_lib ${nl})
ENDIF()
+IF(RESOLV_SUPPORT)
+ SET(LIBRARIES ${LIBRARIES} resolv_lib)
+ ADD_LIBRARY(resolv_lib MODULE lib/resolv.c)
+ SET_TARGET_PROPERTIES(resolv_lib PROPERTIES OUTPUT_NAME resolv PREFIX "")
+ CHECK_FUNCTION_EXISTS(res_mkquery RES_MKQUERY_FUNCTION_EXISTS)
+ CHECK_FUNCTION_EXISTS(clock_gettime CLOCK_GETTIME_FUNCTION_EXISTS)
+ IF (NOT RES_MKQUERY_FUNCTION_EXISTS)
+ TARGET_LINK_LIBRARIES(resolv_lib resolv)
+ ENDIF()
+ IF (NOT CLOCK_GETTIME_FUNCTION_EXISTS)
+ TARGET_LINK_LIBRARIES(resolv_lib rt)
+ ENDIF()
+ENDIF()
+
IF(UNIT_TESTING)
ENABLE_TESTING()
ADD_DEFINITIONS(-DUNIT_TESTING)