xref: /netbsd-src/external/bsd/unbound/dist/dynlibmod/dynlibmod.h (revision d0eba39ba71d0ccd0f91ae4c5ff83442e84710bf)
1*d0eba39bSchristos /*
2*d0eba39bSchristos  * dynlibmod.h: module header file
3*d0eba39bSchristos  *
4*d0eba39bSchristos  * Copyright (c) 2019, Peter Munch-Ellingsen (peterme AT peterme.net)
5*d0eba39bSchristos  *
6*d0eba39bSchristos  * This software is open source.
7*d0eba39bSchristos  *
8*d0eba39bSchristos  * Redistribution and use in source and binary forms, with or without
9*d0eba39bSchristos  * modification, are permitted provided that the following conditions
10*d0eba39bSchristos  * are met:
11*d0eba39bSchristos  *
12*d0eba39bSchristos  *    * Redistributions of source code must retain the above copyright notice,
13*d0eba39bSchristos  *      this list of conditions and the following disclaimer.
14*d0eba39bSchristos  *
15*d0eba39bSchristos  *    * Redistributions in binary form must reproduce the above copyright notice,
16*d0eba39bSchristos  *      this list of conditions and the following disclaimer in the documentation
17*d0eba39bSchristos  *      and/or other materials provided with the distribution.
18*d0eba39bSchristos  *
19*d0eba39bSchristos  *    * Neither the name of the organization nor the names of its
20*d0eba39bSchristos  *      contributors may be used to endorse or promote products derived from this
21*d0eba39bSchristos  *      software without specific prior written permission.
22*d0eba39bSchristos  *
23*d0eba39bSchristos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24*d0eba39bSchristos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25*d0eba39bSchristos  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26*d0eba39bSchristos  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
27*d0eba39bSchristos  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28*d0eba39bSchristos  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29*d0eba39bSchristos  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30*d0eba39bSchristos  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31*d0eba39bSchristos  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32*d0eba39bSchristos  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33*d0eba39bSchristos  * POSSIBILITY OF SUCH DAMAGE.
34*d0eba39bSchristos  */
35*d0eba39bSchristos /**
36*d0eba39bSchristos  * \file
37*d0eba39bSchristos  * Dynamic loading module for unbound.  Loads dynamic library.
38*d0eba39bSchristos  */
39*d0eba39bSchristos #ifndef DYNLIBMOD_H
40*d0eba39bSchristos #define DYNLIBMOD_H
41*d0eba39bSchristos #include "util/module.h"
42*d0eba39bSchristos #include "services/outbound_list.h"
43*d0eba39bSchristos 
44*d0eba39bSchristos /**
45*d0eba39bSchristos  * Get the module function block.
46*d0eba39bSchristos  * @return: function block with function pointers to module methods.
47*d0eba39bSchristos  */
48*d0eba39bSchristos struct module_func_block* dynlibmod_get_funcblock(void);
49*d0eba39bSchristos 
50*d0eba39bSchristos /** dynlib module init */
51*d0eba39bSchristos int dynlibmod_init(struct module_env* env, int id);
52*d0eba39bSchristos 
53*d0eba39bSchristos /** dynlib module deinit */
54*d0eba39bSchristos void dynlibmod_deinit(struct module_env* env, int id);
55*d0eba39bSchristos 
56*d0eba39bSchristos /** dynlib module operate on a query */
57*d0eba39bSchristos void dynlibmod_operate(struct module_qstate* qstate, enum module_ev event,
58*d0eba39bSchristos 	int id, struct outbound_entry* outbound);
59*d0eba39bSchristos 
60*d0eba39bSchristos /** dynlib module  */
61*d0eba39bSchristos void dynlibmod_inform_super(struct module_qstate* qstate, int id,
62*d0eba39bSchristos 	struct module_qstate* super);
63*d0eba39bSchristos 
64*d0eba39bSchristos /** dynlib module cleanup query state */
65*d0eba39bSchristos void dynlibmod_clear(struct module_qstate* qstate, int id);
66*d0eba39bSchristos 
67*d0eba39bSchristos /** dynlib module alloc size routine */
68*d0eba39bSchristos size_t dynlibmod_get_mem(struct module_env* env, int id);
69*d0eba39bSchristos 
70*d0eba39bSchristos int dynlib_inplace_cb_reply_generic(struct query_info* qinfo,
71*d0eba39bSchristos     struct module_qstate* qstate, struct reply_info* rep, int rcode,
72*d0eba39bSchristos     struct edns_data* edns, struct edns_option** opt_list_out,
73*d0eba39bSchristos     struct comm_reply* repinfo, struct regional* region,
74*d0eba39bSchristos 	struct timeval* start_time, int id, void* callback);
75*d0eba39bSchristos 
76*d0eba39bSchristos int dynlib_inplace_cb_query_generic(struct query_info* qinfo, uint16_t flags,
77*d0eba39bSchristos     struct module_qstate* qstate, struct sockaddr_storage* addr,
78*d0eba39bSchristos     socklen_t addrlen, uint8_t* zone, size_t zonelen, struct regional* region,
79*d0eba39bSchristos     int id, void* callback);
80*d0eba39bSchristos 
81*d0eba39bSchristos int dynlib_inplace_cb_edns_back_parsed(struct module_qstate* qstate,
82*d0eba39bSchristos     int id, void* cb_args);
83*d0eba39bSchristos 
84*d0eba39bSchristos int dynlib_inplace_cb_query_response(struct module_qstate* qstate,
85*d0eba39bSchristos     struct dns_msg* response, int id, void* cb_args);
86*d0eba39bSchristos 
87*d0eba39bSchristos int
88*d0eba39bSchristos inplace_cb_register_wrapped(void* cb, enum inplace_cb_list_type type, void* cbarg,
89*d0eba39bSchristos   struct module_env* env, int id);
90*d0eba39bSchristos 
91*d0eba39bSchristos void
92*d0eba39bSchristos inplace_cb_delete_wrapped(struct module_env* env, enum inplace_cb_list_type type,
93*d0eba39bSchristos   int id);
94*d0eba39bSchristos 
95*d0eba39bSchristos struct cb_pair {
96*d0eba39bSchristos     void *cb;
97*d0eba39bSchristos     void *cb_arg;
98*d0eba39bSchristos };
99*d0eba39bSchristos 
100*d0eba39bSchristos /**
101*d0eba39bSchristos  * Global state for the module.
102*d0eba39bSchristos  */
103*d0eba39bSchristos 
104*d0eba39bSchristos typedef int (*func_init_t)(struct module_env*, int);
105*d0eba39bSchristos typedef void (*func_deinit_t)(struct module_env*, int);
106*d0eba39bSchristos typedef void (*func_operate_t)(struct module_qstate*, enum module_ev, int, struct outbound_entry*);
107*d0eba39bSchristos typedef void (*func_inform_t)(struct module_qstate*, int, struct module_qstate*);
108*d0eba39bSchristos typedef void (*func_clear_t)(struct module_qstate*, int);
109*d0eba39bSchristos typedef size_t (*func_get_mem_t)(struct module_env*, int);
110*d0eba39bSchristos typedef void (*inplace_cb_delete_wrapped_t)(struct module_env*, enum inplace_cb_list_type, int);
111*d0eba39bSchristos typedef int (*inplace_cb_register_wrapped_t)(void*, enum inplace_cb_list_type, void*, struct module_env*, int);
112*d0eba39bSchristos 
113*d0eba39bSchristos 
114*d0eba39bSchristos struct dynlibmod_env {
115*d0eba39bSchristos 	/** Dynamic library filename. */
116*d0eba39bSchristos 	const char* fname;
117*d0eba39bSchristos 	/** dynamic library handle */
118*d0eba39bSchristos 	void* dynamic_library;
119*d0eba39bSchristos 	/** Module init function */
120*d0eba39bSchristos 	func_init_t func_init;
121*d0eba39bSchristos 	/** Module deinit function */
122*d0eba39bSchristos 	func_deinit_t func_deinit;
123*d0eba39bSchristos 	/** Module operate function */
124*d0eba39bSchristos 	func_operate_t func_operate;
125*d0eba39bSchristos 	/** Module super_inform function */
126*d0eba39bSchristos 	func_inform_t func_inform;
127*d0eba39bSchristos 	/** Module clear function */
128*d0eba39bSchristos 	func_clear_t func_clear;
129*d0eba39bSchristos 	/** Module get_mem function */
130*d0eba39bSchristos 	func_get_mem_t func_get_mem;
131*d0eba39bSchristos   /** Wrapped inplace callback functions to circumvent callback whitelisting */
132*d0eba39bSchristos   inplace_cb_delete_wrapped_t inplace_cb_delete_wrapped;
133*d0eba39bSchristos   inplace_cb_register_wrapped_t inplace_cb_register_wrapped;
134*d0eba39bSchristos   /** Pointer to any data the dynamic library might want to keep */
135*d0eba39bSchristos   void *dyn_env;
136*d0eba39bSchristos };
137*d0eba39bSchristos 
138*d0eba39bSchristos 
139*d0eba39bSchristos #endif /* DYNLIBMOD_H */
140