]> git.ipfire.org Git - people/ms/dnsmasq.git/blame - src/dnsmasq.h
import of dnsmasq-2.58.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
7de060b0
SK
205#define OPT_CONSEC_ADDR 34
206#define OPT_CONNTRACK 35
207#define OPT_LAST 36
9e4abcb5 208
7622fc06
SK
209/* extra flags for my_syslog, we use a couple of facilities since they are known
210 not to occupy the same bits as priorities, no matter how syslog.h is set up. */
211#define MS_TFTP LOG_USER
212#define MS_DHCP LOG_DAEMON
213
9e4abcb5
SK
214struct all_addr {
215 union {
216 struct in_addr addr4;
217#ifdef HAVE_IPV6
218 struct in6_addr addr6;
219#endif
220 } addr;
221};
222
223struct bogus_addr {
224 struct in_addr addr;
225 struct bogus_addr *next;
226};
227
1cff166d
SK
228/* dns doctor param */
229struct doctor {
73a08a24 230 struct in_addr in, end, out, mask;
1cff166d
SK
231 struct doctor *next;
232};
233
0a852541
SK
234struct mx_srv_record {
235 char *name, *target;
3d8df260
SK
236 int issrv, srvport, priority, weight;
237 unsigned int offset;
0a852541 238 struct mx_srv_record *next;
de37951c
SK
239};
240
1a6bca81
SK
241struct naptr {
242 char *name, *replace, *regexp, *services, *flags;
243 unsigned int order, pref;
244 struct naptr *next;
245};
246
0a852541 247struct txt_record {
28866e95
SK
248 char *name;
249 unsigned char *txt;
0a852541
SK
250 unsigned short class, len;
251 struct txt_record *next;
f6b7dc47
SK
252};
253
832af0ba
SK
254struct ptr_record {
255 char *name, *ptr;
256 struct ptr_record *next;
257};
258
9009d746
SK
259struct cname {
260 char *alias, *target;
261 struct cname *next;
262};
263
f2621c7f
SK
264struct interface_name {
265 char *name; /* domain name */
266 char *intr; /* interface name */
267 struct interface_name *next;
268};
269
9e4abcb5
SK
270union bigname {
271 char name[MAXDNAME];
272 union bigname *next; /* freelist */
273};
274
275struct crec {
276 struct crec *next, *prev, *hash_next;
277 time_t ttd; /* time to die */
fd9fa481
SK
278 int uid;
279 union {
280 struct all_addr addr;
281 struct {
282 struct crec *cache;
283 int uid;
284 } cname;
285 } addr;
9e4abcb5
SK
286 unsigned short flags;
287 union {
288 char sname[SMALLDNAME];
289 union bigname *bname;
290 char *namep;
291 } name;
292};
293
28866e95
SK
294#define F_IMMORTAL (1u<<0)
295#define F_NAMEP (1u<<1)
296#define F_REVERSE (1u<<2)
297#define F_FORWARD (1u<<3)
298#define F_DHCP (1u<<4)
299#define F_NEG (1u<<5)
300#define F_HOSTS (1u<<6)
301#define F_IPV4 (1u<<7)
302#define F_IPV6 (1u<<8)
303#define F_BIGNAME (1u<<9)
304#define F_NXDOMAIN (1u<<10)
305#define F_CNAME (1u<<11)
306#define F_NOERR (1u<<12)
307#define F_CONFIG (1u<<13)
308/* below here are only valid as args to log_query: cache
309 entries are limited to 16 bits */
310#define F_UPSTREAM (1u<<16)
311#define F_RRNAME (1u<<17)
312#define F_SERVER (1u<<18)
313#define F_QUERY (1u<<19)
28866e95 314
9e4abcb5
SK
315
316/* struct sockaddr is not large enough to hold any address,
cdeda28f 317 and specifically not big enough to hold an IPv6 address.
9e4abcb5
SK
318 Blech. Roll our own. */
319union mysockaddr {
320 struct sockaddr sa;
321 struct sockaddr_in in;
7622fc06 322#if defined(HAVE_IPV6)
9e4abcb5
SK
323 struct sockaddr_in6 in6;
324#endif
325};
326
0a852541
SK
327#define SERV_FROM_RESOLV 1 /* 1 for servers from resolv, 0 for command line. */
328#define SERV_NO_ADDR 2 /* no server, this domain is local only */
329#define SERV_LITERAL_ADDRESS 4 /* addr is the answer, not the server */
5aabfc78
SK
330#define SERV_HAS_DOMAIN 8 /* server for one domain only */
331#define SERV_HAS_SOURCE 16 /* source address defined */
0a852541
SK
332#define SERV_FOR_NODOTS 32 /* server for names with no domain part only */
333#define SERV_WARNED_RECURSIVE 64 /* avoid warning spam */
3d8df260
SK
334#define SERV_FROM_DBUS 128 /* 1 if source is DBus */
335#define SERV_MARK 256 /* for mark-and-delete */
9e4abcb5 336#define SERV_TYPE (SERV_HAS_DOMAIN | SERV_FOR_NODOTS)
824af85b 337#define SERV_COUNTED 512 /* workspace for log code */
8ef5ada2
SK
338#define SERV_USE_RESOLV 1024 /* forward this domain in the normal way */
339#define SERV_NO_REBIND 2048 /* inhibit dns-rebind protection */
9e4abcb5
SK
340
341struct serverfd {
342 int fd;
343 union mysockaddr source_addr;
824af85b 344 char interface[IF_NAMESIZE+1];
9e4abcb5
SK
345 struct serverfd *next;
346};
347
1a6bca81
SK
348struct randfd {
349 int fd;
350 unsigned short refcount, family;
351};
352
9e4abcb5
SK
353struct server {
354 union mysockaddr addr, source_addr;
824af85b 355 char interface[IF_NAMESIZE+1];
1697269c 356 struct serverfd *sfd;
9e4abcb5 357 char *domain; /* set if this server only handles a domain. */
feba5c1d 358 int flags, tcpfd;
824af85b 359 unsigned int queries, failed_queries;
9e4abcb5
SK
360 struct server *next;
361};
362
9e4abcb5
SK
363struct irec {
364 union mysockaddr addr;
f6b7dc47 365 struct in_addr netmask; /* only valid for IPv4 */
8ef5ada2
SK
366 int tftp_ok, mtu;
367 char *name;
9e4abcb5
SK
368 struct irec *next;
369};
370
44a2a316 371struct listener {
832af0ba 372 int fd, tcpfd, tftpfd, family;
f6b7dc47 373 struct irec *iface; /* only valid for non-wildcard */
44a2a316
SK
374 struct listener *next;
375};
376
9e4abcb5
SK
377/* interface and address parms from command line. */
378struct iname {
379 char *name;
380 union mysockaddr addr;
de37951c 381 int isloop, used;
9e4abcb5
SK
382 struct iname *next;
383};
384
385/* resolv-file parms from command-line */
386struct resolvc {
387 struct resolvc *next;
3d8df260
SK
388 int is_default, logged;
389 time_t mtime;
9e4abcb5
SK
390 char *name;
391};
392
28866e95 393/* adn-hosts parms from command-line (also dhcp-hostsfile and dhcp-optsfile */
7622fc06
SK
394#define AH_DIR 1
395#define AH_INACTIVE 2
fd9fa481
SK
396struct hostsfile {
397 struct hostsfile *next;
7622fc06 398 int flags;
fd9fa481 399 char *fname;
cdeda28f 400 int index; /* matches to cache entries for logging */
fd9fa481
SK
401};
402
28866e95
SK
403#define FREC_NOREBIND 1
404#define FREC_CHECKING_DISABLED 2
405
9e4abcb5
SK
406struct frec {
407 union mysockaddr source;
44a2a316 408 struct all_addr dest;
832af0ba 409 struct server *sentto; /* NULL means free */
1a6bca81
SK
410 struct randfd *rfd4;
411#ifdef HAVE_IPV6
412 struct randfd *rfd6;
413#endif
dfa666f2 414 unsigned int iface;
9e4abcb5 415 unsigned short orig_id, new_id;
28866e95 416 int fd, forwardall, flags;
fd9fa481 417 unsigned int crc;
9e4abcb5
SK
418 time_t time;
419 struct frec *next;
420};
421
1697269c
SK
422/* actions in the daemon->helper RPC */
423#define ACTION_DEL 1
424#define ACTION_OLD_HOSTNAME 2
425#define ACTION_OLD 3
426#define ACTION_ADD 4
427
9e4abcb5
SK
428struct dhcp_lease {
429 int clid_len; /* length of client identifier */
430 unsigned char *clid; /* clientid */
431 char *hostname, *fqdn; /* name from client-hostname option or config */
1697269c 432 char *old_hostname; /* hostname before it moved to another lease */
7cebd20f
SK
433 char auth_name; /* hostname came from config, not from client */
434 char new; /* newly created */
208b65c5
SK
435 char changed; /* modified */
436 char aux_changed; /* CLID or expiry changed */
9e4abcb5 437 time_t expires; /* lease expiry */
5e9e0efb
SK
438#ifdef HAVE_BROKEN_RTC
439 unsigned int length;
440#endif
cdeda28f
SK
441 int hwaddr_len, hwaddr_type;
442 unsigned char hwaddr[DHCP_CHADDR_MAX];
1f15b81d 443 struct in_addr addr, override, giaddr;
316e2730
SK
444 unsigned char *extradata;
445 unsigned int extradata_len, extradata_size;
824af85b 446 int last_interface;
9e4abcb5
SK
447 struct dhcp_lease *next;
448};
449
a222641c
SK
450struct dhcp_netid {
451 char *net;
452 struct dhcp_netid *next;
453};
454
26128d27
SK
455struct dhcp_netid_list {
456 struct dhcp_netid *list;
457 struct dhcp_netid_list *next;
458};
1697269c 459
8ef5ada2
SK
460struct tag_if {
461 struct dhcp_netid_list *set;
462 struct dhcp_netid *tag;
463 struct tag_if *next;
464};
465
9009d746
SK
466struct hwaddr_config {
467 int hwaddr_len, hwaddr_type;
468 unsigned char hwaddr[DHCP_CHADDR_MAX];
469 unsigned int wildcard_mask;
470 struct hwaddr_config *next;
471};
472
9e4abcb5 473struct dhcp_config {
33820b7e 474 unsigned int flags;
9e4abcb5
SK
475 int clid_len; /* length of client identifier */
476 unsigned char *clid; /* clientid */
9009d746 477 char *hostname, *domain;
8ef5ada2 478 struct dhcp_netid_list *netid;
9e4abcb5 479 struct in_addr addr;
849a8357 480 time_t decline_time;
9009d746
SK
481 unsigned int lease_time;
482 struct hwaddr_config *hwaddr;
9e4abcb5
SK
483 struct dhcp_config *next;
484};
485
0a852541
SK
486#define CONFIG_DISABLE 1
487#define CONFIG_CLID 2
0a852541
SK
488#define CONFIG_TIME 8
489#define CONFIG_NAME 16
490#define CONFIG_ADDR 32
0a852541 491#define CONFIG_NOCLID 128
849a8357
SK
492#define CONFIG_FROM_ETHERS 256 /* entry created by /etc/ethers */
493#define CONFIG_ADDR_HOSTS 512 /* address added by from /etc/hosts */
494#define CONFIG_DECLINED 1024 /* address declined by client */
5aabfc78 495#define CONFIG_BANK 2048 /* from dhcp hosts file */
33820b7e 496
9e4abcb5 497struct dhcp_opt {
cdeda28f 498 int opt, len, flags;
73a08a24
SK
499 union {
500 int encap;
501 unsigned int wildcard_mask;
502 unsigned char *vendor_class;
503 } u;
504 unsigned char *val;
26128d27 505 struct dhcp_netid *netid;
9e4abcb5 506 struct dhcp_opt *next;
a84fa1d0
SK
507};
508
cdeda28f
SK
509#define DHOPT_ADDR 1
510#define DHOPT_STRING 2
6b01084f 511#define DHOPT_ENCAPSULATE 4
73a08a24 512#define DHOPT_ENCAP_MATCH 8
6b01084f 513#define DHOPT_FORCE 16
824af85b 514#define DHOPT_BANK 32
73a08a24
SK
515#define DHOPT_ENCAP_DONE 64
516#define DHOPT_MATCH 128
517#define DHOPT_VENDOR 256
518#define DHOPT_HEX 512
7622fc06 519#define DHOPT_VENDOR_MATCH 1024
316e2730 520#define DHOPT_RFC3925 2048
7de060b0 521#define DHOPT_TAGOK 4096
cdeda28f 522
26128d27 523struct dhcp_boot {
7de060b0 524 char *file, *sname, *tftp_sname;
26128d27
SK
525 struct in_addr next_server;
526 struct dhcp_netid *netid;
527 struct dhcp_boot *next;
528};
529
7622fc06
SK
530struct pxe_service {
531 unsigned short CSA, type;
532 char *menu, *basename;
533 struct in_addr server;
534 struct dhcp_netid *netid;
535 struct pxe_service *next;
536};
537
f2621c7f
SK
538#define MATCH_VENDOR 1
539#define MATCH_USER 2
540#define MATCH_CIRCUIT 3
541#define MATCH_REMOTE 4
542#define MATCH_SUBSCRIBER 5
543
544/* vendorclass, userclass, remote-id or cicuit-id */
a84fa1d0 545struct dhcp_vendor {
824af85b 546 int len, match_type, option;
a222641c
SK
547 char *data;
548 struct dhcp_netid netid;
a84fa1d0
SK
549 struct dhcp_vendor *next;
550};
9e4abcb5 551
cdeda28f
SK
552struct dhcp_mac {
553 unsigned int mask;
554 int hwaddr_len, hwaddr_type;
555 unsigned char hwaddr[DHCP_CHADDR_MAX];
556 struct dhcp_netid netid;
557 struct dhcp_mac *next;
558};
559
832af0ba
SK
560struct dhcp_bridge {
561 char iface[IF_NAMESIZE];
562 struct dhcp_bridge *alias, *next;
563};
832af0ba 564
9009d746
SK
565struct cond_domain {
566 char *domain;
567 struct in_addr start, end;
568 struct cond_domain *next;
569};
570
9e4abcb5 571struct dhcp_context {
feba5c1d 572 unsigned int lease_time, addr_epoch;
0a852541
SK
573 struct in_addr netmask, broadcast;
574 struct in_addr local, router;
a84fa1d0 575 struct in_addr start, end; /* range of available addresses */
0a852541 576 int flags;
8ef5ada2 577 char *interface;
cdeda28f 578 struct dhcp_netid netid, *filter;
36717eee 579 struct dhcp_context *next, *current;
9e4abcb5
SK
580};
581
0a852541 582#define CONTEXT_STATIC 1
cdeda28f
SK
583#define CONTEXT_NETMASK 2
584#define CONTEXT_BRDCAST 4
7622fc06 585#define CONTEXT_PROXY 8
0a852541 586
3d8df260
SK
587struct ping_result {
588 struct in_addr addr;
589 time_t time;
7de060b0 590 unsigned int hash;
3d8df260
SK
591 struct ping_result *next;
592};
9e4abcb5 593
832af0ba
SK
594struct tftp_file {
595 int refcount, fd;
596 off_t size;
5aabfc78
SK
597 dev_t dev;
598 ino_t inode;
832af0ba
SK
599 char filename[];
600};
601
602struct tftp_transfer {
603 int sockfd;
604 time_t timeout;
605 int backoff;
9e038946
SK
606 unsigned int block, blocksize, expansion;
607 off_t offset;
28866e95 608 union mysockaddr peer;
9e038946 609 char opt_blocksize, opt_transize, netascii, carrylf;
832af0ba
SK
610 struct tftp_file *file;
611 struct tftp_transfer *next;
612};
613
8ef5ada2
SK
614struct addr_list {
615 struct in_addr addr;
616 struct addr_list *next;
617};
618
619struct interface_list {
620 char *interface;
621 struct interface_list *next;
622};
623
624struct tftp_prefix {
625 char *interface;
626 char *prefix;
627 struct tftp_prefix *next;
628};
629
630
5aabfc78 631extern struct daemon {
3be34541
SK
632 /* datastuctures representing the command-line and
633 config file arguments. All set (including defaults)
634 in option.c */
635
28866e95 636 unsigned int options, options2;
3be34541 637 struct resolvc default_resolv, *resolv_files;
9009d746 638 time_t last_resolv;
0a852541 639 struct mx_srv_record *mxnames;
1a6bca81 640 struct naptr *naptr;
0a852541 641 struct txt_record *txt;
832af0ba 642 struct ptr_record *ptr;
9009d746 643 struct cname *cnames;
f2621c7f 644 struct interface_name *int_names;
3be34541
SK
645 char *mxtarget;
646 char *lease_file;
9e038946 647 char *username, *groupname, *scriptuser;
1a6bca81 648 int group_set, osport;
3be34541 649 char *domain_suffix;
9009d746 650 struct cond_domain *cond_domain;
3be34541 651 char *runfile;
7cebd20f 652 char *lease_change_command;
3d8df260 653 struct iname *if_names, *if_addrs, *if_except, *dhcp_except;
3be34541
SK
654 struct bogus_addr *bogus_addr;
655 struct server *servers;
849a8357 656 int log_fac; /* log facility */
f2621c7f
SK
657 char *log_file; /* optional log file */
658 int max_logs; /* queue limit */
208b65c5 659 int cachesize, ftabsize;
1a6bca81 660 int port, query_port, min_port;
8ef5ada2 661 unsigned long local_ttl, neg_ttl, max_ttl;
fd9fa481 662 struct hostsfile *addn_hosts;
3be34541
SK
663 struct dhcp_context *dhcp;
664 struct dhcp_config *dhcp_conf;
73a08a24 665 struct dhcp_opt *dhcp_opts, *dhcp_match;
3be34541 666 struct dhcp_vendor *dhcp_vendors;
cdeda28f 667 struct dhcp_mac *dhcp_macs;
26128d27 668 struct dhcp_boot *boot_config;
7622fc06 669 struct pxe_service *pxe_services;
8ef5ada2
SK
670 struct tag_if *tag_if;
671 struct addr_list *override_relays;
672 int override;
1f15b81d 673 int enable_pxe;
8ef5ada2
SK
674 struct dhcp_netid_list *dhcp_ignore, *dhcp_ignore_names, *dhcp_gen_names;
675 struct dhcp_netid_list *force_broadcast, *bootp_dynamic;
28866e95 676 struct hostsfile *dhcp_hosts_file, *dhcp_opts_file;
824af85b 677 int dhcp_max, tftp_max;
9e038946 678 int dhcp_server_port, dhcp_client_port;
824af85b 679 int start_tftp_port, end_tftp_port;
3be34541
SK
680 unsigned int min_leasetime;
681 struct doctor *doctors;
682 unsigned short edns_pktsz;
824af85b 683 char *tftp_prefix;
8ef5ada2
SK
684 struct tftp_prefix *if_prefix; /* per-interface TFTP prefixes */
685 struct interface_list *tftp_interfaces; /* interfaces for limited TFTP service */
686 int tftp_unlimited;
3be34541
SK
687
688 /* globally used stuff for DNS */
689 char *packet; /* packet buffer */
0a852541 690 int packet_buff_sz; /* size of above */
3be34541 691 char *namebuff; /* MAXDNAME size buffer */
824af85b 692 unsigned int local_answer, queries_forwarded;
1a6bca81 693 struct frec *frec_list;
3be34541 694 struct serverfd *sfds;
3d8df260 695 struct irec *interfaces;
3be34541
SK
696 struct listener *listeners;
697 struct server *last_server;
1f15b81d
SK
698 time_t forwardtime;
699 int forwardcount;
cdeda28f
SK
700 struct server *srv_save; /* Used for resend on DoD */
701 size_t packet_len; /* " " */
3927da46 702 struct randfd *rfd_save; /* " " */
7622fc06 703 pid_t tcp_pids[MAX_PROCS];
1a6bca81 704 struct randfd randomsocks[RANDOM_SOCKS];
316e2730 705 int v6pktinfo;
1a6bca81 706
3be34541 707 /* DHCP state */
316e2730 708 int dhcpfd, helperfd, pxefd;
7622fc06 709#if defined(HAVE_LINUX_NETWORK)
0a852541 710 int netlinkfd;
7622fc06 711#elif defined(HAVE_BSD_NETWORK)
5e9e0efb 712 int dhcp_raw_fd, dhcp_icmp_fd;
0a852541 713#endif
5e9e0efb 714 struct iovec dhcp_packet;
8ef5ada2 715 char *dhcp_buff, *dhcp_buff2, *dhcp_buff3;
3d8df260 716 struct ping_result *ping_results;
cdeda28f 717 FILE *lease_stream;
832af0ba 718 struct dhcp_bridge *bridges;
3d8df260
SK
719
720 /* DBus stuff */
3d8df260
SK
721 /* void * here to avoid depending on dbus headers outside dbus.c */
722 void *dbus;
832af0ba 723#ifdef HAVE_DBUS
3d8df260
SK
724 struct watch *watches;
725#endif
726
832af0ba
SK
727 /* TFTP stuff */
728 struct tftp_transfer *tftp_trans;
824af85b 729
5aabfc78 730} *daemon;
3be34541 731
9e4abcb5 732/* cache.c */
5aabfc78 733void cache_init(void);
28866e95 734void log_query(unsigned int flags, char *name, struct all_addr *addr, char *arg);
7622fc06 735char *record_source(int index);
1a6bca81 736void querystr(char *str, unsigned short type);
9e4abcb5
SK
737struct crec *cache_find_by_addr(struct crec *crecp,
738 struct all_addr *addr, time_t now,
739 unsigned short prot);
740struct crec *cache_find_by_name(struct crec *crecp,
741 char *name, time_t now, unsigned short prot);
742void cache_end_insert(void);
743void cache_start_insert(void);
fd9fa481
SK
744struct crec *cache_insert(char *name, struct all_addr *addr,
745 time_t now, unsigned long ttl, unsigned short flags);
7622fc06 746void cache_reload(void);
5aabfc78 747void cache_add_dhcp_entry(char *host_name, struct in_addr *host_address, time_t ttd);
7de060b0 748struct in_addr a_record_from_hosts(char *name, time_t now);
9e4abcb5 749void cache_unhash_dhcp(void);
5aabfc78 750void dump_cache(time_t now);
9e4abcb5 751char *cache_get_name(struct crec *crecp);
7622fc06 752char *get_domain(struct in_addr addr);
9e4abcb5
SK
753
754/* rfc1035.c */
572b41eb 755unsigned int extract_request(struct dns_header *header, size_t qlen,
c1bb8504 756 char *name, unsigned short *typep);
572b41eb 757size_t setup_reply(struct dns_header *header, size_t qlen,
28866e95 758 struct all_addr *addrp, unsigned int flags,
cdeda28f 759 unsigned long local_ttl);
572b41eb 760int extract_addresses(struct dns_header *header, size_t qlen, char *namebuff,
28866e95 761 time_t now, int is_sign, int checkrebind, int checking_disabled);
572b41eb 762size_t answer_request(struct dns_header *header, char *limit, size_t qlen,
f6b7dc47 763 struct in_addr local_addr, struct in_addr local_netmask, time_t now);
572b41eb 764int check_for_bogus_wildcard(struct dns_header *header, size_t qlen, char *name,
9e4abcb5 765 struct bogus_addr *addr, time_t now);
572b41eb 766unsigned char *find_pseudoheader(struct dns_header *header, size_t plen,
832af0ba 767 size_t *len, unsigned char **p, int *is_sign);
5aabfc78 768int check_for_local_domain(char *name, time_t now);
572b41eb
SK
769unsigned int questions_crc(struct dns_header *header, size_t plen, char *buff);
770size_t resize_packet(struct dns_header *header, size_t plen,
cdeda28f 771 unsigned char *pheader, size_t hlen);
572b41eb 772size_t add_mac(struct dns_header *header, size_t plen, char *limit, union mysockaddr *l3);
9e4abcb5
SK
773
774/* util.c */
1a6bca81 775void rand_init(void);
9e4abcb5 776unsigned short rand16(void);
1f15b81d
SK
777int legal_hostname(char *c);
778char *canonicalise(char *s, int *nomem);
3d8df260 779unsigned char *do_rfc1035_name(unsigned char *p, char *sval);
0a852541 780void *safe_malloc(size_t size);
1a6bca81 781void safe_pipe(int *fd, int read_noblock);
5aabfc78 782void *whine_malloc(size_t size);
9e4abcb5
SK
783int sa_len(union mysockaddr *addr);
784int sockaddr_isequal(union mysockaddr *s1, union mysockaddr *s2);
3d8df260 785int hostname_isequal(char *a, char *b);
5e9e0efb 786time_t dnsmasq_time(void);
a84fa1d0 787int is_same_net(struct in_addr a, struct in_addr b, struct in_addr mask);
fd9fa481 788int retry_send(void);
0a852541 789void prettyprint_time(char *buf, unsigned int t);
3d8df260 790int prettyprint_addr(union mysockaddr *addr, char *buf);
0a852541 791int parse_hex(char *in, unsigned char *out, int maxlen,
cdeda28f 792 unsigned int *wildcard_mask, int *mac_type);
5e9e0efb
SK
793int memcmp_masked(unsigned char *a, unsigned char *b, int len,
794 unsigned int mask);
795int expand_buf(struct iovec *iov, size_t size);
5aabfc78 796char *print_mac(char *buff, unsigned char *mac, int len);
1697269c 797void bump_maxfd(int fd, int *max);
1697269c 798int read_write(int fd, unsigned char *packet, int size, int rw);
7cebd20f 799
f2621c7f 800/* log.c */
5aabfc78 801void die(char *message, char *arg1, int exit_code);
1a6bca81 802int log_start(struct passwd *ent_pw, int errfd);
5aabfc78 803int log_reopen(char *log_file);
f2621c7f
SK
804void my_syslog(int priority, const char *format, ...);
805void set_log_writer(fd_set *set, int *maxfdp);
806void check_log_writer(fd_set *set);
5aabfc78 807void flush_log(void);
f2621c7f 808
9e4abcb5 809/* option.c */
5aabfc78 810void read_opts (int argc, char **argv, char *compile_opts);
7622fc06 811char *option_string(unsigned char opt, int *is_ip, int *is_name);
824af85b 812void reread_dhcp(void);
28866e95
SK
813void set_option_bool(unsigned int opt);
814struct hostsfile *expand_filelist(struct hostsfile *list);
9e4abcb5
SK
815
816/* forward.c */
1a6bca81 817void reply_query(int fd, int family, time_t now);
5aabfc78
SK
818void receive_query(struct listener *listen, time_t now);
819unsigned char *tcp_request(int confd, time_t now,
7de060b0 820 union mysockaddr *local_addr, struct in_addr netmask);
5aabfc78
SK
821void server_gone(struct server *server);
822struct frec *get_new_frec(time_t now, int *wait);
3be34541 823
9e4abcb5 824/* network.c */
7622fc06 825int indextoname(int fd, int index, char *name);
824af85b 826int local_bind(int fd, union mysockaddr *addr, char *intname, int is_tcp);
1a6bca81 827int random_sock(int family);
824af85b 828void pre_allocate_sfds(void);
5aabfc78
SK
829int reload_servers(char *fname);
830void check_servers(void);
831int enumerate_interfaces();
832struct listener *create_wildcard_listeners(void);
833struct listener *create_bound_listeners(void);
7622fc06 834int iface_check(int family, struct all_addr *addr, char *name, int *indexp);
7cebd20f 835int fix_fd(int fd);
5aabfc78 836struct in_addr get_ifaddr(char *intr);
3be34541 837
9e4abcb5 838/* dhcp.c */
7622fc06 839#ifdef HAVE_DHCP
5aabfc78 840void dhcp_init(void);
316e2730 841void dhcp_packet(time_t now, int pxe_fd);
824af85b
SK
842struct dhcp_context *address_available(struct dhcp_context *context,
843 struct in_addr addr,
844 struct dhcp_netid *netids);
845struct dhcp_context *narrow_context(struct dhcp_context *context,
846 struct in_addr taddr,
847 struct dhcp_netid *netids);
8ef5ada2
SK
848int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool, int negonly);
849int address_allocate(struct dhcp_context *context,
cdeda28f 850 struct in_addr *addrp, unsigned char *hwaddr, int hw_len,
3d8df260 851 struct dhcp_netid *netids, time_t now);
8ef5ada2 852struct dhcp_netid *run_tag_if(struct dhcp_netid *input);
9009d746 853int config_has_mac(struct dhcp_config *config, unsigned char *hwaddr, int len, int type);
9e4abcb5
SK
854struct dhcp_config *find_config(struct dhcp_config *configs,
855 struct dhcp_context *context,
856 unsigned char *clid, int clid_len,
cdeda28f
SK
857 unsigned char *hwaddr, int hw_len,
858 int hw_type, char *hostname);
44a2a316 859void dhcp_update_configs(struct dhcp_config *configs);
5aabfc78 860void dhcp_read_ethers(void);
824af85b 861void check_dhcp_hosts(int fatal);
dfa666f2 862struct dhcp_config *config_find_by_address(struct dhcp_config *configs, struct in_addr addr);
5aabfc78
SK
863char *strip_hostname(char *hostname);
864char *host_from_dns(struct in_addr addr);
9009d746 865char *get_domain(struct in_addr addr);
7622fc06 866#endif
3be34541 867
9e4abcb5 868/* lease.c */
7622fc06 869#ifdef HAVE_DHCP
5aabfc78
SK
870void lease_update_file(time_t now);
871void lease_update_dns();
872void lease_init(time_t now);
7cebd20f
SK
873struct dhcp_lease *lease_allocate(struct in_addr addr);
874void lease_set_hwaddr(struct dhcp_lease *lease, unsigned char *hwaddr,
cdeda28f 875 unsigned char *clid, int hw_len, int hw_type, int clid_len);
9009d746 876void lease_set_hostname(struct dhcp_lease *lease, char *name, int auth);
5e9e0efb 877void lease_set_expires(struct dhcp_lease *lease, unsigned int len, time_t now);
824af85b 878void lease_set_interface(struct dhcp_lease *lease, int interface);
cdeda28f 879struct dhcp_lease *lease_find_by_client(unsigned char *hwaddr, int hw_len, int hw_type,
0a852541 880 unsigned char *clid, int clid_len);
9e4abcb5 881struct dhcp_lease *lease_find_by_addr(struct in_addr addr);
7de060b0 882struct in_addr lease_find_max_addr(struct dhcp_context *context);
9e4abcb5 883void lease_prune(struct dhcp_lease *target, time_t now);
5aabfc78
SK
884void lease_update_from_configs(void);
885int do_script_run(time_t now);
886void rerun_scripts(void);
7622fc06 887#endif
a84fa1d0 888
9e4abcb5 889/* rfc2131.c */
7622fc06 890#ifdef HAVE_DHCP
824af85b 891size_t dhcp_reply(struct dhcp_context *context, char *iface_name, int int_index,
7de060b0 892 size_t sz, time_t now, int unicast_dest, int *is_inform, int pxe_fd, struct in_addr fallback);
9009d746
SK
893unsigned char *extended_hwaddr(int hwtype, int hwlen, unsigned char *hwaddr,
894 int clid_len, unsigned char *clid, int *len_out);
7622fc06 895#endif
3be34541
SK
896
897/* dnsmasq.c */
7622fc06 898#ifdef HAVE_DHCP
5e9e0efb 899int make_icmp_sock(void);
5aabfc78 900int icmp_ping(struct in_addr addr);
7622fc06 901#endif
5aabfc78
SK
902void send_event(int fd, int event, int data);
903void clear_cache_and_reload(time_t now);
8ef5ada2 904void poll_resolv(int force, int do_reload, time_t now);
44a2a316 905
0a852541 906/* netlink.c */
5e9e0efb 907#ifdef HAVE_LINUX_NETWORK
5aabfc78 908void netlink_init(void);
5aabfc78 909void netlink_multicast(void);
5e9e0efb
SK
910#endif
911
912/* bpf.c */
824af85b 913#ifdef HAVE_BSD_NETWORK
5aabfc78
SK
914void init_bpf(void);
915void send_via_bpf(struct dhcp_packet *mess, size_t len,
5e9e0efb 916 struct in_addr iface_addr, struct ifreq *ifr);
0a852541 917#endif
3d8df260 918
824af85b 919/* bpf.c or netlink.c */
28866e95 920int iface_enumerate(int family, void *parm, int (callback)());
824af85b 921
3d8df260
SK
922/* dbus.c */
923#ifdef HAVE_DBUS
5aabfc78
SK
924char *dbus_init(void);
925void check_dbus_listeners(fd_set *rset, fd_set *wset, fd_set *eset);
926void set_dbus_listeners(int *maxfdp, fd_set *rset, fd_set *wset, fd_set *eset);
316e2730 927# ifdef HAVE_DHCP
1f15b81d 928void emit_dbus_signal(int action, struct dhcp_lease *lease, char *hostname);
316e2730 929# endif
3d8df260 930#endif
1697269c
SK
931
932/* helper.c */
7622fc06 933#if defined(HAVE_DHCP) && !defined(NO_FORK)
1a6bca81 934int create_helper(int event_fd, int err_fd, uid_t uid, gid_t gid, long max_fd);
5aabfc78
SK
935void helper_write(void);
936void queue_script(int action, struct dhcp_lease *lease,
937 char *hostname, time_t now);
1697269c 938int helper_buf_empty(void);
5aabfc78 939#endif
832af0ba
SK
940
941/* tftp.c */
942#ifdef HAVE_TFTP
5aabfc78
SK
943void tftp_request(struct listener *listen, time_t now);
944void check_tftp_listeners(fd_set *rset, time_t now);
832af0ba 945#endif
7de060b0
SK
946
947/* conntrack.c */
948#ifdef HAVE_CONNTRACK
949int get_incoming_mark(union mysockaddr *peer_addr, struct all_addr *local_addr,
950 int istcp, unsigned int *markp);
951#endif