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