gnunet_dns_service.h (6167B)
1 /* 2 This file is part of GNUnet 3 Copyright (C) 2012 GNUnet e.V. 4 5 GNUnet is free software: you can redistribute it and/or modify it 6 under the terms of the GNU Affero General Public License as published 7 by the Free Software Foundation, either version 3 of the License, 8 or (at your option) any later version. 9 10 GNUnet is distributed in the hope that it will be useful, but 11 WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Affero General Public License for more details. 14 15 You should have received a copy of the GNU Affero General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 SPDX-License-Identifier: AGPL3.0-or-later 19 */ 20 21 /** 22 * @addtogroup vpn_suite VPN services and libraries 23 * @{ 24 * 25 * @author Christian Grothoff 26 * 27 * @file 28 * API to access the DNS service. 29 * 30 * @defgroup dns DNS service 31 * 32 * @see [Documentation](https://gnunet.org/gnunet-service-dns) 33 * 34 * @{ 35 */ 36 #ifndef GNUNET_DNS_SERVICE_H 37 #define GNUNET_DNS_SERVICE_H 38 39 40 #include "gnunet_util_lib.h" 41 42 43 /** 44 * Opaque DNS handle 45 */ 46 struct GNUNET_DNS_Handle; 47 48 /** 49 * Handle to identify an individual DNS request. 50 */ 51 struct GNUNET_DNS_RequestHandle; 52 53 /** 54 * Flags that specify when to call the client's handler. 55 */ 56 enum GNUNET_DNS_Flags 57 { 58 /** 59 * Useless option: never call the client. 60 */ 61 GNUNET_DNS_FLAG_NEVER = 0, 62 63 /** 64 * Set this flag to see all requests first prior to resolution 65 * (for monitoring). Clients that set this flag must then 66 * call "GNUNET_DNS_request_forward" when they process a request 67 * for the first time. Calling "GNUNET_DNS_request_answer" is 68 * not allowed for MONITOR peers. 69 */ 70 GNUNET_DNS_FLAG_REQUEST_MONITOR = 1, 71 72 /** 73 * This client should be called on requests that have not 74 * yet been resolved as this client provides a resolution 75 * service. Note that this does not guarantee that the 76 * client will see all requests as another client might be 77 * called first and that client might have already done the 78 * resolution, in which case other pre-resolution clients 79 * won't see the request anymore. 80 */ 81 GNUNET_DNS_FLAG_PRE_RESOLUTION = 2, 82 83 /** 84 * This client wants to be called on the results of a DNS resolution 85 * (either resolved by PRE-RESOLUTION clients or the global DNS). 86 * The client then has a chance to modify the answer (or cause it to 87 * be dropped). There is no guarantee that other POST-RESOLUTION 88 * client's won't modify (or drop) the answer afterwards. 89 */ 90 GNUNET_DNS_FLAG_POST_RESOLUTION = 4, 91 92 /** 93 * Set this flag to see all requests just before they are 94 * returned to the network. Clients that set this flag must then 95 * call "GNUNET_DNS_request_forward" when they process a request 96 * for the last time. Calling "GNUNET_DNS_request_answer" is 97 * not allowed for MONITOR peers. 98 */ 99 GNUNET_DNS_FLAG_RESPONSE_MONITOR = 8 100 }; 101 102 103 /** 104 * Signature of a function that is called whenever the DNS service 105 * encounters a DNS request and needs to do something with it. The 106 * function has then the chance to generate or modify the response by 107 * calling one of the three "GNUNET_DNS_request_*" continuations. 108 * 109 * When a request is intercepted, this function is called first to 110 * give the client a chance to do the complete address resolution; 111 * "rdata" will be NULL for this first call for a DNS request, unless 112 * some other client has already filled in a response. 113 * 114 * If multiple clients exist, all of them are called before the global 115 * DNS. The global DNS is only called if all of the clients' 116 * functions call GNUNET_DNS_request_forward. Functions that call 117 * GNUNET_DNS_request_forward will be called again before a final 118 * response is returned to the application. If any of the clients' 119 * functions call GNUNET_DNS_request_drop, the response is dropped. 120 * 121 * @param cls closure 122 * @param rh request handle to user for reply 123 * @param request_length number of bytes in request 124 * @param request udp payload of the DNS request 125 */ 126 typedef void 127 (*GNUNET_DNS_RequestHandler)(void *cls, 128 struct GNUNET_DNS_RequestHandle *rh, 129 size_t request_length, 130 const char *request); 131 132 133 /** 134 * If a GNUNET_DNS_RequestHandler calls this function, the client 135 * has no desire to interfere with the request and it should 136 * continue to be processed normally. 137 * 138 * @param rh request that should now be forwarded 139 */ 140 void 141 GNUNET_DNS_request_forward (struct GNUNET_DNS_RequestHandle *rh); 142 143 144 /** 145 * If a GNUNET_DNS_RequestHandler calls this function, the request is 146 * to be dropped and no response should be generated. 147 * 148 * @param rh request that should now be dropped 149 */ 150 void 151 GNUNET_DNS_request_drop (struct GNUNET_DNS_RequestHandle *rh); 152 153 154 /** 155 * If a GNUNET_DNS_RequestHandler calls this function, the request is 156 * supposed to be answered with the data provided to this call (with 157 * the modifications the function might have made). The reply given 158 * must always be a valid DNS reply and not a mutated DNS request. 159 * 160 * @param rh request that should now be answered 161 * @param reply_length size of @a reply (uint16_t to force sane size) 162 * @param reply reply data 163 */ 164 void 165 GNUNET_DNS_request_answer (struct GNUNET_DNS_RequestHandle *rh, 166 uint16_t reply_length, 167 const char *reply); 168 169 170 /** 171 * Connect to the service-dns 172 * 173 * @param cfg configuration to use 174 * @param flags when to call @a rh 175 * @param rh function to call with DNS requests 176 * @param rh_cls closure to pass to @a rh 177 * @return DNS handle 178 */ 179 struct GNUNET_DNS_Handle * 180 GNUNET_DNS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, 181 enum GNUNET_DNS_Flags flags, 182 GNUNET_DNS_RequestHandler rh, 183 void *rh_cls); 184 185 186 /** 187 * Disconnect from the DNS service. 188 * 189 * @param dh DNS handle 190 */ 191 void 192 GNUNET_DNS_disconnect (struct GNUNET_DNS_Handle *dh); 193 194 195 #endif 196 197 /** @} */ /* end of group */ 198 199 /** @} */ /* end of group addition */