]> git.ipfire.org Git - people/ms/dnsmasq.git/blame - src/dnsmasq.h
import of dnsmasq-2.38.tar.gz
[people/ms/dnsmasq.git] / src / dnsmasq.h
CommitLineData
1b7ecd11 1/* dnsmasq is Copyright (c) 2000-2007 Simon Kelley
9e4abcb5
SK
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.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11*/
12
1b7ecd11 13#define COPYRIGHT "Copyright (C) 2000-2007 Simon Kelley"
9e4abcb5 14
9e4abcb5 15/* get these before config.h for IPv6 stuff... */
44a2a316 16#include <sys/types.h>
9e4abcb5
SK
17#include <netinet/in.h>
18
f6b7dc47
SK
19#ifdef __APPLE__
20/* need this before arpa/nameser.h */
21# define BIND_8_COMPAT
22#endif
3be34541 23#include <arpa/nameser.h>
9e4abcb5 24
59353a6b
SK
25/* and this. */
26#include <getopt.h>
27
9e4abcb5 28#include "config.h"
b8187c80
SK
29
30#define gettext_noop(S) (S)
31#ifdef NO_GETTEXT
32# define _(S) (S)
33#else
34# include <libintl.h>
35# include <locale.h>
36# define _(S) gettext(S)
37#endif
38
9e4abcb5
SK
39#include <arpa/inet.h>
40#include <sys/stat.h>
41#include <sys/socket.h>
9e4abcb5
SK
42#include <sys/ioctl.h>
43#include <sys/select.h>
feba5c1d 44#include <sys/wait.h>
9e4abcb5 45#include <sys/time.h>
8a911ccc 46#include <limits.h>
9e4abcb5
SK
47#include <net/if.h>
48#include <unistd.h>
49#include <stdio.h>
50#include <string.h>
51#include <stdlib.h>
52#include <fcntl.h>
53#include <ctype.h>
54#include <signal.h>
9e4abcb5
SK
55#include <time.h>
56#include <errno.h>
57#include <pwd.h>
58#include <grp.h>
f6b7dc47 59#include <stdarg.h>
de37951c 60#if defined(__OpenBSD__) || defined(__NetBSD__)
44a2a316
SK
61# include <netinet/if_ether.h>
62#else
63# include <net/ethernet.h>
64#endif
9e4abcb5
SK
65#include <net/if_arp.h>
66#include <netinet/in_systm.h>
67#include <netinet/ip.h>
3be34541 68#include <netinet/ip_icmp.h>
5e9e0efb 69#include <sys/uio.h>
849a8357
SK
70#include <syslog.h>
71#include <dirent.h>
5e9e0efb 72#ifndef HAVE_LINUX_NETWORK
44a2a316 73# include <net/if_dl.h>
9e4abcb5 74#endif
5e9e0efb
SK
75
76#ifdef HAVE_LINUX_NETWORK
77#include <linux/capability.h>
78/* There doesn't seem to be a universally-available
79 userpace header for this. */
80extern int capset(cap_user_header_t header, cap_user_data_t data);
81#include <sys/prctl.h>
82#endif
9e4abcb5 83
0a852541
SK
84/* Min buffer size: we check after adding each record, so there must be
85 memory for the largest packet, and the largest record so the
86 min for DNS is PACKETSZ+MAXDNAME+RRFIXEDSZ which is < 1000.
87 This might be increased is EDNS packet size if greater than the minimum.
cdeda28f
SK
88*/
89#define DNSMASQ_PACKETSZ PACKETSZ+MAXDNAME+RRFIXEDSZ
44a2a316 90
832af0ba
SK
91#define OPT_BOGUSPRIV (1<<0)
92#define OPT_FILTER (1<<1)
93#define OPT_LOG (1<<2)
94#define OPT_SELFMX (1<<3)
95#define OPT_NO_HOSTS (1<<4)
96#define OPT_NO_POLL (1<<5)
97#define OPT_DEBUG (1<<6)
98#define OPT_ORDER (1<<7)
99#define OPT_NO_RESOLV (1<<8)
100#define OPT_EXPAND (1<<9)
101#define OPT_LOCALMX (1<<10)
102#define OPT_NO_NEG (1<<11)
103#define OPT_NODOTS_LOCAL (1<<12)
104#define OPT_NOWILD (1<<13)
105#define OPT_ETHERS (1<<14)
106#define OPT_RESOLV_DOMAIN (1<<15)
107#define OPT_NO_FORK (1<<16)
108#define OPT_AUTHORITATIVE (1<<17)
109#define OPT_LOCALISE (1<<18)
110#define OPT_DBUS (1<<19)
111#define OPT_BOOTP_DYNAMIC (1<<20)
112#define OPT_NO_PING (1<<21)
113#define OPT_LEASE_RO (1<<22)
114#define OPT_RELOAD (1<<24)
115#define OPT_TFTP (1<<25)
116#define OPT_TFTP_SECURE (1<<26)
6b01084f 117#define OPT_TFTP_NOBLOCK (1<<27)
9e4abcb5
SK
118
119struct all_addr {
120 union {
121 struct in_addr addr4;
122#ifdef HAVE_IPV6
123 struct in6_addr addr6;
124#endif
125 } addr;
126};
127
128struct bogus_addr {
129 struct in_addr addr;
130 struct bogus_addr *next;
131};
132
1cff166d
SK
133/* dns doctor param */
134struct doctor {
135 struct in_addr in, out, mask;
136 struct doctor *next;
137};
138
0a852541
SK
139struct mx_srv_record {
140 char *name, *target;
3d8df260
SK
141 int issrv, srvport, priority, weight;
142 unsigned int offset;
0a852541 143 struct mx_srv_record *next;
de37951c
SK
144};
145
0a852541
SK
146struct txt_record {
147 char *name, *txt;
148 unsigned short class, len;
149 struct txt_record *next;
f6b7dc47
SK
150};
151
832af0ba
SK
152struct ptr_record {
153 char *name, *ptr;
154 struct ptr_record *next;
155};
156
9e4abcb5
SK
157union bigname {
158 char name[MAXDNAME];
159 union bigname *next; /* freelist */
160};
161
162struct crec {
163 struct crec *next, *prev, *hash_next;
164 time_t ttd; /* time to die */
fd9fa481
SK
165 int uid;
166 union {
167 struct all_addr addr;
168 struct {
169 struct crec *cache;
170 int uid;
171 } cname;
172 } addr;
9e4abcb5
SK
173 unsigned short flags;
174 union {
175 char sname[SMALLDNAME];
176 union bigname *bname;
177 char *namep;
178 } name;
179};
180
181#define F_IMMORTAL 1
fd9fa481 182#define F_CONFIG 2
9e4abcb5
SK
183#define F_REVERSE 4
184#define F_FORWARD 8
185#define F_DHCP 16
186#define F_NEG 32
187#define F_HOSTS 64
188#define F_IPV4 128
189#define F_IPV6 256
190#define F_BIGNAME 512
191#define F_UPSTREAM 1024
192#define F_SERVER 2048
193#define F_NXDOMAIN 4096
194#define F_QUERY 8192
fd9fa481 195#define F_CNAME 16384
9e4abcb5
SK
196#define F_NOERR 32768
197
198/* struct sockaddr is not large enough to hold any address,
cdeda28f 199 and specifically not big enough to hold an IPv6 address.
9e4abcb5
SK
200 Blech. Roll our own. */
201union mysockaddr {
202 struct sockaddr sa;
203 struct sockaddr_in in;
204#ifdef HAVE_BROKEN_SOCKADDR_IN6
205 /* early versions of glibc don't include sin6_scope_id in sockaddr_in6
206 but latest kernels _require_ it to be set. The choice is to have
207 dnsmasq fail to compile on back-level libc or fail to run
208 on latest kernels with IPv6. Or to do this: sorry that it's so gross. */
209 struct my_sockaddr_in6 {
210 sa_family_t sin6_family; /* AF_INET6 */
211 uint16_t sin6_port; /* transport layer port # */
212 uint32_t sin6_flowinfo; /* IPv6 traffic class & flow info */
213 struct in6_addr sin6_addr; /* IPv6 address */
214 uint32_t sin6_scope_id; /* set of interfaces for a scope */
215 } in6;
216#elif defined(HAVE_IPV6)
217 struct sockaddr_in6 in6;
218#endif
219};
220
0a852541
SK
221#define SERV_FROM_RESOLV 1 /* 1 for servers from resolv, 0 for command line. */
222#define SERV_NO_ADDR 2 /* no server, this domain is local only */
223#define SERV_LITERAL_ADDRESS 4 /* addr is the answer, not the server */
224#define SERV_HAS_SOURCE 8 /* source address specified */
225#define SERV_HAS_DOMAIN 16 /* server for one domain only */
226#define SERV_FOR_NODOTS 32 /* server for names with no domain part only */
227#define SERV_WARNED_RECURSIVE 64 /* avoid warning spam */
3d8df260
SK
228#define SERV_FROM_DBUS 128 /* 1 if source is DBus */
229#define SERV_MARK 256 /* for mark-and-delete */
9e4abcb5
SK
230#define SERV_TYPE (SERV_HAS_DOMAIN | SERV_FOR_NODOTS)
231
0a852541 232
9e4abcb5
SK
233struct serverfd {
234 int fd;
235 union mysockaddr source_addr;
236 struct serverfd *next;
237};
238
239struct server {
240 union mysockaddr addr, source_addr;
1697269c 241 struct serverfd *sfd;
9e4abcb5 242 char *domain; /* set if this server only handles a domain. */
feba5c1d 243 int flags, tcpfd;
9e4abcb5
SK
244 struct server *next;
245};
246
9e4abcb5
SK
247struct irec {
248 union mysockaddr addr;
f6b7dc47 249 struct in_addr netmask; /* only valid for IPv4 */
832af0ba 250 int dhcp_ok;
9e4abcb5
SK
251 struct irec *next;
252};
253
44a2a316 254struct listener {
832af0ba 255 int fd, tcpfd, tftpfd, family;
f6b7dc47 256 struct irec *iface; /* only valid for non-wildcard */
44a2a316
SK
257 struct listener *next;
258};
259
9e4abcb5
SK
260/* interface and address parms from command line. */
261struct iname {
262 char *name;
263 union mysockaddr addr;
de37951c 264 int isloop, used;
9e4abcb5
SK
265 struct iname *next;
266};
267
268/* resolv-file parms from command-line */
269struct resolvc {
270 struct resolvc *next;
3d8df260
SK
271 int is_default, logged;
272 time_t mtime;
9e4abcb5
SK
273 char *name;
274};
275
fd9fa481
SK
276/* adn-hosts parms from command-line */
277struct hostsfile {
278 struct hostsfile *next;
279 char *fname;
cdeda28f 280 int index; /* matches to cache entries for logging */
fd9fa481
SK
281};
282
9e4abcb5
SK
283struct frec {
284 union mysockaddr source;
44a2a316 285 struct all_addr dest;
832af0ba 286 struct server *sentto; /* NULL means free */
dfa666f2 287 unsigned int iface;
9e4abcb5 288 unsigned short orig_id, new_id;
0a852541 289 int fd, forwardall;
fd9fa481 290 unsigned int crc;
9e4abcb5
SK
291 time_t time;
292 struct frec *next;
293};
294
1697269c
SK
295/* actions in the daemon->helper RPC */
296#define ACTION_DEL 1
297#define ACTION_OLD_HOSTNAME 2
298#define ACTION_OLD 3
299#define ACTION_ADD 4
300
cdeda28f
SK
301#define DHCP_CHADDR_MAX 16
302
9e4abcb5
SK
303struct dhcp_lease {
304 int clid_len; /* length of client identifier */
305 unsigned char *clid; /* clientid */
306 char *hostname, *fqdn; /* name from client-hostname option or config */
1697269c 307 char *old_hostname; /* hostname before it moved to another lease */
7cebd20f
SK
308 char auth_name; /* hostname came from config, not from client */
309 char new; /* newly created */
208b65c5
SK
310 char changed; /* modified */
311 char aux_changed; /* CLID or expiry changed */
9e4abcb5 312 time_t expires; /* lease expiry */
5e9e0efb
SK
313#ifdef HAVE_BROKEN_RTC
314 unsigned int length;
315#endif
cdeda28f
SK
316 int hwaddr_len, hwaddr_type;
317 unsigned char hwaddr[DHCP_CHADDR_MAX];
9e4abcb5 318 struct in_addr addr;
1697269c
SK
319 unsigned char *vendorclass, *userclass;
320 unsigned int vendorclass_len, userclass_len;
9e4abcb5
SK
321 struct dhcp_lease *next;
322};
323
a222641c
SK
324struct dhcp_netid {
325 char *net;
326 struct dhcp_netid *next;
327};
328
26128d27
SK
329struct dhcp_netid_list {
330 struct dhcp_netid *list;
331 struct dhcp_netid_list *next;
332};
1697269c 333
9e4abcb5 334struct dhcp_config {
33820b7e 335 unsigned int flags;
9e4abcb5
SK
336 int clid_len; /* length of client identifier */
337 unsigned char *clid; /* clientid */
cdeda28f
SK
338 int hwaddr_len, hwaddr_type;
339 unsigned char hwaddr[DHCP_CHADDR_MAX];
a222641c
SK
340 char *hostname;
341 struct dhcp_netid netid;
9e4abcb5 342 struct in_addr addr;
849a8357 343 time_t decline_time;
0a852541 344 unsigned int lease_time, wildcard_mask;
9e4abcb5
SK
345 struct dhcp_config *next;
346};
347
0a852541
SK
348#define CONFIG_DISABLE 1
349#define CONFIG_CLID 2
350#define CONFIG_HWADDR 4
351#define CONFIG_TIME 8
352#define CONFIG_NAME 16
353#define CONFIG_ADDR 32
354#define CONFIG_NETID 64
355#define CONFIG_NOCLID 128
849a8357
SK
356#define CONFIG_FROM_ETHERS 256 /* entry created by /etc/ethers */
357#define CONFIG_ADDR_HOSTS 512 /* address added by from /etc/hosts */
358#define CONFIG_DECLINED 1024 /* address declined by client */
33820b7e 359
9e4abcb5 360struct dhcp_opt {
cdeda28f 361 int opt, len, flags;
91dccd09 362 unsigned char *val, *vendor_class;
26128d27 363 struct dhcp_netid *netid;
9e4abcb5 364 struct dhcp_opt *next;
a84fa1d0
SK
365};
366
cdeda28f
SK
367#define DHOPT_ADDR 1
368#define DHOPT_STRING 2
6b01084f
SK
369#define DHOPT_ENCAPSULATE 4
370#define DHOPT_VENDOR_MATCH 8
371#define DHOPT_FORCE 16
cdeda28f 372
26128d27
SK
373struct dhcp_boot {
374 char *file, *sname;
375 struct in_addr next_server;
376 struct dhcp_netid *netid;
377 struct dhcp_boot *next;
378};
379
a84fa1d0 380struct dhcp_vendor {
26128d27 381 int len, is_vendor;
a222641c
SK
382 char *data;
383 struct dhcp_netid netid;
a84fa1d0
SK
384 struct dhcp_vendor *next;
385};
9e4abcb5 386
cdeda28f
SK
387struct dhcp_mac {
388 unsigned int mask;
389 int hwaddr_len, hwaddr_type;
390 unsigned char hwaddr[DHCP_CHADDR_MAX];
391 struct dhcp_netid netid;
392 struct dhcp_mac *next;
393};
394
832af0ba
SK
395#if defined(__FreeBSD__) || defined(__DragonFly__)
396struct dhcp_bridge {
397 char iface[IF_NAMESIZE];
398 struct dhcp_bridge *alias, *next;
399};
400#endif
401
9e4abcb5 402struct dhcp_context {
feba5c1d 403 unsigned int lease_time, addr_epoch;
0a852541
SK
404 struct in_addr netmask, broadcast;
405 struct in_addr local, router;
a84fa1d0 406 struct in_addr start, end; /* range of available addresses */
0a852541 407 int flags;
cdeda28f 408 struct dhcp_netid netid, *filter;
36717eee 409 struct dhcp_context *next, *current;
9e4abcb5
SK
410};
411
0a852541 412#define CONTEXT_STATIC 1
cdeda28f
SK
413#define CONTEXT_NETMASK 2
414#define CONTEXT_BRDCAST 4
0a852541
SK
415
416
9e4abcb5
SK
417typedef unsigned char u8;
418typedef unsigned short u16;
419typedef unsigned int u32;
420
421
5e9e0efb
SK
422struct dhcp_packet {
423 u8 op, htype, hlen, hops;
424 u32 xid;
425 u16 secs, flags;
426 struct in_addr ciaddr, yiaddr, siaddr, giaddr;
427 u8 chaddr[DHCP_CHADDR_MAX], sname[64], file[128];
428 u8 options[312];
9e4abcb5
SK
429};
430
3d8df260
SK
431struct ping_result {
432 struct in_addr addr;
433 time_t time;
434 struct ping_result *next;
435};
9e4abcb5 436
832af0ba
SK
437struct tftp_file {
438 int refcount, fd;
439 off_t size;
440 char filename[];
441};
442
443struct tftp_transfer {
444 int sockfd;
445 time_t timeout;
446 int backoff;
447 unsigned int block, blocksize;
448 struct sockaddr_in peer;
449 char opt_blocksize, opt_transize;
450 struct tftp_file *file;
451 struct tftp_transfer *next;
452};
453
3be34541
SK
454struct daemon {
455 /* datastuctures representing the command-line and
456 config file arguments. All set (including defaults)
457 in option.c */
458
459 unsigned int options;
460 struct resolvc default_resolv, *resolv_files;
0a852541
SK
461 struct mx_srv_record *mxnames;
462 struct txt_record *txt;
832af0ba 463 struct ptr_record *ptr;
3be34541
SK
464 char *mxtarget;
465 char *lease_file;
466 char *username, *groupname;
467 char *domain_suffix;
468 char *runfile;
7cebd20f 469 char *lease_change_command;
3d8df260 470 struct iname *if_names, *if_addrs, *if_except, *dhcp_except;
3be34541
SK
471 struct bogus_addr *bogus_addr;
472 struct server *servers;
849a8357 473 int log_fac; /* log facility */
208b65c5 474 int cachesize, ftabsize;
3be34541
SK
475 int port, query_port;
476 unsigned long local_ttl;
fd9fa481 477 struct hostsfile *addn_hosts;
3be34541
SK
478 struct dhcp_context *dhcp;
479 struct dhcp_config *dhcp_conf;
6b01084f 480 struct dhcp_opt *dhcp_opts;
3be34541 481 struct dhcp_vendor *dhcp_vendors;
cdeda28f 482 struct dhcp_mac *dhcp_macs;
26128d27 483 struct dhcp_boot *boot_config;
832af0ba
SK
484 struct dhcp_netid_list *dhcp_ignore, *dhcp_ignore_names;
485 int dhcp_max, tftp_max;
3be34541
SK
486 unsigned int min_leasetime;
487 struct doctor *doctors;
488 unsigned short edns_pktsz;
489
490 /* globally used stuff for DNS */
491 char *packet; /* packet buffer */
0a852541 492 int packet_buff_sz; /* size of above */
3be34541
SK
493 char *namebuff; /* MAXDNAME size buffer */
494 struct serverfd *sfds;
3d8df260 495 struct irec *interfaces;
3be34541
SK
496 struct listener *listeners;
497 struct server *last_server;
cdeda28f
SK
498 struct server *srv_save; /* Used for resend on DoD */
499 size_t packet_len; /* " " */
1697269c
SK
500 pid_t tcp_pids[MAX_PROCS];
501
3be34541 502 /* DHCP state */
1697269c 503 int dhcpfd, helperfd;
5e9e0efb 504#ifdef HAVE_LINUX_NETWORK
0a852541 505 int netlinkfd;
5e9e0efb
SK
506#else
507 int dhcp_raw_fd, dhcp_icmp_fd;
0a852541 508#endif
5e9e0efb 509 struct iovec dhcp_packet;
3be34541 510 char *dhcp_buff, *dhcp_buff2;
3d8df260 511 struct ping_result *ping_results;
cdeda28f 512 FILE *lease_stream;
832af0ba
SK
513#if defined(__FreeBSD__) || defined(__DragonFly__)
514 struct dhcp_bridge *bridges;
515#endif
3d8df260
SK
516
517 /* DBus stuff */
3d8df260
SK
518 /* void * here to avoid depending on dbus headers outside dbus.c */
519 void *dbus;
832af0ba 520#ifdef HAVE_DBUS
3d8df260
SK
521 struct watch *watches;
522#endif
523
832af0ba
SK
524 /* TFTP stuff */
525 struct tftp_transfer *tftp_trans;
526 char *tftp_prefix;
3be34541
SK
527};
528
9e4abcb5
SK
529/* cache.c */
530void cache_init(int cachesize, int log);
fd9fa481
SK
531void log_query(unsigned short flags, char *name, struct all_addr *addr,
532 unsigned short type, struct hostsfile *addn_hosts, int index);
9e4abcb5
SK
533struct crec *cache_find_by_addr(struct crec *crecp,
534 struct all_addr *addr, time_t now,
535 unsigned short prot);
536struct crec *cache_find_by_name(struct crec *crecp,
537 char *name, time_t now, unsigned short prot);
538void cache_end_insert(void);
539void cache_start_insert(void);
fd9fa481
SK
540struct crec *cache_insert(char *name, struct all_addr *addr,
541 time_t now, unsigned long ttl, unsigned short flags);
542void cache_reload(int opts, char *buff, char *domain_suffix, struct hostsfile *addn_hosts);
543void cache_add_dhcp_entry(struct daemon *daemon, char *host_name, struct in_addr *host_address, time_t ttd);
9e4abcb5 544void cache_unhash_dhcp(void);
5e9e0efb 545void dump_cache(struct daemon *daemon, time_t now);
9e4abcb5
SK
546char *cache_get_name(struct crec *crecp);
547
548/* rfc1035.c */
cdeda28f 549unsigned short extract_request(HEADER *header, size_t qlen,
c1bb8504 550 char *name, unsigned short *typep);
cdeda28f
SK
551size_t setup_reply(HEADER *header, size_t qlen,
552 struct all_addr *addrp, unsigned short flags,
553 unsigned long local_ttl);
554void extract_addresses(HEADER *header, size_t qlen, char *namebuff,
fd9fa481 555 time_t now, struct daemon *daemon);
cdeda28f 556size_t answer_request(HEADER *header, char *limit, size_t qlen, struct daemon *daemon,
f6b7dc47 557 struct in_addr local_addr, struct in_addr local_netmask, time_t now);
cdeda28f 558int check_for_bogus_wildcard(HEADER *header, size_t qlen, char *name,
9e4abcb5 559 struct bogus_addr *addr, time_t now);
cdeda28f 560unsigned char *find_pseudoheader(HEADER *header, size_t plen,
832af0ba 561 size_t *len, unsigned char **p, int *is_sign);
f6b7dc47 562int check_for_local_domain(char *name, time_t now, struct daemon *daemon);
cdeda28f
SK
563unsigned int questions_crc(HEADER *header, size_t plen, char *buff);
564size_t resize_packet(HEADER *header, size_t plen,
565 unsigned char *pheader, size_t hlen);
9e4abcb5
SK
566
567/* util.c */
568unsigned short rand16(void);
569int legal_char(char c);
570int canonicalise(char *s);
3d8df260 571unsigned char *do_rfc1035_name(unsigned char *p, char *sval);
9e4abcb5 572void die(char *message, char *arg1);
0a852541
SK
573void complain(char *message, int lineno, char *file);
574void *safe_malloc(size_t size);
9e4abcb5
SK
575int sa_len(union mysockaddr *addr);
576int sockaddr_isequal(union mysockaddr *s1, union mysockaddr *s2);
3d8df260 577int hostname_isequal(char *a, char *b);
5e9e0efb 578time_t dnsmasq_time(void);
a84fa1d0 579int is_same_net(struct in_addr a, struct in_addr b, struct in_addr mask);
fd9fa481 580int retry_send(void);
0a852541 581void prettyprint_time(char *buf, unsigned int t);
3d8df260 582int prettyprint_addr(union mysockaddr *addr, char *buf);
0a852541 583int parse_hex(char *in, unsigned char *out, int maxlen,
cdeda28f 584 unsigned int *wildcard_mask, int *mac_type);
5e9e0efb
SK
585int memcmp_masked(unsigned char *a, unsigned char *b, int len,
586 unsigned int mask);
587int expand_buf(struct iovec *iov, size_t size);
7cebd20f 588char *print_mac(struct daemon *daemon, unsigned char *mac, int len);
1697269c
SK
589void bump_maxfd(int fd, int *max);
590void log_start(struct daemon *daemon);
591int read_write(int fd, unsigned char *packet, int size, int rw);
7cebd20f 592
9e4abcb5 593/* option.c */
3d8df260 594struct daemon *read_opts (int argc, char **argv, char *compile_opts);
9e4abcb5
SK
595
596/* forward.c */
3be34541
SK
597void reply_query(struct serverfd *sfd, struct daemon *daemon, time_t now);
598void receive_query(struct listener *listen, struct daemon *daemon, time_t now);
3d8df260
SK
599unsigned char *tcp_request(struct daemon *daemon, int confd, time_t now,
600 struct in_addr local_addr, struct in_addr netmask);
849a8357 601void server_gone(struct daemon *daemon, struct server *server);
1697269c 602struct frec *get_new_frec(struct daemon *daemon, time_t now, int *wait);
3be34541 603
9e4abcb5 604/* network.c */
feba5c1d 605struct serverfd *allocate_sfd(union mysockaddr *addr, struct serverfd **sfds);
849a8357 606int reload_servers(char *fname, struct daemon *daemon);
3d8df260 607void check_servers(struct daemon *daemon);
5e9e0efb 608int enumerate_interfaces(struct daemon *daemon);
832af0ba 609struct listener *create_wildcard_listeners(int port, int have_tftp);
5e9e0efb 610struct listener *create_bound_listeners(struct daemon *daemon);
832af0ba
SK
611int iface_check(struct daemon *daemon, int family, struct all_addr *addr,
612 struct ifreq *ifr, int *indexp);
7cebd20f 613int fix_fd(int fd);
3be34541 614
9e4abcb5 615/* dhcp.c */
3be34541
SK
616void dhcp_init(struct daemon *daemon);
617void dhcp_packet(struct daemon *daemon, time_t now);
618
59353a6b
SK
619struct dhcp_context *address_available(struct dhcp_context *context, struct in_addr addr);
620struct dhcp_context *narrow_context(struct dhcp_context *context, struct in_addr taddr);
cdeda28f 621int match_netid(struct dhcp_netid *check, struct dhcp_netid *pool, int negonly);
3be34541 622int address_allocate(struct dhcp_context *context, struct daemon *daemon,
cdeda28f 623 struct in_addr *addrp, unsigned char *hwaddr, int hw_len,
3d8df260 624 struct dhcp_netid *netids, time_t now);
9e4abcb5
SK
625struct dhcp_config *find_config(struct dhcp_config *configs,
626 struct dhcp_context *context,
627 unsigned char *clid, int clid_len,
cdeda28f
SK
628 unsigned char *hwaddr, int hw_len,
629 int hw_type, char *hostname);
44a2a316 630void dhcp_update_configs(struct dhcp_config *configs);
3be34541 631void dhcp_read_ethers(struct daemon *daemon);
dfa666f2 632struct dhcp_config *config_find_by_address(struct dhcp_config *configs, struct in_addr addr);
bb01cb96
SK
633char *strip_hostname(struct daemon *daemon, char *hostname);
634char *host_from_dns(struct daemon *daemon, struct in_addr addr);
3be34541 635
9e4abcb5 636/* lease.c */
7cebd20f 637void lease_update_file(struct daemon *daemon, time_t now);
fd9fa481 638void lease_update_dns(struct daemon *daemon);
3be34541 639void lease_init(struct daemon *daemon, time_t now);
7cebd20f
SK
640struct dhcp_lease *lease_allocate(struct in_addr addr);
641void lease_set_hwaddr(struct dhcp_lease *lease, unsigned char *hwaddr,
cdeda28f 642 unsigned char *clid, int hw_len, int hw_type, int clid_len);
b8187c80
SK
643void lease_set_hostname(struct dhcp_lease *lease, char *name,
644 char *suffix, int auth);
5e9e0efb 645void lease_set_expires(struct dhcp_lease *lease, unsigned int len, time_t now);
cdeda28f 646struct dhcp_lease *lease_find_by_client(unsigned char *hwaddr, int hw_len, int hw_type,
0a852541 647 unsigned char *clid, int clid_len);
9e4abcb5
SK
648struct dhcp_lease *lease_find_by_addr(struct in_addr addr);
649void lease_prune(struct dhcp_lease *target, time_t now);
b8187c80 650void lease_update_from_configs(struct daemon *daemon);
1697269c 651int do_script_run(struct daemon *daemon);
a84fa1d0 652
9e4abcb5 653/* rfc2131.c */
cdeda28f 654size_t dhcp_reply(struct daemon *daemon, struct dhcp_context *context, char *iface_name, size_t sz, time_t now, int unicast_dest);
3be34541
SK
655
656/* dnsmasq.c */
5e9e0efb 657int make_icmp_sock(void);
3be34541 658int icmp_ping(struct daemon *daemon, struct in_addr addr);
7cebd20f 659void clear_cache_and_reload(struct daemon *daemon, time_t now);
44a2a316 660
33820b7e
SK
661/* isc.c */
662#ifdef HAVE_ISC_READER
fd9fa481 663void load_dhcp(struct daemon *daemon, time_t now);
33820b7e 664#endif
feba5c1d 665
0a852541 666/* netlink.c */
5e9e0efb 667#ifdef HAVE_LINUX_NETWORK
cdeda28f 668void netlink_init(struct daemon *daemon);
5e9e0efb
SK
669int iface_enumerate(struct daemon *daemon, void *parm,
670 int (*ipv4_callback)(), int (*ipv6_callback)());
cdeda28f 671void netlink_multicast(struct daemon *daemon);
5e9e0efb
SK
672#endif
673
674/* bpf.c */
675#ifndef HAVE_LINUX_NETWORK
676void init_bpf(struct daemon *daemon);
677void send_via_bpf(struct daemon *daemon, struct dhcp_packet *mess, size_t len,
678 struct in_addr iface_addr, struct ifreq *ifr);
679int iface_enumerate(struct daemon *daemon, void *parm,
680 int (*ipv4_callback)(), int (*ipv6_callback)());
0a852541 681#endif
3d8df260
SK
682
683/* dbus.c */
684#ifdef HAVE_DBUS
685char *dbus_init(struct daemon *daemon);
686void check_dbus_listeners(struct daemon *daemon,
687 fd_set *rset, fd_set *wset, fd_set *eset);
1697269c
SK
688void set_dbus_listeners(struct daemon *daemon, int *maxfdp,
689 fd_set *rset, fd_set *wset, fd_set *eset);
3d8df260 690#endif
1697269c
SK
691
692/* helper.c */
693int create_helper(struct daemon *daemon);
694void helper_write(struct daemon *daemon);
695void queue_script(struct daemon *daemon, int action,
696 struct dhcp_lease *lease, char *hostname);
697int helper_buf_empty(void);
832af0ba
SK
698
699/* tftp.c */
700#ifdef HAVE_TFTP
701void tftp_request(struct listener *listen, struct daemon *daemon, time_t now);
702void check_tftp_listeners(struct daemon *daemon, fd_set *rset, time_t now);
703#endif