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

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

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