]> git.ipfire.org Git - people/ms/dnsmasq.git/blame - src/dnsmasq.h
import of dnsmasq-2.57.tar.gz
[people/ms/dnsmasq.git] / src / dnsmasq.h
CommitLineData
28866e95 1/* dnsmasq is Copyright (c) 2000-2011 Simon Kelley
824af85b 2
9e4abcb5
SK
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
824af85b
SK
5 the Free Software Foundation; version 2 dated June, 1991, or
6 (at your option) version 3 dated 29 June, 2007.
7
9e4abcb5
SK
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.
824af85b 12
73a08a24
SK
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/>.
9e4abcb5
SK
15*/
16
28866e95 17#define COPYRIGHT "Copyright (c) 2000-2011 Simon Kelley"
9e4abcb5 18
1a6bca81 19#ifndef NO_LARGEFILE
9e038946 20/* Ensure we can use files >2GB (log files may grow this big) */
1a6bca81
SK
21# define _LARGEFILE_SOURCE 1
22# define _FILE_OFFSET_BITS 64
23#endif
9e038946 24
8ef5ada2
SK
25/* Get linux C library versions and define _GNU_SOURCE for kFreeBSD. */
26#if defined(__linux__) || defined(__GLIBC__)
572b41eb
SK
27# ifndef __ANDROID__
28# define _GNU_SOURCE
29# endif
9e038946
SK
30# include <features.h>
31#endif
32
316e2730
SK
33/* Need these defined early */
34#if defined(__sun) || defined(__sun__)
35# define _XPG4_2
36# define __EXTENSIONS__
37#endif
38
9e4abcb5 39/* get these before config.h for IPv6 stuff... */
44a2a316 40#include <sys/types.h>
1f15b81d 41#include <sys/socket.h>
9e4abcb5
SK
42#include <netinet/in.h>
43
59353a6b
SK
44/* and this. */
45#include <getopt.h>
46
9e4abcb5 47#include "config.h"
b8187c80 48
572b41eb
SK
49typedef unsigned char u8;
50typedef unsigned short u16;
51typedef unsigned int u32;
52
53#include "dns_protocol.h"
54#include "dhcp_protocol.h"
55
b8187c80 56#define gettext_noop(S) (S)
824af85b 57#ifndef LOCALEDIR
b8187c80
SK
58# define _(S) (S)
59#else
60# include <libintl.h>
61# include <locale.h>
62# define _(S) gettext(S)
63#endif
64
9e4abcb5
SK
65#include <arpa/inet.h>
66#include <sys/stat.h>
9e4abcb5 67#include <sys/ioctl.h>
824af85b 68#if defined(HAVE_SOLARIS_NETWORK)
316e2730 69# include <sys/sockio.h>
824af85b 70#endif
9e4abcb5 71#include <sys/select.h>
feba5c1d 72#include <sys/wait.h>
9e4abcb5 73#include <sys/time.h>
f2621c7f 74#include <sys/un.h>
8a911ccc 75#include <limits.h>
9e4abcb5 76#include <net/if.h>
316e2730
SK
77#if defined(HAVE_SOLARIS_NETWORK) && !defined(ifr_mtu)
78/* Some solaris net/if./h omit this. */
79# define ifr_mtu ifr_ifru.ifru_metric
80#endif
9e4abcb5
SK
81#include <unistd.h>
82#include <stdio.h>
83#include <string.h>
84#include <stdlib.h>
85#include <fcntl.h>
86#include <ctype.h>
87#include <signal.h>
9e038946 88#include <stddef.h>
9e4abcb5
SK
89#include <time.h>
90#include <errno.h>
91#include <pwd.h>
92#include <grp.h>
f6b7dc47 93#include <stdarg.h>
572b41eb 94#if defined(__OpenBSD__) || defined(__NetBSD__) || defined(__sun__) || defined (__sun) || defined (__ANDROID__)
44a2a316
SK
95# include <netinet/if_ether.h>
96#else
97# include <net/ethernet.h>
98#endif
9e4abcb5
SK
99#include <net/if_arp.h>
100#include <netinet/in_systm.h>
101#include <netinet/ip.h>
3be34541 102#include <netinet/ip_icmp.h>
5e9e0efb 103#include <sys/uio.h>
849a8357
SK
104#include <syslog.h>
105#include <dirent.h>
5e9e0efb 106#ifndef HAVE_LINUX_NETWORK
44a2a316 107# include <net/if_dl.h>
9e4abcb5 108#endif
5e9e0efb 109
824af85b 110#if defined(HAVE_LINUX_NETWORK)
5e9e0efb
SK
111#include <linux/capability.h>
112/* There doesn't seem to be a universally-available
9e038946 113 userpace header for these. */
5e9e0efb 114extern int capset(cap_user_header_t header, cap_user_data_t data);
9e038946
SK
115extern int capget(cap_user_header_t header, cap_user_data_t data);
116#define LINUX_CAPABILITY_VERSION_1 0x19980330
117#define LINUX_CAPABILITY_VERSION_2 0x20071026
1a6bca81 118#define LINUX_CAPABILITY_VERSION_3 0x20080522
9e038946 119
5e9e0efb 120#include <sys/prctl.h>
7622fc06 121#elif defined(HAVE_SOLARIS_NETWORK)
824af85b 122#include <priv.h>
5e9e0efb 123#endif
9e4abcb5 124
824af85b 125/* daemon is function in the C library.... */
5aabfc78
SK
126#define daemon dnsmasq_daemon
127
128/* Async event queue */
129struct event_desc {
130 int event, data;
131};
132
133#define EVENT_RELOAD 1
134#define EVENT_DUMP 2
135#define EVENT_ALARM 3
136#define EVENT_TERM 4
137#define EVENT_CHILD 5
138#define EVENT_REOPEN 6
139#define EVENT_EXITED 7
140#define EVENT_KILLED 8
141#define EVENT_EXEC_ERR 9
142#define EVENT_PIPE_ERR 10
9e038946 143#define EVENT_USER_ERR 11
1a6bca81
SK
144#define EVENT_CAP_ERR 12
145#define EVENT_PIDFILE 13
146#define EVENT_HUSER_ERR 14
147#define EVENT_GROUP_ERR 15
148#define EVENT_DIE 16
149#define EVENT_LOG_ERR 17
7622fc06 150#define EVENT_FORK_ERR 18
5aabfc78
SK
151
152/* Exit codes. */
153#define EC_GOOD 0
154#define EC_BADCONF 1
155#define EC_BADNET 2
156#define EC_FILE 3
157#define EC_NOMEM 4
158#define EC_MISC 5
159#define EC_INIT_OFFSET 10
160
0a852541
SK
161/* Min buffer size: we check after adding each record, so there must be
162 memory for the largest packet, and the largest record so the
163 min for DNS is PACKETSZ+MAXDNAME+RRFIXEDSZ which is < 1000.
164 This might be increased is EDNS packet size if greater than the minimum.
cdeda28f
SK
165*/
166#define DNSMASQ_PACKETSZ PACKETSZ+MAXDNAME+RRFIXEDSZ
44a2a316 167
572b41eb 168/* Trust the compiler dead-code eliminator.... */
28866e95
SK
169#define option_bool(x) (((x) < 32) ? daemon->options & (1u << (x)) : daemon->options2 & (1u << ((x) - 32)))
170
171#define OPT_BOGUSPRIV 0
172#define OPT_FILTER 1
173#define OPT_LOG 2
174#define OPT_SELFMX 3
175#define OPT_NO_HOSTS 4
176#define OPT_NO_POLL 5
177#define OPT_DEBUG 6
178#define OPT_ORDER 7
179#define OPT_NO_RESOLV 8
180#define OPT_EXPAND 9
181#define OPT_LOCALMX 10
182#define OPT_NO_NEG 11
183#define OPT_NODOTS_LOCAL 12
184#define OPT_NOWILD 13
185#define OPT_ETHERS 14
186#define OPT_RESOLV_DOMAIN 15
187#define OPT_NO_FORK 16
188#define OPT_AUTHORITATIVE 17
189#define OPT_LOCALISE 18
190#define OPT_DBUS 19
191#define OPT_DHCP_FQDN 20
192#define OPT_NO_PING 21
193#define OPT_LEASE_RO 22
194#define OPT_ALL_SERVERS 23
195#define OPT_RELOAD 24
196#define OPT_LOCAL_REBIND 25
197#define OPT_TFTP_SECURE 26
198#define OPT_TFTP_NOBLOCK 27
199#define OPT_LOG_OPTS 28
200#define OPT_TFTP_APREF 29
201#define OPT_NO_OVERRIDE 30
202#define OPT_NO_REBIND 31
203#define OPT_ADD_MAC 32
204#define OPT_DNSSEC 33
205#define OPT_LAST 34
9e4abcb5 206
7622fc06
SK
207/* extra flags for my_syslog, we use a couple of facilities since they are known
208 not to occupy the same bits as priorities, no matter how syslog.h is set up. */
209#define MS_TFTP LOG_USER
210#define MS_DHCP LOG_DAEMON
211
9e4abcb5
SK
212struct all_addr {
213 union {
214 struct in_addr addr4;
215#ifdef HAVE_IPV6
216 struct in6_addr addr6;
217#endif
218 } addr;
219};
220
221struct bogus_addr {
222 struct in_addr addr;
223 struct bogus_addr *next;
224};
225
1cff166d
SK
226/* dns doctor param */
227struct doctor {
73a08a24 228 struct in_addr in, end, out, mask;
1cff166d
SK
229 struct doctor *next;
230};
231
0a852541
SK
232struct mx_srv_record {
233 char *name, *target;
3d8df260
SK
234 int issrv, srvport, priority, weight;
235 unsigned int offset;
0a852541 236 struct mx_srv_record *next;
de37951c
SK
237};
238
1a6bca81
SK
239struct naptr {
240 char *name, *replace, *regexp, *services, *flags;
241 unsigned int order, pref;
242 struct naptr *next;
243};
244
0a852541 245struct txt_record {
28866e95
SK
246 char *name;
247 unsigned char *txt;
0a852541
SK
248 unsigned short class, len;
249 struct txt_record *next;
f6b7dc47
SK
250};
251
832af0ba
SK
252struct ptr_record {
253 char *name, *ptr;
254 struct ptr_record *next;
255};
256
9009d746
SK
257struct cname {
258 char *alias, *target;
259 struct cname *next;
260};
261
f2621c7f
SK
262struct interface_name {
263 char *name; /* domain name */
264 char *intr; /* interface name */
265 struct interface_name *next;
266};
267
9e4abcb5
SK
268union bigname {
269 char name[MAXDNAME];
270 union bigname *next; /* freelist */
271};
272
273struct crec {
274 struct crec *next, *prev, *hash_next;
275 time_t ttd; /* time to die */
fd9fa481
SK
276 int uid;
277 union {
278 struct all_addr addr;
279 struct {
280 struct crec *cache;
281 int uid;
282 } cname;
283 } addr;
9e4abcb5
SK
284 unsigned short flags;
285 union {
286 char sname[SMALLDNAME];
287 union bigname *bname;
288 char *namep;
289 } name;
290};
291
28866e95
SK
292#define F_IMMORTAL (1u<<0)
293#define F_NAMEP (1u<<1)
294#define F_REVERSE (1u<<2)
295#define F_FORWARD (1u<<3)
296#define F_DHCP (1u<<4)
297#define F_NEG (1u<<5)
298#define F_HOSTS (1u<<6)
299#define F_IPV4 (1u<<7)
300#define F_IPV6 (1u<<8)
301#define F_BIGNAME (1u<<9)
302#define F_NXDOMAIN (1u<<10)
303#define F_CNAME (1u<<11)
304#define F_NOERR (1u<<12)
305#define F_CONFIG (1u<<13)
306/* below here are only valid as args to log_query: cache
307 entries are limited to 16 bits */
308#define F_UPSTREAM (1u<<16)
309#define F_RRNAME (1u<<17)
310#define F_SERVER (1u<<18)
311#define F_QUERY (1u<<19)
312#define F_NSRR (1u<<20)
313
9e4abcb5
SK
314
315/* struct sockaddr is not large enough to hold any address,
cdeda28f 316 and specifically not big enough to hold an IPv6 address.
9e4abcb5
SK
317 Blech. Roll our own. */
318union mysockaddr {
319 struct sockaddr sa;
320 struct sockaddr_in in;
7622fc06 321#if defined(HAVE_IPV6)
9e4abcb5
SK
322 struct sockaddr_in6 in6;
323#endif
324};
325
0a852541
SK
326#define SERV_FROM_RESOLV 1 /* 1 for servers from resolv, 0 for command line. */
327#define SERV_NO_ADDR 2 /* no server, this domain is local only */
328#define SERV_LITERAL_ADDRESS 4 /* addr is the answer, not the server */
5aabfc78
SK
329#define SERV_HAS_DOMAIN 8 /* server for one domain only */
330#define SERV_HAS_SOURCE 16 /* source address defined */
0a852541
SK
331#define SERV_FOR_NODOTS 32 /* server for names with no domain part only */
332#define SERV_WARNED_RECURSIVE 64 /* avoid warning spam */
3d8df260
SK
333#define SERV_FROM_DBUS 128 /* 1 if source is DBus */
334#define SERV_MARK 256 /* for mark-and-delete */
9e4abcb5 335#define SERV_TYPE (SERV_HAS_DOMAIN | SERV_FOR_NODOTS)
824af85b 336#define SERV_COUNTED 512 /* workspace for log code */
8ef5ada2
SK
337#define SERV_USE_RESOLV 1024 /* forward this domain in the normal way */
338#define SERV_NO_REBIND 2048 /* inhibit dns-rebind protection */
9e4abcb5
SK
339
340struct serverfd {
341 int fd;
342 union mysockaddr source_addr;
824af85b 343 char interface[IF_NAMESIZE+1];
9e4abcb5
SK
344 struct serverfd *next;
345};
346
1a6bca81
SK
347struct randfd {
348 int fd;
349 unsigned short refcount, family;
350};
351
9e4abcb5
SK
352struct server {
353 union mysockaddr addr, source_addr;
824af85b 354 char interface[IF_NAMESIZE+1];
1697269c 355 struct serverfd *sfd;
9e4abcb5 356 char *domain; /* set if this server only handles a domain. */
feba5c1d 357 int flags, tcpfd;
824af85b 358 unsigned int queries, failed_queries;
9e4abcb5
SK
359 struct server *next;
360};
361
9e4abcb5
SK
362struct irec {
363 union mysockaddr addr;
f6b7dc47 364 struct in_addr netmask; /* only valid for IPv4 */
8ef5ada2
SK
365 int tftp_ok, mtu;
366 char *name;
9e4abcb5
SK
367 struct irec *next;
368};
369
44a2a316 370struct listener {
832af0ba 371 int fd, tcpfd, tftpfd, family;
f6b7dc47 372 struct irec *iface; /* only valid for non-wildcard */
44a2a316
SK
373 struct listener *next;
374};
375
9e4abcb5
SK
376/* interface and address parms from command line. */
377struct iname {
378 char *name;
379 union mysockaddr addr;
de37951c 380 int isloop, used;
9e4abcb5
SK
381 struct iname *next;
382};
383
384/* resolv-file parms from command-line */
385struct resolvc {
386 struct resolvc *next;
3d8df260
SK
387 int is_default, logged;
388 time_t mtime;
9e4abcb5
SK
389 char *name;
390};
391
28866e95 392/* adn-hosts parms from command-line (also dhcp-hostsfile and dhcp-optsfile */
7622fc06
SK
393#define AH_DIR 1
394#define AH_INACTIVE 2
fd9fa481
SK
395struct hostsfile {
396 struct hostsfile *next;
7622fc06 397 int flags;
fd9fa481 398 char *fname;
cdeda28f 399 int index; /* matches to cache entries for logging */
fd9fa481
SK
400};
401
28866e95
SK
402#define FREC_NOREBIND 1
403#define FREC_CHECKING_DISABLED 2
404
9e4abcb5
SK
405struct frec {
406 union mysockaddr source;
44a2a316 407 struct all_addr dest;
832af0ba 408 struct server *sentto; /* NULL means free */
1a6bca81
SK
409 struct randfd *rfd4;
410#ifdef HAVE_IPV6
411 struct randfd *rfd6;
412#endif
dfa666f2 413 unsigned int iface;
9e4abcb5 414 unsigned short orig_id, new_id;
28866e95 415 int fd, forwardall, flags;
fd9fa481 416 unsigned int crc;
9e4abcb5
SK
417 time_t time;
418 struct frec *next;
419};
420
1697269c
SK
421/* actions in the daemon->helper RPC */
422#define ACTION_DEL 1
423#define ACTION_OLD_HOSTNAME 2
424#define ACTION_OLD 3
425#define ACTION_ADD 4
426
9e4abcb5
SK
427struct dhcp_lease {
428 int clid_len; /* length of client identifier */
429 unsigned char *clid; /* clientid */
430 char *hostname, *fqdn; /* name from client-hostname option or config */
1697269c 431 char *old_hostname; /* hostname before it moved to another lease */
7cebd20f
SK
432 char auth_name; /* hostname came from config, not from client */
433 char new; /* newly created */
208b65c5
SK
434 char changed; /* modified */
435 char aux_changed; /* CLID or expiry changed */
9e4abcb5 436 time_t expires; /* lease expiry */
5e9e0efb
SK
437#ifdef HAVE_BROKEN_RTC
438 unsigned int length;
439#endif
cdeda28f
SK
440 int hwaddr_len, hwaddr_type;
441 unsigned char hwaddr[DHCP_CHADDR_MAX];
1f15b81d 442 struct in_addr addr, override, giaddr;
316e2730
SK
443 unsigned char *extradata;
444 unsigned int extradata_len, extradata_size;
824af85b 445 int last_interface;
9e4abcb5
SK
446 struct dhcp_lease *next;
447};
448
a222641c
SK
449struct dhcp_netid {
450 char *net;
451 struct dhcp_netid *next;
452};
453
26128d27
SK
454struct dhcp_netid_list {
455 struct dhcp_netid *list;
456 struct dhcp_netid_list *next;
457};
1697269c 458
8ef5ada2
SK
459struct tag_if {
460 struct dhcp_netid_list *set;
461 struct dhcp_netid *tag;
462 struct tag_if *next;
463};
464
9009d746
SK
465struct hwaddr_config {
466 int hwaddr_len, hwaddr_type;
467 unsigned char hwaddr[DHCP_CHADDR_MAX];
468 unsigned int wildcard_mask;
469 struct hwaddr_config *next;
470};
471
9e4abcb5 472struct dhcp_config {
33820b7e 473 unsigned int flags;
9e4abcb5
SK
474 int clid_len; /* length of client identifier */
475 unsigned char *clid; /* clientid */
9009d746 476 char *hostname, *domain;
8ef5ada2 477 struct dhcp_netid_list *netid;
9e4abcb5 478 struct in_addr addr;
849a8357 479 time_t decline_time;
9009d746
SK
480 unsigned int lease_time;
481 struct hwaddr_config *hwaddr;
9e4abcb5
SK
482 struct dhcp_config *next;
483};
484
0a852541
SK
485#define CONFIG_DISABLE 1
486#define CONFIG_CLID 2
0a852541
SK
487#define CONFIG_TIME 8
488#define CONFIG_NAME 16
489#define CONFIG_ADDR 32
0a852541 490#define CONFIG_NOCLID 128
849a8357
SK
491#define CONFIG_FROM_ETHERS 256 /* entry created by /etc/ethers */
492#define CONFIG_ADDR_HOSTS 512 /* address added by from /etc/hosts */
493#define CONFIG_DECLINED 1024 /* address declined by client */
5aabfc78 494#define CONFIG_BANK 2048 /* from dhcp hosts file */
33820b7e 495
9e4abcb5 496struct dhcp_opt {
cdeda28f 497 int opt, len, flags;
73a08a24
SK
498 union {
499 int encap;
500 unsigned int wildcard_mask;
501 unsigned char *vendor_class;
502 } u;
503 unsigned char *val;
26128d27 504 struct dhcp_netid *netid;
9e4abcb5 505 struct dhcp_opt *next;
a84fa1d0
SK
506};
507
cdeda28f
SK
508#define DHOPT_ADDR 1
509#define DHOPT_STRING 2
6b01084f 510#define DHOPT_ENCAPSULATE 4
73a08a24 511#define DHOPT_ENCAP_MATCH 8
6b01084f 512#define DHOPT_FORCE 16
824af85b 513#define DHOPT_BANK 32
73a08a24
SK
514#define DHOPT_ENCAP_DONE 64
515#define DHOPT_MATCH 128
516#define DHOPT_VENDOR 256
517#define DHOPT_HEX 512
7622fc06 518#define DHOPT_VENDOR_MATCH 1024
316e2730 519#define DHOPT_RFC3925 2048
cdeda28f 520
26128d27
SK
521struct dhcp_boot {
522 char *file, *sname;
523 struct in_addr next_server;
524 struct dhcp_netid *netid;
525 struct dhcp_boot *next;
526};
527
7622fc06
SK
528struct pxe_service {
529 unsigned short CSA, type;
530 char *menu, *basename;
531 struct in_addr server;
532 struct dhcp_netid *netid;
533 struct pxe_service *next;
534};
535
f2621c7f
SK
536#define MATCH_VENDOR 1
537#define MATCH_USER 2
538#define MATCH_CIRCUIT 3
539#define MATCH_REMOTE 4
540#define MATCH_SUBSCRIBER 5
541
542/* vendorclass, userclass, remote-id or cicuit-id */
a84fa1d0 543struct dhcp_vendor {
824af85b 544 int len, match_type, option;
a222641c
SK
545 char *data;
546 struct dhcp_netid netid;
a84fa1d0
SK
547 struct dhcp_vendor *next;
548};
9e4abcb5 549
cdeda28f
SK
550struct dhcp_mac {
551 unsigned int mask;
552 int hwaddr_len, hwaddr_type;
553 unsigned char hwaddr[DHCP_CHADDR_MAX];
554 struct dhcp_netid netid;
555 struct dhcp_mac *next;
556};
557
832af0ba
SK
558struct dhcp_bridge {
559 char iface[IF_NAMESIZE];
560 struct dhcp_bridge *alias, *next;
561};
832af0ba 562
9009d746
SK
563struct cond_domain {
564 char *domain;
565 struct in_addr start, end;
566 struct cond_domain *next;
567};
568
9e4abcb5 569struct dhcp_context {
feba5c1d 570 unsigned int lease_time, addr_epoch;
0a852541
SK
571 struct in_addr netmask, broadcast;
572 struct in_addr local, router;
a84fa1d0 573 struct in_addr start, end; /* range of available addresses */
0a852541 574 int flags;
8ef5ada2 575 char *interface;
cdeda28f 576 struct dhcp_netid netid, *filter;
36717eee 577 struct dhcp_context *next, *current;
9e4abcb5
SK
578};
579
0a852541 580#define CONTEXT_STATIC 1
cdeda28f
SK
581#define CONTEXT_NETMASK 2
582#define CONTEXT_BRDCAST 4
7622fc06 583#define CONTEXT_PROXY 8
0a852541 584
3d8df260
SK
585struct ping_result {
586 struct in_addr addr;
587 time_t time;
588 struct ping_result *next;
589};
9e4abcb5 590
832af0ba
SK
591struct tftp_file {
592 int refcount, fd;
593 off_t size;
5aabfc78
SK
594 dev_t dev;
595 ino_t inode;
832af0ba
SK
596 char filename[];
597};
598
599struct tftp_transfer {
600 int sockfd;
601 time_t timeout;
602 int backoff;
9e038946
SK
603 unsigned int block, blocksize, expansion;
604 off_t offset;
28866e95 605 union mysockaddr peer;
9e038946 606 char opt_blocksize, opt_transize, netascii, carrylf;
832af0ba
SK
607 struct tftp_file *file;
608 struct tftp_transfer *next;
609};
610
8ef5ada2
SK
611struct addr_list {
612 struct in_addr addr;
613 struct addr_list *next;
614};
615
616struct interface_list {
617 char *interface;
618 struct interface_list *next;
619};
620
621struct tftp_prefix {
622 char *interface;
623 char *prefix;
624 struct tftp_prefix *next;
625};
626
627
5aabfc78 628extern struct daemon {
3be34541
SK
629 /* datastuctures representing the command-line and
630 config file arguments. All set (including defaults)
631 in option.c */
632
28866e95 633 unsigned int options, options2;
3be34541 634 struct resolvc default_resolv, *resolv_files;
9009d746 635 time_t last_resolv;
0a852541 636 struct mx_srv_record *mxnames;
1a6bca81 637 struct naptr *naptr;
0a852541 638 struct txt_record *txt;
832af0ba 639 struct ptr_record *ptr;
9009d746 640 struct cname *cnames;
f2621c7f 641 struct interface_name *int_names;
3be34541
SK
642 char *mxtarget;
643 char *lease_file;
9e038946 644 char *username, *groupname, *scriptuser;
1a6bca81 645 int group_set, osport;
3be34541 646 char *domain_suffix;
9009d746 647 struct cond_domain *cond_domain;
3be34541 648 char *runfile;
7cebd20f 649 char *lease_change_command;
3d8df260 650 struct iname *if_names, *if_addrs, *if_except, *dhcp_except;
3be34541
SK
651 struct bogus_addr *bogus_addr;
652 struct server *servers;
849a8357 653 int log_fac; /* log facility */
f2621c7f
SK
654 char *log_file; /* optional log file */
655 int max_logs; /* queue limit */
208b65c5 656 int cachesize, ftabsize;
1a6bca81 657 int port, query_port, min_port;
8ef5ada2 658 unsigned long local_ttl, neg_ttl, max_ttl;
fd9fa481 659 struct hostsfile *addn_hosts;
3be34541
SK
660 struct dhcp_context *dhcp;
661 struct dhcp_config *dhcp_conf;
73a08a24 662 struct dhcp_opt *dhcp_opts, *dhcp_match;
3be34541 663 struct dhcp_vendor *dhcp_vendors;
cdeda28f 664 struct dhcp_mac *dhcp_macs;
26128d27 665 struct dhcp_boot *boot_config;
7622fc06 666 struct pxe_service *pxe_services;
8ef5ada2
SK
667 struct tag_if *tag_if;
668 struct addr_list *override_relays;
669 int override;
1f15b81d 670 int enable_pxe;
8ef5ada2
SK
671 struct dhcp_netid_list *dhcp_ignore, *dhcp_ignore_names, *dhcp_gen_names;
672 struct dhcp_netid_list *force_broadcast, *bootp_dynamic;
28866e95 673 struct hostsfile *dhcp_hosts_file, *dhcp_opts_file;
824af85b 674 int dhcp_max, tftp_max;
9e038946 675 int dhcp_server_port, dhcp_client_port;
824af85b 676 int start_tftp_port, end_tftp_port;
3be34541
SK
677 unsigned int min_leasetime;
678 struct doctor *doctors;
679 unsigned short edns_pktsz;
824af85b 680 char *tftp_prefix;
8ef5ada2
SK
681 struct tftp_prefix *if_prefix; /* per-interface TFTP prefixes */
682 struct interface_list *tftp_interfaces; /* interfaces for limited TFTP service */
683 int tftp_unlimited;
3be34541
SK
684
685 /* globally used stuff for DNS */
686 char *packet; /* packet buffer */
0a852541 687 int packet_buff_sz; /* size of above */
3be34541 688 char *namebuff; /* MAXDNAME size buffer */
824af85b 689 unsigned int local_answer, queries_forwarded;
1a6bca81 690 struct frec *frec_list;
3be34541 691 struct serverfd *sfds;
3d8df260 692 struct irec *interfaces;
3be34541
SK
693 struct listener *listeners;
694 struct server *last_server;
1f15b81d
SK
695 time_t forwardtime;
696 int forwardcount;
cdeda28f
SK
697 struct server *srv_save; /* Used for resend on DoD */
698 size_t packet_len; /* " " */
3927da46 699 struct randfd *rfd_save; /* " " */
7622fc06 700 pid_t tcp_pids[MAX_PROCS];
1a6bca81 701 struct randfd randomsocks[RANDOM_SOCKS];
316e2730 702 int v6pktinfo;
1a6bca81 703
3be34541 704 /* DHCP state */
316e2730 705 int dhcpfd, helperfd, pxefd;
7622fc06 706#if defined(HAVE_LINUX_NETWORK)
0a852541 707 int netlinkfd;
7622fc06 708#elif defined(HAVE_BSD_NETWORK)
5e9e0efb 709 int dhcp_raw_fd, dhcp_icmp_fd;
0a852541 710#endif
5e9e0efb 711 struct iovec dhcp_packet;
8ef5ada2 712 char *dhcp_buff, *dhcp_buff2, *dhcp_buff3;
3d8df260 713 struct ping_result *ping_results;
cdeda28f 714 FILE *lease_stream;
832af0ba 715 struct dhcp_bridge *bridges;
3d8df260
SK
716
717 /* DBus stuff */
3d8df260
SK
718 /* void * here to avoid depending on dbus headers outside dbus.c */
719 void *dbus;
832af0ba 720#ifdef HAVE_DBUS
3d8df260
SK
721 struct watch *watches;
722#endif
723
832af0ba
SK
724 /* TFTP stuff */
725 struct tftp_transfer *tftp_trans;
824af85b 726
5aabfc78 727} *daemon;
3be34541 728
9e4abcb5 729/* cache.c */
5aabfc78 730void cache_init(void);
28866e95 731void log_query(unsigned int flags, char *name, struct all_addr *addr, char *arg);
7622fc06 732char *record_source(int index);
1a6bca81 733void querystr(char *str, unsigned short type);
9e4abcb5
SK
734struct crec *cache_find_by_addr(struct crec *crecp,
735 struct all_addr *addr, time_t now,
736 unsigned short prot);
737struct crec *cache_find_by_name(struct crec *crecp,
738 char *name, time_t now, unsigned short prot);
739void cache_end_insert(void);
740void cache_start_insert(void);
fd9fa481
SK
741struct crec *cache_insert(char *name, struct all_addr *addr,
742 time_t now, unsigned long ttl, unsigned short flags);
7622fc06 743void cache_reload(void);
5aabfc78 744void cache_add_dhcp_entry(char *host_name, struct in_addr *host_address, time_t ttd);
9e4abcb5 745void cache_unhash_dhcp(void);
5aabfc78 746void dump_cache(time_t now);
9e4abcb5 747char *cache_get_name(struct crec *crecp);
7622fc06 748char *get_domain(struct in_addr addr);
9e4abcb5
SK
749
750/* rfc1035.c */
572b41eb 751unsigned int extract_request(struct dns_header *header, size_t qlen,
c1bb8504 752 char *name, unsigned short *typep);
572b41eb 753size_t setup_reply(struct dns_header *header, size_t qlen,
28866e95 754 struct all_addr *addrp, unsigned int flags,
cdeda28f 755 unsigned long local_ttl);
572b41eb 756int extract_addresses(struct dns_header *header, size_t qlen, char *namebuff,
28866e95 757 time_t now, int is_sign, int checkrebind, int checking_disabled);
572b41eb 758size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
f6b7dc47 759 struct in_addr local_addr, struct in_addr local_netmask, time_t now);
572b41eb 760int check_for_bogus_wildcard(struct dns_header *header, size_t qlen, char *name,
9e4abcb5 761 struct bogus_addr *addr, time_t now);
572b41eb 762unsigned char *find_pseudoheader(struct dns_header *header, size_t plen,
832af0ba 763 size_t *len, unsigned char **p, int *is_sign);
5aabfc78 764int check_for_local_domain(char *name, time_t now);
572b41eb
SK
765unsigned int questions_crc(struct dns_header *header, size_t plen, char *buff);
766size_t resize_packet(struct dns_header *header, size_t plen,
cdeda28f 767 unsigned char *pheader, size_t hlen);
572b41eb 768size_t add_mac(struct dns_header *header, size_t plen, char *limit, union mysockaddr *l3);
9e4abcb5
SK
769
770/* util.c */
1a6bca81 771void rand_init(void);
9e4abcb5 772unsigned short rand16(void);
1f15b81d
SK
773int legal_hostname(char *c);
774char *canonicalise(char *s, int *nomem);
3d8df260 775unsigned char *do_rfc1035_name(unsigned char *p, char *sval);
0a852541 776void *safe_malloc(size_t size);
1a6bca81 777void safe_pipe(int *fd, int read_noblock);
5aabfc78 778void *whine_malloc(size_t size);
9e4abcb5
SK
779int sa_len(union mysockaddr *addr);
780int sockaddr_isequal(union mysockaddr *s1, union mysockaddr *s2);
3d8df260 781int hostname_isequal(char *a, char *b);
5e9e0efb 782time_t dnsmasq_time(void);
a84fa1d0 783int is_same_net(struct in_addr a, struct in_addr b, struct in_addr mask);
fd9fa481 784int retry_send(void);
0a852541 785void prettyprint_time(char *buf, unsigned int t);
3d8df260 786int prettyprint_addr(union mysockaddr *addr, char *buf);
0a852541 787int parse_hex(char *in, unsigned char *out, int maxlen,
cdeda28f 788 unsigned int *wildcard_mask, int *mac_type);
5e9e0efb
SK
789int memcmp_masked(unsigned char *a, unsigned char *b, int len,
790 unsigned int mask);
791int expand_buf(struct iovec *iov, size_t size);
5aabfc78 792char *print_mac(char *buff, unsigned char *mac, int len);
1697269c 793void bump_maxfd(int fd, int *max);
1697269c 794int read_write(int fd, unsigned char *packet, int size, int rw);
7cebd20f 795
f2621c7f 796/* log.c */
5aabfc78 797void die(char *message, char *arg1, int exit_code);
1a6bca81 798int log_start(struct passwd *ent_pw, int errfd);
5aabfc78 799int log_reopen(char *log_file);
f2621c7f
SK
800void my_syslog(int priority, const char *format, ...);
801void set_log_writer(fd_set *set, int *maxfdp);
802void check_log_writer(fd_set *set);
5aabfc78 803void flush_log(void);
f2621c7f 804
9e4abcb5 805/* option.c */
5aabfc78 806void read_opts (int argc, char **argv, char *compile_opts);
7622fc06 807char *option_string(unsigned char opt, int *is_ip, int *is_name);
824af85b 808void reread_dhcp(void);
28866e95
SK
809void set_option_bool(unsigned int opt);
810struct hostsfile *expand_filelist(struct hostsfile *list);
9e4abcb5
SK
811
812/* forward.c */
1a6bca81 813void reply_query(int fd, int family, time_t now);
5aabfc78
SK
814void receive_query(struct listener *listen, time_t now);
815unsigned char *tcp_request(int confd, time_t now,
3d8df260 816 struct in_addr local_addr, struct in_addr netmask);
5aabfc78
SK
817void server_gone(struct server *server);
818struct frec *get_new_frec(time_t now, int *wait);
3be34541 819
9e4abcb5 820/* network.c */
7622fc06 821int indextoname(int fd, int index, char *name);
824af85b 822int local_bind(int fd, union mysockaddr *addr, char *intname, int is_tcp);
1a6bca81 823int random_sock(int family);
824af85b 824void pre_allocate_sfds(void);
5aabfc78
SK
825int reload_servers(char *fname);
826void check_servers(void);
827int enumerate_interfaces();
828struct listener *create_wildcard_listeners(void);
829struct listener *create_bound_listeners(void);
7622fc06 830int iface_check(int family, struct all_addr *addr, char *name, int *indexp);
7cebd20f 831int fix_fd(int fd);
5aabfc78 832struct in_addr get_ifaddr(char *intr);
3be34541 833
9e4abcb5 834/* dhcp.c */
7622fc06 835#ifdef HAVE_DHCP
5aabfc78 836void dhcp_init(void);
316e2730 837void dhcp_packet(time_t now, int pxe_fd);
824af85b
SK
838struct dhcp_context *address_available(struct dhcp_context *context,
839 struct in_addr addr,
840 struct dhcp_netid *netids);
841struct dhcp_context *narrow_context(struct dhcp_context *context,
842 struct in_addr taddr,
843 struct dhcp_netid *netids);
8ef5ada2
SK
844int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool, int negonly);
845int address_allocate(struct dhcp_context *context,
cdeda28f 846 struct in_addr *addrp, unsigned char *hwaddr, int hw_len,
3d8df260 847 struct dhcp_netid *netids, time_t now);
8ef5ada2 848struct dhcp_netid *run_tag_if(struct dhcp_netid *input);
9009d746 849int config_has_mac(struct dhcp_config *config, unsigned char *hwaddr, int len, int type);
9e4abcb5
SK
850struct dhcp_config *find_config(struct dhcp_config *configs,
851 struct dhcp_context *context,
852 unsigned char *clid, int clid_len,
cdeda28f
SK
853 unsigned char *hwaddr, int hw_len,
854 int hw_type, char *hostname);
44a2a316 855void dhcp_update_configs(struct dhcp_config *configs);
5aabfc78 856void dhcp_read_ethers(void);
824af85b 857void check_dhcp_hosts(int fatal);
dfa666f2 858struct dhcp_config *config_find_by_address(struct dhcp_config *configs, struct in_addr addr);
5aabfc78
SK
859char *strip_hostname(char *hostname);
860char *host_from_dns(struct in_addr addr);
9009d746 861char *get_domain(struct in_addr addr);
7622fc06 862#endif
3be34541 863
9e4abcb5 864/* lease.c */
7622fc06 865#ifdef HAVE_DHCP
5aabfc78
SK
866void lease_update_file(time_t now);
867void lease_update_dns();
868void lease_init(time_t now);
7cebd20f
SK
869struct dhcp_lease *lease_allocate(struct in_addr addr);
870void lease_set_hwaddr(struct dhcp_lease *lease, unsigned char *hwaddr,
cdeda28f 871 unsigned char *clid, int hw_len, int hw_type, int clid_len);
9009d746 872void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth);
5e9e0efb 873void lease_set_expires(struct dhcp_lease *lease, unsigned int len, time_t now);
824af85b 874void lease_set_interface(struct dhcp_lease *lease, int interface);
cdeda28f 875struct dhcp_lease *lease_find_by_client(unsigned char *hwaddr, int hw_len, int hw_type,
0a852541 876 unsigned char *clid, int clid_len);
9e4abcb5
SK
877struct dhcp_lease *lease_find_by_addr(struct in_addr addr);
878void lease_prune(struct dhcp_lease *target, time_t now);
5aabfc78
SK
879void lease_update_from_configs(void);
880int do_script_run(time_t now);
881void rerun_scripts(void);
7622fc06 882#endif
a84fa1d0 883
9e4abcb5 884/* rfc2131.c */
7622fc06 885#ifdef HAVE_DHCP
824af85b 886size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
316e2730 887 size_t sz, time_t now, int unicast_dest, int *is_inform, int pxe_fd);
9009d746
SK
888unsigned char *extended_hwaddr(int hwtype, int hwlen, unsigned char *hwaddr,
889 int clid_len, unsigned char *clid, int *len_out);
7622fc06 890#endif
3be34541
SK
891
892/* dnsmasq.c */
7622fc06 893#ifdef HAVE_DHCP
5e9e0efb 894int make_icmp_sock(void);
5aabfc78 895int icmp_ping(struct in_addr addr);
7622fc06 896#endif
5aabfc78
SK
897void send_event(int fd, int event, int data);
898void clear_cache_and_reload(time_t now);
8ef5ada2 899void poll_resolv(int force, int do_reload, time_t now);
44a2a316 900
0a852541 901/* netlink.c */
5e9e0efb 902#ifdef HAVE_LINUX_NETWORK
5aabfc78 903void netlink_init(void);
5aabfc78 904void netlink_multicast(void);
5e9e0efb
SK
905#endif
906
907/* bpf.c */
824af85b 908#ifdef HAVE_BSD_NETWORK
5aabfc78
SK
909void init_bpf(void);
910void send_via_bpf(struct dhcp_packet *mess, size_t len,
5e9e0efb 911 struct in_addr iface_addr, struct ifreq *ifr);
0a852541 912#endif
3d8df260 913
824af85b 914/* bpf.c or netlink.c */
28866e95 915int iface_enumerate(int family, void *parm, int (callback)());
824af85b 916
3d8df260
SK
917/* dbus.c */
918#ifdef HAVE_DBUS
5aabfc78
SK
919char *dbus_init(void);
920void check_dbus_listeners(fd_set *rset, fd_set *wset, fd_set *eset);
921void set_dbus_listeners(int *maxfdp, fd_set *rset, fd_set *wset, fd_set *eset);
316e2730 922# ifdef HAVE_DHCP
1f15b81d 923void emit_dbus_signal(int action, struct dhcp_lease *lease, char *hostname);
316e2730 924# endif
3d8df260 925#endif
1697269c
SK
926
927/* helper.c */
7622fc06 928#if defined(HAVE_DHCP) && !defined(NO_FORK)
1a6bca81 929int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd);
5aabfc78
SK
930void helper_write(void);
931void queue_script(int action, struct dhcp_lease *lease,
932 char *hostname, time_t now);
1697269c 933int helper_buf_empty(void);
5aabfc78 934#endif
832af0ba
SK
935
936/* tftp.c */
937#ifdef HAVE_TFTP
5aabfc78
SK
938void tftp_request(struct listener *listen, time_t now);
939void check_tftp_listeners(fd_set *rset, time_t now);
832af0ba 940#endif