1 /* dnsmasq is Copyright (c) 2000-2022 Simon Kelley
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.
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.
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/>.
17 #define COPYRIGHT "Copyright (c) 2000-2022 Simon Kelley"
19 /* We do defines that influence behavior of stdio.h, so complain
20 if included too early. */
22 # error "Header file stdio.h included too early!"
26 /* Ensure we can use files >2GB (log files may grow this big) */
27 # define _LARGEFILE_SOURCE 1
28 # define _FILE_OFFSET_BITS 64
31 /* Get linux C library versions and define _GNU_SOURCE for kFreeBSD. */
32 #if defined(__linux__) || defined(__GLIBC__)
36 # include <features.h>
39 /* Need these defined early */
40 #if defined(__sun) || defined(__sun__)
42 # define __EXTENSIONS__
45 #if (defined(__GNUC__) && __GNUC__ >= 3) || defined(__clang__)
46 #define ATTRIBUTE_NORETURN __attribute__ ((noreturn))
48 #define ATTRIBUTE_NORETURN
51 /* get these before config.h for IPv6 stuff... */
52 #include <sys/types.h>
53 #include <sys/socket.h>
56 /* Define before netinet/in.h to select API. OSX Lion onwards. */
57 # define __APPLE_USE_RFC_3542
59 #include <netinet/in.h>
61 /* Also needed before config.h. */
68 typedef unsigned char u8;
69 typedef unsigned short u16;
70 typedef unsigned int u32;
71 typedef unsigned long long u64;
73 #define countof(x) (long)(sizeof(x) / sizeof(x[0]))
74 #define MIN(a,b) ((a) < (b) ? (a) : (b))
76 #include "dns-protocol.h"
77 #include "dhcp-protocol.h"
79 #include "dhcp6-protocol.h"
80 #include "radv-protocol.h"
83 #define gettext_noop(S) (S)
89 # define _(S) gettext(S)
92 #include <arpa/inet.h>
94 #include <sys/ioctl.h>
95 #if defined(HAVE_SOLARIS_NETWORK)
96 # include <sys/sockio.h>
100 #include <sys/time.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
122 #if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__sun__) || defined (__sun) || defined (__ANDROID__)
123 # include <netinet/if_ether.h>
125 # include <net/ethernet.h>
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>
137 #ifndef HAVE_LINUX_NETWORK
138 # include <net/if_dl.h>
141 #if defined(HAVE_LINUX_NETWORK)
142 #include <linux/version.h>
143 #include <linux/sockios.h>
144 #include <linux/capability.h>
145 /* There doesn't seem to be a universally-available
146 userspace header for these. */
147 extern int capset(cap_user_header_t header, cap_user_data_t data);
148 extern int capget(cap_user_header_t header, cap_user_data_t data);
149 #define LINUX_CAPABILITY_VERSION_1 0x19980330
150 #define LINUX_CAPABILITY_VERSION_2 0x20071026
151 #define LINUX_CAPABILITY_VERSION_3 0x20080522
153 #include <sys/prctl.h>
154 #elif defined(HAVE_SOLARIS_NETWORK)
158 /* Backwards compat with 2.83 */
159 #if defined(HAVE_NETTLEHASH)
160 # define HAVE_CRYPTOHASH
162 #if defined(HAVE_DNSSEC) || defined(HAVE_CRYPTOHASH)
163 # include <nettle/nettle-meta.h>
166 /* daemon is function in the C library.... */
167 #define daemon dnsmasq_daemon
169 #define ADDRSTRLEN INET6_ADDRSTRLEN
171 /* Async event queue */
173 int event, data, msg_sz;
176 #define EVENT_RELOAD 1
178 #define EVENT_ALARM 3
180 #define EVENT_CHILD 5
181 #define EVENT_REOPEN 6
182 #define EVENT_EXITED 7
183 #define EVENT_KILLED 8
184 #define EVENT_EXEC_ERR 9
185 #define EVENT_PIPE_ERR 10
186 #define EVENT_USER_ERR 11
187 #define EVENT_CAP_ERR 12
188 #define EVENT_PIDFILE 13
189 #define EVENT_HUSER_ERR 14
190 #define EVENT_GROUP_ERR 15
192 #define EVENT_LOG_ERR 17
193 #define EVENT_FORK_ERR 18
194 #define EVENT_LUA_ERR 19
195 #define EVENT_TFTP_ERR 20
196 #define EVENT_INIT 21
197 #define EVENT_NEWADDR 22
198 #define EVENT_NEWROUTE 23
199 #define EVENT_TIME_ERR 24
200 #define EVENT_SCRIPT_LOG 25
201 #define EVENT_TIME 26
210 #define EC_INIT_OFFSET 10
212 #define OPT_BOGUSPRIV 0
216 #define OPT_NO_HOSTS 4
217 #define OPT_NO_POLL 5
220 #define OPT_NO_RESOLV 8
222 #define OPT_LOCALMX 10
223 #define OPT_NO_NEG 11
224 #define OPT_NODOTS_LOCAL 12
225 #define OPT_NOWILD 13
226 #define OPT_ETHERS 14
227 #define OPT_RESOLV_DOMAIN 15
228 #define OPT_NO_FORK 16
229 #define OPT_AUTHORITATIVE 17
230 #define OPT_LOCALISE 18
232 #define OPT_DHCP_FQDN 20
233 #define OPT_NO_PING 21
234 #define OPT_LEASE_RO 22
235 #define OPT_ALL_SERVERS 23
236 #define OPT_RELOAD 24
237 #define OPT_LOCAL_REBIND 25
238 #define OPT_TFTP_SECURE 26
239 #define OPT_TFTP_NOBLOCK 27
240 #define OPT_LOG_OPTS 28
241 #define OPT_TFTP_APREF_IP 29
242 #define OPT_NO_OVERRIDE 30
243 #define OPT_NO_REBIND 31
244 #define OPT_ADD_MAC 32
245 #define OPT_DNSSEC_PROXY 33
246 #define OPT_CONSEC_ADDR 34
247 #define OPT_CONNTRACK 35
248 #define OPT_FQDN_UPDATE 36
250 #define OPT_TFTP_LC 38
251 #define OPT_CLEVERBIND 39
253 #define OPT_CLIENT_SUBNET 41
254 #define OPT_QUIET_DHCP 42
255 #define OPT_QUIET_DHCP6 43
256 #define OPT_QUIET_RA 44
257 #define OPT_DNSSEC_VALID 45
258 #define OPT_DNSSEC_TIME 46
259 #define OPT_DNSSEC_DEBUG 47
260 #define OPT_DNSSEC_IGN_NS 48
261 #define OPT_LOCAL_SERVICE 49
262 #define OPT_LOOP_DETECT 50
263 #define OPT_EXTRALOG 51
264 #define OPT_TFTP_NO_FAIL 52
265 #define OPT_SCRIPT_ARP 53
266 #define OPT_MAC_B64 54
267 #define OPT_MAC_HEX 55
268 #define OPT_TFTP_APREF_MAC 56
269 #define OPT_RAPID_COMMIT 57
271 #define OPT_IGNORE_CLID 59
272 #define OPT_SINGLE_PORT 60
273 #define OPT_LEASE_RENEW 61
274 #define OPT_LOG_DEBUG 62
275 #define OPT_UMBRELLA 63
276 #define OPT_UMBRELLA_DEVID 64
277 #define OPT_CMARK_ALST_EN 65
278 #define OPT_QUIET_TFTP 66
279 #define OPT_FILTER_A 67
280 #define OPT_FILTER_AAAA 68
281 #define OPT_STRIP_ECS 69
282 #define OPT_STRIP_MAC 70
286 #define OPTION_BITS (sizeof(unsigned int)*8)
287 #define OPTION_SIZE ( (OPT_LAST/OPTION_BITS)+((OPT_LAST%OPTION_BITS)!=0) )
288 #define option_var(x) (daemon->options[(x) / OPTION_BITS])
289 #define option_val(x) ((1u) << ((x) % OPTION_BITS))
290 #define option_bool(x) (option_var(x) & option_val(x))
292 /* extra flags for my_syslog, we use facilities since they are known
293 not to occupy the same bits as priorities, no matter how syslog.h is set up.
294 MS_DEBUG messages are suppressed unless --log-debug is set. */
295 #define MS_TFTP LOG_USER
296 #define MS_DHCP LOG_DAEMON
297 #define MS_SCRIPT LOG_MAIL
298 #define MS_DEBUG LOG_NEWS
300 /* Note that this is used widely as a container for IPv4/IPv6 addresses,
301 so for that reason, was well as to avoid wasting memory in almost every
302 cache entry, the other variants should not be larger than
303 sizeof(struct in6_addr) - 16 bytes.
306 struct in_addr addr4;
307 struct in6_addr addr6;
314 int is_name_ptr; /* disciminates target union */
317 struct blockdata *keydata;
318 unsigned short keylen, flags, keytag;
322 struct blockdata *keydata;
323 unsigned short keylen, keytag;
325 unsigned char digest;
328 struct blockdata *target;
329 unsigned short targetlen, srvport, priority, weight;
333 unsigned short keytag, algo, digest, rcode;
342 struct bogus_addr *next;
345 /* dns doctor param */
347 struct in_addr in, end, out, mask;
351 struct mx_srv_record {
353 int issrv, srvport, priority, weight;
355 struct mx_srv_record *next;
359 char *name, *replace, *regexp, *services, *flags;
360 unsigned int order, pref;
365 #define TXT_STAT_CACHESIZE 1
366 #define TXT_STAT_INSERTS 2
367 #define TXT_STAT_EVICTIONS 3
368 #define TXT_STAT_MISSES 4
369 #define TXT_STAT_HITS 5
370 #define TXT_STAT_AUTH 6
371 #define TXT_STAT_SERVERS 7
377 unsigned short class, len;
379 struct txt_record *next;
384 struct ptr_record *next;
389 char *alias, *target;
390 struct cname *next, *targetp;
395 int digestlen, class, algo, keytag, digest_type;
396 struct ds_config *next;
399 #define ADDRLIST_LITERAL 1
400 #define ADDRLIST_IPV6 2
401 #define ADDRLIST_REVONLY 4
402 #define ADDRLIST_PREFIX 8
403 #define ADDRLIST_WILDCARD 16
404 #define ADDRLIST_DECLINED 32
408 int flags, prefixlen;
410 struct addrlist *next;
418 struct auth_name_list {
421 struct auth_name_list *next;
423 struct addrlist *subnet;
424 struct addrlist *exclude;
425 struct auth_zone *next;
435 struct name_list *next;
438 struct in6_addr addr6;
439 struct host_record *next;
447 struct interface_name {
448 char *name; /* domain name */
449 char *intr; /* interface name */
451 struct in_addr proto4;
452 struct in6_addr proto6;
453 struct addrlist *addr;
454 struct interface_name *next;
459 union bigname *next; /* freelist */
463 struct blockdata *next;
464 unsigned char key[KEYBLOCK_LEN];
468 struct crec *next, *prev, *hash_next;
470 time_t ttd; /* time to die */
471 /* used as class if DNSKEY/DS, index to source for F_HOSTS */
475 char sname[SMALLDNAME];
476 union bigname *bname;
481 #define SIZEOF_BARE_CREC (sizeof(struct crec) - SMALLDNAME)
482 #define SIZEOF_POINTER_CREC (sizeof(struct crec) + sizeof(char *) - SMALLDNAME)
484 #define F_IMMORTAL (1u<<0)
485 #define F_NAMEP (1u<<1)
486 #define F_REVERSE (1u<<2)
487 #define F_FORWARD (1u<<3)
488 #define F_DHCP (1u<<4)
489 #define F_NEG (1u<<5)
490 #define F_HOSTS (1u<<6)
491 #define F_IPV4 (1u<<7)
492 #define F_IPV6 (1u<<8)
493 #define F_BIGNAME (1u<<9)
494 #define F_NXDOMAIN (1u<<10)
495 #define F_CNAME (1u<<11)
496 #define F_DNSKEY (1u<<12)
497 #define F_CONFIG (1u<<13)
498 #define F_DS (1u<<14)
499 #define F_DNSSECOK (1u<<15)
500 #define F_UPSTREAM (1u<<16)
501 #define F_RRNAME (1u<<17)
502 #define F_SERVER (1u<<18)
503 #define F_QUERY (1u<<19)
504 #define F_NOERR (1u<<20)
505 #define F_AUTH (1u<<21)
506 #define F_DNSSEC (1u<<22)
507 #define F_KEYTAG (1u<<23)
508 #define F_SECSTAT (1u<<24)
509 #define F_NO_RR (1u<<25)
510 #define F_IPSET (1u<<26)
511 #define F_NOEXTRA (1u<<27)
512 #define F_DOMAINSRV (1u<<28)
513 #define F_RCODE (1u<<29)
514 #define F_SRV (1u<<30)
515 #define F_STALE (1u<<31)
518 /* Values of uid in crecs with F_CONFIG bit set. */
524 /* struct sockaddr is not large enough to hold any address,
525 and specifically not big enough to hold an IPv6 address.
526 Blech. Roll our own. */
529 struct sockaddr_in in;
530 struct sockaddr_in6 in6;
533 /* bits in flag param to IPv6 callbacks from iface_enumerate() */
534 #define IFACE_TENTATIVE 1
535 #define IFACE_DEPRECATED 2
536 #define IFACE_PERMANENT 4
539 /* The actual values here matter, since we sort on them to get records in the order
540 IPv6 addr, IPv4 addr, all zero return, resolvconf servers, upstream server, no-data return */
541 #define SERV_LITERAL_ADDRESS 1 /* addr is the answer, or NoDATA is the answer, depending on the next four flags */
542 #define SERV_USE_RESOLV 2 /* forward this domain in the normal way */
543 #define SERV_ALL_ZEROS 4 /* return all zeros for A and AAAA */
544 #define SERV_4ADDR 8 /* addr is IPv4 */
545 #define SERV_6ADDR 16 /* addr is IPv6 */
546 #define SERV_HAS_SOURCE 32 /* source address defined */
547 #define SERV_FOR_NODOTS 64 /* server for names with no domain part only */
548 #define SERV_WARNED_RECURSIVE 128 /* avoid warning spam */
549 #define SERV_FROM_DBUS 256 /* 1 if source is DBus */
550 #define SERV_MARK 512 /* for mark-and-delete and log code */
551 #define SERV_WILDCARD 1024 /* domain has leading '*' */
552 #define SERV_FROM_RESOLV 2048 /* 1 for servers from resolv, 0 for command line. */
553 #define SERV_FROM_FILE 4096 /* read from --servers-file */
554 #define SERV_LOOP 8192 /* server causes forwarding loop */
555 #define SERV_DO_DNSSEC 16384 /* Validate DNSSEC when using this server */
556 #define SERV_GOT_TCP 32768 /* Got some data from the TCP connection */
560 union mysockaddr source_addr;
561 char interface[IF_NAMESIZE+1];
562 unsigned int ifindex, used, preallocated;
563 struct serverfd *next;
569 unsigned short refcount; /* refcount == 0xffff means overflow record. */
574 struct randfd_list *next;
579 u16 flags, domain_len;
582 int serial, arrayposn;
584 union mysockaddr addr, source_addr;
585 char interface[IF_NAMESIZE+1];
586 unsigned int ifindex; /* corresponding to interface, above */
587 struct serverfd *sfd;
588 int tcpfd, edns_pktsz;
589 time_t pktsz_reduced;
590 unsigned int queries, failed_queries, nxdomain_replies, retrys;
591 unsigned int query_latency, mma_latency;
599 /* First four fields must match struct server in next three definitions.. */
601 u16 flags, domain_len;
608 u16 flags, domain_len;
611 struct in6_addr addr;
615 u16 flags, domain_len;
620 struct rebind_domain {
622 struct rebind_domain *next;
634 struct allowlist *next;
638 union mysockaddr addr;
639 struct in_addr netmask; /* only valid for IPv4 */
640 int tftp_ok, dhcp_ok, mtu, done, warned, dad, dns_auth, index, multicast_done, found, label;
646 int fd, tcpfd, tftpfd, used;
647 union mysockaddr addr;
648 struct irec *iface; /* only sometimes valid for non-wildcard */
649 struct listener *next;
652 /* interface and address parms from command line. */
655 union mysockaddr addr;
660 /* subnet parameters from command line */
662 union mysockaddr addr;
667 /* resolv-file parms from command-line */
669 struct resolvc *next;
670 int is_default, logged;
675 int wd; /* inotify watch descriptor */
676 char *file; /* pointer to file part if path */
680 /* adn-hosts parms from command-line (also dhcp-hostsfile and dhcp-optsfile and dhcp-hostsdir*/
682 #define AH_INACTIVE 2
685 #define AH_DHCP_HST 16
686 #define AH_DHCP_OPT 32
688 struct hostsfile *next;
691 unsigned int index; /* matches to cache entries for logging */
696 struct hostsfile *files;
700 int wd; /* inotify watch descriptor */
704 /* packet-dump flags */
705 #define DUMP_QUERY 0x0001
706 #define DUMP_REPLY 0x0002
707 #define DUMP_UP_QUERY 0x0004
708 #define DUMP_UP_REPLY 0x0008
709 #define DUMP_SEC_QUERY 0x0010
710 #define DUMP_SEC_REPLY 0x0020
711 #define DUMP_BOGUS 0x0040
712 #define DUMP_SEC_BOGUS 0x0080
713 #define DUMP_DHCP 0x1000
714 #define DUMP_DHCPV6 0x2000
715 #define DUMP_RA 0x4000
716 #define DUMP_TFTP 0x8000
718 /* DNSSEC status values. */
719 #define STAT_SECURE 0x10000
720 #define STAT_INSECURE 0x20000
721 #define STAT_BOGUS 0x30000
722 #define STAT_NEED_DS 0x40000
723 #define STAT_NEED_KEY 0x50000
724 #define STAT_TRUNCATED 0x60000
725 #define STAT_SECURE_WILDCARD 0x70000
726 #define STAT_OK 0x80000
727 #define STAT_ABANDONED 0x90000
729 #define DNSSEC_FAIL_NYV 0x0001 /* key not yet valid */
730 #define DNSSEC_FAIL_EXP 0x0002 /* key expired */
731 #define DNSSEC_FAIL_INDET 0x0004 /* indetermined */
732 #define DNSSEC_FAIL_NOKEYSUP 0x0008 /* no supported key algo. */
733 #define DNSSEC_FAIL_NOSIG 0x0010 /* No RRsigs */
734 #define DNSSEC_FAIL_NOZONE 0x0020 /* No Zone bit set */
735 #define DNSSEC_FAIL_NONSEC 0x0040 /* No NSEC */
736 #define DNSSEC_FAIL_NODSSUP 0x0080 /* no supported DS algo. */
737 #define DNSSEC_FAIL_NOKEY 0x0100 /* no DNSKEY */
739 #define STAT_ISEQUAL(a, b) (((a) & 0xffff0000) == (b))
741 #define FREC_NOREBIND 1
742 #define FREC_CHECKING_DISABLED 2
743 #define FREC_NO_CACHE 4
744 #define FREC_DNSKEY_QUERY 8
745 #define FREC_DS_QUERY 16
746 #define FREC_AD_QUESTION 32
747 #define FREC_DO_QUESTION 64
748 #define FREC_ADDED_PHEADER 128
749 #define FREC_TEST_PKTSZ 256
750 #define FREC_HAS_EXTRADATA 512
751 #define FREC_HAS_PHEADER 1024
753 #define HASH_SIZE 32 /* SHA-256 digest size */
757 union mysockaddr source;
759 unsigned int iface, log_id;
761 unsigned short orig_id;
762 struct frec_src *next;
764 struct server *sentto; /* NULL means free */
765 struct randfd_list *rfds;
766 unsigned short new_id;
767 int forwardall, flags;
769 u32 forward_timestamp;
771 unsigned char *hash[HASH_SIZE];
772 struct blockdata *stash; /* Saved reply, whilst we validate */
775 int class, work_counter;
776 struct frec *dependent; /* Query awaiting internally-generated DNSKEY or DS query */
777 struct frec *next_dependent; /* list of above. */
778 struct frec *blocking_query; /* Query which is blocking us. */
783 /* flags in top of length field for DHCP-option tables */
784 #define OT_ADDR_LIST 0x8000
785 #define OT_RFC1035_NAME 0x4000
786 #define OT_INTERNAL 0x2000
787 #define OT_NAME 0x1000
788 #define OT_CSTRING 0x0800
789 #define OT_DEC 0x0400
790 #define OT_TIME 0x0200
792 /* actions in the daemon->helper RPC */
794 #define ACTION_OLD_HOSTNAME 2
797 #define ACTION_TFTP 5
799 #define ACTION_ARP_DEL 7
800 #define ACTION_RELAY_SNOOP 8
802 #define LEASE_NEW 1 /* newly created */
803 #define LEASE_CHANGED 2 /* modified */
804 #define LEASE_AUX_CHANGED 4 /* CLID or expiry changed */
805 #define LEASE_AUTH_NAME 8 /* hostname came from config, not from client */
806 #define LEASE_USED 16 /* used this DHCPv6 transaction */
807 #define LEASE_NA 32 /* IPv6 no-temporary lease */
808 #define LEASE_TA 64 /* IPv6 temporary lease */
809 #define LEASE_HAVE_HWADDR 128 /* Have set hwaddress */
810 #define LEASE_EXP_CHANGED 256 /* Lease expiry time changed */
813 int clid_len; /* length of client identifier */
814 unsigned char *clid; /* clientid */
815 char *hostname, *fqdn; /* name from client-hostname option or config */
816 char *old_hostname; /* hostname before it moved to another lease */
818 time_t expires; /* lease expiry */
819 #ifdef HAVE_BROKEN_RTC
822 int hwaddr_len, hwaddr_type;
823 unsigned char hwaddr[DHCP_CHADDR_MAX];
824 struct in_addr addr, override, giaddr;
825 unsigned char *extradata;
826 unsigned int extradata_len, extradata_size;
828 int new_interface; /* save possible originated interface */
829 int new_prefixlen; /* and its prefix length */
831 struct in6_addr addr6;
833 struct slaac_address {
834 struct in6_addr addr;
836 int backoff; /* zero -> confirmed */
837 struct slaac_address *next;
839 int vendorclass_count;
841 struct dhcp_lease *next;
846 struct dhcp_netid *next;
849 struct dhcp_netid_list {
850 struct dhcp_netid *list;
851 struct dhcp_netid_list *next;
855 struct dhcp_netid_list *set;
856 struct dhcp_netid *tag;
860 struct delay_config {
862 struct dhcp_netid *netid;
863 struct delay_config *next;
866 struct hwaddr_config {
867 int hwaddr_len, hwaddr_type;
868 unsigned char hwaddr[DHCP_CHADDR_MAX];
869 unsigned int wildcard_mask;
870 struct hwaddr_config *next;
875 int clid_len; /* length of client identifier */
876 unsigned char *clid; /* clientid */
877 char *hostname, *domain;
878 struct dhcp_netid_list *netid;
879 struct dhcp_netid *filter;
881 struct addrlist *addr6;
885 unsigned int lease_time;
886 struct hwaddr_config *hwaddr;
887 struct dhcp_config *next;
890 #define have_config(config, mask) ((config) && ((config)->flags & (mask)))
892 #define CONFIG_DISABLE 1
893 #define CONFIG_CLID 2
894 #define CONFIG_TIME 8
895 #define CONFIG_NAME 16
896 #define CONFIG_ADDR 32
897 #define CONFIG_NOCLID 128
898 #define CONFIG_FROM_ETHERS 256 /* entry created by /etc/ethers */
899 #define CONFIG_ADDR_HOSTS 512 /* address added by from /etc/hosts */
900 #define CONFIG_DECLINED 1024 /* address declined by client */
901 #define CONFIG_BANK 2048 /* from dhcp hosts file */
902 #define CONFIG_ADDR6 4096
903 #define CONFIG_ADDR6_HOSTS 16384 /* address added by from /etc/hosts */
909 unsigned int wildcard_mask;
910 unsigned char *vendor_class;
913 struct dhcp_netid *netid;
914 struct dhcp_opt *next;
918 #define DHOPT_STRING 2
919 #define DHOPT_ENCAPSULATE 4
920 #define DHOPT_ENCAP_MATCH 8
921 #define DHOPT_FORCE 16
922 #define DHOPT_BANK 32
923 #define DHOPT_ENCAP_DONE 64
924 #define DHOPT_MATCH 128
925 #define DHOPT_VENDOR 256
926 #define DHOPT_HEX 512
927 #define DHOPT_VENDOR_MATCH 1024
928 #define DHOPT_RFC3925 2048
929 #define DHOPT_TAGOK 4096
930 #define DHOPT_ADDR6 8192
931 #define DHOPT_VENDOR_PXE 16384
934 char *file, *sname, *tftp_sname;
935 struct in_addr next_server;
936 struct dhcp_netid *netid;
937 struct dhcp_boot *next;
940 struct dhcp_match_name {
943 struct dhcp_netid *netid;
944 struct dhcp_match_name *next;
948 unsigned short CSA, type;
949 char *menu, *basename, *sname;
950 struct in_addr server;
951 struct dhcp_netid *netid;
952 struct pxe_service *next;
955 #define DHCP_PXE_DEF_VENDOR "PXEClient"
957 #define MATCH_VENDOR 1
959 #define MATCH_CIRCUIT 3
960 #define MATCH_REMOTE 4
961 #define MATCH_SUBSCRIBER 5
963 /* vendorclass, userclass, remote-id or circuit-id */
966 unsigned int enterprise;
968 struct dhcp_netid netid;
969 struct dhcp_vendor *next;
972 struct dhcp_pxe_vendor {
974 struct dhcp_pxe_vendor *next;
979 int hwaddr_len, hwaddr_type;
980 unsigned char hwaddr[DHCP_CHADDR_MAX];
981 struct dhcp_netid netid;
982 struct dhcp_mac *next;
986 char iface[IF_NAMESIZE];
987 struct dhcp_bridge *alias, *next;
991 char *domain, *prefix; /* prefix is text-prefix on domain name */
992 char *interface; /* These two set when domain comes from interface. */
994 struct in_addr start, end;
995 struct in6_addr start6, end6;
996 int is6, indexed, prefixlen;
997 struct cond_domain *next;
1000 struct ra_interface {
1003 int interval, lifetime, prio, mtu;
1004 struct ra_interface *next;
1007 struct dhcp_context {
1008 unsigned int lease_time, addr_epoch;
1009 struct in_addr netmask, broadcast;
1010 struct in_addr local, router;
1011 struct in_addr start, end; /* range of available addresses */
1013 struct in6_addr start6, end6; /* range of available addresses */
1014 struct in6_addr local6;
1015 int prefix, if_index;
1016 unsigned int valid, preferred, saved_valid;
1017 time_t ra_time, ra_short_period_start, address_lost_time;
1018 char *template_interface;
1021 struct dhcp_netid netid, *filter;
1022 struct dhcp_context *next, *current;
1025 struct shared_network {
1027 struct in_addr match_addr, shared_addr;
1029 /* shared_addr == 0 for IP6 entries. */
1030 struct in6_addr match_addr6, shared_addr6;
1032 struct shared_network *next;
1035 #define CONTEXT_STATIC (1u<<0)
1036 #define CONTEXT_NETMASK (1u<<1)
1037 #define CONTEXT_BRDCAST (1u<<2)
1038 #define CONTEXT_PROXY (1u<<3)
1039 #define CONTEXT_RA_ROUTER (1u<<4)
1040 #define CONTEXT_RA_DONE (1u<<5)
1041 #define CONTEXT_RA_NAME (1u<<6)
1042 #define CONTEXT_RA_STATELESS (1u<<7)
1043 #define CONTEXT_DHCP (1u<<8)
1044 #define CONTEXT_DEPRECATE (1u<<9)
1045 #define CONTEXT_TEMPLATE (1u<<10) /* create contexts using addresses */
1046 #define CONTEXT_CONSTRUCTED (1u<<11)
1047 #define CONTEXT_GC (1u<<12)
1048 #define CONTEXT_RA (1u<<13)
1049 #define CONTEXT_CONF_USED (1u<<14)
1050 #define CONTEXT_USED (1u<<15)
1051 #define CONTEXT_OLD (1u<<16)
1052 #define CONTEXT_V6 (1u<<17)
1053 #define CONTEXT_RA_OFF_LINK (1u<<18)
1054 #define CONTEXT_SETLEASE (1u<<19)
1056 struct ping_result {
1057 struct in_addr addr;
1060 struct ping_result *next;
1071 struct tftp_transfer {
1075 unsigned int block, blocksize, expansion;
1077 union mysockaddr peer;
1078 union all_addr source;
1080 char opt_blocksize, opt_transize, netascii, carrylf;
1081 struct tftp_file *file;
1082 struct tftp_transfer *next;
1086 struct in_addr addr;
1087 struct addr_list *next;
1090 struct tftp_prefix {
1094 struct tftp_prefix *next;
1098 union all_addr local, server;
1099 char *interface; /* Allowable interface for replies from server, and dest for IPv6 multicast */
1100 int iface_index; /* working - interface in which requests arrived, for return */
1101 int port; /* Port of relay we forward to. */
1103 struct snoop_record {
1104 struct in6_addr client, prefix;
1106 struct snoop_record *next;
1109 struct dhcp_relay *next;
1112 extern struct daemon {
1113 /* datastuctures representing the command-line and
1114 config file arguments. All set (including defaults)
1117 unsigned int options[OPTION_SIZE];
1118 struct resolvc default_resolv, *resolv_files;
1121 struct mx_srv_record *mxnames;
1122 struct naptr *naptr;
1123 struct txt_record *txt, *rr;
1124 struct ptr_record *ptr;
1125 struct host_record *host_records, *host_records_tail;
1126 struct cname *cnames;
1127 struct auth_zone *auth_zones;
1128 struct interface_name *int_names;
1130 struct mysubnet *add_subnet4;
1131 struct mysubnet *add_subnet6;
1133 char *username, *groupname, *scriptuser;
1135 char *authserver, *hostmaster;
1136 struct iname *authinterface;
1137 struct name_list *secondary_forward_server;
1138 int group_set, osport;
1139 char *domain_suffix;
1140 struct cond_domain *cond_domain, *synth_domains;
1142 char *lease_change_command;
1143 struct iname *if_names, *if_addrs, *if_except, *dhcp_except, *auth_peers, *tftp_interfaces;
1144 struct bogus_addr *bogus_addr, *ignore_addr;
1145 struct server *servers, *servers_tail, *local_domains, **serverarray;
1146 struct rebind_domain *no_rebind;
1147 int server_has_wildcard;
1148 int serverarraysz, serverarrayhwm;
1149 struct ipsets *ipsets, *nftsets;
1151 struct allowlist *allowlists;
1152 int log_fac; /* log facility */
1153 char *log_file; /* optional log file */
1154 int max_logs; /* queue limit */
1155 int randport_limit; /* Maximum number of source ports for query. */
1156 int cachesize, ftabsize;
1157 int port, query_port, min_port, max_port;
1158 unsigned long local_ttl, neg_ttl, max_ttl, min_cache_ttl, max_cache_ttl, auth_ttl, dhcp_ttl, use_dhcp_ttl;
1159 char *dns_client_id;
1162 u8 umbrella_device[8];
1164 struct hostsfile *addn_hosts;
1165 struct dhcp_context *dhcp, *dhcp6;
1166 struct ra_interface *ra_interfaces;
1167 struct dhcp_config *dhcp_conf;
1168 struct dhcp_opt *dhcp_opts, *dhcp_match, *dhcp_opts6, *dhcp_match6;
1169 struct dhcp_match_name *dhcp_name_match;
1170 struct dhcp_pxe_vendor *dhcp_pxe_vendors;
1171 struct dhcp_vendor *dhcp_vendors;
1172 struct dhcp_mac *dhcp_macs;
1173 struct dhcp_boot *boot_config;
1174 struct pxe_service *pxe_services;
1175 struct tag_if *tag_if;
1176 struct addr_list *override_relays;
1177 struct dhcp_relay *relay4, *relay6;
1178 struct delay_config *delay_conf;
1181 int doing_ra, doing_dhcp6;
1182 struct dhcp_netid_list *dhcp_ignore, *dhcp_ignore_names, *dhcp_gen_names;
1183 struct dhcp_netid_list *force_broadcast, *bootp_dynamic;
1184 struct hostsfile *dhcp_hosts_file, *dhcp_opts_file;
1185 struct dyndir *dynamic_dirs;
1186 int dhcp_max, tftp_max, tftp_mtu;
1187 int dhcp_server_port, dhcp_client_port;
1188 int start_tftp_port, end_tftp_port;
1189 unsigned int min_leasetime;
1190 struct doctor *doctors;
1191 unsigned short edns_pktsz;
1193 struct tftp_prefix *if_prefix; /* per-interface TFTP prefixes */
1194 unsigned int duid_enterprise, duid_config_len;
1195 unsigned char *duid_config;
1200 unsigned long soa_sn, soa_refresh, soa_retry, soa_expiry;
1201 u32 metrics[__METRIC_MAX];
1202 int fast_retry_time, fast_retry_timeout;
1203 int cache_max_expiry;
1205 struct ds_config *ds;
1206 char *timestamp_file;
1209 /* globally used stuff for DNS */
1210 char *packet; /* packet buffer */
1211 int packet_buff_sz; /* size of above */
1212 char *namebuff; /* MAXDNAME size buffer */
1213 #if (defined(HAVE_CONNTRACK) && defined(HAVE_UBUS)) || defined(HAVE_DNSSEC)
1214 /* CONNTRACK UBUS code uses this buffer, as well as DNSSEC code. */
1215 char *workspacename;
1218 char *keyname; /* MAXDNAME size buffer */
1219 unsigned long *rr_status; /* ceiling in TTL from DNSSEC or zero for insecure */
1221 int dnssec_no_time_check;
1222 int back_to_the_future;
1224 struct frec *frec_list;
1225 struct frec_src *free_frec_src;
1227 struct serverfd *sfds;
1228 struct irec *interfaces;
1229 struct listener *listeners;
1230 struct server *srv_save; /* Used for resend on DoD */
1231 size_t packet_len; /* " " */
1232 int fd_save; /* " " */
1233 pid_t tcp_pids[MAX_PROCS];
1234 int tcp_pipes[MAX_PROCS];
1237 struct randfd *randomsocks;
1238 struct randfd_list *rfl_spare, *rfl_poll;
1240 struct addrlist *interface_addrs; /* list of all addresses/prefix lengths associated with all local interfaces */
1241 int log_id, log_display_id; /* ids of transactions for logging */
1242 union mysockaddr *log_source_addr;
1245 int dhcpfd, helperfd, pxefd;
1249 #if defined(HAVE_LINUX_NETWORK)
1250 int netlinkfd, kernel_version;
1251 #elif defined(HAVE_BSD_NETWORK)
1252 int dhcp_raw_fd, dhcp_icmp_fd, routefd;
1254 struct iovec dhcp_packet;
1255 char *dhcp_buff, *dhcp_buff2, *dhcp_buff3;
1256 struct ping_result *ping_results;
1258 struct dhcp_bridge *bridges;
1259 struct shared_network *shared_networks;
1262 unsigned char *duid;
1263 struct iovec outpacket;
1264 int dhcp6fd, icmp6fd;
1266 struct snoop_record *free_snoops;
1271 /* void * here to avoid depending on dbus headers outside dbus.c */
1274 struct watch *watches;
1279 /* void * here to avoid depending on ubus headers outside ubus.c */
1284 struct tftp_transfer *tftp_trans, *tftp_done_trans;
1286 /* utility string buffer, hold max sized IP address as string */
1288 char *addrbuff2; /* only allocated when OPT_EXTRALOG */
1290 #ifdef HAVE_DUMPFILE
1291 /* file for packet dumps. */
1296 struct server_details {
1297 union mysockaddr *addr, *source_addr;
1298 struct addrinfo *hostinfo, *orig_hostinfo;
1299 char *interface, *source, *scope_id, *interface_opt;
1300 int serv_port, source_port, addr_type, scope_index, valid;
1305 void cache_init(void);
1306 void next_uid(struct crec *crecp);
1307 void log_query(unsigned int flags, char *name, union all_addr *addr, char *arg, unsigned short type);
1308 char *record_source(unsigned int index);
1309 int cache_find_non_terminal(char *name, time_t now);
1310 struct crec *cache_find_by_addr(struct crec *crecp,
1311 union all_addr *addr, time_t now,
1313 struct crec *cache_find_by_name(struct crec *crecp,
1314 char *name, time_t now, unsigned int prot);
1315 void cache_end_insert(void);
1316 void cache_start_insert(void);
1317 unsigned int cache_remove_uid(const unsigned int uid);
1318 int cache_recv_insert(time_t now, int fd);
1319 struct crec *cache_insert(char *name, union all_addr *addr, unsigned short class,
1320 time_t now, unsigned long ttl, unsigned int flags);
1321 void cache_reload(void);
1322 void cache_add_dhcp_entry(char *host_name, int prot, union all_addr *host_address, time_t ttd);
1323 struct in_addr a_record_from_hosts(char *name, time_t now);
1324 void cache_unhash_dhcp(void);
1325 void dump_cache(time_t now);
1327 int cache_make_stat(struct txt_record *t);
1329 char *cache_get_name(struct crec *crecp);
1330 char *cache_get_cname_target(struct crec *crecp);
1331 struct crec *cache_enumerate(int init);
1332 int read_hostsfile(char *filename, unsigned int index, int cache_size,
1333 struct crec **rhash, int hashsz);
1336 void blockdata_init(void);
1337 void blockdata_report(void);
1338 struct blockdata *blockdata_alloc(char *data, size_t len);
1339 void *blockdata_retrieve(struct blockdata *block, size_t len, void *data);
1340 struct blockdata *blockdata_read(int fd, size_t len);
1341 void blockdata_write(struct blockdata *block, size_t len, int fd);
1342 void blockdata_free(struct blockdata *blocks);
1345 char *get_domain(struct in_addr addr);
1346 char *get_domain6(struct in6_addr *addr);
1347 int is_name_synthetic(int flags, char *name, union all_addr *addr);
1348 int is_rev_synth(int flag, union all_addr *addr, char *name);
1351 int extract_name(struct dns_header *header, size_t plen, unsigned char **pp,
1352 char *name, int isExtract, int extrabytes);
1353 unsigned char *skip_name(unsigned char *ansp, struct dns_header *header, size_t plen, int extrabytes);
1354 unsigned char *skip_questions(struct dns_header *header, size_t plen);
1355 unsigned char *skip_section(unsigned char *ansp, int count, struct dns_header *header, size_t plen);
1356 unsigned int extract_request(struct dns_header *header, size_t qlen,
1357 char *name, unsigned short *typep);
1358 void setup_reply(struct dns_header *header, unsigned int flags, int ede);
1359 int extract_addresses(struct dns_header *header, size_t qlen, char *name,
1360 time_t now, struct ipsets *ipsets, struct ipsets *nftsets, int is_sign,
1361 int check_rebind, int no_cache_dnssec, int secure, int *doctored);
1362 #if defined(HAVE_CONNTRACK) && defined(HAVE_UBUS)
1363 void report_addresses(struct dns_header *header, size_t len, u32 mark);
1365 size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
1366 struct in_addr local_addr, struct in_addr local_netmask,
1367 time_t now, int ad_reqd, int do_bit, int have_pseudoheader,
1369 int check_for_bogus_wildcard(struct dns_header *header, size_t qlen, char *name,
1371 int check_for_ignored_address(struct dns_header *header, size_t qlen);
1372 int check_for_local_domain(char *name, time_t now);
1373 size_t resize_packet(struct dns_header *header, size_t plen,
1374 unsigned char *pheader, size_t hlen);
1375 int add_resource_record(struct dns_header *header, char *limit, int *truncp,
1376 int nameoffset, unsigned char **pp, unsigned long ttl,
1377 int *offset, unsigned short type, unsigned short class, char *format, ...);
1378 int in_arpa_name_2_addr(char *namein, union all_addr *addrp);
1379 int private_net(struct in_addr addr, int ban_localhost);
1383 size_t answer_auth(struct dns_header *header, char *limit, size_t qlen,
1384 time_t now, union mysockaddr *peer_addr, int local_query,
1385 int do_bit, int have_pseudoheader);
1386 int in_zone(struct auth_zone *zone, char *name, char **cut);
1391 size_t dnssec_generate_query(struct dns_header *header, unsigned char *end, char *name, int class, int type, int edns_pktsz);
1392 int dnssec_validate_by_ds(time_t now, struct dns_header *header, size_t plen, char *name, char *keyname, int class);
1393 int dnssec_validate_ds(time_t now, struct dns_header *header, size_t plen, char *name, char *keyname, int class);
1394 int dnssec_validate_reply(time_t now, struct dns_header *header, size_t plen, char *name, char *keyname, int *class,
1395 int check_unsigned, int *neganswer, int *nons, int *nsec_ttl);
1396 int dnskey_keytag(int alg, int flags, unsigned char *key, int keylen);
1397 size_t filter_rrsigs(struct dns_header *header, size_t plen);
1398 int setup_timestamp(void);
1399 int errflags_to_ede(int status);
1402 /* hash_questions.c */
1403 void hash_questions_init(void);
1404 unsigned char *hash_questions(struct dns_header *header, size_t plen, char *name);
1407 const struct nettle_hash *hash_find(char *name);
1408 int hash_init(const struct nettle_hash *hash, void **ctxp, unsigned char **digestp);
1409 int verify(struct blockdata *key_data, unsigned int key_len, unsigned char *sig, size_t sig_len,
1410 unsigned char *digest, size_t digest_len, int algo);
1411 char *ds_digest_name(int digest);
1412 char *algo_digest_name(int algo);
1413 char *nsec3_digest_name(int digest);
1416 void rand_init(void);
1417 unsigned short rand16(void);
1420 int legal_hostname(char *name);
1421 char *canonicalise(char *in, int *nomem);
1422 unsigned char *do_rfc1035_name(unsigned char *p, char *sval, char *limit);
1423 void *safe_malloc(size_t size);
1424 void safe_strncpy(char *dest, const char *src, size_t size);
1425 void safe_pipe(int *fd, int read_noblock);
1426 void *whine_malloc(size_t size);
1427 void *whine_realloc(void *ptr, size_t size);
1428 int sa_len(union mysockaddr *addr);
1429 int sockaddr_isequal(const union mysockaddr *s1, const union mysockaddr *s2);
1430 int sockaddr_isnull(const union mysockaddr *s);
1431 int hostname_order(const char *a, const char *b);
1432 int hostname_isequal(const char *a, const char *b);
1433 int hostname_issubdomain(char *a, char *b);
1434 time_t dnsmasq_time(void);
1435 u32 dnsmasq_milliseconds(void);
1436 int netmask_length(struct in_addr mask);
1437 int is_same_net(struct in_addr a, struct in_addr b, struct in_addr mask);
1438 int is_same_net_prefix(struct in_addr a, struct in_addr b, int prefix);
1439 int is_same_net6(struct in6_addr *a, struct in6_addr *b, int prefixlen);
1440 u64 addr6part(struct in6_addr *addr);
1441 void setaddr6part(struct in6_addr *addr, u64 host);
1442 int retry_send(ssize_t rc);
1443 void prettyprint_time(char *buf, unsigned int t);
1444 int prettyprint_addr(union mysockaddr *addr, char *buf);
1445 int parse_hex(char *in, unsigned char *out, int maxlen,
1446 unsigned int *wildcard_mask, int *mac_type);
1447 int memcmp_masked(unsigned char *a, unsigned char *b, int len,
1449 int expand_buf(struct iovec *iov, size_t size);
1450 char *print_mac(char *buff, unsigned char *mac, int len);
1451 int read_write(int fd, unsigned char *packet, int size, int rw);
1452 void close_fds(long max_fd, int spare1, int spare2, int spare3);
1453 int wildcard_match(const char* wildcard, const char* match);
1454 int wildcard_matchn(const char* wildcard, const char* match, int num);
1455 #ifdef HAVE_LINUX_NETWORK
1456 int kernel_version(void);
1460 void die(char *message, char *arg1, int exit_code) ATTRIBUTE_NORETURN;
1461 int log_start(struct passwd *ent_pw, int errfd);
1462 int log_reopen(char *log_file);
1464 void my_syslog(int priority, const char *format, ...);
1466 void set_log_writer(void);
1467 void check_log_writer(int force);
1468 void flush_log(void);
1471 void read_opts (int argc, char **argv, char *compile_opts);
1472 char *option_string(int prot, unsigned int opt, unsigned char *val,
1473 int opt_len, char *buf, int buf_len);
1474 void reread_dhcp(void);
1475 void read_servers_file(void);
1476 void set_option_bool(unsigned int opt);
1477 void reset_option_bool(unsigned int opt);
1478 struct hostsfile *expand_filelist(struct hostsfile *list);
1479 char *parse_server(char *arg, struct server_details *sdetails);
1480 char *parse_server_addr(struct server_details *sdetails);
1481 int parse_server_next(struct server_details *sdetails);
1482 int option_read_dynfile(char *file, int flags);
1485 void reply_query(int fd, time_t now);
1486 void receive_query(struct listener *listen, time_t now);
1487 unsigned char *tcp_request(int confd, time_t now,
1488 union mysockaddr *local_addr, struct in_addr netmask, int auth_dns);
1489 void server_gone(struct server *server);
1490 int send_from(int fd, int nowild, char *packet, size_t len,
1491 union mysockaddr *to, union all_addr *source,
1492 unsigned int iface);
1493 void resend_query(void);
1494 int allocate_rfd(struct randfd_list **fdlp, struct server *serv);
1495 void free_rfds(struct randfd_list **fdlp);
1496 int fast_retry(time_t now);
1499 int indextoname(int fd, int index, char *name);
1500 int local_bind(int fd, union mysockaddr *addr, char *intname, unsigned int ifindex, int is_tcp);
1501 void pre_allocate_sfds(void);
1502 int reload_servers(char *fname);
1503 void check_servers(int no_loop_call);
1504 int enumerate_interfaces(int reset);
1505 void create_wildcard_listeners(void);
1506 void create_bound_listeners(int dienow);
1507 void warn_bound_listeners(void);
1508 void warn_wild_labels(void);
1509 void warn_int_names(void);
1510 int is_dad_listeners(void);
1511 int iface_check(int family, union all_addr *addr, char *name, int *auth);
1512 int loopback_exception(int fd, int family, union all_addr *addr, char *name);
1513 int label_exception(int index, int family, union all_addr *addr);
1515 int tcp_interface(int fd, int af);
1516 int set_ipv6pktinfo(int fd);
1518 void join_multicast(int dienow);
1520 #if defined(HAVE_LINUX_NETWORK) || defined(HAVE_BSD_NETWORK)
1521 void newaddress(time_t now);
1527 void dhcp_init(void);
1528 void dhcp_packet(time_t now, int pxe_fd);
1529 struct dhcp_context *address_available(struct dhcp_context *context,
1530 struct in_addr taddr,
1531 struct dhcp_netid *netids);
1532 struct dhcp_context *narrow_context(struct dhcp_context *context,
1533 struct in_addr taddr,
1534 struct dhcp_netid *netids);
1535 struct ping_result *do_icmp_ping(time_t now, struct in_addr addr,
1536 unsigned int hash, int loopback);
1537 int address_allocate(struct dhcp_context *context,
1538 struct in_addr *addrp, unsigned char *hwaddr, int hw_len,
1539 struct dhcp_netid *netids, time_t now, int loopback);
1540 void dhcp_read_ethers(void);
1541 struct dhcp_config *config_find_by_address(struct dhcp_config *configs, struct in_addr addr);
1542 char *host_from_dns(struct in_addr addr);
1547 void lease_update_file(time_t now);
1548 void lease_update_dns(int force);
1549 void lease_init(time_t now);
1550 struct dhcp_lease *lease4_allocate(struct in_addr addr);
1552 struct dhcp_lease *lease6_allocate(struct in6_addr *addrp, int lease_type);
1553 struct dhcp_lease *lease6_find(unsigned char *clid, int clid_len,
1554 int lease_type, unsigned int iaid, struct in6_addr *addr);
1555 void lease6_reset(void);
1556 struct dhcp_lease *lease6_find_by_client(struct dhcp_lease *first, int lease_type,
1557 unsigned char *clid, int clid_len, unsigned int iaid);
1558 struct dhcp_lease *lease6_find_by_addr(struct in6_addr *net, int prefix, u64 addr);
1559 u64 lease_find_max_addr6(struct dhcp_context *context);
1560 void lease_ping_reply(struct in6_addr *sender, unsigned char *packet, char *interface);
1561 void lease_update_slaac(time_t now);
1562 void lease_set_iaid(struct dhcp_lease *lease, unsigned int iaid);
1563 void lease_make_duid(time_t now);
1565 void lease_set_hwaddr(struct dhcp_lease *lease, const unsigned char *hwaddr,
1566 const unsigned char *clid, int hw_len, int hw_type,
1567 int clid_len, time_t now, int force);
1568 void lease_set_hostname(struct dhcp_lease *lease, const char *name, int auth, char *domain, char *config_domain);
1569 void lease_set_expires(struct dhcp_lease *lease, unsigned int len, time_t now);
1570 void lease_set_interface(struct dhcp_lease *lease, int interface, time_t now);
1571 struct dhcp_lease *lease_find_by_client(unsigned char *hwaddr, int hw_len, int hw_type,
1572 unsigned char *clid, int clid_len);
1573 struct dhcp_lease *lease_find_by_addr(struct in_addr addr);
1574 struct in_addr lease_find_max_addr(struct dhcp_context *context);
1575 void lease_prune(struct dhcp_lease *target, time_t now);
1576 void lease_update_from_configs(void);
1577 int do_script_run(time_t now);
1578 void rerun_scripts(void);
1579 void lease_find_interfaces(time_t now);
1581 void lease_add_extradata(struct dhcp_lease *lease, unsigned char *data,
1582 unsigned int len, int delim);
1588 size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
1589 size_t sz, time_t now, int unicast_dest, int loopback,
1590 int *is_inform, int pxe, struct in_addr fallback, time_t recvtime);
1591 unsigned char *extended_hwaddr(int hwtype, int hwlen, unsigned char *hwaddr,
1592 int clid_len, unsigned char *clid, int *len_out);
1597 int make_icmp_sock(void);
1598 int icmp_ping(struct in_addr addr);
1599 int delay_dhcp(time_t start, int sec, int fd, uint32_t addr, unsigned short id);
1601 void queue_event(int event);
1602 void send_alarm(time_t event, time_t now);
1603 void send_event(int fd, int event, int data, char *msg);
1604 void clear_cache_and_reload(time_t now);
1607 #ifdef HAVE_LINUX_NETWORK
1608 char *netlink_init(void);
1609 void netlink_multicast(void);
1613 #ifdef HAVE_BSD_NETWORK
1614 void init_bpf(void);
1615 void send_via_bpf(struct dhcp_packet *mess, size_t len,
1616 struct in_addr iface_addr, struct ifreq *ifr);
1617 void route_init(void);
1618 void route_sock(void);
1621 /* bpf.c or netlink.c */
1622 int iface_enumerate(int family, void *parm, int (callback)());
1626 char *dbus_init(void);
1627 void check_dbus_listeners(void);
1628 void set_dbus_listeners(void);
1630 void emit_dbus_signal(int action, struct dhcp_lease *lease, char *hostname);
1636 char *ubus_init(void);
1637 void set_ubus_listeners(void);
1638 void check_ubus_listeners(void);
1639 void ubus_event_bcast(const char *type, const char *mac, const char *ip, const char *name, const char *interface);
1640 # ifdef HAVE_CONNTRACK
1641 void ubus_event_bcast_connmark_allowlist_refused(u32 mark, const char *name);
1642 void ubus_event_bcast_connmark_allowlist_resolved(u32 mark, const char *pattern, const char *ip, u32 ttl);
1648 void ipset_init(void);
1649 int add_to_ipset(const char *setname, const union all_addr *ipaddr, int flags, int remove);
1654 void nftset_init(void);
1655 int add_to_nftset(const char *setpath, const union all_addr *ipaddr, int flags, int remove);
1659 #ifdef HAVE_CONNTRACK
1660 int is_valid_dns_name(const char *value);
1661 int is_valid_dns_name_pattern(const char *value);
1662 int is_dns_name_matching_pattern(const char *name, const char *pattern);
1666 #if defined(HAVE_SCRIPT)
1667 int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd);
1668 void helper_write(void);
1669 void queue_script(int action, struct dhcp_lease *lease,
1670 char *hostname, time_t now);
1672 void queue_tftp(off_t file_len, char *filename, union mysockaddr *peer);
1674 void queue_arp(int action, unsigned char *mac, int maclen,
1675 int family, union all_addr *addr);
1676 int helper_buf_empty(void);
1678 void queue_relay_snoop(struct in6_addr *client, int if_index, struct in6_addr *prefix, int prefix_len);
1684 void tftp_request(struct listener *listen, time_t now);
1685 void check_tftp_listeners(time_t now);
1686 int do_tftp_script_run(void);
1690 #ifdef HAVE_CONNTRACK
1691 int get_incoming_mark(union mysockaddr *peer_addr, union all_addr *local_addr,
1692 int istcp, unsigned int *markp);
1697 void dhcp6_init(void);
1698 void dhcp6_packet(time_t now);
1699 struct dhcp_context *address6_allocate(struct dhcp_context *context, unsigned char *clid, int clid_len, int temp_addr,
1700 unsigned int iaid, int serial, struct dhcp_netid *netids, int plain_range, struct in6_addr *ans);
1701 struct dhcp_context *address6_available(struct dhcp_context *context,
1702 struct in6_addr *taddr,
1703 struct dhcp_netid *netids,
1705 struct dhcp_context *address6_valid(struct dhcp_context *context,
1706 struct in6_addr *taddr,
1707 struct dhcp_netid *netids,
1709 struct dhcp_config *config_find_by_address6(struct dhcp_config *configs, struct in6_addr *net,
1710 int prefix, struct in6_addr *addr);
1711 void make_duid(time_t now);
1712 void dhcp_construct_contexts(time_t now);
1713 void get_client_mac(struct in6_addr *client, int iface, unsigned char *mac,
1714 unsigned int *maclenp, unsigned int *mactypep, time_t now);
1719 unsigned short dhcp6_reply(struct dhcp_context *context, int interface, char *iface_name,
1720 struct in6_addr *fallback, struct in6_addr *ll_addr, struct in6_addr *ula_addr,
1721 size_t sz, struct in6_addr *client_addr, time_t now);
1722 int relay_upstream6(int iface_index, ssize_t sz, struct in6_addr *peer_address,
1723 u32 scope_id, time_t now);
1725 int relay_reply6( struct sockaddr_in6 *peer, ssize_t sz, char *arrival_interface);
1727 int do_snoop_script_run(void);
1733 void dhcp_common_init(void);
1734 ssize_t recv_dhcp_packet(int fd, struct msghdr *msg);
1735 struct dhcp_netid *run_tag_if(struct dhcp_netid *tags);
1736 struct dhcp_netid *option_filter(struct dhcp_netid *tags, struct dhcp_netid *context_tags,
1737 struct dhcp_opt *opts);
1738 int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool, int tagnotneeded);
1739 char *strip_hostname(char *hostname);
1740 void log_tags(struct dhcp_netid *netid, u32 xid);
1741 int match_bytes(struct dhcp_opt *o, unsigned char *p, int len);
1742 void dhcp_update_configs(struct dhcp_config *configs);
1743 void display_opts(void);
1744 int lookup_dhcp_opt(int prot, char *name);
1745 int lookup_dhcp_len(int prot, int val);
1746 struct dhcp_config *find_config(struct dhcp_config *configs,
1747 struct dhcp_context *context,
1748 unsigned char *clid, int clid_len,
1749 unsigned char *hwaddr, int hw_len,
1750 int hw_type, char *hostname,
1751 struct dhcp_netid *filter);
1752 int config_has_mac(struct dhcp_config *config, unsigned char *hwaddr, int len, int type);
1753 #ifdef HAVE_LINUX_NETWORK
1754 char *whichdevice(void);
1755 int bind_dhcp_devices(char *bound_device);
1758 void display_opts6(void);
1760 void log_context(int family, struct dhcp_context *context);
1761 void log_relay(int family, struct dhcp_relay *relay);
1766 void end_opt6(int container);
1767 void reset_counter(void);
1768 int save_counter(int newval);
1769 void *expand(size_t headroom);
1770 int new_opt6(int opt);
1771 void *put_opt6(void *data, size_t len);
1772 void put_opt6_long(unsigned int val);
1773 void put_opt6_short(unsigned int val);
1774 void put_opt6_char(unsigned int val);
1775 void put_opt6_string(char *s);
1780 void ra_init(time_t now);
1781 void icmp6_packet(time_t now);
1782 time_t periodic_ra(time_t now);
1783 void ra_start_unsolicited(time_t now, struct dhcp_context *context);
1788 void slaac_add_addrs(struct dhcp_lease *lease, time_t now, int force);
1789 time_t periodic_slaac(time_t now, struct dhcp_lease *leases);
1790 void slaac_ping_reply(struct in6_addr *sender, unsigned char *packet, char *interface, struct dhcp_lease *leases);
1795 void loop_send_probes(void);
1796 int detect_loop(char *query, int type);
1801 void inotify_dnsmasq_init(void);
1802 int inotify_check(time_t now);
1803 void set_dynamic_inotify(int flag, int total_size, struct crec **rhash, int revhashsz);
1807 void poll_reset(void);
1808 int poll_check(int fd, short event);
1809 void poll_listen(int fd, short event);
1810 int do_poll(int timeout);
1813 size_t rrfilter(struct dns_header *header, size_t plen, int mode);
1814 u16 *rrfilter_desc(int type);
1815 int expand_workspace(unsigned char ***wkspc, int *szp, int new);
1817 #define RRFILTER_EDNS0 0
1818 #define RRFILTER_DNSSEC 1
1819 #define RRFILTER_A 2
1820 #define RRFILTER_AAAA 3
1822 unsigned char *find_pseudoheader(struct dns_header *header, size_t plen,
1823 size_t *len, unsigned char **p, int *is_sign, int *is_last);
1824 size_t add_pseudoheader(struct dns_header *header, size_t plen, unsigned char *limit,
1825 unsigned short udp_sz, int optno, unsigned char *opt, size_t optlen, int set_do, int replace);
1826 size_t add_do_bit(struct dns_header *header, size_t plen, unsigned char *limit);
1827 size_t add_edns0_config(struct dns_header *header, size_t plen, unsigned char *limit,
1828 union mysockaddr *source, time_t now, int *cacheable);
1829 int check_source(struct dns_header *header, size_t plen, unsigned char *pseudoheader, union mysockaddr *peer);
1832 int find_mac(union mysockaddr *addr, unsigned char *mac, int lazy, time_t now);
1833 int do_arp_script_run(void);
1836 #ifdef HAVE_DUMPFILE
1837 void dump_init(void);
1838 void dump_packet_udp(int mask, void *packet, size_t len, union mysockaddr *src,
1839 union mysockaddr *dst, int fd);
1840 void dump_packet_icmp(int mask, void *packet, size_t len, union mysockaddr *src,
1841 union mysockaddr *dst);
1844 /* domain-match.c */
1845 void build_server_array(void);
1846 int lookup_domain(char *qdomain, int flags, int *lowout, int *highout);
1847 int filter_servers(int seed, int flags, int *lowout, int *highout);
1848 int is_local_answer(time_t now, int first, char *name);
1849 size_t make_local_answer(int flags, int gotname, size_t size, struct dns_header *header,
1850 char *name, char *limit, int first, int last, int ede);
1851 int server_samegroup(struct server *a, struct server *b);
1853 int dnssec_server(struct server *server, char *keyname, int *firstp, int *lastp);
1855 void mark_servers(int flag);
1856 void cleanup_servers(void);
1857 int add_update_server(int flags,
1858 union mysockaddr *addr,
1859 union mysockaddr *source_addr,
1860 const char *interface,
1862 union all_addr *local_addr);