Debian Codegraph @

src/dnsmasq.h

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