1 /*	$NetBSD: dlz_minimal.h,v 1.1.1.3 2014/12/10 03:34:31 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2011  Internet Systems Consortium, Inc. ("ISC")
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the
8  * above copyright notice and this permission notice appear in all
9  * copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR
12  * DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
13  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
14  * THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
15  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
16  * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
17  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
18  * USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 /*
22  * This header provides a minimal set of defines and typedefs needed
23  * for building an external DLZ module for bind9. When creating a new
24  * external DLZ driver, please copy this header into your own source
25  * tree.
26  */
27 
28 #ifndef DLZ_MINIMAL_H
29 #define DLZ_MINIMAL_H 1
30 
31 #include <sys/types.h>
32 #include <sys/socket.h>
33 #ifdef ISC_PLATFORM_HAVESYSUNH
34 #include <sys/un.h>
35 #endif
36 #include <net/if.h>
37 #include <netinet/in.h>
38 #include <arpa/inet.h>
39 
40 typedef unsigned int isc_result_t;
41 typedef int isc_boolean_t;
42 typedef uint32_t dns_ttl_t;
43 
44 /*
45  * Define DLZ_DLOPEN_VERSION to different values to use older versions
46  * of the interface
47  */
48 #ifndef DLZ_DLOPEN_VERSION
49 #define DLZ_DLOPEN_VERSION 3
50 #define DLZ_DLOPEN_AGE 0
51 #endif
52 
53 /* return these in flags from dlz_version() */
54 #define DNS_SDLZFLAG_THREADSAFE		0x00000001U
55 #define DNS_SDLZFLAG_RELATIVEOWNER	0x00000002U
56 #define DNS_SDLZFLAG_RELATIVERDATA	0x00000004U
57 
58 /* result codes */
59 #define ISC_R_SUCCESS			0
60 #define ISC_R_NOMEMORY			1
61 #define ISC_R_NOPERM			6
62 #define ISC_R_NOSPACE			19
63 #define ISC_R_NOTFOUND			23
64 #define ISC_R_FAILURE			25
65 #define ISC_R_NOTIMPLEMENTED		27
66 #define ISC_R_NOMORE			29
67 #define ISC_R_INVALIDFILE		30
68 #define ISC_R_UNEXPECTED		34
69 #define ISC_R_FILENOTFOUND		38
70 
71 /* boolean values */
72 #define ISC_TRUE 1
73 #define ISC_FALSE 0
74 
75 /* log levels */
76 #define ISC_LOG_INFO		(-1)
77 #define ISC_LOG_NOTICE		(-2)
78 #define ISC_LOG_WARNING 	(-3)
79 #define ISC_LOG_ERROR		(-4)
80 #define ISC_LOG_CRITICAL	(-5)
81 #define ISC_LOG_DEBUG(level)	(level)
82 
83 /* other useful definitions */
84 #define UNUSED(x) (void)(x)
85 
86 /* opaque structures */
87 typedef void *dns_sdlzlookup_t;
88 typedef void *dns_sdlzallnodes_t;
89 typedef void *dns_view_t;
90 typedef void *dns_dlzdb_t;
91 
92 #if DLZ_DLOPEN_VERSION > 1
93 /*
94  * Method and type definitions needed for retrieval of client info
95  * from the caller.
96  */
97 typedef struct isc_sockaddr {
98 	union {
99 		struct sockaddr         sa;
100 		struct sockaddr_in      sin;
101 		struct sockaddr_in6     sin6;
102 #ifdef ISC_PLATFORM_HAVESYSUNH
103 		struct sockaddr_un      sunix;
104 #endif
105 	}                               type;
106 	unsigned int                    length;
107 	void *                          link;
108 } isc_sockaddr_t;
109 
110 #define DNS_CLIENTINFO_VERSION 1
111 typedef struct dns_clientinfo {
112 	uint16_t version;
113 	void *data;
114 } dns_clientinfo_t;
115 
116 typedef isc_result_t (*dns_clientinfo_sourceip_t)(dns_clientinfo_t *client,
117 						  isc_sockaddr_t **addrp);
118 
119 #define DNS_CLIENTINFOMETHODS_VERSION 1
120 #define DNS_CLIENTINFOMETHODS_AGE 0
121 
122 typedef struct dns_clientinfomethods {
123 	uint16_t version;
124 	uint16_t age;
125 	dns_clientinfo_sourceip_t sourceip;
126 } dns_clientinfomethods_t;
127 #endif /* DLZ_DLOPEN_VERSION > 1 */
128 
129 /*
130  * Method definitions for callbacks provided by the dlopen driver
131  */
132 typedef void log_t(int level, const char *fmt, ...);
133 
134 typedef isc_result_t dns_sdlz_putrr_t(dns_sdlzlookup_t *lookup,
135 				      const char *type,
136 				      dns_ttl_t ttl,
137 				      const char *data);
138 
139 typedef isc_result_t dns_sdlz_putnamedrr_t(dns_sdlzallnodes_t *allnodes,
140 					   const char *name,
141 					   const char *type,
142 					   dns_ttl_t ttl,
143 					   const char *data);
144 
145 #if DLZ_DLOPEN_VERSION < 3
146 typedef isc_result_t dns_dlz_writeablezone_t(dns_view_t *view,
147 					     const char *zone_name);
148 #else /* DLZ_DLOPEN_VERSION >= 3 */
149 typedef isc_result_t dns_dlz_writeablezone_t(dns_view_t *view,
150 					     dns_dlzdb_t *dlzdb,
151 					     const char *zone_name);
152 #endif /* DLZ_DLOPEN_VERSION */
153 
154 /*
155  * prototypes for the functions you can include in your module
156  */
157 
158 /*
159  * dlz_version() is required for all DLZ external drivers. It should
160  * return DLZ_DLOPEN_VERSION.  'flags' is updated to indicate capabilities
161  * of the module.  In particular, if the module is thread-safe then it
162  * sets 'flags' to include DNS_SDLZFLAG_THREADSAFE.  Other capability
163  * flags may be added in the future.
164  */
165 int
166 dlz_version(unsigned int *flags);
167 
168 /*
169  * dlz_create() is required for all DLZ external drivers.
170  */
171 isc_result_t
172 dlz_create(const char *dlzname, unsigned int argc, char *argv[],
173 	   void **dbdata, ...);
174 
175 /*
176  * dlz_destroy() is optional, and will be called when the driver is
177  * unloaded if supplied
178  */
179 void
180 dlz_destroy(void *dbdata);
181 
182 /*
183  * dlz_findzonedb is required for all DLZ external drivers
184  */
185 #if DLZ_DLOPEN_VERSION < 3
186 isc_result_t
187 dlz_findzonedb(void *dbdata, const char *name);
188 #else /* DLZ_DLOPEN_VERSION >= 3 */
189 isc_result_t
190 dlz_findzonedb(void *dbdata, const char *name,
191 	       dns_clientinfomethods_t *methods,
192 	       dns_clientinfo_t *clientinfo);
193 #endif /* DLZ_DLOPEN_VERSION */
194 
195 /*
196  * dlz_lookup is required for all DLZ external drivers
197  */
198 #if DLZ_DLOPEN_VERSION == 1
199 isc_result_t
200 dlz_lookup(const char *zone, const char *name, void *dbdata,
201 	   dns_sdlzlookup_t *lookup);
202 #else /* DLZ_DLOPEN_VERSION > 1 */
203 isc_result_t
204 dlz_lookup(const char *zone, const char *name, void *dbdata,
205 	   dns_sdlzlookup_t *lookup,
206 	   dns_clientinfomethods_t *methods,
207 	   dns_clientinfo_t *clientinfo);
208 #endif /* DLZ_DLOPEN_VERSION */
209 
210 /*
211  * dlz_authority() is optional if dlz_lookup() supplies
212  * authority information (i.e., SOA, NS) for the dns record
213  */
214 isc_result_t
215 dlz_authority(const char *zone, void *dbdata, dns_sdlzlookup_t *lookup);
216 
217 /*
218  * dlz_allowzonexfr() is optional, and should be supplied if you want to
219  * support zone transfers
220  */
221 isc_result_t
222 dlz_allowzonexfr(void *dbdata, const char *name, const char *client);
223 
224 /*
225  * dlz_allnodes() is optional, but must be supplied if supply a
226  * dlz_allowzonexfr() function
227  */
228 isc_result_t
229 dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes);
230 
231 /*
232  * dlz_newversion() is optional. It should be supplied if you want to
233  * support dynamic updates.
234  */
235 isc_result_t
236 dlz_newversion(const char *zone, void *dbdata, void **versionp);
237 
238 /*
239  * dlz_closeversion() is optional, but must be supplied if you supply a
240  * dlz_newversion() function
241  */
242 void
243 dlz_closeversion(const char *zone, isc_boolean_t commit, void *dbdata,
244 		 void **versionp);
245 
246 /*
247  * dlz_configure() is optional, but must be supplied if you want to support
248  * dynamic updates
249  */
250 #if DLZ_DLOPEN_VERSION < 3
251 isc_result_t
252 dlz_configure(dns_view_t *view, void *dbdata);
253 #else /* DLZ_DLOPEN_VERSION >= 3 */
254 isc_result_t
255 dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *dbdata);
256 #endif /* DLZ_DLOPEN_VERSION */
257 
258 /*
259  * dlz_ssumatch() is optional, but must be supplied if you want to support
260  * dynamic updates
261  */
262 isc_boolean_t
263 dlz_ssumatch(const char *signer, const char *name, const char *tcpaddr,
264 	     const char *type, const char *key, uint32_t keydatalen,
265 	     uint8_t *keydata, void *dbdata);
266 
267 /*
268  * dlz_addrdataset() is optional, but must be supplied if you want to
269  * support dynamic updates
270  */
271 isc_result_t
272 dlz_addrdataset(const char *name, const char *rdatastr, void *dbdata,
273 		void *version);
274 
275 /*
276  * dlz_subrdataset() is optional, but must be supplied if you want to
277  * support dynamic updates
278  */
279 isc_result_t
280 dlz_subrdataset(const char *name, const char *rdatastr, void *dbdata,
281 		void *version);
282 
283 /*
284  * dlz_delrdataset() is optional, but must be supplied if you want to
285  * support dynamic updates
286  */
287 isc_result_t
288 dlz_delrdataset(const char *name, const char *type, void *dbdata,
289 		void *version);
290 
291 #endif /* DLZ_MINIMAL_H */
292