mirror of
https://github.com/NLnetLabs/unbound.git
synced 2025-12-20 23:00:56 -05:00
ub_
git-svn-id: file:///svn/unbound/trunk@942 be551aaa-1e26-0410-a405-d3ace91eadb9
This commit is contained in:
parent
8bde1c7cb3
commit
58c34b2dda
10 changed files with 262 additions and 263 deletions
|
|
@ -1,3 +1,6 @@
|
||||||
|
11 February 2008: Wouter
|
||||||
|
- changed library to use ub_ instead of ub_val_ as prefix.
|
||||||
|
|
||||||
8 February 2008: Wouter
|
8 February 2008: Wouter
|
||||||
- test program for multiple queries over a TCP channel.
|
- test program for multiple queries over a TCP channel.
|
||||||
- tpkg test for stream tcp queries.
|
- tpkg test for stream tcp queries.
|
||||||
|
|
|
||||||
166
doc/libunbound.3
166
doc/libunbound.3
|
|
@ -11,101 +11,97 @@
|
||||||
.LP
|
.LP
|
||||||
.B libunbound,
|
.B libunbound,
|
||||||
.B unbound.h,
|
.B unbound.h,
|
||||||
.B ub_val_ctx,
|
.B ub_ctx,
|
||||||
.B ub_val_result,
|
.B ub_result,
|
||||||
.B ub_val_callback_t,
|
.B ub_callback_t,
|
||||||
.B ub_val_ctx_create,
|
.B ub_ctx_create,
|
||||||
.B ub_val_ctx_delete,
|
.B ub_ctx_delete,
|
||||||
.B ub_val_ctx_config,
|
.B ub_ctx_config,
|
||||||
.B ub_val_ctx_set_fwd,
|
.B ub_ctx_set_fwd,
|
||||||
.B ub_val_ctx_resolvconf,
|
.B ub_ctx_resolvconf,
|
||||||
.B ub_val_ctx_add_ta,
|
.B ub_ctx_add_ta,
|
||||||
.B ub_val_ctx_add_ta_file,
|
.B ub_ctx_add_ta_file,
|
||||||
.B ub_val_ctx_trustedkeys,
|
.B ub_ctx_trustedkeys,
|
||||||
.B ub_val_ctx_debuglevel,
|
.B ub_ctx_debuglevel,
|
||||||
.B ub_val_ctx_async,
|
.B ub_ctx_async,
|
||||||
.B ub_val_poll,
|
.B ub_poll,
|
||||||
.B ub_val_wait,
|
.B ub_wait,
|
||||||
.B ub_val_fd,
|
.B ub_fd,
|
||||||
.B ub_val_process,
|
.B ub_process,
|
||||||
.B ub_val_resolve,
|
.B ub_resolve,
|
||||||
.B ub_val_resolve_async,
|
.B ub_resolve_async,
|
||||||
.B ub_val_cancel,
|
.B ub_cancel,
|
||||||
.B ub_val_resolve_free,
|
.B ub_resolve_free,
|
||||||
.B ub_val_strerror
|
.B ub_strerror
|
||||||
\- Unbound DNS validating resolver @version@ functions.
|
\- Unbound DNS validating resolver @version@ functions.
|
||||||
.SH "SYNOPSIS"
|
.SH "SYNOPSIS"
|
||||||
.LP
|
.LP
|
||||||
.B #include <unbound.h>
|
.B #include <unbound.h>
|
||||||
.LP
|
.LP
|
||||||
\fIstruct ub_val_ctx *\fR
|
\fIstruct ub_ctx *\fR
|
||||||
\fBub_val_ctx_create\fR(\fIvoid\fR);
|
\fBub_ctx_create\fR(\fIvoid\fR);
|
||||||
.LP
|
.LP
|
||||||
\fIvoid\fR
|
\fIvoid\fR
|
||||||
\fBub_val_ctx_delete\fR(\fIstruct ub_val_ctx*\fR ctx);
|
\fBub_ctx_delete\fR(\fIstruct ub_ctx*\fR ctx);
|
||||||
.LP
|
.LP
|
||||||
\fIint\fR
|
\fIint\fR
|
||||||
\fBub_val_ctx_config\fR(\fIstruct ub_val_ctx*\fR ctx, \fIchar*\fR fname);
|
\fBub_ctx_config\fR(\fIstruct ub_ctx*\fR ctx, \fIchar*\fR fname);
|
||||||
.LP
|
.LP
|
||||||
\fIint\fR
|
\fIint\fR
|
||||||
\fBub_val_ctx_set_fwd\fR(\fIstruct ub_val_ctx*\fR ctx, \fIchar*\fR addr);
|
\fBub_ctx_set_fwd\fR(\fIstruct ub_ctx*\fR ctx, \fIchar*\fR addr);
|
||||||
.LP
|
.LP
|
||||||
\fIint\fR
|
\fIint\fR
|
||||||
\fBub_val_ctx_resolvconf\fR(\fIstruct ub_val_ctx*\fR ctx, \fIchar*\fR fname);
|
\fBub_ctx_resolvconf\fR(\fIstruct ub_ctx*\fR ctx, \fIchar*\fR fname);
|
||||||
.LP
|
.LP
|
||||||
\fIint\fR
|
\fIint\fR
|
||||||
\fBub_val_ctx_add_ta\fR(\fIstruct ub_val_ctx*\fR ctx, \fIchar*\fR ta);
|
\fBub_ctx_add_ta\fR(\fIstruct ub_ctx*\fR ctx, \fIchar*\fR ta);
|
||||||
.LP
|
.LP
|
||||||
\fIint\fR
|
\fIint\fR
|
||||||
\fBub_val_ctx_add_ta_file\fR(\fIstruct ub_val_ctx*\fR ctx,
|
\fBub_ctx_add_ta_file\fR(\fIstruct ub_ctx*\fR ctx, \fIchar*\fR fname);
|
||||||
.br
|
|
||||||
\fIchar*\fR fname);
|
|
||||||
.LP
|
.LP
|
||||||
\fIint\fR
|
\fIint\fR
|
||||||
\fBub_val_ctx_trustedkeys\fR(\fIstruct ub_val_ctx*\fR ctx,
|
\fBub_ctx_trustedkeys\fR(\fIstruct ub_ctx*\fR ctx, \fIchar*\fR fname);
|
||||||
.br
|
|
||||||
\fIchar*\fR fname);
|
|
||||||
.LP
|
.LP
|
||||||
\fIint\fR
|
\fIint\fR
|
||||||
\fBub_val_ctx_debuglevel\fR(\fIstruct ub_val_ctx*\fR ctx, \fIint\fR d);
|
\fBub_ctx_debuglevel\fR(\fIstruct ub_ctx*\fR ctx, \fIint\fR d);
|
||||||
.LP
|
.LP
|
||||||
\fIint\fR
|
\fIint\fR
|
||||||
\fBub_val_ctx_async\fR(\fIstruct ub_val_ctx*\fR ctx, \fIint\fR dothread);
|
\fBub_ctx_async\fR(\fIstruct ub_ctx*\fR ctx, \fIint\fR dothread);
|
||||||
.LP
|
.LP
|
||||||
\fIint\fR
|
\fIint\fR
|
||||||
\fBub_val_poll\fR(\fIstruct ub_val_ctx*\fR ctx);
|
\fBub_poll\fR(\fIstruct ub_ctx*\fR ctx);
|
||||||
.LP
|
.LP
|
||||||
\fIint\fR
|
\fIint\fR
|
||||||
\fBub_val_wait\fR(\fIstruct ub_val_ctx*\fR ctx);
|
\fBub_wait\fR(\fIstruct ub_ctx*\fR ctx);
|
||||||
.LP
|
.LP
|
||||||
\fIint\fR
|
\fIint\fR
|
||||||
\fBub_val_fd\fR(\fIstruct ub_val_ctx*\fR ctx);
|
\fBub_fd\fR(\fIstruct ub_ctx*\fR ctx);
|
||||||
.LP
|
.LP
|
||||||
\fIint\fR
|
\fIint\fR
|
||||||
\fBub_val_process\fR(\fIstruct ub_val_ctx*\fR ctx);
|
\fBub_process\fR(\fIstruct ub_ctx*\fR ctx);
|
||||||
.LP
|
.LP
|
||||||
\fIint\fR
|
\fIint\fR
|
||||||
\fBub_val_resolve\fR(\fIstruct ub_val_ctx*\fR ctx, \fIchar*\fR name,
|
\fBub_resolve\fR(\fIstruct ub_ctx*\fR ctx, \fIchar*\fR name,
|
||||||
.br
|
.br
|
||||||
\fIint\fR rrtype, \fIint\fR rrclass, \fIint*\fR secure,
|
\fIint\fR rrtype, \fIint\fR rrclass, \fIint*\fR secure,
|
||||||
.br
|
.br
|
||||||
\fIint*\fR data, \fIstruct ub_val_result**\fR result);
|
\fIint*\fR data, \fIstruct ub_result**\fR result);
|
||||||
.LP
|
.LP
|
||||||
\fIint\fR
|
\fIint\fR
|
||||||
\fBub_val_resolve_async\fR(\fIstruct ub_val_ctx*\fR ctx, \fIchar*\fR name,
|
\fBub_resolve_async\fR(\fIstruct ub_ctx*\fR ctx, \fIchar*\fR name,
|
||||||
.br
|
.br
|
||||||
\fIint\fR rrtype, \fIint\fR rrclass, \fIvoid*\fR mydata,
|
\fIint\fR rrtype, \fIint\fR rrclass, \fIvoid*\fR mydata,
|
||||||
.br
|
.br
|
||||||
\fIub_val_callback_t\fR callback, \fIint*\fR async_id);
|
\fIub_callback_t\fR callback, \fIint*\fR async_id);
|
||||||
.LP
|
.LP
|
||||||
\fIint\fR
|
\fIint\fR
|
||||||
\fBub_val_cancel\fR(\fIstruct ub_val_ctx*\fR ctx, \fIint\fR async_id);
|
\fBub_cancel\fR(\fIstruct ub_ctx*\fR ctx, \fIint\fR async_id);
|
||||||
.LP
|
.LP
|
||||||
\fIvoid\fR
|
\fIvoid\fR
|
||||||
\fBub_val_resolve_free\fR(\fIstruct ub_val_result*\fR result);
|
\fBub_resolve_free\fR(\fIstruct ub_result*\fR result);
|
||||||
.LP
|
.LP
|
||||||
\fIconst char *\fR
|
\fIconst char *\fR
|
||||||
\fBub_val_strerror\fR(\fIint\fR err);
|
\fBub_strerror\fR(\fIint\fR err);
|
||||||
.SH "DESCRIPTION"
|
.SH "DESCRIPTION"
|
||||||
.LP
|
.LP
|
||||||
.B Unbound
|
.B Unbound
|
||||||
|
|
@ -116,11 +112,11 @@ The library can be used to convert hostnames to ip addresses, and back,
|
||||||
and obtain other information from the DNS. The library performs public\-key
|
and obtain other information from the DNS. The library performs public\-key
|
||||||
validation of results with DNSSEC.
|
validation of results with DNSSEC.
|
||||||
.P
|
.P
|
||||||
The library uses a variable of type \fIstruct ub_val_ctx\fR to keep context
|
The library uses a variable of type \fIstruct ub_ctx\fR to keep context
|
||||||
between calls. The user must maintain it, creating it with
|
between calls. The user must maintain it, creating it with
|
||||||
.B ub_val_ctx_create
|
.B ub_ctx_create
|
||||||
and deleting it with
|
and deleting it with
|
||||||
.B ub_val_ctx_delete\fR.
|
.B ub_ctx_delete\fR.
|
||||||
It can be created and deleted at any time. Creating it anew removes any
|
It can be created and deleted at any time. Creating it anew removes any
|
||||||
previous configuration (such as trusted keys) and clears any cached results.
|
previous configuration (such as trusted keys) and clears any cached results.
|
||||||
.P
|
.P
|
||||||
|
|
@ -133,20 +129,20 @@ can go on, while the results become available later.
|
||||||
The functions are discussed in turn below.
|
The functions are discussed in turn below.
|
||||||
.SH "FUNCTIONS"
|
.SH "FUNCTIONS"
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_ctx_create
|
.B ub_ctx_create
|
||||||
Create a new context, initialised with defaults.
|
Create a new context, initialised with defaults.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_ctx_delete
|
.B ub_ctx_delete
|
||||||
Delete validation context and free associated resources.
|
Delete validation context and free associated resources.
|
||||||
Outstanding async queries are killed and callbacks are not called for them.
|
Outstanding async queries are killed and callbacks are not called for them.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_ctx_config
|
.B ub_ctx_config
|
||||||
A power\-user interface that lets you specify an unbound config file, see
|
A power\-user interface that lets you specify an unbound config file, see
|
||||||
\fIunbound.conf\fR(5), which is read for configuration. Not all options are
|
\fIunbound.conf\fR(5), which is read for configuration. Not all options are
|
||||||
relevant. For some specific options, such as adding trust anchors, special
|
relevant. For some specific options, such as adding trust anchors, special
|
||||||
routines exist.
|
routines exist.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_ctx_set_fwd
|
.B ub_ctx_set_fwd
|
||||||
Set machine to forward DNS queries to, the caching resolver to use.
|
Set machine to forward DNS queries to, the caching resolver to use.
|
||||||
IP4 or IP6 address. Forwards all DNS requests to that machine, which
|
IP4 or IP6 address. Forwards all DNS requests to that machine, which
|
||||||
is expected to run a recursive resolver. If the proxy is not
|
is expected to run a recursive resolver. If the proxy is not
|
||||||
|
|
@ -155,7 +151,7 @@ that case the addresses are used as backup servers.
|
||||||
At this time it is only possible to set configuration before the
|
At this time it is only possible to set configuration before the
|
||||||
first resolve is done.
|
first resolve is done.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_ctx_resolvconf
|
.B ub_ctx_resolvconf
|
||||||
Read list of nameservers to use from the filename given.
|
Read list of nameservers to use from the filename given.
|
||||||
Usually "/etc/resolv.conf". Uses those nameservers as caching proxies.
|
Usually "/etc/resolv.conf". Uses those nameservers as caching proxies.
|
||||||
If they do not support DNSSEC, validation may fail.
|
If they do not support DNSSEC, validation may fail.
|
||||||
|
|
@ -166,66 +162,66 @@ At this time it is only possible to set configuration before the
|
||||||
first resolve is done.
|
first resolve is done.
|
||||||
.TP
|
.TP
|
||||||
.B
|
.B
|
||||||
ub_val_ctx_add_ta
|
ub_ctx_add_ta
|
||||||
Add a trust anchor to the given context.
|
Add a trust anchor to the given context.
|
||||||
At this time it is only possible to add trusted keys before the
|
At this time it is only possible to add trusted keys before the
|
||||||
first resolve is done.
|
first resolve is done.
|
||||||
The format is a string, similar to the zone-file format,
|
The format is a string, similar to the zone-file format,
|
||||||
[domainname] [type] [rdata contents]. Both DS and DNSKEY records are accepted.
|
[domainname] [type] [rdata contents]. Both DS and DNSKEY records are accepted.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_ctx_add_ta_file
|
.B ub_ctx_add_ta_file
|
||||||
Add trust anchors to the given context.
|
Add trust anchors to the given context.
|
||||||
Pass name of a file with DS and DNSKEY records in zone file format.
|
Pass name of a file with DS and DNSKEY records in zone file format.
|
||||||
At this time it is only possible to add trusted keys before the
|
At this time it is only possible to add trusted keys before the
|
||||||
first resolve is done.
|
first resolve is done.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_ctx_trustedkeys
|
.B ub_ctx_trustedkeys
|
||||||
Add trust anchors to the given context.
|
Add trust anchors to the given context.
|
||||||
Pass the name of a bind-style config file with trusted-keys{}.
|
Pass the name of a bind-style config file with trusted-keys{}.
|
||||||
At this time it is only possible to add trusted keys before the
|
At this time it is only possible to add trusted keys before the
|
||||||
first resolve is done.
|
first resolve is done.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_ctx_debuglevel
|
.B ub_ctx_debuglevel
|
||||||
Set debug verbosity for the context. Output is directed to stderr.
|
Set debug verbosity for the context. Output is directed to stderr.
|
||||||
Higher debug level gives more output.
|
Higher debug level gives more output.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_ctx_async
|
.B ub_ctx_async
|
||||||
Set a context behaviour for asynchronous action.
|
Set a context behaviour for asynchronous action.
|
||||||
if set to true, enables threading and a call to
|
if set to true, enables threading and a call to
|
||||||
.B ub_val_resolve_async
|
.B ub_resolve_async
|
||||||
creates a thread to handle work in the background.
|
creates a thread to handle work in the background.
|
||||||
If false, a process is forked to handle work in the background.
|
If false, a process is forked to handle work in the background.
|
||||||
Changes to this setting after
|
Changes to this setting after
|
||||||
.B ub_val_resolve_async
|
.B ub_resolve_async
|
||||||
calls have been made have no effect (delete and re\-create the context
|
calls have been made have no effect (delete and re\-create the context
|
||||||
to change).
|
to change).
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_poll
|
.B ub_poll
|
||||||
Poll a context to see if it has any new results.
|
Poll a context to see if it has any new results.
|
||||||
Do not poll in a loop, instead extract the fd below to poll for readiness,
|
Do not poll in a loop, instead extract the fd below to poll for readiness,
|
||||||
and then check, or wait using the wait routine.
|
and then check, or wait using the wait routine.
|
||||||
Returns 0 if nothing to read, or nonzero if a result is available.
|
Returns 0 if nothing to read, or nonzero if a result is available.
|
||||||
If nonzero, call
|
If nonzero, call
|
||||||
.B ub_val_process
|
.B ub_process
|
||||||
to do callbacks.
|
to do callbacks.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_wait
|
.B ub_wait
|
||||||
Wait for a context to finish with results. Calls
|
Wait for a context to finish with results. Calls
|
||||||
.B ub_val_process
|
.B ub_process
|
||||||
after the wait for you. After the wait, there are no more outstanding
|
after the wait for you. After the wait, there are no more outstanding
|
||||||
asynchronous queries.
|
asynchronous queries.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_fd
|
.B ub_fd
|
||||||
Get file descriptor. Wait for it to become readable, at this point
|
Get file descriptor. Wait for it to become readable, at this point
|
||||||
answers are returned from the asynchronous validating resolver.
|
answers are returned from the asynchronous validating resolver.
|
||||||
Then call the \fBub_val_process\fR to continue processing.
|
Then call the \fBub_process\fR to continue processing.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_process
|
.B ub_process
|
||||||
Call this routine to continue processing results from the validating
|
Call this routine to continue processing results from the validating
|
||||||
resolver (when the fd becomes readable).
|
resolver (when the fd becomes readable).
|
||||||
Will perform necessary callbacks.
|
Will perform necessary callbacks.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_resolve
|
.B ub_resolve
|
||||||
Perform resolution and validation of the target name.
|
Perform resolution and validation of the target name.
|
||||||
The name is a domain name in a zero terminated text string.
|
The name is a domain name in a zero terminated text string.
|
||||||
The rrtype and rrclass are DNS type and class codes.
|
The rrtype and rrclass are DNS type and class codes.
|
||||||
|
|
@ -233,9 +229,9 @@ The value secure returns true if the answer validated securely.
|
||||||
The value data returns true if there was data.
|
The value data returns true if there was data.
|
||||||
The result structure is newly allocated with the resulting data.
|
The result structure is newly allocated with the resulting data.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_resolve_async
|
.B ub_resolve_async
|
||||||
Perform asynchronous resolution and validation of the target name.
|
Perform asynchronous resolution and validation of the target name.
|
||||||
Arguments mean the same as for \fBub_val_resolve\fR except no
|
Arguments mean the same as for \fBub_resolve\fR except no
|
||||||
data is returned immediately, instead a callback is called later.
|
data is returned immediately, instead a callback is called later.
|
||||||
The callback receives a copy of the mydata pointer, that you can use to pass
|
The callback receives a copy of the mydata pointer, that you can use to pass
|
||||||
information to the callback. The callback type is a function pointer to
|
information to the callback. The callback type is a function pointer to
|
||||||
|
|
@ -243,27 +239,27 @@ a function declared as
|
||||||
.IP
|
.IP
|
||||||
void my_callback_function(void* my_arg, int err,
|
void my_callback_function(void* my_arg, int err,
|
||||||
.br
|
.br
|
||||||
struct ub_val_result* result);
|
struct ub_result* result);
|
||||||
.IP
|
.IP
|
||||||
The async_id is returned so you can (at your option) decide to track it
|
The async_id is returned so you can (at your option) decide to track it
|
||||||
and cancel the request if needed.
|
and cancel the request if needed.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_cancel
|
.B ub_cancel
|
||||||
Cancel an async query in progress.
|
Cancel an async query in progress.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_resolve_free
|
.B ub_resolve_free
|
||||||
Free struct ub_val_result contents after use.
|
Free struct ub_result contents after use.
|
||||||
.TP
|
.TP
|
||||||
.B ub_val_strerror
|
.B ub_strerror
|
||||||
Convert error value from one of the unbound library functions
|
Convert error value from one of the unbound library functions
|
||||||
to a human readable string.
|
to a human readable string.
|
||||||
.SH "RESULT DATA STRUCTURE"
|
.SH "RESULT DATA STRUCTURE"
|
||||||
.LP
|
.LP
|
||||||
The result of the DNS resolution and validation is returned as
|
The result of the DNS resolution and validation is returned as
|
||||||
\fIstruct ub_val_result\fR. The result structure contains the following entries.
|
\fIstruct ub_result\fR. The result structure contains the following entries.
|
||||||
.P
|
.P
|
||||||
.nf
|
.nf
|
||||||
struct ub_val_result {
|
struct ub_result {
|
||||||
char* qname; /* text string, original question */
|
char* qname; /* text string, original question */
|
||||||
int qtype; /* type code asked for */
|
int qtype; /* type code asked for */
|
||||||
int qclass; /* class code asked for */
|
int qclass; /* class code asked for */
|
||||||
|
|
@ -283,15 +279,15 @@ domain of the query.
|
||||||
.SH "RETURN VALUES"
|
.SH "RETURN VALUES"
|
||||||
Many routines return an error code. The value 0 (zero) denotes no error
|
Many routines return an error code. The value 0 (zero) denotes no error
|
||||||
happened. Other values can be passed to
|
happened. Other values can be passed to
|
||||||
.B ub_val_strerror
|
.B ub_strerror
|
||||||
to obtain a readable error string.
|
to obtain a readable error string.
|
||||||
.B ub_val_strerror
|
.B ub_strerror
|
||||||
returns a zero terminated string.
|
returns a zero terminated string.
|
||||||
.B ub_val_ctx_create
|
.B ub_ctx_create
|
||||||
returns NULL on an error (a malloc failure).
|
returns NULL on an error (a malloc failure).
|
||||||
.B ub_val_poll
|
.B ub_poll
|
||||||
returns true if some information may be available, false otherwise.
|
returns true if some information may be available, false otherwise.
|
||||||
.B ub_val_fd
|
.B ub_fd
|
||||||
returns a file descriptor or -1 on error.
|
returns a file descriptor or -1 on error.
|
||||||
.SH "SEE ALSO"
|
.SH "SEE ALSO"
|
||||||
\fIunbound.conf\fR(5),
|
\fIunbound.conf\fR(5),
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@
|
||||||
#include "util/storage/slabhash.h"
|
#include "util/storage/slabhash.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
context_finalize(struct ub_val_ctx* ctx)
|
context_finalize(struct ub_ctx* ctx)
|
||||||
{
|
{
|
||||||
struct config_file* cfg = ctx->env->cfg;
|
struct config_file* cfg = ctx->env->cfg;
|
||||||
verbosity = cfg->verbosity;
|
verbosity = cfg->verbosity;
|
||||||
|
|
@ -99,7 +99,7 @@ void
|
||||||
context_query_delete(struct ctx_query* q)
|
context_query_delete(struct ctx_query* q)
|
||||||
{
|
{
|
||||||
if(!q) return;
|
if(!q) return;
|
||||||
ub_val_resolve_free(q->res);
|
ub_resolve_free(q->res);
|
||||||
free(q->msg);
|
free(q->msg);
|
||||||
free(q);
|
free(q);
|
||||||
}
|
}
|
||||||
|
|
@ -108,7 +108,7 @@ context_query_delete(struct ctx_query* q)
|
||||||
#define NUM_ID_TRIES 100000
|
#define NUM_ID_TRIES 100000
|
||||||
/** find next useful id number of 0 on error */
|
/** find next useful id number of 0 on error */
|
||||||
static int
|
static int
|
||||||
find_id(struct ub_val_ctx* ctx, int* id)
|
find_id(struct ub_ctx* ctx, int* id)
|
||||||
{
|
{
|
||||||
size_t tries = 0;
|
size_t tries = 0;
|
||||||
ctx->next_querynum++;
|
ctx->next_querynum++;
|
||||||
|
|
@ -122,8 +122,8 @@ find_id(struct ub_val_ctx* ctx, int* id)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ctx_query*
|
struct ctx_query*
|
||||||
context_new(struct ub_val_ctx* ctx, char* name, int rrtype, int rrclass,
|
context_new(struct ub_ctx* ctx, char* name, int rrtype, int rrclass,
|
||||||
ub_val_callback_t cb, void* cbarg)
|
ub_callback_t cb, void* cbarg)
|
||||||
{
|
{
|
||||||
struct ctx_query* q = (struct ctx_query*)calloc(1, sizeof(*q));
|
struct ctx_query* q = (struct ctx_query*)calloc(1, sizeof(*q));
|
||||||
if(!q) return NULL;
|
if(!q) return NULL;
|
||||||
|
|
@ -138,7 +138,7 @@ context_new(struct ub_val_ctx* ctx, char* name, int rrtype, int rrclass,
|
||||||
q->async = (cb != NULL);
|
q->async = (cb != NULL);
|
||||||
q->cb = cb;
|
q->cb = cb;
|
||||||
q->cb_arg = cbarg;
|
q->cb_arg = cbarg;
|
||||||
q->res = (struct ub_val_result*)calloc(1, sizeof(*q->res));
|
q->res = (struct ub_result*)calloc(1, sizeof(*q->res));
|
||||||
if(!q->res) {
|
if(!q->res) {
|
||||||
free(q);
|
free(q);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -162,7 +162,7 @@ context_new(struct ub_val_ctx* ctx, char* name, int rrtype, int rrclass,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct alloc_cache*
|
struct alloc_cache*
|
||||||
context_obtain_alloc(struct ub_val_ctx* ctx, int locking)
|
context_obtain_alloc(struct ub_ctx* ctx, int locking)
|
||||||
{
|
{
|
||||||
struct alloc_cache* a;
|
struct alloc_cache* a;
|
||||||
int tnum = 0;
|
int tnum = 0;
|
||||||
|
|
@ -188,7 +188,7 @@ context_obtain_alloc(struct ub_val_ctx* ctx, int locking)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
context_release_alloc(struct ub_val_ctx* ctx, struct alloc_cache* alloc,
|
context_release_alloc(struct ub_ctx* ctx, struct alloc_cache* alloc,
|
||||||
int locking)
|
int locking)
|
||||||
{
|
{
|
||||||
if(!ctx || !alloc)
|
if(!ctx || !alloc)
|
||||||
|
|
@ -227,7 +227,7 @@ context_serialize_new_query(struct ctx_query* q, uint32_t* len)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ctx_query*
|
struct ctx_query*
|
||||||
context_deserialize_new_query(struct ub_val_ctx* ctx, uint8_t* p, uint32_t len)
|
context_deserialize_new_query(struct ub_ctx* ctx, uint8_t* p, uint32_t len)
|
||||||
{
|
{
|
||||||
struct ctx_query* q = (struct ctx_query*)calloc(1, sizeof(*q));
|
struct ctx_query* q = (struct ctx_query*)calloc(1, sizeof(*q));
|
||||||
if(!q) return NULL;
|
if(!q) return NULL;
|
||||||
|
|
@ -239,7 +239,7 @@ context_deserialize_new_query(struct ub_val_ctx* ctx, uint8_t* p, uint32_t len)
|
||||||
q->querynum = (int)ldns_read_uint32(p+sizeof(uint32_t));
|
q->querynum = (int)ldns_read_uint32(p+sizeof(uint32_t));
|
||||||
q->node.key = &q->querynum;
|
q->node.key = &q->querynum;
|
||||||
q->async = 1;
|
q->async = 1;
|
||||||
q->res = (struct ub_val_result*)calloc(1, sizeof(*q->res));
|
q->res = (struct ub_result*)calloc(1, sizeof(*q->res));
|
||||||
if(!q->res) {
|
if(!q->res) {
|
||||||
free(q);
|
free(q);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -260,7 +260,7 @@ context_deserialize_new_query(struct ub_val_ctx* ctx, uint8_t* p, uint32_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ctx_query*
|
struct ctx_query*
|
||||||
context_lookup_new_query(struct ub_val_ctx* ctx, uint8_t* p, uint32_t len)
|
context_lookup_new_query(struct ub_ctx* ctx, uint8_t* p, uint32_t len)
|
||||||
{
|
{
|
||||||
struct ctx_query* q;
|
struct ctx_query* q;
|
||||||
int querynum;
|
int querynum;
|
||||||
|
|
@ -304,7 +304,7 @@ context_serialize_answer(struct ctx_query* q, int err, ldns_buffer* pkt,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ctx_query*
|
struct ctx_query*
|
||||||
context_deserialize_answer(struct ub_val_ctx* ctx,
|
context_deserialize_answer(struct ub_ctx* ctx,
|
||||||
uint8_t* p, uint32_t len, int* err)
|
uint8_t* p, uint32_t len, int* err)
|
||||||
{
|
{
|
||||||
struct ctx_query* q = NULL ;
|
struct ctx_query* q = NULL ;
|
||||||
|
|
@ -343,7 +343,7 @@ context_serialize_cancel(struct ctx_query* q, uint32_t* len)
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ctx_query* context_deserialize_cancel(struct ub_val_ctx* ctx,
|
struct ctx_query* context_deserialize_cancel(struct ub_ctx* ctx,
|
||||||
uint8_t* p, uint32_t len)
|
uint8_t* p, uint32_t len)
|
||||||
{
|
{
|
||||||
struct ctx_query* q;
|
struct ctx_query* q;
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ struct libworker;
|
||||||
* qq : write queries to the async service pid/tid.
|
* qq : write queries to the async service pid/tid.
|
||||||
* rr : read results from the async service pid/tid.
|
* rr : read results from the async service pid/tid.
|
||||||
*/
|
*/
|
||||||
struct ub_val_ctx {
|
struct ub_ctx {
|
||||||
/* --- pipes --- */
|
/* --- pipes --- */
|
||||||
/** mutex on query write pipe */
|
/** mutex on query write pipe */
|
||||||
lock_basic_t qqpipe_lock;
|
lock_basic_t qqpipe_lock;
|
||||||
|
|
@ -137,7 +137,7 @@ struct ctx_query {
|
||||||
int cancelled;
|
int cancelled;
|
||||||
|
|
||||||
/** for async query, the callback function */
|
/** for async query, the callback function */
|
||||||
ub_val_callback_t cb;
|
ub_callback_t cb;
|
||||||
/** for async query, the callback user arg */
|
/** for async query, the callback user arg */
|
||||||
void* cb_arg;
|
void* cb_arg;
|
||||||
|
|
||||||
|
|
@ -152,7 +152,7 @@ struct ctx_query {
|
||||||
|
|
||||||
/** result structure, also contains original query, type, class.
|
/** result structure, also contains original query, type, class.
|
||||||
* malloced ptr ready to hand to the client. */
|
* malloced ptr ready to hand to the client. */
|
||||||
struct ub_val_result* res;
|
struct ub_result* res;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -206,7 +206,7 @@ enum ub_ctx_cmd {
|
||||||
* @param ctx: context to finalize. creates shared data.
|
* @param ctx: context to finalize. creates shared data.
|
||||||
* @return 0 if OK, or errcode.
|
* @return 0 if OK, or errcode.
|
||||||
*/
|
*/
|
||||||
int context_finalize(struct ub_val_ctx* ctx);
|
int context_finalize(struct ub_ctx* ctx);
|
||||||
|
|
||||||
/** compare two ctx_query elements */
|
/** compare two ctx_query elements */
|
||||||
int context_query_cmp(const void* a, const void* b);
|
int context_query_cmp(const void* a, const void* b);
|
||||||
|
|
@ -227,8 +227,8 @@ void context_query_delete(struct ctx_query* q);
|
||||||
* @param cbarg: user arg for async queries.
|
* @param cbarg: user arg for async queries.
|
||||||
* @return new ctx_query or NULL for malloc failure.
|
* @return new ctx_query or NULL for malloc failure.
|
||||||
*/
|
*/
|
||||||
struct ctx_query* context_new(struct ub_val_ctx* ctx, char* name, int rrtype,
|
struct ctx_query* context_new(struct ub_ctx* ctx, char* name, int rrtype,
|
||||||
int rrclass, ub_val_callback_t cb, void* cbarg);
|
int rrclass, ub_callback_t cb, void* cbarg);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a new alloc. Creates a new one or uses a cached one.
|
* Get a new alloc. Creates a new one or uses a cached one.
|
||||||
|
|
@ -236,7 +236,7 @@ struct ctx_query* context_new(struct ub_val_ctx* ctx, char* name, int rrtype,
|
||||||
* @param locking: if true, cfglock is locked while getting alloc.
|
* @param locking: if true, cfglock is locked while getting alloc.
|
||||||
* @return an alloc, or NULL on mem error.
|
* @return an alloc, or NULL on mem error.
|
||||||
*/
|
*/
|
||||||
struct alloc_cache* context_obtain_alloc(struct ub_val_ctx* ctx, int locking);
|
struct alloc_cache* context_obtain_alloc(struct ub_ctx* ctx, int locking);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Release an alloc. Puts it into the cache.
|
* Release an alloc. Puts it into the cache.
|
||||||
|
|
@ -244,7 +244,7 @@ struct alloc_cache* context_obtain_alloc(struct ub_val_ctx* ctx, int locking);
|
||||||
* @param locking: if true, cfglock is locked while releasing alloc.
|
* @param locking: if true, cfglock is locked while releasing alloc.
|
||||||
* @param alloc: alloc to relinquish.
|
* @param alloc: alloc to relinquish.
|
||||||
*/
|
*/
|
||||||
void context_release_alloc(struct ub_val_ctx* ctx, struct alloc_cache* alloc,
|
void context_release_alloc(struct ub_ctx* ctx, struct alloc_cache* alloc,
|
||||||
int locking);
|
int locking);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -301,7 +301,7 @@ enum ub_ctx_cmd context_serial_getcmd(uint8_t* p, uint32_t len);
|
||||||
* @param len: length of buffer.
|
* @param len: length of buffer.
|
||||||
* @return looked up ctx_query or NULL for malloc failure.
|
* @return looked up ctx_query or NULL for malloc failure.
|
||||||
*/
|
*/
|
||||||
struct ctx_query* context_lookup_new_query(struct ub_val_ctx* ctx,
|
struct ctx_query* context_lookup_new_query(struct ub_ctx* ctx,
|
||||||
uint8_t* p, uint32_t len);
|
uint8_t* p, uint32_t len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -311,7 +311,7 @@ struct ctx_query* context_lookup_new_query(struct ub_val_ctx* ctx,
|
||||||
* @param len: length of buffer.
|
* @param len: length of buffer.
|
||||||
* @return new ctx_query or NULL for malloc failure.
|
* @return new ctx_query or NULL for malloc failure.
|
||||||
*/
|
*/
|
||||||
struct ctx_query* context_deserialize_new_query(struct ub_val_ctx* ctx,
|
struct ctx_query* context_deserialize_new_query(struct ub_ctx* ctx,
|
||||||
uint8_t* p, uint32_t len);
|
uint8_t* p, uint32_t len);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -322,7 +322,7 @@ struct ctx_query* context_deserialize_new_query(struct ub_val_ctx* ctx,
|
||||||
* @param err: error code to be returned to client is passed.
|
* @param err: error code to be returned to client is passed.
|
||||||
* @return ctx_query with answer added or NULL for malloc failure.
|
* @return ctx_query with answer added or NULL for malloc failure.
|
||||||
*/
|
*/
|
||||||
struct ctx_query* context_deserialize_answer(struct ub_val_ctx* ctx,
|
struct ctx_query* context_deserialize_answer(struct ub_ctx* ctx,
|
||||||
uint8_t* p, uint32_t len, int* err);
|
uint8_t* p, uint32_t len, int* err);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -332,7 +332,7 @@ struct ctx_query* context_deserialize_answer(struct ub_val_ctx* ctx,
|
||||||
* @param len: length of buffer.
|
* @param len: length of buffer.
|
||||||
* @return ctx_query to cancel or NULL for failure.
|
* @return ctx_query to cancel or NULL for failure.
|
||||||
*/
|
*/
|
||||||
struct ctx_query* context_deserialize_cancel(struct ub_val_ctx* ctx,
|
struct ctx_query* context_deserialize_cancel(struct ub_ctx* ctx,
|
||||||
uint8_t* p, uint32_t len);
|
uint8_t* p, uint32_t len);
|
||||||
|
|
||||||
#endif /* LIBUNBOUND_CONTEXT_H */
|
#endif /* LIBUNBOUND_CONTEXT_H */
|
||||||
|
|
|
||||||
|
|
@ -59,16 +59,16 @@
|
||||||
#include "services/cache/infra.h"
|
#include "services/cache/infra.h"
|
||||||
#include "services/cache/rrset.h"
|
#include "services/cache/rrset.h"
|
||||||
|
|
||||||
struct ub_val_ctx*
|
struct ub_ctx*
|
||||||
ub_val_ctx_create()
|
ub_ctx_create()
|
||||||
{
|
{
|
||||||
struct ub_val_ctx* ctx;
|
struct ub_ctx* ctx;
|
||||||
unsigned int seed;
|
unsigned int seed;
|
||||||
log_init(NULL, 0, NULL); /* logs to stderr */
|
log_init(NULL, 0, NULL); /* logs to stderr */
|
||||||
log_ident_set("libunbound");
|
log_ident_set("libunbound");
|
||||||
verbosity = 0; /* errors only */
|
verbosity = 0; /* errors only */
|
||||||
checklock_start();
|
checklock_start();
|
||||||
ctx = (struct ub_val_ctx*)calloc(1, sizeof(*ctx));
|
ctx = (struct ub_ctx*)calloc(1, sizeof(*ctx));
|
||||||
if(!ctx) {
|
if(!ctx) {
|
||||||
errno = ENOMEM;
|
errno = ENOMEM;
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -154,7 +154,7 @@ delq(rbnode_t* n, void* ATTR_UNUSED(arg))
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ub_val_ctx_delete(struct ub_val_ctx* ctx)
|
ub_ctx_delete(struct ub_ctx* ctx)
|
||||||
{
|
{
|
||||||
struct alloc_cache* a, *na;
|
struct alloc_cache* a, *na;
|
||||||
if(!ctx) return;
|
if(!ctx) return;
|
||||||
|
|
@ -234,7 +234,7 @@ ub_val_ctx_delete(struct ub_val_ctx* ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ub_val_ctx_config(struct ub_val_ctx* ctx, char* fname)
|
ub_ctx_config(struct ub_ctx* ctx, char* fname)
|
||||||
{
|
{
|
||||||
lock_basic_lock(&ctx->cfglock);
|
lock_basic_lock(&ctx->cfglock);
|
||||||
if(ctx->finalized) {
|
if(ctx->finalized) {
|
||||||
|
|
@ -250,7 +250,7 @@ ub_val_ctx_config(struct ub_val_ctx* ctx, char* fname)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ub_val_ctx_add_ta(struct ub_val_ctx* ctx, char* ta)
|
ub_ctx_add_ta(struct ub_ctx* ctx, char* ta)
|
||||||
{
|
{
|
||||||
char* dup = strdup(ta);
|
char* dup = strdup(ta);
|
||||||
if(!dup) return UB_NOMEM;
|
if(!dup) return UB_NOMEM;
|
||||||
|
|
@ -269,7 +269,7 @@ ub_val_ctx_add_ta(struct ub_val_ctx* ctx, char* ta)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ub_val_ctx_add_ta_file(struct ub_val_ctx* ctx, char* fname)
|
ub_ctx_add_ta_file(struct ub_ctx* ctx, char* fname)
|
||||||
{
|
{
|
||||||
char* dup = strdup(fname);
|
char* dup = strdup(fname);
|
||||||
if(!dup) return UB_NOMEM;
|
if(!dup) return UB_NOMEM;
|
||||||
|
|
@ -288,7 +288,7 @@ ub_val_ctx_add_ta_file(struct ub_val_ctx* ctx, char* fname)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ub_val_ctx_trustedkeys(struct ub_val_ctx* ctx, char* fname)
|
ub_ctx_trustedkeys(struct ub_ctx* ctx, char* fname)
|
||||||
{
|
{
|
||||||
char* dup = strdup(fname);
|
char* dup = strdup(fname);
|
||||||
if(!dup) return UB_NOMEM;
|
if(!dup) return UB_NOMEM;
|
||||||
|
|
@ -307,7 +307,7 @@ ub_val_ctx_trustedkeys(struct ub_val_ctx* ctx, char* fname)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ub_val_ctx_debuglevel(struct ub_val_ctx* ctx, int d)
|
ub_ctx_debuglevel(struct ub_ctx* ctx, int d)
|
||||||
{
|
{
|
||||||
lock_basic_lock(&ctx->cfglock);
|
lock_basic_lock(&ctx->cfglock);
|
||||||
verbosity = d;
|
verbosity = d;
|
||||||
|
|
@ -317,7 +317,7 @@ ub_val_ctx_debuglevel(struct ub_val_ctx* ctx, int d)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ub_val_ctx_async(struct ub_val_ctx* ctx, int dothread)
|
ub_ctx_async(struct ub_ctx* ctx, int dothread)
|
||||||
{
|
{
|
||||||
#if !defined(HAVE_PTHREAD) && !defined(HAVE_SOLARIS_THREADS)
|
#if !defined(HAVE_PTHREAD) && !defined(HAVE_SOLARIS_THREADS)
|
||||||
if(dothread) /* cannot do threading */
|
if(dothread) /* cannot do threading */
|
||||||
|
|
@ -335,7 +335,7 @@ ub_val_ctx_async(struct ub_val_ctx* ctx, int dothread)
|
||||||
|
|
||||||
/** perform a select() on the result read pipe */
|
/** perform a select() on the result read pipe */
|
||||||
static int
|
static int
|
||||||
pollit(struct ub_val_ctx* ctx, struct timeval* t)
|
pollit(struct ub_ctx* ctx, struct timeval* t)
|
||||||
{
|
{
|
||||||
fd_set r;
|
fd_set r;
|
||||||
#ifndef S_SPLINT_S
|
#ifndef S_SPLINT_S
|
||||||
|
|
@ -350,7 +350,7 @@ pollit(struct ub_val_ctx* ctx, struct timeval* t)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ub_val_poll(struct ub_val_ctx* ctx)
|
ub_poll(struct ub_ctx* ctx)
|
||||||
{
|
{
|
||||||
struct timeval t;
|
struct timeval t;
|
||||||
memset(&t, 0, sizeof(t));
|
memset(&t, 0, sizeof(t));
|
||||||
|
|
@ -359,16 +359,16 @@ ub_val_poll(struct ub_val_ctx* ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ub_val_fd(struct ub_val_ctx* ctx)
|
ub_fd(struct ub_ctx* ctx)
|
||||||
{
|
{
|
||||||
return ctx->rrpipe[0];
|
return ctx->rrpipe[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/** process answer from bg worker */
|
/** process answer from bg worker */
|
||||||
static int
|
static int
|
||||||
process_answer_detail(struct ub_val_ctx* ctx, uint8_t* msg, uint32_t len,
|
process_answer_detail(struct ub_ctx* ctx, uint8_t* msg, uint32_t len,
|
||||||
ub_val_callback_t* cb, void** cbarg, int* err,
|
ub_callback_t* cb, void** cbarg, int* err,
|
||||||
struct ub_val_result** res)
|
struct ub_result** res)
|
||||||
{
|
{
|
||||||
struct ctx_query* q;
|
struct ctx_query* q;
|
||||||
if(context_serial_getcmd(msg, len) != UB_LIBCMD_ANSWER) {
|
if(context_serial_getcmd(msg, len) != UB_LIBCMD_ANSWER) {
|
||||||
|
|
@ -397,7 +397,7 @@ process_answer_detail(struct ub_val_ctx* ctx, uint8_t* msg, uint32_t len,
|
||||||
}
|
}
|
||||||
if(*err) {
|
if(*err) {
|
||||||
*res = NULL;
|
*res = NULL;
|
||||||
ub_val_resolve_free(q->res);
|
ub_resolve_free(q->res);
|
||||||
} else {
|
} else {
|
||||||
/* parse the message, extract rcode, fill result */
|
/* parse the message, extract rcode, fill result */
|
||||||
ldns_buffer* buf = ldns_buffer_new(q->msg_len);
|
ldns_buffer* buf = ldns_buffer_new(q->msg_len);
|
||||||
|
|
@ -427,12 +427,12 @@ process_answer_detail(struct ub_val_ctx* ctx, uint8_t* msg, uint32_t len,
|
||||||
|
|
||||||
/** process answer from bg worker */
|
/** process answer from bg worker */
|
||||||
static int
|
static int
|
||||||
process_answer(struct ub_val_ctx* ctx, uint8_t* msg, uint32_t len)
|
process_answer(struct ub_ctx* ctx, uint8_t* msg, uint32_t len)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
ub_val_callback_t cb;
|
ub_callback_t cb;
|
||||||
void* cbarg;
|
void* cbarg;
|
||||||
struct ub_val_result* res;
|
struct ub_result* res;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
r = process_answer_detail(ctx, msg, len, &cb, &cbarg, &err, &res);
|
r = process_answer_detail(ctx, msg, len, &cb, &cbarg, &err, &res);
|
||||||
|
|
@ -446,7 +446,7 @@ process_answer(struct ub_val_ctx* ctx, uint8_t* msg, uint32_t len)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ub_val_process(struct ub_val_ctx* ctx)
|
ub_process(struct ub_ctx* ctx)
|
||||||
{
|
{
|
||||||
int r;
|
int r;
|
||||||
uint8_t* msg;
|
uint8_t* msg;
|
||||||
|
|
@ -470,12 +470,12 @@ ub_val_process(struct ub_val_ctx* ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ub_val_wait(struct ub_val_ctx* ctx)
|
ub_wait(struct ub_ctx* ctx)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
ub_val_callback_t cb;
|
ub_callback_t cb;
|
||||||
void* cbarg;
|
void* cbarg;
|
||||||
struct ub_val_result* res;
|
struct ub_result* res;
|
||||||
int r;
|
int r;
|
||||||
uint8_t* msg;
|
uint8_t* msg;
|
||||||
uint32_t len;
|
uint32_t len;
|
||||||
|
|
@ -523,8 +523,8 @@ ub_val_wait(struct ub_val_ctx* ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ub_val_resolve(struct ub_val_ctx* ctx, char* name, int rrtype,
|
ub_resolve(struct ub_ctx* ctx, char* name, int rrtype,
|
||||||
int rrclass, struct ub_val_result** result)
|
int rrclass, struct ub_result** result)
|
||||||
{
|
{
|
||||||
struct ctx_query* q;
|
struct ctx_query* q;
|
||||||
int r;
|
int r;
|
||||||
|
|
@ -564,8 +564,8 @@ ub_val_resolve(struct ub_val_ctx* ctx, char* name, int rrtype,
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ub_val_resolve_async(struct ub_val_ctx* ctx, char* name, int rrtype,
|
ub_resolve_async(struct ub_ctx* ctx, char* name, int rrtype,
|
||||||
int rrclass, void* mydata, ub_val_callback_t callback, int* async_id)
|
int rrclass, void* mydata, ub_callback_t callback, int* async_id)
|
||||||
{
|
{
|
||||||
struct ctx_query* q;
|
struct ctx_query* q;
|
||||||
uint8_t* msg = NULL;
|
uint8_t* msg = NULL;
|
||||||
|
|
@ -627,7 +627,7 @@ ub_val_resolve_async(struct ub_val_ctx* ctx, char* name, int rrtype,
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ub_val_cancel(struct ub_val_ctx* ctx, int async_id)
|
ub_cancel(struct ub_ctx* ctx, int async_id)
|
||||||
{
|
{
|
||||||
struct ctx_query* q;
|
struct ctx_query* q;
|
||||||
uint8_t* msg = NULL;
|
uint8_t* msg = NULL;
|
||||||
|
|
@ -668,7 +668,7 @@ ub_val_cancel(struct ub_val_ctx* ctx, int async_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ub_val_resolve_free(struct ub_val_result* result)
|
ub_resolve_free(struct ub_result* result)
|
||||||
{
|
{
|
||||||
char** p;
|
char** p;
|
||||||
if(!result) return;
|
if(!result) return;
|
||||||
|
|
@ -684,7 +684,7 @@ ub_val_resolve_free(struct ub_val_result* result)
|
||||||
}
|
}
|
||||||
|
|
||||||
const char*
|
const char*
|
||||||
ub_val_strerror(int err)
|
ub_strerror(int err)
|
||||||
{
|
{
|
||||||
switch(err) {
|
switch(err) {
|
||||||
case UB_NOERROR: return "no error";
|
case UB_NOERROR: return "no error";
|
||||||
|
|
@ -702,7 +702,7 @@ ub_val_strerror(int err)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ub_val_ctx_set_fwd(struct ub_val_ctx* ctx, char* addr)
|
ub_ctx_set_fwd(struct ub_ctx* ctx, char* addr)
|
||||||
{
|
{
|
||||||
struct sockaddr_storage storage;
|
struct sockaddr_storage storage;
|
||||||
socklen_t stlen;
|
socklen_t stlen;
|
||||||
|
|
@ -774,7 +774,7 @@ ub_val_ctx_set_fwd(struct ub_val_ctx* ctx, char* addr)
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
ub_val_ctx_resolvconf(struct ub_val_ctx* ctx, char* fname)
|
ub_ctx_resolvconf(struct ub_ctx* ctx, char* fname)
|
||||||
{
|
{
|
||||||
FILE* in;
|
FILE* in;
|
||||||
int numserv = 0;
|
int numserv = 0;
|
||||||
|
|
@ -806,7 +806,7 @@ ub_val_ctx_resolvconf(struct ub_val_ctx* ctx, char* fname)
|
||||||
/* terminate after the address, remove newline */
|
/* terminate after the address, remove newline */
|
||||||
*parse = 0;
|
*parse = 0;
|
||||||
|
|
||||||
if((r = ub_val_ctx_set_fwd(ctx, addr)) != UB_NOERROR) {
|
if((r = ub_ctx_set_fwd(ctx, addr)) != UB_NOERROR) {
|
||||||
fclose(in);
|
fclose(in);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
@ -815,7 +815,7 @@ ub_val_ctx_resolvconf(struct ub_val_ctx* ctx, char* fname)
|
||||||
fclose(in);
|
fclose(in);
|
||||||
if(numserv == 0) {
|
if(numserv == 0) {
|
||||||
/* from resolv.conf(5) if none given, use localhost */
|
/* from resolv.conf(5) if none given, use localhost */
|
||||||
return ub_val_ctx_set_fwd(ctx, "127.0.0.1");
|
return ub_ctx_set_fwd(ctx, "127.0.0.1");
|
||||||
}
|
}
|
||||||
return UB_NOERROR;
|
return UB_NOERROR;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -88,7 +88,7 @@ libworker_delete(struct libworker* w)
|
||||||
|
|
||||||
/** setup fresh libworker struct */
|
/** setup fresh libworker struct */
|
||||||
static struct libworker*
|
static struct libworker*
|
||||||
libworker_setup(struct ub_val_ctx* ctx, int is_bg)
|
libworker_setup(struct ub_ctx* ctx, int is_bg)
|
||||||
{
|
{
|
||||||
unsigned int seed;
|
unsigned int seed;
|
||||||
struct libworker* w = (struct libworker*)calloc(1, sizeof(*w));
|
struct libworker* w = (struct libworker*)calloc(1, sizeof(*w));
|
||||||
|
|
@ -354,7 +354,7 @@ libworker_dobg(void* arg)
|
||||||
uint32_t m;
|
uint32_t m;
|
||||||
int fd;
|
int fd;
|
||||||
struct libworker* w = (struct libworker*)arg;
|
struct libworker* w = (struct libworker*)arg;
|
||||||
struct ub_val_ctx* ctx = w->ctx;
|
struct ub_ctx* ctx = w->ctx;
|
||||||
log_thread_set(&w->thread_num);
|
log_thread_set(&w->thread_num);
|
||||||
#if !defined(HAVE_PTHREAD) && !defined(HAVE_SOLARIS_THREADS)
|
#if !defined(HAVE_PTHREAD) && !defined(HAVE_SOLARIS_THREADS)
|
||||||
/* we are forked */
|
/* we are forked */
|
||||||
|
|
@ -399,7 +399,7 @@ libworker_dobg(void* arg)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int libworker_bg(struct ub_val_ctx* ctx)
|
int libworker_bg(struct ub_ctx* ctx)
|
||||||
{
|
{
|
||||||
struct libworker* w;
|
struct libworker* w;
|
||||||
/* fork or threadcreate */
|
/* fork or threadcreate */
|
||||||
|
|
@ -457,7 +457,7 @@ parse_reply(ldns_buffer* pkt, struct regional* region, struct query_info* qi)
|
||||||
|
|
||||||
/** insert canonname */
|
/** insert canonname */
|
||||||
static int
|
static int
|
||||||
fill_canon(struct ub_val_result* res, uint8_t* s)
|
fill_canon(struct ub_result* res, uint8_t* s)
|
||||||
{
|
{
|
||||||
char buf[255+2];
|
char buf[255+2];
|
||||||
dname_str(s, buf);
|
dname_str(s, buf);
|
||||||
|
|
@ -467,7 +467,7 @@ fill_canon(struct ub_val_result* res, uint8_t* s)
|
||||||
|
|
||||||
/** fill data into result */
|
/** fill data into result */
|
||||||
static int
|
static int
|
||||||
fill_res(struct ub_val_result* res, struct ub_packed_rrset_key* answer,
|
fill_res(struct ub_result* res, struct ub_packed_rrset_key* answer,
|
||||||
uint8_t* finalcname, struct query_info* rq)
|
uint8_t* finalcname, struct query_info* rq)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
@ -504,7 +504,7 @@ fill_res(struct ub_val_result* res, struct ub_packed_rrset_key* answer,
|
||||||
|
|
||||||
/** fill result from parsed message, on error fills servfail */
|
/** fill result from parsed message, on error fills servfail */
|
||||||
void
|
void
|
||||||
libworker_enter_result(struct ub_val_result* res, ldns_buffer* buf,
|
libworker_enter_result(struct ub_result* res, ldns_buffer* buf,
|
||||||
struct regional* temp, enum sec_status msg_security)
|
struct regional* temp, enum sec_status msg_security)
|
||||||
{
|
{
|
||||||
struct query_info rq;
|
struct query_info rq;
|
||||||
|
|
@ -591,7 +591,7 @@ setup_qinfo_edns(struct libworker* w, struct ctx_query* q,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int libworker_fg(struct ub_val_ctx* ctx, struct ctx_query* q)
|
int libworker_fg(struct ub_ctx* ctx, struct ctx_query* q)
|
||||||
{
|
{
|
||||||
struct libworker* w = libworker_setup(ctx, 0);
|
struct libworker* w = libworker_setup(ctx, 0);
|
||||||
uint16_t qflags, qid;
|
uint16_t qflags, qid;
|
||||||
|
|
@ -690,7 +690,7 @@ libworker_bg_done_cb(void* arg, int rcode, ldns_buffer* buf, enum sec_status s)
|
||||||
if(q->cancelled) {
|
if(q->cancelled) {
|
||||||
if(q->w->is_bg_thread) {
|
if(q->w->is_bg_thread) {
|
||||||
/* delete it now */
|
/* delete it now */
|
||||||
struct ub_val_ctx* ctx = q->w->ctx;
|
struct ub_ctx* ctx = q->w->ctx;
|
||||||
lock_basic_lock(&ctx->cfglock);
|
lock_basic_lock(&ctx->cfglock);
|
||||||
(void)rbtree_delete(&ctx->queries, q->node.key);
|
(void)rbtree_delete(&ctx->queries, q->node.key);
|
||||||
ctx->num_async--;
|
ctx->num_async--;
|
||||||
|
|
|
||||||
|
|
@ -44,8 +44,8 @@
|
||||||
#ifndef LIBUNBOUND_WORKER_H
|
#ifndef LIBUNBOUND_WORKER_H
|
||||||
#define LIBUNBOUND_WORKER_H
|
#define LIBUNBOUND_WORKER_H
|
||||||
#include "util/data/packed_rrset.h"
|
#include "util/data/packed_rrset.h"
|
||||||
struct ub_val_ctx;
|
struct ub_ctx;
|
||||||
struct ub_val_result;
|
struct ub_result;
|
||||||
struct module_env;
|
struct module_env;
|
||||||
struct comm_base;
|
struct comm_base;
|
||||||
struct outside_network;
|
struct outside_network;
|
||||||
|
|
@ -66,7 +66,7 @@ struct libworker {
|
||||||
/** every worker has a unique thread_num. (first in struct) */
|
/** every worker has a unique thread_num. (first in struct) */
|
||||||
int thread_num;
|
int thread_num;
|
||||||
/** context we are operating under */
|
/** context we are operating under */
|
||||||
struct ub_val_ctx* ctx;
|
struct ub_ctx* ctx;
|
||||||
|
|
||||||
/** is this the bg worker? */
|
/** is this the bg worker? */
|
||||||
int is_bg;
|
int is_bg;
|
||||||
|
|
@ -122,7 +122,7 @@ struct libworker_res_list {
|
||||||
* @return 0 if OK, else error.
|
* @return 0 if OK, else error.
|
||||||
* Further communication is done via the pipes in ctx.
|
* Further communication is done via the pipes in ctx.
|
||||||
*/
|
*/
|
||||||
int libworker_bg(struct ub_val_ctx* ctx);
|
int libworker_bg(struct ub_ctx* ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a foreground worker.
|
* Create a foreground worker.
|
||||||
|
|
@ -133,7 +133,7 @@ int libworker_bg(struct ub_val_ctx* ctx);
|
||||||
* @param q: query (result is stored in here).
|
* @param q: query (result is stored in here).
|
||||||
* @return 0 if finished OK, else error.
|
* @return 0 if finished OK, else error.
|
||||||
*/
|
*/
|
||||||
int libworker_fg(struct ub_val_ctx* ctx, struct ctx_query* q);
|
int libworker_fg(struct ub_ctx* ctx, struct ctx_query* q);
|
||||||
|
|
||||||
/** cleanup the cache to remove all rrset IDs from it, arg is libworker */
|
/** cleanup the cache to remove all rrset IDs from it, arg is libworker */
|
||||||
void libworker_alloc_cleanup(void* arg);
|
void libworker_alloc_cleanup(void* arg);
|
||||||
|
|
@ -230,7 +230,7 @@ int libworker_read_msg(int fd, uint8_t** buf, uint32_t* len, int nonblock);
|
||||||
* On error, the res may contain a different status
|
* On error, the res may contain a different status
|
||||||
* (out of memory is not secure, not bogus).
|
* (out of memory is not secure, not bogus).
|
||||||
*/
|
*/
|
||||||
void libworker_enter_result(struct ub_val_result* res, ldns_buffer* buf,
|
void libworker_enter_result(struct ub_result* res, ldns_buffer* buf,
|
||||||
struct regional* temp, enum sec_status msg_security);
|
struct regional* temp, enum sec_status msg_security);
|
||||||
|
|
||||||
#endif /* LIBUNBOUND_WORKER_H */
|
#endif /* LIBUNBOUND_WORKER_H */
|
||||||
|
|
|
||||||
|
|
@ -43,29 +43,29 @@
|
||||||
* to perform (validated) DNS lookups.
|
* to perform (validated) DNS lookups.
|
||||||
*
|
*
|
||||||
* All start with
|
* All start with
|
||||||
* ctx = ub_val_ctx_create();
|
* ctx = ub_ctx_create();
|
||||||
* err = ub_val_ctx_add_ta(ctx, "...");
|
* err = ub_ctx_add_ta(ctx, "...");
|
||||||
* err = ub_val_ctx_add_ta(ctx, "...");
|
* err = ub_ctx_add_ta(ctx, "...");
|
||||||
* ... some lookups
|
* ... some lookups
|
||||||
* ... call ub_val_ctx_delete(ctx); when you want to stop.
|
* ... call ub_ctx_delete(ctx); when you want to stop.
|
||||||
*
|
*
|
||||||
* Application not threaded. Blocking.
|
* Application not threaded. Blocking.
|
||||||
* int err = ub_val_resolve(ctx, "www.example.com", ...
|
* int err = ub_resolve(ctx, "www.example.com", ...
|
||||||
* if(err) fprintf(stderr, "lookup error: %s\n", ub_val_strerror(err));
|
* if(err) fprintf(stderr, "lookup error: %s\n", ub_strerror(err));
|
||||||
* ... use the answer
|
* ... use the answer
|
||||||
*
|
*
|
||||||
* Application not threaded. Non-blocking ('asynchronous').
|
* Application not threaded. Non-blocking ('asynchronous').
|
||||||
* err = ub_val_resolve_async(ctx, "www.example.com", ... my_callback);
|
* err = ub_resolve_async(ctx, "www.example.com", ... my_callback);
|
||||||
* ... application resumes processing ...
|
* ... application resumes processing ...
|
||||||
* ... and when either ub_val_poll(ctx) is true
|
* ... and when either ub_poll(ctx) is true
|
||||||
* ... or when the file descriptor ub_val_fd(ctx) is readable,
|
* ... or when the file descriptor ub_fd(ctx) is readable,
|
||||||
* ... or whenever, the app calls ...
|
* ... or whenever, the app calls ...
|
||||||
* ub_val_process(ctx);
|
* ub_process(ctx);
|
||||||
* ... if no result is ready, the app resumes processing above,
|
* ... if no result is ready, the app resumes processing above,
|
||||||
* ... or process() calls my_callback() with results.
|
* ... or process() calls my_callback() with results.
|
||||||
*
|
*
|
||||||
* ... if the application has nothing more to do, wait for answer
|
* ... if the application has nothing more to do, wait for answer
|
||||||
* ub_val_wait(ctx);
|
* ub_wait(ctx);
|
||||||
*
|
*
|
||||||
* Application threaded. Blocking.
|
* Application threaded. Blocking.
|
||||||
* Blocking, same as above. The current thread does the work.
|
* Blocking, same as above. The current thread does the work.
|
||||||
|
|
@ -74,7 +74,7 @@
|
||||||
*
|
*
|
||||||
* Application threaded. Non-blocking ('asynchronous').
|
* Application threaded. Non-blocking ('asynchronous').
|
||||||
* ... setup threaded-asynchronous config option
|
* ... setup threaded-asynchronous config option
|
||||||
* err = ub_val_ctx_async(ctx, 1);
|
* err = ub_ctx_async(ctx, 1);
|
||||||
* ... same as async for non-threaded
|
* ... same as async for non-threaded
|
||||||
* ... the callbacks are called in the thread that calls process(ctx)
|
* ... the callbacks are called in the thread that calls process(ctx)
|
||||||
*
|
*
|
||||||
|
|
@ -84,7 +84,7 @@
|
||||||
* Otherwise, for asynchronous with threading, a worker thread is created.
|
* Otherwise, for asynchronous with threading, a worker thread is created.
|
||||||
*
|
*
|
||||||
* The blocking calls use shared ctx-cache when threaded. Thus
|
* The blocking calls use shared ctx-cache when threaded. Thus
|
||||||
* ub_val_resolve() and ub_val_resolve_async() && ub_val_wait() are
|
* ub_resolve() and ub_resolve_async() && ub_wait() are
|
||||||
* not the same. The first makes the current thread do the work, setting
|
* not the same. The first makes the current thread do the work, setting
|
||||||
* up buffers, etc, to perform the work (but using shared cache data).
|
* up buffers, etc, to perform the work (but using shared cache data).
|
||||||
* The second calls another worker thread (or process) to perform the work.
|
* The second calls another worker thread (or process) to perform the work.
|
||||||
|
|
@ -100,14 +100,14 @@
|
||||||
*
|
*
|
||||||
* Its contents are internally defined.
|
* Its contents are internally defined.
|
||||||
*/
|
*/
|
||||||
struct ub_val_ctx;
|
struct ub_ctx;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The validation and resolution results.
|
* The validation and resolution results.
|
||||||
* Allocated by the resolver, and need to be freed by the application
|
* Allocated by the resolver, and need to be freed by the application
|
||||||
* with ub_val_resolve_free().
|
* with ub_resolve_free().
|
||||||
*/
|
*/
|
||||||
struct ub_val_result {
|
struct ub_result {
|
||||||
/** The original question, name text string. */
|
/** The original question, name text string. */
|
||||||
char* qname;
|
char* qname;
|
||||||
/** the type asked for */
|
/** the type asked for */
|
||||||
|
|
@ -179,7 +179,7 @@ struct ub_val_result {
|
||||||
/**
|
/**
|
||||||
* Callback for results of async queries.
|
* Callback for results of async queries.
|
||||||
* The readable function definition looks like:
|
* The readable function definition looks like:
|
||||||
* void my_callback(void* my_arg, int err, struct ub_val_result* result);
|
* void my_callback(void* my_arg, int err, struct ub_result* result);
|
||||||
* It is called with
|
* It is called with
|
||||||
* void* my_arg: your pointer to a (struct of) data of your choice,
|
* void* my_arg: your pointer to a (struct of) data of your choice,
|
||||||
* or NULL.
|
* or NULL.
|
||||||
|
|
@ -187,23 +187,23 @@ struct ub_val_result {
|
||||||
* are forthcoming.
|
* are forthcoming.
|
||||||
* struct result: pointer to more detailed result structure.
|
* struct result: pointer to more detailed result structure.
|
||||||
* This structure is allocated on the heap and needs to be
|
* This structure is allocated on the heap and needs to be
|
||||||
* freed with ub_val_resolve_free(result);
|
* freed with ub_resolve_free(result);
|
||||||
*/
|
*/
|
||||||
typedef void (*ub_val_callback_t)(void*, int, struct ub_val_result*);
|
typedef void (*ub_callback_t)(void*, int, struct ub_result*);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a resolving and validation context.
|
* Create a resolving and validation context.
|
||||||
* @return a new context. default initialisation.
|
* @return a new context. default initialisation.
|
||||||
* returns NULL on error.
|
* returns NULL on error.
|
||||||
*/
|
*/
|
||||||
struct ub_val_ctx* ub_val_ctx_create(void);
|
struct ub_ctx* ub_ctx_create(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy a validation context and free all its resources.
|
* Destroy a validation context and free all its resources.
|
||||||
* Outstanding async queries are killed and callbacks are not called for them.
|
* Outstanding async queries are killed and callbacks are not called for them.
|
||||||
* @param ctx: context to delete.
|
* @param ctx: context to delete.
|
||||||
*/
|
*/
|
||||||
void ub_val_ctx_delete(struct ub_val_ctx* ctx);
|
void ub_ctx_delete(struct ub_ctx* ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* setup configuration for the given context.
|
* setup configuration for the given context.
|
||||||
|
|
@ -215,7 +215,7 @@ void ub_val_ctx_delete(struct ub_val_ctx* ctx);
|
||||||
* routines exist.
|
* routines exist.
|
||||||
* @return: 0 if OK, else error.
|
* @return: 0 if OK, else error.
|
||||||
*/
|
*/
|
||||||
int ub_val_ctx_config(struct ub_val_ctx* ctx, char* fname);
|
int ub_ctx_config(struct ub_ctx* ctx, char* fname);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set machine to forward DNS queries to, the caching resolver to use.
|
* Set machine to forward DNS queries to, the caching resolver to use.
|
||||||
|
|
@ -225,7 +225,7 @@ int ub_val_ctx_config(struct ub_val_ctx* ctx, char* fname);
|
||||||
* that case the addresses are used as backup servers.
|
* that case the addresses are used as backup servers.
|
||||||
*
|
*
|
||||||
* To read the list of nameservers from /etc/resolv.conf (from DHCP or so),
|
* To read the list of nameservers from /etc/resolv.conf (from DHCP or so),
|
||||||
* use the call ub_val_ctx_resolvconf.
|
* use the call ub_ctx_resolvconf.
|
||||||
*
|
*
|
||||||
* @param ctx: context.
|
* @param ctx: context.
|
||||||
* At this time it is only possible to set configuration before the
|
* At this time it is only possible to set configuration before the
|
||||||
|
|
@ -234,7 +234,7 @@ int ub_val_ctx_config(struct ub_val_ctx* ctx, char* fname);
|
||||||
* If the addr is NULL, forwarding is disabled.
|
* If the addr is NULL, forwarding is disabled.
|
||||||
* @return 0 if OK, else error.
|
* @return 0 if OK, else error.
|
||||||
*/
|
*/
|
||||||
int ub_val_ctx_set_fwd(struct ub_val_ctx* ctx, char* addr);
|
int ub_ctx_set_fwd(struct ub_ctx* ctx, char* addr);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read list of nameservers to use from the filename given.
|
* Read list of nameservers to use from the filename given.
|
||||||
|
|
@ -250,7 +250,7 @@ int ub_val_ctx_set_fwd(struct ub_val_ctx* ctx, char* addr);
|
||||||
* @param fname: file name string. If NULL "/etc/resolv.conf" is used.
|
* @param fname: file name string. If NULL "/etc/resolv.conf" is used.
|
||||||
* @return 0 if OK, else error.
|
* @return 0 if OK, else error.
|
||||||
*/
|
*/
|
||||||
int ub_val_ctx_resolvconf(struct ub_val_ctx* ctx, char* fname);
|
int ub_ctx_resolvconf(struct ub_ctx* ctx, char* fname);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a trust anchor to the given context.
|
* Add a trust anchor to the given context.
|
||||||
|
|
@ -263,7 +263,7 @@ int ub_val_ctx_resolvconf(struct ub_val_ctx* ctx, char* fname);
|
||||||
* [domainname] [TTL optional] [type] [class optional] [rdata contents]
|
* [domainname] [TTL optional] [type] [class optional] [rdata contents]
|
||||||
* @return 0 if OK, else error.
|
* @return 0 if OK, else error.
|
||||||
*/
|
*/
|
||||||
int ub_val_ctx_add_ta(struct ub_val_ctx* ctx, char* ta);
|
int ub_ctx_add_ta(struct ub_ctx* ctx, char* ta);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add trust anchors to the given context.
|
* Add trust anchors to the given context.
|
||||||
|
|
@ -274,7 +274,7 @@ int ub_val_ctx_add_ta(struct ub_val_ctx* ctx, char* ta);
|
||||||
* @param fname: filename of file with keyfile with trust anchors.
|
* @param fname: filename of file with keyfile with trust anchors.
|
||||||
* @return 0 if OK, else error.
|
* @return 0 if OK, else error.
|
||||||
*/
|
*/
|
||||||
int ub_val_ctx_add_ta_file(struct ub_val_ctx* ctx, char* fname);
|
int ub_ctx_add_ta_file(struct ub_ctx* ctx, char* fname);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add trust anchors to the given context.
|
* Add trust anchors to the given context.
|
||||||
|
|
@ -286,7 +286,7 @@ int ub_val_ctx_add_ta_file(struct ub_val_ctx* ctx, char* fname);
|
||||||
* anchors.
|
* anchors.
|
||||||
* @return 0 if OK, else error.
|
* @return 0 if OK, else error.
|
||||||
*/
|
*/
|
||||||
int ub_val_ctx_trustedkeys(struct ub_val_ctx* ctx, char* fname);
|
int ub_ctx_trustedkeys(struct ub_ctx* ctx, char* fname);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set debug verbosity for the context
|
* Set debug verbosity for the context
|
||||||
|
|
@ -296,7 +296,7 @@ int ub_val_ctx_trustedkeys(struct ub_val_ctx* ctx, char* fname);
|
||||||
* and 3 is lots.
|
* and 3 is lots.
|
||||||
* @return 0 if OK, else error.
|
* @return 0 if OK, else error.
|
||||||
*/
|
*/
|
||||||
int ub_val_ctx_debuglevel(struct ub_val_ctx* ctx, int d);
|
int ub_ctx_debuglevel(struct ub_ctx* ctx, int d);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a context behaviour for asynchronous action.
|
* Set a context behaviour for asynchronous action.
|
||||||
|
|
@ -308,7 +308,7 @@ int ub_val_ctx_debuglevel(struct ub_val_ctx* ctx, int d);
|
||||||
* no effect (delete and re-create the context to change).
|
* no effect (delete and re-create the context to change).
|
||||||
* @return 0 if OK, else error.
|
* @return 0 if OK, else error.
|
||||||
*/
|
*/
|
||||||
int ub_val_ctx_async(struct ub_val_ctx* ctx, int dothread);
|
int ub_ctx_async(struct ub_ctx* ctx, int dothread);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Poll a context to see if it has any new results
|
* Poll a context to see if it has any new results
|
||||||
|
|
@ -318,27 +318,27 @@ int ub_val_ctx_async(struct ub_val_ctx* ctx, int dothread);
|
||||||
* @return: 0 if nothing to read, or nonzero if a result is available.
|
* @return: 0 if nothing to read, or nonzero if a result is available.
|
||||||
* If nonzero, call ctx_process() to do callbacks.
|
* If nonzero, call ctx_process() to do callbacks.
|
||||||
*/
|
*/
|
||||||
int ub_val_poll(struct ub_val_ctx* ctx);
|
int ub_poll(struct ub_ctx* ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Wait for a context to finish with results. Calls ub_val_process() after
|
* Wait for a context to finish with results. Calls ub_process() after
|
||||||
* the wait for you. After the wait, there are no more outstanding
|
* the wait for you. After the wait, there are no more outstanding
|
||||||
* asynchronous queries.
|
* asynchronous queries.
|
||||||
* @param ctx: context.
|
* @param ctx: context.
|
||||||
* @return: 0 if OK, else error.
|
* @return: 0 if OK, else error.
|
||||||
*/
|
*/
|
||||||
int ub_val_wait(struct ub_val_ctx* ctx);
|
int ub_wait(struct ub_ctx* ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get file descriptor. Wait for it to become readable, at this point
|
* Get file descriptor. Wait for it to become readable, at this point
|
||||||
* answers are returned from the asynchronous validating resolver.
|
* answers are returned from the asynchronous validating resolver.
|
||||||
* Then call the ub_val_process to continue processing.
|
* Then call the ub_process to continue processing.
|
||||||
* This routine works immediately after context creation, the fd
|
* This routine works immediately after context creation, the fd
|
||||||
* does not change.
|
* does not change.
|
||||||
* @param ctx: context.
|
* @param ctx: context.
|
||||||
* @return: -1 on error, or file descriptor to use select(2) with.
|
* @return: -1 on error, or file descriptor to use select(2) with.
|
||||||
*/
|
*/
|
||||||
int ub_val_fd(struct ub_val_ctx* ctx);
|
int ub_fd(struct ub_ctx* ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Call this routine to continue processing results from the validating
|
* Call this routine to continue processing results from the validating
|
||||||
|
|
@ -347,7 +347,7 @@ int ub_val_fd(struct ub_val_ctx* ctx);
|
||||||
* @param ctx: context
|
* @param ctx: context
|
||||||
* @return: 0 if OK, else error.
|
* @return: 0 if OK, else error.
|
||||||
*/
|
*/
|
||||||
int ub_val_process(struct ub_val_ctx* ctx);
|
int ub_process(struct ub_ctx* ctx);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform resolution and validation of the target name.
|
* Perform resolution and validation of the target name.
|
||||||
|
|
@ -361,8 +361,8 @@ int ub_val_process(struct ub_val_ctx* ctx);
|
||||||
* in that case (out of memory).
|
* in that case (out of memory).
|
||||||
* @return 0 if OK, else error.
|
* @return 0 if OK, else error.
|
||||||
*/
|
*/
|
||||||
int ub_val_resolve(struct ub_val_ctx* ctx, char* name, int rrtype,
|
int ub_resolve(struct ub_ctx* ctx, char* name, int rrtype,
|
||||||
int rrclass, struct ub_val_result** result);
|
int rrclass, struct ub_result** result);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Perform resolution and validation of the target name.
|
* Perform resolution and validation of the target name.
|
||||||
|
|
@ -379,7 +379,7 @@ int ub_val_resolve(struct ub_val_ctx* ctx, char* name, int rrtype,
|
||||||
* and is passed on to the callback function.
|
* and is passed on to the callback function.
|
||||||
* @param callback: this is called on completion of the resolution.
|
* @param callback: this is called on completion of the resolution.
|
||||||
* It is called as:
|
* It is called as:
|
||||||
* void callback(void* mydata, int err, struct ub_val_result* result)
|
* void callback(void* mydata, int err, struct ub_result* result)
|
||||||
* with mydata: the same as passed here, you may pass NULL,
|
* with mydata: the same as passed here, you may pass NULL,
|
||||||
* with err: is 0 when a result has been found.
|
* with err: is 0 when a result has been found.
|
||||||
* with result: a newly allocated result structure.
|
* with result: a newly allocated result structure.
|
||||||
|
|
@ -392,8 +392,8 @@ int ub_val_resolve(struct ub_val_ctx* ctx, char* name, int rrtype,
|
||||||
* cancel the query.
|
* cancel the query.
|
||||||
* @return 0 if OK, else error.
|
* @return 0 if OK, else error.
|
||||||
*/
|
*/
|
||||||
int ub_val_resolve_async(struct ub_val_ctx* ctx, char* name, int rrtype,
|
int ub_resolve_async(struct ub_ctx* ctx, char* name, int rrtype,
|
||||||
int rrclass, void* mydata, ub_val_callback_t callback, int* async_id);
|
int rrclass, void* mydata, ub_callback_t callback, int* async_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cancel an async query in progress.
|
* Cancel an async query in progress.
|
||||||
|
|
@ -403,19 +403,19 @@ int ub_val_resolve_async(struct ub_val_ctx* ctx, char* name, int rrtype,
|
||||||
* @param async_id: which query to cancel.
|
* @param async_id: which query to cancel.
|
||||||
* @return 0 if OK, else error.
|
* @return 0 if OK, else error.
|
||||||
*/
|
*/
|
||||||
int ub_val_cancel(struct ub_val_ctx* ctx, int async_id);
|
int ub_cancel(struct ub_ctx* ctx, int async_id);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Free storage associated with a result structure.
|
* Free storage associated with a result structure.
|
||||||
* @param result: to free
|
* @param result: to free
|
||||||
*/
|
*/
|
||||||
void ub_val_resolve_free(struct ub_val_result* result);
|
void ub_resolve_free(struct ub_result* result);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert error value to a human readable string.
|
* Convert error value to a human readable string.
|
||||||
* @param err: error code from one of the ub_val* functions.
|
* @param err: error code from one of the ub_val* functions.
|
||||||
* @return pointer to constant text string, zero terminated.
|
* @return pointer to constant text string, zero terminated.
|
||||||
*/
|
*/
|
||||||
const char* ub_val_strerror(int err);
|
const char* ub_strerror(int err);
|
||||||
|
|
||||||
#endif /* _UB_UNBOUND_H */
|
#endif /* _UB_UNBOUND_H */
|
||||||
|
|
|
||||||
|
|
@ -176,7 +176,7 @@ massage_class(const char* c)
|
||||||
|
|
||||||
/** nice security status string */
|
/** nice security status string */
|
||||||
static const char*
|
static const char*
|
||||||
secure_str(struct ub_val_result* result)
|
secure_str(struct ub_result* result)
|
||||||
{
|
{
|
||||||
if(result->secure) return "(secure)";
|
if(result->secure) return "(secure)";
|
||||||
if(result->bogus) return "(BOGUS (security failure))";
|
if(result->bogus) return "(BOGUS (security failure))";
|
||||||
|
|
@ -274,7 +274,7 @@ pretty_rdata(char* q, char* cstr, char* tstr, int t, const char* sec,
|
||||||
|
|
||||||
/** pretty line of output for results */
|
/** pretty line of output for results */
|
||||||
static void
|
static void
|
||||||
pretty_output(char* q, int t, int c, struct ub_val_result* result, int docname)
|
pretty_output(char* q, int t, int c, struct ub_result* result, int docname)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
const char *secstatus = secure_str(result);
|
const char *secstatus = secure_str(result);
|
||||||
|
|
@ -337,25 +337,25 @@ pretty_output(char* q, int t, int c, struct ub_val_result* result, int docname)
|
||||||
|
|
||||||
/** perform a lookup and printout return if domain existed */
|
/** perform a lookup and printout return if domain existed */
|
||||||
static int
|
static int
|
||||||
dnslook(struct ub_val_ctx* ctx, char* q, int t, int c, int docname)
|
dnslook(struct ub_ctx* ctx, char* q, int t, int c, int docname)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
struct ub_val_result* result;
|
struct ub_result* result;
|
||||||
|
|
||||||
ret = ub_val_resolve(ctx, q, t, c, &result);
|
ret = ub_resolve(ctx, q, t, c, &result);
|
||||||
if(ret != 0) {
|
if(ret != 0) {
|
||||||
fprintf(stderr, "resolve error: %s\n", ub_val_strerror(ret));
|
fprintf(stderr, "resolve error: %s\n", ub_strerror(ret));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
pretty_output(q, t, c, result, docname);
|
pretty_output(q, t, c, result, docname);
|
||||||
ret = result->nxdomain;
|
ret = result->nxdomain;
|
||||||
ub_val_resolve_free(result);
|
ub_resolve_free(result);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** perform host lookup */
|
/** perform host lookup */
|
||||||
static void
|
static void
|
||||||
lookup(struct ub_val_ctx* ctx, const char* nm, const char* qt, const char* qc)
|
lookup(struct ub_ctx* ctx, const char* nm, const char* qt, const char* qc)
|
||||||
{
|
{
|
||||||
/* massage input into a query name, type and class */
|
/* massage input into a query name, type and class */
|
||||||
int multi = 0; /* no type, so do A, AAAA, MX */
|
int multi = 0; /* no type, so do A, AAAA, MX */
|
||||||
|
|
@ -374,7 +374,7 @@ lookup(struct ub_val_ctx* ctx, const char* nm, const char* qt, const char* qc)
|
||||||
} else {
|
} else {
|
||||||
(void)dnslook(ctx, realq, t, c, 1);
|
(void)dnslook(ctx, realq, t, c, 1);
|
||||||
}
|
}
|
||||||
ub_val_ctx_delete(ctx);
|
ub_ctx_delete(ctx);
|
||||||
free(realq);
|
free(realq);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -389,10 +389,10 @@ int main(int argc, char* argv[])
|
||||||
int c;
|
int c;
|
||||||
char* qclass = NULL;
|
char* qclass = NULL;
|
||||||
char* qtype = NULL;
|
char* qtype = NULL;
|
||||||
struct ub_val_ctx* ctx = NULL;
|
struct ub_ctx* ctx = NULL;
|
||||||
int debuglevel = 0;
|
int debuglevel = 0;
|
||||||
|
|
||||||
ctx = ub_val_ctx_create();
|
ctx = ub_ctx_create();
|
||||||
if(!ctx) {
|
if(!ctx) {
|
||||||
fprintf(stderr, "error: out of memory\n");
|
fprintf(stderr, "error: out of memory\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
@ -408,7 +408,7 @@ int main(int argc, char* argv[])
|
||||||
debuglevel++;
|
debuglevel++;
|
||||||
if(debuglevel < 2)
|
if(debuglevel < 2)
|
||||||
debuglevel = 2; /* at least VERB_DETAIL */
|
debuglevel = 2; /* at least VERB_DETAIL */
|
||||||
ub_val_ctx_debuglevel(ctx, debuglevel);
|
ub_ctx_debuglevel(ctx, debuglevel);
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
qtype = optarg;
|
qtype = optarg;
|
||||||
|
|
@ -417,13 +417,13 @@ int main(int argc, char* argv[])
|
||||||
verb++;
|
verb++;
|
||||||
break;
|
break;
|
||||||
case 'y':
|
case 'y':
|
||||||
ub_val_ctx_add_ta(ctx, optarg);
|
ub_ctx_add_ta(ctx, optarg);
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
ub_val_ctx_add_ta_file(ctx, optarg);
|
ub_ctx_add_ta_file(ctx, optarg);
|
||||||
break;
|
break;
|
||||||
case 'F':
|
case 'F':
|
||||||
ub_val_ctx_trustedkeys(ctx, optarg);
|
ub_ctx_trustedkeys(ctx, optarg);
|
||||||
break;
|
break;
|
||||||
case '?':
|
case '?':
|
||||||
case 'h':
|
case 'h':
|
||||||
|
|
|
||||||
|
|
@ -56,7 +56,7 @@ struct lookinfo {
|
||||||
/** error code from libunbound */
|
/** error code from libunbound */
|
||||||
int err;
|
int err;
|
||||||
/** result from lookup */
|
/** result from lookup */
|
||||||
struct ub_val_result* result;
|
struct ub_result* result;
|
||||||
};
|
};
|
||||||
|
|
||||||
/** global variable to see how many queries we have left */
|
/** global variable to see how many queries we have left */
|
||||||
|
|
@ -85,7 +85,7 @@ print_result(struct lookinfo* info)
|
||||||
char buf[100];
|
char buf[100];
|
||||||
if(info->err) /* error (from libunbound) */
|
if(info->err) /* error (from libunbound) */
|
||||||
printf("%s: error %s\n", info->name,
|
printf("%s: error %s\n", info->name,
|
||||||
ub_val_strerror(info->err));
|
ub_strerror(info->err));
|
||||||
else if(!info->result)
|
else if(!info->result)
|
||||||
printf("%s: cancelled\n", info->name);
|
printf("%s: cancelled\n", info->name);
|
||||||
else if(info->result->havedata)
|
else if(info->result->havedata)
|
||||||
|
|
@ -105,9 +105,9 @@ print_result(struct lookinfo* info)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** this is a function of type ub_val_callback_t */
|
/** this is a function of type ub_callback_t */
|
||||||
static void
|
static void
|
||||||
lookup_is_done(void* mydata, int err, struct ub_val_result* result)
|
lookup_is_done(void* mydata, int err, struct ub_result* result)
|
||||||
{
|
{
|
||||||
/* cast mydata back to the correct type */
|
/* cast mydata back to the correct type */
|
||||||
struct lookinfo* info = (struct lookinfo*)mydata;
|
struct lookinfo* info = (struct lookinfo*)mydata;
|
||||||
|
|
@ -123,7 +123,7 @@ static void
|
||||||
checkerr(const char* desc, int err)
|
checkerr(const char* desc, int err)
|
||||||
{
|
{
|
||||||
if(err != 0) {
|
if(err != 0) {
|
||||||
printf("%s error: %s\n", desc, ub_val_strerror(err));
|
printf("%s error: %s\n", desc, ub_strerror(err));
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -143,7 +143,7 @@ struct ext_thr_info {
|
||||||
/** thread id */
|
/** thread id */
|
||||||
ub_thread_t tid;
|
ub_thread_t tid;
|
||||||
/** context */
|
/** context */
|
||||||
struct ub_val_ctx* ctx;
|
struct ub_ctx* ctx;
|
||||||
/** size of array to query */
|
/** size of array to query */
|
||||||
int argc;
|
int argc;
|
||||||
/** array of names to query */
|
/** array of names to query */
|
||||||
|
|
@ -157,7 +157,7 @@ static int q_is_localhost = 0;
|
||||||
|
|
||||||
/** check result structure for the 'correct' answer */
|
/** check result structure for the 'correct' answer */
|
||||||
static void
|
static void
|
||||||
ext_check_result(const char* desc, int err, struct ub_val_result* result)
|
ext_check_result(const char* desc, int err, struct ub_result* result)
|
||||||
{
|
{
|
||||||
checkerr(desc, err);
|
checkerr(desc, err);
|
||||||
if(result == NULL) {
|
if(result == NULL) {
|
||||||
|
|
@ -218,9 +218,9 @@ ext_check_result(const char* desc, int err, struct ub_val_result* result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** extended bg result callback, this function is ub_val_callback_t */
|
/** extended bg result callback, this function is ub_callback_t */
|
||||||
static void
|
static void
|
||||||
ext_callback(void* mydata, int err, struct ub_val_result* result)
|
ext_callback(void* mydata, int err, struct ub_result* result)
|
||||||
{
|
{
|
||||||
int* my_id = (int*)mydata;
|
int* my_id = (int*)mydata;
|
||||||
int doprint = 0;
|
int doprint = 0;
|
||||||
|
|
@ -243,7 +243,7 @@ ext_callback(void* mydata, int err, struct ub_val_result* result)
|
||||||
pi.err = 0;
|
pi.err = 0;
|
||||||
print_result(&pi);
|
print_result(&pi);
|
||||||
}
|
}
|
||||||
ub_val_resolve_free(result);
|
ub_resolve_free(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** extended thread worker */
|
/** extended thread worker */
|
||||||
|
|
@ -252,7 +252,7 @@ ext_thread(void* arg)
|
||||||
{
|
{
|
||||||
struct ext_thr_info* inf = (struct ext_thr_info*)arg;
|
struct ext_thr_info* inf = (struct ext_thr_info*)arg;
|
||||||
int i, r;
|
int i, r;
|
||||||
struct ub_val_result* result;
|
struct ub_result* result;
|
||||||
int* async_ids = NULL;
|
int* async_ids = NULL;
|
||||||
log_thread_set(&inf->thread_num);
|
log_thread_set(&inf->thread_num);
|
||||||
if(inf->thread_num > NUMTHR*2/3) {
|
if(inf->thread_num > NUMTHR*2/3) {
|
||||||
|
|
@ -264,32 +264,32 @@ ext_thread(void* arg)
|
||||||
}
|
}
|
||||||
for(i=0; i<inf->numq; i++) {
|
for(i=0; i<inf->numq; i++) {
|
||||||
if(async_ids) {
|
if(async_ids) {
|
||||||
r = ub_val_resolve_async(inf->ctx,
|
r = ub_resolve_async(inf->ctx,
|
||||||
inf->argv[i%inf->argc], LDNS_RR_TYPE_A,
|
inf->argv[i%inf->argc], LDNS_RR_TYPE_A,
|
||||||
LDNS_RR_CLASS_IN, &async_ids[i], ext_callback,
|
LDNS_RR_CLASS_IN, &async_ids[i], ext_callback,
|
||||||
&async_ids[i]);
|
&async_ids[i]);
|
||||||
checkerr("ub_val_resolve_async", r);
|
checkerr("ub_resolve_async", r);
|
||||||
if(i > 100) {
|
if(i > 100) {
|
||||||
r = ub_val_cancel(inf->ctx, async_ids[i-100]);
|
r = ub_cancel(inf->ctx, async_ids[i-100]);
|
||||||
checkerr("ub_val_cancel", r);
|
checkerr("ub_cancel", r);
|
||||||
async_ids[i-100]=0;
|
async_ids[i-100]=0;
|
||||||
}
|
}
|
||||||
} else if(inf->thread_num > NUMTHR/2) {
|
} else if(inf->thread_num > NUMTHR/2) {
|
||||||
/* async */
|
/* async */
|
||||||
r = ub_val_resolve_async(inf->ctx,
|
r = ub_resolve_async(inf->ctx,
|
||||||
inf->argv[i%inf->argc], LDNS_RR_TYPE_A,
|
inf->argv[i%inf->argc], LDNS_RR_TYPE_A,
|
||||||
LDNS_RR_CLASS_IN, NULL, ext_callback, NULL);
|
LDNS_RR_CLASS_IN, NULL, ext_callback, NULL);
|
||||||
checkerr("ub_val_resolve_async", r);
|
checkerr("ub_resolve_async", r);
|
||||||
} else {
|
} else {
|
||||||
/* blocking */
|
/* blocking */
|
||||||
r = ub_val_resolve(inf->ctx, inf->argv[i%inf->argc],
|
r = ub_resolve(inf->ctx, inf->argv[i%inf->argc],
|
||||||
LDNS_RR_TYPE_A, LDNS_RR_CLASS_IN, &result);
|
LDNS_RR_TYPE_A, LDNS_RR_CLASS_IN, &result);
|
||||||
ext_check_result("ub_val_resolve", r, result);
|
ext_check_result("ub_resolve", r, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(inf->thread_num > NUMTHR/2) {
|
if(inf->thread_num > NUMTHR/2) {
|
||||||
r = ub_val_wait(inf->ctx);
|
r = ub_wait(inf->ctx);
|
||||||
checkerr("ub_val_ctx_wait", r);
|
checkerr("ub_ctx_wait", r);
|
||||||
}
|
}
|
||||||
free(async_ids);
|
free(async_ids);
|
||||||
|
|
||||||
|
|
@ -298,7 +298,7 @@ ext_thread(void* arg)
|
||||||
|
|
||||||
/** perform extended threaded test */
|
/** perform extended threaded test */
|
||||||
static int
|
static int
|
||||||
ext_test(struct ub_val_ctx* ctx, int argc, char** argv)
|
ext_test(struct ub_ctx* ctx, int argc, char** argv)
|
||||||
{
|
{
|
||||||
struct ext_thr_info inf[NUMTHR];
|
struct ext_thr_info inf[NUMTHR];
|
||||||
int i;
|
int i;
|
||||||
|
|
@ -319,7 +319,7 @@ ext_test(struct ub_val_ctx* ctx, int argc, char** argv)
|
||||||
ub_thread_join(inf[i].tid);
|
ub_thread_join(inf[i].tid);
|
||||||
}
|
}
|
||||||
printf("extended test end\n");
|
printf("extended test end\n");
|
||||||
ub_val_ctx_delete(ctx);
|
ub_ctx_delete(ctx);
|
||||||
checklock_stop();
|
checklock_stop();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -333,7 +333,7 @@ extern char* optarg;
|
||||||
int main(int argc, char** argv)
|
int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
struct ub_val_ctx* ctx;
|
struct ub_ctx* ctx;
|
||||||
struct lookinfo* lookups;
|
struct lookinfo* lookups;
|
||||||
int i, r, cancel=0, blocking=0, ext=0;
|
int i, r, cancel=0, blocking=0, ext=0;
|
||||||
|
|
||||||
|
|
@ -341,7 +341,7 @@ int main(int argc, char** argv)
|
||||||
checklock_start();
|
checklock_start();
|
||||||
|
|
||||||
/* create context */
|
/* create context */
|
||||||
ctx = ub_val_ctx_create();
|
ctx = ub_ctx_create();
|
||||||
if(!ctx) {
|
if(!ctx) {
|
||||||
printf("could not create context, %s\n", strerror(errno));
|
printf("could not create context, %s\n", strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
|
|
@ -354,12 +354,12 @@ int main(int argc, char** argv)
|
||||||
while( (c=getopt(argc, argv, "bcdf:hr:tx")) != -1) {
|
while( (c=getopt(argc, argv, "bcdf:hr:tx")) != -1) {
|
||||||
switch(c) {
|
switch(c) {
|
||||||
case 'd':
|
case 'd':
|
||||||
r = ub_val_ctx_debuglevel(ctx, 3);
|
r = ub_ctx_debuglevel(ctx, 3);
|
||||||
checkerr("ub_val_ctx_debuglevel", r);
|
checkerr("ub_ctx_debuglevel", r);
|
||||||
break;
|
break;
|
||||||
case 't':
|
case 't':
|
||||||
r = ub_val_ctx_async(ctx, 1);
|
r = ub_ctx_async(ctx, 1);
|
||||||
checkerr("ub_val_ctx_async", r);
|
checkerr("ub_ctx_async", r);
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
cancel = 1;
|
cancel = 1;
|
||||||
|
|
@ -368,18 +368,18 @@ int main(int argc, char** argv)
|
||||||
blocking = 1;
|
blocking = 1;
|
||||||
break;
|
break;
|
||||||
case 'r':
|
case 'r':
|
||||||
r = ub_val_ctx_resolvconf(ctx, optarg);
|
r = ub_ctx_resolvconf(ctx, optarg);
|
||||||
if(r != 0) {
|
if(r != 0) {
|
||||||
printf("ub_val_ctx_resolvconf "
|
printf("ub_ctx_resolvconf "
|
||||||
"error: %s : %s\n",
|
"error: %s : %s\n",
|
||||||
ub_val_strerror(r),
|
ub_strerror(r),
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
r = ub_val_ctx_set_fwd(ctx, optarg);
|
r = ub_ctx_set_fwd(ctx, optarg);
|
||||||
checkerr("ub_val_ctx_set_fwd", r);
|
checkerr("ub_ctx_set_fwd", r);
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
ext = 1;
|
ext = 1;
|
||||||
|
|
@ -410,15 +410,15 @@ int main(int argc, char** argv)
|
||||||
lookups[i].name = argv[i];
|
lookups[i].name = argv[i];
|
||||||
if(blocking) {
|
if(blocking) {
|
||||||
fprintf(stderr, "lookup %s\n", argv[i]);
|
fprintf(stderr, "lookup %s\n", argv[i]);
|
||||||
r = ub_val_resolve(ctx, argv[i], LDNS_RR_TYPE_A,
|
r = ub_resolve(ctx, argv[i], LDNS_RR_TYPE_A,
|
||||||
LDNS_RR_CLASS_IN, &lookups[i].result);
|
LDNS_RR_CLASS_IN, &lookups[i].result);
|
||||||
checkerr("ub_val_resolve", r);
|
checkerr("ub_resolve", r);
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "start async lookup %s\n", argv[i]);
|
fprintf(stderr, "start async lookup %s\n", argv[i]);
|
||||||
r = ub_val_resolve_async(ctx, argv[i], LDNS_RR_TYPE_A,
|
r = ub_resolve_async(ctx, argv[i], LDNS_RR_TYPE_A,
|
||||||
LDNS_RR_CLASS_IN, &lookups[i], &lookup_is_done,
|
LDNS_RR_CLASS_IN, &lookups[i], &lookup_is_done,
|
||||||
&lookups[i].async_id);
|
&lookups[i].async_id);
|
||||||
checkerr("ub_val_resolve_async", r);
|
checkerr("ub_resolve_async", r);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(blocking)
|
if(blocking)
|
||||||
|
|
@ -426,8 +426,8 @@ int main(int argc, char** argv)
|
||||||
else if(cancel) {
|
else if(cancel) {
|
||||||
for(i=0; i<argc; i++) {
|
for(i=0; i<argc; i++) {
|
||||||
fprintf(stderr, "cancel %s\n", argv[i]);
|
fprintf(stderr, "cancel %s\n", argv[i]);
|
||||||
r = ub_val_cancel(ctx, lookups[i].async_id);
|
r = ub_cancel(ctx, lookups[i].async_id);
|
||||||
checkerr("ub_val_cancel", r);
|
checkerr("ub_cancel", r);
|
||||||
}
|
}
|
||||||
num_wait = 0;
|
num_wait = 0;
|
||||||
}
|
}
|
||||||
|
|
@ -437,8 +437,8 @@ int main(int argc, char** argv)
|
||||||
for(i=0; i<1000; i++) {
|
for(i=0; i<1000; i++) {
|
||||||
usleep(100000);
|
usleep(100000);
|
||||||
fprintf(stderr, "%g seconds passed\n", 0.1*(double)i);
|
fprintf(stderr, "%g seconds passed\n", 0.1*(double)i);
|
||||||
r = ub_val_process(ctx);
|
r = ub_process(ctx);
|
||||||
checkerr("ub_val_process", r);
|
checkerr("ub_process", r);
|
||||||
if(num_wait == 0)
|
if(num_wait == 0)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -451,10 +451,10 @@ int main(int argc, char** argv)
|
||||||
/* print lookup results */
|
/* print lookup results */
|
||||||
for(i=0; i<argc; i++) {
|
for(i=0; i<argc; i++) {
|
||||||
print_result(&lookups[i]);
|
print_result(&lookups[i]);
|
||||||
ub_val_resolve_free(lookups[i].result);
|
ub_resolve_free(lookups[i].result);
|
||||||
}
|
}
|
||||||
|
|
||||||
ub_val_ctx_delete(ctx);
|
ub_ctx_delete(ctx);
|
||||||
free(lookups);
|
free(lookups);
|
||||||
checklock_stop();
|
checklock_stop();
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue