#include "util/locks.h"
#include "util/alloc.h"
#include "util/rbtree.h"
#include "services/modstack.h"
#include "libunbound/unbound.h"
#include "util/data/packed_rrset.h"
Data Structures | |
struct | ub_ctx |
The context structure. More... | |
struct | ctx_query |
The queries outstanding for the libunbound resolver. More... | |
Enumerations | |
enum | ub_ctx_err { UB_NOERROR = 0, UB_SOCKET = -1, UB_NOMEM = -2, UB_SYNTAX = -3, UB_SERVFAIL = -4, UB_FORKFAIL = -5, UB_AFTERFINAL = -6, UB_INITFAIL = -7, UB_PIPE = -8, UB_READFILE = -9 } |
The error constants. More... | |
enum | ub_ctx_cmd { UB_LIBCMD_QUIT = 0, UB_LIBCMD_NEWQUERY, UB_LIBCMD_CANCEL, UB_LIBCMD_ANSWER } |
Command codes for libunbound pipe. More... | |
Functions | |
int | context_finalize (struct ub_ctx *ctx) |
finalize a context. | |
int | context_query_cmp (const void *a, const void *b) |
compare two ctx_query elements | |
void | context_query_delete (struct ctx_query *q) |
delete context query | |
struct ctx_query * | context_new (struct ub_ctx *ctx, char *name, int rrtype, int rrclass, ub_callback_t cb, void *cbarg) |
Create new query in context, add to querynum list. | |
struct alloc_cache * | context_obtain_alloc (struct ub_ctx *ctx, int locking) |
Get a new alloc. | |
void | context_release_alloc (struct ub_ctx *ctx, struct alloc_cache *alloc, int locking) |
Release an alloc. | |
uint8_t * | context_serialize_new_query (struct ctx_query *q, uint32_t *len) |
Serialize a context query that questions data. | |
uint8_t * | context_serialize_answer (struct ctx_query *q, int err, ldns_buffer *pkt, uint32_t *len) |
Serialize a context_query result to hand back to user. | |
uint8_t * | context_serialize_cancel (struct ctx_query *q, uint32_t *len) |
Serialize a query cancellation. | |
uint8_t * | context_serialize_quit (uint32_t *len) |
Serialize a 'quit' command. | |
enum ub_ctx_cmd | context_serial_getcmd (uint8_t *p, uint32_t len) |
Obtain command code from serialized buffer. | |
struct ctx_query * | context_lookup_new_query (struct ub_ctx *ctx, uint8_t *p, uint32_t len) |
Lookup query from new_query buffer. | |
struct ctx_query * | context_deserialize_new_query (struct ub_ctx *ctx, uint8_t *p, uint32_t len) |
Deserialize a new_query buffer. | |
struct ctx_query * | context_deserialize_answer (struct ub_ctx *ctx, uint8_t *p, uint32_t len, int *err) |
Deserialize an answer buffer. | |
struct ctx_query * | context_deserialize_cancel (struct ub_ctx *ctx, uint8_t *p, uint32_t len) |
Deserialize a cancel buffer. |
enum ub_ctx_err |
The error constants.
UB_NOERROR | no error |
UB_SOCKET |
socket operation.
Set to -1, so that if an error from _fd() is passed (-1) it gives a socket error. |
UB_NOMEM | alloc failure |
UB_SYNTAX | syntax error |
UB_SERVFAIL | DNS service failed. |
UB_FORKFAIL | fork() failed |
UB_AFTERFINAL | cfg change after finalize() |
UB_INITFAIL | initialization failed (bad settings) |
UB_PIPE | error in pipe communication with async bg worker |
UB_READFILE | error reading from file (resolv.conf) |
enum ub_ctx_cmd |
Command codes for libunbound pipe.
Serialization looks like this: o length (of remainder) uint32. o uint32 command code. o per command format.
int context_finalize | ( | struct ub_ctx * | ctx | ) |
finalize a context.
ctx,: | context to finalize. creates shared data. |
References module_env::alloc, module_env::cfg, config_apply(), ub_ctx::env, ub_ctx::finalized, HASH_DEFAULT_STARTARRAY, infra_adjust(), module_env::infra_cache, ub_ctx::local_zones, local_zones_apply_cfg(), local_zones_create(), log_file(), log_init(), ub_ctx::log_out, config_file::logfile, ub_ctx::logfile_override, ub_ctx::mods, modstack_setup(), config_file::module_conf, module_env::msg_cache, config_file::msg_cache_size, config_file::msg_cache_slabs, msgreply_sizefunc(), query_entry_delete(), query_info_compare(), reply_info_delete(), module_env::rrset_cache, rrset_cache_adjust(), slabhash::size, slabhash_create(), slabhash_delete(), slabhash_get_size(), UB_INITFAIL, UB_NOERROR, UB_NOMEM, config_file::use_syslog, config_file::verbosity, and verbosity.
Referenced by ub_resolve(), and ub_resolve_async().
void context_query_delete | ( | struct ctx_query * | q | ) |
delete context query
q,: | query to delete, including message packet and prealloc result |
References ctx_query::msg, ctx_query::res, and ub_resolve_free().
Referenced by add_bg_result(), delq(), libworker_bg_done_cb(), process_answer_detail(), ub_cancel(), ub_resolve(), and ub_resolve_async().
struct ctx_query* context_new | ( | struct ub_ctx * | ctx, | |
char * | name, | |||
int | rrtype, | |||
int | rrclass, | |||
ub_callback_t | cb, | |||
void * | cbarg | |||
) | [read] |
Create new query in context, add to querynum list.
ctx,: | context | |
name,: | query name | |
rrtype,: | type | |
rrclass,: | class | |
cb,: | callback for async, or NULL for sync. | |
cbarg,: | user arg for async queries. |
References ctx_query::async, ctx_query::cb, ctx_query::cb_arg, ub_ctx::cfglock, find_id(), rbnode_t::key, ctx_query::node, ub_ctx::num_async, ub_result::qclass, ub_result::qname, ub_result::qtype, ub_ctx::queries, ctx_query::querynum, rbtree_insert(), and ctx_query::res.
Referenced by ub_resolve(), and ub_resolve_async().
struct alloc_cache* context_obtain_alloc | ( | struct ub_ctx * | ctx, | |
int | locking | |||
) | [read] |
Get a new alloc.
Creates a new one or uses a cached one.
ctx,: | context | |
locking,: | if true, cfglock is locked while getting alloc. |
References alloc_init(), ub_ctx::alloc_list, ub_ctx::cfglock, alloc_cache::super, ub_ctx::superalloc, and ub_ctx::thr_next_num.
Referenced by libworker_setup().
void context_release_alloc | ( | struct ub_ctx * | ctx, | |
struct alloc_cache * | alloc, | |||
int | locking | |||
) |
Release an alloc.
Puts it into the cache.
ctx,: | context | |
locking,: | if true, cfglock is locked while releasing alloc. | |
alloc,: | alloc to relinquish. |
References ub_ctx::alloc_list, ub_ctx::cfglock, and alloc_cache::super.
Referenced by libworker_delete().
uint8_t* context_serialize_new_query | ( | struct ctx_query * | q, | |
uint32_t * | len | |||
) |
Serialize a context query that questions data.
This serializes the query name, type, ... As well as command code 'new_query'.
q,: | context query | |
len,: | the length of the allocation is returned. |
References ub_result::qclass, ub_result::qname, ub_result::qtype, ctx_query::querynum, ctx_query::res, and UB_LIBCMD_NEWQUERY.
Referenced by ub_resolve_async().
uint8_t* context_serialize_answer | ( | struct ctx_query * | q, | |
int | err, | |||
ldns_buffer * | pkt, | |||
uint32_t * | len | |||
) |
Serialize a context_query result to hand back to user.
This serializes the query name, type, ..., and result. As well as command code 'answer'.
q,: | context query | |
err,: | error code to pass to client. | |
pkt,: | the packet to add, can be NULL. | |
len,: | the length of the allocation is returned. |
References ctx_query::msg_security, ctx_query::querynum, and UB_LIBCMD_ANSWER.
Referenced by add_bg_result().
uint8_t* context_serialize_cancel | ( | struct ctx_query * | q, | |
uint32_t * | len | |||
) |
Serialize a query cancellation.
Serializes query async id as well as command code 'cancel'
q,: | context query | |
len,: | the length of the allocation is returned. |
References ctx_query::querynum, and UB_LIBCMD_CANCEL.
Referenced by ub_cancel().
uint8_t* context_serialize_quit | ( | uint32_t * | len | ) |
Serialize a 'quit' command.
len,: | the length of the allocation is returned. |
References UB_LIBCMD_QUIT.
enum ub_ctx_cmd context_serial_getcmd | ( | uint8_t * | p, | |
uint32_t | len | |||
) |
Obtain command code from serialized buffer.
p,: | buffer serialized. | |
len,: | length of buffer. |
References UB_LIBCMD_QUIT.
Referenced by libworker_do_cmd(), process_answer_detail(), and ub_ctx_delete().
struct ctx_query* context_lookup_new_query | ( | struct ub_ctx * | ctx, | |
uint8_t * | p, | |||
uint32_t | len | |||
) | [read] |
Lookup query from new_query buffer.
ctx,: | context | |
p,: | buffer serialized. | |
len,: | length of buffer. |
References ctx_query::async, log_assert, ub_ctx::queries, ctx_query::querynum, rbtree_search(), and UB_LIBCMD_NEWQUERY.
Referenced by handle_newq().
struct ctx_query* context_deserialize_new_query | ( | struct ub_ctx * | ctx, | |
uint8_t * | p, | |||
uint32_t | len | |||
) | [read] |
Deserialize a new_query buffer.
ctx,: | context | |
p,: | buffer serialized. | |
len,: | length of buffer. |
add to query list
References ctx_query::async, rbnode_t::key, log_assert, ctx_query::node, ub_ctx::num_async, ub_result::qclass, ub_result::qname, ub_result::qtype, ub_ctx::queries, ctx_query::querynum, rbtree_insert(), ctx_query::res, and UB_LIBCMD_NEWQUERY.
Referenced by handle_newq().
struct ctx_query* context_deserialize_answer | ( | struct ub_ctx * | ctx, | |
uint8_t * | p, | |||
uint32_t | len, | |||
int * | err | |||
) | [read] |
Deserialize an answer buffer.
ctx,: | context | |
p,: | buffer serialized. | |
len,: | length of buffer. | |
err,: | error code to be returned to client is passed. |
References log_assert, memdup(), ctx_query::msg, ctx_query::msg_len, ctx_query::msg_security, ub_ctx::queries, rbtree_search(), UB_LIBCMD_ANSWER, and UB_NOMEM.
Referenced by process_answer_detail().
struct ctx_query* context_deserialize_cancel | ( | struct ub_ctx * | ctx, | |
uint8_t * | p, | |||
uint32_t | len | |||
) | [read] |
Deserialize a cancel buffer.
ctx,: | context | |
p,: | buffer serialized. | |
len,: | length of buffer. |
References log_assert, ub_ctx::queries, rbtree_search(), and UB_LIBCMD_CANCEL.
Referenced by handle_cancel().