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