Electroneum
context.h File Reference
#include "util/locks.h"
#include "util/alloc.h"
#include "util/rbtree.h"
#include "services/modstack.h"
#include "libunbound/unbound.h"
#include "libunbound/unbound-event.h"
#include "util/data/packed_rrset.h"
Include dependency graph for context.h:

Go to the source code of this file.

Classes

struct  ub_ctx
 
struct  ctx_query
 

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, UB_NOID = -10
}
 
enum  ub_ctx_cmd { UB_LIBCMD_QUIT = 0, UB_LIBCMD_NEWQUERY, UB_LIBCMD_CANCEL, UB_LIBCMD_ANSWER }
 

Functions

int context_finalize (struct ub_ctx *ctx)
 
int context_query_cmp (const void *a, const void *b)
 
void context_query_delete (struct ctx_query *q)
 
struct ctx_querycontext_new (struct ub_ctx *ctx, const char *name, int rrtype, int rrclass, ub_callback_type cb, ub_event_callback_type cb_event, void *cbarg)
 
struct alloc_cachecontext_obtain_alloc (struct ub_ctx *ctx, int locking)
 
void context_release_alloc (struct ub_ctx *ctx, struct alloc_cache *alloc, int locking)
 
uint8_tcontext_serialize_new_query (struct ctx_query *q, uint32_t *len)
 
uint8_tcontext_serialize_answer (struct ctx_query *q, int err, struct sldns_buffer *pkt, uint32_t *len)
 
uint8_tcontext_serialize_cancel (struct ctx_query *q, uint32_t *len)
 
uint8_tcontext_serialize_quit (uint32_t *len)
 
enum ub_ctx_cmd context_serial_getcmd (uint8_t *p, uint32_t len)
 
struct ctx_querycontext_lookup_new_query (struct ub_ctx *ctx, uint8_t *p, uint32_t len)
 
struct ctx_querycontext_deserialize_new_query (struct ub_ctx *ctx, uint8_t *p, uint32_t len)
 
struct ctx_querycontext_deserialize_answer (struct ub_ctx *ctx, uint8_t *p, uint32_t len, int *err)
 
struct ctx_querycontext_deserialize_cancel (struct ub_ctx *ctx, uint8_t *p, uint32_t len)
 

Detailed Description

This file contains the validator context structure.

Definition in file context.h.

Enumeration Type Documentation

◆ ub_ctx_cmd

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.

Enumerator
UB_LIBCMD_QUIT 

QUIT

UB_LIBCMD_NEWQUERY 

New query, sent to bg worker

UB_LIBCMD_CANCEL 

Cancel query, sent to bg worker

UB_LIBCMD_ANSWER 

Query result, originates from bg worker

Definition at line 210 of file context.h.

◆ ub_ctx_err

enum ub_ctx_err

The error constants

Enumerator
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)

UB_NOID 

error async_id does not exist or result already been delivered

Definition at line 176 of file context.h.

176  {
178  UB_NOERROR = 0,
181  UB_SOCKET = -1,
183  UB_NOMEM = -2,
185  UB_SYNTAX = -3,
187  UB_SERVFAIL = -4,
189  UB_FORKFAIL = -5,
191  UB_AFTERFINAL = -6,
193  UB_INITFAIL = -7,
195  UB_PIPE = -8,
197  UB_READFILE = -9,
199  UB_NOID = -10
200 };

Function Documentation

◆ context_deserialize_answer()

struct ctx_query* context_deserialize_answer ( struct ub_ctx ctx,
uint8_t p,
uint32_t  len,
int *  err 
)

Deserialize an answer buffer.

Parameters
ctxcontext
pbuffer serialized.
lenlength of buffer.
errerror code to be returned to client is passed.
Returns
ctx_query with answer added or NULL for malloc failure.

◆ context_deserialize_cancel()

struct ctx_query* context_deserialize_cancel ( struct ub_ctx ctx,
uint8_t p,
uint32_t  len 
)

Deserialize a cancel buffer.

Parameters
ctxcontext
pbuffer serialized.
lenlength of buffer.
Returns
ctx_query to cancel or NULL for failure.

◆ context_deserialize_new_query()

struct ctx_query* context_deserialize_new_query ( struct ub_ctx ctx,
uint8_t p,
uint32_t  len 
)

Deserialize a new_query buffer.

Parameters
ctxcontext
pbuffer serialized.
lenlength of buffer.
Returns
new ctx_query or NULL for malloc failure.

◆ context_finalize()

int context_finalize ( struct ub_ctx ctx)

finalize a context.

Parameters
ctxcontext to finalize. creates shared data.
Returns
0 if OK, or errcode.

◆ context_lookup_new_query()

struct ctx_query* context_lookup_new_query ( struct ub_ctx ctx,
uint8_t p,
uint32_t  len 
)

Lookup query from new_query buffer.

Parameters
ctxcontext
pbuffer serialized.
lenlength of buffer.
Returns
looked up ctx_query or NULL for malloc failure.

◆ context_new()

struct ctx_query* context_new ( struct ub_ctx ctx,
const char *  name,
int  rrtype,
int  rrclass,
ub_callback_type  cb,
ub_event_callback_type  cb_event,
void *  cbarg 
)

Create new query in context, add to querynum list.

Parameters
ctxcontext
namequery name
rrtypetype
rrclassclass
cbcallback for async, or NULL for sync.
cb_eventevent callback for async, or NULL for sync.
cbarguser arg for async queries.
Returns
new ctx_query or NULL for malloc failure.

◆ context_obtain_alloc()

struct alloc_cache* context_obtain_alloc ( struct ub_ctx ctx,
int  locking 
)

Get a new alloc. Creates a new one or uses a cached one.

Parameters
ctxcontext
lockingif true, cfglock is locked while getting alloc.
Returns
an alloc, or NULL on mem error.

◆ context_query_cmp()

int context_query_cmp ( const void *  a,
const void *  b 
)

compare two ctx_query elements

◆ context_query_delete()

void context_query_delete ( struct ctx_query q)

delete context query

Parameters
qquery to delete, including message packet and prealloc result

◆ context_release_alloc()

void context_release_alloc ( struct ub_ctx ctx,
struct alloc_cache alloc,
int  locking 
)

Release an alloc. Puts it into the cache.

Parameters
ctxcontext
lockingif true, cfglock is locked while releasing alloc.
allocalloc to relinquish.

◆ context_serial_getcmd()

enum ub_ctx_cmd context_serial_getcmd ( uint8_t p,
uint32_t  len 
)

Obtain command code from serialized buffer

Parameters
pbuffer serialized.
lenlength of buffer.
Returns
command code or QUIT on error.

◆ context_serialize_answer()

uint8_t* context_serialize_answer ( struct ctx_query q,
int  err,
struct sldns_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'.

Parameters
qcontext query
errerror code to pass to client.
pktthe packet to add, can be NULL.
lenthe length of the allocation is returned.
Returns
: an alloc, or NULL on mem error.

◆ context_serialize_cancel()

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'

Parameters
qcontext query
lenthe length of the allocation is returned.
Returns
: an alloc, or NULL on mem error.

◆ context_serialize_new_query()

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'.

Parameters
qcontext query
lenthe length of the allocation is returned.
Returns
: an alloc, or NULL on mem error.

◆ context_serialize_quit()

uint8_t* context_serialize_quit ( uint32_t len)

Serialize a 'quit' command.

Parameters
lenthe length of the allocation is returned.
Returns
: an alloc, or NULL on mem error.