1/* $OpenBSD: unwind.h,v 1.56 2021/08/31 20:18:03 kn 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 ". 172800 IN DNSKEY 257 3 8 AwEAAaz/tAm8yTn4Mfeh5eyI96WSVexTBAvkMgJzkKTOiW1vkIbzxeF3+/4RgWOq7HrxRixHlFlExOLAJr5emLvN7SWXgnLh4+B5xQlNVz8Og8kvArMtNROxVQuCaSnIDdD5LKyWbRd2n9WGe2R8PzgCmr3EgVLrjyBxWezF0jLHwVN8efS3rCj/EWgvIWgb9tarpVUDK/b58Da+sqqls3eNbuv7pr+eoZG+SrDK6nWeL3c6H5Apxz7LjVc1uTIdsIXxuOLYA4/ilBmSVIzuDWfdRUfhHdY6+cn8HFRm+2hM8AnXGXws9555KrUB5qihylGa8subX2Nn6UwNR1AkUTV74bU=" 44 45#define IMSG_DATA_SIZE(imsg) ((imsg).hdr.len - IMSG_HEADER_SIZE) 46 47enum uw_resolver_type { 48 UW_RES_RECURSOR, 49 UW_RES_AUTOCONF, 50 UW_RES_ODOT_AUTOCONF, 51 UW_RES_ASR, 52 UW_RES_FORWARDER, 53 UW_RES_ODOT_FORWARDER, 54 UW_RES_DOT, 55 UW_RES_NONE 56}; 57 58static const char * const uw_resolver_type_str[] = { 59 "recursor", 60 "autoconf", 61 "oDoT-autoconf", 62 "stub", 63 "forwarder", 64 "oDoT-forwarder", 65 "DoT" 66}; 67 68static const char * const uw_resolver_type_short[] = { 69 "rec", 70 "auto", 71 "auto*", 72 "stub", 73 "forw", 74 "forw*", 75 "DoT" 76}; 77 78struct imsgev { 79 struct imsgbuf ibuf; 80 void (*handler)(int, short, void *); 81 struct event ev; 82 short events; 83}; 84 85enum imsg_type { 86 IMSG_NONE, 87 IMSG_CTL_LOG_VERBOSE, 88 IMSG_CTL_RELOAD, 89 IMSG_CTL_STATUS, 90 IMSG_CTL_AUTOCONF, 91 IMSG_CTL_MEM, 92 IMSG_RECONF_CONF, 93 IMSG_RECONF_BLOCKLIST_FILE, 94 IMSG_RECONF_FORWARDER, 95 IMSG_RECONF_DOT_FORWARDER, 96 IMSG_RECONF_FORCE, 97 IMSG_RECONF_END, 98 IMSG_UDP4SOCK, 99 IMSG_UDP6SOCK, 100 IMSG_TCP4SOCK, 101 IMSG_TCP6SOCK, 102 IMSG_ROUTESOCK, 103 IMSG_CONTROLFD, 104 IMSG_STARTUP, 105 IMSG_STARTUP_DONE, 106 IMSG_SOCKET_IPC_FRONTEND, 107 IMSG_SOCKET_IPC_RESOLVER, 108 IMSG_QUERY, 109 IMSG_ANSWER, 110 IMSG_CTL_RESOLVER_INFO, 111 IMSG_CTL_AUTOCONF_RESOLVER_INFO, 112 IMSG_CTL_MEM_INFO, 113 IMSG_CTL_END, 114 IMSG_HTTPSOCK, 115 IMSG_TAFD, 116 IMSG_NEW_TA, 117 IMSG_NEW_TAS_ABORT, 118 IMSG_NEW_TAS_DONE, 119 IMSG_NETWORK_CHANGED, 120 IMSG_BLFD, 121 IMSG_REPLACE_DNS, 122 IMSG_NEW_DNS64_PREFIXES_START, 123 IMSG_NEW_DNS64_PREFIX, 124 IMSG_NEW_DNS64_PREFIXES_DONE, 125 IMSG_CHANGE_AFS, 126}; 127 128struct uw_forwarder { 129 TAILQ_ENTRY(uw_forwarder) entry; 130 char ip[INET6_ADDRSTRLEN]; 131 char auth_name[NI_MAXHOST]; 132 uint16_t port; 133 uint32_t if_index; 134 int src; 135}; 136 137struct force_tree_entry { 138 RB_ENTRY(force_tree_entry) entry; 139 char domain[NI_MAXHOST]; 140 enum uw_resolver_type type; 141 int acceptbogus; 142}; 143 144RB_HEAD(force_tree, force_tree_entry); 145 146struct resolver_preference { 147 enum uw_resolver_type types[UW_RES_NONE]; 148 int len; 149}; 150 151TAILQ_HEAD(uw_forwarder_head, uw_forwarder); 152struct uw_conf { 153 struct uw_forwarder_head uw_forwarder_list; 154 struct uw_forwarder_head uw_dot_forwarder_list; 155 struct force_tree force; 156 struct resolver_preference res_pref; 157 int enabled_resolvers[UW_RES_NONE]; 158 char *blocklist_file; 159 int blocklist_log; 160}; 161 162struct query_imsg { 163 uint64_t id; 164 char qname[NI_MAXHOST]; 165 int t; 166 int c; 167 struct timespec tp; 168}; 169 170struct answer_header { 171 uint64_t id; 172 int srvfail; 173 int bogus; 174 int answer_len; 175}; 176 177extern uint32_t cmd_opts; 178 179/* unwind.c */ 180void main_imsg_compose_frontend(int, pid_t, void *, uint16_t); 181void main_imsg_compose_frontend_fd(int, pid_t, int); 182void main_imsg_compose_resolver(int, pid_t, void *, uint16_t); 183void merge_config(struct uw_conf *, struct uw_conf *); 184void imsg_event_add(struct imsgev *); 185int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, pid_t, 186 int, void *, uint16_t); 187void imsg_receive_config(struct imsg *, struct uw_conf **); 188 189struct uw_conf *config_new_empty(void); 190void config_clear(struct uw_conf *); 191 192/* printconf.c */ 193void print_config(struct uw_conf *); 194 195/* parse.y */ 196struct uw_conf *parse_config(char *); 197int cmdline_symset(char *); 198 199RB_PROTOTYPE(force_tree, force_tree_entry, entry, force_tree_cmp); 200