1*b2efd602SCy Schubert.. 2*b2efd602SCy Schubert WHEN EDITING MAKE SURE EACH SENTENCE STARTS ON A NEW LINE 3*b2efd602SCy Schubert 4*b2efd602SCy Schubert.. 5*b2efd602SCy Schubert IT HELPS RENDERERS TO DO THE RIGHT THING WRT SPACE 6*b2efd602SCy Schubert 7*b2efd602SCy Schubert.. 8*b2efd602SCy Schubert IT HELPS PEOPLE DIFFING THE CHANGES 9*b2efd602SCy Schubert 10*b2efd602SCy Schubert.. 11*b2efd602SCy Schubert WHEN EDITING MAKE SURE EACH SENTENCE STARTS ON A NEW LINE 12*b2efd602SCy Schubert 13*b2efd602SCy Schubert.. 14*b2efd602SCy Schubert IT HELPS RENDERERS TO DO THE RIGHT THING WRT SPACE 15*b2efd602SCy Schubert 16*b2efd602SCy Schubert.. 17*b2efd602SCy Schubert IT HELPS PEOPLE DIFFING THE CHANGES 18*b2efd602SCy Schubert 19*b2efd602SCy Schubert.. 20*b2efd602SCy Schubert WHEN EDITING MAKE SURE EACH SENTENCE STARTS ON A NEW LINE 21*b2efd602SCy Schubert 22*b2efd602SCy Schubert.. 23*b2efd602SCy Schubert IT HELPS RENDERERS TO DO THE RIGHT THING WRT SPACE 24*b2efd602SCy Schubert 25*b2efd602SCy Schubert.. 26*b2efd602SCy Schubert IT HELPS PEOPLE DIFFING THE CHANGES 27*b2efd602SCy Schubert 28*b2efd602SCy Schubert.. 29*b2efd602SCy Schubert WHEN EDITING MAKE SURE EACH SENTENCE STARTS ON A NEW LINE 30*b2efd602SCy Schubert 31*b2efd602SCy Schubert.. 32*b2efd602SCy Schubert IT HELPS RENDERERS TO DO THE RIGHT THING WRT SPACE 33*b2efd602SCy Schubert 34*b2efd602SCy Schubert.. 35*b2efd602SCy Schubert IT HELPS PEOPLE DIFFING THE CHANGES 36*b2efd602SCy Schubert 37*b2efd602SCy Schubertlibunbound(3) 38*b2efd602SCy Schubert============= 39*b2efd602SCy Schubert 40*b2efd602SCy SchubertSynopsis 41*b2efd602SCy Schubert-------- 42*b2efd602SCy Schubert 43*b2efd602SCy Schubert.. only:: html 44*b2efd602SCy Schubert 45*b2efd602SCy Schubert .. code-block:: c 46*b2efd602SCy Schubert 47*b2efd602SCy Schubert #include <unbound.h> 48*b2efd602SCy Schubert 49*b2efd602SCy Schubert struct ub_ctx * ub_ctx_create(void); 50*b2efd602SCy Schubert 51*b2efd602SCy Schubert void ub_ctx_delete(struct ub_ctx* ctx); 52*b2efd602SCy Schubert 53*b2efd602SCy Schubert int ub_ctx_set_option(struct ub_ctx* ctx, char* opt, char* val); 54*b2efd602SCy Schubert 55*b2efd602SCy Schubert int ub_ctx_get_option(struct ub_ctx* ctx, char* opt, char** val); 56*b2efd602SCy Schubert 57*b2efd602SCy Schubert int ub_ctx_config(struct ub_ctx* ctx, char* fname); 58*b2efd602SCy Schubert 59*b2efd602SCy Schubert int ub_ctx_set_fwd(struct ub_ctx* ctx, char* addr); 60*b2efd602SCy Schubert 61*b2efd602SCy Schubert int ub_ctx_set_stub(struct ub_ctx* ctx, char* zone, char* addr, 62*b2efd602SCy Schubert int isprime); 63*b2efd602SCy Schubert 64*b2efd602SCy Schubert int ub_ctx_set_tls(struct ub_ctx* ctx, int tls); 65*b2efd602SCy Schubert 66*b2efd602SCy Schubert int ub_ctx_resolvconf(struct ub_ctx* ctx, char* fname); 67*b2efd602SCy Schubert 68*b2efd602SCy Schubert int ub_ctx_hosts(struct ub_ctx* ctx, char* fname); 69*b2efd602SCy Schubert 70*b2efd602SCy Schubert int ub_ctx_add_ta(struct ub_ctx* ctx, char* ta); 71*b2efd602SCy Schubert 72*b2efd602SCy Schubert int ub_ctx_add_ta_autr(struct ub_ctx* ctx, char* fname); 73*b2efd602SCy Schubert 74*b2efd602SCy Schubert int ub_ctx_add_ta_file(struct ub_ctx* ctx, char* fname); 75*b2efd602SCy Schubert 76*b2efd602SCy Schubert int ub_ctx_trustedkeys(struct ub_ctx* ctx, char* fname); 77*b2efd602SCy Schubert 78*b2efd602SCy Schubert int ub_ctx_debugout(struct ub_ctx* ctx, FILE* out); 79*b2efd602SCy Schubert 80*b2efd602SCy Schubert int ub_ctx_debuglevel(struct ub_ctx* ctx, int d); 81*b2efd602SCy Schubert 82*b2efd602SCy Schubert int ub_ctx_async(struct ub_ctx* ctx, int dothread); 83*b2efd602SCy Schubert 84*b2efd602SCy Schubert int ub_poll(struct ub_ctx* ctx); 85*b2efd602SCy Schubert 86*b2efd602SCy Schubert int ub_wait(struct ub_ctx* ctx); 87*b2efd602SCy Schubert 88*b2efd602SCy Schubert int ub_fd(struct ub_ctx* ctx); 89*b2efd602SCy Schubert 90*b2efd602SCy Schubert int ub_process(struct ub_ctx* ctx); 91*b2efd602SCy Schubert 92*b2efd602SCy Schubert int ub_resolve(struct ub_ctx* ctx, char* name, int rrtype, 93*b2efd602SCy Schubert int rrclass, struct ub_result** result); 94*b2efd602SCy Schubert 95*b2efd602SCy Schubert int ub_resolve_async(struct ub_ctx* ctx, char* name, int rrtype, 96*b2efd602SCy Schubert int rrclass, void* mydata, ub_callback_type callback, 97*b2efd602SCy Schubert int* async_id); 98*b2efd602SCy Schubert 99*b2efd602SCy Schubert int ub_cancel(struct ub_ctx* ctx, int async_id); 100*b2efd602SCy Schubert 101*b2efd602SCy Schubert void ub_resolve_free(struct ub_result* result); 102*b2efd602SCy Schubert 103*b2efd602SCy Schubert const char * ub_strerror(int err); 104*b2efd602SCy Schubert 105*b2efd602SCy Schubert int ub_ctx_print_local_zones(struct ub_ctx* ctx); 106*b2efd602SCy Schubert 107*b2efd602SCy Schubert int ub_ctx_zone_add(struct ub_ctx* ctx, char* zone_name, char* zone_type); 108*b2efd602SCy Schubert 109*b2efd602SCy Schubert int ub_ctx_zone_remove(struct ub_ctx* ctx, char* zone_name); 110*b2efd602SCy Schubert 111*b2efd602SCy Schubert int ub_ctx_data_add(struct ub_ctx* ctx, char* data); 112*b2efd602SCy Schubert 113*b2efd602SCy Schubert int ub_ctx_data_remove(struct ub_ctx* ctx, char* data); 114*b2efd602SCy Schubert 115*b2efd602SCy Schubert.. only:: man 116*b2efd602SCy Schubert 117*b2efd602SCy Schubert **#include <unbound.h>** 118*b2efd602SCy Schubert 119*b2efd602SCy Schubert struct ub_ctx \* **ub_ctx_create**\ (void); 120*b2efd602SCy Schubert 121*b2efd602SCy Schubert void **ub_ctx_delete**\ (struct ub_ctx\* ctx); 122*b2efd602SCy Schubert 123*b2efd602SCy Schubert int **ub_ctx_set_option**\ (struct ub_ctx\* ctx, char\* opt, char\* val); 124*b2efd602SCy Schubert 125*b2efd602SCy Schubert int **ub_ctx_get_option**\ (struct ub_ctx\* ctx, char\* opt, char\*\* val); 126*b2efd602SCy Schubert 127*b2efd602SCy Schubert int **ub_ctx_config**\ (struct ub_ctx\* ctx, char* fname); 128*b2efd602SCy Schubert 129*b2efd602SCy Schubert int **ub_ctx_set_fwd**\ (struct ub_ctx\* ctx, char\* addr); 130*b2efd602SCy Schubert 131*b2efd602SCy Schubert int **ub_ctx_set_stub**\ (struct ub_ctx\* ctx, char\* zone, char\* addr, 132*b2efd602SCy Schubert int isprime); 133*b2efd602SCy Schubert 134*b2efd602SCy Schubert int **ub_ctx_set_tls**\ (struct ub_ctx\* ctx, int tls); 135*b2efd602SCy Schubert 136*b2efd602SCy Schubert int **ub_ctx_resolvconf**\ (struct ub_ctx\* ctx, char\* fname); 137*b2efd602SCy Schubert 138*b2efd602SCy Schubert int **ub_ctx_hosts**\ (struct ub_ctx\* ctx, char\* fname); 139*b2efd602SCy Schubert 140*b2efd602SCy Schubert int **ub_ctx_add_ta**\ (struct ub_ctx\* ctx, char\* ta); 141*b2efd602SCy Schubert 142*b2efd602SCy Schubert int **ub_ctx_add_ta_autr**\ (struct ub_ctx\* ctx, char\* fname); 143*b2efd602SCy Schubert 144*b2efd602SCy Schubert int **ub_ctx_add_ta_file**\ (struct ub_ctx\* ctx, char\* fname); 145*b2efd602SCy Schubert 146*b2efd602SCy Schubert int **ub_ctx_trustedkeys**\ (struct ub_ctx\* ctx, char\* fname); 147*b2efd602SCy Schubert 148*b2efd602SCy Schubert int **ub_ctx_debugout**\ (struct ub_ctx\* ctx, FILE\* out); 149*b2efd602SCy Schubert 150*b2efd602SCy Schubert int **ub_ctx_debuglevel**\ (struct ub_ctx\* ctx, int d); 151*b2efd602SCy Schubert 152*b2efd602SCy Schubert int **ub_ctx_async**\ (struct ub_ctx\* ctx, int dothread); 153*b2efd602SCy Schubert 154*b2efd602SCy Schubert int **ub_poll**\ (struct ub_ctx\* ctx); 155*b2efd602SCy Schubert 156*b2efd602SCy Schubert int **ub_wait**\ (struct ub_ctx\* ctx); 157*b2efd602SCy Schubert 158*b2efd602SCy Schubert int **ub_fd**\ (struct ub_ctx\* ctx); 159*b2efd602SCy Schubert 160*b2efd602SCy Schubert int **ub_process**\ (struct ub_ctx\* ctx); 161*b2efd602SCy Schubert 162*b2efd602SCy Schubert int **ub_resolve**\ (struct ub_ctx\* ctx, char\* name, 163*b2efd602SCy Schubert int rrtype, int rrclass, struct ub_result\*\* result); 164*b2efd602SCy Schubert 165*b2efd602SCy Schubert int **ub_resolve_async**\ (struct ub_ctx\* ctx, char\* name, 166*b2efd602SCy Schubert int rrtype, int rrclass, void\* mydata, 167*b2efd602SCy Schubert ub_callback_type\* callback, int\* async_id); 168*b2efd602SCy Schubert 169*b2efd602SCy Schubert int **ub_cancel**\ (struct ub_ctx\* ctx, int async_id); 170*b2efd602SCy Schubert 171*b2efd602SCy Schubert void **ub_resolve_free**\ (struct ub_result\* result); 172*b2efd602SCy Schubert 173*b2efd602SCy Schubert const char \* **ub_strerror**\ (int err); 174*b2efd602SCy Schubert 175*b2efd602SCy Schubert int **ub_ctx_print_local_zones**\ (struct ub_ctx\* ctx); 176*b2efd602SCy Schubert 177*b2efd602SCy Schubert int **ub_ctx_zone_add**\ (struct ub_ctx\* ctx, char\* zone_name, char\* zone_type); 178*b2efd602SCy Schubert 179*b2efd602SCy Schubert int **ub_ctx_zone_remove**\ (struct ub_ctx\* ctx, char\* zone_name); 180*b2efd602SCy Schubert 181*b2efd602SCy Schubert int **ub_ctx_data_add**\ (struct ub_ctx\* ctx, char\* data); 182*b2efd602SCy Schubert 183*b2efd602SCy Schubert int **ub_ctx_data_remove**\ (struct ub_ctx\* ctx, char\* data); 184*b2efd602SCy Schubert 185*b2efd602SCy SchubertDescription 186*b2efd602SCy Schubert----------- 187*b2efd602SCy Schubert 188*b2efd602SCy SchubertUnbound is an implementation of a DNS resolver, that does caching and DNSSEC 189*b2efd602SCy Schubertvalidation. 190*b2efd602SCy SchubertThis is the library API, for using the ``-lunbound`` library. 191*b2efd602SCy SchubertThe server daemon is described in :doc:`unbound(8)</manpages/unbound>`. 192*b2efd602SCy SchubertThe library works independent from a running unbound server, and can be used to 193*b2efd602SCy Schubertconvert hostnames to ip addresses, and back, and obtain other information from 194*b2efd602SCy Schubertthe DNS. 195*b2efd602SCy SchubertThe library performs public-key validation of results with DNSSEC. 196*b2efd602SCy Schubert 197*b2efd602SCy SchubertThe library uses a variable of type *struct ub_ctx* to keep context between 198*b2efd602SCy Schubertcalls. 199*b2efd602SCy SchubertThe user must maintain it, creating it with **ub_ctx_create** and deleting it 200*b2efd602SCy Schubertwith **ub_ctx_delete**. 201*b2efd602SCy SchubertIt can be created and deleted at any time. 202*b2efd602SCy SchubertCreating it anew removes any previous configuration (such as trusted keys) and 203*b2efd602SCy Schubertclears any cached results. 204*b2efd602SCy Schubert 205*b2efd602SCy SchubertThe functions are thread-safe, and a context can be used in a threaded (as well 206*b2efd602SCy Schubertas in a non-threaded) environment. 207*b2efd602SCy SchubertAlso resolution (and validation) can be performed blocking and non-blocking 208*b2efd602SCy Schubert(also called asynchronous). 209*b2efd602SCy SchubertThe async method returns from the call immediately, so that processing can go 210*b2efd602SCy Schuberton, while the results become available later. 211*b2efd602SCy Schubert 212*b2efd602SCy SchubertThe functions are discussed in turn below. 213*b2efd602SCy Schubert 214*b2efd602SCy SchubertFunctions 215*b2efd602SCy Schubert--------- 216*b2efd602SCy Schubert 217*b2efd602SCy Schubert.. glossary:: 218*b2efd602SCy Schubert 219*b2efd602SCy Schubert ub_ctx_create 220*b2efd602SCy Schubert Create a new context, initialised with defaults. 221*b2efd602SCy Schubert The information from :file:`/etc/resolv.conf` and :file:`/etc/hosts` is 222*b2efd602SCy Schubert not utilised by default. 223*b2efd602SCy Schubert Use **ub_ctx_resolvconf** and **ub_ctx_hosts** to read them. 224*b2efd602SCy Schubert Before you call this, use the openssl functions 225*b2efd602SCy Schubert **CRYPTO_set_id_callback** and **CRYPTO_set_locking_callback** to set 226*b2efd602SCy Schubert up asynchronous operation if you use lib openssl (the application calls 227*b2efd602SCy Schubert these functions once for initialisation). 228*b2efd602SCy Schubert Openssl 1.0.0 or later uses the **CRYPTO_THREADID_set_callback** 229*b2efd602SCy Schubert function. 230*b2efd602SCy Schubert 231*b2efd602SCy Schubert ub_ctx_delete 232*b2efd602SCy Schubert Delete validation context and free associated resources. 233*b2efd602SCy Schubert Outstanding async queries are killed and callbacks are not called for 234*b2efd602SCy Schubert them. 235*b2efd602SCy Schubert 236*b2efd602SCy Schubert ub_ctx_set_option 237*b2efd602SCy Schubert A power-user interface that lets you specify one of the options from 238*b2efd602SCy Schubert the config file format, see :doc:`unbound.conf(5)</manpages/unbound.conf>`. 239*b2efd602SCy Schubert Not all options are relevant. 240*b2efd602SCy Schubert For some specific options, such as adding trust anchors, special 241*b2efd602SCy Schubert routines exist. 242*b2efd602SCy Schubert Pass the option name with the trailing ``':'``. 243*b2efd602SCy Schubert 244*b2efd602SCy Schubert ub_ctx_get_option 245*b2efd602SCy Schubert A power-user interface that gets an option value. 246*b2efd602SCy Schubert Some options cannot be gotten, and others return a newline separated 247*b2efd602SCy Schubert list. 248*b2efd602SCy Schubert Pass the option name without trailing ``':'``. 249*b2efd602SCy Schubert The returned value must be free(2)d by the caller. 250*b2efd602SCy Schubert 251*b2efd602SCy Schubert ub_ctx_config 252*b2efd602SCy Schubert A power-user interface that lets you specify an unbound config file, 253*b2efd602SCy Schubert see :doc:`unbound.conf(5)</manpages/unbound.conf>`, which is read for 254*b2efd602SCy Schubert configuration. 255*b2efd602SCy Schubert Not all options are relevant. 256*b2efd602SCy Schubert For some specific options, such as adding trust anchors, special 257*b2efd602SCy Schubert routines exist. 258*b2efd602SCy Schubert This function is thread-safe only if a single instance of **ub_ctx**\* 259*b2efd602SCy Schubert exists in the application. 260*b2efd602SCy Schubert If several instances exist the application has to ensure that 261*b2efd602SCy Schubert **ub_ctx_config** is not called in parallel by the different instances. 262*b2efd602SCy Schubert 263*b2efd602SCy Schubert ub_ctx_set_fwd 264*b2efd602SCy Schubert Set machine to forward DNS queries to, the caching resolver to use. 265*b2efd602SCy Schubert IP4 or IP6 address. 266*b2efd602SCy Schubert Forwards all DNS requests to that machine, which is expected to run a 267*b2efd602SCy Schubert recursive resolver. 268*b2efd602SCy Schubert If the proxy is not DNSSEC capable, validation may fail. 269*b2efd602SCy Schubert Can be called several times, in that case the addresses are used as 270*b2efd602SCy Schubert backup servers. 271*b2efd602SCy Schubert At this time it is only possible to set configuration before the first 272*b2efd602SCy Schubert resolve is done. 273*b2efd602SCy Schubert 274*b2efd602SCy Schubert ub_ctx_set_stub 275*b2efd602SCy Schubert Set a stub zone, authoritative dns servers to use for a particular 276*b2efd602SCy Schubert zone. 277*b2efd602SCy Schubert IP4 or IP6 address. 278*b2efd602SCy Schubert If the address is NULL the stub entry is removed. 279*b2efd602SCy Schubert Set isprime true if you configure root hints with it. 280*b2efd602SCy Schubert Otherwise similar to the stub zone item from unbound's config file. 281*b2efd602SCy Schubert Can be called several times, for different zones, or to add multiple 282*b2efd602SCy Schubert addresses for a particular zone. 283*b2efd602SCy Schubert At this time it is only possible to set configuration before the first 284*b2efd602SCy Schubert resolve is done. 285*b2efd602SCy Schubert 286*b2efd602SCy Schubert ub_ctx_set_tls 287*b2efd602SCy Schubert Enable DNS over TLS (DoT) for machines set with **ub_ctx_set_fwd**. 288*b2efd602SCy Schubert At this time it is only possible to set configuration before the first 289*b2efd602SCy Schubert resolve is done. 290*b2efd602SCy Schubert 291*b2efd602SCy Schubert ub_ctx_resolvconf 292*b2efd602SCy Schubert By default the root servers are queried and full resolver mode is used, 293*b2efd602SCy Schubert but you can use this call to read the list of nameservers to use from 294*b2efd602SCy Schubert the filename given. 295*b2efd602SCy Schubert Usually :file:`"/etc/resolv.conf"`. 296*b2efd602SCy Schubert Uses those nameservers as caching proxies. 297*b2efd602SCy Schubert If they do not support DNSSEC, validation may fail. 298*b2efd602SCy Schubert Only nameservers are picked up, the searchdomain, ndots and other 299*b2efd602SCy Schubert settings from *resolv.conf(5)* are ignored. 300*b2efd602SCy Schubert If fname NULL is passed, :file:`"/etc/resolv.conf"` is used (if on 301*b2efd602SCy Schubert Windows, the system-wide configured nameserver is picked instead). 302*b2efd602SCy Schubert At this time it is only possible to set configuration before the first 303*b2efd602SCy Schubert resolve is done. 304*b2efd602SCy Schubert 305*b2efd602SCy Schubert ub_ctx_hosts 306*b2efd602SCy Schubert Read list of hosts from the filename given. 307*b2efd602SCy Schubert Usually :file:`"/etc/hosts"`. 308*b2efd602SCy Schubert When queried for, these addresses are not marked DNSSEC secure. 309*b2efd602SCy Schubert If fname NULL is passed, :file:`"/etc/hosts"` is used (if on Windows, 310*b2efd602SCy Schubert :file:`etc/hosts` from WINDIR is picked instead). 311*b2efd602SCy Schubert At this time it is only possible to set configuration before the first 312*b2efd602SCy Schubert resolve is done. 313*b2efd602SCy Schubert 314*b2efd602SCy Schubert ub_ctx_add_ta 315*b2efd602SCy Schubert Add a trust anchor to the given context. 316*b2efd602SCy Schubert At this time it is only possible to add trusted keys before the first 317*b2efd602SCy Schubert resolve is done. 318*b2efd602SCy Schubert The format is a string, similar to the zone-file format, 319*b2efd602SCy Schubert **[domainname]** **[type]** **[rdata contents]**. 320*b2efd602SCy Schubert Both DS and DNSKEY records are accepted. 321*b2efd602SCy Schubert 322*b2efd602SCy Schubert ub_ctx_add_ta_autr 323*b2efd602SCy Schubert Add filename with automatically tracked trust anchor to the given 324*b2efd602SCy Schubert context. 325*b2efd602SCy Schubert Pass name of a file with the managed trust anchor. 326*b2efd602SCy Schubert You can create this file with 327*b2efd602SCy Schubert :doc:`unbound-anchor(8)</manpages/unbound-anchor>` for the root anchor. 328*b2efd602SCy Schubert You can also create it with an initial file with one line with a DNSKEY 329*b2efd602SCy Schubert or DS record. 330*b2efd602SCy Schubert If the file is writable, it is updated when the trust anchor changes. 331*b2efd602SCy Schubert At this time it is only possible to add trusted keys before the first 332*b2efd602SCy Schubert resolve is done. 333*b2efd602SCy Schubert 334*b2efd602SCy Schubert ub_ctx_add_ta_file 335*b2efd602SCy Schubert Add trust anchors to the given context. 336*b2efd602SCy Schubert Pass name of a file with DS and DNSKEY records in zone file format. 337*b2efd602SCy Schubert At this time it is only possible to add trusted keys before the first 338*b2efd602SCy Schubert resolve is done. 339*b2efd602SCy Schubert 340*b2efd602SCy Schubert ub_ctx_trustedkeys 341*b2efd602SCy Schubert Add trust anchors to the given context. 342*b2efd602SCy Schubert Pass the name of a bind-style config file with ``trusted-keys{}``. 343*b2efd602SCy Schubert At this time it is only possible to add trusted keys before the first 344*b2efd602SCy Schubert resolve is done. 345*b2efd602SCy Schubert 346*b2efd602SCy Schubert ub_ctx_debugout 347*b2efd602SCy Schubert Set debug and error log output to the given stream. 348*b2efd602SCy Schubert Pass NULL to disable output. 349*b2efd602SCy Schubert Default is stderr. 350*b2efd602SCy Schubert File-names or using syslog can be enabled using config options, this 351*b2efd602SCy Schubert routine is for using your own stream. 352*b2efd602SCy Schubert 353*b2efd602SCy Schubert ub_ctx_debuglevel 354*b2efd602SCy Schubert Set debug verbosity for the context. 355*b2efd602SCy Schubert Output is directed to stderr. 356*b2efd602SCy Schubert Higher debug level gives more output. 357*b2efd602SCy Schubert 358*b2efd602SCy Schubert ub_ctx_async 359*b2efd602SCy Schubert Set a context behaviour for asynchronous action. 360*b2efd602SCy Schubert if set to true, enables threading and a call to **ub_resolve_async** 361*b2efd602SCy Schubert creates a thread to handle work in the background. 362*b2efd602SCy Schubert If false, a process is forked to handle work in the background. 363*b2efd602SCy Schubert Changes to this setting after **ub_resolve_async** calls have been made 364*b2efd602SCy Schubert have no effect (delete and re-create the context to change). 365*b2efd602SCy Schubert 366*b2efd602SCy Schubert ub_poll 367*b2efd602SCy Schubert Poll a context to see if it has any new results. 368*b2efd602SCy Schubert Do not poll in a loop, instead extract the **fd** below to poll for 369*b2efd602SCy Schubert readiness, and then check, or wait using the wait routine. 370*b2efd602SCy Schubert Returns 0 if nothing to read, or nonzero if a result is available. 371*b2efd602SCy Schubert If nonzero, call **ub_process** to do callbacks. 372*b2efd602SCy Schubert 373*b2efd602SCy Schubert ub_wait 374*b2efd602SCy Schubert Wait for a context to finish with results. 375*b2efd602SCy Schubert Calls **ub_process** after the wait for you. 376*b2efd602SCy Schubert After the wait, there are no more outstanding asynchronous queries. 377*b2efd602SCy Schubert 378*b2efd602SCy Schubert ub_fd 379*b2efd602SCy Schubert Get file descriptor. 380*b2efd602SCy Schubert Wait for it to become readable, at this point answers are returned from 381*b2efd602SCy Schubert the asynchronous validating resolver. 382*b2efd602SCy Schubert Then call the **ub_process** to continue processing. 383*b2efd602SCy Schubert 384*b2efd602SCy Schubert ub_process 385*b2efd602SCy Schubert Call this routine to continue processing results from the validating 386*b2efd602SCy Schubert resolver (when the **fd** becomes readable). 387*b2efd602SCy Schubert Will perform necessary callbacks. 388*b2efd602SCy Schubert 389*b2efd602SCy Schubert ub_resolve 390*b2efd602SCy Schubert Perform resolution and validation of the target name. 391*b2efd602SCy Schubert The name is a domain name in a zero terminated text string. 392*b2efd602SCy Schubert The rrtype and rrclass are DNS type and class codes. 393*b2efd602SCy Schubert The result structure is newly allocated with the resulting data. 394*b2efd602SCy Schubert 395*b2efd602SCy Schubert ub_resolve_async 396*b2efd602SCy Schubert Perform asynchronous resolution and validation of the target name. 397*b2efd602SCy Schubert Arguments mean the same as for **ub_resolve** except no data is 398*b2efd602SCy Schubert returned immediately, instead a callback is called later. 399*b2efd602SCy Schubert The callback receives a copy of the mydata pointer, that you can use to 400*b2efd602SCy Schubert pass information to the callback. 401*b2efd602SCy Schubert The callback type is a function pointer to a function declared as: 402*b2efd602SCy Schubert 403*b2efd602SCy Schubert .. code-block:: c 404*b2efd602SCy Schubert 405*b2efd602SCy Schubert void my_callback_function(void* my_arg, int err, 406*b2efd602SCy Schubert struct ub_result* result); 407*b2efd602SCy Schubert 408*b2efd602SCy Schubert The **async_id** is returned so you can (at your option) decide to 409*b2efd602SCy Schubert track it and cancel the request if needed. 410*b2efd602SCy Schubert If you pass a NULL pointer the **async_id** is not returned. 411*b2efd602SCy Schubert 412*b2efd602SCy Schubert ub_cancel 413*b2efd602SCy Schubert Cancel an async query in progress. 414*b2efd602SCy Schubert This may return an error if the query does not exist, or the query is 415*b2efd602SCy Schubert already being delivered, in that case you may still get a callback for 416*b2efd602SCy Schubert the query. 417*b2efd602SCy Schubert 418*b2efd602SCy Schubert ub_resolve_free 419*b2efd602SCy Schubert Free struct **ub_result** contents after use. 420*b2efd602SCy Schubert 421*b2efd602SCy Schubert ub_strerror 422*b2efd602SCy Schubert Convert error value from one of the unbound library functions to a 423*b2efd602SCy Schubert human readable string. 424*b2efd602SCy Schubert 425*b2efd602SCy Schubert ub_ctx_print_local_zones 426*b2efd602SCy Schubert Debug printout the local authority information to debug output. 427*b2efd602SCy Schubert 428*b2efd602SCy Schubert ub_ctx_zone_add 429*b2efd602SCy Schubert Add new zone to local authority info, like local-zone 430*b2efd602SCy Schubert :doc:`unbound.conf(5)</manpages/unbound.conf>` statement. 431*b2efd602SCy Schubert 432*b2efd602SCy Schubert ub_ctx_zone_remove 433*b2efd602SCy Schubert Delete zone from local authority info. 434*b2efd602SCy Schubert 435*b2efd602SCy Schubert ub_ctx_data_add 436*b2efd602SCy Schubert Add resource record data to local authority info, like local-data 437*b2efd602SCy Schubert :doc:`unbound.conf(5)</manpages/unbound.conf>` statement. 438*b2efd602SCy Schubert 439*b2efd602SCy Schubert ub_ctx_data_remove 440*b2efd602SCy Schubert Delete local authority data from the name given. 441*b2efd602SCy Schubert 442*b2efd602SCy SchubertResult Data structure 443*b2efd602SCy Schubert--------------------- 444*b2efd602SCy Schubert 445*b2efd602SCy SchubertThe result of the DNS resolution and validation is returned as *struct 446*b2efd602SCy Schubertub_result*. 447*b2efd602SCy SchubertThe result structure contains the following entries: 448*b2efd602SCy Schubert 449*b2efd602SCy Schubert.. code-block:: c 450*b2efd602SCy Schubert 451*b2efd602SCy Schubert struct ub_result { 452*b2efd602SCy Schubert char* qname; /* text string, original question */ 453*b2efd602SCy Schubert int qtype; /* type code asked for */ 454*b2efd602SCy Schubert int qclass; /* class code asked for */ 455*b2efd602SCy Schubert char** data; /* array of rdata items, NULL terminated*/ 456*b2efd602SCy Schubert int* len; /* array with lengths of rdata items */ 457*b2efd602SCy Schubert char* canonname; /* canonical name of result */ 458*b2efd602SCy Schubert int rcode; /* additional error code in case of no data */ 459*b2efd602SCy Schubert void* answer_packet; /* full network format answer packet */ 460*b2efd602SCy Schubert int answer_len; /* length of packet in octets */ 461*b2efd602SCy Schubert int havedata; /* true if there is data */ 462*b2efd602SCy Schubert int nxdomain; /* true if nodata because name does not exist */ 463*b2efd602SCy Schubert int secure; /* true if result is secure */ 464*b2efd602SCy Schubert int bogus; /* true if a security failure happened */ 465*b2efd602SCy Schubert char* why_bogus; /* string with error if bogus */ 466*b2efd602SCy Schubert int was_ratelimited; /* true if the query was ratelimited (SERVFAIL) by unbound */ 467*b2efd602SCy Schubert int ttl; /* number of seconds the result is valid */ 468*b2efd602SCy Schubert }; 469*b2efd602SCy Schubert 470*b2efd602SCy SchubertIf both secure and bogus are false, security was not enabled for the domain of 471*b2efd602SCy Schubertthe query. 472*b2efd602SCy SchubertElse, they are not both true, one of them is true. 473*b2efd602SCy Schubert 474*b2efd602SCy SchubertReturn Values 475*b2efd602SCy Schubert------------- 476*b2efd602SCy Schubert 477*b2efd602SCy SchubertMany routines return an error code. 478*b2efd602SCy SchubertThe value 0 (zero) denotes no error happened. 479*b2efd602SCy SchubertOther values can be passed to **ub_strerror** to obtain a readable error 480*b2efd602SCy Schubertstring. 481*b2efd602SCy Schubert**ub_strerror** returns a zero terminated string. 482*b2efd602SCy Schubert**ub_ctx_create** returns NULL on an error (a malloc failure). 483*b2efd602SCy Schubert**ub_poll** returns true if some information may be available, false otherwise. 484*b2efd602SCy Schubert**ub_fd** returns a file descriptor or -1 on error. 485*b2efd602SCy Schubert**ub_ctx_config** and **ub_ctx_resolvconf** attempt to leave errno informative 486*b2efd602SCy Schuberton a function return with file read failure. 487*b2efd602SCy Schubert 488*b2efd602SCy SchubertSee Also 489*b2efd602SCy Schubert-------- 490*b2efd602SCy Schubert 491*b2efd602SCy Schubert:doc:`unbound.conf(5)</manpages/unbound.conf>`, :doc:`unbound(8)</manpages/unbound>`. 492