Annotation of embedaddon/dnsmasq/src/dnsmasq.h, revision 1.1.1.5

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

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>