1 /* 2 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 3 * 4 * Permission to use, copy, modify, and/or distribute this software for any 5 * purpose with or without fee is hereby granted, provided that the above 6 * copyright notice and this permission notice appear in all copies. 7 * 8 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH 9 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 10 * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, 11 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 12 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 13 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 14 * PERFORMANCE OF THIS SOFTWARE. 15 */ 16 17 /* $Id: lwres.h,v 1.6 2024/08/14 17:38:57 florian Exp $ */ 18 19 #ifndef LWRES_LWRES_H 20 #define LWRES_LWRES_H 1 21 22 #include <sys/types.h> 23 #include <sys/socket.h> 24 25 #include <netinet/in.h> 26 #include <arpa/inet.h> 27 #include <net/if.h> 28 29 #include <stdio.h> 30 31 #include <lwres/result.h> 32 33 /*! \file lwres/lwres.h */ 34 35 /*! 36 * Design notes: 37 * 38 * Each opcode has two structures and three functions which operate on each 39 * structure. For example, using the "no operation/ping" opcode as an 40 * example: 41 * 42 * <ul><li>lwres_nooprequest_t: 43 * 44 * lwres_nooprequest_render() takes a lwres_nooprequest_t and 45 * and renders it into wire format, storing the allocated 46 * buffer information in a passed-in buffer. When this buffer 47 * is no longer needed, it must be freed by 48 * lwres_context_freemem(). All other memory used by the 49 * caller must be freed manually, including the 50 * lwres_nooprequest_t passed in.<br /><br /> 51 * 52 * lwres_nooprequest_parse() takes a wire format message and 53 * breaks it out into a lwres_nooprequest_t. The structure 54 * must be freed via lwres_nooprequest_free() when it is no longer 55 * needed.<br /><br /> 56 * 57 * lwres_nooprequest_free() releases into the lwres_context_t 58 * any space allocated during parsing.</li> 59 * 60 * <li>lwres_noopresponse_t: 61 * 62 * The functions used are similar to the three used for 63 * requests, just with different names.</li></ul> 64 * 65 * Typically, the client will use request_render, response_parse, and 66 * response_free, while the daemon will use request_parse, response_render, 67 * and request_free. 68 * 69 * The basic flow of a typical client is: 70 * 71 * \li fill in a request_t, and call the render function. 72 * 73 * \li Transmit the buffer returned to the daemon. 74 * 75 * \li Wait for a response. 76 * 77 * \li When a response is received, parse it into a response_t. 78 * 79 * \li free the request buffer using lwres_context_freemem(). 80 * 81 * \li free the response structure and its associated buffer using 82 * response_free(). 83 */ 84 85 #define LWRES_USEIPV4 0x0001 86 #define LWRES_USEIPV6 0x0002 87 88 /*% lwres_addr_t */ 89 typedef struct lwres_addr lwres_addr_t; 90 91 /*% lwres_addr */ 92 struct lwres_addr { 93 uint32_t family; 94 uint16_t length; 95 unsigned char address[sizeof(struct in6_addr)]; 96 uint32_t zone; 97 }; 98 99 /*! 100 * resolv.conf data 101 */ 102 103 #define LWRES_CONFMAXNAMESERVERS 3 /*%< max 3 "nameserver" entries */ 104 #define LWRES_CONFMAXSEARCH 8 /*%< max 8 domains in "search" entry */ 105 #define LWRES_CONFMAXLINELEN 256 /*%< max size of a line */ 106 107 /*% lwres_conf_t */ 108 typedef struct { 109 lwres_addr_t nameservers[LWRES_CONFMAXNAMESERVERS]; 110 uint8_t nsnext; /*%< index for next free slot */ 111 112 char *domainname; 113 114 char *search[LWRES_CONFMAXSEARCH]; 115 uint8_t searchnxt; /*%< index for next free slot */ 116 117 uint8_t ndots; /*%< set to n in 'options ndots:n' */ 118 int flags; 119 } lwres_conf_t; 120 121 #define LWRES_ADDRTYPE_V4 0x00000001U /*%< ipv4 */ 122 #define LWRES_ADDRTYPE_V6 0x00000002U /*%< ipv6 */ 123 124 #define LWRES_MAX_ALIASES 16 /*%< max # of aliases */ 125 #define LWRES_MAX_ADDRS 64 /*%< max # of addrs */ 126 127 extern const char *lwres_resolv_conf; 128 129 lwres_result_t 130 lwres_conf_parse(lwres_conf_t *confdata, const char *filename); 131 /**< 132 * parses a resolv.conf-format file and stores the results in the structure 133 * pointed to by *ctx. 134 * 135 * Requires: 136 * confdata != NULL 137 * filename != NULL && strlen(filename) > 0 138 * 139 * Returns: 140 * LWRES_R_SUCCESS on a successful parse. 141 * Anything else on error, although the structure may be partially filled 142 * in. 143 */ 144 145 void 146 lwres_conf_init(lwres_conf_t *confdata, int lwresflags); 147 /**< 148 * sets all internal fields to a default state. Used to initialize a new 149 * lwres_conf_t structure (not reset a used on). 150 * 151 * Requires: 152 * ctx != NULL 153 */ 154 155 void 156 lwres_conf_clear(lwres_conf_t *confdata); 157 /**< 158 * frees all internally allocated memory in confdata. Uses the memory 159 * routines supplied by ctx. 160 * 161 * Requires: 162 * confdata != NULL 163 */ 164 165 #endif /* LWRES_LWRES_H */ 166