Electroneum
context.h
Go to the documentation of this file.
1 /*
2  * libunbound/context.h - validating context for unbound internal use
3  *
4  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5  *
6  * This software is open source.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * Neither the name of the NLNET LABS nor the names of its contributors may
20  * be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 
41 #ifndef LIBUNBOUND_CONTEXT_H
42 #define LIBUNBOUND_CONTEXT_H
43 #include "util/locks.h"
44 #include "util/alloc.h"
45 #include "util/rbtree.h"
46 #include "services/modstack.h"
47 #include "libunbound/unbound.h"
49 #include "util/data/packed_rrset.h"
50 struct libworker;
51 struct tube;
52 struct sldns_buffer;
53 struct ub_event_base;
54 
62 struct ub_ctx {
63  /* --- pipes --- */
67  struct tube* qq_pipe;
71  struct tube* rr_pipe;
72 
73  /* --- shared data --- */
81  int finalized;
82 
86  pid_t bg_pid;
89 
91  int dothread;
97  FILE* log_out;
105 
109  struct module_env* env;
115  struct ub_randstate* seed_rnd;
116 
121 
125  size_t num_async;
134 };
135 
142 struct ctx_query {
146  int querynum;
148  int async;
151 
157  void* cb_arg;
158 
162  size_t msg_len;
166  struct libworker* w;
167 
170  struct ub_result* res;
171 };
172 
181  UB_SOCKET = -1,
183  UB_NOMEM = -2,
185  UB_SYNTAX = -3,
195  UB_PIPE = -8,
199  UB_NOID = -10
200 };
201 
219 };
220 
226 int context_finalize(struct ub_ctx* ctx);
227 
229 int context_query_cmp(const void* a, const void* b);
230 
235 void context_query_delete(struct ctx_query* q);
236 
248 struct ctx_query* context_new(struct ub_ctx* ctx, const char* name, int rrtype,
250  void* cbarg);
251 
258 struct alloc_cache* context_obtain_alloc(struct ub_ctx* ctx, int locking);
259 
266 void context_release_alloc(struct ub_ctx* ctx, struct alloc_cache* alloc,
267  int locking);
268 
278 
289 uint8_t* context_serialize_answer(struct ctx_query* q, int err,
290  struct sldns_buffer* pkt, uint32_t* len);
291 
300 
307 
315 
323 struct ctx_query* context_lookup_new_query(struct ub_ctx* ctx,
324  uint8_t* p, uint32_t len);
325 
333 struct ctx_query* context_deserialize_new_query(struct ub_ctx* ctx,
334  uint8_t* p, uint32_t len);
335 
344 struct ctx_query* context_deserialize_answer(struct ub_ctx* ctx,
345  uint8_t* p, uint32_t len, int* err);
346 
354 struct ctx_query* context_deserialize_cancel(struct ub_ctx* ctx,
355  uint8_t* p, uint32_t len);
356 
357 #endif /* LIBUNBOUND_CONTEXT_H */
struct ub_event_base * event_base
Definition: context.h:118
enum sec_status msg_security
Definition: context.h:164
ub_thread_type bg_tid
Definition: context.h:88
size_t msg_len
Definition: context.h:162
struct alloc_cache * alloc_list
Definition: context.h:104
ub_ctx_err
Definition: context.h:176
int logfile_override
Definition: context.h:95
int thr_next_num
Definition: context.h:93
struct libworker * event_worker
Definition: context.h:120
struct alloc_cache superalloc
Definition: context.h:107
enum ub_ctx_cmd context_serial_getcmd(uint8_t *p, uint32_t len)
ub_event_callback_type cb_event
Definition: context.h:155
struct ctx_query * context_deserialize_new_query(struct ub_ctx *ctx, uint8_t *p, uint32_t len)
void(* ub_event_callback_type)(void *, int, void *, int, int, char *)
unsigned char uint8_t
Definition: stdint.h:124
struct ub_result * res
Definition: context.h:170
ub_ctx_cmd
Definition: context.h:210
const char * name
int async
Definition: context.h:148
struct rbnode_type node
Definition: context.h:144
struct ctx_query * context_deserialize_cancel(struct ub_ctx *ctx, uint8_t *p, uint32_t len)
ub_callback_type cb
Definition: context.h:153
int next_querynum
Definition: context.h:123
FILE * log_out
Definition: context.h:97
lock_basic_type cfglock
Definition: context.h:75
void(* ub_callback_type)(void *, int, struct ub_result *)
Definition: unbound.h:226
void context_query_delete(struct ctx_query *q)
struct tube * qq_pipe
Definition: context.h:67
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)
unsigned int uint32_t
Definition: stdint.h:126
int cancelled
Definition: context.h:150
uint8_t * context_serialize_answer(struct ctx_query *q, int err, struct sldns_buffer *pkt, uint32_t *len)
int finalized
Definition: context.h:81
int lock_basic_type
Definition: locks.h:269
struct module_env * env
Definition: context.h:109
sec_status
Definition: packed_rrset.h:176
void context_release_alloc(struct ub_ctx *ctx, struct alloc_cache *alloc, int locking)
int created_bg
Definition: context.h:84
struct module_stack mods
Definition: context.h:111
pid_t ub_thread_type
Definition: locks.h:283
rbtree_type queries
Definition: context.h:133
struct libworker * w
Definition: context.h:166
void * cb_arg
Definition: context.h:157
uint8_t * context_serialize_new_query(struct ctx_query *q, uint32_t *len)
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
size_t num_async
Definition: context.h:125
uint8_t * msg
Definition: context.h:160
int querynum
Definition: context.h:146
struct ctx_query * context_lookup_new_query(struct ub_ctx *ctx, uint8_t *p, uint32_t len)
struct alloc_cache * context_obtain_alloc(struct ub_ctx *ctx, int locking)
uint8_t * context_serialize_cancel(struct ctx_query *q, uint32_t *len)
int context_finalize(struct ub_ctx *ctx)
struct tube * rr_pipe
Definition: context.h:71
int dothread
Definition: context.h:91
lock_basic_type qqpipe_lock
Definition: context.h:65
Definition: tube.h:63
struct local_zones * local_zones
Definition: context.h:113
pid_t bg_pid
Definition: context.h:86
struct ub_randstate * seed_rnd
Definition: context.h:115
lock_basic_type rrpipe_lock
Definition: context.h:69
uint8_t * context_serialize_quit(uint32_t *len)
struct ctx_query * context_deserialize_answer(struct ub_ctx *ctx, uint8_t *p, uint32_t len, int *err)
Definition: context.h:62
int context_query_cmp(const void *a, const void *b)