summaryrefslogtreecommitdiff
path: root/src/include
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2023-07-06 11:00:58 +0000
committerLaurent Bercot <ska@appnovation.com>2023-07-06 11:00:58 +0000
commitcfe4051aaffd4ff5e7a1b55b023840042896dbd6 (patch)
tree254e4ba0b8d5e1fd2286ad562518f65aba5df07e /src/include
parentad7f496c36025a4177e061bbf7d1205d38685316 (diff)
downloads6-dns-cfe4051aaffd4ff5e7a1b55b023840042896dbd6.tar.xz
Add s6dns_hosts reading functions
Signed-off-by: Laurent Bercot <ska@appnovation.com>
Diffstat (limited to 'src/include')
-rw-r--r--src/include/s6-dns/hosts.h65
1 files changed, 64 insertions, 1 deletions
diff --git a/src/include/s6-dns/hosts.h b/src/include/s6-dns/hosts.h
index 9c2baaf..7c11af0 100644
--- a/src/include/s6-dns/hosts.h
+++ b/src/include/s6-dns/hosts.h
@@ -4,13 +4,76 @@
#define S6DNS_HOSTS_H
#include <skalibs/cdb.h>
+#include <skalibs/stralloc.h>
#include <skalibs/genalloc.h>
+#include <s6-dns/s6dns-rci.h>
+
extern cdb s6dns_hosts_here ;
+extern int s6dns_hosts_compile (int, int) ;
+
extern int s6dns_hosts_init (cdb *) ;
#define s6dns_hosts_free(c) cdb_free(c)
-extern int s6dns_hosts_compile (int, int) ;
+
+
+ /* IP to name */
+
+extern int s6dns_hosts_name_r (cdb const *, char const *, stralloc *, genalloc *, int) ;
+#define s6dns_hosts_name4_r(cdb, ip, sa, ga) s6dns_hosts_name_r(cdb, ip, sa, ga, 0)
+#define s6dns_hosts_name6_r(cdb, ip, sa, ga) s6dns_hosts_name_r(cdb, ip, sa, (ga), 1)
+
+#define s6dns_hosts_name(ip, sa, ga, is6) s6dns_hosts_name_r(&s6dns_hosts_here, (ip), sa, ga, is6)
+#define s6dns_hosts_name4(ip, sa, ga) s6dns_hosts_name4_r(&s6dns_hosts_here, (ip), sa, ga)
+#define s6dns_hosts_name6(ip, sa, ga) s6dns_hosts_name6_r(&s6dns_hosts_here, (ip), sa, ga)
+
+
+ /* name to IP. noq: name is an fqdn. unq: name is unqualified. */
+
+extern int s6dns_hosts_ip_string_r (cdb const *, char const *, stralloc *, unsigned int) ;
+#define s6dns_hosts_ip_noq_r(c, name, sa, is6) s6dns_hosts_ip_string_r(c, name, sa, !!(is6))
+#define s6dns_hosts_ip_unq_r(c, name, sa, is6) s6dns_hosts_ip_string_r(c, name, sa, (!!(is6)) | 2)
+
+#define s6dns_hosts_ip_string(name, sa, flags) s6dns_hosts_ip_string_r(&s6dns_hosts_here, (name), sa, flags)
+#define s6dns_hosts_ip_noq(name, sa, is6) s6dns_hosts_ip_noq_r(&s6dns_hosts_here, (name), sa, is6)
+#define s6dns_hosts_ip_unq(name, sa, is6) s6dns_hosts_ip_unq_r(&s6dns_hosts_here, (name), sa, is6)
+
+#define s6dns_hosts_a_string_r(c, name, sa, isalias) s6dns_hosts_ip_string_r(c, name, sa, !!(isunq) << 1)
+#define s6dns_hosts_aaaa_string_r(c, name, sa, isalias) s6dns_hosts_ip_string_r(c, name, sa, (!!(isunq) << 1) | 1)
+extern int s6dns_hosts_aaaaa_string_r (cdb const *, char const *, genalloc *, int) ;
+
+#define s6dns_hosts_a_string(name, sa, isunq) s6dns_hosts_a_string_r(&s6dns_hosts_here, (name), sa, isunq)
+#define s6dns_hosts_aaaa_string(name, sa, isunq) s6dns_hosts_aaaa_string_r(&s6dns_hosts_here, (name), sa, isunq)
+#define s6dns_hosts_aaaaa_string(name, ga, isunq) s6dns_hosts_aaaaa_string_r(&s6dns_hosts_here, (name), ga, isunq)
+
+#define s6dns_hosts_a_noq_r(c, name, sa) s6dns_hosts_a_string_r(c, name, (sa), 0)
+#define s6dns_hosts_aaaa_noq_r(c, name, sa) s6dns_hosts_aaaa_string_r(c, name, (sa), 1)
+#define s6dns_hosts_aaaaa_noq_r(c, name, ga) s6dns_hosts_aaaaa_string_r(c, name, (ga), 0)
+
+#define s6dns_hosts_a_noq(name, sa) s6dns_hosts_a_noq_r(&s6dns_hosts_here, (name), sa)
+#define s6dns_hosts_aaaa_noq(name, sa) s6dns_hosts_aaaa_noq_r(&s6dns_hosts_here, (name), sa)
+#define s6dns_hosts_aaaaa_noq(name, ga) s6dns_hosts_aaaaa_noq_r(&s6dns_hosts_here, (name), ga)
+
+#define s6dns_hosts_a_unq_r(c, name, sa) s6dns_hosts_a_string_r(c, name, (sa), 2)
+#define s6dns_hosts_aaaa_unq_r(c, name, sa) s6dns_hosts_aaaa_string_r(c, name, (sa), 3)
+#define s6dns_hosts_aaaaa_unq_r(c, name, ga) s6dns_hosts_aaaaa_string_r(c, name, (ga), 1)
+
+#define s6dns_hosts_a_unq(name, sa) s6dns_hosts_a_unq_r(&s6dns_hosts_here, (name), sa)
+#define s6dns_hosts_aaaa_unq(name, sa) s6dns_hosts_aaaa_unq_r(&s6dns_hosts_here, (name), sa)
+#define s6dns_hosts_aaaaa_unq(name, ga) s6dns_hosts_aaaaa_unq_r(&s6dns_hosts_here, (name), ga)
+
+
+ /* name to IP, with qualification */
+
+extern int s6dns_hosts_ip_q_r (cdb const *, char const *, stralloc *sa, char const *, unsigned int, int) ;
+#define s6dns_hosts_a_q_r(c, name, sa, rules, rulesnum) s6dns_hosts_ip_q_r(c, name, sa, rules, rulesnum, 0)
+#define s6dns_hosts_aaaa_q_r(c, name, rules, rulesnum, sa) s6dns_hosts_ip_q_r(c, name, sa, rules, rulesnum, 1)
+extern int s6dns_hosts_aaaaa_q_r (cdb const *, char const *, genalloc *, char const *, unsigned int) ;
+
+#define s6dns_hosts_ip_q(name, sa, is6) s6dns_hosts_ip_q_r(&s6dns_hosts_here, (name), sa, s6dns_rci_here.rules.s, s6dns_rci_here.rulesnum, is6)
+#define s6dns_hosts_a_q(name, sa) s6dns_hosts_a_q_r(&s6dns_hosts_here, (name), sa, s6dns_rci_here.rules.s, s6dns_rci_here.rulesnum)
+#define s6dns_hosts_aaaa_q(name, sa) s6dns_hosts_ip_q_r(&s6dns_hosts_here, (name), sa, s6dns_rci_here.rules.s, s6dns_rci_here.rulesnum)
+#define s6dns_hosts_aaaaa_q(name, ga) s6dns_hosts_aaaaa_q_r(&s6dns_hosts_here, (name), ga)
#endif