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 
107  struct alloc_cache superalloc;
109  struct module_env* env;
111  struct module_stack mods;
115  struct ub_randstate* seed_rnd;
116 
121 
125  size_t num_async;
134 };
135 
142 struct ctx_query {
144  struct rbnode_type node;
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 
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 
290  struct sldns_buffer* pkt, uint32_t* len);
291 
300 
307 
315 
324  uint8_t* p, uint32_t len);
325 
334  uint8_t* p, uint32_t len);
335 
345  uint8_t* p, uint32_t len, int* err);
346 
355  uint8_t* p, uint32_t len);
356 
357 #endif /* LIBUNBOUND_CONTEXT_H */
struct alloc_cache * context_obtain_alloc(struct ub_ctx *ctx, int locking)
int context_finalize(struct ub_ctx *ctx)
uint8_t * context_serialize_quit(uint32_t *len)
ub_ctx_cmd
Definition: context.h:210
@ UB_LIBCMD_CANCEL
Definition: context.h:216
@ UB_LIBCMD_NEWQUERY
Definition: context.h:214
@ UB_LIBCMD_QUIT
Definition: context.h:212
@ UB_LIBCMD_ANSWER
Definition: context.h:218
enum ub_ctx_cmd context_serial_getcmd(uint8_t *p, uint32_t len)
struct ctx_query * context_deserialize_new_query(struct ub_ctx *ctx, uint8_t *p, uint32_t len)
struct ctx_query * context_lookup_new_query(struct ub_ctx *ctx, uint8_t *p, uint32_t len)
void context_query_delete(struct ctx_query *q)
int context_query_cmp(const void *a, const void *b)
uint8_t * context_serialize_answer(struct ctx_query *q, int err, struct sldns_buffer *pkt, uint32_t *len)
ub_ctx_err
Definition: context.h:176
@ UB_SERVFAIL
Definition: context.h:187
@ UB_SOCKET
Definition: context.h:181
@ UB_PIPE
Definition: context.h:195
@ UB_FORKFAIL
Definition: context.h:189
@ UB_NOID
Definition: context.h:199
@ UB_SYNTAX
Definition: context.h:185
@ UB_NOERROR
Definition: context.h:178
@ UB_AFTERFINAL
Definition: context.h:191
@ UB_READFILE
Definition: context.h:197
@ UB_NOMEM
Definition: context.h:183
@ UB_INITFAIL
Definition: context.h:193
uint8_t * context_serialize_new_query(struct ctx_query *q, uint32_t *len)
void context_release_alloc(struct ub_ctx *ctx, struct alloc_cache *alloc, int locking)
struct ctx_query * context_deserialize_answer(struct ub_ctx *ctx, uint8_t *p, uint32_t len, int *err)
uint8_t * context_serialize_cancel(struct ctx_query *q, uint32_t *len)
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)
struct ctx_query * context_deserialize_cancel(struct ub_ctx *ctx, uint8_t *p, uint32_t len)
pid_t ub_thread_type
Definition: locks.h:283
int lock_basic_type
Definition: locks.h:269
const char * name
sec_status
Definition: packed_rrset.h:176
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
unsigned int uint32_t
Definition: stdint.h:126
unsigned char uint8_t
Definition: stdint.h:124
void * cb_arg
Definition: context.h:157
ub_event_callback_type cb_event
Definition: context.h:155
int querynum
Definition: context.h:146
size_t msg_len
Definition: context.h:162
uint8_t * msg
Definition: context.h:160
int cancelled
Definition: context.h:150
struct ub_result * res
Definition: context.h:170
ub_callback_type cb
Definition: context.h:153
struct rbnode_type node
Definition: context.h:144
int async
Definition: context.h:148
struct libworker * w
Definition: context.h:166
enum sec_status msg_security
Definition: context.h:164
Definition: tube.h:63
Definition: context.h:62
struct libworker * event_worker
Definition: context.h:120
struct tube * rr_pipe
Definition: context.h:71
lock_basic_type cfglock
Definition: context.h:75
lock_basic_type rrpipe_lock
Definition: context.h:69
struct module_stack mods
Definition: context.h:111
lock_basic_type qqpipe_lock
Definition: context.h:65
int created_bg
Definition: context.h:84
rbtree_type queries
Definition: context.h:133
struct alloc_cache * alloc_list
Definition: context.h:104
pid_t bg_pid
Definition: context.h:86
ub_thread_type bg_tid
Definition: context.h:88
int logfile_override
Definition: context.h:95
FILE * log_out
Definition: context.h:97
struct local_zones * local_zones
Definition: context.h:113
int finalized
Definition: context.h:81
int dothread
Definition: context.h:91
struct tube * qq_pipe
Definition: context.h:67
struct ub_event_base * event_base
Definition: context.h:118
int next_querynum
Definition: context.h:123
struct ub_randstate * seed_rnd
Definition: context.h:115
size_t num_async
Definition: context.h:125
int thr_next_num
Definition: context.h:93
struct alloc_cache superalloc
Definition: context.h:107
struct module_env * env
Definition: context.h:109
void(* ub_event_callback_type)(void *, int, void *, int, int, char *)
void(* ub_callback_type)(void *, int, struct ub_result *)
Definition: unbound.h:226