1 /* $NetBSD: remote.h,v 1.2 2025/01/26 16:25:28 christos Exp $ */ 2 3 /* 4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC") 5 * 6 * SPDX-License-Identifier: MPL-2.0 7 * 8 * This Source Code Form is subject to the terms of the Mozilla Public 9 * License, v. 2.0. If a copy of the MPL was not distributed with this 10 * file, you can obtain one at https://mozilla.org/MPL/2.0/. 11 * 12 * See the COPYRIGHT file distributed with this work for additional 13 * information regarding copyright ownership. 14 */ 15 16 #pragma once 17 18 /*! \file dns/remote.h */ 19 20 #include <stdbool.h> 21 22 #include <isc/lang.h> 23 #include <isc/magic.h> 24 #include <isc/mem.h> 25 26 #include <dns/types.h> 27 28 ISC_LANG_BEGINDECLS 29 30 #define DNS_REMOTE_MAGIC ISC_MAGIC('R', 'm', 't', 'e') 31 #define DNS_REMOTE_VALID(remote) ISC_MAGIC_VALID(remote, DNS_REMOTE_MAGIC) 32 33 struct dns_remote { 34 unsigned int magic; 35 isc_mem_t *mctx; 36 isc_sockaddr_t *addresses; 37 isc_sockaddr_t *sources; 38 dns_name_t **keynames; 39 dns_name_t **tlsnames; 40 bool *ok; 41 unsigned int addrcnt; 42 unsigned int curraddr; 43 }; 44 45 isc_sockaddr_t * 46 dns_remote_addresses(dns_remote_t *remote); 47 /*%< 48 * Return the addresses of the remote server. 49 * 50 * Requires: 51 * 'remote' is a valid remote structure. 52 */ 53 54 isc_sockaddr_t * 55 dns_remote_sources(dns_remote_t *remote); 56 /*%< 57 * Return the source addresses to be used for the remote server. 58 * 59 * Requires: 60 * 'remote' is a valid remote structure. 61 */ 62 63 unsigned int 64 dns_remote_count(dns_remote_t *remote); 65 /*%< 66 * Return the number of addresses of the remote server. 67 * 68 * Requires: 69 * 'remote' is a valid remote structure. 70 */ 71 72 dns_name_t ** 73 dns_remote_keynames(dns_remote_t *remote); 74 /*%< 75 * Return the keynames of the remote server. 76 * 77 * Requires: 78 * 'remote' is a valid remote structure. 79 */ 80 81 dns_name_t ** 82 dns_remote_tlsnames(dns_remote_t *remote); 83 /*%< 84 * Return the tlsnames of the remote server. 85 * 86 * Requires: 87 * 'remote' is a valid remote structure. 88 */ 89 90 void 91 dns_remote_init(dns_remote_t *remote, unsigned int count, 92 const isc_sockaddr_t *addrs, const isc_sockaddr_t *srcs, 93 dns_name_t **keynames, dns_name_t **tlsnames, bool mark, 94 isc_mem_t *mctx); 95 96 /*%< 97 * Initialize a remote server. Set the provided addresses (addrs), 98 * source addresses (srcs), key names (keynames) and tls names 99 * (tlsnames). Use the provided memory context (mctx) for allocations. 100 * If 'mark' is 'true', set up a list of boolean values to mark the 101 * server bad or good. 102 * 103 * Requires: 104 * 'remote' is a valid remote structure. 105 * 'mctx' is not NULL. 106 * 'addrs' is not NULL, or 'count' equals zero. 107 * 'keynames' and 'tlsnames' are not NULL, then 'count > 0'. 108 */ 109 110 void 111 dns_remote_clear(dns_remote_t *remote); 112 /*%< 113 * Clear remote server 'remote', free memory. 114 * 115 * Requires: 116 * 'remote' is a valid remote structure. 117 */ 118 119 bool 120 dns_remote_equal(dns_remote_t *a, dns_remote_t *b); 121 /*%< 122 * Compare two remote servers 'a' and 'b'. Check if the address 123 * count, the addresses, the key names and the tls names are 124 * the same. Return 'true' if so, 'false' otherwise. 125 * 126 * Requires: 127 * 'a' and 'b' are valid remote structures. 128 */ 129 130 void 131 dns_remote_reset(dns_remote_t *remote, bool clear_ok); 132 /*%< 133 * Reset the remote server, set the current address back to the 134 * first. If 'clear_ok' is 'true', clear any servers marked ok. 135 * 136 * Requires: 137 * 'remote' is a valid remote structure. 138 */ 139 140 void 141 dns_remote_next(dns_remote_t *remote, bool skip_good); 142 /*%< 143 * Skip to the next address. If 'skip_good' is 'true', skip over 144 * already addresses already considered good, whatever good means in the 145 * context of this remote server. 146 * 147 * Requires: 148 * 'remote' is a valid remote structure. 149 */ 150 151 isc_sockaddr_t 152 dns_remote_curraddr(dns_remote_t *remote); 153 /*%< 154 * Return the currently used address for this remote server. 155 * 156 * Requires: 157 * 'remote' is a valid remote structure. 158 * 'remote->addresses' is not NULL. 159 */ 160 161 isc_sockaddr_t 162 dns_remote_sourceaddr(dns_remote_t *remote); 163 /*%< 164 * Return the current source address. 165 * 166 * Requires: 167 * 'remote' is a valid remote structure. 168 * 'remote->sources' is not NULL. 169 */ 170 171 isc_sockaddr_t 172 dns_remote_addr(dns_remote_t *remote, unsigned int i); 173 /*%< 174 * Return the address at index 'i'. 175 * 176 * Requires: 177 * 'remote' is a valid remote structure. 178 * 'remote->addresses' is not NULL. 179 */ 180 181 dns_name_t * 182 dns_remote_keyname(dns_remote_t *remote); 183 /*%< 184 * Return the current key name. Returns NULL if we have iterated 185 * over all addresses already, or if keynames are not used. 186 * 187 * Requires: 188 * 'remote' is a valid remote structure. 189 */ 190 191 dns_name_t * 192 dns_remote_tlsname(dns_remote_t *remote); 193 /*%< 194 * Return the current tls name. Returns NULL if we have iterated 195 * over all addresses already, or if tlsnames are not used. 196 * 197 * Requires: 198 * 'remote' is a valid remote structure. 199 */ 200 201 void 202 dns_remote_mark(dns_remote_t *remote, bool good); 203 /*%< 204 * Mark the current address 'good' (or not good if 'good' is 205 * 'false'). 206 * 207 * Requires: 208 * 'remote' is a valid remote structure. 209 * The current address index is lower than the address count. 210 */ 211 212 bool 213 dns_remote_done(dns_remote_t *remote); 214 /*%< 215 * Return 'true' if we iterated over all addresses, 'false' otherwise. 216 * 217 * Requires: 218 * 'remote' is a valid remote structure. 219 */ 220 221 ISC_LANG_ENDDECLS 222