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