| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* dnsmasq is Copyright (c) 2000-2021 Simon Kelley |
| 2 | |
| 3 | This program is free software; you can redistribute it and/or modify |
| 4 | it under the terms of the GNU General Public License as published by |
| 5 | the Free Software Foundation; version 2 dated June, 1991, or |
| 6 | (at your option) version 3 dated 29 June, 2007. |
| 7 | |
| 8 | This program is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
| 12 | |
| 13 | You should have received a copy of the GNU General Public License |
| 14 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 | */ |
| 16 | |
| 17 | #define COPYRIGHT "Copyright (c) 2000-2021 Simon Kelley" |
| 18 | |
| 19 | /* We do defines that influence behavior of stdio.h, so complain |
| 20 | if included too early. */ |
| 21 | #ifdef _STDIO_H |
| 22 | # error "Header file stdio.h included too early!" |
| 23 | #endif |
| 24 | |
| 25 | #ifndef NO_LARGEFILE |
| 26 | /* Ensure we can use files >2GB (log files may grow this big) */ |
| 27 | # define _LARGEFILE_SOURCE 1 |
| 28 | # define _FILE_OFFSET_BITS 64 |
| 29 | #endif |
| 30 | |
| 31 | /* Get linux C library versions and define _GNU_SOURCE for kFreeBSD. */ |
| 32 | #if defined(__linux__) || defined(__GLIBC__) |
| 33 | # ifndef __ANDROID__ |
| 34 | # define _GNU_SOURCE |
| 35 | # endif |
| 36 | # include <features.h> |
| 37 | #endif |
| 38 | |
| 39 | /* Need these defined early */ |
| 40 | #if defined(__sun) || defined(__sun__) |
| 41 | # define _XPG4_2 |
| 42 | # define __EXTENSIONS__ |
| 43 | #endif |
| 44 | |
| 45 | #if (defined(__GNUC__) && __GNUC__ >= 3) || defined(__clang__) |
| 46 | #define ATTRIBUTE_NORETURN __attribute__ ((noreturn)) |
| 47 | #else |
| 48 | #define ATTRIBUTE_NORETURN |
| 49 | #endif |
| 50 | |
| 51 | /* get these before config.h for IPv6 stuff... */ |
| 52 | #include <sys/types.h> |
| 53 | #include <sys/socket.h> |
| 54 | |
| 55 | #ifdef __APPLE__ |
| 56 | /* Define before netinet/in.h to select API. OSX Lion onwards. */ |
| 57 | # define __APPLE_USE_RFC_3542 |
| 58 | #endif |
| 59 | #include <netinet/in.h> |
| 60 | |
| 61 | /* Also needed before config.h. */ |
| 62 | #include <getopt.h> |
| 63 | |
| 64 | #include "config.h" |
| 65 | #include "ip6addr.h" |
| 66 | #include "metrics.h" |
| 67 | |
| 68 | typedef unsigned char u8; |
| 69 | typedef unsigned short u16; |
| 70 | typedef unsigned int u32; |
| 71 | typedef unsigned long long u64; |
| 72 | |
| 73 | #define countof(x) (long)(sizeof(x) / sizeof(x[0])) |
| 74 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
| 75 | |
| 76 | #include "dns-protocol.h" |
| 77 | #include "dhcp-protocol.h" |
| 78 | #ifdef HAVE_DHCP6 |
| 79 | #include "dhcp6-protocol.h" |
| 80 | #include "radv-protocol.h" |
| 81 | #endif |
| 82 | |
| 83 | #define gettext_noop(S) (S) |
| 84 | #ifndef LOCALEDIR |
| 85 | # define _(S) (S) |
| 86 | #else |
| 87 | # include <libintl.h> |
| 88 | # include <locale.h> |
| 89 | # define _(S) gettext(S) |
| 90 | #endif |
| 91 | |
| 92 | #include <arpa/inet.h> |
| 93 | #include <sys/stat.h> |
| 94 | #include <sys/ioctl.h> |
| 95 | #if defined(HAVE_SOLARIS_NETWORK) |
| 96 | # include <sys/sockio.h> |
| 97 | #endif |
| 98 | #include <poll.h> |
| 99 | #include <sys/wait.h> |
| 100 | #include <sys/time.h> |
| 101 | #include <sys/un.h> |
| 102 | #include <limits.h> |
| 103 | #include <net/if.h> |
| 104 | #if defined(HAVE_SOLARIS_NETWORK) && !defined(ifr_mtu) |
| 105 | /* Some solaris net/if./h omit this. */ |
| 106 | # define ifr_mtu ifr_ifru.ifru_metric |
| 107 | #endif |
| 108 | #include <unistd.h> |
| 109 | #include <stdio.h> |
| 110 | #include <stdint.h> |
| 111 | #include <string.h> |
| 112 | #include <stdlib.h> |
| 113 | #include <fcntl.h> |
| 114 | #include <ctype.h> |
| 115 | #include <signal.h> |
| 116 | #include <stddef.h> |
| 117 | #include <time.h> |
| 118 | #include <errno.h> |
| 119 | #include <pwd.h> |
| 120 | #include <grp.h> |
| 121 | #include <stdarg.h> |
| 122 | #if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__sun__) || defined (__sun) || defined (__ANDROID__) |
| 123 | # include <netinet/if_ether.h> |
| 124 | #else |
| 125 | # include <net/ethernet.h> |
| 126 | #endif |
| 127 | #include <net/if_arp.h> |
| 128 | #include <netinet/in_systm.h> |
| 129 | #include <netinet/ip.h> |
| 130 | #include <netinet/ip6.h> |
| 131 | #include <netinet/ip_icmp.h> |
| 132 | #include <netinet/tcp.h> |
| 133 | #include <sys/uio.h> |
| 134 | #include <syslog.h> |
| 135 | #include <dirent.h> |
| 136 | #ifndef HAVE_LINUX_NETWORK |
| 137 | # include <net/if_dl.h> |
| 138 | #endif |
| 139 | |
| 140 | #if defined(HAVE_LINUX_NETWORK) |
| 141 | #include <linux/version.h> |
| 142 | #include <linux/sockios.h> |
| 143 | #include <linux/capability.h> |
| 144 | /* There doesn't seem to be a universally-available |
| 145 | userspace header for these. */ |
| 146 | extern int capset(cap_user_header_t header, cap_user_data_t data); |
| 147 | extern int capget(cap_user_header_t header, cap_user_data_t data); |
| 148 | #define LINUX_CAPABILITY_VERSION_1 0x19980330 |
| 149 | #define LINUX_CAPABILITY_VERSION_2 0x20071026 |
| 150 | #define LINUX_CAPABILITY_VERSION_3 0x20080522 |
| 151 | |
| 152 | #include <sys/prctl.h> |
| 153 | #elif defined(HAVE_SOLARIS_NETWORK) |
| 154 | #include <priv.h> |
| 155 | #endif |
| 156 | |
| 157 | /* Backwards compat with 2.83 */ |
| 158 | #if defined(HAVE_NETTLEHASH) |
| 159 | # define HAVE_CRYPTOHASH |
| 160 | #endif |
| 161 | #if defined(HAVE_DNSSEC) || defined(HAVE_CRYPTOHASH) |
| 162 | # include <nettle/nettle-meta.h> |
| 163 | #endif |
| 164 | |
| 165 | /* daemon is function in the C library.... */ |
| 166 | #define daemon dnsmasq_daemon |
| 167 | |
| 168 | #define ADDRSTRLEN INET6_ADDRSTRLEN |
| 169 | |
| 170 | /* Async event queue */ |
| 171 | struct event_desc { |
| 172 | int event, data, msg_sz; |
| 173 | }; |
| 174 | |
| 175 | #define EVENT_RELOAD 1 |
| 176 | #define EVENT_DUMP 2 |
| 177 | #define EVENT_ALARM 3 |
| 178 | #define EVENT_TERM 4 |
| 179 | #define EVENT_CHILD 5 |
| 180 | #define EVENT_REOPEN 6 |
| 181 | #define EVENT_EXITED 7 |
| 182 | #define EVENT_KILLED 8 |
| 183 | #define EVENT_EXEC_ERR 9 |
| 184 | #define EVENT_PIPE_ERR 10 |
| 185 | #define EVENT_USER_ERR 11 |
| 186 | #define EVENT_CAP_ERR 12 |
| 187 | #define EVENT_PIDFILE 13 |
| 188 | #define EVENT_HUSER_ERR 14 |
| 189 | #define EVENT_GROUP_ERR 15 |
| 190 | #define EVENT_DIE 16 |
| 191 | #define EVENT_LOG_ERR 17 |
| 192 | #define EVENT_FORK_ERR 18 |
| 193 | #define EVENT_LUA_ERR 19 |
| 194 | #define EVENT_TFTP_ERR 20 |
| 195 | #define EVENT_INIT 21 |
| 196 | #define EVENT_NEWADDR 22 |
| 197 | #define EVENT_NEWROUTE 23 |
| 198 | #define EVENT_TIME_ERR 24 |
| 199 | #define EVENT_SCRIPT_LOG 25 |
| 200 | #define EVENT_TIME 26 |
| 201 | |
| 202 | /* Exit codes. */ |
| 203 | #define EC_GOOD 0 |
| 204 | #define EC_BADCONF 1 |
| 205 | #define EC_BADNET 2 |
| 206 | #define EC_FILE 3 |
| 207 | #define EC_NOMEM 4 |
| 208 | #define EC_MISC 5 |
| 209 | #define EC_INIT_OFFSET 10 |
| 210 | |
| 211 | #define OPT_BOGUSPRIV 0 |
| 212 | #define OPT_FILTER 1 |
| 213 | #define OPT_LOG 2 |
| 214 | #define OPT_SELFMX 3 |
| 215 | #define OPT_NO_HOSTS 4 |
| 216 | #define OPT_NO_POLL 5 |
| 217 | #define OPT_DEBUG 6 |
| 218 | #define OPT_ORDER 7 |
| 219 | #define OPT_NO_RESOLV 8 |
| 220 | #define OPT_EXPAND 9 |
| 221 | #define OPT_LOCALMX 10 |
| 222 | #define OPT_NO_NEG 11 |
| 223 | #define OPT_NODOTS_LOCAL 12 |
| 224 | #define OPT_NOWILD 13 |
| 225 | #define OPT_ETHERS 14 |
| 226 | #define OPT_RESOLV_DOMAIN 15 |
| 227 | #define OPT_NO_FORK 16 |
| 228 | #define OPT_AUTHORITATIVE 17 |
| 229 | #define OPT_LOCALISE 18 |
| 230 | #define OPT_DBUS 19 |
| 231 | #define OPT_DHCP_FQDN 20 |
| 232 | #define OPT_NO_PING 21 |
| 233 | #define OPT_LEASE_RO 22 |
| 234 | #define OPT_ALL_SERVERS 23 |
| 235 | #define OPT_RELOAD 24 |
| 236 | #define OPT_LOCAL_REBIND 25 |
| 237 | #define OPT_TFTP_SECURE 26 |
| 238 | #define OPT_TFTP_NOBLOCK 27 |
| 239 | #define OPT_LOG_OPTS 28 |
| 240 | #define OPT_TFTP_APREF_IP 29 |
| 241 | #define OPT_NO_OVERRIDE 30 |
| 242 | #define OPT_NO_REBIND 31 |
| 243 | #define OPT_ADD_MAC 32 |
| 244 | #define OPT_DNSSEC_PROXY 33 |
| 245 | #define OPT_CONSEC_ADDR 34 |
| 246 | #define OPT_CONNTRACK 35 |
| 247 | #define OPT_FQDN_UPDATE 36 |
| 248 | #define OPT_RA 37 |
| 249 | #define OPT_TFTP_LC 38 |
| 250 | #define OPT_CLEVERBIND 39 |
| 251 | #define OPT_TFTP 40 |
| 252 | #define OPT_CLIENT_SUBNET 41 |
| 253 | #define OPT_QUIET_DHCP 42 |
| 254 | #define OPT_QUIET_DHCP6 43 |
| 255 | #define OPT_QUIET_RA 44 |
| 256 | #define OPT_DNSSEC_VALID 45 |
| 257 | #define OPT_DNSSEC_TIME 46 |
| 258 | #define OPT_DNSSEC_DEBUG 47 |
| 259 | #define OPT_DNSSEC_IGN_NS 48 |
| 260 | #define OPT_LOCAL_SERVICE 49 |
| 261 | #define OPT_LOOP_DETECT 50 |
| 262 | #define OPT_EXTRALOG 51 |
| 263 | #define OPT_TFTP_NO_FAIL 52 |
| 264 | #define OPT_SCRIPT_ARP 53 |
| 265 | #define OPT_MAC_B64 54 |
| 266 | #define OPT_MAC_HEX 55 |
| 267 | #define OPT_TFTP_APREF_MAC 56 |
| 268 | #define OPT_RAPID_COMMIT 57 |
| 269 | #define OPT_UBUS 58 |
| 270 | #define OPT_IGNORE_CLID 59 |
| 271 | #define OPT_SINGLE_PORT 60 |
| 272 | #define OPT_LEASE_RENEW 61 |
| 273 | #define OPT_LOG_DEBUG 62 |
| 274 | #define OPT_UMBRELLA 63 |
| 275 | #define OPT_UMBRELLA_DEVID 64 |
| 276 | #define OPT_CMARK_ALST_EN 65 |
| 277 | #define OPT_QUIET_TFTP 66 |
| 278 | #define OPT_LAST 67 |
| 279 | |
| 280 | #define OPTION_BITS (sizeof(unsigned int)*8) |
| 281 | #define OPTION_SIZE ( (OPT_LAST/OPTION_BITS)+((OPT_LAST%OPTION_BITS)!=0) ) |
| 282 | #define option_var(x) (daemon->options[(x) / OPTION_BITS]) |
| 283 | #define option_val(x) ((1u) << ((x) % OPTION_BITS)) |
| 284 | #define option_bool(x) (option_var(x) & option_val(x)) |
| 285 | |
| 286 | /* extra flags for my_syslog, we use facilities since they are known |
| 287 | not to occupy the same bits as priorities, no matter how syslog.h is set up. |
| 288 | MS_DEBUG messages are suppressed unless --log-debug is set. */ |
| 289 | #define MS_TFTP LOG_USER |
| 290 | #define MS_DHCP LOG_DAEMON |
| 291 | #define MS_SCRIPT LOG_MAIL |
| 292 | #define MS_DEBUG LOG_NEWS |
| 293 | |
| 294 | /* Note that this is used widely as a container for IPv4/IPv6 addresses, |
| 295 | so for that reason, was well as to avoid wasting memory in almost every |
| 296 | cache entry, the other variants should not be larger than |
| 297 | sizeof(struct in6_addr) - 16 bytes. |
| 298 | */ |
| 299 | union all_addr { |
| 300 | struct in_addr addr4; |
| 301 | struct in6_addr addr6; |
| 302 | struct { |
| 303 | union { |
| 304 | struct crec *cache; |
| 305 | char *name; |
| 306 | } target; |
| 307 | unsigned int uid; |
| 308 | int is_name_ptr; /* disciminates target union */ |
| 309 | } cname; |
| 310 | struct { |
| 311 | struct blockdata *keydata; |
| 312 | unsigned short keylen, flags, keytag; |
| 313 | unsigned char algo; |
| 314 | } key; |
| 315 | struct { |
| 316 | struct blockdata *keydata; |
| 317 | unsigned short keylen, keytag; |
| 318 | unsigned char algo; |
| 319 | unsigned char digest; |
| 320 | } ds; |
| 321 | struct { |
| 322 | struct blockdata *target; |
| 323 | unsigned short targetlen, srvport, priority, weight; |
| 324 | } srv; |
| 325 | /* for log_query */ |
| 326 | struct { |
| 327 | unsigned short keytag, algo, digest, rcode; |
| 328 | int ede; |
| 329 | } log; |
| 330 | }; |
| 331 | |
| 332 | |
| 333 | struct bogus_addr { |
| 334 | int is6, prefix; |
| 335 | union all_addr addr; |
| 336 | struct bogus_addr *next; |
| 337 | }; |
| 338 | |
| 339 | /* dns doctor param */ |
| 340 | struct doctor { |
| 341 | struct in_addr in, end, out, mask; |
| 342 | struct doctor *next; |
| 343 | }; |
| 344 | |
| 345 | struct mx_srv_record { |
| 346 | char *name, *target; |
| 347 | int issrv, srvport, priority, weight; |
| 348 | unsigned int offset; |
| 349 | struct mx_srv_record *next; |
| 350 | }; |
| 351 | |
| 352 | struct naptr { |
| 353 | char *name, *replace, *regexp, *services, *flags; |
| 354 | unsigned int order, pref; |
| 355 | struct naptr *next; |
| 356 | }; |
| 357 | |
| 358 | #ifndef NO_ID |
| 359 | #define TXT_STAT_CACHESIZE 1 |
| 360 | #define TXT_STAT_INSERTS 2 |
| 361 | #define TXT_STAT_EVICTIONS 3 |
| 362 | #define TXT_STAT_MISSES 4 |
| 363 | #define TXT_STAT_HITS 5 |
| 364 | #define TXT_STAT_AUTH 6 |
| 365 | #define TXT_STAT_SERVERS 7 |
| 366 | #endif |
| 367 | |
| 368 | struct txt_record { |
| 369 | char *name; |
| 370 | unsigned char *txt; |
| 371 | unsigned short class, len; |
| 372 | int stat; |
| 373 | struct txt_record *next; |
| 374 | }; |
| 375 | |
| 376 | struct ptr_record { |
| 377 | char *name, *ptr; |
| 378 | struct ptr_record *next; |
| 379 | }; |
| 380 | |
| 381 | struct cname { |
| 382 | int ttl, flag; |
| 383 | char *alias, *target; |
| 384 | struct cname *next, *targetp; |
| 385 | }; |
| 386 | |
| 387 | struct ds_config { |
| 388 | char *name, *digest; |
| 389 | int digestlen, class, algo, keytag, digest_type; |
| 390 | struct ds_config *next; |
| 391 | }; |
| 392 | |
| 393 | #define ADDRLIST_LITERAL 1 |
| 394 | #define ADDRLIST_IPV6 2 |
| 395 | #define ADDRLIST_REVONLY 4 |
| 396 | #define ADDRLIST_PREFIX 8 |
| 397 | #define ADDRLIST_WILDCARD 16 |
| 398 | #define ADDRLIST_DECLINED 32 |
| 399 | |
| 400 | struct addrlist { |
| 401 | union all_addr addr; |
| 402 | int flags, prefixlen; |
| 403 | time_t decline_time; |
| 404 | struct addrlist *next; |
| 405 | }; |
| 406 | |
| 407 | #define AUTH6 1 |
| 408 | #define AUTH4 2 |
| 409 | |
| 410 | struct auth_zone { |
| 411 | char *domain; |
| 412 | struct auth_name_list { |
| 413 | char *name; |
| 414 | int flags; |
| 415 | struct auth_name_list *next; |
| 416 | } *interface_names; |
| 417 | struct addrlist *subnet; |
| 418 | struct addrlist *exclude; |
| 419 | struct auth_zone *next; |
| 420 | }; |
| 421 | |
| 422 | #define HR_6 1 |
| 423 | #define HR_4 2 |
| 424 | |
| 425 | struct host_record { |
| 426 | int ttl, flags; |
| 427 | struct name_list { |
| 428 | char *name; |
| 429 | struct name_list *next; |
| 430 | } *names; |
| 431 | struct in_addr addr; |
| 432 | struct in6_addr addr6; |
| 433 | struct host_record *next; |
| 434 | }; |
| 435 | |
| 436 | #define IN4 1 |
| 437 | #define IN6 2 |
| 438 | #define INP4 4 |
| 439 | #define INP6 8 |
| 440 | |
| 441 | struct interface_name { |
| 442 | char *name; /* domain name */ |
| 443 | char *intr; /* interface name */ |
| 444 | int flags; |
| 445 | struct in_addr proto4; |
| 446 | struct in6_addr proto6; |
| 447 | struct addrlist *addr; |
| 448 | struct interface_name *next; |
| 449 | }; |
| 450 | |
| 451 | union bigname { |
| 452 | char name[MAXDNAME]; |
| 453 | union bigname *next; /* freelist */ |
| 454 | }; |
| 455 | |
| 456 | struct blockdata { |
| 457 | struct blockdata *next; |
| 458 | unsigned char key[KEYBLOCK_LEN]; |
| 459 | }; |
| 460 | |
| 461 | struct crec { |
| 462 | struct crec *next, *prev, *hash_next; |
| 463 | union all_addr addr; |
| 464 | time_t ttd; /* time to die */ |
| 465 | /* used as class if DNSKEY/DS, index to source for F_HOSTS */ |
| 466 | unsigned int uid; |
| 467 | unsigned int flags; |
| 468 | union { |
| 469 | char sname[SMALLDNAME]; |
| 470 | union bigname *bname; |
| 471 | char *namep; |
| 472 | } name; |
| 473 | }; |
| 474 | |
| 475 | #define SIZEOF_BARE_CREC (sizeof(struct crec) - SMALLDNAME) |
| 476 | #define SIZEOF_POINTER_CREC (sizeof(struct crec) + sizeof(char *) - SMALLDNAME) |
| 477 | |
| 478 | #define F_IMMORTAL (1u<<0) |
| 479 | #define F_NAMEP (1u<<1) |
| 480 | #define F_REVERSE (1u<<2) |
| 481 | #define F_FORWARD (1u<<3) |
| 482 | #define F_DHCP (1u<<4) |
| 483 | #define F_NEG (1u<<5) |
| 484 | #define F_HOSTS (1u<<6) |
| 485 | #define F_IPV4 (1u<<7) |
| 486 | #define F_IPV6 (1u<<8) |
| 487 | #define F_BIGNAME (1u<<9) |
| 488 | #define F_NXDOMAIN (1u<<10) |
| 489 | #define F_CNAME (1u<<11) |
| 490 | #define F_DNSKEY (1u<<12) |
| 491 | #define F_CONFIG (1u<<13) |
| 492 | #define F_DS (1u<<14) |
| 493 | #define F_DNSSECOK (1u<<15) |
| 494 | #define F_UPSTREAM (1u<<16) |
| 495 | #define F_RRNAME (1u<<17) |
| 496 | #define F_SERVER (1u<<18) |
| 497 | #define F_QUERY (1u<<19) |
| 498 | #define F_NOERR (1u<<20) |
| 499 | #define F_AUTH (1u<<21) |
| 500 | #define F_DNSSEC (1u<<22) |
| 501 | #define F_KEYTAG (1u<<23) |
| 502 | #define F_SECSTAT (1u<<24) |
| 503 | #define F_NO_RR (1u<<25) |
| 504 | #define F_IPSET (1u<<26) |
| 505 | #define F_NOEXTRA (1u<<27) |
| 506 | #define F_DOMAINSRV (1u<<28) |
| 507 | #define F_RCODE (1u<<29) |
| 508 | #define F_SRV (1u<<30) |
| 509 | |
| 510 | #define UID_NONE 0 |
| 511 | /* Values of uid in crecs with F_CONFIG bit set. */ |
| 512 | #define SRC_CONFIG 1 |
| 513 | #define SRC_HOSTS 2 |
| 514 | #define SRC_AH 3 |
| 515 | |
| 516 | |
| 517 | /* struct sockaddr is not large enough to hold any address, |
| 518 | and specifically not big enough to hold an IPv6 address. |
| 519 | Blech. Roll our own. */ |
| 520 | union mysockaddr { |
| 521 | struct sockaddr sa; |
| 522 | struct sockaddr_in in; |
| 523 | struct sockaddr_in6 in6; |
| 524 | }; |
| 525 | |
| 526 | /* bits in flag param to IPv6 callbacks from iface_enumerate() */ |
| 527 | #define IFACE_TENTATIVE 1 |
| 528 | #define IFACE_DEPRECATED 2 |
| 529 | #define IFACE_PERMANENT 4 |
| 530 | |
| 531 | |
| 532 | /* The actual values here matter, since we sort on them to get records in the order |
| 533 | IPv6 addr, IPv4 addr, all zero return, no-data return, send upstream. */ |
| 534 | #define SERV_LITERAL_ADDRESS 1 /* addr is the answer, or NoDATA is the answer, depending on the next three flags */ |
| 535 | #define SERV_ALL_ZEROS 2 /* return all zeros for A and AAAA */ |
| 536 | #define SERV_4ADDR 4 /* addr is IPv4 */ |
| 537 | #define SERV_6ADDR 8 /* addr is IPv6 */ |
| 538 | #define SERV_HAS_SOURCE 16 /* source address defined */ |
| 539 | #define SERV_FOR_NODOTS 32 /* server for names with no domain part only */ |
| 540 | #define SERV_WARNED_RECURSIVE 64 /* avoid warning spam */ |
| 541 | #define SERV_FROM_DBUS 128 /* 1 if source is DBus */ |
| 542 | #define SERV_MARK 256 /* for mark-and-delete and log code */ |
| 543 | #define SERV_WILDCARD 512 /* domain has leading '*' */ |
| 544 | #define SERV_USE_RESOLV 1024 /* forward this domain in the normal way */ |
| 545 | #define SERV_FROM_RESOLV 2048 /* 1 for servers from resolv, 0 for command line. */ |
| 546 | #define SERV_FROM_FILE 4096 /* read from --servers-file */ |
| 547 | #define SERV_LOOP 8192 /* server causes forwarding loop */ |
| 548 | #define SERV_DO_DNSSEC 16384 /* Validate DNSSEC when using this server */ |
| 549 | #define SERV_GOT_TCP 32768 /* Got some data from the TCP connection */ |
| 550 | |
| 551 | struct serverfd { |
| 552 | int fd; |
| 553 | union mysockaddr source_addr; |
| 554 | char interface[IF_NAMESIZE+1]; |
| 555 | unsigned int ifindex, used, preallocated; |
| 556 | struct serverfd *next; |
| 557 | }; |
| 558 | |
| 559 | struct randfd { |
| 560 | struct server *serv; |
| 561 | int fd; |
| 562 | unsigned short refcount; /* refcount == 0xffff means overflow record. */ |
| 563 | }; |
| 564 | |
| 565 | struct randfd_list { |
| 566 | struct randfd *rfd; |
| 567 | struct randfd_list *next; |
| 568 | }; |
| 569 | |
| 570 | |
| 571 | struct server { |
| 572 | u16 flags, domain_len; |
| 573 | char *domain; |
| 574 | struct server *next; |
| 575 | int serial, arrayposn; |
| 576 | int last_server; |
| 577 | union mysockaddr addr, source_addr; |
| 578 | char interface[IF_NAMESIZE+1]; |
| 579 | unsigned int ifindex; /* corresponding to interface, above */ |
| 580 | struct serverfd *sfd; |
| 581 | int tcpfd, edns_pktsz; |
| 582 | time_t pktsz_reduced; |
| 583 | unsigned int queries, failed_queries; |
| 584 | time_t forwardtime; |
| 585 | int forwardcount; |
| 586 | #ifdef HAVE_LOOP |
| 587 | u32 uid; |
| 588 | #endif |
| 589 | }; |
| 590 | |
| 591 | /* First four fields must match struct server in next three definitions.. */ |
| 592 | struct serv_addr4 { |
| 593 | u16 flags, domain_len; |
| 594 | char *domain; |
| 595 | struct server *next; |
| 596 | struct in_addr addr; |
| 597 | }; |
| 598 | |
| 599 | struct serv_addr6 { |
| 600 | u16 flags, domain_len; |
| 601 | char *domain; |
| 602 | struct server *next; |
| 603 | struct in6_addr addr; |
| 604 | }; |
| 605 | |
| 606 | struct serv_local { |
| 607 | u16 flags, domain_len; |
| 608 | char *domain; |
| 609 | struct server *next; |
| 610 | }; |
| 611 | |
| 612 | struct ipsets { |
| 613 | char **sets; |
| 614 | char *domain; |
| 615 | struct ipsets *next; |
| 616 | }; |
| 617 | |
| 618 | struct allowlist { |
| 619 | u32 mark, mask; |
| 620 | char **patterns; |
| 621 | struct allowlist *next; |
| 622 | }; |
| 623 | |
| 624 | struct irec { |
| 625 | union mysockaddr addr; |
| 626 | struct in_addr netmask; /* only valid for IPv4 */ |
| 627 | int tftp_ok, dhcp_ok, mtu, done, warned, dad, dns_auth, index, multicast_done, found, label; |
| 628 | char *name; |
| 629 | struct irec *next; |
| 630 | }; |
| 631 | |
| 632 | struct listener { |
| 633 | int fd, tcpfd, tftpfd, used; |
| 634 | union mysockaddr addr; |
| 635 | struct irec *iface; /* only sometimes valid for non-wildcard */ |
| 636 | struct listener *next; |
| 637 | }; |
| 638 | |
| 639 | /* interface and address parms from command line. */ |
| 640 | struct iname { |
| 641 | char *name; |
| 642 | union mysockaddr addr; |
| 643 | int used; |
| 644 | struct iname *next; |
| 645 | }; |
| 646 | |
| 647 | /* subnet parameters from command line */ |
| 648 | struct mysubnet { |
| 649 | union mysockaddr addr; |
| 650 | int addr_used; |
| 651 | int mask; |
| 652 | }; |
| 653 | |
| 654 | /* resolv-file parms from command-line */ |
| 655 | struct resolvc { |
| 656 | struct resolvc *next; |
| 657 | int is_default, logged; |
| 658 | time_t mtime; |
| 659 | char *name; |
| 660 | #ifdef HAVE_INOTIFY |
| 661 | int wd; /* inotify watch descriptor */ |
| 662 | char *file; /* pointer to file part if path */ |
| 663 | #endif |
| 664 | }; |
| 665 | |
| 666 | /* adn-hosts parms from command-line (also dhcp-hostsfile and dhcp-optsfile and dhcp-hostsdir*/ |
| 667 | #define AH_DIR 1 |
| 668 | #define AH_INACTIVE 2 |
| 669 | #define AH_WD_DONE 4 |
| 670 | #define AH_HOSTS 8 |
| 671 | #define AH_DHCP_HST 16 |
| 672 | #define AH_DHCP_OPT 32 |
| 673 | struct hostsfile { |
| 674 | struct hostsfile *next; |
| 675 | int flags; |
| 676 | char *fname; |
| 677 | #ifdef HAVE_INOTIFY |
| 678 | int wd; /* inotify watch descriptor */ |
| 679 | #endif |
| 680 | unsigned int index; /* matches to cache entries for logging */ |
| 681 | }; |
| 682 | |
| 683 | /* packet-dump flags */ |
| 684 | #define DUMP_QUERY 0x0001 |
| 685 | #define DUMP_REPLY 0x0002 |
| 686 | #define DUMP_UP_QUERY 0x0004 |
| 687 | #define DUMP_UP_REPLY 0x0008 |
| 688 | #define DUMP_SEC_QUERY 0x0010 |
| 689 | #define DUMP_SEC_REPLY 0x0020 |
| 690 | #define DUMP_BOGUS 0x0040 |
| 691 | #define DUMP_SEC_BOGUS 0x0080 |
| 692 | |
| 693 | /* DNSSEC status values. */ |
| 694 | #define STAT_SECURE 0x10000 |
| 695 | #define STAT_INSECURE 0x20000 |
| 696 | #define STAT_BOGUS 0x30000 |
| 697 | #define STAT_NEED_DS 0x40000 |
| 698 | #define STAT_NEED_KEY 0x50000 |
| 699 | #define STAT_TRUNCATED 0x60000 |
| 700 | #define STAT_SECURE_WILDCARD 0x70000 |
| 701 | #define STAT_OK 0x80000 |
| 702 | #define STAT_ABANDONED 0x90000 |
| 703 | |
| 704 | #define DNSSEC_FAIL_NYV 0x0001 /* key not yet valid */ |
| 705 | #define DNSSEC_FAIL_EXP 0x0002 /* key expired */ |
| 706 | #define DNSSEC_FAIL_INDET 0x0004 /* indetermined */ |
| 707 | #define DNSSEC_FAIL_NOKEYSUP 0x0008 /* no supported key algo. */ |
| 708 | #define DNSSEC_FAIL_NOSIG 0x0010 /* No RRsigs */ |
| 709 | #define DNSSEC_FAIL_NOZONE 0x0020 /* No Zone bit set */ |
| 710 | #define DNSSEC_FAIL_NONSEC 0x0040 /* No NSEC */ |
| 711 | #define DNSSEC_FAIL_NODSSUP 0x0080 /* no supported DS algo. */ |
| 712 | #define DNSSEC_FAIL_NOKEY 0x0100 /* no DNSKEY */ |
| 713 | |
| 714 | #define STAT_ISEQUAL(a, b) (((a) & 0xffff0000) == (b)) |
| 715 | |
| 716 | #define FREC_NOREBIND 1 |
| 717 | #define FREC_CHECKING_DISABLED 2 |
| 718 | #define FREC_HAS_SUBNET 4 |
| 719 | #define FREC_DNSKEY_QUERY 8 |
| 720 | #define FREC_DS_QUERY 16 |
| 721 | #define FREC_AD_QUESTION 32 |
| 722 | #define FREC_DO_QUESTION 64 |
| 723 | #define FREC_ADDED_PHEADER 128 |
| 724 | #define FREC_TEST_PKTSZ 256 |
| 725 | #define FREC_HAS_EXTRADATA 512 |
| 726 | #define FREC_HAS_PHEADER 1024 |
| 727 | #define FREC_NO_CACHE 2048 |
| 728 | |
| 729 | #define HASH_SIZE 32 /* SHA-256 digest size */ |
| 730 | |
| 731 | struct frec { |
| 732 | struct frec_src { |
| 733 | union mysockaddr source; |
| 734 | union all_addr dest; |
| 735 | unsigned int iface, log_id; |
| 736 | int fd; |
| 737 | unsigned short orig_id; |
| 738 | struct frec_src *next; |
| 739 | } frec_src; |
| 740 | struct server *sentto; /* NULL means free */ |
| 741 | struct randfd_list *rfds; |
| 742 | unsigned short new_id; |
| 743 | int forwardall, flags; |
| 744 | time_t time; |
| 745 | unsigned char *hash[HASH_SIZE]; |
| 746 | #ifdef HAVE_DNSSEC |
| 747 | int class, work_counter; |
| 748 | struct blockdata *stash; /* Saved reply, whilst we validate */ |
| 749 | size_t stash_len; |
| 750 | struct frec *dependent; /* Query awaiting internally-generated DNSKEY or DS query */ |
| 751 | struct frec *next_dependent; /* list of above. */ |
| 752 | struct frec *blocking_query; /* Query which is blocking us. */ |
| 753 | #endif |
| 754 | struct frec *next; |
| 755 | }; |
| 756 | |
| 757 | /* flags in top of length field for DHCP-option tables */ |
| 758 | #define OT_ADDR_LIST 0x8000 |
| 759 | #define OT_RFC1035_NAME 0x4000 |
| 760 | #define OT_INTERNAL 0x2000 |
| 761 | #define OT_NAME 0x1000 |
| 762 | #define OT_CSTRING 0x0800 |
| 763 | #define OT_DEC 0x0400 |
| 764 | #define OT_TIME 0x0200 |
| 765 | |
| 766 | /* actions in the daemon->helper RPC */ |
| 767 | #define ACTION_DEL 1 |
| 768 | #define ACTION_OLD_HOSTNAME 2 |
| 769 | #define ACTION_OLD 3 |
| 770 | #define ACTION_ADD 4 |
| 771 | #define ACTION_TFTP 5 |
| 772 | #define ACTION_ARP 6 |
| 773 | #define ACTION_ARP_DEL 7 |
| 774 | |
| 775 | #define LEASE_NEW 1 /* newly created */ |
| 776 | #define LEASE_CHANGED 2 /* modified */ |
| 777 | #define LEASE_AUX_CHANGED 4 /* CLID or expiry changed */ |
| 778 | #define LEASE_AUTH_NAME 8 /* hostname came from config, not from client */ |
| 779 | #define LEASE_USED 16 /* used this DHCPv6 transaction */ |
| 780 | #define LEASE_NA 32 /* IPv6 no-temporary lease */ |
| 781 | #define LEASE_TA 64 /* IPv6 temporary lease */ |
| 782 | #define LEASE_HAVE_HWADDR 128 /* Have set hwaddress */ |
| 783 | #define LEASE_EXP_CHANGED 256 /* Lease expiry time changed */ |
| 784 | |
| 785 | struct dhcp_lease { |
| 786 | int clid_len; /* length of client identifier */ |
| 787 | unsigned char *clid; /* clientid */ |
| 788 | char *hostname, *fqdn; /* name from client-hostname option or config */ |
| 789 | char *old_hostname; /* hostname before it moved to another lease */ |
| 790 | int flags; |
| 791 | time_t expires; /* lease expiry */ |
| 792 | #ifdef HAVE_BROKEN_RTC |
| 793 | unsigned int length; |
| 794 | #endif |
| 795 | int hwaddr_len, hwaddr_type; |
| 796 | unsigned char hwaddr[DHCP_CHADDR_MAX]; |
| 797 | struct in_addr addr, override, giaddr; |
| 798 | unsigned char *extradata; |
| 799 | unsigned int extradata_len, extradata_size; |
| 800 | int last_interface; |
| 801 | int new_interface; /* save possible originated interface */ |
| 802 | int new_prefixlen; /* and its prefix length */ |
| 803 | #ifdef HAVE_DHCP6 |
| 804 | struct in6_addr addr6; |
| 805 | unsigned int iaid; |
| 806 | struct slaac_address { |
| 807 | struct in6_addr addr; |
| 808 | time_t ping_time; |
| 809 | int backoff; /* zero -> confirmed */ |
| 810 | struct slaac_address *next; |
| 811 | } *slaac_address; |
| 812 | int vendorclass_count; |
| 813 | #endif |
| 814 | struct dhcp_lease *next; |
| 815 | }; |
| 816 | |
| 817 | struct dhcp_netid { |
| 818 | char *net; |
| 819 | struct dhcp_netid *next; |
| 820 | }; |
| 821 | |
| 822 | struct dhcp_netid_list { |
| 823 | struct dhcp_netid *list; |
| 824 | struct dhcp_netid_list *next; |
| 825 | }; |
| 826 | |
| 827 | struct tag_if { |
| 828 | struct dhcp_netid_list *set; |
| 829 | struct dhcp_netid *tag; |
| 830 | struct tag_if *next; |
| 831 | }; |
| 832 | |
| 833 | struct delay_config { |
| 834 | int delay; |
| 835 | struct dhcp_netid *netid; |
| 836 | struct delay_config *next; |
| 837 | }; |
| 838 | |
| 839 | struct hwaddr_config { |
| 840 | int hwaddr_len, hwaddr_type; |
| 841 | unsigned char hwaddr[DHCP_CHADDR_MAX]; |
| 842 | unsigned int wildcard_mask; |
| 843 | struct hwaddr_config *next; |
| 844 | }; |
| 845 | |
| 846 | struct dhcp_config { |
| 847 | unsigned int flags; |
| 848 | int clid_len; /* length of client identifier */ |
| 849 | unsigned char *clid; /* clientid */ |
| 850 | char *hostname, *domain; |
| 851 | struct dhcp_netid_list *netid; |
| 852 | struct dhcp_netid *filter; |
| 853 | #ifdef HAVE_DHCP6 |
| 854 | struct addrlist *addr6; |
| 855 | #endif |
| 856 | struct in_addr addr; |
| 857 | time_t decline_time; |
| 858 | unsigned int lease_time; |
| 859 | struct hwaddr_config *hwaddr; |
| 860 | struct dhcp_config *next; |
| 861 | }; |
| 862 | |
| 863 | #define have_config(config, mask) ((config) && ((config)->flags & (mask))) |
| 864 | |
| 865 | #define CONFIG_DISABLE 1 |
| 866 | #define CONFIG_CLID 2 |
| 867 | #define CONFIG_TIME 8 |
| 868 | #define CONFIG_NAME 16 |
| 869 | #define CONFIG_ADDR 32 |
| 870 | #define CONFIG_NOCLID 128 |
| 871 | #define CONFIG_FROM_ETHERS 256 /* entry created by /etc/ethers */ |
| 872 | #define CONFIG_ADDR_HOSTS 512 /* address added by from /etc/hosts */ |
| 873 | #define CONFIG_DECLINED 1024 /* address declined by client */ |
| 874 | #define CONFIG_BANK 2048 /* from dhcp hosts file */ |
| 875 | #define CONFIG_ADDR6 4096 |
| 876 | #define CONFIG_ADDR6_HOSTS 16384 /* address added by from /etc/hosts */ |
| 877 | |
| 878 | struct dhcp_opt { |
| 879 | int opt, len, flags; |
| 880 | union { |
| 881 | int encap; |
| 882 | unsigned int wildcard_mask; |
| 883 | unsigned char *vendor_class; |
| 884 | } u; |
| 885 | unsigned char *val; |
| 886 | struct dhcp_netid *netid; |
| 887 | struct dhcp_opt *next; |
| 888 | }; |
| 889 | |
| 890 | #define DHOPT_ADDR 1 |
| 891 | #define DHOPT_STRING 2 |
| 892 | #define DHOPT_ENCAPSULATE 4 |
| 893 | #define DHOPT_ENCAP_MATCH 8 |
| 894 | #define DHOPT_FORCE 16 |
| 895 | #define DHOPT_BANK 32 |
| 896 | #define DHOPT_ENCAP_DONE 64 |
| 897 | #define DHOPT_MATCH 128 |
| 898 | #define DHOPT_VENDOR 256 |
| 899 | #define DHOPT_HEX 512 |
| 900 | #define DHOPT_VENDOR_MATCH 1024 |
| 901 | #define DHOPT_RFC3925 2048 |
| 902 | #define DHOPT_TAGOK 4096 |
| 903 | #define DHOPT_ADDR6 8192 |
| 904 | #define DHOPT_VENDOR_PXE 16384 |
| 905 | |
| 906 | struct dhcp_boot { |
| 907 | char *file, *sname, *tftp_sname; |
| 908 | struct in_addr next_server; |
| 909 | struct dhcp_netid *netid; |
| 910 | struct dhcp_boot *next; |
| 911 | }; |
| 912 | |
| 913 | struct dhcp_match_name { |
| 914 | char *name; |
| 915 | int wildcard; |
| 916 | struct dhcp_netid *netid; |
| 917 | struct dhcp_match_name *next; |
| 918 | }; |
| 919 | |
| 920 | struct pxe_service { |
| 921 | unsigned short CSA, type; |
| 922 | char *menu, *basename, *sname; |
| 923 | struct in_addr server; |
| 924 | struct dhcp_netid *netid; |
| 925 | struct pxe_service *next; |
| 926 | }; |
| 927 | |
| 928 | #define DHCP_PXE_DEF_VENDOR "PXEClient" |
| 929 | |
| 930 | #define MATCH_VENDOR 1 |
| 931 | #define MATCH_USER 2 |
| 932 | #define MATCH_CIRCUIT 3 |
| 933 | #define MATCH_REMOTE 4 |
| 934 | #define MATCH_SUBSCRIBER 5 |
| 935 | |
| 936 | /* vendorclass, userclass, remote-id or circuit-id */ |
| 937 | struct dhcp_vendor { |
| 938 | int len, match_type; |
| 939 | unsigned int enterprise; |
| 940 | char *data; |
| 941 | struct dhcp_netid netid; |
| 942 | struct dhcp_vendor *next; |
| 943 | }; |
| 944 | |
| 945 | struct dhcp_pxe_vendor { |
| 946 | char *data; |
| 947 | struct dhcp_pxe_vendor *next; |
| 948 | }; |
| 949 | |
| 950 | struct dhcp_mac { |
| 951 | unsigned int mask; |
| 952 | int hwaddr_len, hwaddr_type; |
| 953 | unsigned char hwaddr[DHCP_CHADDR_MAX]; |
| 954 | struct dhcp_netid netid; |
| 955 | struct dhcp_mac *next; |
| 956 | }; |
| 957 | |
| 958 | struct dhcp_bridge { |
| 959 | char iface[IF_NAMESIZE]; |
| 960 | struct dhcp_bridge *alias, *next; |
| 961 | }; |
| 962 | |
| 963 | struct cond_domain { |
| 964 | char *domain, *prefix; /* prefix is text-prefix on domain name */ |
| 965 | struct in_addr start, end; |
| 966 | struct in6_addr start6, end6; |
| 967 | int is6, indexed, prefixlen; |
| 968 | struct cond_domain *next; |
| 969 | }; |
| 970 | |
| 971 | struct ra_interface { |
| 972 | char *name; |
| 973 | char *mtu_name; |
| 974 | int interval, lifetime, prio, mtu; |
| 975 | struct ra_interface *next; |
| 976 | }; |
| 977 | |
| 978 | struct dhcp_context { |
| 979 | unsigned int lease_time, addr_epoch; |
| 980 | struct in_addr netmask, broadcast; |
| 981 | struct in_addr local, router; |
| 982 | struct in_addr start, end; /* range of available addresses */ |
| 983 | #ifdef HAVE_DHCP6 |
| 984 | struct in6_addr start6, end6; /* range of available addresses */ |
| 985 | struct in6_addr local6; |
| 986 | int prefix, if_index; |
| 987 | unsigned int valid, preferred, saved_valid; |
| 988 | time_t ra_time, ra_short_period_start, address_lost_time; |
| 989 | char *template_interface; |
| 990 | #endif |
| 991 | int flags; |
| 992 | struct dhcp_netid netid, *filter; |
| 993 | struct dhcp_context *next, *current; |
| 994 | }; |
| 995 | |
| 996 | struct shared_network { |
| 997 | int if_index; |
| 998 | struct in_addr match_addr, shared_addr; |
| 999 | #ifdef HAVE_DHCP6 |
| 1000 | /* shared_addr == 0 for IP6 entries. */ |
| 1001 | struct in6_addr match_addr6, shared_addr6; |
| 1002 | #endif |
| 1003 | struct shared_network *next; |
| 1004 | }; |
| 1005 | |
| 1006 | #define CONTEXT_STATIC (1u<<0) |
| 1007 | #define CONTEXT_NETMASK (1u<<1) |
| 1008 | #define CONTEXT_BRDCAST (1u<<2) |
| 1009 | #define CONTEXT_PROXY (1u<<3) |
| 1010 | #define CONTEXT_RA_ROUTER (1u<<4) |
| 1011 | #define CONTEXT_RA_DONE (1u<<5) |
| 1012 | #define CONTEXT_RA_NAME (1u<<6) |
| 1013 | #define CONTEXT_RA_STATELESS (1u<<7) |
| 1014 | #define CONTEXT_DHCP (1u<<8) |
| 1015 | #define CONTEXT_DEPRECATE (1u<<9) |
| 1016 | #define CONTEXT_TEMPLATE (1u<<10) /* create contexts using addresses */ |
| 1017 | #define CONTEXT_CONSTRUCTED (1u<<11) |
| 1018 | #define CONTEXT_GC (1u<<12) |
| 1019 | #define CONTEXT_RA (1u<<13) |
| 1020 | #define CONTEXT_CONF_USED (1u<<14) |
| 1021 | #define CONTEXT_USED (1u<<15) |
| 1022 | #define CONTEXT_OLD (1u<<16) |
| 1023 | #define CONTEXT_V6 (1u<<17) |
| 1024 | #define CONTEXT_RA_OFF_LINK (1u<<18) |
| 1025 | #define CONTEXT_SETLEASE (1u<<19) |
| 1026 | |
| 1027 | struct ping_result { |
| 1028 | struct in_addr addr; |
| 1029 | time_t time; |
| 1030 | unsigned int hash; |
| 1031 | struct ping_result *next; |
| 1032 | }; |
| 1033 | |
| 1034 | struct tftp_file { |
| 1035 | int refcount, fd; |
| 1036 | off_t size; |
| 1037 | dev_t dev; |
| 1038 | ino_t inode; |
| 1039 | char filename[]; |
| 1040 | }; |
| 1041 | |
| 1042 | struct tftp_transfer { |
| 1043 | int sockfd; |
| 1044 | time_t timeout; |
| 1045 | int backoff; |
| 1046 | unsigned int block, blocksize, expansion; |
| 1047 | off_t offset; |
| 1048 | union mysockaddr peer; |
| 1049 | union all_addr source; |
| 1050 | int if_index; |
| 1051 | char opt_blocksize, opt_transize, netascii, carrylf; |
| 1052 | struct tftp_file *file; |
| 1053 | struct tftp_transfer *next; |
| 1054 | }; |
| 1055 | |
| 1056 | struct addr_list { |
| 1057 | struct in_addr addr; |
| 1058 | struct addr_list *next; |
| 1059 | }; |
| 1060 | |
| 1061 | struct tftp_prefix { |
| 1062 | char *interface; |
| 1063 | char *prefix; |
| 1064 | int missing; |
| 1065 | struct tftp_prefix *next; |
| 1066 | }; |
| 1067 | |
| 1068 | struct dhcp_relay { |
| 1069 | union all_addr local, server; |
| 1070 | char *interface; /* Allowable interface for replies from server, and dest for IPv6 multicast */ |
| 1071 | int iface_index; /* working - interface in which requests arrived, for return */ |
| 1072 | struct dhcp_relay *current, *next; |
| 1073 | }; |
| 1074 | |
| 1075 | extern struct daemon { |
| 1076 | /* datastuctures representing the command-line and |
| 1077 | config file arguments. All set (including defaults) |
| 1078 | in option.c */ |
| 1079 | |
| 1080 | unsigned int options[OPTION_SIZE]; |
| 1081 | struct resolvc default_resolv, *resolv_files; |
| 1082 | time_t last_resolv; |
| 1083 | char *servers_file; |
| 1084 | struct mx_srv_record *mxnames; |
| 1085 | struct naptr *naptr; |
| 1086 | struct txt_record *txt, *rr; |
| 1087 | struct ptr_record *ptr; |
| 1088 | struct host_record *host_records, *host_records_tail; |
| 1089 | struct cname *cnames; |
| 1090 | struct auth_zone *auth_zones; |
| 1091 | struct interface_name *int_names; |
| 1092 | char *mxtarget; |
| 1093 | struct mysubnet *add_subnet4; |
| 1094 | struct mysubnet *add_subnet6; |
| 1095 | char *lease_file; |
| 1096 | char *username, *groupname, *scriptuser; |
| 1097 | char *luascript; |
| 1098 | char *authserver, *hostmaster; |
| 1099 | struct iname *authinterface; |
| 1100 | struct name_list *secondary_forward_server; |
| 1101 | int group_set, osport; |
| 1102 | char *domain_suffix; |
| 1103 | struct cond_domain *cond_domain, *synth_domains; |
| 1104 | char *runfile; |
| 1105 | char *lease_change_command; |
| 1106 | struct iname *if_names, *if_addrs, *if_except, *dhcp_except, *auth_peers, *tftp_interfaces; |
| 1107 | struct bogus_addr *bogus_addr, *ignore_addr; |
| 1108 | struct server *servers, *local_domains, **serverarray, *no_rebind; |
| 1109 | int server_has_wildcard; |
| 1110 | int serverarraysz, serverarrayhwm; |
| 1111 | struct ipsets *ipsets; |
| 1112 | u32 allowlist_mask; |
| 1113 | struct allowlist *allowlists; |
| 1114 | int log_fac; /* log facility */ |
| 1115 | char *log_file; /* optional log file */ |
| 1116 | int max_logs; /* queue limit */ |
| 1117 | int cachesize, ftabsize; |
| 1118 | int port, query_port, min_port, max_port; |
| 1119 | unsigned long local_ttl, neg_ttl, max_ttl, min_cache_ttl, max_cache_ttl, auth_ttl, dhcp_ttl, use_dhcp_ttl; |
| 1120 | char *dns_client_id; |
| 1121 | u32 umbrella_org; |
| 1122 | u32 umbrella_asset; |
| 1123 | u8 umbrella_device[8]; |
| 1124 | struct hostsfile *addn_hosts; |
| 1125 | struct dhcp_context *dhcp, *dhcp6; |
| 1126 | struct ra_interface *ra_interfaces; |
| 1127 | struct dhcp_config *dhcp_conf; |
| 1128 | struct dhcp_opt *dhcp_opts, *dhcp_match, *dhcp_opts6, *dhcp_match6; |
| 1129 | struct dhcp_match_name *dhcp_name_match; |
| 1130 | struct dhcp_pxe_vendor *dhcp_pxe_vendors; |
| 1131 | struct dhcp_vendor *dhcp_vendors; |
| 1132 | struct dhcp_mac *dhcp_macs; |
| 1133 | struct dhcp_boot *boot_config; |
| 1134 | struct pxe_service *pxe_services; |
| 1135 | struct tag_if *tag_if; |
| 1136 | struct addr_list *override_relays; |
| 1137 | struct dhcp_relay *relay4, *relay6; |
| 1138 | struct delay_config *delay_conf; |
| 1139 | int override; |
| 1140 | int enable_pxe; |
| 1141 | int doing_ra, doing_dhcp6; |
| 1142 | struct dhcp_netid_list *dhcp_ignore, *dhcp_ignore_names, *dhcp_gen_names; |
| 1143 | struct dhcp_netid_list *force_broadcast, *bootp_dynamic; |
| 1144 | struct hostsfile *dhcp_hosts_file, *dhcp_opts_file, *dynamic_dirs; |
| 1145 | int dhcp_max, tftp_max, tftp_mtu; |
| 1146 | int dhcp_server_port, dhcp_client_port; |
| 1147 | int start_tftp_port, end_tftp_port; |
| 1148 | unsigned int min_leasetime; |
| 1149 | struct doctor *doctors; |
| 1150 | unsigned short edns_pktsz; |
| 1151 | char *tftp_prefix; |
| 1152 | struct tftp_prefix *if_prefix; /* per-interface TFTP prefixes */ |
| 1153 | unsigned int duid_enterprise, duid_config_len; |
| 1154 | unsigned char *duid_config; |
| 1155 | char *dbus_name; |
| 1156 | char *ubus_name; |
| 1157 | char *dump_file; |
| 1158 | int dump_mask; |
| 1159 | unsigned long soa_sn, soa_refresh, soa_retry, soa_expiry; |
| 1160 | u32 metrics[__METRIC_MAX]; |
| 1161 | #ifdef HAVE_DNSSEC |
| 1162 | struct ds_config *ds; |
| 1163 | char *timestamp_file; |
| 1164 | #endif |
| 1165 | |
| 1166 | /* globally used stuff for DNS */ |
| 1167 | char *packet; /* packet buffer */ |
| 1168 | int packet_buff_sz; /* size of above */ |
| 1169 | char *namebuff; /* MAXDNAME size buffer */ |
| 1170 | #ifdef HAVE_DNSSEC |
| 1171 | char *keyname; /* MAXDNAME size buffer */ |
| 1172 | char *workspacename; /* ditto */ |
| 1173 | unsigned long *rr_status; /* ceiling in TTL from DNSSEC or zero for insecure */ |
| 1174 | int rr_status_sz; |
| 1175 | int dnssec_no_time_check; |
| 1176 | int back_to_the_future; |
| 1177 | #endif |
| 1178 | struct frec *frec_list; |
| 1179 | struct frec_src *free_frec_src; |
| 1180 | int frec_src_count; |
| 1181 | struct serverfd *sfds; |
| 1182 | struct irec *interfaces; |
| 1183 | struct listener *listeners; |
| 1184 | struct server *srv_save; /* Used for resend on DoD */ |
| 1185 | size_t packet_len; /* " " */ |
| 1186 | int fd_save; /* " " */ |
| 1187 | pid_t tcp_pids[MAX_PROCS]; |
| 1188 | int tcp_pipes[MAX_PROCS]; |
| 1189 | int pipe_to_parent; |
| 1190 | int numrrand; |
| 1191 | struct randfd *randomsocks; |
| 1192 | struct randfd_list *rfl_spare, *rfl_poll; |
| 1193 | int v6pktinfo; |
| 1194 | struct addrlist *interface_addrs; /* list of all addresses/prefix lengths associated with all local interfaces */ |
| 1195 | int log_id, log_display_id; /* ids of transactions for logging */ |
| 1196 | union mysockaddr *log_source_addr; |
| 1197 | |
| 1198 | /* DHCP state */ |
| 1199 | int dhcpfd, helperfd, pxefd; |
| 1200 | #ifdef HAVE_INOTIFY |
| 1201 | int inotifyfd; |
| 1202 | #endif |
| 1203 | #if defined(HAVE_LINUX_NETWORK) |
| 1204 | int netlinkfd, kernel_version; |
| 1205 | #elif defined(HAVE_BSD_NETWORK) |
| 1206 | int dhcp_raw_fd, dhcp_icmp_fd, routefd; |
| 1207 | #endif |
| 1208 | struct iovec dhcp_packet; |
| 1209 | char *dhcp_buff, *dhcp_buff2, *dhcp_buff3; |
| 1210 | struct ping_result *ping_results; |
| 1211 | FILE *lease_stream; |
| 1212 | struct dhcp_bridge *bridges; |
| 1213 | struct shared_network *shared_networks; |
| 1214 | #ifdef HAVE_DHCP6 |
| 1215 | int duid_len; |
| 1216 | unsigned char *duid; |
| 1217 | struct iovec outpacket; |
| 1218 | int dhcp6fd, icmp6fd; |
| 1219 | #endif |
| 1220 | /* DBus stuff */ |
| 1221 | /* void * here to avoid depending on dbus headers outside dbus.c */ |
| 1222 | void *dbus; |
| 1223 | #ifdef HAVE_DBUS |
| 1224 | struct watch *watches; |
| 1225 | #endif |
| 1226 | /* UBus stuff */ |
| 1227 | #ifdef HAVE_UBUS |
| 1228 | /* void * here to avoid depending on ubus headers outside ubus.c */ |
| 1229 | void *ubus; |
| 1230 | #endif |
| 1231 | |
| 1232 | /* TFTP stuff */ |
| 1233 | struct tftp_transfer *tftp_trans, *tftp_done_trans; |
| 1234 | |
| 1235 | /* utility string buffer, hold max sized IP address as string */ |
| 1236 | char *addrbuff; |
| 1237 | char *addrbuff2; /* only allocated when OPT_EXTRALOG */ |
| 1238 | |
| 1239 | #ifdef HAVE_DUMPFILE |
| 1240 | /* file for packet dumps. */ |
| 1241 | int dumpfd; |
| 1242 | #endif |
| 1243 | } *daemon; |
| 1244 | |
| 1245 | /* cache.c */ |
| 1246 | void cache_init(void); |
| 1247 | void next_uid(struct crec *crecp); |
| 1248 | void log_query(unsigned int flags, char *name, union all_addr *addr, char *arg); |
| 1249 | char *record_source(unsigned int index); |
| 1250 | char *querystr(char *desc, unsigned short type); |
| 1251 | int cache_find_non_terminal(char *name, time_t now); |
| 1252 | struct crec *cache_find_by_addr(struct crec *crecp, |
| 1253 | union all_addr *addr, time_t now, |
| 1254 | unsigned int prot); |
| 1255 | struct crec *cache_find_by_name(struct crec *crecp, |
| 1256 | char *name, time_t now, unsigned int prot); |
| 1257 | void cache_end_insert(void); |
| 1258 | void cache_start_insert(void); |
| 1259 | int cache_recv_insert(time_t now, int fd); |
| 1260 | struct crec *cache_insert(char *name, union all_addr *addr, unsigned short class, |
| 1261 | time_t now, unsigned long ttl, unsigned int flags); |
| 1262 | void cache_reload(void); |
| 1263 | void cache_add_dhcp_entry(char *host_name, int prot, union all_addr *host_address, time_t ttd); |
| 1264 | struct in_addr a_record_from_hosts(char *name, time_t now); |
| 1265 | void cache_unhash_dhcp(void); |
| 1266 | void dump_cache(time_t now); |
| 1267 | #ifndef NO_ID |
| 1268 | int cache_make_stat(struct txt_record *t); |
| 1269 | #endif |
| 1270 | char *cache_get_name(struct crec *crecp); |
| 1271 | char *cache_get_cname_target(struct crec *crecp); |
| 1272 | struct crec *cache_enumerate(int init); |
| 1273 | int read_hostsfile(char *filename, unsigned int index, int cache_size, |
| 1274 | struct crec **rhash, int hashsz); |
| 1275 | |
| 1276 | /* blockdata.c */ |
| 1277 | void blockdata_init(void); |
| 1278 | void blockdata_report(void); |
| 1279 | struct blockdata *blockdata_alloc(char *data, size_t len); |
| 1280 | void *blockdata_retrieve(struct blockdata *block, size_t len, void *data); |
| 1281 | struct blockdata *blockdata_read(int fd, size_t len); |
| 1282 | void blockdata_write(struct blockdata *block, size_t len, int fd); |
| 1283 | void blockdata_free(struct blockdata *blocks); |
| 1284 | |
| 1285 | /* domain.c */ |
| 1286 | char *get_domain(struct in_addr addr); |
| 1287 | char *get_domain6(struct in6_addr *addr); |
| 1288 | int is_name_synthetic(int flags, char *name, union all_addr *addr); |
| 1289 | int is_rev_synth(int flag, union all_addr *addr, char *name); |
| 1290 | |
| 1291 | /* rfc1035.c */ |
| 1292 | int extract_name(struct dns_header *header, size_t plen, unsigned char **pp, |
| 1293 | char *name, int isExtract, int extrabytes); |
| 1294 | unsigned char *skip_name(unsigned char *ansp, struct dns_header *header, size_t plen, int extrabytes); |
| 1295 | unsigned char *skip_questions(struct dns_header *header, size_t plen); |
| 1296 | unsigned char *skip_section(unsigned char *ansp, int count, struct dns_header *header, size_t plen); |
| 1297 | unsigned int extract_request(struct dns_header *header, size_t qlen, |
| 1298 | char *name, unsigned short *typep); |
| 1299 | void setup_reply(struct dns_header *header, unsigned int flags, int ede); |
| 1300 | int extract_addresses(struct dns_header *header, size_t qlen, char *name, |
| 1301 | time_t now, char **ipsets, int is_sign, int check_rebind, |
| 1302 | int no_cache_dnssec, int secure, int *doctored); |
| 1303 | #if defined(HAVE_CONNTRACK) && defined(HAVE_UBUS) |
| 1304 | void report_addresses(struct dns_header *header, size_t len, u32 mark); |
| 1305 | #endif |
| 1306 | size_t answer_request(struct dns_header *header, char *limit, size_t qlen, |
| 1307 | struct in_addr local_addr, struct in_addr local_netmask, |
| 1308 | time_t now, int ad_reqd, int do_bit, int have_pseudoheader); |
| 1309 | int check_for_bogus_wildcard(struct dns_header *header, size_t qlen, char *name, |
| 1310 | time_t now); |
| 1311 | int check_for_ignored_address(struct dns_header *header, size_t qlen); |
| 1312 | int check_for_local_domain(char *name, time_t now); |
| 1313 | size_t resize_packet(struct dns_header *header, size_t plen, |
| 1314 | unsigned char *pheader, size_t hlen); |
| 1315 | int add_resource_record(struct dns_header *header, char *limit, int *truncp, |
| 1316 | int nameoffset, unsigned char **pp, unsigned long ttl, |
| 1317 | int *offset, unsigned short type, unsigned short class, char *format, ...); |
| 1318 | int in_arpa_name_2_addr(char *namein, union all_addr *addrp); |
| 1319 | int private_net(struct in_addr addr, int ban_localhost); |
| 1320 | |
| 1321 | /* auth.c */ |
| 1322 | #ifdef HAVE_AUTH |
| 1323 | size_t answer_auth(struct dns_header *header, char *limit, size_t qlen, |
| 1324 | time_t now, union mysockaddr *peer_addr, int local_query, |
| 1325 | int do_bit, int have_pseudoheader); |
| 1326 | int in_zone(struct auth_zone *zone, char *name, char **cut); |
| 1327 | #endif |
| 1328 | |
| 1329 | /* dnssec.c */ |
| 1330 | #ifdef HAVE_DNSSEC |
| 1331 | size_t dnssec_generate_query(struct dns_header *header, unsigned char *end, char *name, int class, int type, int edns_pktsz); |
| 1332 | int dnssec_validate_by_ds(time_t now, struct dns_header *header, size_t plen, char *name, char *keyname, int class); |
| 1333 | int dnssec_validate_ds(time_t now, struct dns_header *header, size_t plen, char *name, char *keyname, int class); |
| 1334 | int dnssec_validate_reply(time_t now, struct dns_header *header, size_t plen, char *name, char *keyname, int *class, |
| 1335 | int check_unsigned, int *neganswer, int *nons, int *nsec_ttl); |
| 1336 | int dnskey_keytag(int alg, int flags, unsigned char *key, int keylen); |
| 1337 | size_t filter_rrsigs(struct dns_header *header, size_t plen); |
| 1338 | int setup_timestamp(void); |
| 1339 | int errflags_to_ede(int status); |
| 1340 | #endif |
| 1341 | |
| 1342 | /* hash_questions.c */ |
| 1343 | void hash_questions_init(void); |
| 1344 | unsigned char *hash_questions(struct dns_header *header, size_t plen, char *name); |
| 1345 | |
| 1346 | /* crypto.c */ |
| 1347 | const struct nettle_hash *hash_find(char *name); |
| 1348 | int hash_init(const struct nettle_hash *hash, void **ctxp, unsigned char **digestp); |
| 1349 | int verify(struct blockdata *key_data, unsigned int key_len, unsigned char *sig, size_t sig_len, |
| 1350 | unsigned char *digest, size_t digest_len, int algo); |
| 1351 | char *ds_digest_name(int digest); |
| 1352 | char *algo_digest_name(int algo); |
| 1353 | char *nsec3_digest_name(int digest); |
| 1354 | |
| 1355 | /* util.c */ |
| 1356 | void rand_init(void); |
| 1357 | unsigned short rand16(void); |
| 1358 | u32 rand32(void); |
| 1359 | u64 rand64(void); |
| 1360 | int legal_hostname(char *name); |
| 1361 | char *canonicalise(char *in, int *nomem); |
| 1362 | unsigned char *do_rfc1035_name(unsigned char *p, char *sval, char *limit); |
| 1363 | void *safe_malloc(size_t size); |
| 1364 | void safe_strncpy(char *dest, const char *src, size_t size); |
| 1365 | void safe_pipe(int *fd, int read_noblock); |
| 1366 | void *whine_malloc(size_t size); |
| 1367 | int sa_len(union mysockaddr *addr); |
| 1368 | int sockaddr_isequal(const union mysockaddr *s1, const union mysockaddr *s2); |
| 1369 | int hostname_isequal(const char *a, const char *b); |
| 1370 | int hostname_issubdomain(char *a, char *b); |
| 1371 | time_t dnsmasq_time(void); |
| 1372 | int netmask_length(struct in_addr mask); |
| 1373 | int is_same_net(struct in_addr a, struct in_addr b, struct in_addr mask); |
| 1374 | int is_same_net_prefix(struct in_addr a, struct in_addr b, int prefix); |
| 1375 | int is_same_net6(struct in6_addr *a, struct in6_addr *b, int prefixlen); |
| 1376 | u64 addr6part(struct in6_addr *addr); |
| 1377 | void setaddr6part(struct in6_addr *addr, u64 host); |
| 1378 | int retry_send(ssize_t rc); |
| 1379 | void prettyprint_time(char *buf, unsigned int t); |
| 1380 | int prettyprint_addr(union mysockaddr *addr, char *buf); |
| 1381 | int parse_hex(char *in, unsigned char *out, int maxlen, |
| 1382 | unsigned int *wildcard_mask, int *mac_type); |
| 1383 | int memcmp_masked(unsigned char *a, unsigned char *b, int len, |
| 1384 | unsigned int mask); |
| 1385 | int expand_buf(struct iovec *iov, size_t size); |
| 1386 | char *print_mac(char *buff, unsigned char *mac, int len); |
| 1387 | int read_write(int fd, unsigned char *packet, int size, int rw); |
| 1388 | void close_fds(long max_fd, int spare1, int spare2, int spare3); |
| 1389 | int wildcard_match(const char* wildcard, const char* match); |
| 1390 | int wildcard_matchn(const char* wildcard, const char* match, int num); |
| 1391 | #ifdef HAVE_LINUX_NETWORK |
| 1392 | int kernel_version(void); |
| 1393 | #endif |
| 1394 | |
| 1395 | /* log.c */ |
| 1396 | void die(char *message, char *arg1, int exit_code) ATTRIBUTE_NORETURN; |
| 1397 | int log_start(struct passwd *ent_pw, int errfd); |
| 1398 | int log_reopen(char *log_file); |
| 1399 | |
| 1400 | void my_syslog(int priority, const char *format, ...); |
| 1401 | |
| 1402 | void set_log_writer(void); |
| 1403 | void check_log_writer(int force); |
| 1404 | void flush_log(void); |
| 1405 | |
| 1406 | /* option.c */ |
| 1407 | void read_opts (int argc, char **argv, char *compile_opts); |
| 1408 | char *option_string(int prot, unsigned int opt, unsigned char *val, |
| 1409 | int opt_len, char *buf, int buf_len); |
| 1410 | void reread_dhcp(void); |
| 1411 | void read_servers_file(void); |
| 1412 | void set_option_bool(unsigned int opt); |
| 1413 | void reset_option_bool(unsigned int opt); |
| 1414 | struct hostsfile *expand_filelist(struct hostsfile *list); |
| 1415 | char *parse_server(char *arg, union mysockaddr *addr, |
| 1416 | union mysockaddr *source_addr, char *interface, u16 *flags); |
| 1417 | int option_read_dynfile(char *file, int flags); |
| 1418 | |
| 1419 | /* forward.c */ |
| 1420 | void reply_query(int fd, time_t now); |
| 1421 | void receive_query(struct listener *listen, time_t now); |
| 1422 | unsigned char *tcp_request(int confd, time_t now, |
| 1423 | union mysockaddr *local_addr, struct in_addr netmask, int auth_dns); |
| 1424 | void server_gone(struct server *server); |
| 1425 | int send_from(int fd, int nowild, char *packet, size_t len, |
| 1426 | union mysockaddr *to, union all_addr *source, |
| 1427 | unsigned int iface); |
| 1428 | void resend_query(void); |
| 1429 | int allocate_rfd(struct randfd_list **fdlp, struct server *serv); |
| 1430 | void free_rfds(struct randfd_list **fdlp); |
| 1431 | |
| 1432 | /* network.c */ |
| 1433 | int indextoname(int fd, int index, char *name); |
| 1434 | int local_bind(int fd, union mysockaddr *addr, char *intname, unsigned int ifindex, int is_tcp); |
| 1435 | void pre_allocate_sfds(void); |
| 1436 | int reload_servers(char *fname); |
| 1437 | void check_servers(int no_loop_call); |
| 1438 | int enumerate_interfaces(int reset); |
| 1439 | void create_wildcard_listeners(void); |
| 1440 | void create_bound_listeners(int dienow); |
| 1441 | void warn_bound_listeners(void); |
| 1442 | void warn_wild_labels(void); |
| 1443 | void warn_int_names(void); |
| 1444 | int is_dad_listeners(void); |
| 1445 | int iface_check(int family, union all_addr *addr, char *name, int *auth); |
| 1446 | int loopback_exception(int fd, int family, union all_addr *addr, char *name); |
| 1447 | int label_exception(int index, int family, union all_addr *addr); |
| 1448 | int fix_fd(int fd); |
| 1449 | int tcp_interface(int fd, int af); |
| 1450 | int set_ipv6pktinfo(int fd); |
| 1451 | #ifdef HAVE_DHCP6 |
| 1452 | void join_multicast(int dienow); |
| 1453 | #endif |
| 1454 | #if defined(HAVE_LINUX_NETWORK) || defined(HAVE_BSD_NETWORK) |
| 1455 | void newaddress(time_t now); |
| 1456 | #endif |
| 1457 | |
| 1458 | |
| 1459 | /* dhcp.c */ |
| 1460 | #ifdef HAVE_DHCP |
| 1461 | void dhcp_init(void); |
| 1462 | void dhcp_packet(time_t now, int pxe_fd); |
| 1463 | struct dhcp_context *address_available(struct dhcp_context *context, |
| 1464 | struct in_addr taddr, |
| 1465 | struct dhcp_netid *netids); |
| 1466 | struct dhcp_context *narrow_context(struct dhcp_context *context, |
| 1467 | struct in_addr taddr, |
| 1468 | struct dhcp_netid *netids); |
| 1469 | struct ping_result *do_icmp_ping(time_t now, struct in_addr addr, |
| 1470 | unsigned int hash, int loopback); |
| 1471 | int address_allocate(struct dhcp_context *context, |
| 1472 | struct in_addr *addrp, unsigned char *hwaddr, int hw_len, |
| 1473 | struct dhcp_netid *netids, time_t now, int loopback); |
| 1474 | void dhcp_read_ethers(void); |
| 1475 | struct dhcp_config *config_find_by_address(struct dhcp_config *configs, struct in_addr addr); |
| 1476 | char *host_from_dns(struct in_addr addr); |
| 1477 | #endif |
| 1478 | |
| 1479 | /* lease.c */ |
| 1480 | #ifdef HAVE_DHCP |
| 1481 | void lease_update_file(time_t now); |
| 1482 | void lease_update_dns(int force); |
| 1483 | void lease_init(time_t now); |
| 1484 | struct dhcp_lease *lease4_allocate(struct in_addr addr); |
| 1485 | #ifdef HAVE_DHCP6 |
| 1486 | struct dhcp_lease *lease6_allocate(struct in6_addr *addrp, int lease_type); |
| 1487 | struct dhcp_lease *lease6_find(unsigned char *clid, int clid_len, |
| 1488 | int lease_type, unsigned int iaid, struct in6_addr *addr); |
| 1489 | void lease6_reset(void); |
| 1490 | struct dhcp_lease *lease6_find_by_client(struct dhcp_lease *first, int lease_type, |
| 1491 | unsigned char *clid, int clid_len, unsigned int iaid); |
| 1492 | struct dhcp_lease *lease6_find_by_addr(struct in6_addr *net, int prefix, u64 addr); |
| 1493 | u64 lease_find_max_addr6(struct dhcp_context *context); |
| 1494 | void lease_ping_reply(struct in6_addr *sender, unsigned char *packet, char *interface); |
| 1495 | void lease_update_slaac(time_t now); |
| 1496 | void lease_set_iaid(struct dhcp_lease *lease, unsigned int iaid); |
| 1497 | void lease_make_duid(time_t now); |
| 1498 | #endif |
| 1499 | void lease_set_hwaddr(struct dhcp_lease *lease, const unsigned char *hwaddr, |
| 1500 | const unsigned char *clid, int hw_len, int hw_type, |
| 1501 | int clid_len, time_t now, int force); |
| 1502 | void lease_set_hostname(struct dhcp_lease *lease, const char *name, int auth, char *domain, char *config_domain); |
| 1503 | void lease_set_expires(struct dhcp_lease *lease, unsigned int len, time_t now); |
| 1504 | void lease_set_interface(struct dhcp_lease *lease, int interface, time_t now); |
| 1505 | struct dhcp_lease *lease_find_by_client(unsigned char *hwaddr, int hw_len, int hw_type, |
| 1506 | unsigned char *clid, int clid_len); |
| 1507 | struct dhcp_lease *lease_find_by_addr(struct in_addr addr); |
| 1508 | struct in_addr lease_find_max_addr(struct dhcp_context *context); |
| 1509 | void lease_prune(struct dhcp_lease *target, time_t now); |
| 1510 | void lease_update_from_configs(void); |
| 1511 | int do_script_run(time_t now); |
| 1512 | void rerun_scripts(void); |
| 1513 | void lease_find_interfaces(time_t now); |
| 1514 | #ifdef HAVE_SCRIPT |
| 1515 | void lease_add_extradata(struct dhcp_lease *lease, unsigned char *data, |
| 1516 | unsigned int len, int delim); |
| 1517 | #endif |
| 1518 | #endif |
| 1519 | |
| 1520 | /* rfc2131.c */ |
| 1521 | #ifdef HAVE_DHCP |
| 1522 | size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index, |
| 1523 | size_t sz, time_t now, int unicast_dest, int loopback, |
| 1524 | int *is_inform, int pxe, struct in_addr fallback, time_t recvtime); |
| 1525 | unsigned char *extended_hwaddr(int hwtype, int hwlen, unsigned char *hwaddr, |
| 1526 | int clid_len, unsigned char *clid, int *len_out); |
| 1527 | #endif |
| 1528 | |
| 1529 | /* dnsmasq.c */ |
| 1530 | #ifdef HAVE_DHCP |
| 1531 | int make_icmp_sock(void); |
| 1532 | int icmp_ping(struct in_addr addr); |
| 1533 | int delay_dhcp(time_t start, int sec, int fd, uint32_t addr, unsigned short id); |
| 1534 | #endif |
| 1535 | void queue_event(int event); |
| 1536 | void send_alarm(time_t event, time_t now); |
| 1537 | void send_event(int fd, int event, int data, char *msg); |
| 1538 | void clear_cache_and_reload(time_t now); |
| 1539 | |
| 1540 | /* netlink.c */ |
| 1541 | #ifdef HAVE_LINUX_NETWORK |
| 1542 | char *netlink_init(void); |
| 1543 | void netlink_multicast(void); |
| 1544 | #endif |
| 1545 | |
| 1546 | /* bpf.c */ |
| 1547 | #ifdef HAVE_BSD_NETWORK |
| 1548 | void init_bpf(void); |
| 1549 | void send_via_bpf(struct dhcp_packet *mess, size_t len, |
| 1550 | struct in_addr iface_addr, struct ifreq *ifr); |
| 1551 | void route_init(void); |
| 1552 | void route_sock(void); |
| 1553 | #endif |
| 1554 | |
| 1555 | /* bpf.c or netlink.c */ |
| 1556 | int iface_enumerate(int family, void *parm, int (callback)()); |
| 1557 | |
| 1558 | /* dbus.c */ |
| 1559 | #ifdef HAVE_DBUS |
| 1560 | char *dbus_init(void); |
| 1561 | void check_dbus_listeners(void); |
| 1562 | void set_dbus_listeners(void); |
| 1563 | # ifdef HAVE_DHCP |
| 1564 | void emit_dbus_signal(int action, struct dhcp_lease *lease, char *hostname); |
| 1565 | # endif |
| 1566 | #endif |
| 1567 | |
| 1568 | /* ubus.c */ |
| 1569 | #ifdef HAVE_UBUS |
| 1570 | char *ubus_init(void); |
| 1571 | void set_ubus_listeners(void); |
| 1572 | void check_ubus_listeners(void); |
| 1573 | void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name, const char *interface); |
| 1574 | # ifdef HAVE_CONNTRACK |
| 1575 | void ubus_event_bcast_connmark_allowlist_refused(u32 mark, const char *name); |
| 1576 | void ubus_event_bcast_connmark_allowlist_resolved(u32 mark, const char *pattern, const char *ip, u32 ttl); |
| 1577 | # endif |
| 1578 | #endif |
| 1579 | |
| 1580 | /* ipset.c */ |
| 1581 | #ifdef HAVE_IPSET |
| 1582 | void ipset_init(void); |
| 1583 | int add_to_ipset(const char *setname, const union all_addr *ipaddr, int flags, int remove); |
| 1584 | #endif |
| 1585 | |
| 1586 | /* pattern.c */ |
| 1587 | #ifdef HAVE_CONNTRACK |
| 1588 | int is_valid_dns_name(const char *value); |
| 1589 | int is_valid_dns_name_pattern(const char *value); |
| 1590 | int is_dns_name_matching_pattern(const char *name, const char *pattern); |
| 1591 | #endif |
| 1592 | |
| 1593 | /* helper.c */ |
| 1594 | #if defined(HAVE_SCRIPT) |
| 1595 | int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd); |
| 1596 | void helper_write(void); |
| 1597 | void queue_script(int action, struct dhcp_lease *lease, |
| 1598 | char *hostname, time_t now); |
| 1599 | #ifdef HAVE_TFTP |
| 1600 | void queue_tftp(off_t file_len, char *filename, union mysockaddr *peer); |
| 1601 | #endif |
| 1602 | void queue_arp(int action, unsigned char *mac, int maclen, |
| 1603 | int family, union all_addr *addr); |
| 1604 | int helper_buf_empty(void); |
| 1605 | #endif |
| 1606 | |
| 1607 | /* tftp.c */ |
| 1608 | #ifdef HAVE_TFTP |
| 1609 | void tftp_request(struct listener *listen, time_t now); |
| 1610 | void check_tftp_listeners(time_t now); |
| 1611 | int do_tftp_script_run(void); |
| 1612 | #endif |
| 1613 | |
| 1614 | /* conntrack.c */ |
| 1615 | #ifdef HAVE_CONNTRACK |
| 1616 | int get_incoming_mark(union mysockaddr *peer_addr, union all_addr *local_addr, |
| 1617 | int istcp, unsigned int *markp); |
| 1618 | #endif |
| 1619 | |
| 1620 | /* dhcp6.c */ |
| 1621 | #ifdef HAVE_DHCP6 |
| 1622 | void dhcp6_init(void); |
| 1623 | void dhcp6_packet(time_t now); |
| 1624 | struct dhcp_context *address6_allocate(struct dhcp_context *context, unsigned char *clid, int clid_len, int temp_addr, |
| 1625 | unsigned int iaid, int serial, struct dhcp_netid *netids, int plain_range, struct in6_addr *ans); |
| 1626 | struct dhcp_context *address6_available(struct dhcp_context *context, |
| 1627 | struct in6_addr *taddr, |
| 1628 | struct dhcp_netid *netids, |
| 1629 | int plain_range); |
| 1630 | struct dhcp_context *address6_valid(struct dhcp_context *context, |
| 1631 | struct in6_addr *taddr, |
| 1632 | struct dhcp_netid *netids, |
| 1633 | int plain_range); |
| 1634 | struct dhcp_config *config_find_by_address6(struct dhcp_config *configs, struct in6_addr *net, |
| 1635 | int prefix, struct in6_addr *addr); |
| 1636 | void make_duid(time_t now); |
| 1637 | void dhcp_construct_contexts(time_t now); |
| 1638 | void get_client_mac(struct in6_addr *client, int iface, unsigned char *mac, |
| 1639 | unsigned int *maclenp, unsigned int *mactypep, time_t now); |
| 1640 | #endif |
| 1641 | |
| 1642 | /* rfc3315.c */ |
| 1643 | #ifdef HAVE_DHCP6 |
| 1644 | unsigned short dhcp6_reply(struct dhcp_context *context, int interface, char *iface_name, |
| 1645 | struct in6_addr *fallback, struct in6_addr *ll_addr, struct in6_addr *ula_addr, |
| 1646 | size_t sz, struct in6_addr *client_addr, time_t now); |
| 1647 | void relay_upstream6(struct dhcp_relay *relay, ssize_t sz, struct in6_addr *peer_address, |
| 1648 | u32 scope_id, time_t now); |
| 1649 | |
| 1650 | unsigned short relay_reply6( struct sockaddr_in6 *peer, ssize_t sz, char *arrival_interface); |
| 1651 | #endif |
| 1652 | |
| 1653 | /* dhcp-common.c */ |
| 1654 | #ifdef HAVE_DHCP |
| 1655 | void dhcp_common_init(void); |
| 1656 | ssize_t recv_dhcp_packet(int fd, struct msghdr *msg); |
| 1657 | struct dhcp_netid *run_tag_if(struct dhcp_netid *tags); |
| 1658 | struct dhcp_netid *option_filter(struct dhcp_netid *tags, struct dhcp_netid *context_tags, |
| 1659 | struct dhcp_opt *opts); |
| 1660 | int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool, int tagnotneeded); |
| 1661 | char *strip_hostname(char *hostname); |
| 1662 | void log_tags(struct dhcp_netid *netid, u32 xid); |
| 1663 | int match_bytes(struct dhcp_opt *o, unsigned char *p, int len); |
| 1664 | void dhcp_update_configs(struct dhcp_config *configs); |
| 1665 | void display_opts(void); |
| 1666 | int lookup_dhcp_opt(int prot, char *name); |
| 1667 | int lookup_dhcp_len(int prot, int val); |
| 1668 | struct dhcp_config *find_config(struct dhcp_config *configs, |
| 1669 | struct dhcp_context *context, |
| 1670 | unsigned char *clid, int clid_len, |
| 1671 | unsigned char *hwaddr, int hw_len, |
| 1672 | int hw_type, char *hostname, |
| 1673 | struct dhcp_netid *filter); |
| 1674 | int config_has_mac(struct dhcp_config *config, unsigned char *hwaddr, int len, int type); |
| 1675 | #ifdef HAVE_LINUX_NETWORK |
| 1676 | char *whichdevice(void); |
| 1677 | void bindtodevice(char *device, int fd); |
| 1678 | #endif |
| 1679 | # ifdef HAVE_DHCP6 |
| 1680 | void display_opts6(void); |
| 1681 | # endif |
| 1682 | void log_context(int family, struct dhcp_context *context); |
| 1683 | void log_relay(int family, struct dhcp_relay *relay); |
| 1684 | #endif |
| 1685 | |
| 1686 | /* outpacket.c */ |
| 1687 | #ifdef HAVE_DHCP6 |
| 1688 | void end_opt6(int container); |
| 1689 | void reset_counter(void); |
| 1690 | int save_counter(int newval); |
| 1691 | void *expand(size_t headroom); |
| 1692 | int new_opt6(int opt); |
| 1693 | void *put_opt6(void *data, size_t len); |
| 1694 | void put_opt6_long(unsigned int val); |
| 1695 | void put_opt6_short(unsigned int val); |
| 1696 | void put_opt6_char(unsigned int val); |
| 1697 | void put_opt6_string(char *s); |
| 1698 | #endif |
| 1699 | |
| 1700 | /* radv.c */ |
| 1701 | #ifdef HAVE_DHCP6 |
| 1702 | void ra_init(time_t now); |
| 1703 | void icmp6_packet(time_t now); |
| 1704 | time_t periodic_ra(time_t now); |
| 1705 | void ra_start_unsolicited(time_t now, struct dhcp_context *context); |
| 1706 | #endif |
| 1707 | |
| 1708 | /* slaac.c */ |
| 1709 | #ifdef HAVE_DHCP6 |
| 1710 | void slaac_add_addrs(struct dhcp_lease *lease, time_t now, int force); |
| 1711 | time_t periodic_slaac(time_t now, struct dhcp_lease *leases); |
| 1712 | void slaac_ping_reply(struct in6_addr *sender, unsigned char *packet, char *interface, struct dhcp_lease *leases); |
| 1713 | #endif |
| 1714 | |
| 1715 | /* loop.c */ |
| 1716 | #ifdef HAVE_LOOP |
| 1717 | void loop_send_probes(void); |
| 1718 | int detect_loop(char *query, int type); |
| 1719 | #endif |
| 1720 | |
| 1721 | /* inotify.c */ |
| 1722 | #ifdef HAVE_INOTIFY |
| 1723 | void inotify_dnsmasq_init(void); |
| 1724 | int inotify_check(time_t now); |
| 1725 | void set_dynamic_inotify(int flag, int total_size, struct crec **rhash, int revhashsz); |
| 1726 | #endif |
| 1727 | |
| 1728 | /* poll.c */ |
| 1729 | void poll_reset(void); |
| 1730 | int poll_check(int fd, short event); |
| 1731 | void poll_listen(int fd, short event); |
| 1732 | int do_poll(int timeout); |
| 1733 | |
| 1734 | /* rrfilter.c */ |
| 1735 | size_t rrfilter(struct dns_header *header, size_t plen, int mode); |
| 1736 | u16 *rrfilter_desc(int type); |
| 1737 | int expand_workspace(unsigned char ***wkspc, int *szp, int new); |
| 1738 | |
| 1739 | /* edns0.c */ |
| 1740 | unsigned char *find_pseudoheader(struct dns_header *header, size_t plen, |
| 1741 | size_t *len, unsigned char **p, int *is_sign, int *is_last); |
| 1742 | size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned char *limit, |
| 1743 | unsigned short udp_sz, int optno, unsigned char *opt, size_t optlen, int set_do, int replace); |
| 1744 | size_t add_do_bit(struct dns_header *header, size_t plen, unsigned char *limit); |
| 1745 | size_t add_edns0_config(struct dns_header *header, size_t plen, unsigned char *limit, |
| 1746 | union mysockaddr *source, time_t now, int *check_subnet, int *cacheable); |
| 1747 | int check_source(struct dns_header *header, size_t plen, unsigned char *pseudoheader, union mysockaddr *peer); |
| 1748 | |
| 1749 | /* arp.c */ |
| 1750 | int find_mac(union mysockaddr *addr, unsigned char *mac, int lazy, time_t now); |
| 1751 | int do_arp_script_run(void); |
| 1752 | |
| 1753 | /* dump.c */ |
| 1754 | #ifdef HAVE_DUMPFILE |
| 1755 | void dump_init(void); |
| 1756 | void dump_packet(int mask, void *packet, size_t len, union mysockaddr *src, union mysockaddr *dst); |
| 1757 | #endif |
| 1758 | |
| 1759 | /* domain-match.c */ |
| 1760 | void build_server_array(void); |
| 1761 | int lookup_domain(char *qdomain, int flags, int *lowout, int *highout); |
| 1762 | int filter_servers(int seed, int flags, int *lowout, int *highout); |
| 1763 | int is_local_answer(time_t now, int first, char *name); |
| 1764 | size_t make_local_answer(int flags, int gotname, size_t size, struct dns_header *header, |
| 1765 | char *name, char *limit, int first, int last, int ede); |
| 1766 | int server_samegroup(struct server *a, struct server *b); |
| 1767 | #ifdef HAVE_DNSSEC |
| 1768 | int dnssec_server(struct server *server, char *keyname, int *firstp, int *lastp); |
| 1769 | #endif |
| 1770 | void mark_servers(int flag); |
| 1771 | void cleanup_servers(void); |
| 1772 | int add_update_server(int flags, |
| 1773 | union mysockaddr *addr, |
| 1774 | union mysockaddr *source_addr, |
| 1775 | const char *interface, |
| 1776 | const char *domain, |
| 1777 | union all_addr *local_addr); |