1 /* $OpenBSD: unwind.h,v 1.58 2025年09月15日 08:43:51 florian Exp $ */ 2 3 /* 4 * Copyright (c) 2018 Florian Obser <florian@openbsd.org> 5 * Copyright (c) 2004 Esben Norby <norby@openbsd.org> 6 * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> 7 * 8 * Permission to use, copy, modify, and distribute this software for any 9 * purpose with or without fee is hereby granted, provided that the above 10 * copyright notice and this permission notice appear in all copies. 11 * 12 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 13 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 14 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 15 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 16 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 17 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 18 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 19 */ 20 21#include <sys/types.h> 22#include <sys/tree.h> 23#include <netinet/in.h> /* INET6_ADDRSTRLEN */ 24#include <event.h> 25#include <imsg.h> 26#include <netdb.h> /* NI_MAXHOST */ 27#include <stdint.h> 28 29#ifndef nitems 30#define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) 31#endif 32 33#define _PATH_CONF_FILE "/etc/unwind.conf" 34#define _PATH_UNWIND_SOCKET "/dev/unwind.sock" 35#define UNWIND_USER "_unwind" 36 37#define OPT_VERBOSE 0x00000001 38#define OPT_VERBOSE2 0x00000002 39#define OPT_VERBOSE3 0x00000004 40#define OPT_NOACTION 0x00000008 41 42#define ROOT_DNSKEY_TTL 172800 /* TTL from authority */ 43#define KSK2017 ". IN DS 20326 8 2 E06D44B80B8F1D39A95C0B0D7C65D08458E880409BBC683457104237C7F8EC8D" 44#define KSK2024 ". IN DS 38696 8 2 683D2D0ACB8C9B712A1948B27F741219298D0A450D612C483AF444A4C0FB2B16" 45 46#define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE) 47 48 enum uw_resolver_type { 49 UW_RES_RECURSOR, 50 UW_RES_AUTOCONF, 51 UW_RES_ODOT_AUTOCONF, 52 UW_RES_ASR, 53 UW_RES_FORWARDER, 54 UW_RES_ODOT_FORWARDER, 55 UW_RES_DOT, 56 UW_RES_NONE 57}; 58 59 static const char * const uw_resolver_type_str[] = { 60 "recursor", 61 "autoconf", 62 "oDoT-autoconf", 63 "stub", 64 "forwarder", 65 "oDoT-forwarder", 66 "DoT" 67}; 68 69 static const char * const uw_resolver_type_short[] = { 70 "rec", 71 "auto", 72 "auto*", 73 "stub", 74 "forw", 75 "forw*", 76 "DoT" 77}; 78 79 struct imsgev { 80 struct imsgbuf ibuf; 81 void (*handler)(int, short, void *); 82 struct event ev; 83 short events; 84}; 85 86 enum imsg_type { 87 IMSG_NONE, 88 IMSG_CTL_LOG_VERBOSE, 89 IMSG_CTL_RELOAD, 90 IMSG_CTL_STATUS, 91 IMSG_CTL_AUTOCONF, 92 IMSG_CTL_MEM, 93 IMSG_RECONF_CONF, 94 IMSG_RECONF_BLOCKLIST_FILE, 95 IMSG_RECONF_FORWARDER, 96 IMSG_RECONF_DOT_FORWARDER, 97 IMSG_RECONF_FORCE, 98 IMSG_RECONF_END, 99 IMSG_UDP4SOCK, 100 IMSG_UDP6SOCK, 101 IMSG_TCP4SOCK, 102 IMSG_TCP6SOCK, 103 IMSG_ROUTESOCK, 104 IMSG_CONTROLFD, 105 IMSG_STARTUP, 106 IMSG_STARTUP_DONE, 107 IMSG_SOCKET_IPC_FRONTEND, 108 IMSG_SOCKET_IPC_RESOLVER, 109 IMSG_QUERY, 110 IMSG_ANSWER, 111 IMSG_CTL_RESOLVER_INFO, 112 IMSG_CTL_AUTOCONF_RESOLVER_INFO, 113 IMSG_CTL_MEM_INFO, 114 IMSG_CTL_END, 115 IMSG_HTTPSOCK, 116 IMSG_TAFD, 117 IMSG_NEW_TA, 118 IMSG_NEW_TAS_ABORT, 119 IMSG_NEW_TAS_DONE, 120 IMSG_NETWORK_CHANGED, 121 IMSG_BLFD, 122 IMSG_REPLACE_DNS, 123 IMSG_NEW_DNS64_PREFIXES_START, 124 IMSG_NEW_DNS64_PREFIX, 125 IMSG_NEW_DNS64_PREFIXES_DONE, 126 IMSG_CHANGE_AFS, 127}; 128 129 struct uw_forwarder { 130 TAILQ_ENTRY(uw_forwarder) entry; 131 char ip[INET6_ADDRSTRLEN]; 132 char auth_name[NI_MAXHOST]; 133 uint16_t port; 134 uint32_t if_index; 135 int src; 136}; 137 138 struct force_tree_entry { 139 RB_ENTRY(force_tree_entry) entry; 140 char domain[NI_MAXHOST]; 141 enum uw_resolver_type type; 142 int acceptbogus; 143}; 144 145 RB_HEAD(force_tree, force_tree_entry); 146 147 struct resolver_preference { 148 enum uw_resolver_type types[UW_RES_NONE]; 149 int len; 150}; 151 152 TAILQ_HEAD(uw_forwarder_head, uw_forwarder); 153 struct uw_conf { 154 struct uw_forwarder_head uw_forwarder_list; 155 struct uw_forwarder_head uw_dot_forwarder_list; 156 struct force_tree force; 157 struct resolver_preference res_pref; 158 int enabled_resolvers[UW_RES_NONE]; 159 int force_resolvers[UW_RES_NONE]; 160 char *blocklist_file; 161 int blocklist_log; 162}; 163 164 struct query_imsg { 165 uint64_t id; 166 char qname[NI_MAXHOST]; 167 int t; 168 int c; 169 struct timespec tp; 170}; 171 172 struct answer_header { 173 uint64_t id; 174 int srvfail; 175 int bogus; 176 int answer_len; 177}; 178 179 extern uint32_t cmd_opts; 180 181 /* unwind.c */ 182 void main_imsg_compose_frontend(int, pid_t, void *, uint16_t); 183 void main_imsg_compose_frontend_fd(int, pid_t, int); 184 void main_imsg_compose_resolver(int, pid_t, void *, uint16_t); 185 void merge_config(struct uw_conf *, struct uw_conf *); 186 void imsg_event_add(struct imsgev *); 187 int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t, 188 int, void *, uint16_t); 189 void imsg_receive_config(struct imsg *, struct uw_conf **); 190 191 struct uw_conf *config_new_empty(void); 192 void config_clear(struct uw_conf *); 193 194 /* printconf.c */ 195 void print_config(struct uw_conf *); 196 197 /* parse.y */ 198 struct uw_conf *parse_config(char *); 199 int cmdline_symset(char *); 200 201 RB_PROTOTYPE(force_tree, force_tree_entry, entry, force_tree_cmp); 202